def run(self): while not self.stop and globals.running.is_set(): d0 = datetime.now() if (d0 >= self.alarmTime) and self.alarmActive: globals.display_override.set() print("Wake up time") # sound alarm print_str16("Alarm Alarm " + self.alarmTime.strftime("%H%M"), override=True) set_decimal_point16(13, print_override=True) write_display16() if globals.AlarmTone == 0: globals.BUZZ.beep(0.1, 0.05, 5) else: mpc.clear() mpc.alarm(globals.AlarmTone) CM = globals.ClockMode while not globals.B[3].is_pressed and CM == globals.ClockMode: time.sleep(1) mpc.clear() globals.display_override.clear() self.stop = True if not self.stop: time.sleep(30) mpc.stop() mpc.clear() self.toggleAlarm()
def initMP3(): """ Initialize the MP3 player """ mpc.stop() # stop what's playing mpc.clear() # clear any existing playlists mpc.repeat( True) # repeat mode so the play cycles at the end of the playlist
def play_mp3(mode=0): """ Play the next MP3 file in the playlist (mode 0), or the next radio station (mode 1) """ globals.B[1].when_pressed = Previous globals.B[2].when_pressed = VolDown globals.B[3].when_pressed = Pause globals.B[4].when_pressed = VolUp globals.B[5].when_pressed = Next mpc.play() msg = getNowPlayingString() # Use 12 leftmost digits to scroll title and artist # The remaining 4 digits display the playing time # For internet radio, use the 16 characters if mode == 0: width = 12 else: width = 16 try: td = ScrollDisplayThread(msg, width) td.start() # signal.pause() except (KeyboardInterrupt, SystemExit): mpc.stop() mpc.clear() clear_display16() sys.exit() CM = globals.ClockMode msg_ant = msg d0 = datetime.now() while CM == globals.ClockMode: msg = getNowPlayingString() if mode == 0: # MP3 with a running clock dt = datetime.now() - d0 minute, second = divmod(int(dt.total_seconds()), 60) tstr = "{0:02d}{1:02d}".format(minute, second) print_time(tstr) if msg != msg_ant: td.msg = msg msg_ant = msg d0 = datetime.now() time.sleep(1) td.stop = True # Stop the thread for the scrolling display mpc.stop() # stop playing mpc.clear() # clear existing playlists clear_display16()
def run(self): while globals.running.is_set(): if globals.B[2].is_pressed and globals.B[ 4].is_pressed: # reload parameters file globals.display_override.set() print("Reloading...") mpc.stop() mpc.clear() print_str16("Reloading... ", override=True) write_display16() # override other displays time.sleep(1) # actual reloading getParameters() globals.ClockMode = globals.DefaultClockMode set_brightness16(globals.Brightness) clear_display16() print_str16("Done", override=True) write_display16() time.sleep(1) print("Done reloading.") globals.display_override.clear() if globals.B[1].is_pressed and globals.B[ 5].is_pressed: # exit system if globals.ClockMode == 1: clear_display16() # time.sleep(0.5) CM = globals.ClockMode d0 = datetime.now() while not globals.B[ 3].is_pressed and CM == globals.ClockMode: globals.display_override.set() print_str16("Terminate? ", override=True) write_display16() # override other displays time.sleep(0.5) dt = datetime.now() - d0 if dt.total_seconds() > 5: break if globals.B[3].is_pressed: globals.running.clear() clear_display16() cleanupButtons() sys.exit() globals.display_override.clear() time.sleep(0.2)
def Timer(): """ A countdown timer """ clear_display16() # set the timer lower_limit = [0, 0, 0] upper_limit = [60, 60, 24] msg = ['Sec ', 'Min ', 'Hour ', 'Set '] count = [0, 0, 0] # sec, min, hour # get alarm time from the keys pos = 0 print_str16("{3:5}{0:02}h{1:02}m{2:02}000".format(count[2], count[1], count[0], msg[0])) set_decimal_point16(12) write_display16() CM = globals.ClockMode # detect change in MODE while pos < 3 and CM == globals.ClockMode: while (not globals.B[3].is_pressed) and (CM == globals.ClockMode): if globals.B[2].is_pressed: count[pos] -= 1 if globals.B[4].is_pressed: count[pos] += 1 if count[pos] < lower_limit[pos]: count[pos] = upper_limit[pos] - 1 if count[pos] >= upper_limit[pos]: count[pos] = lower_limit[pos] print_str16("{3:5}{0:02}h{1:02}m{2:02}000".format( count[2], count[1], count[0], msg[pos])) set_decimal_point16(12) write_display16() time.sleep(0.2) time.sleep(0.2) pos += 1 if CM == globals.ClockMode: # timer set: display print_str16("{3:5}{0:02}h{1:02}m{2:02}000".format( count[2], count[1], count[0], msg[pos])) set_decimal_point16(12) write_display16() time.sleep(1) timer = count[0] + 60 * count[1] + 60 * 60 * count[2] # seconds origTimer = timer zero = timedelta(seconds=0) mpc.clear() while CM == globals.ClockMode: print_str16( '{:>16}'.format(td_format_milliseconds(timedelta(seconds=timer))), True) set_decimal_point16(12) write_display16() while (not globals.B[3].is_pressed) and ( CM == globals.ClockMode): # Wait for GO if globals.B[4].is_pressed and CM == globals.ClockMode: timer = origTimer time.sleep(0.1) t0 = datetime.now() + timedelta(microseconds=timer * 1000000) dt = t0 - t0 finish = False # Running: STOP and MODE interrupt while (not globals.B[4].is_pressed) and ( CM == globals.ClockMode) and not finish: t1 = datetime.now() dt = t0 - t1 if dt <= zero: finish = True dt = timedelta(seconds=0) print_str16('{:>16}'.format(td_format_milliseconds(dt)), True) set_decimal_point16(12) write_display16() time.sleep(0.001) if (CM == globals.ClockMode ) and not finish: # STOP was pressed, wait for GO timer = dt.microseconds / 1000000 + dt.seconds else: print_str16('{:>16}'.format(td_format_milliseconds(dt)), True) set_decimal_point16(12) write_display16() time.sleep(0.2) # if finish: beep timer finish if globals.AlarmTone == 0: globals.BUZZ.beep(0.1, 0.05, 5) else: mpc.clear() mpc.alarm(globals.AlarmTone) while (not globals.B[1].is_pressed) and ( CM == globals.ClockMode): # Waiting for RESET or MODE change time.sleep(0.2) mpc.stop() timer = origTimer
def run(self): while globals.running.is_set(): if globals.ClockMode == 1: try: BTTF_Clock() except (KeyboardInterrupt, SystemExit): clear_display16() cleanupButtons() globals.running.clear() sys.exit() elif globals.ClockMode == 2: Clock_temp_humid() elif globals.ClockMode == 3: current_weather(globals.AirportCode) elif globals.ClockMode == 4: weather_forecast(globals.CityCode, 4) elif globals.ClockMode == 5: TimeSinceDate(globals.FromDate) elif globals.ClockMode == 6: TimeToDeadline(globals.Deadline) elif globals.ClockMode == 7: WorldClock() elif globals.ClockMode == 8: initMP3() init_MP3_playlist() try: play_mp3() # local files time.sleep(0.2) except (KeyboardInterrupt, SystemExit): mpc.stop() mpc.clear() clear_display16() globals.running.clear() sys.exit() elif globals.ClockMode == 9: initMP3() init_MP3_playlist(1) try: play_mp3(1) # Internet radio time.sleep(0.2) except (KeyboardInterrupt, SystemExit): mpc.stop() mpc.clear() clear_display16() globals.running.clear() sys.exit() elif globals.ClockMode == 10: Clock() elif globals.ClockMode == 11: Now_Milliseconds() elif globals.ClockMode == 12: Chrono() # milliseconds chronometer elif globals.ClockMode == 13: Chrono(1) # seconds chronometer elif globals.ClockMode == 14: setAlarm() elif globals.ClockMode == 15: Timer() elif globals.ClockMode == 16: ChessClock() elif globals.ClockMode == 17: # display the device's IP address showIP() else: globals.ClockMode = 1 time.sleep(0.01)