Skip to content

Commit

Permalink
Added timeout for temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
jake1164 committed Aug 20, 2023
1 parent 186a25b commit e12ee65
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
light_sensor = LightSensor(settings)

datetime = DateTimeProcessing(settings, network)
#settings_display = SettingsDisplay(display, datetime)
key_input = KeyProcessing(settings, datetime, buzzer)

weather_display = WeatherDisplay(display, icons)
Expand All @@ -102,6 +101,9 @@
last_weather = time.time()
settings_visited = False

# remove splash from memory
del bg, splash

print('free memory', gc.mem_free())
while True:
# Always process keys first
Expand Down
17 changes: 13 additions & 4 deletions src/weather/open_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, weather_display, datetime, network) -> None:
# TODO: check parameters here and ensure geo works.
lat, lon = self._get_geo(https, zip, country, token)
self._url = URL.format(https, lat, lon, weather_display.units, token)
self._missed_weather = 0


def _get_geo(self, https, zip, country, token):
Expand All @@ -42,16 +43,17 @@ def get_weather(self):
# TODO: reduce size of json data and purge gc
return weather


def show_datetime(self) -> bool:
self._weather_display.set_time(self._datetime.get_time())
changed = self._weather_display.set_time(self._datetime.get_time())

# Only adjust the brightness once
if self._datetime.is_display_on != self._is_display_on:
self._weather_display.brightness = 0.1 if self._datetime.is_display_on else 0.0
self._is_display_on = self._datetime.is_display_on

if self._datetime.is_display_on:
self._weather_display.show()
if changed and self._datetime.is_display_on:
self._weather_display.show()

return self._is_display_on

Expand All @@ -70,8 +72,15 @@ def show_weather(self):
)

if weather == None or weather == {} or weather["main"] == None:
if self._missed_weather > 5:
self._weather_display.hide_temperature()
self._weather_display.add_test_display("Unable to contact API")
else:
self._missed_weather += 1
return
try:

try:
self._missed_weather = 0
self._weather_display.set_temperature(weather["main"]["temp"])
self._weather_display.set_icon(weather["weather"][0]["icon"])
# add Scrolling items
Expand Down
26 changes: 18 additions & 8 deletions src/weather/weather_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,16 @@ def get_temperature(self, temp):
if self.units == 'metric':
unit = "%d°C"
else:
unit = "%d°F"


unit = "%d°F"
return unit % temp


def hide_temperature(self):
self.temperature.text = ""
if self._icon_group:
self._icon_group.pop()


def set_icon(self, name):
if self._current_icon == name:
return
Expand All @@ -127,8 +131,11 @@ def set_icon(self, name):
gc.collect()


def set_time(self, time_string):
self.time.text = time_string
def set_time(self, time_string) -> bool:
if self.time.text != time_string:
self.time.text = time_string
return True
return False


def set_humidity(self, humidity):
Expand All @@ -153,14 +160,17 @@ def set_wind(self, wind):
else:
self.scroll_queue.append(f'wind {wind:.1f} m/s')



def add_test_display(self, text):
self.scroll_queue.append(text)


def scroll_label(self, key_input):
'''
Scrolls the label until all the text has been shown
TODO: Includes a hack to check if a button has been pressed to exit early because user is trying to get into the settings menu.
'''
# Take the top item to display

# Button press leaves items in scroll group and mucks things up
while len(self._scrolling_group) > 0:
self._scrolling_group.pop()

Expand Down

0 comments on commit e12ee65

Please sign in to comment.