@@ -312,28 +312,68 @@ def set_text_color(self, color, index=0):
312
312
if self ._text [index ]["label" ] is not None :
313
313
self ._text [index ]["label" ].color = color
314
314
315
- def exit_and_deep_sleep (self , sleep_time ):
315
+ def create_time_alarm (self , sleep_time ):
316
316
"""
317
- Stops the current program and enters deep sleep. The program is restarted from the beginning
318
- after a certain period of time.
319
-
320
- See https://circuitpython.readthedocs.io/en/latest/shared-bindings/alarm/index.html for more
321
- details.
317
+ Create a TimeAlarm based on the specified amount of delay
322
318
323
319
:param float sleep_time: The amount of time to sleep in seconds
324
320
325
321
"""
326
322
if self ._alarm :
327
- pause = self ._alarm .time .TimeAlarm (
323
+ return self ._alarm .time .TimeAlarm (
328
324
monotonic_time = time .monotonic () + sleep_time
329
325
)
330
- self ._alarm .exit_and_deep_sleep_until_alarms (pause )
331
- else :
332
- raise NotImplementedError (
333
- "Deep sleep not supported. Make sure you have the latest CircuitPython."
334
- )
326
+ raise NotImplementedError (
327
+ "Alarms not supported. Make sure you have the latest CircuitPython."
328
+ )
329
+
330
+ def create_pin_alarm (self , pin , value , edge = False , pull = False ):
331
+ """
332
+ Create a PinAlarm that is triggered when the pin has a specific value
333
+
334
+ :param microcontroller.Pin pin: The trigger pin.
335
+ :param bool value: The value on which to trigger.
336
+ :param bool edge: Trigger only when there is a transition.
337
+ :param bool pull: Enable a pull-up or pull-down for the ``pin``.
335
338
336
- def enter_light_sleep (self , sleep_time ):
339
+ """
340
+ if self ._alarm :
341
+ return self ._alarm .time .PinAlarm (pin , value , edge , pull )
342
+ raise NotImplementedError (
343
+ "Alarms not supported. Make sure you have the latest CircuitPython."
344
+ )
345
+
346
+ def create_touch_alarm (self , pin ):
347
+ """
348
+ Create a TouchAlarm that is triggered when the pin is touched.
349
+
350
+ :param microcontroller.Pin pin: The trigger pin.
351
+ """
352
+ if self ._alarm :
353
+ return self ._alarm .time .TouchAlarm (pin )
354
+ raise NotImplementedError (
355
+ "Alarms not supported. Make sure you have the latest CircuitPython."
356
+ )
357
+
358
+ def exit_and_deep_sleep (self , alarms ):
359
+ """
360
+ Stops the current program and enters deep sleep. The program is restarted from the beginning
361
+ after the alarm or alarms are triggered.
362
+
363
+ See https://circuitpython.readthedocs.io/en/latest/shared-bindings/alarm/index.html for more
364
+ details.
365
+
366
+ :param float alarms: The alarm or alarms to use as a trigger
367
+
368
+ """
369
+
370
+ # For backwards compatibility
371
+ if isinstance (alarms , (float , int )):
372
+ alarms = self .create_time_alarm (alarms )
373
+
374
+ self ._alarm .exit_and_deep_sleep_until_alarms (alarms )
375
+
376
+ def enter_light_sleep (self , alarms ):
337
377
"""
338
378
Enter light sleep and resume the program after a certain period of time.
339
379
@@ -343,15 +383,11 @@ def enter_light_sleep(self, sleep_time):
343
383
:param float sleep_time: The amount of time to sleep in seconds
344
384
345
385
"""
346
- if self ._alarm :
347
- pause = self ._alarm .time .TimeAlarm (
348
- monotonic_time = time .monotonic () + sleep_time
349
- )
350
- self ._alarm .light_sleep_until_alarms (pause )
351
- else :
352
- raise NotImplementedError (
353
- "Hardware light sleep not supported. Make sure you have the latest CircuitPython."
354
- )
386
+ # For backwards compatibility
387
+ if isinstance (alarms , (float , int )):
388
+ alarms = self .create_time_alarm (alarms )
389
+
390
+ self ._alarm .light_sleep_until_alarms (alarms )
355
391
356
392
def _fetch_set_text (self , val , index = 0 ):
357
393
self .set_text (val , index = index )
0 commit comments