fix day discrepancy bug
@@ -27,6 +27,7 @@ wake_up_times = (up_time_monday,
up_time_saturday,
up_time_sunday,
default_wake_up)
+days_str = ("Mon.", "Tues.", "Wed.", "Thurs.", "Fri.", "Sat.", "Sun.")
# set neopixel min and max brightness
BRIGHTNESS = 0
@@ -122,16 +123,19 @@ def whichDay():
if now_mk < val_times[day]:
if current_day == day:
input_wake_up_time = wake_up_times[day]
- # set wake up time to the next day's wake up time the night before
+ use_day = day
+ # set wake up time to the next day's wake up time after current day's wake up time
else:
if current_day == 6:
input_wake_up_time = wake_up_times[0]
+ use_day = 0
else:
if current_day == day:
input_wake_up_time = wake_up_times[day+1]
- input_wake_up_time_text = "Wake up at " + input_wake_up_time
+ use_day = day + 1
+ input_wake_up_time_text = "Wake up " + days_str[use_day] + " at " + input_wake_up_time
wakeup_time_textarea.text = input_wake_up_time_text
- return current_day
+ return use_day
def displayTime():
now = time.localtime()
@@ -156,13 +160,13 @@ def formatTime(raw_hours, raw_minutes):
return time_str
# backlight function - if screen tapped, turn on back light for 30 seconds?
-def backLight(day):
+def backLight():
now = time.localtime()
now_val = time.mktime((now[0], now[1], now[2], now[3], now[4], now[5], now[6], now[7], now[8]))
- wake_up_day_val = val_times[day]
+ wake_up_day_val = val_times[now[6]]
+ # if time is more than 9 hours after current day's wake up time,
+ # or time is before light start time, backlight off, tap to turn on
if (now_val - wake_up_day_val) > 32400 or (now_val - wake_up_day_val) < -1800:
- # if time is more than 9 hours after wake up time, or time is before light start time:
- # backlight off, tap to turn on
if pyportal.touchscreen.touch_point:
pyportal.set_backlight(backlight_on)
time.sleep(5)
@@ -197,11 +201,11 @@ while True:
continue
time_str_text = displayTime()
print(time_str_text)
- currentHour = time.localtime()
# determine which wake up time to choose based on the day
wake_up_day = whichDay()
- # if time is more than 9 hours after wake up time, backlight off and can tap to turn on
- backLight(wake_up_day)
+ # if time is more than 9 hours after previous day's wake up time,
+ # backlight off and can tap to turn on
+ backLight()
# start the light 30 min before wake up time
start_light_time = subtract30min(wake_up_day)
# If wake up time - 30 minutes equals current time, start the light
