diff --git a/character_display.py b/character_display.py index 1260e48..e7cc9ac 100644 --- a/character_display.py +++ b/character_display.py @@ -59,6 +59,13 @@ class CharacterDisplay: self.unicorn.show() + def clearRow(self, y): + for row in range(y, y-5, -1): + for col in range(self.minX, self.maxX + 1): + self.setPixel(col, row, colors.BLACK) + + self.unicorn.show() + def displayTimeDots(self, x, y, color): self.setPixel(x, y, colors.BLACK) self.setPixel(x, y-1, color) diff --git a/chutney.py b/chutney.py index 4ccf59d..bf36b94 100644 --- a/chutney.py +++ b/chutney.py @@ -37,7 +37,6 @@ def main(): if (x == 0): weatherDisplay.showWeather() - print("weather updated") x = x + 1 x = x % 120 diff --git a/weather_display.py b/weather_display.py index a0ba3c9..3123b09 100644 --- a/weather_display.py +++ b/weather_display.py @@ -3,6 +3,7 @@ import requests from configparser import ConfigParser + class WeatherDisplay: def __init__(self, characterDisplay, topRow, configFile): self.characterDisplay = characterDisplay @@ -10,7 +11,7 @@ class WeatherDisplay: self.currentTemperature = [9, 9] self.currentColor = colors.BLACK self.color = colors.BLUE - + config = ConfigParser() config.read(configFile) @@ -23,22 +24,24 @@ class WeatherDisplay: print(self.host) def showWeather(self): - self.showTemperature(self.getTemperatureCharacters(self.getTemperature())) + self.characterDisplay.clearRow(self.topRow) + self.showTemperature( + self.getTemperatureCharacters(self.getTemperature())) def showTemperature(self, temperature): - start = 6 - - for c in temperature: - if c == '-': - self.characterDisplay.displayNegative(start, self.topRow, self.color) - start = start + 3 - else: - self.characterDisplay.displayDigit(start, self.topRow, c, self.color) - start = start + 4 + start = 13 if ( len(temperature) == 2 and temperature[0] == '-') or len(temperature) == 1 else 9 + for c in temperature: + if c == '-': + self.characterDisplay.displayNegative( + start-3, self.topRow, self.color) + else: + self.characterDisplay.displayDigit( + start, self.topRow, c, self.color) + start = start + 4 def getTemperature(self): - return list(filter(lambda t: t["timestep"] == 'current', requests.get(f'https://{self.host}/api/weather?lat={self.lat}&lon={self.lon}&units=metric', auth=(self.user, self.password)).json()["tomorrow"]["data"]['timelines']))[0]["intervals"][0]["values"]["temperature"] + return list(filter(lambda t: t["timestep"] == 'current', requests.get(f'https://{self.host}/api/weather?lat={self.lat}&lon={self.lon}&units=metric', auth=(self.user, self.password)).json()["tomorrow"]["data"]['timelines']))[0]["intervals"][0]["values"]["temperature"] def getTemperatureCharacters(self, temperature): - return list(str(round(temperature))) + return list(str(round(temperature)))