Skip to content

Commit

Permalink
Thermo WIP2
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-prodigy committed Jan 5, 2025
1 parent de431d2 commit bc111a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
23 changes: 13 additions & 10 deletions dashboard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math
import sys
import datetime
import traceback
Expand Down Expand Up @@ -332,22 +332,25 @@ def content_update(self, io_status):
self._line[1] = menu[self.current_menu_item][1]
io_status.ui_changing = menu_item[5]
else:
time = strftime("%H:%M")
if config.MODULE_TEMP and math.floor(datetime.datetime.now().second / 10) in [0,2,4]:
data = '{:04.1f}\''.format(io_status.int_temp_c)
else:
data = strftime("%H:%M")
# add leading space
time1 = time2 = ' '
for char in time:
line1 = line2 = ' '
for char in data:
try:
if char == '.' or char == ':' or char == '\'':
time1 = time1[:-1]
time2 = time2[:-1]
time1 += BIGNUMMATRIX[char][0]
time2 += BIGNUMMATRIX[char][1]
line1 = line1[:-1]
line2 = line2[:-1]
line1 += BIGNUMMATRIX[char][0]
line2 += BIGNUMMATRIX[char][1]
except Exception:
traceback.print_exc()
pass
# remove last space, then center
self._line[0] = time1[:-1].center(LCD_COLUMNS)
self._line[1] = time2[:-1].center(LCD_COLUMNS)
self._line[0] = line1[:-1].center(LCD_COLUMNS)
self._line[1] = line2[:-1].center(LCD_COLUMNS)
# add playing icon
if io_status.state == 'playing':
self._line[1] = "&\x04&" + self._line[1][1:]
Expand Down
37 changes: 19 additions & 18 deletions snapdash.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,39 @@ def main():
dash.content_update(io_status)
while True:
try:
now = datetime.datetime.now()
command = rotary.scan()
if config.TEST_MODE and command is None:
command = keyreader.scan()
if command is not None:
inactive_time = now
if not dash.is_active:
command = None
dash.idle_update(True, INACTIVE_DISPLAY_SECS)
if dash.menu_action(io_status, command):
# anticipated refresh
state_refresh_time = now - datetime.timedelta(seconds=STATE_REFRESH_TIME_ACTIVE - 1)
for loop in range(10):
now = datetime.datetime.now()
command = rotary.scan()
if config.TEST_MODE and command is None:
command = keyreader.scan()
if command is not None:
inactive_time = now
if not dash.is_active:
command = None
dash.idle_update(True, INACTIVE_DISPLAY_SECS)
if dash.menu_action(io_status, command):
# anticipated refresh
state_refresh_time = now - datetime.timedelta(seconds=STATE_REFRESH_TIME_ACTIVE - 1)
time.sleep(.01)

if (now - lcd_refresh_time).total_seconds() > LCD_REFRESH_TIME:
if (now - lcd_refresh_time).total_seconds() >= LCD_REFRESH_TIME:
dash.update()
lcd_refresh_time = now
if (now - content_refresh_time).total_seconds() > CONTENT_REFRESH_TIME:
if (now - content_refresh_time).total_seconds() >= CONTENT_REFRESH_TIME:
dash.content_update(io_status)
content_refresh_time = now
# inactive time reached -> back to default view
if (now - inactive_time).total_seconds() > INACTIVE_MENU_SECS:
if (now - inactive_time).total_seconds() >= INACTIVE_MENU_SECS:
dash.default_view(io_status)
# periodic refresh (longer if inactive)
refresh_timeout = STATE_REFRESH_TIME_ACTIVE if dash.is_active else STATE_REFRESH_TIME_INACTIVE
if (now - state_refresh_time).total_seconds() > refresh_timeout and not io_status.ui_changing:
if (now - state_refresh_time).total_seconds() >= refresh_timeout and not io_status.ui_changing:
hass.get_status(io_status)
state_refresh_time = now
if (now - temperature_time).total_seconds() > TEMPERATURE_REFRESH_TIME:
if (now - temperature_time).total_seconds() >= TEMPERATURE_REFRESH_TIME:
temp = sensor.read_temp()
if temp: io_status.int_temp_c = temp * config.TEMP_CORRECTION
temperature_time = now
time.sleep(.01)
except (KeyboardInterrupt, SystemExit):
# cleanup
dash.cleanup()
Expand Down

0 comments on commit bc111a9

Please sign in to comment.