Skip to content

Commit

Permalink
add modified dual-configuration syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
RealET committed May 22, 2024
1 parent 7d5f6fc commit 47417fd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
1 change: 1 addition & 0 deletions keyboards/cyboard/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@
#define POINTING_DEVICE_COMBINED
#define CHARYBDIS_DRAGSCROLL_REVERSE_Y
#define POINTING_DEVICE_TASK_THROTTLE_MS 3
#define CHARYBDIS_CONFIG_DUAL_SYNC
58 changes: 56 additions & 2 deletions keyboards/cyboard/cyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,23 @@ void charybdis_config_sync_handler(uint8_t initiator2target_buffer_size, const v
}
# endif

#ifdef CHARYBDIS_CONFIG_DUAL_SYNC
void charybdis_config_dual_sync_handler(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) {
if (initiator2target_buffer_size == sizeof(g_charybdis_config_left.raw) + sizeof(g_charybdis_config_right.raw)) {
// Copy left configuration
memcpy(&g_charybdis_config_left, initiator2target_buffer, sizeof(g_charybdis_config_left));
// Copy right configuration
memcpy(&g_charybdis_config_right, (const uint8_t*)initiator2target_buffer + sizeof(g_charybdis_config_left), sizeof(g_charybdis_config_right));
}
}
#endif


void keyboard_post_init_kb(void) {
maybe_update_pointing_device_cpi(&g_charybdis_config_left, true);
maybe_update_pointing_device_cpi(&g_charybdis_config_right, false);
# ifdef CHARYBDIS_CONFIG_SYNC
transaction_register_rpc(RPC_ID_KB_CONFIG_SYNC, charybdis_config_sync_handler);
# ifdef CHARYBDIS_CONFIG_DUAL_SYNC
transaction_register_rpc(RPC_ID_KB_CONFIG_DUAL_SYNC, charybdis_config_dual_sync_handler);
# endif
keyboard_post_init_user();
}
Expand Down Expand Up @@ -437,4 +449,46 @@ void housekeeping_task_kb(void) {
// already.
}
# endif // CHARYBDIS_CONFIG_SYNC

#ifdef CHARYBDIS_CONFIG_DUAL_SYNC
void housekeeping_task_kb(void) {
if (is_keyboard_master()) {
// Keep track of the last state, so that we can tell if we need to propagate to slave.
static charybdis_config_t last_charybdis_config_left = {0};
static charybdis_config_t last_charybdis_config_right = {0};
static uint32_t last_sync = 0;
bool needs_sync = false;

// Check if the left state values are different.
if (memcmp(&g_charybdis_config_left, &last_charybdis_config_left, sizeof(g_charybdis_config_left))) {
needs_sync = true;
memcpy(&last_charybdis_config_left, &g_charybdis_config_left, sizeof(g_charybdis_config_left));
}

// Check if the right state values are different.
if (memcmp(&g_charybdis_config_right, &last_charybdis_config_right, sizeof(g_charybdis_config_right))) {
needs_sync = true;
memcpy(&last_charybdis_config_right, &g_charybdis_config_right, sizeof(g_charybdis_config_right));
}

// Send to slave every 500ms regardless of state change.
if (timer_elapsed32(last_sync) > 500) {
needs_sync = true;
}

// Perform the sync if requested.
if (needs_sync) {
uint8_t sync_buffer[sizeof(g_charybdis_config_left) + sizeof(g_charybdis_config_right)];
memcpy(sync_buffer, &g_charybdis_config_left, sizeof(g_charybdis_config_left));
memcpy(sync_buffer + sizeof(g_charybdis_config_left), &g_charybdis_config_right, sizeof(g_charybdis_config_right));
if (transaction_rpc_send(RPC_ID_KB_CONFIG_DUAL_SYNC, sizeof(sync_buffer), sync_buffer)) {
last_sync = timer_read32();
}
}
}
// No need to invoke the user-specific callback, as it's been called already.
}
#endif // CHARYBDIS_CONFIG_DUAL_SYNC


#endif // POINTING_DEVICE_ENABLE
4 changes: 4 additions & 0 deletions keyboards/cyboard/post_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
# define SPLIT_TRANSACTION_IDS_KB RPC_ID_KB_CONFIG_SYNC
#endif

#ifdef CHARYBDIS_CONFIG_DUAL_SYNC
# define SPLIT_TRANSACTION_IDS_KB RPC_ID_KB_CONFIG_DUAL_SYNC
#endif

/* Mouse config. */

#ifndef MOUSEKEY_MOVE_DELTA
Expand Down

0 comments on commit 47417fd

Please sign in to comment.