Clean up code
This commit is contained in:
parent
9749f51332
commit
fcd9d6465f
|
@ -45,109 +45,109 @@ class CharacterDisplay:
|
||||||
def clearDigit(self, x, y):
|
def clearDigit(self, x, y):
|
||||||
for y1 in range(y, y-5, -1):
|
for y1 in range(y, y-5, -1):
|
||||||
for x1 in range(x, x+3):
|
for x1 in range(x, x+3):
|
||||||
self.setPixel(x1, y1, 0, 0, 0)
|
self.setPixel(x1, y1, [0, 0, 0])
|
||||||
|
|
||||||
self.unicorn.show()
|
self.unicorn.show()
|
||||||
|
|
||||||
def displayTimeDots(self, x, y, color):
|
def displayTimeDots(self, x, y, color):
|
||||||
self.setPixel(x, y-1, *color)
|
self.setPixel(x, y-1, color)
|
||||||
self.setPixel(x, y-3, *color)
|
self.setPixel(x, y-3, color)
|
||||||
self.unicorn.show()
|
self.unicorn.show()
|
||||||
|
|
||||||
def displayZero(self, x, y, color):
|
def displayZero(self, x, y, color):
|
||||||
self.clearDigit(x, y)
|
self.clearDigit(x, y)
|
||||||
self.fullLine(x, y, *color)
|
self.fullLine(x, y, color)
|
||||||
self.bothSides(x, y-1, *color)
|
self.bothSides(x, y-1, color)
|
||||||
self.bothSides(x, y-2, *color)
|
self.bothSides(x, y-2, color)
|
||||||
self.bothSides(x, y-3, *color)
|
self.bothSides(x, y-3, color)
|
||||||
self.fullLine(x, y-4, *color)
|
self.fullLine(x, y-4, color)
|
||||||
|
|
||||||
def displayOne(self, x, y, color):
|
def displayOne(self, x, y, color):
|
||||||
self.clearDigit(x, y)
|
self.clearDigit(x, y)
|
||||||
self.rightSide(x, y, *color)
|
self.rightSide(x, y, color)
|
||||||
self.rightSide(x, y-1, *color)
|
self.rightSide(x, y-1, color)
|
||||||
self.rightSide(x, y-2, *color)
|
self.rightSide(x, y-2, color)
|
||||||
self.rightSide(x, y-3, *color)
|
self.rightSide(x, y-3, color)
|
||||||
self.rightSide(x, y-4, *color)
|
self.rightSide(x, y-4, color)
|
||||||
|
|
||||||
def displayTwo(self, x, y, color):
|
def displayTwo(self, x, y, color):
|
||||||
self.clearDigit(x, y)
|
self.clearDigit(x, y)
|
||||||
self.fullLine(x, y, *color)
|
self.fullLine(x, y, color)
|
||||||
self.rightSide(x, y-1, *color)
|
self.rightSide(x, y-1, color)
|
||||||
self.fullLine(x, y-2, *color)
|
self.fullLine(x, y-2, color)
|
||||||
self.leftSide(x, y-3, *color)
|
self.leftSide(x, y-3, color)
|
||||||
self.fullLine(x, y-4, *color)
|
self.fullLine(x, y-4, color)
|
||||||
|
|
||||||
def displayThree(self, x, y, color):
|
def displayThree(self, x, y, color):
|
||||||
self.clearDigit(x, y)
|
self.clearDigit(x, y)
|
||||||
self.fullLine(x, y, *color)
|
self.fullLine(x, y, color)
|
||||||
self.rightSide(x, y-1, *color)
|
self.rightSide(x, y-1, color)
|
||||||
self.fullLine(x, y-2, *color)
|
self.fullLine(x, y-2, color)
|
||||||
self.rightSide(x, y-3, *color)
|
self.rightSide(x, y-3, color)
|
||||||
self.fullLine(x, y-4, *color)
|
self.fullLine(x, y-4, color)
|
||||||
|
|
||||||
def displayFour(self, x, y, color):
|
def displayFour(self, x, y, color):
|
||||||
self.clearDigit(x, y)
|
self.clearDigit(x, y)
|
||||||
self.bothSides(x, y, *color)
|
self.bothSides(x, y, color)
|
||||||
self.bothSides(x, y-1, *color)
|
self.bothSides(x, y-1, color)
|
||||||
self.fullLine(x, y-2, *color)
|
self.fullLine(x, y-2, color)
|
||||||
self.rightSide(x, y-3, *color)
|
self.rightSide(x, y-3, color)
|
||||||
self.rightSide(x, y-4, *color)
|
self.rightSide(x, y-4, color)
|
||||||
|
|
||||||
def displayFive(self, x, y, color):
|
def displayFive(self, x, y, color):
|
||||||
self.clearDigit(x, y)
|
self.clearDigit(x, y)
|
||||||
self.fullLine(x, y, *color)
|
self.fullLine(x, y, color)
|
||||||
self.leftSide(x, y-1, *color)
|
self.leftSide(x, y-1, color)
|
||||||
self.fullLine(x, y-2, *color)
|
self.fullLine(x, y-2, color)
|
||||||
self.rightSide(x, y-3, *color)
|
self.rightSide(x, y-3, color)
|
||||||
self.fullLine(x, y-4, *color)
|
self.fullLine(x, y-4, color)
|
||||||
|
|
||||||
def displaySix(self, x, y, color):
|
def displaySix(self, x, y, color):
|
||||||
self.clearDigit(x, y)
|
self.clearDigit(x, y)
|
||||||
self.fullLine(x, y, *color)
|
self.fullLine(x, y, color)
|
||||||
self.leftSide(x, y-1, *color)
|
self.leftSide(x, y-1, color)
|
||||||
self.fullLine(x, y-2, *color)
|
self.fullLine(x, y-2, color)
|
||||||
self.bothSides(x, y-3, *color)
|
self.bothSides(x, y-3, color)
|
||||||
self.fullLine(x, y-4, *color)
|
self.fullLine(x, y-4, color)
|
||||||
|
|
||||||
def displaySeven(self, x, y, color):
|
def displaySeven(self, x, y, color):
|
||||||
self.clearDigit(x, y)
|
self.clearDigit(x, y)
|
||||||
self.fullLine(x, y, *color)
|
self.fullLine(x, y, color)
|
||||||
self.rightSide(x, y-1, *color)
|
self.rightSide(x, y-1, color)
|
||||||
self.rightSide(x, y-2, *color)
|
self.rightSide(x, y-2, color)
|
||||||
self.rightSide(x, y-3, *color)
|
self.rightSide(x, y-3, color)
|
||||||
self.rightSide(x, y-4, *color)
|
self.rightSide(x, y-4, color)
|
||||||
|
|
||||||
def displayEight(self, x, y, color):
|
def displayEight(self, x, y, color):
|
||||||
self.clearDigit(x, y)
|
self.clearDigit(x, y)
|
||||||
self.fullLine(x, y, *color)
|
self.fullLine(x, y, color)
|
||||||
self.bothSides(x, y-1, *color)
|
self.bothSides(x, y-1, color)
|
||||||
self.fullLine(x, y-2, *color)
|
self.fullLine(x, y-2, color)
|
||||||
self.bothSides(x, y-3, *color)
|
self.bothSides(x, y-3, color)
|
||||||
self.fullLine(x, y-4, *color)
|
self.fullLine(x, y-4, color)
|
||||||
|
|
||||||
def displayNine(self, x, y, color):
|
def displayNine(self, x, y, color):
|
||||||
self.clearDigit(x, y)
|
self.clearDigit(x, y)
|
||||||
self.fullLine(x, y, *color)
|
self.fullLine(x, y, color)
|
||||||
self.bothSides(x, y-1, *color)
|
self.bothSides(x, y-1, color)
|
||||||
self.fullLine(x, y-2, *color)
|
self.fullLine(x, y-2, color)
|
||||||
self.rightSide(x, y-3, *color)
|
self.rightSide(x, y-3, color)
|
||||||
self.fullLine(x, y-4, *color)
|
self.fullLine(x, y-4, color)
|
||||||
|
|
||||||
def fullLine(self, start, row, r, g, b):
|
def fullLine(self, start, row, color):
|
||||||
for x in range(start, start+3):
|
for x in range(start, start+3):
|
||||||
self.setPixel(x, row, r, g, b)
|
self.setPixel(x, row, color)
|
||||||
|
|
||||||
def bothSides(self, start, row, r, g, b):
|
def bothSides(self, start, row, color):
|
||||||
self.setPixel(start, row, r, g, b)
|
self.setPixel(start, row, color)
|
||||||
self.setPixel(start+2, row, r, g, b)
|
self.setPixel(start+2, row, color)
|
||||||
|
|
||||||
def leftSide(self, start, row, r, g, b):
|
def leftSide(self, start, row, color):
|
||||||
self.setPixel(start, row, r, g, b)
|
self.setPixel(start, row, color)
|
||||||
|
|
||||||
def rightSide(self, start, row, r, g, b):
|
def rightSide(self, start, row, color):
|
||||||
self.setPixel(start+2, row, r, g, b)
|
self.setPixel(start+2, row, color)
|
||||||
|
|
||||||
def setPixel(self, x, y, r, g, b):
|
def setPixel(self, x, y, color):
|
||||||
if x >= self.minX and x <= self.maxX:
|
if x >= self.minX and x <= self.maxX:
|
||||||
self.unicorn.set_pixel(x, y, r, g, b)
|
self.unicorn.set_pixel(x, y, *color)
|
||||||
|
|
|
@ -8,8 +8,8 @@ class TimeDisplay:
|
||||||
self.topRow = topRow
|
self.topRow = topRow
|
||||||
self.currentHour = [-1, -1]
|
self.currentHour = [-1, -1]
|
||||||
self.currentMinute = [-1, -1]
|
self.currentMinute = [-1, -1]
|
||||||
self.currentColor = (0, 0, 0)
|
self.currentColor = [0, 0, 0]
|
||||||
self.color = (255, 80, 0)
|
self.color = [255, 120, 0]
|
||||||
self.hourStartColumn = -1
|
self.hourStartColumn = -1
|
||||||
self.timeDotsColumn = 7
|
self.timeDotsColumn = 7
|
||||||
self.minuteStartColumn = 9
|
self.minuteStartColumn = 9
|
||||||
|
@ -29,45 +29,36 @@ class TimeDisplay:
|
||||||
self.currentHour[0] = hour[0]
|
self.currentHour[0] = hour[0]
|
||||||
|
|
||||||
if hour[0] == 0:
|
if hour[0] == 0:
|
||||||
self.characterDisplay.clearDigit(
|
self.hideDigit(self.hourStartColumn)
|
||||||
x=self.hourStartColumn,
|
|
||||||
y=self.topRow
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
self.characterDisplay.displayDigit(
|
self.showDigit(self.hourStartColumn, hour[0])
|
||||||
x=self.hourStartColumn,
|
|
||||||
y=self.topRow,
|
|
||||||
digit=hour[0],
|
|
||||||
color=self.color
|
|
||||||
)
|
|
||||||
|
|
||||||
if hour[1] != self.currentHour[1]:
|
if hour[1] != self.currentHour[1]:
|
||||||
self.currentHour[1] = hour[1]
|
self.currentHour[1] = hour[1]
|
||||||
self.characterDisplay.displayDigit(
|
self.showDigit(self.hourStartColumn + 4, hour[1])
|
||||||
x=self.hourStartColumn + 4,
|
|
||||||
y=self.topRow,
|
|
||||||
digit=hour[1],
|
|
||||||
color=self.color
|
|
||||||
)
|
|
||||||
|
|
||||||
def showMinute(self, minute):
|
def showMinute(self, minute):
|
||||||
if minute[0] != self.currentMinute[0]:
|
if minute[0] != self.currentMinute[0]:
|
||||||
self.currentMinute[0] = minute[0]
|
self.currentMinute[0] = minute[0]
|
||||||
self.characterDisplay.displayDigit(
|
self.showDigit(self.minuteStartColumn, minute[0])
|
||||||
x=self.minuteStartColumn,
|
|
||||||
y=self.topRow,
|
|
||||||
digit=minute[0],
|
|
||||||
color=self.color
|
|
||||||
)
|
|
||||||
|
|
||||||
if minute[1] != self.currentMinute[1]:
|
if minute[1] != self.currentMinute[1]:
|
||||||
self.currentMinute[1] = minute[1]
|
self.currentMinute[1] = minute[1]
|
||||||
self.characterDisplay.displayDigit(
|
self.showDigit(self.minuteStartColumn + 4, minute[1])
|
||||||
x=self.minuteStartColumn + 4,
|
|
||||||
y=self.topRow,
|
def showDigit(self, x, digit):
|
||||||
digit=minute[1],
|
self.characterDisplay.displayDigit(
|
||||||
color=self.color
|
x=x,
|
||||||
)
|
y=self.topRow,
|
||||||
|
digit=digit,
|
||||||
|
color=self.color
|
||||||
|
)
|
||||||
|
|
||||||
|
def hideDigit(self, x):
|
||||||
|
self.characterDisplay.clearDigit(
|
||||||
|
x=x,
|
||||||
|
y=self.topRow
|
||||||
|
)
|
||||||
|
|
||||||
def getHourDigits(self):
|
def getHourDigits(self):
|
||||||
return self.getTimeDigits('%l')
|
return self.getTimeDigits('%l')
|
||||||
|
|
Loading…
Reference in New Issue