upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-18 19:58:12 +0530
committerYour Name <you@example.com>2026-05-18 19:58:12 +0530
commit7820837d79ebc8e00221b5206bdd8e3ca0ae4c15 (patch)
tree98070e83e4e8bfa0b46009d202e7b81410c960f6 /main
parent7dd532cee475d486552e886dd7173c8853f80b60 (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')
-rw-r--r--main/display.c23
-rw-r--r--main/display.h1
-rw-r--r--main/tollgate_api.c3
-rw-r--r--main/tollgate_main.c13
4 files changed, 36 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;
34static bool s_initialized = false; 35static bool s_initialized = false;
35static int64_t s_last_qr_switch = 0; 36static int64_t s_last_qr_switch = 0;
36static display_qr_mode_t s_qr_mode = DISPLAY_QR_WIFI; 37static display_qr_mode_t s_qr_mode = DISPLAY_QR_WIFI;
38static int s_last_payment_sats = 0;
39static int64_t s_last_allotment_ms = 0;
37 40
38static int qr_version_from_strlen(int len) { 41static 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
390void 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}
diff --git a/main/display.h b/main/display.h
index 1530e57..49b3ffd 100644
--- a/main/display.h
+++ b/main/display.h
@@ -23,6 +23,7 @@ void display_update(const char *ap_ssid, int active_clients,
23 uint64_t wallet_balance, const char *portal_url, 23 uint64_t wallet_balance, const char *portal_url,
24 const char *mint_url, int price_per_step, 24 const char *mint_url, int price_per_step,
25 const char *wifi_status); 25 const char *wifi_status);
26void display_notify_payment(int amount_sats, int64_t allotment_ms);
26void display_render_text(int x, int y, const char *text, uint16_t fg, uint16_t bg, int scale); 27void display_render_text(int x, int y, const char *text, uint16_t fg, uint16_t bg, int scale);
27void display_render_qr(const char *text); 28void display_render_qr(const char *text);
28 29
diff --git a/main/tollgate_api.c b/main/tollgate_api.c
index 650b0f3..7ddfb9e 100644
--- a/main/tollgate_api.c
+++ b/main/tollgate_api.c
@@ -4,6 +4,7 @@
4#include "session.h" 4#include "session.h"
5#include "firewall.h" 5#include "firewall.h"
6#include "nucula_wallet.h" 6#include "nucula_wallet.h"
7#include "display.h"
7#include "esp_log.h" 8#include "esp_log.h"
8#include "cJSON.h" 9#include "cJSON.h"
9#include "lwip/sockets.h" 10#include "lwip/sockets.h"
@@ -313,6 +314,8 @@ static esp_err_t api_post_payment(httpd_req_t *req)
313 314
314 nucula_wallet_receive(body_copy); 315 nucula_wallet_receive(body_copy);
315 316
317 display_notify_payment(token->total_amount, allotment);
318
316 free(states); 319 free(states);
317 free(token); 320 free(token);
318 return ESP_OK; 321 return ESP_OK;
diff --git a/main/tollgate_main.c b/main/tollgate_main.c
index 7fd50ad..345295a 100644
--- a/main/tollgate_main.c
+++ b/main/tollgate_main.c
@@ -77,11 +77,13 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base,
77 ESP_LOGI(TAG, "Station connected: MAC=%02x:%02x:%02x:%02x:%02x:%02x", 77 ESP_LOGI(TAG, "Station connected: MAC=%02x:%02x:%02x:%02x:%02x:%02x",
78 event->mac[0], event->mac[1], event->mac[2], 78 event->mac[0], event->mac[1], event->mac[2],
79 event->mac[3], event->mac[4], event->mac[5]); 79 event->mac[3], event->mac[4], event->mac[5]);
80 display_update(NULL, session_active_count(), 0, NULL, NULL, 0, NULL);
80 } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_AP_STADISCONNECTED) { 81 } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_AP_STADISCONNECTED) {
81 wifi_event_ap_stadisconnected_t *event = (wifi_event_ap_stadisconnected_t *)event_data; 82 wifi_event_ap_stadisconnected_t *event = (wifi_event_ap_stadisconnected_t *)event_data;
82 ESP_LOGI(TAG, "Station disconnected: MAC=%02x:%02x:%02x:%02x:%02x:%02x", 83 ESP_LOGI(TAG, "Station disconnected: MAC=%02x:%02x:%02x:%02x:%02x:%02x",
83 event->mac[0], event->mac[1], event->mac[2], 84 event->mac[0], event->mac[1], event->mac[2],
84 event->mac[3], event->mac[4], event->mac[5]); 85 event->mac[3], event->mac[4], event->mac[5]);
86 display_update(NULL, session_active_count(), 0, NULL, NULL, 0, NULL);
85 } 87 }
86} 88}
87 89
@@ -314,6 +316,9 @@ void app_main(void)
314 316
315 ESP_LOGI(TAG, "WiFi AP+STA started, waiting for connection..."); 317 ESP_LOGI(TAG, "WiFi AP+STA started, waiting for connection...");
316 318
319 display_update(tcfg->ap_ssid, 0, 0, NULL,
320 tcfg->mint_url, tcfg->price_per_step, "connecting...");
321
317 if (tollgate_config_get_wifi(&(wifi_config_t){0}) != ESP_OK) { 322 if (tollgate_config_get_wifi(&(wifi_config_t){0}) != ESP_OK) {
318 ESP_LOGI(TAG, "No STA network configured, starting services immediately"); 323 ESP_LOGI(TAG, "No STA network configured, starting services immediately");
319 xTaskCreate(services_start_task, "svc_start", 32768, NULL, 5, NULL); 324 xTaskCreate(services_start_task, "svc_start", 32768, NULL, 5, NULL);
@@ -324,5 +329,13 @@ void app_main(void)
324 session_tick(); 329 session_tick();
325 tollgate_client_tick(); 330 tollgate_client_tick();
326 lightning_payout_tick(); 331 lightning_payout_tick();
332
333 static int display_tick = 0;
334 if (++display_tick >= 5) {
335 display_tick = 0;
336 display_update(NULL, session_active_count(),
337 nucula_wallet_balance(), NULL,
338 NULL, 0, NULL);
339 }
327 } 340 }
328} 341}