OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 |
| 3 """Tell system to suspend, and resume some number of seconds later. |
| 4 |
| 5 Use the RTC to generate a wakeup some number of seconds into the |
| 6 future, then go to sleep. Note that this module is not aware of |
| 7 the actual time when the system will suspend. Depending on other |
| 8 system activities, there may be several seconds between when this |
| 9 script runs until when the system actually goes to sleep. In fact |
| 10 that time may be after the wakeup has been scheduled, and the |
| 11 system may never wake up! It is up to the caller to make prudent |
| 12 decisions as to upper bound of delay before going to sleep, and to |
| 13 choose a wakeup time greater than this interval. |
| 14 """ |
| 15 |
| 16 import os, re, subprocess, sys |
| 17 import rtc, sys_power |
| 18 |
| 19 time_to_sleep = 30 |
| 20 if len(sys.argv) > 1: |
| 21 time_to_sleep = int(sys.argv[1]) |
| 22 |
| 23 if len(sys.argv) > 2: |
| 24 after_command = ' '.join(sys.argv[2:]) |
| 25 else: |
| 26 after_command = None |
| 27 |
| 28 rtc.set_wake_alarm(rtc.get_seconds() + time_to_sleep) |
| 29 sys_power.suspend_to_ram() |
| 30 |
| 31 if after_command: |
| 32 os.system(after_command) |
OLD | NEW |