Update badger from remote and extract overrides

This commit is contained in:
Gabriel Augendre 2023-03-21 16:29:48 +01:00
parent f5d856f6ff
commit 7db36cd6b5
5 changed files with 50 additions and 24 deletions

View file

@ -2,20 +2,20 @@ import urequests
import jpegdec
from pcf85063a import PCF85063A
from badger2040w import (
from badger2040 import (
WIDTH,
Badger2040W,
UPDATE_NORMAL,
UPDATE_MEDIUM,
UPDATE_FAST,
)
from badger_with_clock import Badger2040
from badger_os import get_battery_level
import secrets
from secrets import HA_BASE_URL, HA_ACCESS_TOKEN
display = Badger2040W()
display = Badger2040()
display.led(128)
jpeg = jpegdec.JPEG(display.display)

View file

@ -2,7 +2,7 @@ import gc
import os
import time
import math
import badger2040w as badger2040
import badger2040
import badger_os
import jpegdec
@ -26,7 +26,7 @@ else:
badger_os.state_launch()
display = badger2040.Badger2040W()
display = badger2040.Badger2040()
display.set_font("bitmap8")
display.led(128)

View file

@ -1,9 +1,6 @@
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
@ -53,6 +50,10 @@ BUTTONS = {
WAKEUP_MASK = 0
def is_wireless():
return True
def woken_by_button():
return wakeup.get_gpio_state() & BUTTON_MASK > 0
@ -79,15 +80,13 @@ def system_speed(speed):
pass
class Badger2040W:
class Badger2040:
def __init__(self):
self.display = PicoGraphics(DISPLAY_INKY_PACK)
self._led = machine.PWM(machine.Pin(LED))
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
@ -121,7 +120,7 @@ class Badger2040W:
time.sleep(0.05)
enable = machine.Pin(ENABLE_3V3, machine.Pin.OUT)
enable.off()
while not self.pressed_any() and not self.rtc.read_timer_flag():
while not self.pressed_any():
pass
def pressed(self, button):
@ -154,8 +153,16 @@ class Badger2040W:
row >>= 1
def status_handler(self, mode, status, ip):
# Explicitly do not display anything when connecting to Wi-Fi.
pass
print(mode, status, ip)
self.display.set_pen(15)
self.display.clear()
self.display.set_pen(0)
if status:
self.display.text("Connected!", 10, 10, 300, 0.5)
self.display.text(ip, 10, 30, 300, 0.5)
else:
self.display.text("Connecting...", 10, 10, 300, 0.5)
self.update()
def isconnected(self):
return network.WLAN(network.STA_IF).isconnected()
@ -174,8 +181,3 @@ class Badger2040W:
network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK)
)
gc.collect()
def set_clocks(self):
ntptime.settime()
now = time.localtime()
self.rtc.datetime(now[:7])

View file

@ -1,11 +1,9 @@
"""Keep track of app state in persistent flash storage."""
import os
import gc
import time
import json
import machine
import badger2040w as badger2040
import badger2040
def get_battery_level():
@ -137,7 +135,7 @@ def launch(file):
# If the app throws an error, catch it and display!
print(e)
state_clear_running()
display = badger2040.Badger2040W()
display = badger2040.Badger2040()
warning(display, str(e))
display.halt()
@ -158,7 +156,7 @@ def warning(
print(message)
if display is None:
display = badger2040.Badger2040W()
display = badger2040.Badger2040()
display.led(128)
# Draw a light grey background

View file

@ -0,0 +1,26 @@
import time
import machine
from pimoroni_i2c import PimoroniI2C
from pcf85063a import PCF85063A
import ntptime
import badger2040
class Badger2040(badger2040.Badger2040):
def __init__(self):
super().__init__()
i2c = PimoroniI2C(sda=4, scl=5)
self.rtc = PCF85063A(i2c)
def halt(self):
time.sleep(0.05)
enable = machine.Pin(badger2040.ENABLE_3V3, machine.Pin.OUT)
enable.off()
while not self.pressed_any() and not self.rtc.read_timer_flag():
pass
def set_clocks(self):
ntptime.settime()
now = time.localtime()
self.rtc.datetime(now[:7])