diff --git a/components/control_protocol/control_protocol_internal.h b/components/control_protocol/control_protocol_internal.h index c17e128c..b6146674 100644 --- a/components/control_protocol/control_protocol_internal.h +++ b/components/control_protocol/control_protocol_internal.h @@ -189,6 +189,11 @@ bool rpc_get_usb_emulation_state(const jetkvm_control_context_t *context, bool rpc_set_usb_emulation_state(const jetkvm_control_context_t *context, const cJSON *params, rpc_dispatch_result_t *dispatch); +extern jetkvm_pointer_context_t s_default_pointer; +bool rpc_get_pointer_type(const jetkvm_control_context_t *context, + const cJSON *params, rpc_dispatch_result_t *dispatch); +bool rpc_set_pointer_type(const jetkvm_control_context_t *context, + const cJSON *params, rpc_dispatch_result_t *dispatch); extern jetkvm_usb_debugging_context_t s_default_usb_debugging; bool rpc_get_usb_debugging_state(const jetkvm_control_context_t *context, const cJSON *params, diff --git a/components/control_protocol/include/jetkvm_control.h b/components/control_protocol/include/jetkvm_control.h index 1121992e..91f3a019 100644 --- a/components/control_protocol/include/jetkvm_control.h +++ b/components/control_protocol/include/jetkvm_control.h @@ -1143,6 +1143,20 @@ typedef struct { } jetkvm_usb_debugging_context_t; void jetkvm_control_set_default_usb_debugging_context(const jetkvm_usb_debugging_context_t *context); +/* The pointer type (components/jetkvm_pointer): "mouse" or "pen". set stores + * and applies it and returns NULL, or the reason it could not; a change + * presents USB again. A registered context adds the "pointer_types" + * capability. setPointerType uses the request's context (pointer), which the + * RPC worker fills with the default, because set writes NVS and waits for + * USB. */ +typedef struct { + const char *(*get)(void *ctx); + const char *(*set)(const char *type, void *ctx); + void *ctx; +} jetkvm_pointer_context_t; +void jetkvm_control_set_default_pointer_context(const jetkvm_pointer_context_t *context); +jetkvm_pointer_context_t jetkvm_control_default_pointer_context(void); + /* Certificates are public; get never exposes private key material. */ typedef struct { bool (*get)(char *mode, size_t mode_capacity, char *certificate, size_t capacity, void *ctx); @@ -1385,6 +1399,8 @@ typedef struct { jetkvm_guest_clipboard_context_t guest_clipboard; /** Per request, as guest_clipboard. */ jetkvm_guest_file_context_t guest_file; + /** Per request, as guest_clipboard: only its set is used. */ + jetkvm_pointer_context_t pointer; void *network_ctx; void *hid_state_ctx; /** Called for each known method that counts as activity diff --git a/components/control_protocol/jetkvm_control.c b/components/control_protocol/jetkvm_control.c index 9eee7332..83b184c4 100644 --- a/components/control_protocol/jetkvm_control.c +++ b/components/control_protocol/jetkvm_control.c @@ -301,6 +301,8 @@ static const rpc_method_t s_rpc_methods[] = { { "setUsbDeviceState", rpc_set_usb_device_state }, { "getUsbEmulationState", rpc_get_usb_emulation_state }, { "setUsbEmulationState", rpc_set_usb_emulation_state }, + { "getPointerType", rpc_get_pointer_type }, + { "setPointerType", rpc_set_pointer_type }, { "getUsbDebuggingState", rpc_get_usb_debugging_state }, { "setUsbDebuggingState", rpc_set_usb_debugging_state }, { "wakeHost", rpc_wake_host }, diff --git a/components/control_protocol/rpc_usb.c b/components/control_protocol/rpc_usb.c index 56c5ed91..f23402a6 100644 --- a/components/control_protocol/rpc_usb.c +++ b/components/control_protocol/rpc_usb.c @@ -600,6 +600,67 @@ bool rpc_set_usb_emulation_state( } } +jetkvm_pointer_context_t s_default_pointer; + +void jetkvm_control_set_default_pointer_context( + const jetkvm_pointer_context_t *context) +{ + s_default_pointer = context ? *context : (jetkvm_pointer_context_t){ 0 }; +} + +jetkvm_pointer_context_t jetkvm_control_default_pointer_context(void) +{ + return s_default_pointer; +} + +static bool pointer_type_state(rpc_dispatch_result_t *dispatch) +{ + const char *type = s_default_pointer.get ? + s_default_pointer.get(s_default_pointer.ctx) : NULL; + if (!type) { + dispatch->error_code = -32603; + dispatch->error_message = "Internal error"; + dispatch->error_data = "Pointer type unavailable"; + return true; + } + dispatch->result = cJSON_CreateString(type); + return dispatch->result != NULL; +} + +bool rpc_get_pointer_type(const jetkvm_control_context_t *context, + const cJSON *params, rpc_dispatch_result_t *dispatch) +{ + (void)context; + if (!require_no_rpc_params(params, dispatch)) { + return true; + } + return pointer_type_state(dispatch); +} + +bool rpc_set_pointer_type(const jetkvm_control_context_t *context, + const cJSON *params, rpc_dispatch_result_t *dispatch) +{ + const cJSON *type = rpc_param(params, "type"); + if (!cJSON_IsString(type) || !type->valuestring || params->child != type || + type->next != NULL) { + dispatch->error_code = -32602; + dispatch->error_message = "Invalid params"; + dispatch->error_data = "type must be the only parameter and must be a string"; + return true; + } + const jetkvm_pointer_context_t *pointer = &context->pointer; + const char *error = pointer->set ? + pointer->set(type->valuestring, pointer->ctx) : + "Pointer type unavailable"; + if (error) { + dispatch->error_code = -32603; + dispatch->error_message = "Internal error"; + dispatch->error_data = error; + return true; + } + return pointer_type_state(dispatch); +} + jetkvm_usb_debugging_context_t s_default_usb_debugging; void jetkvm_control_set_default_usb_debugging_context( diff --git a/components/control_protocol/rpc_video.c b/components/control_protocol/rpc_video.c index 5cfb51e0..025307d2 100644 --- a/components/control_protocol/rpc_video.c +++ b/components/control_protocol/rpc_video.c @@ -48,6 +48,8 @@ static bool add_capability(cJSON *list, bool present, const char *name) * orientations instead of upstream's Normal (270) and Inverted (90). * "usb_debugging": the build registered the USB debugging setting, so the UI * shows its switch (getUsbDebuggingState, setUsbDebuggingState). + * "pointer_types": the build registered the pointer type, so the UI shows its + * modes (getPointerType, setPointerType). * "extra_hostnames": the web server takes other names for the device * (getExtraHostnames, setExtraHostnames), so the UI shows that setting. * "mdns": the network settings carry mdns_mode, so the UI shows the mDNS @@ -85,6 +87,8 @@ static cJSON *device_capabilities_json(const jetkvm_control_context_t *context) !add_capability(result, ts->get_status && ts->get_config && ts->set_config, "tailscale") || !add_capability(result, s_default_usb_debugging.get && s_default_usb_debugging.set, "usb_debugging") || + !add_capability(result, s_default_pointer.get && s_default_pointer.set, + "pointer_types") || !add_capability(result, s_default_extra_hostnames.get && s_default_extra_hostnames.set, "extra_hostnames") || !add_capability(result, context && context->get_network_settings && diff --git a/components/control_protocol/tests/test_jetkvm_control.c b/components/control_protocol/tests/test_jetkvm_control.c index 95136c7a..c973d832 100644 --- a/components/control_protocol/tests/test_jetkvm_control.c +++ b/components/control_protocol/tests/test_jetkvm_control.c @@ -2131,6 +2131,54 @@ static void test_usb_debugging(void) "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":[]}"); } +/* The pointer type: a stored name that applies at once. */ +typedef struct { + const char *type, *error; + unsigned sets; +} pointer_test_t; +static const char *pointer_test_get(void *ctx) { return ((pointer_test_t *)ctx)->type; } +static const char *pointer_test_set(const char *type, void *ctx) +{ + pointer_test_t *test = ctx; + ++test->sets; + if (test->error) return test->error; + test->type = strcmp(type, "pen") == 0 ? "pen" : "mouse"; + return NULL; +} +static void test_pointer_type(void) +{ + display_test_error("getPointerType", "{}", -32603); + display_test_error("setPointerType", "{\"type\":\"pen\"}", -32603); + pointer_test_t test = {.type = "mouse"}; + const jetkvm_pointer_context_t pointer = { + .get = pointer_test_get, .set = pointer_test_set, .ctx = &test}; + jetkvm_control_set_default_pointer_context(&pointer); + expect_rpc("{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"getDeviceCapabilities\"}", + "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":[\"pointer_types\"]}"); + expect_rpc("{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"getPointerType\",\"params\":{}}", + "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"mouse\"}"); + /* A set runs only with the request's context, as the RPC worker gives it. */ + display_test_error("setPointerType", "{\"type\":\"pen\"}", -32603); + assert(test.sets == 0U); + const jetkvm_control_context_t worker = { + .pointer = jetkvm_control_default_pointer_context()}; + expect_rpc_context(&worker, + "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"setPointerType\",\"params\":{\"type\":\"pen\"}}", + "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"pen\"}"); + /* Bad parameters change nothing. */ + display_test_error("setPointerType", "{}", -32602); + display_test_error("setPointerType", "{\"type\":1}", -32602); + display_test_error("setPointerType", "{\"type\":\"pen\",\"x\":1}", -32602); + display_test_error("getPointerType", "{\"type\":\"pen\"}", -32602); + assert(test.sets == 1U && strcmp(test.type, "pen") == 0); + test.error = "Pointer type not saved"; + expect_rpc_context(&worker, + "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"setPointerType\",\"params\":{\"type\":\"mouse\"}}", + "{\"jsonrpc\":\"2.0\",\"id\":1,\"error\":{\"code\":-32603,\"message\":\"Internal error\",\"data\":\"Pointer type not saved\"}}"); + assert(test.sets == 2U && strcmp(test.type, "pen") == 0); + jetkvm_control_set_default_pointer_context(NULL); +} + void test_os_services(void); /* test_os_services.c */ @@ -2325,6 +2373,7 @@ int main(void) test_audio_contract(); test_cloud_deregistration(); test_usb_debugging(); + test_pointer_type(); expect_rpc( "{\"jsonrpc\":\"2.0\",\"method\":\"ping\",\"params\":{},\"id\":\"probe-1\"}", diff --git a/components/jetkvm_pointer/CMakeLists.txt b/components/jetkvm_pointer/CMakeLists.txt new file mode 100644 index 00000000..44f044c6 --- /dev/null +++ b/components/jetkvm_pointer/CMakeLists.txt @@ -0,0 +1,7 @@ +idf_component_register( + SRCS "jetkvm_pointer.c" + INCLUDE_DIRS "include" + PRIV_REQUIRES control_protocol jetkvm_hid_input jetkvm_usb_hid jetkvm_usb_service log nvs_flash +) + +target_compile_options(${COMPONENT_LIB} PRIVATE -Werror) diff --git a/components/jetkvm_pointer/include/jetkvm_pointer.h b/components/jetkvm_pointer/include/jetkvm_pointer.h new file mode 100644 index 00000000..5fdde9d1 --- /dev/null +++ b/components/jetkvm_pointer/include/jetkvm_pointer.h @@ -0,0 +1,18 @@ +/* + * SPDX-FileCopyrightText: 2026 + * SPDX-License-Identifier: MIT + */ + +#pragma once + +/* + * The pointer type: what the target computer gets from the page's absolute + * positions. It is in NVS with the other device settings (namespace + * jkvm_settings), so a factory reset erases it. Without a stored value it is + * the absolute mouse. + * + * Reads the setting for the first enumeration and registers the + * getPointerType and setPointerType RPCs. Call once, after NVS is ready and + * before jetkvm_usb_service_start(). + */ +void jetkvm_pointer_start(void); diff --git a/components/jetkvm_pointer/jetkvm_pointer.c b/components/jetkvm_pointer/jetkvm_pointer.c new file mode 100644 index 00000000..d91d54c9 --- /dev/null +++ b/components/jetkvm_pointer/jetkvm_pointer.c @@ -0,0 +1,119 @@ +/* + * SPDX-FileCopyrightText: 2026 + * SPDX-License-Identifier: MIT + */ + +#include "jetkvm_pointer.h" + +#include +#include + +#include "esp_log.h" +#include "jetkvm_control.h" +#include "jetkvm_hid_input.h" +#include "jetkvm_usb_hid.h" +#include "jetkvm_usb_service.h" +#include "nvs.h" + +#define POINTER_NAMESPACE "jkvm_settings" +#define POINTER_KEY "pointer_type" + +static const char *TAG = "jetkvm_pointer"; + +/* The selected type is not on USB yet: its reconnect failed. A request for it + * reconnects again instead of reporting success. Only the RPC worker sets the + * type, one request at a time. */ +static bool s_pending; + +/* The RPC names, by jetkvm_usb_hid_pointer_type_t, which is the stored value. */ +static const char *const s_names[] = {"mouse", "pen"}; +#define POINTER_TYPES (sizeof(s_names) / sizeof(s_names[0])) + +static esp_err_t load(uint8_t *type) +{ + nvs_handle_t handle; + esp_err_t error = nvs_open(POINTER_NAMESPACE, NVS_READONLY, &handle); + if (error != ESP_OK) { + return error; + } + error = nvs_get_u8(handle, POINTER_KEY, type); + nvs_close(handle); + return error == ESP_OK && *type >= POINTER_TYPES ? ESP_ERR_INVALID_STATE : error; +} + +static esp_err_t save(uint8_t type) +{ + nvs_handle_t handle; + esp_err_t error = nvs_open(POINTER_NAMESPACE, NVS_READWRITE, &handle); + if (error != ESP_OK) { + return error; + } + error = nvs_set_u8(handle, POINTER_KEY, type); + if (error == ESP_OK) { + error = nvs_commit(handle); + } + nvs_close(handle); + return error; +} + +static const char *rpc_get(void *ctx) +{ + (void)ctx; + return s_names[jetkvm_usb_hid_get_pointer_type()]; +} + +static const char *rpc_set(const char *name, void *ctx) +{ + (void)ctx; + uint8_t type = 0U; + while (type < POINTER_TYPES && strcmp(name, s_names[type]) != 0) { + type++; + } + if (type == POINTER_TYPES) { + return "type must be mouse or pen"; + } + const jetkvm_usb_hid_pointer_type_t previous = jetkvm_usb_hid_get_pointer_type(); + if (type == (uint8_t)previous && !s_pending) { + return NULL; + } + if (type != (uint8_t)previous) { + esp_err_t error = save(type); + if (error != ESP_OK) { + ESP_LOGW(TAG, "pointer type not saved: %s", esp_err_to_name(error)); + return "Pointer type not saved"; + } + jetkvm_usb_hid_set_pointer_type((jetkvm_usb_hid_pointer_type_t)type); + } + /* The pen has its own descriptor, so USB has to reconnect. */ + s_pending = true; + /* After the switch: a button pressed before it is released, and a report + * after it has the new type. The old descriptor stays until the + * reconnect, so the release reaches the interface that pressed. */ + const esp_err_t release = jetkvm_hid_input_release_all(); + if (release != ESP_OK) { + ESP_LOGW(TAG, "input not released: %s", esp_err_to_name(release)); + } + if (jetkvm_usb_service_reenumerate() != + JETKVM_USB_SERVICE_CONFIGURATION_COMPLETED) { + return "Pointer type saved; USB could not reconnect"; + } + s_pending = false; + ESP_LOGI(TAG, "pointer type %s", s_names[type]); + return NULL; +} + +void jetkvm_pointer_start(void) +{ + uint8_t type = JETKVM_USB_HID_POINTER_MOUSE; + esp_err_t error = load(&type); + if (error == ESP_OK) { + jetkvm_usb_hid_set_pointer_type((jetkvm_usb_hid_pointer_type_t)type); + } else if (error != ESP_ERR_NVS_NOT_FOUND) { + ESP_LOGW(TAG, "pointer type unreadable, using the mouse: %s", + esp_err_to_name(error)); + } + jetkvm_control_set_default_pointer_context(&(jetkvm_pointer_context_t){ + .get = rpc_get, + .set = rpc_set, + }); +} diff --git a/components/jetkvm_usb_hid/include/jetkvm_usb_hid.h b/components/jetkvm_usb_hid/include/jetkvm_usb_hid.h index 2e4a1faf..20bd38ad 100644 --- a/components/jetkvm_usb_hid/include/jetkvm_usb_hid.h +++ b/components/jetkvm_usb_hid/include/jetkvm_usb_hid.h @@ -68,6 +68,18 @@ typedef struct { void *ctx; } jetkvm_usb_hid_os_services_hooks_t; +/* What the absolute pointer's interface is to the target computer. */ +typedef enum { + JETKVM_USB_HID_POINTER_MOUSE, + /* An integrated pen: hover, tip, barrel button and leaving range. */ + JETKVM_USB_HID_POINTER_PEN, +} jetkvm_usb_hid_pointer_type_t; + +/* A change takes effect at the next enumeration + * (jetkvm_usb_service_reenumerate). */ +void jetkvm_usb_hid_set_pointer_type(jetkvm_usb_hid_pointer_type_t type); +jetkvm_usb_hid_pointer_type_t jetkvm_usb_hid_get_pointer_type(void); + /* * TinyUSB calls this callback from its CPU0 task. The callback must not block * or call a HID report function synchronously. diff --git a/components/jetkvm_usb_hid/jetkvm_usb_hid.c b/components/jetkvm_usb_hid/jetkvm_usb_hid.c index 7e02701d..0ce9e5c5 100644 --- a/components/jetkvm_usb_hid/jetkvm_usb_hid.c +++ b/components/jetkvm_usb_hid/jetkvm_usb_hid.c @@ -219,6 +219,40 @@ static const uint8_t s_absolute_mouse_report_descriptor[] = { 0xc0, /* End Collection */ }; +/* A pen on the screen, as Windows and Linux describe an integrated pen. */ +static const uint8_t s_pen_report_descriptor[] = { + 0x05, 0x0d, /* Usage Page (Digitizer) */ + 0x09, 0x02, /* Usage (Pen) */ + 0xa1, 0x01, /* Collection (Application) */ + 0x85, 0x01, /* Report ID (1) */ + 0x09, 0x20, /* Usage (Stylus) */ + 0xa1, 0x00, /* Collection (Physical) */ + 0x09, 0x42, /* Usage (Tip Switch) */ + 0x09, 0x44, /* Usage (Barrel Switch) */ + 0x09, 0x32, /* Usage (In Range) */ + 0x15, 0x00, /* Logical Minimum (0) */ + 0x25, 0x01, /* Logical Maximum (1) */ + 0x75, 0x01, /* Report Size (1) */ + 0x95, 0x03, /* Report Count (3) */ + 0x81, 0x02, /* Input (Data, Variable, Absolute) */ + 0x95, 0x05, /* Report Count (5) */ + 0x81, 0x03, /* Input (Constant, Variable, Absolute) */ + 0x05, 0x01, /* Usage Page (Generic Desktop) */ + 0x09, 0x30, /* Usage (X) */ + 0x09, 0x31, /* Usage (Y) */ + 0x26, 0xff, 0x7f, /* Logical Maximum (32767) */ + 0x75, 0x10, /* Report Size (16) */ + 0x95, 0x02, /* Report Count (2) */ + 0x81, 0x02, /* Input (Data, Variable, Absolute) */ + 0x05, 0x0d, /* Usage Page (Digitizer) */ + 0x09, 0x30, /* Usage (Tip Pressure) */ + 0x26, 0xff, 0x03, /* Logical Maximum (1023) */ + 0x95, 0x01, /* Report Count (1) */ + 0x81, 0x02, /* Input (Data, Variable, Absolute) */ + 0xc0, /* End Collection */ + 0xc0, /* End Collection */ +}; + static const uint8_t s_relative_mouse_report_descriptor[] = { 0x05, 0x01, /* Usage Page (Generic Desktop) */ 0x09, 0x02, /* Usage (Mouse) */ @@ -297,6 +331,7 @@ typedef struct { uint16_t configuration_length; /* iConfiguration: STRING_CONFIGURATION, or 0 for an empty string. */ uint8_t configuration_string; + bool pen; bool mass_storage; uint8_t mass_storage_string; bool audio; @@ -310,6 +345,8 @@ static hid_descriptor_bank_t s_descriptor_banks[DESCRIPTOR_BANK_COUNT] EXT_RAM_B static uint8_t s_selected_descriptor_bank; static uint8_t s_active_descriptor_bank; static bool s_descriptor_bank_ready; +static jetkvm_usb_hid_pointer_type_t s_pointer_type; +static esp_timer_handle_t s_pen_hover_timer; typedef struct __attribute__((packed)) { uint8_t buttons; @@ -317,6 +354,30 @@ typedef struct __attribute__((packed)) { uint16_t y; } absolute_pointer_report_t; +#define PEN_TIP 0x01U +#define PEN_BARREL 0x02U +#define PEN_IN_RANGE 0x04U +#define PEN_PRESSURE 512U +/* A pen that hovers this long without a report leaves range. */ +#define PEN_HOVER_US (INT64_C(1500) * 1000) +/* A lift that fails is tried again this often, this many times. */ +#define PEN_HOVER_RETRY_US (INT64_C(250) * 1000) +#define PEN_HOVER_RETRIES 4U + +typedef struct __attribute__((packed)) { + uint8_t flags; + uint16_t x; + uint16_t y; + uint16_t pressure; +} pen_report_t; + +static pen_report_t s_pen; +/* When the last pen report was queued, so that a hover callback that waited + * for the report mutex does not end a newer hover. */ +static int64_t s_pen_report_us; +/* Lifts tried again since the hover timer was armed. Under s_state_lock. */ +static uint8_t s_pen_hover_retries; + typedef struct __attribute__((packed)) { int8_t wheel_y; int8_t wheel_x; @@ -764,6 +825,8 @@ static void reset_input_state(void) jetkvm_keyboard_usage_clear(&s_ctx.keyboard_usages); s_ctx.absolute_pointer.buttons = 0; s_ctx.relative_buttons = 0; + s_pen.flags = 0U; + s_pen.pressure = 0U; portEXIT_CRITICAL(&s_state_lock); } @@ -871,7 +934,8 @@ static size_t append_hid_function_descriptor( uint8_t *destination, hid_function_t function, uint8_t interface_number, - uint8_t interval) + uint8_t interval, + bool pen) { switch (function) { case HID_FUNCTION_KEYBOARD: { @@ -888,14 +952,17 @@ static size_t append_hid_function_descriptor( uint8_t descriptor[] = { TUD_HID_DESCRIPTOR( interface_number, STRING_ABSOLUTE_MOUSE, HID_ITF_PROTOCOL_NONE, - sizeof(s_absolute_mouse_report_descriptor), + pen ? sizeof(s_pen_report_descriptor) : + sizeof(s_absolute_mouse_report_descriptor), (0x80U | ENDPOINT_ABSOLUTE_MOUSE), HID_ENDPOINT_SIZE, interval), }; /* Linux configfs exposes the JetKVM absolute pointer as subclass 0, * protocol 2. TinyUSB's descriptor macro couples any non-zero protocol * to boot subclass 1, so set protocol explicitly without changing the * required subclass byte. */ - descriptor[7] = HID_ITF_PROTOCOL_MOUSE; + if (!pen) { + descriptor[7] = HID_ITF_PROTOCOL_MOUSE; + } memcpy(destination, descriptor, sizeof(descriptor)); return sizeof(descriptor); } @@ -945,7 +1012,8 @@ static esp_err_t build_configuration_descriptor( continue; } offset += append_hid_function_descriptor( - destination + offset, function, interface_number, interval); + destination + offset, function, interface_number, interval, + bank->pen); } if (bank->audio) { @@ -1056,6 +1124,7 @@ static esp_err_t build_descriptor_bank( bank->string_storage[STRING_CONFIGURATION][0] != '\0' ? STRING_CONFIGURATION : 0U; + bank->pen = s_pointer_type == JETKVM_USB_HID_POINTER_PEN; bank->configuration_length = TUD_CONFIG_DESC_LEN; for (hid_function_t function = HID_FUNCTION_KEYBOARD; function < HID_FUNCTION_COUNT; ++function) { @@ -1254,6 +1323,8 @@ static void tinyusb_event_callback(tinyusb_event_t *event, void *arg) jetkvm_keyboard_usage_clear(&s_ctx.keyboard_usages); s_ctx.absolute_pointer.buttons = 0; s_ctx.relative_buttons = 0; + s_pen.flags = 0U; + s_pen.pressure = 0U; wake_waiters = true; break; #ifdef CONFIG_TINYUSB_SUSPEND_CALLBACK @@ -1288,13 +1359,38 @@ static void tinyusb_event_callback(tinyusb_event_t *event, void *arg) } } +void jetkvm_usb_hid_set_pointer_type(jetkvm_usb_hid_pointer_type_t type) +{ + portENTER_CRITICAL(&s_state_lock); + s_pointer_type = type; + portEXIT_CRITICAL(&s_state_lock); +} + +static bool pen_active(void) +{ + portENTER_CRITICAL(&s_state_lock); + const bool pen = s_descriptor_bank_ready && + s_descriptor_banks[s_active_descriptor_bank].pen; + portEXIT_CRITICAL(&s_state_lock); + return pen; +} + +jetkvm_usb_hid_pointer_type_t jetkvm_usb_hid_get_pointer_type(void) +{ + portENTER_CRITICAL(&s_state_lock); + const jetkvm_usb_hid_pointer_type_t type = s_pointer_type; + portEXIT_CRITICAL(&s_state_lock); + return type; +} + uint8_t const *tud_hid_descriptor_report_cb(uint8_t instance) { switch (active_function_for_instance(instance)) { case HID_FUNCTION_KEYBOARD: return s_keyboard_report_descriptor; case HID_FUNCTION_ABSOLUTE_MOUSE: - return s_absolute_mouse_report_descriptor; + return pen_active() ? s_pen_report_descriptor : + s_absolute_mouse_report_descriptor; case HID_FUNCTION_RELATIVE_MOUSE: return s_relative_mouse_report_descriptor; case HID_FUNCTION_WAKE: @@ -1993,8 +2089,13 @@ uint16_t tud_hid_get_report_cb(uint8_t instance, report_length = sizeof(report); } else if (function == HID_FUNCTION_ABSOLUTE_MOUSE && report_id == ABSOLUTE_REPORT_ID_POINTER) { - memcpy(report, &s_ctx.absolute_pointer, sizeof(s_ctx.absolute_pointer)); - report_length = sizeof(s_ctx.absolute_pointer); + if (s_descriptor_banks[s_active_descriptor_bank].pen) { + memcpy(report, &s_pen, sizeof(s_pen)); + report_length = sizeof(s_pen); + } else { + memcpy(report, &s_ctx.absolute_pointer, sizeof(s_ctx.absolute_pointer)); + report_length = sizeof(s_ctx.absolute_pointer); + } } else if (function == HID_FUNCTION_ABSOLUTE_MOUSE && report_id == ABSOLUTE_REPORT_ID_WHEEL) { report_length = sizeof(absolute_wheel_report_t); @@ -2727,6 +2828,106 @@ esp_err_t jetkvm_usb_hid_keypress(uint8_t usage, bool pressed) return error; } +static esp_err_t queue_pen_locked(uint8_t instance, uint8_t flags, uint16_t x, + uint16_t y, const report_deadline_t *deadline) +{ + const pen_report_t report = { + .flags = flags, + .x = x, + .y = y, + .pressure = (flags & PEN_TIP) != 0U ? PEN_PRESSURE : 0U, + }; + const esp_err_t error = queue_report_locked( + instance, ABSOLUTE_REPORT_ID_POINTER, &report, sizeof(report), deadline); + if (error == ESP_OK) { + const int64_t now = esp_timer_get_time(); + portENTER_CRITICAL(&s_state_lock); + s_pen = report; + s_pen_report_us = now; + portEXIT_CRITICAL(&s_state_lock); + } + return error; +} + +/* Tries a failed lift again, a few times. The checks of pen_hover_ended() + * still apply, so a retry can't end a newer hover or a press. */ +static void pen_hover_retry(void) +{ + portENTER_CRITICAL(&s_state_lock); + const bool again = s_pen_hover_retries < PEN_HOVER_RETRIES; + if (again) { + s_pen_hover_retries++; + } + portEXIT_CRITICAL(&s_state_lock); + if (again) { + (void)esp_timer_start_once(s_pen_hover_timer, PEN_HOVER_RETRY_US); + } +} + +/* The hover is over: the pen leaves range unless it is pressed. */ +static void pen_hover_ended(void *arg) +{ + (void)arg; + const uint8_t instance = + active_instance_for_function(HID_FUNCTION_ABSOLUTE_MOUSE); + report_deadline_t deadline; + if (!pen_active()) { + return; + } + if (lock_instance(instance, &deadline) != ESP_OK) { + pen_hover_retry(); + return; + } + const int64_t now = esp_timer_get_time(); + portENTER_CRITICAL(&s_state_lock); + const pen_report_t pen = s_pen; + /* A report after the one that armed this timer restarted it. */ + const bool hovered = now - s_pen_report_us >= PEN_HOVER_US; + portEXIT_CRITICAL(&s_state_lock); + esp_err_t error = ESP_OK; + if (pen.flags == PEN_IN_RANGE && hovered) { + error = queue_pen_locked(instance, 0U, pen.x, pen.y, &deadline); + } + xSemaphoreGive(s_report_mutex[instance]); + if (error != ESP_OK) { + pen_hover_retry(); + } +} + +/* A press and a move are in range. A release lifts the pen at once, so that + * the target computer sees it leave; the next move brings it back. */ +static esp_err_t pen_report(uint8_t instance, uint8_t buttons, uint16_t x, + uint16_t y, const report_deadline_t *deadline) +{ + if (s_pen_hover_timer == NULL) { + const esp_timer_create_args_t args = { + .callback = pen_hover_ended, .name = "pen_hover"}; + (void)esp_timer_create(&args, &s_pen_hover_timer); + } + portENTER_CRITICAL(&s_state_lock); + const bool pressed = (s_pen.flags & (PEN_TIP | PEN_BARREL)) != 0U; + portEXIT_CRITICAL(&s_state_lock); + const uint8_t flags = PEN_IN_RANGE | ((buttons & 0x01U) != 0U ? PEN_TIP : 0U) | + /* The right button. */ + ((buttons & 0x02U) != 0U ? PEN_BARREL : 0U); + esp_err_t error = queue_pen_locked(instance, flags, x, y, deadline); + if (error == ESP_OK && pressed && flags == PEN_IN_RANGE) { + report_deadline_t lift_deadline; + report_deadline_start(&lift_deadline); + error = queue_pen_locked(instance, 0U, x, y, &lift_deadline); + } + if (s_pen_hover_timer != NULL) { + (void)esp_timer_stop(s_pen_hover_timer); + if (flags == PEN_IN_RANGE) { + portENTER_CRITICAL(&s_state_lock); + s_pen_hover_retries = 0U; + portEXIT_CRITICAL(&s_state_lock); + (void)esp_timer_start_once(s_pen_hover_timer, PEN_HOVER_US); + } + } + return error; +} + esp_err_t jetkvm_usb_hid_absolute_mouse_report(int32_t x, int32_t y, uint8_t buttons) @@ -2749,8 +2950,10 @@ esp_err_t jetkvm_usb_hid_absolute_mouse_report(int32_t x, record_error(error); return error; } - error = queue_report_locked(instance, ABSOLUTE_REPORT_ID_POINTER, &report, - sizeof(report), &deadline); + error = pen_active() ? + pen_report(instance, report.buttons, report.x, report.y, &deadline) : + queue_report_locked(instance, ABSOLUTE_REPORT_ID_POINTER, &report, + sizeof(report), &deadline); if (error == ESP_OK) { portENTER_CRITICAL(&s_state_lock); s_ctx.absolute_pointer = report; @@ -2785,7 +2988,8 @@ esp_err_t jetkvm_usb_hid_absolute_wheel_report(int8_t wheel_y, esp_err_t jetkvm_usb_hid_wheel_report(int8_t wheel_y, int8_t wheel_x) { - if (active_function_enabled(HID_FUNCTION_ABSOLUTE_MOUSE)) { + /* A pen has no wheel: the relative mouse scrolls. */ + if (active_function_enabled(HID_FUNCTION_ABSOLUTE_MOUSE) && !pen_active()) { return jetkvm_usb_hid_absolute_wheel_report(wheel_y, wheel_x); } if (active_function_enabled(HID_FUNCTION_RELATIVE_MOUSE)) { diff --git a/components/jetkvm_usb_hid/tests/test_relative_wheel_buttons.py b/components/jetkvm_usb_hid/tests/test_relative_wheel_buttons.py index 79734bd0..15b186cd 100644 --- a/components/jetkvm_usb_hid/tests/test_relative_wheel_buttons.py +++ b/components/jetkvm_usb_hid/tests/test_relative_wheel_buttons.py @@ -81,6 +81,8 @@ def function(source, name): sent_count++; return ESP_OK; } +/* An absolute mouse, not the pen. */ +static bool pen_active(void) { return false; } static esp_err_t jetkvm_usb_hid_absolute_wheel_report(int8_t y, int8_t x) { (void)y; diff --git a/components/webrtc_transport/rpc_worker.c b/components/webrtc_transport/rpc_worker.c index ea6ba14c..c19be95e 100644 --- a/components/webrtc_transport/rpc_worker.c +++ b/components/webrtc_transport/rpc_worker.c @@ -37,6 +37,7 @@ static const struct { { "factoryReset", QUEUE_CONTROL }, { "deregisterDevice", QUEUE_CONTROL }, { "setUsbEmulationState", QUEUE_CONTROL }, + { "setPointerType", QUEUE_CONTROL }, { "checkMountUrl", QUEUE_MEDIA }, { "mountWithHTTP", QUEUE_MEDIA }, { "mountWithStorage", QUEUE_MEDIA }, @@ -272,6 +273,7 @@ static void run_job(rpc_job_t *job, rpc_queue_t queue) .deregister_device = deregister, .deregister_device_ctx = job, .guest_clipboard = jetkvm_control_default_guest_clipboard_context(), + .pointer = jetkvm_control_default_pointer_context(), .guest_file = jetkvm_control_default_guest_file_context(), /* Input of a cloud session does not keep the local login. */ .note_local_activity = job->cloud_authority ? NULL : jetkvm_access_note_activity, @@ -393,6 +395,7 @@ bool rpc_worker_defer(const uint8_t *input, size_t length, } bool reset = strcmp(name, "factoryReset") == 0; bool cloud = strcmp(name, "deregisterDevice") == 0; + bool pointer = strcmp(name, "setPointerType") == 0; rpc_job_t *job = jetkvm_memory_policy_control_alloc(sizeof(*job) + length + 1U); if (!job) return false; memset(job, 0, sizeof(*job)); @@ -437,9 +440,10 @@ bool rpc_worker_defer(const uint8_t *input, size_t length, (void)xSemaphoreGive(s_job_added[queue]); return true; } - /* Reset persists its intent directly to NVS, and deregistration clears - * the cloud configuration there. Flash writes disable cache, so those - * requests must execute on an internal-RAM stack. The control queue holds + /* Reset persists its intent directly to NVS, deregistration clears the + * cloud configuration there, and the pointer type is saved there. Flash + * writes disable cache, so those requests must execute on an + * internal-RAM stack. The control queue holds * one job, so its worker runs only the request it was started for. The * media worker's larger stack covers the exFAT format and HTTPS paths the * peer task ran; the USB owner, not this task, writes the USB @@ -447,9 +451,9 @@ bool rpc_worker_defer(const uint8_t *input, size_t length, * the control worker's, covers the dispatcher, cJSON's parse and print * (16 levels deep at most) and the wait for the OS Services sender; the * request, the clipboard text and the reply are on the heap. */ - unsigned stack_caps = (reset || cloud ? MALLOC_CAP_INTERNAL : MALLOC_CAP_SPIRAM) | MALLOC_CAP_8BIT; + unsigned stack_caps = (reset || cloud || pointer ? MALLOC_CAP_INTERNAL : MALLOC_CAP_SPIRAM) | MALLOC_CAP_8BIT; const char *task_name = reset ? "jk_reset_rpc" : cloud ? "jk_cloud_rpc" : - queue == QUEUE_MEDIA ? "jk_media_rpc" : queue == QUEUE_GUEST ? "jk_guest_rpc" : + pointer ? "jk_pointer_rpc" : queue == QUEUE_MEDIA ? "jk_media_rpc" : queue == QUEUE_GUEST ? "jk_guest_rpc" : queue == QUEUE_MQTT ? "jk_mqtt_rpc" : queue == QUEUE_UPDATE ? "jk_update_rpc" : "jk_control"; /* The MQTT test holds the candidate settings three times over (request, @@ -652,6 +656,13 @@ static bool update_components_not_admitted(const char *app_constraint, return update_status_not_admitted(status, ctx); } +static const char *pointer_not_admitted(const char *type, void *ctx) +{ + (void)type; (void)ctx; + return queue_busy(QUEUE_CONTROL) ? "Another control operation is in progress; try again" + : "Pointer type change could not start"; +} + static const char *file_drop_not_admitted(const cJSON *files, cJSON *result, void *ctx) { (void)files; (void)result; (void)ctx; @@ -675,6 +686,7 @@ void rpc_worker_peer_fallbacks(jetkvm_control_context_t *context) context->storage_download.start = download_not_admitted; context->factory_reset = NULL; context->deregister_device = NULL; + context->pointer = (jetkvm_pointer_context_t){ .set = pointer_not_admitted }; context->guest_clipboard = (jetkvm_guest_clipboard_context_t){ .get = clipboard_get_not_admitted, .set = clipboard_set_not_admitted, diff --git a/components/webrtc_transport/tests/rpc_worker/test_job.c b/components/webrtc_transport/tests/rpc_worker/test_job.c index bd585bbb..02837798 100644 --- a/components/webrtc_transport/tests/rpc_worker/test_job.c +++ b/components/webrtc_transport/tests/rpc_worker/test_job.c @@ -34,7 +34,8 @@ int xTaskCreateWithCaps(void (*fn)(void *), const char *name, uint32_t stack, { (void)stack; (void)priority; (void)handle; /* Requests that write flash run on an internal-RAM stack. */ - bool writes_flash = !strcmp(name, "jk_reset_rpc") || !strcmp(name, "jk_cloud_rpc"); + bool writes_flash = !strcmp(name, "jk_reset_rpc") || !strcmp(name, "jk_cloud_rpc") || + !strcmp(name, "jk_pointer_rpc"); assert(caps == ((writes_flash ? MALLOC_CAP_INTERNAL : MALLOC_CAP_SPIRAM) | MALLOC_CAP_8BIT)); last_task = name; if (create_fails) return 0; @@ -80,6 +81,8 @@ jetkvm_control_result_t jetkvm_control_handle_rpc_with_context( if (strstr((const char *)input, "setUsbEmulationState")) { error = context->usb_configuration.set_emulation_enabled(false, NULL) == JETKVM_USB_EMULATION_CHANGE_ACCEPTED ? NULL : "failed"; + } else if (strstr((const char *)input, "setPointerType")) { + error = NULL; } else if (strstr((const char *)input, "factoryReset")) { error = context->factory_reset(context->factory_reset_ctx); } else error = context->deregister_device(context->deregister_device_ctx); @@ -136,6 +139,10 @@ jetkvm_guest_file_context_t jetkvm_control_default_guest_file_context(void) { return (jetkvm_guest_file_context_t){ 0 }; } +jetkvm_pointer_context_t jetkvm_control_default_pointer_context(void) +{ + return (jetkvm_pointer_context_t){ 0 }; +} bool jetkvm_access_lock_epoch(uint32_t epoch) { return epoch == 1; } void jetkvm_access_unlock(void) {} void jetkvm_access_note_activity(void) {} @@ -148,8 +155,14 @@ static bool control_busy(void) { jetkvm_control_context_t peer = {0}; rpc_worker_peer_fallbacks(&peer); - return peer.usb_configuration.set_emulation_enabled(false, NULL) == + const bool busy = peer.usb_configuration.set_emulation_enabled(false, NULL) == JETKVM_USB_EMULATION_CHANGE_BUSY; + /* Inline, a pointer type change only reports why it did not run. */ + assert(peer.pointer.set && !peer.pointer.get); + assert(!strcmp(peer.pointer.set("pen", NULL), busy ? + "Another control operation is in progress; try again" : + "Pointer type change could not start")); + return busy; } static bool enqueue(void) { @@ -251,6 +264,11 @@ int main(void) assert(!strcmp(reply.json, failure ? "err" : "ok")); assert(!reply.publish_deregistration && published == 4); } + const char pointer_request[] = "{\"id\":3,\"method\":\"setPointerType\",\"params\":{\"type\":\"pen\"}}"; + assert(rpc_worker_defer((const uint8_t *)pointer_request, strlen(pointer_request), &origin)); + assert(!strcmp(last_task, "jk_pointer_rpc")); /* saves to NVS: not the PSRAM stack */ + complete(); + assert(rpc_worker_take_reply(&reply) && !strcmp(reply.json, "ok")); assert(control_arena_blocks == 0); puts("Cloud/USB worker completion, failure and session lifecycle tests passed"); } diff --git a/frontend/jetkvm-ui/localization/messages/en.json b/frontend/jetkvm-ui/localization/messages/en.json index 95ce40e8..c87f25de 100644 --- a/frontend/jetkvm-ui/localization/messages/en.json +++ b/frontend/jetkvm-ui/localization/messages/en.json @@ -903,6 +903,9 @@ "mouse_jiggler_title": "Jiggler", "mouse_mode_absolute": "Absolute", "mouse_mode_absolute_description": "Most convenient", + "mouse_mode_android": "Android", + "mouse_mode_android_description": "Exact position. Your device sees a pen.", + "mouse_mode_failed": "Failed to change the mouse mode: {error}", "mouse_mode_relative": "Relative", "mouse_mode_relative_description": "Most compatible", "mouse_modes_description": "Choose the mouse input mode", diff --git a/frontend/jetkvm-ui/src/hooks/stores.ts b/frontend/jetkvm-ui/src/hooks/stores.ts index e7a95e4a..1b53ddcb 100644 --- a/frontend/jetkvm-ui/src/hooks/stores.ts +++ b/frontend/jetkvm-ui/src/hooks/stores.ts @@ -930,6 +930,7 @@ export type Capability = | "tailscale" // Tailscale client | "os_services" // USB link to the OS Services sender on the remote host (clipboard, file drop, shell) | "display_buttons" // side buttons wake the local display + | "pointer_types" // the device can present a pen instead of the absolute mouse | "usb_debugging" // the USB debugging switch (the Mini's USB Serial/JTAG port) | "extra_hostnames" // other host names the web server answers to (getExtraHostnames) | "storage_download" // device downloads an image from a URL into its storage diff --git a/frontend/jetkvm-ui/src/hooks/usePointerType.ts b/frontend/jetkvm-ui/src/hooks/usePointerType.ts new file mode 100644 index 00000000..7441c2f2 --- /dev/null +++ b/frontend/jetkvm-ui/src/hooks/usePointerType.ts @@ -0,0 +1,81 @@ +import { useCallback, useEffect } from "react"; +import { create } from "zustand"; + +import { JsonRpcResponse, useJsonRpc } from "@hooks/useJsonRpc"; +import { useCapability, useRTCStore } from "@hooks/stores"; + +// What the target gets from absolute positions: the absolute mouse, or a pen +// (Android). The device stores it. +export type PointerType = "mouse" | "pen"; + +interface PointerState { + pointerType: PointerType; + // The channel of a change that has no reply yet. A reply can only come on + // it, so after a reconnect the change no longer waits. + changingOn: RTCDataChannel | null; + setPointerType: (pointerType: PointerType) => void; + setChangingOn: (channel: RTCDataChannel | null) => void; +} + +export const usePointerStore = create(set => ({ + pointerType: "mouse", + changingOn: null, + setPointerType: pointerType => set({ pointerType }), + setChangingOn: changingOn => set({ changingOn }), +})); + +export function usePointerType() { + const { send } = useJsonRpc(); + const hasPointerTypes = useCapability("pointer_types"); + const rpcDataChannel = useRTCStore(state => state.rpcDataChannel); + const { pointerType, changingOn, setPointerType, setChangingOn } = usePointerStore(); + const changing = changingOn !== null && changingOn === rpcDataChannel; + + // Calls done once the read has a reply, or when it could not be sent. + const readPointerType = useCallback( + async (done?: () => void) => { + const sent = await send("getPointerType", {}, (resp: JsonRpcResponse) => { + if (!("error" in resp)) setPointerType(resp.result as PointerType); + done?.(); + }); + if (!sent) done?.(); + }, + [send, setPointerType], + ); + + useEffect(() => { + if (hasPointerTypes) void readPointerType(); + else setPointerType("mouse"); + }, [hasPointerTypes, rpcDataChannel, readPointerType, setPointerType]); + + // One change at a time, so that the last choice is the one that stays. + const changePointerType = useCallback( + async (type: PointerType, onError: (error: string) => void) => { + if (!rpcDataChannel) return onError("not connected"); + if (usePointerStore.getState().changingOn === rpcDataChannel) return; + const channel = rpcDataChannel; + // After a reconnect, a change on the new channel is not this one. + const done = () => { + if (usePointerStore.getState().changingOn === channel) setChangingOn(null); + }; + setChangingOn(channel); + const sent = await send("setPointerType", { type }, (resp: JsonRpcResponse) => { + if ("error" in resp) { + // The device can have stored the type and then failed to apply it, + // so the next change waits until the type is read again. + void readPointerType(done); + return onError(String(resp.error.data ?? resp.error.message)); + } + setPointerType(resp.result as PointerType); + done(); + }); + if (!sent) { + done(); + onError("not connected"); + } + }, + [readPointerType, rpcDataChannel, send, setChangingOn, setPointerType], + ); + + return { hasPointerTypes, pointerType, changing, changePointerType }; +} diff --git a/frontend/jetkvm-ui/src/routes/devices.$id.settings.mouse.tsx b/frontend/jetkvm-ui/src/routes/devices.$id.settings.mouse.tsx index 44cc3c91..0d77012e 100644 --- a/frontend/jetkvm-ui/src/routes/devices.$id.settings.mouse.tsx +++ b/frontend/jetkvm-ui/src/routes/devices.$id.settings.mouse.tsx @@ -6,6 +6,7 @@ import MouseIcon from "@assets/mouse-icon.svg"; import PointingFinger from "@assets/pointing-finger.svg"; import { JsonRpcResponse, useJsonRpc } from "@hooks/useJsonRpc"; import { useSettingsStore } from "@hooks/stores"; +import { type PointerType, usePointerType } from "@hooks/usePointerType"; import { GridCard } from "@components/Card"; import { Checkbox } from "@components/Checkbox"; import { SelectMenuBasic } from "@components/SelectMenuBasic"; @@ -60,6 +61,16 @@ const jigglerOptions = [ }, ] as const; +interface MouseModeOption { + id: string; + // The device's pointer type. The relative mode has none. + pointerType?: PointerType; + title: string; + description: string; + icon: string; + alt: string; +} + type JigglerValues = (typeof jigglerOptions)[number]["value"] | "custom"; export default function SettingsMouseRoute() { @@ -180,6 +191,50 @@ export default function SettingsMouseRoute() { saveJigglerConfig(jigglerConfig); }; + const { hasPointerTypes, pointerType, changing, changePointerType } = usePointerType(); + + const finger = { icon: PointingFinger, alt: m.mouse_alt_finger() }; + const modes: MouseModeOption[] = [ + { + id: "absolute", + pointerType: "mouse", + title: m.mouse_mode_absolute(), + description: m.mouse_mode_absolute_description(), + ...finger, + }, + { + id: "relative", + title: m.mouse_mode_relative(), + description: m.mouse_mode_relative_description(), + icon: MouseIcon, + alt: m.mouse_alt_mouse(), + }, + ]; + if (hasPointerTypes) { + modes.push({ + id: "android", + pointerType: "pen", + title: m.mouse_mode_android(), + description: m.mouse_mode_android_description(), + ...finger, + }); + } + + const isSelected = (mode: MouseModeOption) => + mode.pointerType + ? mouseMode === "absolute" && pointerType === mode.pointerType + : mouseMode === "relative"; + + const selectMode = (mode: MouseModeOption) => { + setMouseMode(mode.pointerType ? "absolute" : "relative"); + // The selected type is sent as well. The device ignores it, unless the + // last change could not reconnect USB: then it tries again. + if (!mode.pointerType || !hasPointerTypes) return; + void changePointerType(mode.pointerType, error => + notifications.error(m.mouse_mode_failed({ error })), + ); + }; + return (
@@ -245,71 +300,39 @@ export default function SettingsMouseRoute() { )}
-
- -
- - + + + ))}
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 37d38f88..24567da7 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -3,7 +3,7 @@ set(_jetkvm_main_priv_requires jetkvm_board_network jetkvm_c5_wifi jetkvm_cloud_service jetkvm_factory_reset jetkvm_flash_read_mode jetkvm_device_state jetkvm_hid_input jetkvm_hid_profiles jetkvm_hdmi_bridge jetkvm_mdns jetkvm_memory_owners jetkvm_memory_policy - jetkvm_mqtt jetkvm_network_settings jetkvm_oidc jetkvm_os_services jetkvm_ota jetkvm_screen jetkvm_settings + jetkvm_mqtt jetkvm_network_settings jetkvm_oidc jetkvm_os_services jetkvm_ota jetkvm_pointer jetkvm_screen jetkvm_settings jetkvm_time_sync jetkvm_tailscale jetkvm_usb_debugging jetkvm_usb_hid jetkvm_usb_service jetkvm_video jetkvm_video_quality jetkvm_virtual_media jetkvm_wol esp_app_format esp_driver_gpio esp_system diff --git a/main/main.c b/main/main.c index 409f4534..cccd83da 100644 --- a/main/main.c +++ b/main/main.c @@ -57,6 +57,7 @@ #include "jetkvm_ota.h" #include "jetkvm_settings.h" #include "jetkvm_time_sync.h" +#include "jetkvm_pointer.h" #include "jetkvm_usb_debugging.h" #include "jetkvm_usb_hid.h" #include "jetkvm_usb_service.h" @@ -1268,6 +1269,8 @@ void app_main(void) p4_device_set_usb_wake_available(false); p4_device_set_usb_configuration_available(false); #if !P4_SKIP_TARGET_USB_DIAGNOSTIC + /* Before USB starts: the pointer type selects the descriptor. */ + jetkvm_pointer_start(); ret = jetkvm_audio_init(); if (ret != ESP_OK) { ESP_LOGW(TAG, "Optional audio unavailable: %s", esp_err_to_name(ret));