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