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 /src/sketch.cpp | |
| parent | b0a361b4c4a6b1b55965cb0ca6017d4c9557aaf5 (diff) | |
fix code (derogatory)
Diffstat (limited to 'src/sketch.cpp')
| -rw-r--r-- | src/sketch.cpp | 46 |
1 files changed, 30 insertions, 16 deletions
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(); |
