8000 Add ability to sleep until an alarm · Issue #2795 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

Add ability to sleep until an alarm #2795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tannewt opened this issue Apr 21, 2020 · 2 comments
Closed

Add ability to sleep until an alarm #2795

tannewt opened this issue Apr 21, 2020 · 2 comments

Comments

@tannewt
Copy link
Member
tannewt commented Apr 21, 2020

#2685 only adds light sleep during time.sleep. We should add a new mechanic for sleeping until an alarm.

An alarm can be anything a microcontroller supports during sleep such as RTC alarm, pin change interrupt and comparator. The alarms should be in separate modules so that the microcontrollers can support different ones.

Then, one sleep_until_alarm() function can take any number of alarms. It will return the object that woke it up.

@tannewt
Copy link
Member Author
tannewt commented Sep 17, 2020

Here is an example:

import sleepio
import time
import alarm.pin
import alarm.time

pin0_alarm = alarm.pin.PinLevelAlarm(board.IO0, True, enable_pull=True)
time_alarm = alarm.pin.TimeAlarm(time.monotonic() + 10.0)

while True:
    # start with a light sleep until an alarm triggers.
    alarm = sleepio.sleep_until_alarm(pin0_alarm, time_alarm)
    # do something based on what alarmed
    if alarm == pin0_alarm:
        print("pin change")
    elif alarm == time_alarm:
        print("time out")

[Example updated for newer sleep API, see #2796]

@dhalbert
Copy link
Collaborator

Subsumed by #2795. Closing and will copy over the example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0