2022-12-23 11:26:50 -05:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
class TimeDisplay:
|
|
|
|
|
2022-12-23 14:57:33 -05:00
|
|
|
def __init__(self, characterDisplay, topRow):
|
|
|
|
self.currentHour = [-1, -1]
|
|
|
|
self.currentMinute = [-1, -1]
|
|
|
|
self.characterDisplay = characterDisplay
|
|
|
|
self.topRow = topRow
|
|
|
|
self.hourStartColumn = -1
|
|
|
|
self.timeDotsColumn = 7
|
|
|
|
self.minuteStartColumn = 9
|
2022-12-23 11:26:50 -05:00
|
|
|
|
2022-12-23 14:57:33 -05:00
|
|
|
self.characterDisplay.displayTimeDots(self.timeDotsColumn, self.topRow)
|
2022-12-23 11:26:50 -05:00
|
|
|
|
|
|
|
def showTime(self):
|
2022-12-23 14:57:33 -05:00
|
|
|
self.showHour(self.getHourDigits())
|
|
|
|
self.showMinute(self.getMinuteDigits())
|
2022-12-23 11:26:50 -05:00
|
|
|
|
2022-12-23 14:57:33 -05:00
|
|
|
def showHour(self, hour):
|
|
|
|
if hour[0] != self.currentHour[0]:
|
|
|
|
self.currentHour[0] = hour[0]
|
2022-12-23 11:26:50 -05:00
|
|
|
|
2022-12-23 14:57:33 -05:00
|
|
|
if hour[0] == 0:
|
|
|
|
self.characterDisplay.clearNumberPixels(
|
|
|
|
self.hourStartColumn,
|
|
|
|
self.topRow
|
|
|
|
)
|
2022-12-23 11:26:50 -05:00
|
|
|
else:
|
2022-12-23 14:57:33 -05:00
|
|
|
self.characterDisplay.displayNumber(
|
|
|
|
self.hourStartColumn,
|
|
|
|
self.topRow,
|
|
|
|
hour[0]
|
|
|
|
)
|
2022-12-23 11:26:50 -05:00
|
|
|
|
2022-12-23 14:57:33 -05:00
|
|
|
if hour[1] != self.currentHour[1]:
|
|
|
|
self.currentHour[1] = hour[1]
|
|
|
|
self.characterDisplay.displayNumber(
|
|
|
|
self.hourStartColumn + 4,
|
|
|
|
self.topRow,
|
|
|
|
hour[1]
|
|
|
|
)
|
2022-12-23 11:26:50 -05:00
|
|
|
|
2022-12-23 14:57:33 -05:00
|
|
|
def showMinute(self, minute):
|
|
|
|
if minute[0] != self.currentMinute[0]:
|
|
|
|
self.currentMinute[0] = minute[0]
|
|
|
|
self.characterDisplay.displayNumber(
|
|
|
|
self.minuteStartColumn,
|
|
|
|
self.topRow,
|
|
|
|
minute[0]
|
|
|
|
)
|
2022-12-23 11:26:50 -05:00
|
|
|
|
2022-12-23 14:57:33 -05:00
|
|
|
if minute[1] != self.currentMinute[1]:
|
|
|
|
self.currentMinute[1] = minute[1]
|
|
|
|
self.characterDisplay.displayNumber(
|
|
|
|
self.minuteStartColumn + 4,
|
|
|
|
self.topRow,
|
|
|
|
minute[1]
|
|
|
|
)
|
2022-12-23 11:26:50 -05:00
|
|
|
|
2022-12-23 14:57:33 -05:00
|
|
|
def getHourDigits(self):
|
|
|
|
return self.getTimeDigits('%l')
|
2022-12-23 11:26:50 -05:00
|
|
|
|
2022-12-23 14:57:33 -05:00
|
|
|
def getMinuteDigits(self):
|
|
|
|
return self.getTimeDigits('%M')
|
|
|
|
|
|
|
|
def getTimeDigits(self, format):
|
|
|
|
digits = datetime.now().strftime(format).strip().rjust(2, '0')
|
|
|
|
|
|
|
|
return [int(x) for x in digits]
|