diff --git a/drivers/tidal_helpers/tidal_helpers.c b/drivers/tidal_helpers/tidal_helpers.c index 9d750c8..a45807b 100644 --- a/drivers/tidal_helpers/tidal_helpers.c +++ b/drivers/tidal_helpers/tidal_helpers.c @@ -70,6 +70,16 @@ STATIC mp_obj_t tidal_helper_usb_connected() { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(tidal_helper_usb_connected_obj, tidal_helper_usb_connected); +STATIC mp_obj_t tidal_helper_usb_suspended() { + return tud_suspended() ? mp_const_true : mp_const_false; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(tidal_helper_usb_suspended_obj, tidal_helper_usb_suspended); + +STATIC mp_obj_t tidal_helper_usb_mounted() { + return tud_mounted() ? mp_const_true : mp_const_false; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(tidal_helper_usb_mounted_obj, tidal_helper_usb_mounted); + STATIC mp_obj_t tidal_esp_sleep_pd_config(mp_obj_t domain_obj, mp_obj_t option_obj) { esp_sleep_pd_domain_t domain = (esp_sleep_pd_domain_t)mp_obj_get_int(domain_obj); esp_sleep_pd_option_t option = (esp_sleep_pd_option_t)mp_obj_get_int(option_obj); @@ -379,6 +389,8 @@ STATIC const mp_rom_map_elem_t tidal_helpers_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ota) }, { MP_ROM_QSTR(MP_QSTR_get_variant), MP_ROM_PTR(&tidal_helper_get_variant_obj) }, { MP_ROM_QSTR(MP_QSTR_usb_connected), MP_ROM_PTR(&tidal_helper_usb_connected_obj) }, + { MP_ROM_QSTR(MP_QSTR_usb_suspended), MP_ROM_PTR(&tidal_helper_usb_suspended_obj) }, + { MP_ROM_QSTR(MP_QSTR_usb_mounted), MP_ROM_PTR(&tidal_helper_usb_mounted_obj) }, { MP_ROM_QSTR(MP_QSTR_esp_sleep_enable_gpio_wakeup), MP_ROM_PTR(&tidal_esp_sleep_enable_gpio_wakeup_obj) }, { MP_ROM_QSTR(MP_QSTR_esp_sleep_pd_config), MP_ROM_PTR(&tidal_esp_sleep_pd_config_obj) }, { MP_ROM_QSTR(MP_QSTR_gpio_wakeup), MP_ROM_PTR(&tidal_gpio_wakeup_obj) }, diff --git a/modules/app_launcher/__init__.py b/modules/app_launcher/__init__.py index ff5766c..a089e80 100644 --- a/modules/app_launcher/__init__.py +++ b/modules/app_launcher/__init__.py @@ -156,7 +156,7 @@ def update_title(self, redraw): if not get_scheduler().is_sleep_enabled(): title += "\nSLEEP DISABLED" pwr = tidal.CHARGE_DET.value() == 0 and 1 or 0 - conn = tidal_helpers.usb_connected() and 1 or 0 + conn = (tidal_helpers.usb_connected() and not tidal_helpers.usb_suspended()) and 1 or 0 if pwr or conn: title += f"\nUSB pwr={pwr} conn={conn}" if title != self.window.title: diff --git a/modules/scheduler.py b/modules/scheduler.py index 0cf9aef..3d3209c 100644 --- a/modules/scheduler.py +++ b/modules/scheduler.py @@ -178,10 +178,11 @@ def is_sleep_enabled(self): return self.sleep_enabled def can_sleep(self): + usb_connected = tidal_helpers.usb_connected() and not tidal_helpers.usb_suspended() return ( self.sleep_enabled and tidal_helpers.get_variant() != "devboard" and - not tidal_helpers.usb_connected() and + not usb_connected and not wifi.active() and time.ticks_ms() >= self.no_sleep_before )