From 6433aaa697ca515f09a9b8374b57d16045d5783e Mon Sep 17 00:00:00 2001 From: anschrammh Date: Thu, 20 Apr 2023 13:18:25 +0200 Subject: [PATCH] Preparing the ble_service to work in bt_controller sleep mode to save power. This will at the end be implemented in the W800_Smart_Watch ble_service module --- app/ble/ble_service.c | 2 ++ app/nano_shell_command.c | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/ble/ble_service.c b/app/ble/ble_service.c index d5b991b..04838a3 100644 --- a/app/ble/ble_service.c +++ b/app/ble/ble_service.c @@ -599,6 +599,8 @@ static int ble_gap_event_cb(struct ble_gap_event *event, void *arg) } //We call the state change callback if registered if(_ble_service_state_change_cb)_ble_service_state_change_cb(_ble_service_state); + + tls_bt_ctrl_sleep(false); } else { diff --git a/app/nano_shell_command.c b/app/nano_shell_command.c index 8a478aa..1e296c5 100644 --- a/app/nano_shell_command.c +++ b/app/nano_shell_command.c @@ -181,7 +181,8 @@ static void nus_data_rx_cb(const uint8_t *data, uint16_t length) gadget_bridge_parser_feed((const char *)data, length); gadget_bridge_parser_code_e code; while((code = gadget_bridge_parser_run()) == GADGET_BRIDGE_PARSER_CODE_PARSING); - shell_printf("Gadget bridge parser code : %s"NEW_LINE, gadget_bridge_parser_code_2_str(code)); + shell_printf("Gadget bridge parser code : %s"NEW_LINE, gadget_bridge_parser_code_2_str(code)); + tls_bt_ctrl_sleep(false); //shell_puts("#"NEW_LINE); } @@ -651,6 +652,18 @@ int _rtc(const shell_cmd_t *pcmd, int argc, char *const argv[]) return 0; } +void tls_bt_controller_sleep_enter_cb(uint32_t sleep_duration_ms) +{ + //shell_printf("BT CTRL sleep for %u"NEW_LINE, sleep_duration_ms); + //tls_bt_ctrl_wakeup(); +} + +void tls_bt_controller_sleep_exit_cb(void) +{ + //shell_printf("BT CTRL wakeup"NEW_LINE); + //tls_bt_ctrl_sleep(false); +} + int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[]) { if(argc > 1) @@ -668,6 +681,8 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[]) gadget_bridge_parser_register_event_callback(&(parser_event_cb)); ble_service_register_nus_data_rx_cb(&(nus_data_rx_cb)); ble_service_set_pairing_passkey(123456); + + tls_bt_register_sleep_callback(tls_bt_controller_sleep_enter_cb, tls_bt_controller_sleep_exit_cb); } } else if(strcmp(argv[1], "disable") == 0)