Skip to content

Commit

Permalink
DeskHop v0.62 (Minor Bugfixes)
Browse files Browse the repository at this point in the history
  - Fixed screen lock regression bug
  - Cleaned up trailing spaces

Due to MacOS having issues:
  - Moved screen lock shortcut to right control + L
  - Moved switch lock shortcut to right control + K
  • Loading branch information
Hrvoje Cavrak committed Aug 3, 2024
1 parent 7a0e7f3 commit 1fd0049
Show file tree
Hide file tree
Showing 24 changed files with 188 additions and 184 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.6)

set(VERSION_MAJOR 00)
set(VERSION_MINOR 139)
set(VERSION_MINOR 147)

set(PICO_SDK_FETCH_FROM_GIT off)
set(PICO_BOARD=pico)
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,14 @@ Ever tried to move that YT video slider to a specific position but your mouse mo

### Switch Lock

If you want to lock yourself to one screen, use ```RIGHT CTRL + L```.
If you want to lock yourself to one screen, use ```RIGHT CTRL + K```.
This will make sure you won't accidentally leave your current screen. To turn off, press the same key combo again.

### Lock Both Screens

You can lock both computers at once by using ```RIGHT CTRL + L```.
To make use of this feature, first set up the OS for each output in config (since the shortcuts are different).

### Screensaver

Supposedly built in to prevent computer from entering standby, but truth be told - it is just fun to watch. **Off by default**, will make your mouse pointer bounce around the screen like a Pong ball. When enabled, it activates after a period of inactivity defined in user config header and automatically switches off as soon as you send any output towards that screen.
Expand Down Expand Up @@ -209,8 +214,8 @@ _Config_

_Usage_
- ```Right CTRL + Right ALT``` - Toggle slower mouse mode
- ```Right CTRL + L``` - Lock/Unlock mouse desktop switching
- ```Right ALT + Right Shift + L``` - Lock both outputs at once (set output OS before, see shortcuts below)
- ```Right CTRL + K``` - Lock/Unlock mouse desktop switching
- ```Right CTRL + L``` - Lock both outputs at once (set output OS before, see shortcuts below)
- ```Caps Lock``` - Switch between outputs

### Switch cursor height calibration
Expand Down
Binary file modified disk/disk.img
Binary file not shown.
6 changes: 3 additions & 3 deletions src/defaults.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const config_t default_config = {
.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,
.max_time_us = SCREENSAVER_A_MAX_TIME_SEC * 1000000,
}
},
},
.output[OUTPUT_B] =
{
.number = OUTPUT_B,
Expand All @@ -41,7 +41,7 @@ const config_t default_config = {
.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,
.max_time_us = SCREENSAVER_B_MAX_TIME_SEC * 1000000,
}
},
.enforce_ports = ENFORCE_PORTS,
Expand Down
36 changes: 18 additions & 18 deletions src/handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ void screenlock_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
lock_report.keycode[0] = HID_KEY_L;
break;
case MACOS:
lock_report.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_LEFTALT;
lock_report.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_LEFTGUI;
lock_report.keycode[0] = HID_KEY_Q;
break;
default:
break;
}

