diff options
| author | Your Name <you@example.com> | 2026-05-18 19:58:12 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-18 19:58:12 +0530 |
| commit | 7820837d79ebc8e00221b5206bdd8e3ca0ae4c15 (patch) | |
| tree | 98070e83e4e8bfa0b46009d202e7b81410c960f6 /main/display.c | |
| parent | 7dd532cee475d486552e886dd7173c8853f80b60 (diff) | |
Sync display with live TollGate state
- Periodic refresh: wallet balance + client count every 5s from main loop
- display_notify_payment() API: passes payment amount and time allotment
- tollgate_api.c: triggers PAYMENT_RECEIVED state after wallet receive
- AP station events update client count in real-time
- Config data (price, mint) passed to display during boot phase
- Payment screen shows actual sats paid and time purchased
- Updated DISPLAY_UI_PLAN.md with state-sync audit and checklist
Diffstat (limited to 'main/display.c')
| -rw-r--r-- | main/display.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/main/display.c b/main/display.c index add97db..0935743 100644 --- a/main/display.c +++ b/main/display.c | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | #include "axs15231b.h" | 2 | #include "axs15231b.h" |
| 3 | #include "qrcoded.h" | 3 | #include "qrcoded.h" |
| 4 | #include "font.h" | 4 | #include "font.h" |
| 5 | #include "nucula_wallet.h" | ||
| 5 | #include "esp_log.h" | 6 | #include "esp_log.h" |
| 6 | #include "freertos/FreeRTOS.h" | 7 | #include "freertos/FreeRTOS.h" |
| 7 | #include "freertos/task.h" | 8 | #include "freertos/task.h" |
| @@ -34,6 +35,8 @@ static int s_price_per_step = 0; | |||
| 34 | static bool s_initialized = false; | 35 | static bool s_initialized = false; |
| 35 | static int64_t s_last_qr_switch = 0; | 36 | static int64_t s_last_qr_switch = 0; |
| 36 | static display_qr_mode_t s_qr_mode = DISPLAY_QR_WIFI; | 37 | static display_qr_mode_t s_qr_mode = DISPLAY_QR_WIFI; |
| 38 | static int s_last_payment_sats = 0; | ||
| 39 | static int64_t s_last_allotment_ms = 0; | ||
| 37 | 40 | ||
| 38 | static int qr_version_from_strlen(int len) { | 41 | static int qr_version_from_strlen(int len) { |
| 39 | if (len <= 17) return 1; | 42 | if (len <= 17) return 1; |
| @@ -251,13 +254,18 @@ static void render_payment_screen(void) { | |||
| 251 | 254 | ||
| 252 | char line[48]; | 255 | char line[48]; |
| 253 | 256 | ||
| 254 | snprintf(line, sizeof(line), "Paid: %d sats", s_price_per_step); | 257 | snprintf(line, sizeof(line), "Paid: %d sats", s_last_payment_sats); |
| 255 | int lw = strlen(line) * 8; | 258 | int lw = strlen(line) * 8; |
| 256 | display_render_text((screen_w - lw) / 2, 270, line, COLOR_WHITE, COLOR_BG, 1); | 259 | display_render_text((screen_w - lw) / 2, 270, line, COLOR_WHITE, COLOR_BG, 1); |
| 257 | 260 | ||
| 258 | const char *time_msg = "Time: 1 min"; | 261 | int64_t secs = s_last_allotment_ms / 1000; |
| 259 | int tw = strlen(time_msg) * 8; | 262 | if (secs >= 60) { |
| 260 | display_render_text((screen_w - tw) / 2, 290, time_msg, COLOR_WHITE, COLOR_BG, 1); | 263 | snprintf(line, sizeof(line), "Time: %lld min", (long long)(secs / 60)); |
| 264 | } else { | ||
| 265 | snprintf(line, sizeof(line), "Time: %lld sec", (long long)secs); | ||
| 266 | } | ||
| 267 | lw = strlen(line) * 8; | ||
| 268 | display_render_text((screen_w - lw) / 2, 290, line, COLOR_WHITE, COLOR_BG, 1); | ||
| 261 | 269 | ||
| 262 | snprintf(line, sizeof(line), "Wallet: %llu sats", (unsigned long long)s_wallet_balance); | 270 | snprintf(line, sizeof(line), "Wallet: %llu sats", (unsigned long long)s_wallet_balance); |
| 263 | lw = strlen(line) * 8; | 271 | lw = strlen(line) * 8; |
| @@ -378,3 +386,10 @@ void display_update(const char *ap_ssid, int active_clients, | |||
| 378 | s_active_clients = active_clients; | 386 | s_active_clients = active_clients; |
| 379 | s_wallet_balance = wallet_balance; | 387 | s_wallet_balance = wallet_balance; |
| 380 | } | 388 | } |
| 389 | |||
| 390 | void display_notify_payment(int amount_sats, int64_t allotment_ms) { | ||
| 391 | s_last_payment_sats = amount_sats; | ||
| 392 | s_last_allotment_ms = allotment_ms; | ||
| 393 | s_wallet_balance = nucula_wallet_balance(); | ||
| 394 | display_set_state(DISPLAY_PAYMENT_RECEIVED); | ||
| 395 | } | ||