Skip to content

Added deep and light sleep functions #31

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

Merged
merged 7 commits into from
Dec 4, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions adafruit_magtag/magtag.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,10 @@ def set_text(self, val, index=0, auto_refresh=True):
if auto_refresh:
self.refresh()

def enter_deep_sleep(self, sleep_time):
def enter_deep_sleep_and_restart(self, sleep_time):
"""
Enter deep sleep and restart the program after a certain amount of time
Stops the current program and enters deep sleep. The program is restarted from the beginning
after a certain period of time.

:param float sleep_time: The amount of time to sleep in seconds

Expand All @@ -321,12 +322,13 @@ def enter_deep_sleep(self, sleep_time):

def enter_light_sleep(self, sleep_time):
"""
Enter light sleep and resume the program after a certain amount of time
Enter light sleep and resume the program after a certain period of time.

:param float sleep_time: The amount of time to sleep in seconds

"""
if self._alarm:
neopixel_values = self.peripherals.neopixels
neopixel_state = self.peripherals.neopixel_disable
self.peripherals.neopixel_disable = True
speaker_state = self.peripherals.speaker_disable
Expand All @@ -335,9 +337,10 @@ def enter_light_sleep(self, sleep_time):
monotonic_time=time.monotonic() + sleep_time
)
self._alarm.light_sleep_until_alarms(pause)

self.peripherals.neopixel_disable = neopixel_state
self.peripherals.speaker_disable = speaker_state
for i in range(4):
self.peripherals.neopixels[i] = neopixel_values[i]
gc.collect()
else:
raise NotImplementedError(
Expand Down