power down Bluetooth on sleep notifcation / turn on, if clients are connected

This commit is contained in:
matthias.ringwald 2011-01-07 21:03:58 +00:00
parent b546ac5469
commit 720d0070fa
2 changed files with 23 additions and 18 deletions

View File

@ -22,7 +22,8 @@ NEXT:
- DONE: handle HCI_POWER_ON and HCI_POWER_OFF in existing 4 states - DONE: handle HCI_POWER_ON and HCI_POWER_OFF in existing 4 states
- DONE: store data of remote db on every change - DONE: store data of remote db on every change
- DONE: don't stop BTdaemon on power down/client disconnect - DONE: don't stop BTdaemon on power down/client disconnect
- handle transition for HCI_POWER_SLEEP and all HCI state transitions - DONE: handle transition for HCI_POWER_SLEEP and all HCI state transitions
- DONE: power down Bluetooth on sleep notifcation / turn on, if clients are connected
- decide on configure flags - decide on configure flags
- clean up components - clean up components

View File

@ -141,12 +141,7 @@ io_connect_t root_port; // a reference to the Root Power Domain IOService
void void
MySleepCallBack( void * refCon, io_service_t service, natural_t messageType, void * messageArgument ) MySleepCallBack( void * refCon, io_service_t service, natural_t messageType, void * messageArgument )
{ {
static int cancelCounter = 3; printf( "messageType %08lx, arg %08lx, counter %u\n", (long unsigned int)messageType, (long unsigned int)messageArgument);
printf( "messageType %08lx, arg %08lx, counter %u\n",
(long unsigned int)messageType,
(long unsigned int)messageArgument, cancelCounter );
switch ( messageType ) switch ( messageType )
{ {
@ -161,14 +156,10 @@ MySleepCallBack( void * refCon, io_service_t service, natural_t messageType, voi
or IOCancelPowerChange, the system will wait 30 seconds then go to sleep. or IOCancelPowerChange, the system will wait 30 seconds then go to sleep.
*/ */
//Uncomment to cancel idle sleep // Uncomment to cancel idle sleep
if (cancelCounter) { // IOCancelPowerChange( root_port, (long)messageArgument );
cancelCounter--; // we will allow idle sleep
IOCancelPowerChange( root_port, (long)messageArgument ); IOAllowPowerChange( root_port, (long)messageArgument );
} else {
// we will allow idle sleep
IOAllowPowerChange( root_port, (long)messageArgument );
}
break; break;
case kIOMessageSystemWillSleep: case kIOMessageSystemWillSleep:
@ -180,11 +171,21 @@ MySleepCallBack( void * refCon, io_service_t service, natural_t messageType, voi
however the system WILL still go to sleep. however the system WILL still go to sleep.
*/ */
IOAllowPowerChange( root_port, (long)messageArgument ); // let's sleep
hci_power_control(HCI_POWER_SLEEP);
// power control only starts falling asleep, count on the 30 second delay
// IOAllowPowerChange( root_port, (long)messageArgument );
break; break;
case kIOMessageSystemWillPowerOn: case kIOMessageSystemWillPowerOn:
//System has started the wake up process... //System has started the wake up process...
// assume that all clients use Bluetooth -> if connection, start Bluetooth
if (num_client_connections) {
hci_power_control(HCI_POWER_ON);
}
break; break;
case kIOMessageSystemHasPoweredOn: case kIOMessageSystemHasPoweredOn:
@ -206,6 +207,8 @@ static hci_uart_config_t config;
static timer_source_t timeout; static timer_source_t timeout;
static uint8_t timeout_active = 0; static uint8_t timeout_active = 0;
static int num_client_connections = 0;
static void dummy_bluetooth_status_handler(BLUETOOTH_STATE state){ static void dummy_bluetooth_status_handler(BLUETOOTH_STATE state){
printf("Bluetooth status: %u\n", state); printf("Bluetooth status: %u\n", state);
}; };
@ -328,12 +331,13 @@ static int daemon_client_handler(connection_t *connection, uint16_t packet_type,
l2cap_close_connection(connection); l2cap_close_connection(connection);
break; break;
case DAEMON_NR_CONNECTIONS_CHANGED: case DAEMON_NR_CONNECTIONS_CHANGED:
printf("Nr Connections changed, new %u\n", data[1]); num_client_connections = data[1];
printf("Nr Connections changed, new %u\n",num_client_connections);
if (timeout_active) { if (timeout_active) {
run_loop_remove_timer(&timeout); run_loop_remove_timer(&timeout);
timeout_active = 0; timeout_active = 0;
} }
if (!data[1]) { if (!num_client_connections) {
run_loop_set_timer(&timeout, DAEMON_NO_CONNECTION_TIMEOUT); run_loop_set_timer(&timeout, DAEMON_NO_CONNECTION_TIMEOUT);
run_loop_add_timer(&timeout); run_loop_add_timer(&timeout);
timeout_active = 1; timeout_active = 1;