Solid color mode fills all ring LEDs; master routes UART commands to slaves via ESPNOW_LED_RING. goTool exposes POST /api/led-ring, WebSocket set_led_ring, and a dashboard LED panel with master/slave/all targets. Co-authored-by: Cursor <cursoragent@cursor.com>
37 lines
959 B
Go
37 lines
959 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
func mountLedRingAPI(mux *http.ServeMux, link *managedSerial) {
|
|
mux.HandleFunc("/api/led-ring", func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodPost {
|
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
serveLedRingPost(w, r, link)
|
|
})
|
|
}
|
|
|
|
func serveLedRingPost(w http.ResponseWriter, r *http.Request, link *managedSerial) {
|
|
var body ledRingAPIRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
|
writeJSON(w, http.StatusBadRequest, ledRingAPIResponse{Error: "invalid JSON"})
|
|
return
|
|
}
|
|
if body.Mode == "" {
|
|
writeJSON(w, http.StatusBadRequest, ledRingAPIResponse{Error: "mode required"})
|
|
return
|
|
}
|
|
out := applyLedRing(link, body)
|
|
status := http.StatusOK
|
|
if out.Error != "" {
|
|
status = http.StatusServiceUnavailable
|
|
} else if !out.Success {
|
|
status = http.StatusServiceUnavailable
|
|
}
|
|
writeJSON(w, status, out)
|
|
}
|