Import led-driver app: pico/ and esp32/ layout
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
102
main.py
Normal file
102
main.py
Normal file
@@ -0,0 +1,102 @@
|
||||
# """
|
||||
# Pico: receive led-driver JSON from UART (one message per line). Runs Presets + patterns.
|
||||
# UART RX on D7 (GPIO1). Non-blocking so presets.tick() runs every loop.
|
||||
# """
|
||||
# from settings import Settings
|
||||
# from machine import UART, Pin
|
||||
# import utime
|
||||
# from presets import Presets
|
||||
# from utils import convert_and_reorder_colors
|
||||
# import json
|
||||
|
||||
# # UART (Pico XIAO: D7 = GPIO1)
|
||||
# UART_RX_PIN = 1
|
||||
# UART_BAUD = 115200
|
||||
# UART_ID = 0
|
||||
|
||||
# settings = Settings()
|
||||
# print(settings)
|
||||
|
||||
# presets = Presets(settings["led_pin"], settings["num_leds"])
|
||||
# presets.load()
|
||||
# presets.b = settings.get("brightness", 255)
|
||||
# startup_preset = settings.get("startup_preset")
|
||||
# if startup_preset:
|
||||
# presets.select(startup_preset)
|
||||
# print("Selected startup preset:", startup_preset)
|
||||
|
||||
# last_brightness_save = 0
|
||||
|
||||
# # Non-blocking UART
|
||||
# uart = UART(UART_ID, baudrate=UART_BAUD, rx=Pin(UART_RX_PIN), rxbuf=512, timeout=0)
|
||||
# uart_buf = bytearray()
|
||||
|
||||
# print("UART RX on pin %s, %s baud (one JSON object per line)" % (UART_RX_PIN, UART_BAUD))
|
||||
|
||||
|
||||
# def process_message(data):
|
||||
# """Handle one JSON message (led-driver protocol: v, b, presets, select, default, save)."""
|
||||
# if data.get("v") != "1":
|
||||
# return
|
||||
# global last_brightness_save
|
||||
# if "b" in data:
|
||||
# try:
|
||||
# presets.b = max(0, min(255, int(data["b"])))
|
||||
# settings["brightness"] = presets.b
|
||||
# now = utime.ticks_ms()
|
||||
# if utime.ticks_diff(now, last_brightness_save) >= 500:
|
||||
# settings.save()
|
||||
# last_brightness_save = now
|
||||
# except (TypeError, ValueError):
|
||||
# pass
|
||||
# if "presets" in data:
|
||||
# for id, preset_data in data["presets"].items():
|
||||
# if "c" in preset_data:
|
||||
# preset_data["c"] = convert_and_reorder_colors(preset_data["c"], settings)
|
||||
# presets.edit(id, preset_data)
|
||||
# print("Edited preset", id, preset_data.get("name", ""))
|
||||
# if settings.get("name") in data.get("select", {}):
|
||||
# select_list = data["select"][settings.get("name")]
|
||||
# if select_list:
|
||||
# preset_name = select_list[0]
|
||||
# step = select_list[1] if len(select_list) > 1 else None
|
||||
# presets.select(preset_name, step=step)
|
||||
# if "default" in data:
|
||||
# settings["startup_preset"] = data["default"]
|
||||
# print("Set startup preset to", data["default"])
|
||||
# settings.save()
|
||||
# if "save" in data:
|
||||
# presets.save()
|
||||
|
||||
|
||||
# while True:
|
||||
# presets.tick()
|
||||
# n = uart.any()
|
||||
# if n:
|
||||
# data_in = uart.read(n)
|
||||
# if data_in:
|
||||
# for b in data_in:
|
||||
# if b in (0x0A, 0x0D): # LF or CR
|
||||
# if uart_buf:
|
||||
# try:
|
||||
# msg = uart_buf.decode("utf-8").strip()
|
||||
# if msg:
|
||||
# data = json.loads(msg)
|
||||
# process_message(data)
|
||||
# except (ValueError, UnicodeError):
|
||||
# pass
|
||||
# uart_buf = bytearray()
|
||||
# else:
|
||||
# if len(uart_buf) < 1024:
|
||||
# uart_buf.append(b)
|
||||
# utime.sleep_ms(1)
|
||||
|
||||
from neopixel import NeoPixel
|
||||
from machine import Pin
|
||||
|
||||
pins = ((2,270), (3,271), (4,272), (0,273), (7,274), (6,275), (29,276), (28,277))
|
||||
for pin, num_leds in pins:
|
||||
print(pin, num_leds)
|
||||
np = NeoPixel(Pin(pin), num_leds)
|
||||
np.fill((8, 0, 0))
|
||||
np.write()
|
||||
Reference in New Issue
Block a user