diff options
| author | kkard2 <[email protected]> | 2026-06-10 17:27:42 +0200 |
|---|---|---|
| committer | kkard2 <[email protected]> | 2026-06-10 17:27:42 +0200 |
| commit | 948fc36aa4ed012ac4943237e771b6d187d43ce5 (patch) | |
| tree | ee08da896aa434eec484dd900b4b77428e5dfff2 | |
| parent | b0a361b4c4a6b1b55965cb0ca6017d4c9557aaf5 (diff) | |
fix code (derogatory)
| -rw-r--r-- | platformio.ini | 3 | ||||
| -rw-r--r-- | src/driver.cpp | 19 | ||||
| -rw-r--r-- | src/sketch.cpp | 46 |
3 files changed, 49 insertions, 19 deletions
diff --git a/platformio.ini b/platformio.ini index 1d210e6..f6d9fa2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,7 +8,8 @@ lib_deps = build_src_filter = +<sketch.cpp> -<driver.cpp> -<driver_raylib.cpp> -<emulator.cpp> -<font_atlas.c> build_flags = -D USER_SETUP_LOADED - -D ILI9163_DRIVER=1 ; Select ILI9163 driver + -D TFT_INVERSION_ON + -D ILI9341_2_DRIVER=1 ; Select ILI9341 driver -D TFT_WIDTH=240 ; Set TFT size -D TFT_HEIGHT=320 ;-D TFT_MISO=19 ; Define SPI pins diff --git a/src/driver.cpp b/src/driver.cpp index 2beff5b..a7b235c 100644 --- a/src/driver.cpp +++ b/src/driver.cpp @@ -63,10 +63,25 @@ void wifi_hotspot_start(const char *ssid, const char *password, WifiHandler hand 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 = server.uri().c_str(), + .uri = uri.c_str(), .method = server.method() == HTTP_GET ? "GET" : "POST", - .body = server.hasArg("plain") ? server.arg("plain").c_str() : nullptr, + .body = body.isEmpty() ? nullptr : body.c_str(), }; WifiResponse res = handler(&req); server.send(res.status, res.content_type, res.body); diff --git a/src/sketch.cpp b/src/sketch.cpp index 168136c..0d11166 100644 --- a/src/sketch.cpp +++ b/src/sketch.cpp @@ -194,6 +194,7 @@ static Color24 display_bg1 = { 0, 0, 0}; static Color24 display_bg2 = { 0, 0, 0}; static int32_t display_scale = 2; static bool display_wrap = true; +static bool display_dirty = true; // === App state =============================================================== @@ -211,6 +212,7 @@ static void wifi_start(void) { wifi_active = true; wifi_on_until = millis() + WIFI_TIMEOUT_MS; display_active = true; + display_dirty = true; display_on(); } @@ -219,6 +221,7 @@ static void wifi_stop(void) { wifi_active = false; screen_on_until = millis() + SCREEN_TIMEOUT_MS; display_active = true; + display_dirty = true; display_on(); } @@ -242,6 +245,7 @@ static WifiResponse on_request(const WifiRequest *req) { if (s >= 1 && s <= 4) display_scale = s; } display_wrap = strstr(body, "wrap=1") != nullptr; + display_dirty = true; return { 200, "text/html; charset=utf-8", ok_html }; } @@ -264,12 +268,14 @@ static void button_tick(uint32_t now) { if (pressed && !button_was_pressed) { button_held_since = now; button_hold_fired = false; + display_dirty = true; } if (pressed && !button_hold_fired && (now - button_held_since) > 2000) { button_hold_fired = true; if (wifi_active) wifi_stop(); else wifi_start(); + display_dirty = true; } if (!pressed && button_was_pressed && !button_hold_fired) { @@ -280,6 +286,7 @@ static void button_tick(uint32_t now) { } else if (!wifi_active) { display_off(); } + display_dirty = true; } button_was_pressed = pressed; @@ -295,8 +302,8 @@ static void draw_frame(uint32_t now) { return; } - display_clear(color565(0, 0, 0)); - + if (display_dirty) + display_clear(color565(0, 0, 0)); // progress bar (top 3px) { float t = wifi_active @@ -306,23 +313,27 @@ static void draw_frame(uint32_t now) { color565(display_fg), color565(display_bg1)); } - int32_t x = DISPLAY_MARGIN; - int32_t y = DISPLAY_MARGIN + 3; + if (display_dirty) { + int32_t x = DISPLAY_MARGIN; + int32_t y = DISPLAY_MARGIN + 3; - // wifi info section - if (wifi_active) { - // "Połącz się z siecią" - display_write_text(&x, &y, (uint8_t *)"Po""\xb3""\xb1""cz si""\xea"" z sieci""\xb1"" i ustaw tekst\n", color565(0, 255, 0), 2, DISPLAY_WIDTH - DISPLAY_MARGIN, false); - display_write_text(&x, &y, (uint8_t *)"SSID: " WIFI_SSID "\n", color565(180, 180, 180), 2, 0, false); - display_write_text(&x, &y, (uint8_t *)"PASS: " WIFI_PASSWORD "\n", color565(180, 180, 180), 2, 0, false); - display_write_text(&x, &y, (uint8_t *)WIFI_HOTSPOT_IP "\n", color565(180, 180, 180), 2, 0, false); - } + // wifi info section + if (wifi_active) { + // "Połącz się z siecią" + display_write_text(&x, &y, (uint8_t *)"Po""\xb3""\xb1""cz si""\xea"" z sieci""\xb1"" i ustaw tekst\n", color565(0, 255, 0), 2, DISPLAY_WIDTH - DISPLAY_MARGIN, false); + display_write_text(&x, &y, (uint8_t *)"SSID: " WIFI_SSID "\n", color565(180, 180, 180), 2, 0, false); + display_write_text(&x, &y, (uint8_t *)"PASS: " WIFI_PASSWORD "\n", color565(180, 180, 180), 2, 0, false); + display_write_text(&x, &y, (uint8_t *)WIFI_HOTSPOT_IP "\n", color565(180, 180, 180), 2, 0, false); + } - // text section: gradient background, then text on top - display_gradient_rect(0, y - DISPLAY_MARGIN, DISPLAY_WIDTH, DISPLAY_HEIGHT - y + DISPLAY_MARGIN, display_bg1, display_bg2); - display_write_text(&x, &y, display_text, color565(display_fg), display_scale, DISPLAY_WIDTH - DISPLAY_MARGIN, display_wrap); + // text section: gradient background, then text on top + display_gradient_rect(0, y - DISPLAY_MARGIN, DISPLAY_WIDTH, DISPLAY_HEIGHT - y + DISPLAY_MARGIN, display_bg1, display_bg2); + display_write_text(&x, &y, display_text, color565(display_fg), display_scale, DISPLAY_WIDTH - DISPLAY_MARGIN, display_wrap); + } display_end(); + + display_dirty = false; } // === Entry points ==================================================== @@ -341,13 +352,16 @@ void loop(void) { button_tick(now); // wifi timeout - if (wifi_active && now >= wifi_on_until) + if (wifi_active && now >= wifi_on_until) { wifi_stop(); + display_dirty = true; + } // screen timeout (only when wifi is off) if (!wifi_active && display_active && now >= screen_on_until) { display_active = false; display_off(); + display_dirty = true; } wifi_tick(); |
