Center temperature and add hot/cold colors
This commit is contained in:
parent
3afa65a1b7
commit
fd1ea198fa
|
@ -20,7 +20,8 @@ class WeatherDisplay:
|
||||||
self.symbolDisplay.clearRow(self.topRow)
|
self.symbolDisplay.clearRow(self.topRow)
|
||||||
|
|
||||||
if self.isTemperatureValid(temperature):
|
if self.isTemperatureValid(temperature):
|
||||||
self.showTemperature(list(temperature))
|
self.updateColor(temperature)
|
||||||
|
self.showTemperature(temperature)
|
||||||
|
|
||||||
def getTemperature(self):
|
def getTemperature(self):
|
||||||
try:
|
try:
|
||||||
|
@ -33,33 +34,57 @@ class WeatherDisplay:
|
||||||
def isTemperatureValid(self, temperature):
|
def isTemperatureValid(self, temperature):
|
||||||
return not (temperature == 'error' or temperature == 'init' or temperature == 'halted')
|
return not (temperature == 'error' or temperature == 'init' or temperature == 'halted')
|
||||||
|
|
||||||
|
def updateColor(self, temperature):
|
||||||
|
if int(temperature) > 0:
|
||||||
|
self.color = colors.ORANGE
|
||||||
|
else:
|
||||||
|
self.color = colors.BLUE
|
||||||
|
|
||||||
def showTemperature(self, temperature):
|
def showTemperature(self, temperature):
|
||||||
start = self.getStartColumn(temperature)
|
column = self.getStartColumn(temperature)
|
||||||
|
|
||||||
for c in temperature:
|
for c in list(temperature):
|
||||||
if c == '-':
|
if c == '-':
|
||||||
self.symbolDisplay.displayNegative(
|
offset = 2 if self.startsWithOne(temperature) else 3
|
||||||
x=start-3,
|
self.showNegative(column - offset)
|
||||||
y=self.topRow,
|
|
||||||
color=self.color
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
self.symbolDisplay.displayDigit(
|
self.showDigit(column, c)
|
||||||
x=start,
|
column = column + self.digitWidth
|
||||||
y=self.topRow,
|
|
||||||
digit=c,
|
|
||||||
color=self.color
|
|
||||||
)
|
|
||||||
start = start + self.digitWidth
|
|
||||||
|
|
||||||
self.symbolDisplay.displayDegree(
|
self.showDegree(column)
|
||||||
x=start,
|
|
||||||
|
def getStartColumn(self, temperature):
|
||||||
|
offset = 1 if self.startsWithOne(temperature) else 0
|
||||||
|
startColumn = self.oneDigitStartColumn if self.isOneDigit(temperature) else self.twoDigitStartColumn
|
||||||
|
|
||||||
|
return startColumn - offset
|
||||||
|
|
||||||
|
def startsWithOne(self, temperature):
|
||||||
|
absoluteTemperature = abs(int(temperature))
|
||||||
|
|
||||||
|
return absoluteTemperature == 1 or absoluteTemperature//10 == 1
|
||||||
|
|
||||||
|
def isOneDigit(self, temperature):
|
||||||
|
return abs(int(temperature))//10 == 0
|
||||||
|
|
||||||
|
def showNegative(self, column):
|
||||||
|
self.symbolDisplay.displayNegative(
|
||||||
|
x=column,
|
||||||
y=self.topRow,
|
y=self.topRow,
|
||||||
color=self.color
|
color=self.color
|
||||||
)
|
)
|
||||||
|
|
||||||
def getStartColumn(self, temperature):
|
def showDigit(self, column, digit):
|
||||||
return self.oneDigitStartColumn if (self.isOneDigit(temperature)) else self.twoDigitStartColumn
|
self.symbolDisplay.displayDigit(
|
||||||
|
x=column,
|
||||||
|
y=self.topRow,
|
||||||
|
digit=digit,
|
||||||
|
color=self.color
|
||||||
|
)
|
||||||
|
|
||||||
def isOneDigit(self, temperature):
|
def showDegree(self, column):
|
||||||
return (len(temperature) == 2 and temperature[0] == '-') or len(temperature) == 1
|
self.symbolDisplay.displayDegree(
|
||||||
|
x=column,
|
||||||
|
y=self.topRow,
|
||||||
|
color=self.color
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue