Added snap click, per-key/mixed rgb, custom debounce, wireless config feature
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
#include "rtc_timer.h"
|
||||
#include "keychron_wireless_common.h"
|
||||
#include "keychron_task.h"
|
||||
#include "wireless_config.h"
|
||||
#include "keychron_raw_hid.h"
|
||||
|
||||
extern uint8_t pairing_indication;
|
||||
extern host_driver_t chibios_driver;
|
||||
@@ -39,6 +41,9 @@ static wt_state_t wireless_state = WT_RESET;
|
||||
static bool pincodeEntry = false;
|
||||
uint8_t wireless_report_protocol = true;
|
||||
|
||||
uint16_t backlit_disable_time = CONNECTED_BACKLIGHT_DISABLE_TIMEOUT;
|
||||
uint16_t connected_idle_time = CONNECTED_IDLE_TIME;
|
||||
|
||||
/* declarations */
|
||||
uint8_t wreless_keyboard_leds(void);
|
||||
void wireless_send_keyboard(report_keyboard_t *report);
|
||||
@@ -55,6 +60,8 @@ wireless_event_t wireless_event_queue[WT_EVENT_QUEUE_SIZE];
|
||||
uint8_t wireless_event_queue_head;
|
||||
uint8_t wireless_event_queue_tail;
|
||||
|
||||
bool wireless_lpm_set(uint8_t *data);
|
||||
|
||||
void wireless_event_queue_init(void) {
|
||||
// Initialise the event queue
|
||||
memset(&wireless_event_queue, 0, sizeof(wireless_event_queue));
|
||||
@@ -82,6 +89,41 @@ static inline bool wireless_event_dequeue(wireless_event_t *event) {
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(EECONFIG_BASE_WIRELESS_CONFIG)
|
||||
void wireless_config_reset(void) {
|
||||
uint8_t data[4] = { 0 };
|
||||
|
||||
uint16_t backlit_disable_time = CONNECTED_BACKLIGHT_DISABLE_TIMEOUT;
|
||||
uint16_t connected_idle_time = CONNECTED_IDLE_TIME;
|
||||
|
||||
memcpy(&data[0], &backlit_disable_time, sizeof(backlit_disable_time));
|
||||
memcpy(&data[2], &connected_idle_time, sizeof(connected_idle_time));
|
||||
wireless_lpm_set(data);
|
||||
}
|
||||
|
||||
void wireless_config_load(void) {
|
||||
uint8_t offset = 0;
|
||||
eeprom_read_block(&backlit_disable_time, (uint8_t *)(EECONFIG_BASE_WIRELESS_CONFIG+offset), sizeof(backlit_disable_time));
|
||||
offset += sizeof(backlit_disable_time);
|
||||
eeprom_read_block(&connected_idle_time, (uint8_t *)(EECONFIG_BASE_WIRELESS_CONFIG+offset), sizeof(connected_idle_time));
|
||||
|
||||
if (backlit_disable_time == 0)
|
||||
backlit_disable_time = CONNECTED_BACKLIGHT_DISABLE_TIMEOUT;
|
||||
else if (backlit_disable_time < 5 ) backlit_disable_time = 5;
|
||||
|
||||
if (connected_idle_time == 0)
|
||||
connected_idle_time = CONNECTED_IDLE_TIME;
|
||||
else if (connected_idle_time < 30 ) connected_idle_time = 30;
|
||||
}
|
||||
|
||||
void wireless_config_save(void) {
|
||||
uint8_t offset = 0;
|
||||
eeprom_update_block(&backlit_disable_time, (uint8_t *)(EECONFIG_BASE_WIRELESS_CONFIG+offset), sizeof(backlit_disable_time));
|
||||
offset += sizeof(backlit_disable_time);
|
||||
eeprom_update_block(&connected_idle_time, (uint8_t *)(EECONFIG_BASE_WIRELESS_CONFIG+offset), sizeof(connected_idle_time));
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Bluetooth init.
|
||||
*/
|
||||
@@ -102,6 +144,10 @@ void wireless_init(void) {
|
||||
#if HAL_USE_RTC
|
||||
rtc_timer_init();
|
||||
#endif
|
||||
|
||||
#if defined(EECONFIG_BASE_WIRELESS_CONFIG)
|
||||
wireless_config_load();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -253,9 +299,10 @@ static void wireless_enter_disconnected(uint8_t host_idx, uint8_t reason) {
|
||||
indicator_set(WT_SUSPEND, host_idx);
|
||||
} else {
|
||||
indicator_set(wireless_state, host_idx);
|
||||
#if defined(RGB_MATRIX) || defined(LED_MATRIX)
|
||||
if (reason && (get_transport() & TRANSPORT_WIRELESS))
|
||||
#if defined(RGB_MATRIX_ENABLE) || defined(LED_MATRIX_ENABLE)
|
||||
if (reason && (get_transport() & TRANSPORT_WIRELESS)) {
|
||||
indicator_set_backlit_timeout(DISCONNECTED_BACKLIGHT_DISABLE_TIMEOUT*1000);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -539,3 +586,72 @@ bool process_record_wireless(uint16_t keycode, keyrecord_t *record) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(EECONFIG_BASE_WIRELESS_CONFIG)
|
||||
bool wireless_lpm_get(uint8_t *data) {
|
||||
uint8_t index = 1;
|
||||
memcpy(&data[index], &backlit_disable_time, sizeof(backlit_disable_time));
|
||||
index += sizeof(backlit_disable_time);
|
||||
memcpy(&data[index], &connected_idle_time, sizeof(connected_idle_time));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wireless_lpm_set(uint8_t *data) {
|
||||
uint8_t index = 0;
|
||||
|
||||
memcpy(&backlit_disable_time, &data[index], sizeof(backlit_disable_time));
|
||||
index += sizeof(backlit_disable_time);
|
||||
memcpy(&connected_idle_time, &data[index], sizeof(connected_idle_time));
|
||||
|
||||
if (backlit_disable_time < 5 || connected_idle_time < 60) {
|
||||
wireless_config_load();
|
||||
return false;
|
||||
}
|
||||
|
||||
wireless_config_save();
|
||||
|
||||
// Reset backlight timeout
|
||||
if ((get_transport() & TRANSPORT_WIRELESS) && wireless_state == WT_CONNECTED)
|
||||
{
|
||||
indicator_set_backlit_timeout(backlit_disable_time*1000);
|
||||
indicator_reset_backlit_time();
|
||||
|
||||
// Wiggle mouse to reset bluetooth module timer
|
||||
mousekey_on(KC_MS_LEFT);
|
||||
mousekey_send();
|
||||
wait_ms(10);
|
||||
mousekey_on(KC_MS_RIGHT);
|
||||
mousekey_send();
|
||||
wait_ms(10);
|
||||
mousekey_off((KC_MS_RIGHT));
|
||||
mousekey_send();
|
||||
wait_ms(10);
|
||||
}
|
||||
|
||||
// Update bluetooth module param
|
||||
lkbt51_param_init();
|
||||
return true;
|
||||
}
|
||||
|
||||
void wireless_raw_hid_rx(uint8_t *data, uint8_t length) {
|
||||
uint8_t cmd = data[1];
|
||||
bool success = true;
|
||||
|
||||
switch (cmd) {
|
||||
case WIRELESS_LPM_GET:
|
||||
success = wireless_lpm_get(&data[2]);
|
||||
break;
|
||||
|
||||
case WIRELESS_LPM_SET:
|
||||
success = wireless_lpm_set(&data[2]);
|
||||
break;
|
||||
|
||||
default:
|
||||
data[0] = 0xFF;
|
||||
break;
|
||||
}
|
||||
|
||||
data[2] = success ? 0 : 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user