Konfigurowalne piny GPIO przez gpio.json i endpoint /api/secure/gpio#2
Konfigurowalne piny GPIO przez gpio.json i endpoint /api/secure/gpio#2koder95 wants to merge 2 commits into
gpio.json i endpoint /api/secure/gpio#2Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d324a53c16
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if previous.get('sensor') != self.gpio['sensor']: | ||
| self.sensorPin = Pin(self.gpio['sensor'], Pin.IN, Pin.PULL_UP) | ||
| if previous.get('pixel') != self.gpio['pixel']: | ||
| self.waterflow.removeAll() |
There was a problem hiding this comment.
Flush the old LED strip before switching pins
When an admin changes pixel while LEDs are lit, this only clears the old WaterflowPixel object's in-memory buffer. WaterflowPixel.removeAll() does not call show(), and the next line replaces the object with one bound to the new GPIO, so the old data line never receives zeros and any lit LEDs can remain latched on until that old pin is driven again. Flush the cleared buffer on the old instance before constructing the replacement.
Useful? React with 👍 / 👎.
| if not isinstance(value, int) or value < 0 or value > 28: | ||
| return json.dumps({"message": "Bad Request"}), 400, {"Content-type": "application/json"} |
There was a problem hiding this comment.
Reject boolean GPIO values before applying them
For JSON bodies containing booleans, this validation accepts them because bool is an int subclass in Python/MicroPython, so a request like {"pixel": true} passes the documented integer check and is then persisted/applied as GPIO 1. That makes malformed API input silently remap hardware pins; reject bool explicitly before calling configure_gpio().
Useful? React with 👍 / 👎.
Motivation
Description
gpio.jsonz domyślnymi wartościami{ "pixel":19, "sensor":18, "off":20 }oraz wpis w README opisujący jego format i użycie.utils.pydodano helperynormalize_gpio_config,load_gpio_configisave_gpio_configz walidacją zakresu (0–28) i domyślnymi wartościami.WaterflowDriverteraz ładuje konfigurację GPIO przy inicjalizacji, używa wartości zgpio.jsondla pinu strip/sensor/off, dodał metodyconfigure_gpioireload_gpiooraz stosuje zmiany w runtime (przełączenie pinów / rekreacja instancjiWaterflowPixel).GET /api/secure/gpioorazPUT|PATCH /api/secure/gpiowmyhttp.py, które wymagają roliadmin, walidują wejście, zapisują znormalizowaną konfigurację i aplikują ją do działającego sterownika.README.mdo opisgpio.json, dokumentację endpointuapi/secure/gpiooraz przykładowe poleceniecurli listę plików konfiguracyjnych.Testing
python3 -m py_compile main.py myhttp.py waterflowdriver.py waterflowpixel.py auth.py utils.py config.py ktime.py neopixel.py— zakończono pomyślnie (syntax checks passed).python3 -m json.tool gpio.json— plikgpio.jsonjest poprawnym JSON-em (succeeded).machine,network) naPYTHONPATH=libwykazał poprawne działanienormalize_gpio_configdla zestawu przypadków (succeeded).Codex Task