Compare commits
2 Commits
922494beb2
...
dfe01e2958
Author | SHA1 | Date |
---|---|---|
Colin | dfe01e2958 | |
梁鸿 | 0f3e2187ab |
|
@ -15,14 +15,14 @@ const config_t default_config = {
|
|||
},
|
||||
.screen_count = 1,
|
||||
.screen_index = 1,
|
||||
.os = OUTPUT_A_OS,
|
||||
// .os = OUTPUT_A_OS,
|
||||
.pos = RIGHT,
|
||||
.screensaver = {
|
||||
.mode = SCREENSAVER_A_MODE,
|
||||
.only_if_inactive = SCREENSAVER_A_ONLY_IF_INACTIVE,
|
||||
.idle_time_us = SCREENSAVER_A_IDLE_TIME_SEC * 1000000,
|
||||
.max_time_us = SCREENSAVER_A_MAX_TIME_SEC * 1000000,
|
||||
}
|
||||
// .screensaver = {
|
||||
// .mode = SCREENSAVER_A_MODE,
|
||||
// .only_if_inactive = SCREENSAVER_A_ONLY_IF_INACTIVE,
|
||||
// .idle_time_us = SCREENSAVER_A_IDLE_TIME_SEC * 1000000,
|
||||
// .max_time_us = SCREENSAVER_A_MAX_TIME_SEC * 1000000,
|
||||
// }
|
||||
},
|
||||
.output[OUTPUT_B] =
|
||||
{
|
||||
|
@ -35,14 +35,14 @@ const config_t default_config = {
|
|||
},
|
||||
.screen_count = 1,
|
||||
.screen_index = 1,
|
||||
.os = OUTPUT_B_OS,
|
||||
// .os = OUTPUT_B_OS,
|
||||
.pos = LEFT,
|
||||
.screensaver = {
|
||||
.mode = SCREENSAVER_B_MODE,
|
||||
.only_if_inactive = SCREENSAVER_B_ONLY_IF_INACTIVE,
|
||||
.idle_time_us = SCREENSAVER_B_IDLE_TIME_SEC * 1000000,
|
||||
.max_time_us = SCREENSAVER_B_MAX_TIME_SEC * 1000000,
|
||||
}
|
||||
// .screensaver = {
|
||||
// .mode = SCREENSAVER_B_MODE,
|
||||
// .only_if_inactive = SCREENSAVER_B_ONLY_IF_INACTIVE,
|
||||
// .idle_time_us = SCREENSAVER_B_IDLE_TIME_SEC * 1000000,
|
||||
// .max_time_us = SCREENSAVER_B_MAX_TIME_SEC * 1000000,
|
||||
// }
|
||||
},
|
||||
.enforce_ports = ENFORCE_PORTS,
|
||||
.force_kbd_boot_protocol = ENFORCE_KEYBOARD_BOOT_PROTOCOL,
|
||||
|
|
246
src/handlers.c
246
src/handlers.c
|
@ -24,8 +24,8 @@
|
|||
/* This is the main hotkey for switching outputs */
|
||||
void output_toggle_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
/* If switching explicitly disabled, return immediately */
|
||||
if (state->switch_lock)
|
||||
return;
|
||||
// if (state->switch_lock)
|
||||
// return;
|
||||
|
||||
state->active_output ^= 1;
|
||||
switch_output(state, state->active_output);
|
||||
|
@ -39,115 +39,115 @@ void _get_border_position(device_t *state, border_size_t *border) {
|
|||
border->top = state->pointer_y;
|
||||
}
|
||||
|
||||
void _screensaver_set(device_t *state, uint8_t value) {
|
||||
if (CURRENT_BOARD_IS_ACTIVE_OUTPUT)
|
||||
state->config.output[BOARD_ROLE].screensaver.mode = value;
|
||||
else
|
||||
send_value(value, SCREENSAVER_MSG);
|
||||
};
|
||||
// void _screensaver_set(device_t *state, uint8_t value) {
|
||||
// if (CURRENT_BOARD_IS_ACTIVE_OUTPUT)
|
||||
// state->config.output[BOARD_ROLE].screensaver.mode = value;
|
||||
// else
|
||||
// send_value(value, SCREENSAVER_MSG);
|
||||
// };
|
||||
|
||||
/* This key combo records switch y top coordinate for different-size monitors */
|
||||
void screen_border_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
border_size_t *border = &state->config.output[state->active_output].border;
|
||||
if (CURRENT_BOARD_IS_ACTIVE_OUTPUT) {
|
||||
_get_border_position(state, border);
|
||||
save_config(state);
|
||||
}
|
||||
// /* This key combo records switch y top coordinate for different-size monitors */
|
||||
// void screen_border_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// border_size_t *border = &state->config.output[state->active_output].border;
|
||||
// if (CURRENT_BOARD_IS_ACTIVE_OUTPUT) {
|
||||
// _get_border_position(state, border);
|
||||
// save_config(state);
|
||||
// }
|
||||
|
||||
queue_packet((uint8_t *)border, SYNC_BORDERS_MSG, sizeof(border_size_t));
|
||||
};
|
||||
// queue_packet((uint8_t *)border, SYNC_BORDERS_MSG, sizeof(border_size_t));
|
||||
// };
|
||||
|
||||
/* This key combo puts board A in firmware upgrade mode */
|
||||
void fw_upgrade_hotkey_handler_A(device_t *state, hid_keyboard_report_t *report) {
|
||||
reset_usb_boot(1 << PICO_DEFAULT_LED_PIN, 0);
|
||||
};
|
||||
// /* This key combo puts board A in firmware upgrade mode */
|
||||
// void fw_upgrade_hotkey_handler_A(device_t *state, hid_keyboard_report_t *report) {
|
||||
// reset_usb_boot(1 << PICO_DEFAULT_LED_PIN, 0);
|
||||
// };
|
||||
|
||||
/* This key combo puts board B in firmware upgrade mode */
|
||||
void fw_upgrade_hotkey_handler_B(device_t *state, hid_keyboard_report_t *report) {
|
||||
send_value(ENABLE, FIRMWARE_UPGRADE_MSG);
|
||||
};
|
||||
// /* This key combo puts board B in firmware upgrade mode */
|
||||
// void fw_upgrade_hotkey_handler_B(device_t *state, hid_keyboard_report_t *report) {
|
||||
// send_value(ENABLE, FIRMWARE_UPGRADE_MSG);
|
||||
// };
|
||||
|
||||
/* This key combo prevents mouse from switching outputs */
|
||||
void switchlock_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
state->switch_lock ^= 1;
|
||||
send_value(state->switch_lock, SWITCH_LOCK_MSG);
|
||||
}
|
||||
// /* This key combo prevents mouse from switching outputs */
|
||||
// void switchlock_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// state->switch_lock ^= 1;
|
||||
// send_value(state->switch_lock, SWITCH_LOCK_MSG);
|
||||
// }
|
||||
|
||||
/* This key combo toggles gaming mode */
|
||||
void toggle_gaming_mode_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
state->gaming_mode ^= 1;
|
||||
send_value(state->gaming_mode, GAMING_MODE_MSG);
|
||||
};
|
||||
// /* This key combo toggles gaming mode */
|
||||
// void toggle_gaming_mode_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// state->gaming_mode ^= 1;
|
||||
// send_value(state->gaming_mode, GAMING_MODE_MSG);
|
||||
// };
|
||||
|
||||
/* This key combo locks both outputs simultaneously */
|
||||
void screenlock_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
hid_keyboard_report_t lock_report = {0}, release_keys = {0};
|
||||
// /* This key combo locks both outputs simultaneously */
|
||||
// void screenlock_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// hid_keyboard_report_t lock_report = {0}, release_keys = {0};
|
||||
|
||||
for (int out = 0; out < NUM_SCREENS; out++) {
|
||||
switch (state->config.output[out].os) {
|
||||
case WINDOWS:
|
||||
case LINUX:
|
||||
lock_report.modifier = KEYBOARD_MODIFIER_LEFTGUI;
|
||||
lock_report.keycode[0] = HID_KEY_L;
|
||||
break;
|
||||
case MACOS:
|
||||
lock_report.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_LEFTGUI;
|
||||
lock_report.keycode[0] = HID_KEY_Q;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// for (int out = 0; out < NUM_SCREENS; out++) {
|
||||
// switch (state->config.output[out].os) {
|
||||
// case WINDOWS:
|
||||
// case LINUX:
|
||||
// lock_report.modifier = KEYBOARD_MODIFIER_LEFTGUI;
|
||||
// lock_report.keycode[0] = HID_KEY_L;
|
||||
// break;
|
||||
// case MACOS:
|
||||
// lock_report.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_LEFTGUI;
|
||||
// lock_report.keycode[0] = HID_KEY_Q;
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
|
||||
if (BOARD_ROLE == out) {
|
||||
queue_kbd_report(&lock_report, state);
|
||||
release_all_keys(state);
|
||||
} else {
|
||||
queue_packet((uint8_t *)&lock_report, KEYBOARD_REPORT_MSG, KBD_REPORT_LENGTH);
|
||||
queue_packet((uint8_t *)&release_keys, KEYBOARD_REPORT_MSG, KBD_REPORT_LENGTH);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (BOARD_ROLE == out) {
|
||||
// queue_kbd_report(&lock_report, state);
|
||||
// release_all_keys(state);
|
||||
// } else {
|
||||
// queue_packet((uint8_t *)&lock_report, KEYBOARD_REPORT_MSG, KBD_REPORT_LENGTH);
|
||||
// queue_packet((uint8_t *)&release_keys, KEYBOARD_REPORT_MSG, KBD_REPORT_LENGTH);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/* When pressed, erases stored config in flash and loads defaults on both boards */
|
||||
void wipe_config_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
wipe_config();
|
||||
load_config(state);
|
||||
send_value(ENABLE, WIPE_CONFIG_MSG);
|
||||
}
|
||||
// /* When pressed, erases stored config in flash and loads defaults on both boards */
|
||||
// void wipe_config_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// wipe_config();
|
||||
// load_config(state);
|
||||
// send_value(ENABLE, WIPE_CONFIG_MSG);
|
||||
// }
|
||||
|
||||
/* When pressed, toggles the current mouse zoom mode state */
|
||||
void mouse_zoom_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
state->mouse_zoom ^= 1;
|
||||
send_value(state->mouse_zoom, MOUSE_ZOOM_MSG);
|
||||
};
|
||||
// /* When pressed, toggles the current mouse zoom mode state */
|
||||
// void mouse_zoom_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// state->mouse_zoom ^= 1;
|
||||
// send_value(state->mouse_zoom, MOUSE_ZOOM_MSG);
|
||||
// };
|
||||
|
||||
/* When pressed, enables the screensaver on active output */
|
||||
void enable_screensaver_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
uint8_t desired_mode = state->config.output[BOARD_ROLE].screensaver.mode;
|
||||
// /* When pressed, enables the screensaver on active output */
|
||||
// void enable_screensaver_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// uint8_t desired_mode = state->config.output[BOARD_ROLE].screensaver.mode;
|
||||
|
||||
/* If the user explicitly asks for screensaver to be active, ignore config and turn it on */
|
||||
if (desired_mode == DISABLED)
|
||||
desired_mode = PONG;
|
||||
// /* If the user explicitly asks for screensaver to be active, ignore config and turn it on */
|
||||
// if (desired_mode == DISABLED)
|
||||
// desired_mode = PONG;
|
||||
|
||||
_screensaver_set(state, desired_mode);
|
||||
}
|
||||
// _screensaver_set(state, desired_mode);
|
||||
// }
|
||||
|
||||
/* When pressed, disables the screensaver on active output */
|
||||
void disable_screensaver_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
_screensaver_set(state, DISABLED);
|
||||
}
|
||||
// /* When pressed, disables the screensaver on active output */
|
||||
// void disable_screensaver_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// _screensaver_set(state, DISABLED);
|
||||
// }
|
||||
|
||||
/* Put the device into a special configuration mode */
|
||||
void config_enable_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
/* If config mode is already active, skip this and reboot to return to normal mode */
|
||||
if (!state->config_mode_active) {
|
||||
watchdog_hw->scratch[5] = MAGIC_WORD_1;
|
||||
watchdog_hw->scratch[6] = MAGIC_WORD_2;
|
||||
}
|
||||
// /* Put the device into a special configuration mode */
|
||||
// void config_enable_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// /* If config mode is already active, skip this and reboot to return to normal mode */
|
||||
// if (!state->config_mode_active) {
|
||||
// watchdog_hw->scratch[5] = MAGIC_WORD_1;
|
||||
// watchdog_hw->scratch[6] = MAGIC_WORD_2;
|
||||
// }
|
||||
|
||||
release_all_keys(state);
|
||||
state->reboot_requested = true;
|
||||
};
|
||||
// release_all_keys(state);
|
||||
// state->reboot_requested = true;
|
||||
// };
|
||||
|
||||
|
||||
/**==================================================== *
|
||||
|
@ -181,15 +181,15 @@ void handle_output_select_msg(uart_packet_t *packet, device_t *state) {
|
|||
restore_leds(state);
|
||||
}
|
||||
|
||||
/* On firmware upgrade message, reboot into the BOOTSEL fw upgrade mode */
|
||||
void handle_fw_upgrade_msg(uart_packet_t *packet, device_t *state) {
|
||||
reset_usb_boot(1 << PICO_DEFAULT_LED_PIN, 0);
|
||||
}
|
||||
// /* On firmware upgrade message, reboot into the BOOTSEL fw upgrade mode */
|
||||
// void handle_fw_upgrade_msg(uart_packet_t *packet, device_t *state) {
|
||||
// reset_usb_boot(1 << PICO_DEFAULT_LED_PIN, 0);
|
||||
// }
|
||||
|
||||
/* Comply with request to turn mouse zoom mode on/off */
|
||||
void handle_mouse_zoom_msg(uart_packet_t *packet, device_t *state) {
|
||||
state->mouse_zoom = packet->data[0];
|
||||
}
|
||||
// /* Comply with request to turn mouse zoom mode on/off */
|
||||
// void handle_mouse_zoom_msg(uart_packet_t *packet, device_t *state) {
|
||||
// state->mouse_zoom = packet->data[0];
|
||||
// }
|
||||
|
||||
/* Process request to update keyboard LEDs */
|
||||
void handle_set_report_msg(uart_packet_t *packet, device_t *state) {
|
||||
|
@ -201,10 +201,10 @@ void handle_set_report_msg(uart_packet_t *packet, device_t *state) {
|
|||
restore_leds(state);
|
||||
}
|
||||
|
||||
/* Process request to block mouse from switching, update internal state */
|
||||
void handle_switch_lock_msg(uart_packet_t *packet, device_t *state) {
|
||||
state->switch_lock = packet->data[0];
|
||||
}
|
||||
// /* Process request to block mouse from switching, update internal state */
|
||||
// void handle_switch_lock_msg(uart_packet_t *packet, device_t *state) {
|
||||
// state->switch_lock = packet->data[0];
|
||||
// }
|
||||
|
||||
/* Handle border syncing message that lets the other device know about monitor height offset */
|
||||
void handle_sync_borders_msg(uart_packet_t *packet, device_t *state) {
|
||||
|
@ -224,16 +224,16 @@ void handle_flash_led_msg(uart_packet_t *packet, device_t *state) {
|
|||
blink_led(state);
|
||||
}
|
||||
|
||||
/* When this message is received, wipe the local flash config */
|
||||
void handle_wipe_config_msg(uart_packet_t *packet, device_t *state) {
|
||||
wipe_config();
|
||||
load_config(state);
|
||||
}
|
||||
// /* When this message is received, wipe the local flash config */
|
||||
// void handle_wipe_config_msg(uart_packet_t *packet, device_t *state) {
|
||||
// wipe_config();
|
||||
// load_config(state);
|
||||
// }
|
||||
|
||||
/* Update screensaver state after received message */
|
||||
void handle_screensaver_msg(uart_packet_t *packet, device_t *state) {
|
||||
state->config.output[BOARD_ROLE].screensaver.mode = packet->data[0];
|
||||
}
|
||||
// /* Update screensaver state after received message */
|
||||
// void handle_screensaver_msg(uart_packet_t *packet, device_t *state) {
|
||||
// state->config.output[BOARD_ROLE].screensaver.mode = packet->data[0];
|
||||
// }
|
||||
|
||||
/* Process consumer control message */
|
||||
void handle_consumer_control_msg(uart_packet_t *packet, device_t *state) {
|
||||
|
@ -255,10 +255,10 @@ void handle_proxy_msg(uart_packet_t *packet, device_t *state) {
|
|||
queue_packet(&packet->data[1], (enum packet_type_e)packet->data[0], PACKET_DATA_LENGTH - 1);
|
||||
}
|
||||
|
||||
/* Process relative mouse command */
|
||||
void handle_toggle_gaming_msg(uart_packet_t *packet, device_t *state) {
|
||||
state->gaming_mode = packet->data[0];
|
||||
}
|
||||
// /* Process relative mouse command */
|
||||
// void handle_toggle_gaming_msg(uart_packet_t *packet, device_t *state) {
|
||||
// state->gaming_mode = packet->data[0];
|
||||
// }
|
||||
|
||||
/* Process api communication messages */
|
||||
void handle_api_msgs(uart_packet_t *packet, device_t *state) {
|
||||
|
@ -320,7 +320,7 @@ void handle_response_byte_msg(uart_packet_t *packet, device_t *state) {
|
|||
uint32_t address = packet->data32[0];
|
||||
|
||||
if (address != state->fw.address) {
|
||||
state->fw.upgrade_in_progress = false;
|
||||
// state->fw.upgrade_in_progress = false;
|
||||
state->fw.address = 0;
|
||||
return;
|
||||
}
|
||||
|
@ -339,15 +339,15 @@ void handle_response_byte_msg(uart_packet_t *packet, device_t *state) {
|
|||
|
||||
/* Neeeeeeext byte, please! */
|
||||
state->fw.address += sizeof(uint32_t);
|
||||
state->fw.byte_done = true;
|
||||
// state->fw.byte_done = true;
|
||||
}
|
||||
|
||||
/* Process a request to read a firmware package from flash */
|
||||
void handle_heartbeat_msg(uart_packet_t *packet, device_t *state) {
|
||||
uint16_t other_running_version = packet->data16[0];
|
||||
|
||||
if (state->fw.upgrade_in_progress)
|
||||
return;
|
||||
// if (state->fw.upgrade_in_progress)
|
||||
// return;
|
||||
|
||||
/* If the other board isn't running a newer version, we are done */
|
||||
if (other_running_version <= state->_running_fw.version)
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
#define TOUCH 2
|
||||
|
||||
#define MOUSE_BOOT_REPORT_LEN 4
|
||||
#define MOUSE_ZOOM_SCALING_FACTOR 2
|
||||
// #define MOUSE_ZOOM_SCALING_FACTOR 2
|
||||
#define NUM_SCREENS 2 // Will be more in the future
|
||||
#define CONFIG_MODE_TIMEOUT 300000000 // 5 minutes into the future
|
||||
|
||||
|
@ -116,16 +116,16 @@ enum packet_type_e {
|
|||
KEYBOARD_REPORT_MSG = 1,
|
||||
MOUSE_REPORT_MSG = 2,
|
||||
OUTPUT_SELECT_MSG = 3,
|
||||
FIRMWARE_UPGRADE_MSG = 4,
|
||||
MOUSE_ZOOM_MSG = 5,
|
||||
// FIRMWARE_UPGRADE_MSG = 4,
|
||||
// MOUSE_ZOOM_MSG = 5,
|
||||
KBD_SET_REPORT_MSG = 6,
|
||||
SWITCH_LOCK_MSG = 7,
|
||||
// SWITCH_LOCK_MSG = 7,
|
||||
SYNC_BORDERS_MSG = 8,
|
||||
FLASH_LED_MSG = 9,
|
||||
WIPE_CONFIG_MSG = 10,
|
||||
SCREENSAVER_MSG = 11,
|
||||
// WIPE_CONFIG_MSG = 10,
|
||||
// SCREENSAVER_MSG = 11,
|
||||
HEARTBEAT_MSG = 12,
|
||||
GAMING_MODE_MSG = 13,
|
||||
// GAMING_MODE_MSG = 13,
|
||||
CONSUMER_CONTROL_MSG = 14,
|
||||
SYSTEM_CONTROL_MSG = 15,
|
||||
SAVE_CONFIG_MSG = 18,
|
||||
|
@ -205,12 +205,12 @@ enum screen_pos_e {
|
|||
MIDDLE = 3,
|
||||
};
|
||||
|
||||
enum screensaver_mode_e {
|
||||
DISABLED = 0,
|
||||
PONG = 1,
|
||||
JITTER = 2,
|
||||
MAX_SS_VAL = JITTER,
|
||||
};
|
||||
// enum screensaver_mode_e {
|
||||
// DISABLED = 0,
|
||||
// PONG = 1,
|
||||
// JITTER = 2,
|
||||
// MAX_SS_VAL = JITTER,
|
||||
// };
|
||||
|
||||
#define ITF_NUM_HID 0
|
||||
#define ITF_NUM_HID_REL_M 1
|
||||
|
@ -223,13 +223,13 @@ typedef struct {
|
|||
// height
|
||||
} border_size_t;
|
||||
|
||||
/* Define screensaver parameters */
|
||||
typedef struct {
|
||||
uint8_t mode;
|
||||
uint8_t only_if_inactive;
|
||||
uint64_t idle_time_us;
|
||||
uint64_t max_time_us;
|
||||
} screensaver_t;
|
||||
// /* Define screensaver parameters */
|
||||
// typedef struct {
|
||||
// uint8_t mode;
|
||||
// uint8_t only_if_inactive;
|
||||
// uint64_t idle_time_us;
|
||||
// uint64_t max_time_us;
|
||||
// } screensaver_t;
|
||||
|
||||
/* Define output parameters */
|
||||
typedef struct {
|
||||
|
@ -242,7 +242,7 @@ typedef struct {
|
|||
uint8_t os; // Operating system on this output
|
||||
uint8_t pos; // Screen position on this output
|
||||
uint8_t mouse_park_pos; // Where the mouse goes after switch
|
||||
screensaver_t screensaver; // Screensaver parameters for this output
|
||||
// screensaver_t screensaver; // Screensaver parameters for this output
|
||||
} output_t;
|
||||
|
||||
/* Data structure defining how configuration is stored */
|
||||
|
@ -422,11 +422,11 @@ typedef struct {
|
|||
bool keyboard_connected; // True when our keyboard is connected locally
|
||||
|
||||
/* Feature flags */
|
||||
bool mouse_zoom; // True when "mouse zoom" is enabled
|
||||
bool switch_lock; // True when device is prevented from switching
|
||||
// bool mouse_zoom; // True when "mouse zoom" is enabled
|
||||
// bool switch_lock; // True when device is prevented from switching
|
||||
bool onboard_led_state; // True when LED is ON
|
||||
bool relative_mouse; // True when relative mouse mode is used
|
||||
bool gaming_mode; // True when gaming mode is on (relative passthru + lock)
|
||||
// bool gaming_mode; // True when gaming mode is on (relative passthru + lock)
|
||||
bool config_mode_active; // True when config mode is active
|
||||
bool digitizer_active; // True when digitizer Win/Mac workaround is active
|
||||
|
||||
|
@ -509,8 +509,8 @@ void usb_device_task(device_t *);
|
|||
void kick_watchdog_task(device_t *);
|
||||
void usb_host_task(device_t *);
|
||||
void packet_receiver_task(device_t *);
|
||||
void screensaver_task(device_t *);
|
||||
void firmware_upgrade_task(device_t *);
|
||||
// void screensaver_task(device_t *);
|
||||
// void firmware_upgrade_task(device_t *);
|
||||
void heartbeat_output_task(device_t *);
|
||||
void led_blinking_task(device_t *);
|
||||
|
||||
|
@ -519,7 +519,7 @@ void task_scheduler(device_t *, task_t *);
|
|||
/********* Configuration **********/
|
||||
void load_config(device_t *);
|
||||
void save_config(device_t *);
|
||||
void wipe_config(void);
|
||||
// void wipe_config(void);
|
||||
void reset_config_timer(device_t *);
|
||||
|
||||
extern const field_map_t api_field_map[];
|
||||
|
@ -531,30 +531,30 @@ void queue_cfg_packet(uart_packet_t *, device_t *);
|
|||
|
||||
/********* Handlers **********/
|
||||
void output_toggle_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void screen_border_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void fw_upgrade_hotkey_handler_A(device_t *, hid_keyboard_report_t *);
|
||||
void fw_upgrade_hotkey_handler_B(device_t *, hid_keyboard_report_t *);
|
||||
void mouse_zoom_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void all_keys_released_handler(device_t *);
|
||||
void switchlock_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void toggle_gaming_mode_handler(device_t *, hid_keyboard_report_t *);
|
||||
void screenlock_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void output_config_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void wipe_config_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void config_enable_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void enable_screensaver_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void disable_screensaver_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void screen_border_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void fw_upgrade_hotkey_handler_A(device_t *, hid_keyboard_report_t *);
|
||||
// void fw_upgrade_hotkey_handler_B(device_t *, hid_keyboard_report_t *);
|
||||
// void mouse_zoom_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void all_keys_released_handler(device_t *);
|
||||
// void switchlock_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void toggle_gaming_mode_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void screenlock_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void output_config_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void wipe_config_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void config_enable_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void enable_screensaver_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void disable_screensaver_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
|
||||
void handle_keyboard_uart_msg(uart_packet_t *, device_t *);
|
||||
void handle_mouse_abs_uart_msg(uart_packet_t *, device_t *);
|
||||
void handle_output_select_msg(uart_packet_t *, device_t *);
|
||||
void handle_mouse_zoom_msg(uart_packet_t *, device_t *);
|
||||
// void handle_mouse_zoom_msg(uart_packet_t *, device_t *);
|
||||
void handle_set_report_msg(uart_packet_t *, device_t *);
|
||||
void handle_switch_lock_msg(uart_packet_t *, device_t *);
|
||||
// void handle_switch_lock_msg(uart_packet_t *, device_t *);
|
||||
void handle_sync_borders_msg(uart_packet_t *, device_t *);
|
||||
void handle_flash_led_msg(uart_packet_t *, device_t *);
|
||||
void handle_fw_upgrade_msg(uart_packet_t *, device_t *);
|
||||
void handle_wipe_config_msg(uart_packet_t *, device_t *);
|
||||
// void handle_fw_upgrade_msg(uart_packet_t *, device_t *);
|
||||
// void handle_wipe_config_msg(uart_packet_t *, device_t *);
|
||||
void handle_consumer_control_msg(uart_packet_t *, device_t *);
|
||||
void handle_read_config_msg(uart_packet_t *, device_t *);
|
||||
void handle_save_config_msg(uart_packet_t *, device_t *);
|
||||
|
@ -567,7 +567,7 @@ void handle_proxy_msg(uart_packet_t *, device_t *);
|
|||
void handle_api_msgs(uart_packet_t *, device_t *);
|
||||
void handle_api_read_all_msg(uart_packet_t *, device_t *);
|
||||
void handle_toggle_gaming_msg(uart_packet_t *, device_t *);
|
||||
void handle_screensaver_msg(uart_packet_t *, device_t *);
|
||||
// void handle_screensaver_msg(uart_packet_t *, device_t *);
|
||||
|
||||
void switch_output(device_t *, uint8_t);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
*
|
||||
* */
|
||||
|
||||
#define HOTKEY_TOGGLE HID_KEY_CAPS_LOCK
|
||||
#define HOTKEY_TOGGLE KEYBOARD_MODIFIER_RIGHTSHIFT
|
||||
|
||||
/**================================================== *
|
||||
* ============== Mouse Speed Factor ============== *
|
||||
|
@ -113,8 +113,8 @@
|
|||
*
|
||||
**/
|
||||
|
||||
#define SCREENSAVER_A_MODE DISABLED
|
||||
#define SCREENSAVER_B_MODE DISABLED
|
||||
// #define SCREENSAVER_A_MODE DISABLED
|
||||
// #define SCREENSAVER_B_MODE DISABLED
|
||||
|
||||
/**================================================== *
|
||||
*
|
||||
|
@ -123,8 +123,8 @@
|
|||
*
|
||||
**/
|
||||
|
||||
#define SCREENSAVER_A_IDLE_TIME_SEC 240
|
||||
#define SCREENSAVER_B_IDLE_TIME_SEC 240
|
||||
// #define SCREENSAVER_A_IDLE_TIME_SEC 240
|
||||
// #define SCREENSAVER_B_IDLE_TIME_SEC 240
|
||||
|
||||
/**================================================== *
|
||||
*
|
||||
|
@ -133,8 +133,8 @@
|
|||
*
|
||||
**/
|
||||
|
||||
#define SCREENSAVER_A_MAX_TIME_SEC 0
|
||||
#define SCREENSAVER_B_MAX_TIME_SEC 0
|
||||
// #define SCREENSAVER_A_MAX_TIME_SEC 0
|
||||
// #define SCREENSAVER_B_MAX_TIME_SEC 0
|
||||
|
||||
/**================================================== *
|
||||
*
|
||||
|
@ -143,8 +143,8 @@
|
|||
*
|
||||
**/
|
||||
|
||||
#define SCREENSAVER_A_ONLY_IF_INACTIVE 0
|
||||
#define SCREENSAVER_B_ONLY_IF_INACTIVE 0
|
||||
// #define SCREENSAVER_A_ONLY_IF_INACTIVE 0
|
||||
// #define SCREENSAVER_B_ONLY_IF_INACTIVE 0
|
||||
|
||||
/**================================================== *
|
||||
* ================ Output OS Config =============== *
|
||||
|
@ -160,8 +160,8 @@
|
|||
*
|
||||
* */
|
||||
|
||||
#define OUTPUT_A_OS MACOS
|
||||
#define OUTPUT_B_OS LINUX
|
||||
// #define OUTPUT_A_OS MACOS
|
||||
// #define OUTPUT_B_OS LINUX
|
||||
|
||||
|
||||
/**================================================== *
|
||||
|
|
138
src/keyboard.c
138
src/keyboard.c
|
@ -23,89 +23,89 @@
|
|||
|
||||
hotkey_combo_t hotkeys[] = {
|
||||
/* Main keyboard switching hotkey */
|
||||
{.modifier = KEYBOARD_MODIFIER_LEFTCTRL,
|
||||
{.modifier = KEYBOARD_MODIFIER_RIGHTCTRL,
|
||||
.keys = {HOTKEY_TOGGLE},
|
||||
.key_count = 1,
|
||||
.pass_to_os = false,
|
||||
.action_handler = &output_toggle_hotkey_handler},
|
||||
.action_handler = &output_toggle_hotkey_handler}};
|
||||
|
||||
/* Pressing right ALT + right CTRL toggles the slow mouse mode */
|
||||
{.modifier = KEYBOARD_MODIFIER_RIGHTALT | KEYBOARD_MODIFIER_RIGHTCTRL,
|
||||
.keys = {},
|
||||
.key_count = 0,
|
||||
.pass_to_os = true,
|
||||
.acknowledge = true,
|
||||
.action_handler = &mouse_zoom_hotkey_handler},
|
||||
// /* Pressing right ALT + right CTRL toggles the slow mouse mode */
|
||||
// {.modifier = KEYBOARD_MODIFIER_RIGHTALT | KEYBOARD_MODIFIER_RIGHTCTRL,
|
||||
// .keys = {},
|
||||
// .key_count = 0,
|
||||
// .pass_to_os = true,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &mouse_zoom_hotkey_handler},
|
||||
|
||||
/* Switch lock */
|
||||
{.modifier = KEYBOARD_MODIFIER_RIGHTCTRL,
|
||||
.keys = {HID_KEY_K},
|
||||
.key_count = 1,
|
||||
.acknowledge = true,
|
||||
.action_handler = &switchlock_hotkey_handler},
|
||||
// /* Switch lock */
|
||||
// {.modifier = KEYBOARD_MODIFIER_RIGHTCTRL,
|
||||
// .keys = {HID_KEY_K},
|
||||
// .key_count = 1,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &switchlock_hotkey_handler},
|
||||
|
||||
/* Screen lock */
|
||||
{.modifier = KEYBOARD_MODIFIER_RIGHTCTRL,
|
||||
.keys = {HID_KEY_L},
|
||||
.key_count = 1,
|
||||
.acknowledge = true,
|
||||
.action_handler = &screenlock_hotkey_handler},
|
||||
// /* Screen lock */
|
||||
// {.modifier = KEYBOARD_MODIFIER_RIGHTCTRL,
|
||||
// .keys = {HID_KEY_L},
|
||||
// .key_count = 1,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &screenlock_hotkey_handler},
|
||||
|
||||
/* Toggle gaming mode */
|
||||
{.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
.keys = {HID_KEY_G},
|
||||
.key_count = 1,
|
||||
.acknowledge = true,
|
||||
.action_handler = &toggle_gaming_mode_handler},
|
||||
// /* Toggle gaming mode */
|
||||
// {.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
// .keys = {HID_KEY_G},
|
||||
// .key_count = 1,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &toggle_gaming_mode_handler},
|
||||
|
||||
/* Enable screensaver for active output */
|
||||
{.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
.keys = {HID_KEY_S},
|
||||
.key_count = 1,
|
||||
.acknowledge = true,
|
||||
.action_handler = &enable_screensaver_hotkey_handler},
|
||||
// /* Enable screensaver for active output */
|
||||
// {.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
// .keys = {HID_KEY_S},
|
||||
// .key_count = 1,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &enable_screensaver_hotkey_handler},
|
||||
|
||||
/* Disable screensaver for active output */
|
||||
{.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
.keys = {HID_KEY_X},
|
||||
.key_count = 1,
|
||||
.acknowledge = true,
|
||||
.action_handler = &disable_screensaver_hotkey_handler},
|
||||
// /* Disable screensaver for active output */
|
||||
// {.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
// .keys = {HID_KEY_X},
|
||||
// .key_count = 1,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &disable_screensaver_hotkey_handler},
|
||||
|
||||
/* Erase stored config */
|
||||
{.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
.keys = {HID_KEY_F12, HID_KEY_D},
|
||||
.key_count = 2,
|
||||
.acknowledge = true,
|
||||
.action_handler = &wipe_config_hotkey_handler},
|
||||
// /* Erase stored config */
|
||||
// {.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
// .keys = {HID_KEY_F12, HID_KEY_D},
|
||||
// .key_count = 2,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &wipe_config_hotkey_handler},
|
||||
|
||||
/* Record switch y coordinate */
|
||||
{.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
.keys = {HID_KEY_F12, HID_KEY_Y},
|
||||
.key_count = 2,
|
||||
.acknowledge = true,
|
||||
.action_handler = &screen_border_hotkey_handler},
|
||||
// /* Record switch y coordinate */
|
||||
// {.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
// .keys = {HID_KEY_F12, HID_KEY_Y},
|
||||
// .key_count = 2,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &screen_border_hotkey_handler},
|
||||
|
||||
/* Switch to configuration mode */
|
||||
{.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
.keys = {HID_KEY_C, HID_KEY_O},
|
||||
.key_count = 2,
|
||||
.acknowledge = true,
|
||||
.action_handler = &config_enable_hotkey_handler},
|
||||
// /* Switch to configuration mode */
|
||||
// {.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
// .keys = {HID_KEY_C, HID_KEY_O},
|
||||
// .key_count = 2,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &config_enable_hotkey_handler},
|
||||
|
||||
/* Hold down left shift + right shift + F12 + A ==> firmware upgrade mode for board A (kbd) */
|
||||
{.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT | KEYBOARD_MODIFIER_LEFTSHIFT,
|
||||
.keys = {HID_KEY_A},
|
||||
.key_count = 1,
|
||||
.acknowledge = true,
|
||||
.action_handler = &fw_upgrade_hotkey_handler_A},
|
||||
// /* Hold down left shift + right shift + F12 + A ==> firmware upgrade mode for board A (kbd) */
|
||||
// {.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT | KEYBOARD_MODIFIER_LEFTSHIFT,
|
||||
// .keys = {HID_KEY_A},
|
||||
// .key_count = 1,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &fw_upgrade_hotkey_handler_A},
|
||||
|
||||
/* Hold down left shift + right shift + F12 + B ==> firmware upgrade mode for board B (mouse) */
|
||||
{.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT | KEYBOARD_MODIFIER_LEFTSHIFT,
|
||||
.keys = {HID_KEY_B},
|
||||
.key_count = 1,
|
||||
.acknowledge = true,
|
||||
.action_handler = &fw_upgrade_hotkey_handler_B}};
|
||||
// /* Hold down left shift + right shift + F12 + B ==> firmware upgrade mode for board B (mouse) */
|
||||
// {.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT | KEYBOARD_MODIFIER_LEFTSHIFT,
|
||||
// .keys = {HID_KEY_B},
|
||||
// .key_count = 1,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &fw_upgrade_hotkey_handler_B}};
|
||||
|
||||
/* ============================================================ *
|
||||
* Detect if any hotkeys were pressed
|
||||
|
|
|
@ -60,8 +60,8 @@ void core1_main() {
|
|||
[0] = {.exec = &usb_host_task, .frequency = _TOP()}, // .-> USB host task, needs to run as often as possible
|
||||
[1] = {.exec = &packet_receiver_task, .frequency = _TOP()}, // | Receive data over serial from the other board
|
||||
[2] = {.exec = &led_blinking_task, .frequency = _HZ(30)}, // | Check if LED needs blinking
|
||||
[3] = {.exec = &screensaver_task, .frequency = _HZ(120)}, // | Handle "screensaver" movements
|
||||
[4] = {.exec = &firmware_upgrade_task, .frequency = _HZ(4000)}, // | Send firmware to the other board if needed
|
||||
// [3] = {.exec = &screensaver_task, .frequency = _HZ(120)}, // | Handle "screensaver" movements
|
||||
// [4] = {.exec = &firmware_upgrade_task, .frequency = _HZ(4000)}, // | Send firmware to the other board if needed
|
||||
[5] = {.exec = &heartbeat_output_task, .frequency = _HZ(1)}, // | Output periodic heartbeats
|
||||
}; // `----- then go back and repeat forever
|
||||
const int NUM_TASKS = ARRAY_SIZE(tasks_core1);
|
||||
|
|
24
src/mouse.c
24
src/mouse.c
|
@ -67,9 +67,9 @@ void update_mouse_position(device_t *state, mouse_values_t *values) {
|
|||
output_t *current = &state->config.output[state->active_output];
|
||||
uint8_t reduce_speed = 0;
|
||||
|
||||
/* Check if we are configured to move slowly */
|
||||
if (state->mouse_zoom)
|
||||
reduce_speed = MOUSE_ZOOM_SCALING_FACTOR;
|
||||
// /* Check if we are configured to move slowly */
|
||||
// if (state->mouse_zoom)
|
||||
// reduce_speed = MOUSE_ZOOM_SCALING_FACTOR;
|
||||
|
||||
/* Calculate movement */
|
||||
int offset_x = accelerate(values->move_x) * (current->speed_x >> reduce_speed);
|
||||
|
@ -191,9 +191,9 @@ void check_screen_switch(const mouse_values_t *values, device_t *state) {
|
|||
|
||||
int direction = jump_left ? LEFT : RIGHT;
|
||||
|
||||
/* No switching allowed if explicitly disabled or in gaming mode */
|
||||
if (state->switch_lock || state->gaming_mode)
|
||||
return;
|
||||
// /* No switching allowed if explicitly disabled or in gaming mode */
|
||||
// if (state->switch_lock)
|
||||
// return;
|
||||
|
||||
/* No jump condition met == nothing to do, return */
|
||||
if (!jump_left && !jump_right)
|
||||
|
@ -252,12 +252,12 @@ mouse_report_t create_mouse_report(device_t *state, mouse_values_t *values) {
|
|||
.mode = ABSOLUTE,
|
||||
};
|
||||
|
||||
/* Workaround for Windows multiple desktops */
|
||||
if (state->relative_mouse || state->gaming_mode) {
|
||||
mouse_report.x = values->move_x;
|
||||
mouse_report.y = values->move_y;
|
||||
mouse_report.mode = RELATIVE;
|
||||
}
|
||||
// /* Workaround for Windows multiple desktops */
|
||||
// if (state->relative_mouse || state->gaming_mode) {
|
||||
// mouse_report.x = values->move_x;
|
||||
// mouse_report.y = values->move_y;
|
||||
// mouse_report.mode = RELATIVE;
|
||||
// }
|
||||
|
||||
return mouse_report;
|
||||
}
|
||||
|
|
|
@ -14,15 +14,15 @@ const field_map_t api_field_map[] = {
|
|||
{ 13, false, INT32, 4, offsetof(device_t, config.output[0].speed_y) },
|
||||
{ 14, false, INT32, 4, offsetof(device_t, config.output[0].border.top) },
|
||||
{ 15, false, INT32, 4, offsetof(device_t, config.output[0].border.bottom) },
|
||||
{ 16, false, UINT8, 1, offsetof(device_t, config.output[0].os) },
|
||||
// { 16, false, UINT8, 1, offsetof(device_t, config.output[0].os) },
|
||||
{ 17, false, UINT8, 1, offsetof(device_t, config.output[0].pos) },
|
||||
{ 18, false, UINT8, 1, offsetof(device_t, config.output[0].mouse_park_pos) },
|
||||
{ 19, false, UINT8, 1, offsetof(device_t, config.output[0].screensaver.mode) },
|
||||
{ 20, false, UINT8, 1, offsetof(device_t, config.output[0].screensaver.only_if_inactive) },
|
||||
// { 19, false, UINT8, 1, offsetof(device_t, config.output[0].screensaver.mode) },
|
||||
// { 20, false, UINT8, 1, offsetof(device_t, config.output[0].screensaver.only_if_inactive) },
|
||||
|
||||
/* Until we increase the payload size from 8 bytes, clamp to avoid exceeding the field size */
|
||||
{ 21, false, UINT64, 7, offsetof(device_t, config.output[0].screensaver.idle_time_us) },
|
||||
{ 22, false, UINT64, 7, offsetof(device_t, config.output[0].screensaver.max_time_us) },
|
||||
// { 21, false, UINT64, 7, offsetof(device_t, config.output[0].screensaver.idle_time_us) },
|
||||
// { 22, false, UINT64, 7, offsetof(device_t, config.output[0].screensaver.max_time_us) },
|
||||
|
||||
/* Output B */
|
||||
{ 40, false, UINT32, 4, offsetof(device_t, config.output[1].number) },
|
||||
|
@ -31,13 +31,13 @@ const field_map_t api_field_map[] = {
|
|||
{ 43, false, INT32, 4, offsetof(device_t, config.output[1].speed_y) },
|
||||
{ 44, false, INT32, 4, offsetof(device_t, config.output[1].border.top) },
|
||||
{ 45, false, INT32, 4, offsetof(device_t, config.output[1].border.bottom) },
|
||||
{ 46, false, UINT8, 1, offsetof(device_t, config.output[1].os) },
|
||||
// { 46, false, UINT8, 1, offsetof(device_t, config.output[1].os) },
|
||||
{ 47, false, UINT8, 1, offsetof(device_t, config.output[1].pos) },
|
||||
{ 48, false, UINT8, 1, offsetof(device_t, config.output[1].mouse_park_pos) },
|
||||
{ 49, false, UINT8, 1, offsetof(device_t, config.output[1].screensaver.mode) },
|
||||
{ 50, false, UINT8, 1, offsetof(device_t, config.output[1].screensaver.only_if_inactive) },
|
||||
{ 51, false, UINT64, 7, offsetof(device_t, config.output[1].screensaver.idle_time_us) },
|
||||
{ 52, false, UINT64, 7, offsetof(device_t, config.output[1].screensaver.max_time_us) },
|
||||
// { 49, false, UINT8, 1, offsetof(device_t, config.output[1].screensaver.mode) },
|
||||
// { 50, false, UINT8, 1, offsetof(device_t, config.output[1].screensaver.only_if_inactive) },
|
||||
// { 51, false, UINT64, 7, offsetof(device_t, config.output[1].screensaver.idle_time_us) },
|
||||
// { 52, false, UINT64, 7, offsetof(device_t, config.output[1].screensaver.max_time_us) },
|
||||
|
||||
/* Common config */
|
||||
{ 70, false, UINT32, 4, offsetof(device_t, config.version) },
|
||||
|
@ -54,7 +54,7 @@ const field_map_t api_field_map[] = {
|
|||
{ 79, true, UINT32, 4, offsetof(device_t, _running_fw.checksum) },
|
||||
|
||||
{ 80, true, UINT8, 1, offsetof(device_t, keyboard_connected) },
|
||||
{ 81, true, UINT8, 1, offsetof(device_t, switch_lock) },
|
||||
// { 81, true, UINT8, 1, offsetof(device_t, switch_lock) },
|
||||
{ 82, true, UINT8, 1, offsetof(device_t, relative_mouse) },
|
||||
};
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t *
|
|||
global_state.fw.checksum = 0xffffffff;
|
||||
|
||||
/* Make sure nobody else touches the flash during this operation, otherwise we get empty pages */
|
||||
global_state.fw.upgrade_in_progress = true;
|
||||
// global_state.fw.upgrade_in_progress = true;
|
||||
}
|
||||
|
||||
/* Update checksum continuously as blocks are being received */
|
||||
|
|
184
src/tasks.c
184
src/tasks.c
|
@ -59,92 +59,92 @@ void usb_host_task(device_t *state) {
|
|||
tuh_task();
|
||||
}
|
||||
|
||||
mouse_report_t *screensaver_pong(device_t *state) {
|
||||
static mouse_report_t report = {0};
|
||||
static int dx = 20, dy = 25;
|
||||
// mouse_report_t *screensaver_pong(device_t *state) {
|
||||
// static mouse_report_t report = {0};
|
||||
// static int dx = 20, dy = 25;
|
||||
|
||||
/* Check if we are bouncing off the walls and reverse direction in that case. */
|
||||
if (report.x + dx < MIN_SCREEN_COORD || report.x + dx > MAX_SCREEN_COORD)
|
||||
dx = -dx;
|
||||
// /* Check if we are bouncing off the walls and reverse direction in that case. */
|
||||
// if (report.x + dx < MIN_SCREEN_COORD || report.x + dx > MAX_SCREEN_COORD)
|
||||
// dx = -dx;
|
||||
|
||||
if (report.y + dy < MIN_SCREEN_COORD || report.y + dy > MAX_SCREEN_COORD)
|
||||
dy = -dy;
|
||||
// if (report.y + dy < MIN_SCREEN_COORD || report.y + dy > MAX_SCREEN_COORD)
|
||||
// dy = -dy;
|
||||
|
||||
report.x += dx;
|
||||
report.y += dy;
|
||||
// report.x += dx;
|
||||
// report.y += dy;
|
||||
|
||||
return &report;
|
||||
}
|
||||
// return &report;
|
||||
// }
|
||||
|
||||
mouse_report_t *screensaver_jitter(device_t *state) {
|
||||
const int16_t jitter_distance = 2;
|
||||
static mouse_report_t report = {
|
||||
.y = jitter_distance,
|
||||
.mode = RELATIVE,
|
||||
};
|
||||
report.y = -report.y;
|
||||
// mouse_report_t *screensaver_jitter(device_t *state) {
|
||||
// const int16_t jitter_distance = 2;
|
||||
// static mouse_report_t report = {
|
||||
// .y = jitter_distance,
|
||||
// .mode = RELATIVE,
|
||||
// };
|
||||
// report.y = -report.y;
|
||||
|
||||
return &report;
|
||||
}
|
||||
// return &report;
|
||||
// }
|
||||
|
||||
/* Have something fun and entertaining when idle. */
|
||||
void screensaver_task(device_t *state) {
|
||||
const uint32_t delays[] = {
|
||||
0, /* DISABLED, unused index 0 */
|
||||
5000, /* PONG, move mouse every 5 ms for a high framerate */
|
||||
10000000, /* JITTER, once every 10 sec is more than enough */
|
||||
};
|
||||
static int last_pointer_move = 0;
|
||||
screensaver_t *screensaver = &state->config.output[BOARD_ROLE].screensaver;
|
||||
uint64_t inactivity_period = time_us_64() - state->last_activity[BOARD_ROLE];
|
||||
// /* Have something fun and entertaining when idle. */
|
||||
// void screensaver_task(device_t *state) {
|
||||
// const uint32_t delays[] = {
|
||||
// 0, /* DISABLED, unused index 0 */
|
||||
// 5000, /* PONG, move mouse every 5 ms for a high framerate */
|
||||
// 10000000, /* JITTER, once every 10 sec is more than enough */
|
||||
// };
|
||||
// static int last_pointer_move = 0;
|
||||
// screensaver_t *screensaver = &state->config.output[BOARD_ROLE].screensaver;
|
||||
// uint64_t inactivity_period = time_us_64() - state->last_activity[BOARD_ROLE];
|
||||
|
||||
/* If we're not enabled, nothing to do here. */
|
||||
if (screensaver->mode == DISABLED)
|
||||
return;
|
||||
// /* If we're not enabled, nothing to do here. */
|
||||
// if (screensaver->mode == DISABLED)
|
||||
// return;
|
||||
|
||||
/* System is still not idle for long enough to activate or screensaver mode is not supported */
|
||||
if (inactivity_period < screensaver->idle_time_us || screensaver->mode > MAX_SS_VAL)
|
||||
return;
|
||||
// /* System is still not idle for long enough to activate or screensaver mode is not supported */
|
||||
// if (inactivity_period < screensaver->idle_time_us || screensaver->mode > MAX_SS_VAL)
|
||||
// return;
|
||||
|
||||
/* We exceeded the maximum permitted screensaver runtime */
|
||||
if (screensaver->max_time_us
|
||||
&& inactivity_period > (screensaver->max_time_us + screensaver->idle_time_us))
|
||||
return;
|
||||
// /* We exceeded the maximum permitted screensaver runtime */
|
||||
// if (screensaver->max_time_us
|
||||
// && inactivity_period > (screensaver->max_time_us + screensaver->idle_time_us))
|
||||
// return;
|
||||
|
||||
/* If we're the selected output and we can only run on inactive output, nothing to do here. */
|
||||
if (screensaver->only_if_inactive && CURRENT_BOARD_IS_ACTIVE_OUTPUT)
|
||||
return;
|
||||
// /* If we're the selected output and we can only run on inactive output, nothing to do here. */
|
||||
// if (screensaver->only_if_inactive && CURRENT_BOARD_IS_ACTIVE_OUTPUT)
|
||||
// return;
|
||||
|
||||
/* We're active! Now check if it's time to move the cursor yet. */
|
||||
if (time_us_32() - last_pointer_move < delays[screensaver->mode])
|
||||
return;
|
||||
// /* We're active! Now check if it's time to move the cursor yet. */
|
||||
// if (time_us_32() - last_pointer_move < delays[screensaver->mode])
|
||||
// return;
|
||||
|
||||
mouse_report_t *report;
|
||||
switch (screensaver->mode) {
|
||||
case PONG:
|
||||
report = screensaver_pong(state);
|
||||
break;
|
||||
// mouse_report_t *report;
|
||||
// switch (screensaver->mode) {
|
||||
// case PONG:
|
||||
// report = screensaver_pong(state);
|
||||
// break;
|
||||
|
||||
case JITTER:
|
||||
report = screensaver_jitter(state);
|
||||
break;
|
||||
// case JITTER:
|
||||
// report = screensaver_jitter(state);
|
||||
// break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
// default:
|
||||
// return;
|
||||
// }
|
||||
|
||||
/* Move mouse pointer */
|
||||
queue_mouse_report(report, state);
|
||||
// /* Move mouse pointer */
|
||||
// queue_mouse_report(report, state);
|
||||
|
||||
/* Update timer of the last pointer move */
|
||||
last_pointer_move = time_us_32();
|
||||
}
|
||||
// /* Update timer of the last pointer move */
|
||||
// last_pointer_move = time_us_32();
|
||||
// }
|
||||
|
||||
/* Periodically emit heartbeat packets */
|
||||
void heartbeat_output_task(device_t *state) {
|
||||
/* If firmware upgrade is in progress, don't touch flash_cs */
|
||||
if (state->fw.upgrade_in_progress)
|
||||
return;
|
||||
// if (state->fw.upgrade_in_progress)
|
||||
// return;
|
||||
|
||||
if (state->config_mode_active) {
|
||||
/* Leave config mode if timeout expired and user didn't click exit */
|
||||
|
@ -191,40 +191,40 @@ void process_hid_queue_task(device_t *state) {
|
|||
queue_try_remove(&state->hid_queue_out, &packet);
|
||||
}
|
||||
|
||||
/* Task that handles copying firmware from the other device to ours */
|
||||
void firmware_upgrade_task(device_t *state) {
|
||||
if (!state->fw.upgrade_in_progress || !state->fw.byte_done)
|
||||
return;
|
||||
// /* Task that handles copying firmware from the other device to ours */
|
||||
// void firmware_upgrade_task(device_t *state) {
|
||||
// if (!state->fw.upgrade_in_progress || !state->fw.byte_done)
|
||||
// return;
|
||||
|
||||
if (queue_is_full(&state->uart_tx_queue))
|
||||
return;
|
||||
// if (queue_is_full(&state->uart_tx_queue))
|
||||
// return;
|
||||
|
||||
/* End condition, when reached the process is completed. */
|
||||
if (state->fw.address > STAGING_IMAGE_SIZE) {
|
||||
state->fw.upgrade_in_progress = 0;
|
||||
state->fw.checksum = ~state->fw.checksum;
|
||||
// /* End condition, when reached the process is completed. */
|
||||
// if (state->fw.address > STAGING_IMAGE_SIZE) {
|
||||
// state->fw.upgrade_in_progress = 0;
|
||||
// state->fw.checksum = ~state->fw.checksum;
|
||||
|
||||
/* Checksum mismatch, we wipe the stage 2 bootloader and rely on ROM recovery */
|
||||
if(calculate_firmware_crc32() != state->fw.checksum) {
|
||||
flash_range_erase((uint32_t)ADDR_FW_RUNNING - XIP_BASE, FLASH_SECTOR_SIZE);
|
||||
reset_usb_boot(1 << PICO_DEFAULT_LED_PIN, 0);
|
||||
}
|
||||
// /* Checksum mismatch, we wipe the stage 2 bootloader and rely on ROM recovery */
|
||||
// if(calculate_firmware_crc32() != state->fw.checksum) {
|
||||
// flash_range_erase((uint32_t)ADDR_FW_RUNNING - XIP_BASE, FLASH_SECTOR_SIZE);
|
||||
// reset_usb_boot(1 << PICO_DEFAULT_LED_PIN, 0);
|
||||
// }
|
||||
|
||||
else {
|
||||
state->_running_fw = _firmware_metadata;
|
||||
global_state.reboot_requested = true;
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// state->_running_fw = _firmware_metadata;
|
||||
// global_state.reboot_requested = true;
|
||||
// }
|
||||
// }
|
||||
|
||||
/* If we're on the last element of the current page, page is done - write it. */
|
||||
if (TU_U32_BYTE0(state->fw.address) == 0x00) {
|
||||
// /* If we're on the last element of the current page, page is done - write it. */
|
||||
// if (TU_U32_BYTE0(state->fw.address) == 0x00) {
|
||||
|
||||
uint32_t page_start_addr = (state->fw.address - 1) & 0xFFFFFF00;
|
||||
write_flash_page((uint32_t)ADDR_FW_RUNNING + page_start_addr - XIP_BASE, state->page_buffer);
|
||||
}
|
||||
// uint32_t page_start_addr = (state->fw.address - 1) & 0xFFFFFF00;
|
||||
// write_flash_page((uint32_t)ADDR_FW_RUNNING + page_start_addr - XIP_BASE, state->page_buffer);
|
||||
// }
|
||||
|
||||
request_byte(state, state->fw.address);
|
||||
}
|
||||
// request_byte(state, state->fw.address);
|
||||
// }
|
||||
|
||||
void packet_receiver_task(device_t *state) {
|
||||
uint32_t current_pointer
|
||||
|
|
12
src/uart.c
12
src/uart.c
|
@ -71,17 +71,17 @@ const uart_handler_t uart_handler[] = {
|
|||
{.type = OUTPUT_SELECT_MSG, .handler = handle_output_select_msg},
|
||||
|
||||
/* Box control */
|
||||
{.type = MOUSE_ZOOM_MSG, .handler = handle_mouse_zoom_msg},
|
||||
// {.type = MOUSE_ZOOM_MSG, .handler = handle_mouse_zoom_msg},
|
||||
{.type = KBD_SET_REPORT_MSG, .handler = handle_set_report_msg},
|
||||
{.type = SWITCH_LOCK_MSG, .handler = handle_switch_lock_msg},
|
||||
// {.type = SWITCH_LOCK_MSG, .handler = handle_switch_lock_msg},
|
||||
{.type = SYNC_BORDERS_MSG, .handler = handle_sync_borders_msg},
|
||||
{.type = FLASH_LED_MSG, .handler = handle_flash_led_msg},
|
||||
{.type = GAMING_MODE_MSG, .handler = handle_toggle_gaming_msg},
|
||||
// {.type = GAMING_MODE_MSG, .handler = handle_toggle_gaming_msg},
|
||||
{.type = CONSUMER_CONTROL_MSG, .handler = handle_consumer_control_msg},
|
||||
{.type = SCREENSAVER_MSG, .handler = handle_screensaver_msg},
|
||||
// {.type = SCREENSAVER_MSG, .handler = handle_screensaver_msg},
|
||||
|
||||
/* Config */
|
||||
{.type = WIPE_CONFIG_MSG, .handler = handle_wipe_config_msg},
|
||||
// {.type = WIPE_CONFIG_MSG, .handler = handle_wipe_config_msg},
|
||||
{.type = SAVE_CONFIG_MSG, .handler = handle_save_config_msg},
|
||||
{.type = REBOOT_MSG, .handler = handle_reboot_msg},
|
||||
{.type = GET_VAL_MSG, .handler = handle_api_msgs},
|
||||
|
@ -91,7 +91,7 @@ const uart_handler_t uart_handler[] = {
|
|||
/* Firmware */
|
||||
{.type = REQUEST_BYTE_MSG, .handler = handle_request_byte_msg},
|
||||
{.type = RESPONSE_BYTE_MSG, .handler = handle_response_byte_msg},
|
||||
{.type = FIRMWARE_UPGRADE_MSG, .handler = handle_fw_upgrade_msg},
|
||||
// {.type = FIRMWARE_UPGRADE_MSG, .handler = handle_fw_upgrade_msg},
|
||||
|
||||
{.type = HEARTBEAT_MSG, .handler = handle_heartbeat_msg},
|
||||
{.type = PROXY_PACKET_MSG, .handler = handle_proxy_msg},
|
||||
|
|
14
src/utils.c
14
src/utils.c
|
@ -59,11 +59,11 @@ uint32_t calculate_firmware_crc32(void) {
|
|||
* Flash and config functions
|
||||
* ================================================== */
|
||||
|
||||
void wipe_config(void) {
|
||||
uint32_t ints = save_and_disable_interrupts();
|
||||
flash_range_erase((uint32_t)ADDR_CONFIG - XIP_BASE, FLASH_SECTOR_SIZE);
|
||||
restore_interrupts(ints);
|
||||
}
|
||||
// void wipe_config(void) {
|
||||
// uint32_t ints = save_and_disable_interrupts();
|
||||
// flash_range_erase((uint32_t)ADDR_CONFIG - XIP_BASE, FLASH_SECTOR_SIZE);
|
||||
// restore_interrupts(ints);
|
||||
// }
|
||||
|
||||
void write_flash_page(uint32_t target_addr, uint8_t *buffer) {
|
||||
/* Start of sector == first 256-byte page in a 4096 byte block */
|
||||
|
@ -150,7 +150,7 @@ void request_byte(device_t *state, uint32_t address) {
|
|||
.data32[0] = address,
|
||||
.type = REQUEST_BYTE_MSG,
|
||||
};
|
||||
state->fw.byte_done = false;
|
||||
// state->fw.byte_done = false;
|
||||
|
||||
queue_try_add(&global_state.uart_tx_queue, &packet);
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ bool validate_packet(uart_packet_t *packet) {
|
|||
GET_VAL_MSG,
|
||||
GET_ALL_VALS_MSG,
|
||||
SET_VAL_MSG,
|
||||
WIPE_CONFIG_MSG,
|
||||
// WIPE_CONFIG_MSG,
|
||||
SAVE_CONFIG_MSG,
|
||||
REBOOT_MSG,
|
||||
PROXY_PACKET_MSG,
|
||||
|
|
Loading…
Reference in New Issue