25 pc_gpio_pin *pins =
nullptr;
28static GpioRoutesCtx s_gpior;
30static void gpio_get_handler(uint8_t slot_id,
HttpReq *req)
33 pc_gpio_read(s_gpior.pins, s_gpior.count);
35 pc_gpio_json(s_gpior.pins, s_gpior.count, buf,
sizeof(buf));
38 s_gpior.srv->send(slot_id, 200, PC_MIME_JSON, buf);
42static void gpio_post_handler(uint8_t slot_id,
HttpReq *req)
50 if (!pc_gpio_parse_set((
const char *)req->
body, req->
body_len, &pin, &level))
52 s_gpior.srv->send(slot_id, 400, PC_MIME_TEXT_PLAIN,
"bad request");
55 if (!pc_gpio_is_output(s_gpior.pins, s_gpior.count, pin))
57 s_gpior.srv->send(slot_id, 403, PC_MIME_TEXT_PLAIN,
"pin not a mapped output");
60 pc_gpio_write(pin, level);
61 pc_gpio_read(s_gpior.pins, s_gpior.count);
63 pc_gpio_json(s_gpior.pins, s_gpior.count, buf,
sizeof(buf));
64 s_gpior.srv->send(slot_id, 200, PC_MIME_JSON, buf);
67void pc_gpio_map_begin(
PC &server,
const char *path, pc_gpio_pin *pins, uint8_t count)
69 s_gpior.srv = &server;
71 s_gpior.count = count;
72 pc_gpio_begin_pins(pins, count);
73 const char *p = (path && path[0]) ? path :
"/gpio";
Single-port HTTP server with deterministic, zero-allocation execution.
void on(const char *path, HttpMethod method, Handler callback)
Register a route handler.
Browser GPIO pin-mapper / diagnostics (PC_ENABLE_GPIO_MAP).
Shared HTTP Content-Type ("MIME") string constants (one source of truth).
Layer 7 (Application) - public HTTP routing API.
@ HTTP_POST
Non-idempotent create / action.
@ HTTP_GET
Safe, idempotent read.
#define PC_GPIO_JSON_BUF
Stack buffer for the GPIO-map JSON (bytes).
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).