Skip to content

Commit

Permalink
Allow each half to handle haptic play
Browse files Browse the repository at this point in the history
  • Loading branch information
drashna committed Oct 22, 2024
1 parent ecea951 commit 1cc1fcd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
10 changes: 0 additions & 10 deletions quantum/haptic.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
# include "solenoid.h"
#endif

#if defined(SPLIT_KEYBOARD) && defined(SPLIT_HAPTIC_ENABLE)
extern uint8_t split_haptic_play;
#endif

haptic_config_t haptic_config;

static void update_haptic_enable_gpios(void) {
Expand Down Expand Up @@ -335,15 +331,9 @@ void haptic_play(void) {
uint8_t play_eff = 0;
play_eff = haptic_config.mode;
drv2605l_pulse(play_eff);
# if defined(SPLIT_KEYBOARD) && defined(SPLIT_HAPTIC_ENABLE)
split_haptic_play = haptic_config.mode;
# endif
#endif
#ifdef HAPTIC_SOLENOID
solenoid_fire_handler();
# if defined(SPLIT_KEYBOARD) && defined(SPLIT_HAPTIC_ENABLE)
split_haptic_play = 1;
# endif
#endif
}

Expand Down
5 changes: 5 additions & 0 deletions quantum/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,11 @@ void switch_events(uint8_t row, uint8_t col, bool pressed) {
#if defined(RGB_MATRIX_ENABLE)
rgb_matrix_handle_key_event(row, col, pressed);
#endif
#if defined(HAPTIC_ENABLE) && defined(SPLIT_HAPTIC_ENABLE)
void haptic_handle_key_event(uint8_t row, uint8_t col, bool pressed);
haptic_handle_key_event(row, col, pressed);
#endif // HAPTIC_ENABLE && SPLIT_HAPTIC_ENABLE

wakeup_matrix_handle_key_event(row, col, pressed);
}

Expand Down
26 changes: 26 additions & 0 deletions quantum/process_keycode/process_haptic.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,29 @@ bool process_haptic(uint16_t keycode, keyrecord_t *record) {

return true;
}



void haptic_handle_key_event(uint8_t row, uint8_t col, bool pressed) {
if (is_keyboard_master()) {
return;
}
keyevent_t event = MAKE_KEYEVENT(row, col, pressed);
keyrecord_t record = {.event = event};
uint16_t keycode = get_event_keycode(event, false);

if (haptic_get_enable() && ((!HAPTIC_OFF_IN_LOW_POWER) || (usb_device_state_get_configure_state() == USB_DEVICE_STATE_CONFIGURED))) {
if (record.event.pressed) {
// keypress
if (haptic_get_feedback() < 2 && get_haptic_enabled_key(keycode, &record)) {
haptic_play();
}
} else {
// keyrelease
if (haptic_get_feedback() > 0 && get_haptic_enabled_key(keycode, &record)) {
haptic_play();
}
}
}

}
13 changes: 1 addition & 12 deletions quantum/split_common/transactions.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,30 +817,19 @@ static void watchdog_handlers_slave(matrix_row_t master_matrix[], matrix_row_t s

#if defined(HAPTIC_ENABLE) && defined(SPLIT_HAPTIC_ENABLE)

uint8_t split_haptic_play = 0xFF;
extern haptic_config_t haptic_config;

static bool haptic_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
static uint32_t last_update = 0;
split_slave_haptic_sync_t haptic_sync;

memcpy(&haptic_sync.haptic_config, &haptic_config, sizeof(haptic_config_t));
haptic_sync.haptic_play = split_haptic_play;

bool okay = send_if_data_mismatch(PUT_HAPTIC, &last_update, &haptic_sync, &split_shmem->haptic_sync, sizeof(haptic_sync));

split_haptic_play = 0xFF;

return okay;
return send_if_data_mismatch(PUT_HAPTIC, &last_update, &haptic_sync, &split_shmem->haptic_sync, sizeof(haptic_sync));
}

static void haptic_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
memcpy(&haptic_config, &split_shmem->haptic_sync.haptic_config, sizeof(haptic_config_t));

if (split_shmem->haptic_sync.haptic_play != 0xFF) {
haptic_set_mode(split_shmem->haptic_sync.haptic_play);
haptic_play();
}
}

// clang-format off
Expand Down

0 comments on commit 1cc1fcd

Please sign in to comment.