From f961306d40654ac6a1ab7c262af7af74401dc693 Mon Sep 17 00:00:00 2001 From: kkard2 Date: Wed, 10 Jun 2026 14:06:55 +0200 Subject: init --- src/driver.cpp | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/driver.cpp (limited to 'src/driver.cpp') diff --git a/src/driver.cpp b/src/driver.cpp new file mode 100644 index 0000000..2beff5b --- /dev/null +++ b/src/driver.cpp @@ -0,0 +1,89 @@ +#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([=]() { + WifiRequest req = { + .uri = server.uri().c_str(), + .method = server.method() == HTTP_GET ? "GET" : "POST", + .body = server.hasArg("plain") ? server.arg("plain").c_str() : nullptr, + }; + 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(); +} -- cgit v1.3.1