2727 up_time_saturday ,
2828 up_time_sunday ,
2929 default_wake_up )
30+ days_str = ("Mon." , "Tues." , "Wed." , "Thurs." , "Fri." , "Sat." , "Sun." )
3031
3132# set neopixel min and max brightness
3233BRIGHTNESS = 0
@@ -122,16 +123,19 @@ def whichDay():
122123 if now_mk < val_times [day ]:
123124 if current_day == day :
124125 input_wake_up_time = wake_up_times [day ]
125- # set wake up time to the next day's wake up time the night before
126+ use_day = day
127+ # set wake up time to the next day's wake up time after current day's wake up time
126128 else :
127129 if current_day == 6 :
128130 input_wake_up_time = wake_up_times [0 ]
131+ use_day = 0
129132 else :
130133 if current_day == day :
131134 input_wake_up_time = wake_up_times [day + 1 ]
132- input_wake_up_time_text = "Wake up at " + input_wake_up_time
135+ use_day = day + 1
136+ input_wake_up_time_text = "Wake up " + days_str [use_day ] + " at " + input_wake_up_time
133137 wakeup_time_textarea .text = input_wake_up_time_text
134- return current_day
138+ return use_day
135139
136140def displayTime ():
137141 now = time .localtime ()
@@ -156,13 +160,13 @@ def formatTime(raw_hours, raw_minutes):
156160 return time_str
157161
158162# backlight function - if screen tapped, turn on back light for 30 seconds?
159- def backLight (day ):
163+ def backLight ():
160164 now = time .localtime ()
161165 now_val = time .mktime ((now [0 ], now [1 ], now [2 ], now [3 ], now [4 ], now [5 ], now [6 ], now [7 ], now [8 ]))
162- wake_up_day_val = val_times [day ]
166+ wake_up_day_val = val_times [now [6 ]]
167+ # if time is more than 9 hours after current day's wake up time,
168+ # or time is before light start time, backlight off, tap to turn on
163169 if (now_val - wake_up_day_val ) > 32400 or (now_val - wake_up_day_val ) < - 1800 :
164- # if time is more than 9 hours after wake up time, or time is before light start time:
165- # backlight off, tap to turn on
166170 if pyportal .touchscreen .touch_point :
167171 pyportal .set_backlight (backlight_on )
168172 time .sleep (5 )
@@ -197,11 +201,11 @@ def subtract30min(day): # subtract 30 min
197201 continue
198202 time_str_text = displayTime ()
199203 print (time_str_text )
200- currentHour = time .localtime ()
201204 # determine which wake up time to choose based on the day
202205 wake_up_day = whichDay ()
203- # if time is more than 9 hours after wake up time, backlight off and can tap to turn on
204- backLight (wake_up_day )
206+ # if time is more than 9 hours after previous day's wake up time,
207+ # backlight off and can tap to turn on
208+ backLight ()
205209 # start the light 30 min before wake up time
206210 start_light_time = subtract30min (wake_up_day )
207211 # If wake up time - 30 minutes equals current time, start the light
0 commit comments