Skip to content

Commit

Permalink
Handle Haptic Feedback play on each half with support for remote sending
Browse files Browse the repository at this point in the history
  • Loading branch information
drashna committed Oct 26, 2024
1 parent d85e1d7 commit 659750c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
19 changes: 13 additions & 6 deletions quantum/haptic.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,18 +335,25 @@ 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
}

void set_haptic_split_play(uint8_t mode) {
split_haptic_play = mode;
}

void split_haptic_play_effect(uint8_t mode) {
#ifdef HAPTIC_DRV2605L
drv2605l_pulse(mode);
#endif // HAPTIC_DRV2605L
#ifdef HAPTIC_SOLENOID
solenoid_fire_handler();
#endif // HAPTIC_SOLENOID
}

void haptic_shutdown(void) {
#ifdef HAPTIC_SOLENOID
solenoid_shutdown();
Expand Down
3 changes: 3 additions & 0 deletions quantum/haptic.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ void haptic_cont_increase(void);
void haptic_cont_decrease(void);

void haptic_play(void);
void set_haptic_split_play(uint8_t mode);
void split_haptic_play_effect(uint8_t mode);

void haptic_shutdown(void);
void haptic_notify_usb_device_state_change(void);

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();
}
}
}

}
3 changes: 1 addition & 2 deletions quantum/split_common/transactions.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,7 @@ static void haptic_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sla
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();
split_haptic_play_effect(split_shmem->haptic_sync.haptic_play);
}
}

Expand Down

0 comments on commit 659750c

Please sign in to comment.