14#if DETWS_ENABLE_GPIO_MAP
25 DetwsGpioPin *pins =
nullptr;
28static GpioRoutesCtx s_gpior;
30static void gpio_get_handler(uint8_t slot_id,
HttpReq *req)
33 detws_gpio_read(s_gpior.pins, s_gpior.count);
35 detws_gpio_json(s_gpior.pins, s_gpior.count, buf,
sizeof(buf));
37 s_gpior.srv->send(slot_id, 200, DET_MIME_JSON, buf);
40static void gpio_post_handler(uint8_t slot_id,
HttpReq *req)
46 if (!detws_gpio_parse_set((
const char *)req->
body, req->
body_len, &pin, &level))
48 s_gpior.srv->send(slot_id, 400, DET_MIME_TEXT_PLAIN,
"bad request");
51 if (!detws_gpio_is_output(s_gpior.pins, s_gpior.count, pin))
53 s_gpior.srv->send(slot_id, 403, DET_MIME_TEXT_PLAIN,
"pin not a mapped output");
56 detws_gpio_write(pin, level);
57 detws_gpio_read(s_gpior.pins, s_gpior.count);
59 detws_gpio_json(s_gpior.pins, s_gpior.count, buf,
sizeof(buf));
60 s_gpior.srv->send(slot_id, 200, DET_MIME_JSON, buf);
63void detws_gpio_map_begin(
DetWebServer &server,
const char *path, DetwsGpioPin *pins, uint8_t count)
65 s_gpior.srv = &server;
67 s_gpior.count = count;
68 detws_gpio_begin_pins(pins, count);
69 const char *p = (path && path[0]) ? path :
"/gpio";
#define DETWS_GPIO_JSON_BUF
Stack buffer for the GPIO-map JSON (bytes).
Single-port HTTP server with deterministic, zero-allocation execution.
void on(const char *path, HttpMethod method, Handler callback)
Register a route handler.
Layer 7 (Application) - public HTTP routing API.
@ HTTP_POST
Non-idempotent create / action.
@ HTTP_GET
Safe, idempotent read.
Browser GPIO pin-mapper / diagnostics (DETWS_ENABLE_GPIO_MAP).
Shared HTTP Content-Type ("MIME") string constants (one source of truth).
Fully-parsed HTTP/1.1 request.
uint8_t body[BODY_BUF_SIZE+1]
Stored body bytes, always null-terminated.
size_t body_len
Bytes stored in body[] (≤ BODY_BUF_SIZE).