diff --git a/device/src/bt_conn.c b/device/src/bt_conn.c index 09b04302..0baf70d6 100644 --- a/device/src/bt_conn.c +++ b/device/src/bt_conn.c @@ -13,7 +13,6 @@ #include "keyboard/oled/screens/pairing_screen.h" #include "usb/usb.h" #include "keyboard/oled/widgets/widgets.h" -#include "power_mode.h" #define PeerCount 3 @@ -21,20 +20,14 @@ peer_t Peers[PeerCount] = { { .id = PeerIdLeft, .name = "left", - .isConnected = false, - .conn = NULL, }, { .id = PeerIdRight, .name = "right", - .isConnected = false, - .conn = NULL, }, { .id = PeerIdDongle, .name = "dongle", - .isConnected = false, - .conn = NULL, }, }; @@ -94,27 +87,12 @@ static void set_data_length_extension_params(struct bt_conn *conn) { } static void set_latency_params(struct bt_conn *conn) { - static const struct bt_le_conn_param rightActive = BT_LE_CONN_PARAM_INIT( - 6, 6, // keep it low, lowest allowed is 6 (7.5ms), lowest supported widely is 9 (11.25ms) - 10, // keeping it higher allows power saving on peripheral when there's nothing to send (keep it under 30 though) - 300 // connection timeout (*10ms) + static const struct bt_le_conn_param conn_params = BT_LE_CONN_PARAM_INIT( + 6, 9, // keep it low, lowest allowed is 6 (7.5ms), lowest supported widely is 9 (11.25ms) + 0, // keeping it higher allows power saving on peripheral when there's nothing to send (keep it under 30 though) + 100 // connection timeout (*10ms) ); - static const struct bt_le_conn_param rightSleep = BT_LE_CONN_PARAM_INIT( - 100, 100, - 10, // so this means a ping every 1.25s? - 300 - ); - static const struct bt_le_conn_param slave = BT_LE_CONN_PARAM_INIT( - 6, 100, - 10, - 300 - ); - int err; - if (DEVICE_IS_UHK80_RIGHT) { - err = bt_conn_le_param_update(conn, CurrentPowerMode >= PowerMode_Sleep ? &rightSleep : &rightActive); - } else { - err = bt_conn_le_param_update(conn, &slave); - } + int err = bt_conn_le_param_update(conn, &conn_params); if (err) { printk("LE latencies update failed: %d", err); } @@ -155,8 +133,6 @@ static void connected(struct bt_conn *conn, uint8_t err) { DeviceState_SetConnection(ConnectionId_BluetoothHid, ConnectionType_Bt); } } else { - Peers[peerId].conn = bt_conn_ref(conn); - set_latency_params(conn); set_data_length_extension_params(conn); @@ -204,7 +180,6 @@ static void disconnected(struct bt_conn *conn, uint8_t reason) { } if (peerId != PeerIdUnknown) { - bt_conn_unref(Peers[peerId].conn); Peers[peerId].isConnected = false; DeviceState_TriggerUpdate(); } else { @@ -212,16 +187,6 @@ static void disconnected(struct bt_conn *conn, uint8_t reason) { } } -void Bt_UpdatePowerModes() { - if (DEVICE_IS_UHK80_RIGHT) { - for (uint8_t peerId = 0; peerId < PeerCount; peerId++) { - if (Peers[peerId].isConnected && Peers[peerId].conn) { - set_latency_params(Peers[peerId].conn); - } - } - } -} - bool Bt_DeviceIsConnected(device_id_t deviceId) { switch (deviceId) { case DeviceId_Uhk80_Left: diff --git a/device/src/bt_conn.h b/device/src/bt_conn.h index 29c88a6f..f02328fb 100644 --- a/device/src/bt_conn.h +++ b/device/src/bt_conn.h @@ -22,7 +22,6 @@ typedef struct { uint8_t id; char name[PeerNameMaxLength + 1]; - struct bt_conn *conn; bt_addr_le_t addr; bool isConnected; } peer_t; @@ -33,7 +32,6 @@ char *GetPeerStringByConn(const struct bt_conn *conn); extern void bt_init(void); extern void num_comp_reply(uint8_t accept); - void Bt_UpdatePowerModes(); void Bt_SetDeviceConnected(device_id_t deviceId); bool Bt_DeviceIsConnected(uint8_t deviceId); diff --git a/device/src/keyboard/i2c.c b/device/src/keyboard/i2c.c index acd33779..30f77cb4 100644 --- a/device/src/keyboard/i2c.c +++ b/device/src/keyboard/i2c.c @@ -8,7 +8,6 @@ #include "legacy/slave_drivers/uhk_module_driver.h" #include "legacy/i2c.h" #include "keyboard/i2c.h" -#include "power_mode.h" // Thread definitions @@ -91,10 +90,6 @@ void i2cPoller() { if (masterTransferInProgress) { lastStatus = processMasterTransfer(); } - - if (CurrentPowerMode >= PowerMode_Sleep) { - k_msleep(100); - } } } diff --git a/device/src/keyboard/key_scanner.c b/device/src/keyboard/key_scanner.c index 72291fa2..5bef4fe6 100644 --- a/device/src/keyboard/key_scanner.c +++ b/device/src/keyboard/key_scanner.c @@ -21,7 +21,6 @@ #include "legacy/config_manager.h" #include "legacy/macros/keyid_parser.h" #include "attributes.h" -#include "power_mode.h" // Thread definitions @@ -150,11 +149,7 @@ static void scanKeys() { void keyScanner() { while (true) { scanKeys(); - if (CurrentPowerMode >= PowerMode_Sleep) { - k_msleep(100); - } else { - k_msleep(1); - } + k_msleep(1); } } diff --git a/device/src/state_sync.c b/device/src/state_sync.c index b4861313..44d60f64 100644 --- a/device/src/state_sync.c +++ b/device/src/state_sync.c @@ -22,7 +22,6 @@ #include #include "legacy/peripherals/merge_sensor.h" #include "power_mode.h" -#include "bt_conn.h" #define THREAD_STACK_SIZE 2000 #define THREAD_PRIORITY 5 @@ -326,10 +325,6 @@ static void receiveProperty(device_id_t src, state_sync_prop_id_t propId, const EventVector_Set(EventVector_LedMapUpdateNeeded); } break; - case StateSyncPropertyId_PowerMode: - // for both local and remote! - Bt_UpdatePowerModes(); - break; case StateSyncPropertyId_MergeSensor: break; default: diff --git a/right/src/power_mode.c b/right/src/power_mode.c index 85f390a3..0158d5cb 100644 --- a/right/src/power_mode.c +++ b/right/src/power_mode.c @@ -4,13 +4,11 @@ #include "led_manager.h" #ifdef __ZEPHYR__ - #include "state_sync.h" #include "device_state.h" #include "usb/usb.h" #else #include "slave_drivers/is31fl3xxx_driver.h" #include "usb_composite_device.h" - #include "stubs.h" #endif ATTR_UNUSED static bool usbAwake = false; @@ -45,9 +43,6 @@ void PowerMode_Update() { static void lightSleep() { CurrentPowerMode = PowerMode_LightSleep; -#ifdef __ZEPHYR__ - StateSync_UpdateProperty(StateSyncPropertyId_PowerMode, &CurrentPowerMode); -#endif EventVector_Set(EventVector_LedManagerFullUpdateNeeded); EventVector_WakeMain(); } @@ -63,9 +58,6 @@ static void deepSleep() { static void wake() { CurrentPowerMode = PowerMode_Awake; -#ifdef __ZEPHYR__ - StateSync_UpdateProperty(StateSyncPropertyId_PowerMode, &CurrentPowerMode); -#endif EventVector_Set(EventVector_LedManagerFullUpdateNeeded); EventVector_WakeMain(); } diff --git a/right/src/power_mode.h b/right/src/power_mode.h index fba992cc..c91f278c 100644 --- a/right/src/power_mode.h +++ b/right/src/power_mode.h @@ -1,5 +1,5 @@ -#ifndef __UHK_POWER_MODE_H__ -#define __UHK_POWER_MODE_H__ +#ifndef __POWER_MODE_H__ +#define __POWER_MODE_H__ // Includes: