feat(07-01): add firmware scaffold — boot.py, config.json, led_driver.py, protocol tests
- firmware/boot.py: WiFi connection on startup (MicroPython boot sequence) - firmware/config.json: default device config with all 9 fields (ssid, password, led_count, strip_type, led_pin, spi_id, spi_clk_pin, spi_dat_pin, udp_port) - firmware/led_driver.py: NeoPixelStrip (SK6812 RGBW) and WS2801Strip (RGB SPI) with unified interface (write_rgb, write_rgbw, fill, clear) - tests/test_firmware_protocol.py: 21 host-side tests for round-trip protocol parsing (DRGB, DRGBW, DNRGB, animation_cmd)
This commit is contained in:
38
firmware/boot.py
Normal file
38
firmware/boot.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import network
|
||||
import time
|
||||
import json
|
||||
|
||||
|
||||
def load_config():
|
||||
try:
|
||||
with open('config.json') as f:
|
||||
return json.load(f)
|
||||
except OSError:
|
||||
print('[boot] config.json not found, using defaults')
|
||||
return {
|
||||
'ssid': 'MyWiFi', 'password': 'secret',
|
||||
'led_count': 300, 'strip_type': 'sk6812',
|
||||
'led_pin': 5, 'spi_id': 1, 'udp_port': 21324
|
||||
}
|
||||
|
||||
|
||||
def connect_wifi(ssid, password, timeout=15):
|
||||
wlan = network.WLAN(network.STA_IF)
|
||||
wlan.active(True)
|
||||
if wlan.isconnected():
|
||||
print('[boot] Already connected:', wlan.ifconfig()[0])
|
||||
return wlan
|
||||
print('[boot] Connecting to', ssid, '...')
|
||||
wlan.connect(ssid, password)
|
||||
start = time.time()
|
||||
while not wlan.isconnected():
|
||||
if time.time() - start > timeout:
|
||||
print('[boot] WiFi timeout after', timeout, 'seconds')
|
||||
return wlan
|
||||
time.sleep(0.5)
|
||||
print('[boot] Connected:', wlan.ifconfig()[0])
|
||||
return wlan
|
||||
|
||||
|
||||
config = load_config()
|
||||
wlan = connect_wifi(config['ssid'], config['password'])
|
||||
Reference in New Issue
Block a user