mirror of
https://github.com/Crocmagnon/plant-badger.git
synced 2024-11-22 09:28:03 +01:00
Move RTC to display instance
This commit is contained in:
parent
e643f531f1
commit
3d7d12bf88
3 changed files with 39 additions and 47 deletions
|
@ -1,11 +1,8 @@
|
|||
import machine
|
||||
import urequests
|
||||
import jpegdec
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from pcf85063a import PCF85063A, MONDAY
|
||||
import ntptime
|
||||
from pcf85063a import PCF85063A
|
||||
|
||||
from badger2040w import WIDTH, Badger2040W, UPDATE_NORMAL, UPDATE_FAST
|
||||
from badger2040w import WIDTH, Badger2040W, UPDATE_NORMAL, UPDATE_FAST, ENABLE_3V3
|
||||
|
||||
import secrets
|
||||
from secrets import HA_BASE_URL, HA_ACCESS_TOKEN
|
||||
|
@ -16,8 +13,6 @@ display.led(128)
|
|||
|
||||
jpeg = jpegdec.JPEG(display.display)
|
||||
|
||||
i2c = PimoroniI2C(sda=4, scl=5)
|
||||
rtc = PCF85063A(i2c)
|
||||
|
||||
BLACK = 0
|
||||
WHITE = 15
|
||||
|
@ -151,43 +146,31 @@ class HAPlant:
|
|||
|
||||
def main():
|
||||
display.connect()
|
||||
set_clocks()
|
||||
display.set_clocks()
|
||||
|
||||
# Call halt in a loop, on battery this switches off power.
|
||||
# On USB, the app will exit when A+C is pressed because the launcher picks that up.
|
||||
while True:
|
||||
fetch_and_display()
|
||||
print("Halting")
|
||||
display.halt()
|
||||
display.rtc.clear_timer_flag()
|
||||
|
||||
|
||||
def fetch_and_display():
|
||||
display.set_pen(WHITE)
|
||||
display.clear()
|
||||
display_image()
|
||||
display_header("Chargement...")
|
||||
display.set_update_speed(UPDATE_FAST)
|
||||
display.update()
|
||||
|
||||
plant = HAPlant()
|
||||
plant.fetch_states()
|
||||
plant.display_state()
|
||||
|
||||
rtc.set_timer(
|
||||
display.rtc.set_timer(
|
||||
secrets.REFRESH_INTERVAL_MINUTES, ttp=PCF85063A.TIMER_TICK_1_OVER_60HZ
|
||||
)
|
||||
|
||||
# Call halt in a loop, on battery this switches off power.
|
||||
# On USB, the app will exit when A+C is pressed because the launcher picks that up.
|
||||
while True:
|
||||
display.halt()
|
||||
|
||||
|
||||
def set_clocks():
|
||||
ntptime.settime()
|
||||
(
|
||||
year,
|
||||
month,
|
||||
day,
|
||||
weekday,
|
||||
hours,
|
||||
minutes,
|
||||
seconds,
|
||||
_,
|
||||
) = machine.RTC().datetime()
|
||||
rtc.datetime((year, month, day, hours, minutes, seconds, weekday))
|
||||
|
||||
|
||||
def display_image():
|
||||
# Display image
|
||||
|
@ -207,7 +190,7 @@ def display_header(text):
|
|||
display.text(text, 3, 4)
|
||||
|
||||
# Display time
|
||||
_, _, _, hour, minute, _, _ = rtc.datetime()
|
||||
_, _, _, hour, minute, _, _ = display.rtc.datetime()
|
||||
hour = (hour + 1) % 24
|
||||
time = f"{hour:02d}:{minute:02d}"
|
||||
time_offset = display.measure_text(time)
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import machine
|
||||
import micropython
|
||||
from picographics import PicoGraphics, DISPLAY_INKY_PACK
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from pcf85063a import PCF85063A
|
||||
import ntptime
|
||||
import network
|
||||
from network_manager import NetworkManager
|
||||
import WIFI_CONFIG
|
||||
|
@ -83,6 +86,8 @@ class Badger2040W:
|
|||
self._led.freq(1000)
|
||||
self._led.duty_u16(0)
|
||||
self._update_speed = 0
|
||||
i2c = PimoroniI2C(sda=4, scl=5)
|
||||
self.rtc = PCF85063A(i2c)
|
||||
|
||||
def __getattr__(self, item):
|
||||
# Glue to redirect calls to PicoGraphics
|
||||
|
@ -116,7 +121,7 @@ class Badger2040W:
|
|||
time.sleep(0.05)
|
||||
enable = machine.Pin(ENABLE_3V3, machine.Pin.OUT)
|
||||
enable.off()
|
||||
while not self.pressed_any():
|
||||
while not self.pressed_any() and not self.rtc.read_timer_flag():
|
||||
pass
|
||||
|
||||
def pressed(self, button):
|
||||
|
@ -177,3 +182,17 @@ class Badger2040W:
|
|||
network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK)
|
||||
)
|
||||
gc.collect()
|
||||
|
||||
def set_clocks(self):
|
||||
ntptime.settime()
|
||||
(
|
||||
year,
|
||||
month,
|
||||
day,
|
||||
weekday,
|
||||
hours,
|
||||
minutes,
|
||||
seconds,
|
||||
_,
|
||||
) = machine.RTC().datetime()
|
||||
self.rtc.datetime((year, month, day, hours, minutes, seconds, weekday))
|
||||
|
|
18
tasks.py
18
tasks.py
|
@ -45,30 +45,20 @@ def initial_setup(c: Context, board_id: str):
|
|||
if MICROPYTHON_DEPENDENCIES:
|
||||
deps = " ".join(MICROPYTHON_DEPENDENCIES)
|
||||
c.run(
|
||||
f"mpremote connect id:{board_id} "
|
||||
f"mip install {deps} + "
|
||||
"cp -r . : + "
|
||||
"reset",
|
||||
pty=True,
|
||||
echo=True,
|
||||
)
|
||||
else:
|
||||
c.run(
|
||||
f"mpremote connect id:{board_id} " "cp -r . : + " "reset",
|
||||
f"mpremote connect id:{board_id} " f"mip install {deps}",
|
||||
pty=True,
|
||||
echo=True,
|
||||
)
|
||||
update_code(c, board_id)
|
||||
|
||||
|
||||
@task
|
||||
def update_code(c: Context, board_id: str):
|
||||
"""Update code on the board."""
|
||||
# mpremote connect id:e6614864d3269c34 \
|
||||
# cp -r . : + \
|
||||
# reset
|
||||
with c.cd(SRC_DIR):
|
||||
c.run("find . -name '.DS_Store' -delete", pty=True, echo=True)
|
||||
c.run(
|
||||
f"mpremote connect id:{board_id} " "cp -r . : + " "reset",
|
||||
f"mpremote connect id:{board_id} cp -r . : + reset",
|
||||
pty=True,
|
||||
echo=True,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue