Skip to content

Add ability to sleep until an alarm #2795

Description

@tannewt

#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.

Activity

  1. added this to the Long term milestone on Apr 21, 2020
  2. tannewt commented on Sep 17, 2020

    @tannewt
    MemberAuthor

    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]

  3. dhalbert commented on Nov 18, 2020

    @dhalbert
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions