Skip to content

Commit

Permalink
feat: request to reboot active board
Browse files Browse the repository at this point in the history
  • Loading branch information
jalmeroth committed Aug 30, 2024
1 parent 1140c73 commit 86a4a56
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- `RIGHT ALT + RIGHT SHIFT + L` locks both screens
- `RIGHT ALT + RIGHT SHIFT + S` suspends both PCs
- `RIGHT ALT + RIGHT SHIFT + D` enables debug mode\*
- `RIGHT ALT + RIGHT SHIFT + R` request to reboot active board

\*the output will be shown on the `UART1 TX` pin.

Expand Down
8 changes: 8 additions & 0 deletions src/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ void lock_screen(void) {
send_lock_screen_report(NULL, NULL);
}

void request_reboot() {
if (global_state.active_output == BOARD_ROLE) {
global_state.reboot_requested = true;
} else {
send_value(1, REQUEST_REBOOT_MSG);
}
}

void suspend_pc(void) {
send_value(1, SUSPEND_PC_MSG);
send_suspend_pc_report(NULL, NULL);
Expand Down
6 changes: 6 additions & 0 deletions src/handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,9 @@ void handle_uart_enable_debug_msg(uart_packet_t *packet, device_t *state) {
(void)state;
_enable_debug();
}

void handle_uart_request_reboot_msg(uart_packet_t *packet, device_t *state) {
(void)packet;
(void)state;
request_reboot();
}
5 changes: 5 additions & 0 deletions src/hotkeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ hotkey_combo_t hotkeys[] = {
.key_count = 1,
.pass_to_os = false,
.action_handler = &enable_debug},
{.modifier = KEYBOARD_MODIFIER_RIGHTALT | KEYBOARD_MODIFIER_RIGHTSHIFT,
.keys = {HID_KEY_R},
.key_count = 1,
.pass_to_os = false,
.action_handler = &request_reboot},
};
9 changes: 6 additions & 3 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ enum packet_type_e {
LOCK_SCREEN_MSG = 16,
SUSPEND_PC_MSG = 17,
ENABLE_DEBUG_MSG = 18,
REQUEST_REBOOT_MSG = 19,
};
typedef enum { IDLE, READING_PACKET, PROCESSING_PACKET } uart_state_t;

Expand Down Expand Up @@ -190,11 +191,12 @@ void setup_tuh(void);
void _enable_debug(void);
void enable_debug(void);
void lock_screen(void);
void suspend_pc(void);
void request_reboot(void);
void screensaver_task(device_t *state);
void send_suspend_pc_report(uart_packet_t *packet, device_t *state);
void send_lock_screen_report(uart_packet_t *packet, device_t *state);
void send_suspend_pc_report(uart_packet_t *packet, device_t *state);
void set_onboard_led(device_t *state);
void suspend_pc(void);
void switch_output_a(device_t *state);
void toggle_output(void);
// handlers.c
Expand All @@ -204,9 +206,10 @@ void handle_mouse(uint8_t instance, uint8_t report_id, uint8_t protocol,
uint8_t const *report, uint8_t len);
void handle_consumer(uint8_t instance, uint8_t report_id, uint8_t protocol,
uint8_t const *report, uint8_t len);
void handle_uart_generic_msg(uart_packet_t *packet, device_t *state);
void handle_uart_enable_debug_msg(uart_packet_t *packet, device_t *state);
void handle_uart_generic_msg(uart_packet_t *packet, device_t *state);
void handle_uart_output_select_msg(uart_packet_t *packet, device_t *state);
void handle_uart_request_reboot_msg(uart_packet_t *packet, device_t *state);
// keyboard.c
uint8_t get_byte_offset(uint8_t key);
uint8_t get_pos_in_byte(uint8_t key);
Expand Down
1 change: 1 addition & 0 deletions src/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const uart_handler_t uart_handler[] = {
{.type = LOCK_SCREEN_MSG, .handler = send_lock_screen_report},
{.type = SUSPEND_PC_MSG, .handler = send_suspend_pc_report},
{.type = ENABLE_DEBUG_MSG, .handler = handle_uart_enable_debug_msg},
{.type = REQUEST_REBOOT_MSG, .handler = handle_uart_request_reboot_msg},
// {.type = FIRMWARE_UPGRADE_MSG, .handler = handle_fw_upgrade_msg},
// {.type = MOUSE_ZOOM_MSG, .handler = handle_mouse_zoom_msg},
// {.type = KBD_SET_REPORT_MSG, .handler = handle_set_report_msg},
Expand Down

0 comments on commit 86a4a56

Please sign in to comment.