@@ -92,6 +92,13 @@ def __init__(
92
92
self ._json_path = None
93
93
self .json_path = json_path
94
94
95
+ try :
96
+ import alarm # pylint: disable=import-outside-toplevel
97
+
98
+ self ._alarm = alarm
99
+ except ImportError :
100
+ self ._alarm = None
101
+
95
102
self ._regexp_path = regexp_path
96
103
97
104
self .splash = self .graphics .splash
@@ -293,6 +300,59 @@ def set_text(self, val, index=0, auto_refresh=True):
293
300
if auto_refresh :
294
301
self .refresh ()
295
302
303
+ def exit_and_deep_sleep (self , sleep_time ):
304
+ """
305
+ Stops the current program and enters deep sleep. The program is restarted from the beginning
306
+ after a certain period of time.
307
+
308
+ See https://circuitpython.readthedocs.io/en/latest/shared-bindings/alarm/index.html for more
309
+ details.
310
+
311
+ :param float sleep_time: The amount of time to sleep in seconds
312
+
313
+ """
314
+ if self ._alarm :
315
+ self .peripherals .neopixel_disable = True
316
+ self .peripherals .speaker_disable = True
317
+ pause = self ._alarm .time .TimeAlarm (
318
+ monotonic_time = time .monotonic () + sleep_time
319
+ )
320
+ self ._alarm .exit_and_deep_sleep_until_alarms (pause )
321
+ else :
322
+ raise NotImplementedError (
323
+ "Deep sleep not supported. Make sure you have the latest CircuitPython."
324
+ )
325
+
326
+ def enter_light_sleep (self , sleep_time ):
327
+ """
328
+ Enter light sleep and resume the program after a certain period of time.
329
+
330
+ See https://circuitpython.readthedocs.io/en/latest/shared-bindings/alarm/index.html for more
331
+ details.
332
+
333
+ :param float sleep_time: The amount of time to sleep in seconds
334
+
335
+ """
336
+ if self ._alarm :
337
+ neopixel_values = self .peripherals .neopixels
338
+ neopixel_state = self .peripherals .neopixel_disable
339
+ self .peripherals .neopixel_disable = True
340
+ speaker_state = self .peripherals .speaker_disable
341
+ self .peripherals .speaker_disable = True
342
+ pause = self ._alarm .time .TimeAlarm (
343
+ monotonic_time = time .monotonic () + sleep_time
344
+ )
345
+ self ._alarm .light_sleep_until_alarms (pause )
346
+ self .peripherals .neopixel_disable = neopixel_state
347
+ self .peripherals .speaker_disable = speaker_state
348
+ for i in range (4 ):
349
+ self .peripherals .neopixels [i ] = neopixel_values [i ]
350
+ gc .collect ()
351
+ else :
352
+ raise NotImplementedError (
353
+ "Hardware light sleep not supported. Make sure you have the latest CircuitPython."
354
+ )
355
+
296
356
def get_local_time (self , location = None ):
297
357
"""Accessor function for get_local_time()"""
298
358
return self .network .get_local_time (location = location )
0 commit comments