Add find-me LED locate on master and slaves via ESP-NOW.
UART FIND_ME (client_id 0 = local ring, >0 = unicast), ESPNOW_FIND_ME payload, CLI/dashboard buttons per slave. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -40,6 +40,16 @@ type unicastAPIResponse struct {
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
type findMeAPIRequest struct {
|
||||
ClientID uint32 `json:"client_id"`
|
||||
}
|
||||
|
||||
type findMeAPIResponse struct {
|
||||
Success bool `json:"success"`
|
||||
ClientID uint32 `json:"client_id,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
type otaAPIResponse struct {
|
||||
Success bool `json:"success"`
|
||||
BytesWritten uint32 `json:"bytes_written,omitempty"`
|
||||
@@ -65,6 +75,13 @@ func mountServeAPI(mux *http.ServeMux, link *managedSerial, hub *wsHub) {
|
||||
}
|
||||
serveUnicastTest(w, r, link)
|
||||
})
|
||||
mux.HandleFunc("/api/find-me", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
serveFindMe(w, r, link)
|
||||
})
|
||||
mux.HandleFunc("/api/ota", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
@@ -216,6 +233,22 @@ func applyDeadzoneToSlaves(link *managedSerial, deadzone uint32) (uint32, error)
|
||||
return updated, nil
|
||||
}
|
||||
|
||||
func serveFindMe(w http.ResponseWriter, r *http.Request, link *managedSerial) {
|
||||
var body findMeAPIRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
writeJSON(w, http.StatusBadRequest, findMeAPIResponse{Error: "invalid JSON"})
|
||||
return
|
||||
}
|
||||
if err := link.FindMe(body.ClientID); err != nil {
|
||||
writeJSON(w, http.StatusServiceUnavailable, findMeAPIResponse{
|
||||
ClientID: body.ClientID,
|
||||
Error: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, findMeAPIResponse{Success: true, ClientID: body.ClientID})
|
||||
}
|
||||
|
||||
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