if (global_state.active_output == out) {
if (BOARD_ROLE == out) {
queue_kbd_report(&lock_report, state);
release_all_keys(state);
} else {
Expand All @@ -111,14 +111,14 @@ void mouse_zoom_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {


/* Put the device into a special configuration mode */
void config_enable_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
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);
release_all_keys(state);
state->reboot_requested = true;
};

Expand Down Expand Up @@ -226,9 +226,9 @@ void handle_api_msgs(uart_packet_t *packet, device_t *state) {

/* If we don't have a valid map entry, return immediately */
if (map == NULL)
return;
return;

/* Create a pointer to the offset into the structure we need to access */
/* Create a pointer to the offset into the structure we need to access */
uint8_t *ptr = (((uint8_t *)&global_state) + map->offset);

if (packet->type == SET_VAL_MSG) {
Expand All @@ -237,7 +237,7 @@ void handle_api_msgs(uart_packet_t *packet, device_t *state) {
return;

memcpy(ptr, &packet->data[1], map->len);
}
}
else if (packet->type == GET_VAL_MSG) {
uart_packet_t response = {.type=GET_VAL_MSG, .data={0}};
memcpy(response.data, ptr, map->len);
Expand All @@ -252,14 +252,14 @@ void handle_api_msgs(uart_packet_t *packet, device_t *state) {
/* Process request packet and create a response */
void handle_request_byte_msg(uart_packet_t *packet, device_t *state) {
uint32_t address = packet->data32[0];

if (address > STAGING_IMAGE_SIZE)
return;

/* Add requested data to bytes 4-7 in the packet and return it with a different type */
/* Add requested data to bytes 4-7 in the packet and return it with a different type */
uint32_t data = *(uint32_t *)&ADDR_FW_RUNNING[address];
packet->data32[1] = data;

queue_packet(packet->data, RESPONSE_BYTE_MSG, PACKET_DATA_LENGTH);
}

Expand All @@ -279,27 +279,27 @@ void handle_response_byte_msg(uart_packet_t *packet, device_t *state) {
if((address & 0xfff) == 0x000)
toggle_led();
}

/* Update checksum as we receive each byte */
if (address < STAGING_IMAGE_SIZE - FLASH_SECTOR_SIZE)
for (int i=0; i<4; i++)
state->fw.checksum = crc32_iter(state->fw.checksum, packet->data[4 + i]);

memcpy(state->page_buffer + offset, &packet->data32[1], sizeof(uint32_t));
memcpy(state->page_buffer + offset, &packet->data32[1], sizeof(uint32_t));

/* Neeeeeeext byte, please! */
state->fw.address += sizeof(uint32_t);
state->fw.address += sizeof(uint32_t);
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) {
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 the other board isn't running a newer version, we are done */
/* If the other board isn't running a newer version, we are done */
if (other_running_version <= state->_running_fw.version)
return;

Expand All @@ -309,7 +309,7 @@ void handle_heartbeat_msg(uart_packet_t *packet, device_t *state) {
.byte_done = true,
.address = 0,
.checksum = 0xffffffff,
};
};
}


Expand Down
24 changes: 12 additions & 12 deletions src/hid_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void update_usage(parser_state_t *parser, int i) {
*(parser->p_usage + i) = *(parser->p_usage + i - 1);
}

void store_element(parser_state_t *parser, report_val_t *val, int i, uint32_t data, uint16_t size, hid_interface_t *iface) {
void store_element(parser_state_t *parser, report_val_t *val, int i, uint32_t data, uint16_t size, hid_interface_t *iface) {
*val = (report_val_t){
.offset = parser->offset_in_bits,
.offset_idx = parser->offset_in_bits >> 3,
Expand All @@ -68,9 +68,9 @@ void store_element(parser_state_t *parser, report_val_t *val, int i, uint32_t da
}

void handle_global_item(parser_state_t *parser, item_t *item) {
if (item->hdr.tag == RI_GLOBAL_REPORT_ID)
parser->report_id = item->val;
if (item->hdr.tag == RI_GLOBAL_REPORT_ID)
parser->report_id = item->val;

parser->globals[item->hdr.tag] = *item;
}

Expand All @@ -80,7 +80,7 @@ void handle_local_item(parser_state_t *parser, item_t *item) {
parser->locals[item->hdr.tag] = *item;

if (item->hdr.tag == RI_LOCAL_USAGE) {
if(IS_BLOCK_END)
if(IS_BLOCK_END)
parser->global_usage = item->val;

else if (parser->usage_count < HID_MAX_USAGES - 1)
Expand All @@ -94,20 +94,20 @@ void handle_main_input(parser_state_t *parser, item_t *item, hid_interface_t *if
report_val_t val = {0};

/* Swap count and size for 1-bit variables, it makes sense to process e.g. NKRO with
size = 1 and count = 240 in one go instead of doing 240 iterations
size = 1 and count = 240 in one go instead of doing 240 iterations
Don't do this if there are usages in the queue, though.
*/
*/
if (size == 1 && parser->usage_count <= 1) {
size = count;
count = 1;
count = 1;
}

for (int i = 0; i < count; i++) {
update_usage(parser, i);
store_element(parser, &val, i, item->val, size, iface);

/* Use the parsed data to populate internal device structures */
extract_data(iface, &val);
extract_data(iface, &val);

/* Iterate <count> times and increase offset by <size> amount, moving by <count> x <size> bits */
parser->offset_in_bits += size;
Expand Down Expand Up @@ -152,7 +152,7 @@ void handle_main_item(parser_state_t *parser, item_t *item, hid_interface_t *ifa
parser_state_t parser_state = {0}; // Avoid placing it on the stack, it's large

void parse_report_descriptor(hid_interface_t *iface,
uint8_t const *report,
uint8_t const *report,
int desc_len
) {
item_t item = {0};
Expand Down Expand Up @@ -181,5 +181,5 @@ void parse_report_descriptor(hid_interface_t *iface,
/* Move to the next position and decrement size by header length + data length */
report += SIZE_LOOKUP[item.hdr.size];
desc_len -= (SIZE_LOOKUP[item.hdr.size] + 1);
}
}
}
40 changes: 20 additions & 20 deletions src/hid_report.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,31 @@ int32_t get_report_value(uint8_t *report, report_val_t *val) {
}

/* After processing the descriptor, assign the values so we can later use them to interpret reports */
void handle_consumer_control_values(report_val_t *src, report_val_t *dst, hid_interface_t *iface) {
void handle_consumer_control_values(report_val_t *src, report_val_t *dst, hid_interface_t *iface) {
if (src->offset > MAX_CC_BUTTONS) {
return;
}

if (src->data_type == VARIABLE) {
iface->keyboard.cc_array[src->offset] = src->usage;
iface->consumer.is_variable = true;
}
iface->consumer.is_array |= (src->data_type == ARRAY);

iface->consumer.is_array |= (src->data_type == ARRAY);
}

/* After processing the descriptor, assign the values so we can later use them to interpret reports */
void handle_system_control_values(report_val_t *src, report_val_t *dst, hid_interface_t *iface) {
if (src->offset > MAX_SYS_BUTTONS) {
return;
}

if (src->data_type == VARIABLE) {
iface->keyboard.sys_array[src->offset] = src->usage;
iface->system.is_variable = true;
}
iface->system.is_array |= (src->data_type == ARRAY);

iface->system.is_array |= (src->data_type == ARRAY);
}

/* After processing the descriptor, assign the values so we can later use them to interpret reports */
Expand Down Expand Up @@ -143,54 +143,54 @@ void extract_data(hid_interface_t *iface, report_val_t *val) {
.id = &iface->mouse.report_id},

{.usage_page = HID_USAGE_PAGE_DESKTOP,
.global_usage = HID_USAGE_DESKTOP_MOUSE,
.global_usage = HID_USAGE_DESKTOP_MOUSE,
.usage = HID_USAGE_DESKTOP_X,
.handler = _store,
.receiver = process_mouse_report,
.dst = &iface->mouse.move_x,
.id = &iface->mouse.report_id},

{.usage_page = HID_USAGE_PAGE_DESKTOP,
.global_usage = HID_USAGE_DESKTOP_MOUSE,
.global_usage = HID_USAGE_DESKTOP_MOUSE,
.usage = HID_USAGE_DESKTOP_Y,
.handler = _store,
.receiver = process_mouse_report,
.dst = &iface->mouse.move_y,
.id = &iface->mouse.report_id},

{.usage_page = HID_USAGE_PAGE_DESKTOP,
.global_usage = HID_USAGE_DESKTOP_MOUSE,
.global_usage = HID_USAGE_DESKTOP_MOUSE,
.usage = HID_USAGE_DESKTOP_WHEEL,
.handler = _store,
.receiver = process_mouse_report,
.dst = &iface->mouse.wheel,
.id = &iface->mouse.report_id},

{.usage_page = HID_USAGE_PAGE_KEYBOARD,
.global_usage = HID_USAGE_DESKTOP_KEYBOARD,
.global_usage = HID_USAGE_DESKTOP_KEYBOARD,
.handler = handle_keyboard_descriptor_values,
.receiver = process_keyboard_report,
.id = &iface->keyboard.report_id},

{.usage_page = HID_USAGE_PAGE_CONSUMER,
.global_usage = HID_USAGE_CONSUMER_CONTROL,
.handler = handle_consumer_control_values,
.receiver = process_consumer_report,
.dst = &iface->consumer.val,
.id = &iface->consumer.report_id},

{.usage_page = HID_USAGE_PAGE_DESKTOP,
.global_usage = HID_USAGE_DESKTOP_SYSTEM_CONTROL,
.handler = _store,
.receiver = process_system_report,
.dst = &iface->system.val,
.id = &iface->system.report_id},
};
};

/* We extracted all we could find in the descriptor to report_values, now go through them and
match them up with the values in the table above, then store those values for later reference */

for (const usage_map_t *hay = map; hay != &map[ARRAY_SIZE(map)]; hay++) {
for (const usage_map_t *hay = map; hay != &map[ARRAY_SIZE(map)]; hay++) {
/* ---> If any condition is not defined, we consider it as matched <--- */
bool global_usages_match = (val->global_usage == hay->global_usage) || (hay->global_usage == 0);
bool usages_match = (val->usage == hay->usage) || (hay->usage == 0);
Expand Down Expand Up @@ -236,7 +236,7 @@ int32_t _extract_kbd_other(uint8_t *raw_report, int len, hid_interface_t *iface,
uint8_t *src = raw_report;
keyboard_t *kb = &iface->keyboard;

if (iface->uses_report_id)
if (iface->uses_report_id)
src++;

report->modifier = src[kb->modifier.offset_idx];
Expand Down Expand Up @@ -286,7 +286,7 @@ int32_t extract_kbd_data(

/* NKRO is a special case */
if (report_id > 0
&& report_id == iface->keyboard.nkro.report_id
&& report_id == iface->keyboard.nkro.report_id
&& iface->keyboard.is_nkro)
return _extract_kbd_nkro(raw_report, len, iface, report);

Expand Down
2 changes: 1 addition & 1 deletion src/include/hid_report.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef struct {
int usage_page;
int usage;
uint8_t *id;
report_val_t *dst;
report_val_t *dst;
value_handler_f handler;
process_report_f receiver;
} usage_map_t;
Loading

0 comments on commit 1fd0049

Please sign in to comment.