2#include "hardware/gpio.h"
14 printf(
"[GpioController] Initializing GPIO routes...\n");
31 int pin = std::stoi(params[0]);
33 res.
json({{
"pin", pin}, {
"state", state ? 1 : 0}});
37 int pin = std::stoi(params[0]);
38 int value = std::stoi(params[1]);
40 res.
json({{
"pin", pin}, {
"state", value}});
46 if (queryParams.empty())
52 json response = json::array();
53 bool foundPinParam =
false;
55 for (
const auto& param : queryParams)
57 if (param.first ==
"pin")
60 int pin = atoi(param.second.c_str());
69 response.push_back(pinState);
Utility functions to send standard JSON responses using nlohmann::json.
Base class for event-driven control logic in embedded applications.
Router & router
Handles path-to-handler mapping - reference to shared Router instance.
GpioController(Router &r, PicoModel &pico)
void initRoutes() override
Initialize routes for this controller.
void handleGetMultipleGpios(HttpRequest &req, HttpResponse &res)
void getState(HttpRequest &req, HttpResponse &res, const std::vector< std::string > ¶ms)
void setState(HttpRequest &req, HttpResponse &res, const std::vector< std::string > ¶ms)
Forward declaration for potential routing needs.
const std::unordered_multimap< std::string, std::string > getQueryParams()
Get parsed query string parameters.
Represents an HTTP response object.
HttpResponse & json(const std::string &jsonString)
Send a JSON string/object with correct content type.
void setGpioState(int pin, bool state)
bool getGpioState(int pin)
The central router for handling HTTP requests and middleware.
void addRoute(const std::string &method, const std::string &path, RouteHandler handler, std::vector< Middleware > middleware={})
Register a route with optional middleware.
void sendNoContent(HttpResponse &res)
Represents a match of a route against an incoming HTTP request.
std::vector< std::string > ordered