Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion device/src/bt_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ void BtManager_StopBt() {
LOG_INF("OOB: Bluetooth stopped");
}

void BtManager_CheckLeftBleVsUart() {
if (DEVICE_IS_UHK80_LEFT) {
bool uartReady = Connections_IsReady(ConnectionId_UartRight);

if (uartReady) {
bool nusConnected = Peers[PeerIdRight].conn != NULL;
if (nusConnected) {
LOG_INF("Left: UART healthy and NUS up — disconnecting NUS to right");
bt_conn_disconnect(Peers[PeerIdRight].conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
}
} else {
BtManager_StartScanningAndAdvertisingAsync(false, "Left UART not ready — resume BLE");
}
}
}

void BtManager_StartScanningAndAdvertisingAsync(bool wasAggresive, const char* eventLabel) {
BT_TRACE_AND_ASSERT("bm4");
Expand Down Expand Up @@ -168,7 +183,7 @@ void BtManager_StartScanningAndAdvertising() {
}
}

bool leftShouldAdvertise = DEVICE_IS_UHK80_LEFT && Peers[PeerIdRight].conn == NULL;
bool leftShouldAdvertise = DEVICE_IS_UHK80_LEFT && Peers[PeerIdRight].conn == NULL && !DeviceState_IsTargetConnected(ConnectionTarget_Right);
bool rightShouldAdvertise = DEVICE_IS_UHK80_RIGHT && true;
bool shouldAdvertise = leftShouldAdvertise || rightShouldAdvertise;

Expand Down
2 changes: 2 additions & 0 deletions device/src/bt_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@
void BtManager_StartScanningAndAdvertisingAsync(bool wasAggresive, const char* eventLabel);
void BtManager_EnterMode(pairing_mode_t mode, bool toggle);

void BtManager_CheckLeftBleVsUart();

#endif // __BT_MANAGER_H__
8 changes: 8 additions & 0 deletions device/src/keyboard/uart_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "messenger.h"
#include "messenger_queue.h"
#include "device.h"
#include "bt_manager.h"
#include "debug.h"
#include "connections.h"
#include "resend.h"
Expand Down Expand Up @@ -210,6 +211,13 @@ static void updateConnectionState(uart_state_t *uartState) {
Connections_SetState(connectionId, newIsConnected ? ConnectionState_Ready : ConnectionState_Disconnected);
k_sem_give(&uartState->txBufferBusy);
k_sem_give(&uartState->core.txControlBusy);
if (DEVICE_IS_UHK80_LEFT) {
if (newIsConnected) {
EventScheduler_Reschedule( Timer_GetCurrentTime() + 10000, EventSchedulerEvent_CheckLeftBleVsUart, "Left UART up — schedule BLE vs UART check");
} else {
BtManager_CheckLeftBleVsUart();
}
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions right/src/event_scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ static void processEvt(event_scheduler_event_t evt)
case EventSchedulerEvent_KickHid:
#if DEVICE_IS_UHK80_RIGHT
BtConn_KickHid();
#endif
break;
case EventSchedulerEvent_CheckLeftBleVsUart:
#if DEVICE_IS_UHK80_LEFT
BtManager_CheckLeftBleVsUart();
#endif
break;
default:
Expand Down
1 change: 1 addition & 0 deletions right/src/event_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
EventSchedulerEvent_UnselectHostConnection,
EventSchedulerEvent_OneShotTimeout,
EventSchedulerEvent_KickHid,
EventSchedulerEvent_CheckLeftBleVsUart,
EventSchedulerEvent_Count
} event_scheduler_event_t;

Expand Down
Loading