Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 2b79bad

Browse files
author
iwahdan88
committed
esp32/modbt: Add API to Enable/Disable bt modem Sleep
1 parent b6dd783 commit 2b79bad

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

esp32/mods/modbt.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,45 @@ STATIC mp_obj_t bt_isscanning(mp_obj_t self_in) {
891891
}
892892
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bt_isscanning_obj, bt_isscanning);
893893

894+
STATIC mp_obj_t bt_modem_sleep(mp_uint_t n_args, const mp_obj_t *args) {
895+
896+
bt_obj_t *self = args[0];
897+
/* Modem sleep APIs shall not be called before bt_controller_enable() */
898+
if(self->init)
899+
{
900+
if(n_args > 1)
901+
{
902+
if(mp_obj_is_true(args[1]))
903+
{
904+
/* Enable Modem Sleep */
905+
esp_bt_sleep_enable();
906+
}
907+
else
908+
{
909+
/* Disable Modem Sleep */
910+
esp_bt_sleep_disable();
911+
/* Wakeup the modem is it is sleeping */
912+
if (esp_bt_controller_is_sleeping())
913+
{
914+
esp_bt_controller_wakeup_request();
915+
}
916+
}
917+
}
918+
else
919+
{
920+
/* return modem sleep status */
921+
return mp_obj_new_bool(esp_bt_controller_is_sleeping());
922+
}
923+
}
924+
else
925+
{
926+
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "BLE module not initialized"));
927+
}
928+
929+
return mp_const_none;
930+
}
931+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bt_modem_sleep_obj, 1, 2, bt_modem_sleep);
932+
894933
STATIC mp_obj_t bt_stop_scan(mp_obj_t self_in) {
895934
if (bt_obj.scanning) {
896935
esp_ble_gap_stop_scanning();
@@ -1558,6 +1597,7 @@ STATIC const mp_map_elem_t bt_locals_dict_table[] = {
15581597
{ MP_OBJ_NEW_QSTR(MP_QSTR_callback), (mp_obj_t)&bt_callback_obj },
15591598
{ MP_OBJ_NEW_QSTR(MP_QSTR_events), (mp_obj_t)&bt_events_obj },
15601599
{ MP_OBJ_NEW_QSTR(MP_QSTR_disconnect_client), (mp_obj_t)&bt_gatts_disconnect_client_obj },
1600+
{ MP_OBJ_NEW_QSTR(MP_QSTR_modem_sleep), (mp_obj_t)&bt_modem_sleep_obj },
15611601

15621602
// exceptions
15631603
{ MP_OBJ_NEW_QSTR(MP_QSTR_timeout), (mp_obj_t)&mp_type_TimeoutError },

0 commit comments

Comments
 (0)