Add native USB HID boot setup and status display
This commit is contained in:
@@ -4,7 +4,8 @@ import network
|
||||
import time
|
||||
import urandom
|
||||
|
||||
from hid import HID
|
||||
from display import StatusDisplay
|
||||
from hid import get_hid
|
||||
from settings import load, save
|
||||
from web import WebServer
|
||||
|
||||
@@ -32,6 +33,14 @@ def choose_due(now, minimum, maximum):
|
||||
return time.ticks_add(now, seconds_to_ms(randint(minimum, maximum)))
|
||||
|
||||
|
||||
def ip_address(wlan):
|
||||
"""Return the station IPv4 address across supported MicroPython versions."""
|
||||
try:
|
||||
return wlan.ipconfig("addr4")[0]
|
||||
except AttributeError:
|
||||
return wlan.ifconfig()[0]
|
||||
|
||||
|
||||
def start_mdns():
|
||||
"""Advertise the configuration page as http://polterhid.local/."""
|
||||
import mdns
|
||||
@@ -44,7 +53,9 @@ def start_mdns():
|
||||
|
||||
def main():
|
||||
settings = load()
|
||||
hid = HID()
|
||||
display = StatusDisplay()
|
||||
display.update(settings["wifi_ssid"])
|
||||
hid = get_hid()
|
||||
wlan = connect_wifi(settings)
|
||||
volume_requests = []
|
||||
|
||||
@@ -63,6 +74,7 @@ def main():
|
||||
next_wifi_retry = now
|
||||
mdns_server = None
|
||||
next_mdns_retry = now
|
||||
next_display_refresh = now
|
||||
|
||||
while True:
|
||||
now = time.ticks_ms()
|
||||
@@ -73,6 +85,11 @@ def main():
|
||||
wlan.connect(settings["wifi_ssid"], settings["wifi_password"])
|
||||
next_wifi_retry = time.ticks_add(now, 10000)
|
||||
|
||||
if time.ticks_diff(now, next_display_refresh) >= 0:
|
||||
address = ip_address(wlan) if wlan.isconnected() else None
|
||||
display.update(settings["wifi_ssid"], address)
|
||||
next_display_refresh = time.ticks_add(now, 1000)
|
||||
|
||||
if (wlan.isconnected() and mdns_server is None and
|
||||
time.ticks_diff(now, next_mdns_retry) >= 0):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user