| @@ -3,6 +3,36 @@ import time | |||
| import datetime | |||
| import pifacedigitalio as p | |||
| TREE = """ | |||
| * , | |||
| _/^\_ | |||
| < > | |||
| * /.-.\ * | |||
| * `/&\` * | |||
| ,@.*;@, | |||
| /_o.I %_\ * | |||
| * (`'--:o(_@; | |||
| /`;--.,__ `') * | |||
| ;@`o % O,*`'`&\ * | |||
| * (`'--)_@ ;o %'()\ * | |||
| /`;--._`''--._O'@; | |||
| /&*,()~o`;-.,_ `""`) | |||
| * /`,@ ;+& () o*`;-';\ * | |||
| (`""--.,_0 +% @' &()\ * | |||
| /-.,_ ``''--....-'`) * | |||
| * /@%;o`:;'--,.__ __.'\ | |||
| ;*,&(); @ % &^;~`"`o;@(); * | |||
| /(); o^~; & ().o@*&`;&%O\ | |||
| jgs `"="==""==,,,.,="=="==="` | |||
| __.----.(\-''#####---...___...-----._ | |||
| '` \)_`'''''` | |||
| .--' ') | |||
| o( )_- | |||
| `'''` ` | |||
| """ | |||
| START = datetime.time(17, 0, 0) | |||
| END = datetime.time(23, 59, 0) | |||
| def timestamp(): | |||
| return datetime.datetime.now() | |||
| @@ -22,23 +52,36 @@ def turn_off(): | |||
| def check_connectivity(): | |||
| """ Flick the switch """ | |||
| for i in range(10): | |||
| print("Checking connectivity:") | |||
| for i in range(2): | |||
| turn_on() | |||
| time.sleep(.3) | |||
| time.sleep(2) | |||
| turn_off() | |||
| time.sleep(.3) | |||
| time.sleep(2) | |||
| # Turn on if we are in the correct interval | |||
| now = datetime.datetime.now().time() | |||
| if START <= now <= END: | |||
| turn_on() | |||
| if __name__ == "__main__": | |||
| # Connect to PiFace | |||
| print(TREE) | |||
| p.init() | |||
| # Check connectivity | |||
| check_connectivity() | |||
| # Message | |||
| print() | |||
| print("Starting scheduler:") | |||
| print("Xmas enabled between {} and {}.".format(START.strftime("%H:%M"), END.strftime("%H:%M"))) | |||
| # Set up the schedule | |||
| schedule.every().day.at("17:00").do(turn_on) | |||
| schedule.every().day.at("23:59").do(turn_off) | |||
| schedule.every().day.at(START.strftime("%H:%M")).do(turn_on) | |||
| schedule.every().day.at(END.strftime("%H:%M")).do(turn_off) | |||
| # Run the event loop | |||
| while(True): | |||