#include #include #include #include #define WIFI_HOTSPOT_IP "192.168.4.1" static TFT_eSPI tft; void display_setup(void) { tft.init(); tft.setRotation(1); tft.writecommand(TFT_DISPON); tft.fillScreen(TFT_BLACK); } void display_on(void) { tft.writecommand(TFT_DISPON); } void display_off(void) { tft.writecommand(TFT_DISPOFF); } void display_begin(void) { tft.startWrite(); } void display_end(void) { tft.endWrite(); } void display_clear(uint16_t color) { tft.fillScreen(color); } void display_set_pixel(int32_t x, int32_t y, uint16_t color) { if (x < 0 || x >= DISPLAY_WIDTH || y < 0 || y >= DISPLAY_HEIGHT) return; tft.drawPixel(x, y, color); } #define BUTTON_PIN 4 void button_setup(void) { pinMode(BUTTON_PIN, INPUT_PULLUP); } bool button_get(void) { return digitalRead(BUTTON_PIN) == LOW; } static WebServer server(80); static bool hotspot_active = false; void wifi_setup(void) { WiFi.mode(WIFI_OFF); } void wifi_hotspot_start(const char *ssid, const char *password, WifiHandler handler) { WiFi.mode(WIFI_AP); WiFi.softAP(ssid, password); server.onNotFound([=]() { String uri = server.uri(); String body; // build body string from parsed args if plain isn't available if (server.hasArg("plain")) { body = server.arg("plain"); } else { for (int i = 0; i < server.args(); i++) { if (!body.isEmpty()) body += "&"; body += server.argName(i).c_str(); body += "="; body += server.arg(i).c_str(); } } WifiRequest req = { .uri = uri.c_str(), .method = server.method() == HTTP_GET ? "GET" : "POST", .body = body.isEmpty() ? nullptr : body.c_str(), }; WifiResponse res = handler(&req); server.send(res.status, res.content_type, res.body); }); server.begin(); hotspot_active = true; } void wifi_hotspot_stop(void) { server.stop(); WiFi.softAPdisconnect(true); WiFi.mode(WIFI_OFF); hotspot_active = false; } void wifi_tick(void) { if (hotspot_active) server.handleClient(); }