mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-07 09:55:45 +00:00
clarify event for Bluetooth status bar icon
This commit is contained in:
parent
b360b6ad92
commit
6ee849a7da
32
src/daemon.c
32
src/daemon.c
@ -142,22 +142,38 @@ static int daemon_client_handler(connection_t *connection, uint16_t packet_type,
|
||||
}
|
||||
|
||||
static void daemon_event_handler(uint8_t *packet, uint16_t size){
|
||||
// local cache
|
||||
static HCI_STATE hci_state = HCI_STATE_OFF;
|
||||
static int num_connections = 0;
|
||||
|
||||
uint8_t update_status = 0;
|
||||
|
||||
// handle state event
|
||||
if (packet[0] == BTSTACK_EVENT_STATE){
|
||||
if (packet[2] == HCI_STATE_WORKING) {
|
||||
bluetooth_status_handler(BLUETOOTH_ON);
|
||||
switch (packet[0]) {
|
||||
case BTSTACK_EVENT_STATE:
|
||||
hci_state = packet[2];
|
||||
update_status = 1;
|
||||
break;
|
||||
case BTSTACK_EVENT_NR_CONNECTIONS_CHANGED:
|
||||
num_connections = packet[2];
|
||||
update_status = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (packet[2] == HCI_STATE_OFF) {
|
||||
|
||||
// choose full bluetooth state
|
||||
if (update_status) {
|
||||
if (hci_state != HCI_STATE_WORKING) {
|
||||
bluetooth_status_handler(BLUETOOTH_OFF);
|
||||
}
|
||||
}
|
||||
if (packet[0] == BTSTACK_EVENT_NR_CONNECTIONS_CHANGED){
|
||||
if (packet[2]) {
|
||||
} else {
|
||||
if (num_connections) {
|
||||
bluetooth_status_handler(BLUETOOTH_ACTIVE);
|
||||
} else {
|
||||
bluetooth_status_handler(BLUETOOTH_ON);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// forward event to clients
|
||||
socket_connection_send_packet_all(HCI_EVENT_PACKET, 0, packet, size);
|
||||
|
Loading…
Reference in New Issue
Block a user