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 showTemperature(self, temperature):
|
def updateColor(self, temperature):
|
||||||
start = self.getStartColumn(temperature)
|
if int(temperature) > 0:
|
||||||
|
self.color = colors.ORANGE
|
||||||
for c in temperature:
|
|
||||||
if c == '-':
|
|
||||||
self.symbolDisplay.displayNegative(
|
|
||||||
x=start-3,
|
|
||||||
y=self.topRow,
|
|
||||||
color=self.color
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
self.symbolDisplay.displayDigit(
|
self.color = colors.BLUE
|
||||||
x=start,
|
|
||||||
y=self.topRow,
|
|
||||||
digit=c,
|
|
||||||
color=self.color
|
|
||||||
)
|
|
||||||
start = start + self.digitWidth
|
|
||||||
|
|
||||||
self.symbolDisplay.displayDegree(
|
def showTemperature(self, temperature):
|
||||||
x=start,
|
column = self.getStartColumn(temperature)
|
||||||
y=self.topRow,
|
|
||||||
color=self.color
|
for c in list(temperature):
|
||||||
)
|
if c == '-':
|
||||||
|
offset = 2 if self.startsWithOne(temperature) else 3
|
||||||
|
self.showNegative(column - offset)
|
||||||
|
else:
|
||||||
|
self.showDigit(column, c)
|
||||||
|
column = column + self.digitWidth
|
||||||
|
|
||||||
|
self.showDegree(column)
|
||||||
|
|
||||||
def getStartColumn(self, temperature):
|
def getStartColumn(self, temperature):
|
||||||
return self.oneDigitStartColumn if (self.isOneDigit(temperature)) else self.twoDigitStartColumn
|
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):
|
def isOneDigit(self, temperature):
|
||||||
return (len(temperature) == 2 and temperature[0] == '-') or len(temperature) == 1
|
return abs(int(temperature))//10 == 0
|
||||||
|
|
||||||
|
def showNegative(self, column):
|
||||||
|
self.symbolDisplay.displayNegative(
|
||||||
|
x=column,
|
||||||
|
y=self.topRow,
|
||||||
|
color=self.color
|
||||||
|
)
|
||||||
|
|
||||||
|
def showDigit(self, column, digit):
|
||||||
|
self.symbolDisplay.displayDigit(
|
||||||
|
x=column,
|
||||||
|
y=self.topRow,
|
||||||
|
digit=digit,
|
||||||
|
color=self.color
|
||||||
|
)
|
||||||
|
|
||||||
|
def showDegree(self, column):
|
||||||
|
self.symbolDisplay.displayDegree(
|
||||||
|
x=column,
|
||||||
|
y=self.topRow,
|
||||||
|
color=self.color
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue