Unified low battery indication of LED/RGB matrix and individual LED; Fixed bluetooth name may not be set correctly after factory reset

This commit is contained in:
lokher 2024-11-09 15:45:12 +08:00
parent b5de40f5c1
commit 27a218a3d1
11 changed files with 98 additions and 147 deletions

View File

@ -167,12 +167,7 @@ void battery_check_empty(void) {
if (voltage < EMPTY_VOLTAGE_VALUE) { if (voltage < EMPTY_VOLTAGE_VALUE) {
if (bat_empty <= BATTERY_EMPTY_COUNT) { if (bat_empty <= BATTERY_EMPTY_COUNT) {
if (++bat_empty > BATTERY_EMPTY_COUNT) { if (++bat_empty > BATTERY_EMPTY_COUNT) {
#ifdef BAT_LOW_LED_PIN
indicator_battery_low_enable(true); indicator_battery_low_enable(true);
#endif
#if defined(LOW_BAT_IND_INDEX)
indicator_battery_low_backlit_enable(true);
#endif
power_on_sample = VOLTAGE_POWER_ON_MEASURE_COUNT; power_on_sample = VOLTAGE_POWER_ON_MEASURE_COUNT;
} }
} }
@ -229,11 +224,6 @@ void battery_task(void) {
if ((bat_empty || critical_low) && usb_power_connected()) { if ((bat_empty || critical_low) && usb_power_connected()) {
bat_empty = false; bat_empty = false;
critical_low = false; critical_low = false;
#ifdef BAT_LOW_LED_PIN
indicator_battery_low_enable(false); indicator_battery_low_enable(false);
#endif
#if defined(LOW_BAT_IND_INDEX)
indicator_battery_low_backlit_enable(false);
#endif
} }
} }

View File

@ -54,7 +54,6 @@ void battery_calculate_voltage(bool vol_src_bt, uint16_t value);
void battery_set_voltage(uint16_t value); void battery_set_voltage(uint16_t value);
uint16_t battery_get_voltage(void); uint16_t battery_get_voltage(void);
uint8_t battery_get_percentage(void); uint8_t battery_get_percentage(void);
void indicator_battery_low_enable(bool enable);
bool battery_is_empty(void); bool battery_is_empty(void);
bool battery_is_critical_low(void); bool battery_is_critical_low(void);
bool battery_power_on_sample(void); bool battery_power_on_sample(void);

View File

@ -28,7 +28,6 @@
# include "factory_test.h" # include "factory_test.h"
#endif #endif
#include "lpm.h" #include "lpm.h"
#include "keychron_task.h" #include "keychron_task.h"
#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) #if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)
# ifdef LED_MATRIX_ENABLE # ifdef LED_MATRIX_ENABLE
@ -71,12 +70,7 @@ static uint16_t next_period;
static indicator_type_t type; static indicator_type_t type;
static uint32_t indicator_timer_buffer = 0; static uint32_t indicator_timer_buffer = 0;
#if defined(BAT_LOW_LED_PIN) #if defined(BAT_LOW_LED_PIN) || defined(SPACE_KEY_LOW_BAT_IND)
static uint32_t bat_low_pin_indicator = 0;
static uint32_t bat_low_blink_duration = 0;
#endif
#if defined(LOW_BAT_IND_INDEX)
static uint32_t bat_low_backlit_indicator = 0; static uint32_t bat_low_backlit_indicator = 0;
static uint8_t bat_low_ind_state = 0; static uint8_t bat_low_ind_state = 0;
static uint32_t rtc_time = 0; static uint32_t rtc_time = 0;
@ -177,8 +171,13 @@ void indicator_init(void) {
#endif #endif
#ifdef BAT_LOW_LED_PIN #ifdef BAT_LOW_LED_PIN
setPinOutput(BAT_LOW_LED_PIN); #ifdef POWER_ON_LED_DURATION
writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE); if (timer_read32() > POWER_ON_LED_DURATION)
#endif
{
setPinOutput(BAT_LOW_LED_PIN);
writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE);
}
#endif #endif
} }
@ -213,10 +212,7 @@ void indicator_eeconfig_reload(void) {
bool indicator_is_running(void) { bool indicator_is_running(void) {
return return
#if defined(BAT_LOW_LED_PIN) #if defined(BAT_LOW_LED_PIN) || defined(SPACE_KEY_LOW_BAT_IND)
bat_low_blink_duration ||
#endif
#if defined(LOW_BAT_IND_INDEX)
bat_low_ind_state || bat_low_ind_state ||
#endif #endif
!!indicator_config.value; !!indicator_config.value;
@ -342,6 +338,7 @@ static void indicator_timer_cb(void *arg) {
void indicator_set(wt_state_t state, uint8_t host_index) { void indicator_set(wt_state_t state, uint8_t host_index) {
if (get_transport() == TRANSPORT_USB) return; if (get_transport() == TRANSPORT_USB) return;
static uint8_t pre_state = 0;
static uint8_t current_state = 0; static uint8_t current_state = 0;
static uint8_t current_host = 0; static uint8_t current_host = 0;
bool host_index_changed = false; bool host_index_changed = false;
@ -354,6 +351,10 @@ void indicator_set(wt_state_t state, uint8_t host_index) {
} }
if (current_state != state || host_index_changed || state == WT_RECONNECTING) { if (current_state != state || host_index_changed || state == WT_RECONNECTING) {
// Some BT chips need to reset to enter sleep mode, ignore it.
if (current_state == WT_SUSPEND && state == WT_DISCONNECTED) return;
pre_state = current_state;
current_state = state; current_state = state;
} else { } else {
return; return;
@ -385,6 +386,9 @@ void indicator_set(wt_state_t state, uint8_t host_index) {
indicator_set_backlit_timeout(1000); indicator_set_backlit_timeout(1000);
} else { } else {
if (pre_state == WT_CONNECTED)
indicator_set_backlit_timeout(1000);
else
/* Set timer so that user has chance to turn on the backlight when is off */ /* Set timer so that user has chance to turn on the backlight when is off */
indicator_set_backlit_timeout(DECIDE_TIME(DISCONNECTED_BACKLIGHT_DISABLE_TIMEOUT * 1000, indicator_config.duration)); indicator_set_backlit_timeout(DECIDE_TIME(DISCONNECTED_BACKLIGHT_DISABLE_TIMEOUT * 1000, indicator_config.duration));
} }
@ -465,22 +469,11 @@ void indicator_stop(void) {
#endif #endif
} }
#ifdef BAT_LOW_LED_PIN
void indicator_battery_low_enable(bool enable) { void indicator_battery_low_enable(bool enable) {
if (enable) { #if defined(BAT_LOW_LED_PIN) || defined(SPACE_KEY_LOW_BAT_IND)
if (bat_low_blink_duration == 0) {
bat_low_blink_duration = bat_low_pin_indicator = timer_read32();
} else
bat_low_blink_duration = timer_read32();
} else
writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE);
}
#endif
#if defined(LOW_BAT_IND_INDEX)
void indicator_battery_low_backlit_enable(bool enable) {
if (enable) { if (enable) {
uint32_t t = rtc_timer_read_ms(); uint32_t t = rtc_timer_read_ms();
/* Check overflow */ /* Check overflow */
if (rtc_time > t) { if (rtc_time > t) {
if (bat_low_ind_state == 0) if (bat_low_ind_state == 0)
@ -489,55 +482,62 @@ void indicator_battery_low_backlit_enable(bool enable) {
rtc_time += t; rtc_time += t;
} }
} }
/* Indicating at first time or after the interval */ /* Indicating at first time or after the interval */
if ((rtc_time == 0 || t - rtc_time > LOW_BAT_LED_TRIG_INTERVAL) && bat_low_ind_state == 0) { if ((rtc_time == 0 || t - rtc_time > LOW_BAT_LED_TRIG_INTERVAL) && bat_low_ind_state == 0) {
bat_low_backlit_indicator = enable ? timer_read32() : 0; bat_low_backlit_indicator = enable ? timer_read32() : 0;
rtc_time = rtc_timer_read_ms(); rtc_time = rtc_timer_read_ms();
bat_low_ind_state = 1; bat_low_ind_state = 1;
# if defined(SPACE_KEY_LOW_BAT_IND)
indicator_enable(); indicator_enable();
# endif
} }
} else { } else {
rtc_time = 0; rtc_time = 0;
bat_low_ind_state = 0; bat_low_ind_state = 0;
# if defined(SPACE_KEY_LOW_BAT_IND)
indicator_eeconfig_reload(); indicator_eeconfig_reload();
if (!LED_DRIVER_IS_ENABLED()) indicator_disable(); if (!LED_DRIVER_IS_ENABLED()) indicator_disable();
# endif
} }
}
#endif #endif
}
void indicator_battery_low(void) { void indicator_battery_low(void) {
#ifdef BAT_LOW_LED_PIN #if defined(BAT_LOW_LED_PIN) || defined(SPACE_KEY_LOW_BAT_IND)
if (bat_low_pin_indicator && timer_elapsed32(bat_low_pin_indicator) > (LOW_BAT_LED_BLINK_PERIOD)) {
togglePin(BAT_LOW_LED_PIN);
bat_low_pin_indicator = timer_read32();
// Turn off low battery indication if we reach the duration
if (timer_elapsed32(bat_low_blink_duration) > LOW_BAT_LED_BLINK_DURATION && palReadLine(BAT_LOW_LED_PIN) != BAT_LOW_LED_PIN_ON_STATE) {
bat_low_blink_duration = bat_low_pin_indicator = 0;
}
}
#endif
#if defined(LOW_BAT_IND_INDEX)
if (bat_low_ind_state) { if (bat_low_ind_state) {
if ((bat_low_ind_state & 0x0F) <= (LOW_BAT_LED_BLINK_TIMES) && timer_elapsed32(bat_low_backlit_indicator) > (LOW_BAT_LED_BLINK_PERIOD)) { if ((bat_low_ind_state & 0x0F) <= (LOW_BAT_LED_BLINK_TIMES) && timer_elapsed32(bat_low_backlit_indicator) > (LOW_BAT_LED_BLINK_PERIOD)) {
if (bat_low_ind_state & 0x80) { if (bat_low_ind_state & 0x80) {
bat_low_ind_state &= 0x7F; bat_low_ind_state &= 0x7F;
bat_low_ind_state++; bat_low_ind_state++;
# if defined(BAT_LOW_LED_PIN)
writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE);
# endif
} else { } else {
bat_low_ind_state |= 0x80; bat_low_ind_state |= 0x80;
# if defined(BAT_LOW_LED_PIN)
writePin(BAT_LOW_LED_PIN, BAT_LOW_LED_PIN_ON_STATE);
# endif
} }
bat_low_backlit_indicator = timer_read32(); bat_low_backlit_indicator = timer_read32();
/* Restore backligth state */ /* Restore backligth state */
if ((bat_low_ind_state & 0x0F) > (LOW_BAT_LED_BLINK_TIMES)) { if ((bat_low_ind_state & 0x0F) > (LOW_BAT_LED_BLINK_TIMES)) {
# if defined(NUM_LOCK_INDEX) || defined(CAPS_LOCK_INDEX) || defined(SCROLL_LOCK_INDEX) || defined(COMPOSE_LOCK_INDEX) || defined(KANA_LOCK_INDEX) # if defined(BAT_LOW_LED_PIN)
if (LED_DRIVER_ALLOW_SHUTDOWN()) writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE);
# endif # endif
# if defined(SPACE_KEY_LOW_BAT_IND)
# if defined(NUM_LOCK_INDEX) || defined(CAPS_LOCK_INDEX) || defined(SCROLL_LOCK_INDEX) || defined(COMPOSE_LOCK_INDEX) || defined(KANA_LOCK_INDEX)
if (LED_DRIVER_ALLOW_SHUTDOWN())
# endif
indicator_disable(); indicator_disable();
# endif
} }
} else if ((bat_low_ind_state & 0x0F) > (LOW_BAT_LED_BLINK_TIMES)) { } else if ((bat_low_ind_state & 0x0F) > (LOW_BAT_LED_BLINK_TIMES)) {
# if defined(BAT_LOW_LED_PIN)
writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE);
# endif
bat_low_ind_state = 0; bat_low_ind_state = 0;
lpm_timer_reset(); lpm_timer_reset();
} }
@ -546,9 +546,7 @@ void indicator_battery_low(void) {
} }
void indicator_task(void) { void indicator_task(void) {
#if (defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)) && defined(BAT_LEVEL_LED_LIST)
bat_level_animiation_task(); bat_level_animiation_task();
#endif
if (indicator_config.value && timer_elapsed32(indicator_timer_buffer) >= next_period) { if (indicator_config.value && timer_elapsed32(indicator_timer_buffer) >= next_period) {
indicator_timer_cb((void *)&type); indicator_timer_cb((void *)&type);
indicator_timer_buffer = timer_read32(); indicator_timer_buffer = timer_read32();
@ -606,7 +604,6 @@ bool LED_INDICATORS_KB(void) {
return true; return true;
} }
# if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)
if (battery_is_empty()) SET_ALL_LED_OFF(); if (battery_is_empty()) SET_ALL_LED_OFF();
# if defined(LOW_BAT_IND_INDEX) # if defined(LOW_BAT_IND_INDEX)
if (bat_low_ind_state && (bat_low_ind_state & 0x0F) <= LOW_BAT_LED_BLINK_TIMES) { if (bat_low_ind_state && (bat_low_ind_state & 0x0F) <= LOW_BAT_LED_BLINK_TIMES) {
@ -619,8 +616,8 @@ bool LED_INDICATORS_KB(void) {
} }
} }
} }
# endif
# endif # endif
# if (defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)) && defined(BAT_LEVEL_LED_LIST) # if (defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)) && defined(BAT_LEVEL_LED_LIST)
if (bat_level_animiation_actived()) { if (bat_level_animiation_actived()) {
bat_level_animiation_indicate(); bat_level_animiation_indicate();
@ -690,10 +687,7 @@ bool led_update_kb(led_t led_state) {
} }
void LED_NONE_INDICATORS_KB(void) { void LED_NONE_INDICATORS_KB(void) {
# if defined(RGB_DISABLE_WHEN_USB_SUSPENDED) # if defined(RGB_DISABLE_WHEN_USB_SUSPENDED) || defined(LED_DISABLE_WHEN_USB_SUSPENDED)
if (get_transport() == TRANSPORT_USB && USB_DRIVER.state == USB_SUSPENDED) return;
# endif
# if defined(LED_DISABLE_WHEN_USB_SUSPENDED)
if (get_transport() == TRANSPORT_USB && USB_DRIVER.state == USB_SUSPENDED) return; if (get_transport() == TRANSPORT_USB && USB_DRIVER.state == USB_SUSPENDED) return;
# endif # endif

View File

@ -49,37 +49,35 @@
# define CONNECTED_BACKLIGHT_OFF_DELAY_TIME 600 # define CONNECTED_BACKLIGHT_OFF_DELAY_TIME 600
#endif #endif
#ifdef BAT_LOW_LED_PIN
/* Uint: ms */ /* Uint: ms */
# ifndef LOW_BAT_LED_BLINK_PERIOD #ifndef LOW_BAT_LED_BLINK_PERIOD
# define LOW_BAT_LED_BLINK_PERIOD 1000 # define LOW_BAT_LED_BLINK_PERIOD 1000
# endif
# ifndef LOW_BAT_LED_BLINK_DURATION
# define LOW_BAT_LED_BLINK_DURATION 10000
# endif
#endif #endif
#ifdef LOW_BAT_IND_INDEX #ifndef LOW_BAT_LED_BLINK_TIMES
/* Uint: ms */ # define LOW_BAT_LED_BLINK_TIMES 5
# ifndef LOW_BAT_LED_BLINK_PERIOD #endif
# define LOW_BAT_LED_BLINK_PERIOD 500
# endif
# ifndef LOW_BAT_LED_BLINK_TIMES #ifndef LOW_BAT_LED_TRIG_INTERVAL
# define LOW_BAT_LED_BLINK_TIMES 3 # define LOW_BAT_LED_TRIG_INTERVAL 30000
# endif #endif
# ifndef LOW_BAT_LED_TRIG_INTERVAL #if ((defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)) && defined(LOW_BAT_IND_INDEX))
# define LOW_BAT_LED_TRIG_INTERVAL 30000 # define SPACE_KEY_LOW_BAT_IND
# endif
#endif #endif
#if BT_HOST_MAX_COUNT > 6 #if BT_HOST_MAX_COUNT > 6
# pragma error("HOST_COUNT max value is 6") # pragma error("HOST_COUNT max value is 6")
#endif #endif
typedef enum { INDICATOR_NONE, INDICATOR_OFF, INDICATOR_ON, INDICATOR_ON_OFF, INDICATOR_BLINK, INDICATOR_LAST } indicator_type_t; typedef enum {
INDICATOR_NONE,
INDICATOR_OFF,
INDICATOR_ON,
INDICATOR_ON_OFF,
INDICATOR_BLINK,
INDICATOR_LAST,
} indicator_type_t;
typedef struct { typedef struct {
indicator_type_t type; indicator_type_t type;
@ -98,6 +96,7 @@ typedef struct {
void indicator_init(void); void indicator_init(void);
void indicator_set(wt_state_t state, uint8_t host_index); void indicator_set(wt_state_t state, uint8_t host_index);
void indicator_set_backlit_timeout(uint32_t time);
void indicator_backlight_timer_reset(bool enable); void indicator_backlight_timer_reset(bool enable);
bool indicator_hook_key(uint16_t keycode); bool indicator_hook_key(uint16_t keycode);
void indicator_enable(void); void indicator_enable(void);
@ -106,12 +105,6 @@ void indicator_stop(void);
void indicator_eeconfig_reload(void); void indicator_eeconfig_reload(void);
bool indicator_is_enabled(void); bool indicator_is_enabled(void);
bool indicator_is_running(void); bool indicator_is_running(void);
#ifdef BAT_LOW_LED_PIN
void indicator_battery_low_enable(bool enable); void indicator_battery_low_enable(bool enable);
#endif
#if defined(LOW_BAT_IND_INDEX)
void indicator_battery_low_backlit_enable(bool enable);
#endif
void indicator_task(void); void indicator_task(void);

View File

@ -100,7 +100,7 @@ void wireless_enter_reset_kb(uint8_t reason) {
lkbt51_param_init(); lkbt51_param_init();
} }
void wireless_enter_disconnected_kb(uint8_t host_idx) { void wireless_enter_disconnected_kb(uint8_t host_idx, uint8_t reason) {
/* CKBT51 bluetooth module boot time is slower, it enters disconnected after boot, /* CKBT51 bluetooth module boot time is slower, it enters disconnected after boot,
so we place initialization here. */ so we place initialization here. */
if (firstDisconnect && timer_read32() < 1000) { if (firstDisconnect && timer_read32() < 1000) {

View File

@ -25,9 +25,9 @@
extern void factory_test_send(uint8_t* payload, uint8_t length); extern void factory_test_send(uint8_t* payload, uint8_t length);
# ifndef RAW_EPSIZE #ifndef RAW_EPSIZE
# define RAW_EPSIZE 32 # define RAW_EPSIZE 32
# endif #endif
#ifndef SPI_SCK_PIN #ifndef SPI_SCK_PIN
# define SPI_SCK_PIN A5 # define SPI_SCK_PIN A5
@ -147,6 +147,7 @@ static uint8_t reg_offset = 0xFF;
static uint8_t expect_len = 22; static uint8_t expect_len = 22;
static uint16_t connection_interval = 1; static uint16_t connection_interval = 1;
static uint32_t wake_time; static uint32_t wake_time;
static uint32_t factory_reset = 0;
// clang-format off // clang-format off
wt_func_t wireless_transport = { wt_func_t wireless_transport = {
@ -434,6 +435,8 @@ void lkbt51_disconnect(void) {
payload[i++] = LKBT51_CMD_DISCONNECT; payload[i++] = LKBT51_CMD_DISCONNECT;
payload[i++] = 0; // Sleep mode payload[i++] = 0; // Sleep mode
if (WT_DRIVER.state != SPI_READY)
spiStart(&WT_DRIVER, &spicfg);
spiSelect(&SPID1); spiSelect(&SPID1);
wait_ms(30); wait_ms(30);
// spiUnselect(&SPID1); // spiUnselect(&SPID1);
@ -539,6 +542,7 @@ void lkbt51_factory_reset(uint8_t p2p4g_clr_msk) {
lkbt51_wake(); lkbt51_wake();
lkbt51_send_cmd(payload, i, false, false); lkbt51_send_cmd(payload, i, false, false);
factory_reset = timer_read32();
} }
void lkbt51_int_pin_test(bool enable) { void lkbt51_int_pin_test(bool enable) {
@ -791,6 +795,10 @@ void lkbt51_task(void) {
break; break;
case LKBT51_DISCONNECTED: case LKBT51_DISCONNECTED:
event.evt_type = EVT_DISCONNECTED; event.evt_type = EVT_DISCONNECTED;
if (factory_reset && timer_elapsed32(factory_reset) < 3000) {
factory_reset = 0;
event.data = 1;
}
break; break;
case LKBT51_PINCODE_ENTRY: case LKBT51_PINCODE_ENTRY:
event.evt_type = EVT_BT_PINCODE_ENTRY; event.evt_type = EVT_BT_PINCODE_ENTRY;

View File

@ -140,12 +140,6 @@ void set_transport(transport_t new_transport) {
p24g_transport_enable(false); p24g_transport_enable(false);
wireless_disconnect(); wireless_disconnect();
lpm_timer_stop(); lpm_timer_stop();
#ifdef NKRO_ENABLE
# if defined(WIRELESS_NKRO_ENABLE)
nkro.bluetooth = keymap_config.nkro;
# endif
keymap_config.nkro = nkro.usb;
#endif
break; break;
case TRANSPORT_BLUETOOTH: case TRANSPORT_BLUETOOTH:
@ -154,14 +148,6 @@ void set_transport(transport_t new_transport) {
bt_transport_enable(true); bt_transport_enable(true);
usb_transport_enable(false); usb_transport_enable(false);
lpm_timer_reset(); lpm_timer_reset();
#if defined(NKRO_ENABLE)
nkro.usb = keymap_config.nkro;
# if defined(WIRELESS_NKRO_ENABLE)
keymap_config.nkro = nkro.bluetooth;
# else
keymap_config.nkro = FALSE;
# endif
#endif
break; break;
case TRANSPORT_P2P4: case TRANSPORT_P2P4:
@ -170,14 +156,6 @@ void set_transport(transport_t new_transport) {
p24g_transport_enable(true); p24g_transport_enable(true);
usb_transport_enable(false); usb_transport_enable(false);
lpm_timer_reset(); lpm_timer_reset();
#if defined(NKRO_ENABLE)
nkro.usb = keymap_config.nkro;
# if defined(WIRELESS_NKRO_ENABLE)
keymap_config.nkro = nkro.bluetooth;
# else
keymap_config.nkro = FALSE;
# endif
#endif
break; break;
default: default:
@ -244,7 +222,11 @@ void usb_remote_wakeup(void) {
/* Do this in the suspended state */ /* Do this in the suspended state */
suspend_power_down(); // on AVR this deep sleeps for 15ms suspend_power_down(); // on AVR this deep sleeps for 15ms
/* Remote wakeup */ /* Remote wakeup */
if (suspend_wakeup_condition()) { if (suspend_wakeup_condition()
#ifdef ENCODER_ENABLE
|| encoder_read()
#endif
) {
usbWakeupHost(&USB_DRIVER); usbWakeupHost(&USB_DRIVER);
wait_ms(300); wait_ms(300);
#ifdef MOUSEKEY_ENABLE #ifdef MOUSEKEY_ENABLE

View File

@ -227,20 +227,19 @@ static void wireless_enter_connected(uint8_t host_idx) {
#endif #endif
wireless_enter_connected_kb(host_idx); wireless_enter_connected_kb(host_idx);
#ifdef BAT_LOW_LED_PIN
if (battery_is_empty()) { if (battery_is_empty()) {
indicator_battery_low_enable(true); indicator_battery_low_enable(true);
} }
#endif
if (wireless_transport.update_bat_level) wireless_transport.update_bat_level(battery_get_percentage()); if (wireless_transport.update_bat_level) wireless_transport.update_bat_level(battery_get_percentage());
lpm_timer_reset();
} }
/* Enters disconnected state. Upon entering this state we perform the following actions: /* Enters disconnected state. Upon entering this state we perform the following actions:
* - change state to DISCONNECTED * - change state to DISCONNECTED
* - set disconnected indication * - set disconnected indication
*/ */
static void wireless_enter_disconnected(uint8_t host_idx) { static void wireless_enter_disconnected(uint8_t host_idx, uint8_t reason) {
kc_printf("wireless_disconnected %d\n\r", host_idx); kc_printf("wireless_disconnected %d, %d\n\r", host_idx, reason);
uint8_t previous_state = wireless_state; uint8_t previous_state = wireless_state;
led_state = 0; led_state = 0;
@ -252,20 +251,19 @@ static void wireless_enter_disconnected(uint8_t host_idx) {
if (previous_state == WT_CONNECTED) { if (previous_state == WT_CONNECTED) {
lpm_timer_reset(); lpm_timer_reset();
indicator_set(WT_SUSPEND, host_idx); indicator_set(WT_SUSPEND, host_idx);
} else } else {
indicator_set(wireless_state, host_idx); indicator_set(wireless_state, host_idx);
if (reason && (get_transport() & TRANSPORT_WIRELESS))
indicator_set_backlit_timeout(DISCONNECTED_BACKLIGHT_DISABLE_TIMEOUT*1000);
}
#ifndef DISABLE_REPORT_BUFFER #ifndef DISABLE_REPORT_BUFFER
report_buffer_init(); report_buffer_init();
#endif #endif
retry = 0; retry = 0;
wireless_enter_disconnected_kb(host_idx); wireless_enter_disconnected_kb(host_idx, reason);
#ifdef BAT_LOW_LED_PIN
indicator_battery_low_enable(false); indicator_battery_low_enable(false);
#endif
#if defined(LOW_BAT_IND_INDEX)
indicator_battery_low_backlit_enable(false);
#endif
} }
/* Enter pin code entry state. */ /* Enter pin code entry state. */
@ -294,18 +292,15 @@ static void wireless_enter_sleep(void) {
kc_printf("wireless_enter_sleep %d\n\r", wireless_state); kc_printf("wireless_enter_sleep %d\n\r", wireless_state);
led_state = 0; led_state = 0;
if (wireless_state == WT_PARING) {
if (wireless_state == WT_CONNECTED || wireless_state == WT_PARING) {
wireless_state = WT_SUSPEND; wireless_state = WT_SUSPEND;
kc_printf("WT_SUSPEND\n\r"); kc_printf("WT_SUSPEND\n\r");
lpm_timer_reset();
wireless_enter_sleep_kb(); wireless_enter_sleep_kb();
indicator_set(wireless_state, 0); indicator_set(wireless_state, 0);
#ifdef BAT_LOW_LED_PIN
indicator_battery_low_enable(false); indicator_battery_low_enable(false);
#endif
#if defined(LOW_BAT_IND_INDEX)
indicator_battery_low_backlit_enable(false);
#endif
} }
} }
@ -313,7 +308,7 @@ __attribute__((weak)) void wireless_enter_reset_kb(uint8_t reason) {}
__attribute__((weak)) void wireless_enter_discoverable_kb(uint8_t host_idx) {} __attribute__((weak)) void wireless_enter_discoverable_kb(uint8_t host_idx) {}
__attribute__((weak)) void wireless_enter_reconnecting_kb(uint8_t host_idx) {} __attribute__((weak)) void wireless_enter_reconnecting_kb(uint8_t host_idx) {}
__attribute__((weak)) void wireless_enter_connected_kb(uint8_t host_idx) {} __attribute__((weak)) void wireless_enter_connected_kb(uint8_t host_idx) {}
__attribute__((weak)) void wireless_enter_disconnected_kb(uint8_t host_idx) {} __attribute__((weak)) void wireless_enter_disconnected_kb(uint8_t host_idx, uint8_t reason) {}
__attribute__((weak)) void wireless_enter_bluetooth_pin_code_entry_kb(void) {} __attribute__((weak)) void wireless_enter_bluetooth_pin_code_entry_kb(void) {}
__attribute__((weak)) void wireless_exit_bluetooth_pin_code_entry_kb(void) {} __attribute__((weak)) void wireless_exit_bluetooth_pin_code_entry_kb(void) {}
__attribute__((weak)) void wireless_enter_sleep_kb(void) {} __attribute__((weak)) void wireless_enter_sleep_kb(void) {}
@ -434,12 +429,8 @@ void wireless_send_extra(report_extra_t *report) {
} }
void wireless_low_battery_shutdown(void) { void wireless_low_battery_shutdown(void) {
#ifdef BAT_LOW_LED_PIN
indicator_battery_low_enable(false); indicator_battery_low_enable(false);
#endif
#if defined(LOW_BAT_IND_INDEX)
indicator_battery_low_backlit_enable(false);
#endif
report_buffer_init(); report_buffer_init();
clear_keyboard(); // clear_keyboard(); //
@ -483,7 +474,7 @@ void wireless_event_task(void) {
wireless_enter_reconnecting(event.params.hostIndex); wireless_enter_reconnecting(event.params.hostIndex);
break; break;
case EVT_DISCONNECTED: case EVT_DISCONNECTED:
wireless_enter_disconnected(event.params.hostIndex); wireless_enter_disconnected(event.params.hostIndex, event.data);
break; break;
case EVT_BT_PINCODE_ENTRY: case EVT_BT_PINCODE_ENTRY:
wireless_enter_bluetooth_pin_code_entry(); wireless_enter_bluetooth_pin_code_entry();
@ -537,16 +528,9 @@ bool process_record_wireless(uint16_t keycode, keyrecord_t *record) {
if (get_transport() & TRANSPORT_WIRELESS) { if (get_transport() & TRANSPORT_WIRELESS) {
lpm_timer_reset(); lpm_timer_reset();
#if defined(BAT_LOW_LED_PIN) || defined(LOW_BAT_IND_INDEX)
if (battery_is_empty() && wireless_get_state() == WT_CONNECTED && record->event.pressed) { if (battery_is_empty() && wireless_get_state() == WT_CONNECTED && record->event.pressed) {
# if defined(BAT_LOW_LED_PIN)
indicator_battery_low_enable(true); indicator_battery_low_enable(true);
# endif
# if defined(LOW_BAT_IND_INDEX)
indicator_battery_low_backlit_enable(true);
# endif
} }
#endif
} }
if (!process_record_keychron_wireless(keycode, record)) return false; if (!process_record_keychron_wireless(keycode, record)) return false;

View File

@ -84,7 +84,7 @@ void wireless_enter_reset_kb(uint8_t reason);
void wireless_enter_discoverable_kb(uint8_t host_idx); void wireless_enter_discoverable_kb(uint8_t host_idx);
void wireless_enter_reconnecting_kb(uint8_t host_idx); void wireless_enter_reconnecting_kb(uint8_t host_idx);
void wireless_enter_connected_kb(uint8_t host_idx); void wireless_enter_connected_kb(uint8_t host_idx);
void wireless_enter_disconnected_kb(uint8_t host_idx); void wireless_enter_disconnected_kb(uint8_t host_idx, uint8_t reason);
void wireless_enter_bluetooth_pin_code_entry_kb(void); void wireless_enter_bluetooth_pin_code_entry_kb(void);
void wireless_exit_bluetooth_pin_code_entry_kb(void); void wireless_exit_bluetooth_pin_code_entry_kb(void);
void wireless_enter_sleep_kb(void); void wireless_enter_sleep_kb(void);

View File

@ -41,4 +41,5 @@ typedef struct {
uint8_t protocol; /* Parameters to EVT_HID_SET_PROTOCOL event */ uint8_t protocol; /* Parameters to EVT_HID_SET_PROTOCOL event */
uint8_t interval; /* Parameters to EVT_CONECTION_INTERVAL event */ uint8_t interval; /* Parameters to EVT_CONECTION_INTERVAL event */
} params; } params;
uint8_t data;
} wireless_event_t; } wireless_event_t;

View File

@ -1,7 +1,7 @@
{ {
"usb": { "usb": {
"pid": "0x0810", "pid": "0x0810",
"device_version": "1.0.0" "device_version": "1.0.2"
}, },
"layouts": { "layouts": {
"LAYOUT_ansi_82": { "LAYOUT_ansi_82": {