# #################################################################################################
# Acknowledgement / Credits
#
# This project was built with assistance from ChatGPT (GPT-5.2 Thinking),
# which helped troubleshoot the Wokwi DS18B20 multi-sensor setup (unique deviceID per sensor)
# and refine the MicroPython code for scanning, ROM printing, and stable sensor labeling (S1–S4).
# #################################################################################################
# Butons
# Green button: Pauses or starts the display loop.
# Blue button: When the loop is paused, navigates between the pages of each sense and provides an overview.
import time
import config
from sensors_ds18b20 import SensorManager
from display_oled import OledView, uptime_str
from net_time import NetTime
from ui_pages import UIPages
sensors = SensorManager(config.ONEWIRE_PIN, config.ROM_TO_LABEL, conv_ms=750)
view = OledView(config.I2C_SDA, config.I2C_SCL, config.OLED_ADDR, config.OLED_W, config.OLED_H)
net = NetTime(config.TZ_OFFSET_HOURS, config.WIFI_CONNECT_TIMEOUT_S, config.WIFI_RETRY_EVERY_S, config.NTP_RETRY_EVERY_S)
ui = UIPages(config.BTN_PAUSE_PIN, config.BTN_NEXT_PIN, config.UI_LOOP_EVERY_S, config.UI_DEBOUNCE_MS)
next_net = time.ticks_ms()
next_render = time.ticks_ms()
NET_MS = 500
RENDER_MS = 150
while True:
now = time.ticks_ms()
# 1) UI (always)
ui.update_inputs()
ui.update_auto()
# 2) Sensors (always - non-blocking)
sensors.update()
# 3) Net (scheduled)
if time.ticks_diff(now, next_net) >= 0:
net.update()
next_net = time.ticks_add(now, NET_MS)
# 4) Render (scheduled)
if time.ticks_diff(now, next_render) >= 0:
temps = sensors.temps
failed = [k.upper() for k in config.ORDERED_LABELS if temps.get(k) is None]
last_line = ("Last " + net.now_str()) if net.time_ok else uptime_str()
ui.render(
view=view,
temps=temps,
failed_upper=failed,
wifi_ok=net.wifi_ok,
time_ok=net.time_ok,
last_line=last_line
)
next_render = time.ticks_add(now, RENDER_MS)
time.sleep_ms(20)