Improve dashboard master config and separate slave deadzone updates.
Always show master deadzone input with read/set controls; apply bulk slave changes via slaves_only without changing the master's BMA456. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+53
-2
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -21,6 +22,8 @@ type deadzoneAPIRequest struct {
|
||||
Deadzone uint32 `json:"deadzone"`
|
||||
ClientID uint32 `json:"client_id"`
|
||||
AllClients bool `json:"all_clients"`
|
||||
// SlavesOnly: with all_clients, push to ESP-NOW slaves only (master BMA456 unchanged).
|
||||
SlavesOnly bool `json:"slaves_only"`
|
||||
}
|
||||
|
||||
type unicastAPIRequest struct {
|
||||
@@ -84,12 +87,30 @@ func serveDeadzonePost(w http.ResponseWriter, r *http.Request, link *managedSeri
|
||||
writeJSON(w, http.StatusBadRequest, deadzoneAPIResponse{Error: "invalid JSON"})
|
||||
return
|
||||
}
|
||||
resp, err := link.AccelDeadzone(&pb.AccelDeadzoneRequest{
|
||||
if body.AllClients && body.SlavesOnly {
|
||||
updated, err := applyDeadzoneToSlaves(link, body.Deadzone)
|
||||
if err != nil {
|
||||
writeJSON(w, http.StatusServiceUnavailable, deadzoneAPIResponse{
|
||||
Error: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, deadzoneAPIResponse{
|
||||
Deadzone: body.Deadzone,
|
||||
Success: updated > 0,
|
||||
SlavesUpdated: updated,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
req := &pb.AccelDeadzoneRequest{
|
||||
Write: true,
|
||||
Deadzone: body.Deadzone,
|
||||
ClientId: body.ClientID,
|
||||
AllClients: body.AllClients,
|
||||
})
|
||||
}
|
||||
// client_id 0 without all_clients: master BMA456 only (same as CLI -client 0).
|
||||
resp, err := link.AccelDeadzone(req)
|
||||
if err != nil {
|
||||
writeJSON(w, http.StatusServiceUnavailable, deadzoneAPIResponse{
|
||||
ClientID: body.ClientID,
|
||||
@@ -105,6 +126,36 @@ func serveDeadzonePost(w http.ResponseWriter, r *http.Request, link *managedSeri
|
||||
})
|
||||
}
|
||||
|
||||
// applyDeadzoneToSlaves sets deadzone on each registered slave via per-client UART/ESP-NOW.
|
||||
// Does not change the master's local BMA456 (use client_id 0 for that).
|
||||
func applyDeadzoneToSlaves(link *managedSerial, deadzone uint32) (uint32, error) {
|
||||
clients, err := link.listClients()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var updated uint32
|
||||
for _, c := range clients {
|
||||
resp, err := link.AccelDeadzone(&pb.AccelDeadzoneRequest{
|
||||
Write: true,
|
||||
Deadzone: deadzone,
|
||||
ClientId: c.GetId(),
|
||||
})
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if resp.GetSuccess() {
|
||||
updated++
|
||||
}
|
||||
}
|
||||
if len(clients) == 0 {
|
||||
return 0, fmt.Errorf("no slaves registered")
|
||||
}
|
||||
if updated == 0 {
|
||||
return 0, fmt.Errorf("deadzone not applied to any slave")
|
||||
}
|
||||
return updated, nil
|
||||
}
|
||||
|
||||
func serveUnicastTest(w http.ResponseWriter, r *http.Request, link *managedSerial) {
|
||||
var body unicastAPIRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user