feat(sacn): Endpunkt zum Einstellen und Statusfeld in system/info

This commit is contained in:
Michael Sauer
2026-09-20 00:24:09 +02:00
parent 882cb55297
commit e892b441ce
3 changed files with 161 additions and 0 deletions
+45
View File
@@ -265,6 +265,13 @@ static void handle_info(const nl_api_ctx_t *ctx, nl_api_response_t *resp)
cJSON_AddStringToObject(o, "last_ota_error", in.last_ota_error);
else
cJSON_AddNullToObject(o, "last_ota_error");
{
nl_settings_t s;
cJSON *sa = cJSON_AddObjectToObject(o, "sacn");
ctx->get_settings(&s);
cJSON_AddBoolToObject(sa, "active", in.sacn_active);
cJSON_AddNumberToObject(sa, "universe", s.sacn_universe);
}
reply_json(resp, 200, o);
}
@@ -286,6 +293,16 @@ static void handle_get_settings(const nl_api_ctx_t *ctx, nl_api_response_t *resp
* kommen, ohne die Bedeutung von "ssid" zu aendern. */
cJSON_AddStringToObject(w, "source", s.wifi_ssid[0] ? "stored" : "compiled");
cJSON_AddBoolToObject(o, "auth_all", s.auth_all != 0);
{
cJSON *sa = cJSON_AddObjectToObject(o, "sacn");
cJSON_AddBoolToObject(sa, "enabled", s.sacn_enabled != 0);
cJSON_AddNumberToObject(sa, "universe", s.sacn_universe);
cJSON_AddNumberToObject(sa, "start_slot", s.sacn_start_slot);
cJSON_AddStringToObject(sa, "on_timeout", s.sacn_hold ? "hold" : "release");
/* Informativ und bewusst aus dem Board, nicht aus dem Datensatz: so steht beim
* Adressieren direkt da, wieviel Platz diese Lampe im Universe belegt. */
cJSON_AddNumberToObject(sa, "slots", nl_board_dmx_slots(ctx->board));
}
reply_json(resp, 200, o);
}
@@ -333,6 +350,34 @@ static void handle_put_settings(const nl_api_ctx_t *ctx, const nl_http_request_t
err = "invalid all";
else
s.auth_all = cJSON_IsTrue(all) ? 1 : 0;
} else if (strcmp(type, "sacn") == 0) {
const cJSON *en = cJSON_GetObjectItemCaseSensitive(j, "enabled");
const cJSON *un = cJSON_GetObjectItemCaseSensitive(j, "universe");
const cJSON *st = cJSON_GetObjectItemCaseSensitive(j, "start_slot");
const char *ot = NULL;
int otp;
uint8_t slots = nl_board_dmx_slots(ctx->board);
if (en && !cJSON_IsBool(en)) {
err = "invalid enabled";
} else if (un && (!cJSON_IsNumber(un) || un->valuedouble < 1 || un->valuedouble > 63999)) {
err = "invalid universe";
} else if (st && (!cJSON_IsNumber(st) || st->valuedouble < 1 ||
st->valuedouble + slots - 1 > 512)) {
err = "invalid start_slot";
} else if ((otp = get_string(j, "on_timeout", 1, 16, &ot)) < 0 ||
(otp == 1 && strcmp(ot, "release") != 0 && strcmp(ot, "hold") != 0)) {
err = "invalid on_timeout";
} else {
if (en)
s.sacn_enabled = cJSON_IsTrue(en) ? 1 : 0;
if (un)
s.sacn_universe = (uint16_t)un->valuedouble;
if (st)
s.sacn_start_slot = (uint16_t)st->valuedouble;
if (otp == 1)
s.sacn_hold = strcmp(ot, "hold") == 0 ? 1 : 0;
}
} else {
err = "invalid type";
}
+1
View File
@@ -24,6 +24,7 @@ typedef struct {
uint32_t uptime_s;
uint32_t free_heap;
const char *last_ota_error; /* NULL until OTA exists */
bool sacn_active; /* true, solange die Lampe ferngesteuert wird */
} nl_sys_info_t;
/* Everything the API needs from the application; implemented by src/sys/nl_app_api.c. */