mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-15 12:39:51 +00:00
disable page and inquiry scan when entering sleep mode
This commit is contained in:
parent
574e07e180
commit
89db417b22
33
src/hci.c
33
src/hci.c
@ -489,6 +489,13 @@ static void event_handler(uint8_t *packet, int size){
|
||||
}
|
||||
}
|
||||
|
||||
// help with BT sleep
|
||||
if (hci_stack.state == HCI_STATE_FALLING_ASLEEP
|
||||
&& hci_stack.substate == 1
|
||||
&& COMMAND_COMPLETE_EVENT(packet, hci_write_scan_enable)){
|
||||
hci_stack.substate++;
|
||||
}
|
||||
|
||||
hci_stack.packet_handler(HCI_EVENT_PACKET, packet, size);
|
||||
|
||||
// execute main loop
|
||||
@ -696,6 +703,7 @@ int hci_power_control(HCI_POWER_MODE power_mode){
|
||||
case HCI_POWER_SLEEP:
|
||||
// see hci_run
|
||||
hci_stack.state = HCI_STATE_FALLING_ASLEEP;
|
||||
hci_stack.substate = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -713,6 +721,7 @@ int hci_power_control(HCI_POWER_MODE power_mode){
|
||||
case HCI_POWER_SLEEP:
|
||||
// see hci_run
|
||||
hci_stack.state = HCI_STATE_FALLING_ASLEEP;
|
||||
hci_stack.substate = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -817,7 +826,7 @@ void hci_run(){
|
||||
hci_send_cmd(&hci_write_page_timeout, 0x6000);
|
||||
break;
|
||||
case 4:
|
||||
hci_send_cmd(&hci_write_scan_enable, 3); // 3 inq scan + page scan
|
||||
hci_send_cmd(&hci_write_scan_enable, 2); // page scan
|
||||
break;
|
||||
case 5:
|
||||
#ifndef EMBEDDED
|
||||
@ -866,9 +875,13 @@ void hci_run(){
|
||||
break;
|
||||
|
||||
case HCI_STATE_FALLING_ASLEEP:
|
||||
switch(hci_stack.substate) {
|
||||
case 0:
|
||||
log_dbg("HCI_STATE_FALLING_ASLEEP\n");
|
||||
// close all open connections
|
||||
connection = (hci_connection_t *) hci_stack.connections;
|
||||
if (connection){
|
||||
log_dbg("HCI_STATE_FALLING_ASLEEP, connection %u, handle %u\n", (int) connection, connection->con_handle);
|
||||
// send disconnect
|
||||
hci_send_cmd(&hci_disconnect, connection->con_handle, 0x13); // remote closed connection
|
||||
|
||||
@ -880,9 +893,25 @@ void hci_run(){
|
||||
return;
|
||||
}
|
||||
|
||||
log_dbg("HCI_STATE_HALTING, disabling inq & page scans\n");
|
||||
|
||||
// disable page and inquiry scan
|
||||
hci_send_cmd(&hci_write_scan_enable, 0); // none
|
||||
|
||||
// continue in next sub state
|
||||
hci_stack.substate++;
|
||||
break;
|
||||
case 1:
|
||||
// wait for command complete "hci_write_scan_enable" in event_handler();
|
||||
break;
|
||||
case 2:
|
||||
log_dbg("HCI_STATE_HALTING, calling sleep\n");
|
||||
// switch mode
|
||||
hci_power_control_sleep();
|
||||
hci_power_control_sleep(); // changes hci_stack.state to SLEEP
|
||||
hci_emit_state();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user