|
cryptnox-pos 1.0.0
Standalone USDC payment terminal firmware (ESP32 + Cryptnox smart card)
|
Touchscreen UI API: screens, events and transaction states for the CYD (ILI9341 + XPT2046) payment flow. More...
Go to the source code of this file.
Typedefs | |
| typedef void(* | ui_event_cb_t) (ui_event_t event, uint64_t payload) |
| Callback invoked from the UI task on user interaction. | |
Functions | |
| void | ui_init (ui_event_cb_t cb) |
| Initialise display + touch and start the UI task. | |
| void | ui_show_splash (void) |
| Switch to the splash screen. | |
| void | ui_show_amount_entry (void) |
| Switch to the amount-entry screen (forces a value redraw). | |
| void | ui_show_confirm (uint64_t amount_units, const char *dest_addr, const char *fee) |
| Switch to the confirm screen. | |
| void | ui_show_tx_status (ui_tx_state_t state, const char *info) |
| Switch to the transaction-status screen. | |
| void | ui_set_tx_info (const char *info) |
| Replace the transaction screen's info line without rebuilding it. | |
| size_t | ui_take_pin (char *out, size_t n) |
| Copy the most recently entered PIN out and wipe the UI's copy. | |
| void | ui_show_wifi_list (const net_wifi_ap_t *aps, uint16_t n, const char *note) |
| Show the scanned Wi-Fi networks for the user to pick from. | |
| void | ui_show_boot_error (ui_boot_err_t kind, const char *detail) |
| Show a startup fault, naming the cause and what to do about it. | |
| void | ui_set_addresses (const char *token_contract, const char *dest_addr) |
| Provide the token contract and destination addresses for the confirm screen and the settings "Tx" tab (pointers stored as-is; pass static/literal storage that outlives the call). | |
| void | ui_refresh_addresses (void) |
| Implemented by main: repoint those two rows at the selected chain. | |
| void | ui_refresh_addresses_for (uint8_t chain) |
| Same, for any chain (a pos_chain_t) rather than the one sales use. | |
| void | ui_show_wifi_connecting (const char *ssid) |
| Show a "Connecting to <ssid>…" screen while main associates. | |
| void | ui_set_boot_status (const char *step) |
| Set the one-line progress note on the splash screen. | |
| void | ui_fees_changed (void) |
| Note that the stored gas caps have changed, so the Tx tab can catch up. | |
| void | ui_clock_changed (void) |
| Note that the stored UTC offset has changed, so the clock can catch up. | |
| void | ui_show_welcome (const char *sub) |
| Greet the operator at the start of first-run setup, or after an update. | |
| void | ui_show_admin_set (void) |
| Run the first-run admin-code creation (enter, then confirm). | |
| size_t | ui_take_wifi_creds (char *ssid, size_t ssid_n, char *pass, size_t pass_n) |
| Fetch the selected SSID + entered password and wipe the UI's copy. | |
| void | ui_stage_wifi_creds (const char *ssid, const char *pass) |
| Load credentials into the same handoff buffers the picker fills. | |
| void | ui_show_prov (int step) |
| Show the setup screen: QR code, AP name and passphrase. | |
| void | ui_show_prov_confirm (void) |
| Raise the modal that asks the operator to accept a value a browser proposed, reading the pending proposal from provision.h. | |
| void | ui_show_prov_auth (void) |
| Demand the admin code so a browser can be authorised. | |
| void | ui_show_card_pin (void) |
| Ask for the card PIN before reading an address off a Cryptnox card. | |
| void | ui_set_prov_note (const char *msg) |
| Put a failure line on the setup screen, in red under the step title. | |
| void | ui_show_card_wait (const char *note) |
| "Hold your card to the reader" while the address is read. | |
| void | ui_show_ota_confirm (void) |
| Raise the modal that asks the operator to accept a firmware image the update page has uploaded, reading it from ota.h. | |
Touchscreen UI API: screens, events and transaction states for the CYD (ILI9341 + XPT2046) payment flow.
Definition in file ui.h.
| typedef void(* ui_event_cb_t) (ui_event_t event, uint64_t payload) |
Callback invoked from the UI task on user interaction.
Runs in the UI task context — keep it short and non-blocking.
| [in] | event | Event identifier. |
| [in] | payload | Amount in USDC base units for UI_EVENT_AMOUNT_CONFIRMED, 0 otherwise. |
| enum ui_boot_err_t |
Startup faults shown on UI_SCREEN_BOOT_ERROR.
Bring-up problems, not declined payments — hence their own screen. Wording lives in ui.cpp; the caller only names the fault.
| Enumerator | |
|---|---|
| UI_BOOT_ERR_NFC | PN532 did not answer — wiring/power/I2C. |
| UI_BOOT_ERR_WALLET | Reader answered, wallet layer failed to start. |
| UI_BOOT_ERR_CONFIG | A config.h address in this build is invalid. |
| enum ui_event_t |
Events emitted by the UI task towards the main task.
| Enumerator | |
|---|---|
| UI_EVENT_AMOUNT_CONFIRMED | CONFIRM tapped; payload = amount. |
| UI_EVENT_CONFIRM_OK | Send tapped on the Confirm screen. |
| UI_EVENT_CONFIRM_CANCEL | Cancel tapped (Confirm or card wait). |
| UI_EVENT_PIN_ENTERED | PIN keypad validated; fetch via ui_take_pin. |
| UI_EVENT_WIFI_SCAN | User opened the Wi-Fi picker; main should scan. |
| UI_EVENT_WIFI_TRY | Wi-Fi creds entered; fetch via ui_take_wifi_creds. |
| UI_EVENT_TX_RETRY | New sale after Done/Failed, or Clear on Unconfirmed. |
| UI_EVENT_ADMIN_SET | Admin code created and stored (first run). |
| UI_EVENT_WELCOME_DONE | Start tapped on the welcome screen. |
| UI_EVENT_PROV_AUTH | A browser asked to be authorised; the admin code has to be taken on the panel. |
| UI_EVENT_PROV_VALUE | A payout address or token contract was proposed; needs accepting on the panel. |
| UI_EVENT_PROV_VALUE_SET | That value was accepted and stored. |
| UI_EVENT_PROV_VALUE_NO | That value was rejected on the panel. Its own event so a caller holding a second value to offer is not left waiting on an accept that will never come. |
| UI_EVENT_PROV_CARD | The page asked the terminal to read the payout addresses off a Cryptnox card. |
| UI_EVENT_PROV_SCAN | The page asked for a fresh Wi-Fi scan. |
| UI_EVENT_PROV_NEXT | Continue tapped in the browser wizard. |
| UI_EVENT_PROV_FINISH | Finish tapped on the panel's last screen. |
| UI_EVENT_CARD_PIN | PIN entered for a card read, not a payment; fetch via ui_take_pin. |
| UI_EVENT_OTA_STAGED | Firmware uploaded and verified; needs accepting on the panel before it boots. |
| UI_EVENT_TX_RECHECK | Recheck tapped on Unconfirmed: poll the same sale's receipt again. |
| UI_EVENT_PROV_STOP | The UI wants the config portal down (closed card, refused/failed update, admin window over). Main calls prov_stop(): it blocks for up to ~2 s, which froze the panel on the UI task. |
| enum ui_screen_t |
Top-level screens of the payment flow.
| enum ui_tx_state_t |
States shown on the transaction-status screen.
| void ui_clock_changed | ( | void | ) |
Note that the stored UTC offset has changed, so the clock can catch up.
Same handoff as ui_fees_changed and for the same reason: the config page writes the offset straight through from the HTTP task, and the band's clock caches it rather than opening NVS on every three-second tick. Without this the panel keeps the old hour until something rebuilds the screen.
Safe from the HTTP task: applied by the UI task on its next pass.
Definition at line 788 of file ui.cpp.
References s_tz_dirty.
Referenced by clock_post().
| void ui_fees_changed | ( | void | ) |
Note that the stored gas caps have changed, so the Tx tab can catch up.
The caps are the one setting the config page writes straight through, and that page is opened from a card raised over the settings screen — so the two gas rows underneath keep the values they were built with until the operator leaves the screen and comes back. This retexts them in place.
Safe from the HTTP task: applied by the UI task on its next pass, and a no-op when the rows are not on screen (any other screen, or Tron, which has no caps).
Definition at line 783 of file ui.cpp.
References s_fees_dirty.
Referenced by fees_post().
| void ui_init | ( | ui_event_cb_t | cb | ) |
Initialise display + touch and start the UI task.
| [in] | cb | Event callback; must remain valid for the program lifetime. |
Definition at line 696 of file ui.cpp.
References s_cb, s_req_screen, s_screen_dirty, s_ui_mx, UI_SCREEN_SPLASH, and ui_task().
Referenced by pos_boot().
| void ui_refresh_addresses | ( | void | ) |
Implemented by main: repoint those two rows at the selected chain.
The asset picker switches the chain on the UI task and rebuilds the page immediately, so it asks for the new pair here rather than posting an event and racing its own redraw. main owns the per-chain contract and payout strings; this only reads them.
Definition at line 170 of file pay.cpp.
References settings_get_chain(), and ui_refresh_addresses_for().
Referenced by app_main(), btn_event_cb(), and pos_boot().
| void ui_refresh_addresses_for | ( | uint8_t | c | ) |
Same, for any chain (a pos_chain_t) rather than the one sales use.
Point the UI's address rows at the selected chain.
The admin Tx tab browses another asset's contract and payout without switching what the terminal charges in.
Same, for any chain (a pos_chain_t) rather than the one sales use.
Called on every entry to the confirm screen and from the asset picker, since the chain can be switched while this task is parked on its queue (see ui.h).
Definition at line 155 of file pay.cpp.
References active_token(), pos_chain_is_polygon(), pos_chain_is_tron(), s_payout_eth, s_payout_tron, token_t::str, and ui_set_addresses().
Referenced by build_settings(), and ui_refresh_addresses().
| void ui_set_addresses | ( | const char * | token_contract, |
| const char * | dest_addr ) |
Provide the token contract and destination addresses for the confirm screen and the settings "Tx" tab (pointers stored as-is; pass static/literal storage that outlives the call).
Definition at line 764 of file ui.cpp.
References s_addr_dest, and s_addr_usdc.
Referenced by ui_refresh_addresses_for().
| void ui_set_boot_status | ( | const char * | step | ) |
Set the one-line progress note on the splash screen.
Updates the splash in place instead of switching screens. Safe from the main task: applied by the UI task on its next pass.
| [in] | step | Short label ("Starting NFC reader"), copied internally. NULL or "" clears the line. |
Definition at line 776 of file ui.cpp.
References s_boot_step, and s_boot_step_dirty.
Referenced by app_main(), pos_boot(), run_wizard(), and wifi_try_saved().
| void ui_set_prov_note | ( | const char * | msg | ) |
Put a failure line on the setup screen, in red under the step title.
For the card read: a refused card, a wrong PIN or sixty seconds with no tap all end with the panel back on the step it started from, and without a reason there that reads as the terminal having reset itself mid-read. The browser gets the same sentence through prov_set_note — this is the copy for the person actually holding the card.
Cleared by ui_show_card_pin, so each attempt starts clean.
| [in] | msg | Message, copied. NULL or "" clears it. |
Definition at line 880 of file ui.cpp.
References s_prov_msg.
Referenced by run_wizard().
| void ui_set_tx_info | ( | const char * | info | ) |
Replace the transaction screen's info line without rebuilding it.
For progress on a state that lasts: the receipt poll can run for two minutes, and calling ui_show_tx_status per pass would restart the spinner the operator is reading as "still working". No-op unless the transaction screen is up in one of its spinner states.
| [in] | info | Line to show; copied internally, may be NULL to clear. |
Definition at line 910 of file ui.cpp.
References s_tx_info, and s_tx_info_dirty.
Referenced by settle_inflight(), and sign_and_broadcast().
| void ui_show_admin_set | ( | void | ) |
Run the first-run admin-code creation (enter, then confirm).
Deliberately has no way out: everything behind the burger menu — Wi-Fi, fees, factory reset — sits behind this code, so the terminal must not become usable without one. Emits UI_EVENT_ADMIN_SET once stored.
Definition at line 818 of file ui.cpp.
References request_screen(), s_admin_confirming, s_admin_first, s_admin_note, and UI_SCREEN_ADMIN_SET.
Referenced by pos_boot().
| void ui_show_amount_entry | ( | void | ) |
Switch to the amount-entry screen (forces a value redraw).
Definition at line 711 of file ui.cpp.
References request_screen(), s_amount_cents, s_amount_units, and UI_SCREEN_AMOUNT.
Referenced by app_main().
| void ui_show_boot_error | ( | ui_boot_err_t | kind, |
| const char * | detail ) |
Show a startup fault, naming the cause and what to do about it.
| [in] | kind | Which bring-up step failed. |
| [in] | detail | Optional technical detail for a technician (an esp_err_t name, say); copied internally, may be NULL. |
Definition at line 795 of file ui.cpp.
References request_screen(), s_boot_detail, s_boot_err, and UI_SCREEN_BOOT_ERROR.
Referenced by boot_fault().
| void ui_show_card_pin | ( | void | ) |
Ask for the card PIN before reading an address off a Cryptnox card.
The card will not export a public key without a verified PIN, so deriving a payout address needs one exactly as signing does. Emits UI_EVENT_CARD_PIN, or UI_EVENT_CONFIRM_CANCEL if the operator backs out.
Definition at line 873 of file ui.cpp.
References request_screen(), s_pin_for_card, s_prov_msg, and UI_SCREEN_PIN.
Referenced by app_main(), and run_wizard().
| void ui_show_card_wait | ( | const char * | note | ) |
"Hold your card to the reader" while the address is read.
Its own screen rather than the transaction one: nothing is being paid here, and the tx screen's wording and its Cancel semantics both belong to a sale.
| [in] | note | Optional line under the prompt, copied internally. |
Definition at line 886 of file ui.cpp.
References request_screen(), s_card_note, and UI_SCREEN_CARD_WAIT.
Referenced by card_connect().
| void ui_show_confirm | ( | uint64_t | amount_units, |
| const char * | dest_addr, | ||
| const char * | fee ) |
Switch to the confirm screen.
| [in] | amount_units | Amount in USDC base units (6 decimals). |
| [in] | dest_addr | "0x..."-prefixed destination address; copied internally, may be NULL for none. |
| [in] | fee | The network-fee ceiling as a line ("Fee up to 0.0013 ETH"), copied; NULL or "" for none. |
Definition at line 718 of file ui.cpp.
References request_screen(), s_confirm_addr, s_confirm_amount, s_confirm_fee, and UI_SCREEN_CONFIRM.
Referenced by app_main().
| void ui_show_ota_confirm | ( | void | ) |
Raise the modal that asks the operator to accept a firmware image the update page has uploaded, reading it from ota.h.
Call after UI_EVENT_OTA_STAGED. Accepting reboots into the new firmware and does not return; declining discards the staging and leaves the running firmware alone. The panel is the only place either can happen — an upload on its own changes nothing about what boots.
Definition at line 893 of file ui.cpp.
References s_ota_modal_dirty.
Referenced by app_main().
| void ui_show_prov | ( | int | step | ) |
Show the setup screen: QR code, AP name and passphrase.
The same screen at every wizard step, captioned with whichever one is current. There is deliberately no "use this screen instead" escape any more: the whole wizard past the admin code happens in the browser, so the panel's job here is to carry the QR code and to report progress.
| [in] | step | The prov_step_t the portal is serving. Typed as int to keep this header free of provision.h, which includes this one. |
Definition at line 850 of file ui.cpp.
References request_screen(), s_prov_step, and UI_SCREEN_PROV.
Referenced by run_wizard().
| void ui_show_prov_auth | ( | void | ) |
Demand the admin code so a browser can be authorised.
Same screen as the settings unlock, but a correct code calls prov_auth_resolve(true) instead of opening the menu, and backing out refuses the request rather than silently leaving the browser waiting.
Definition at line 861 of file ui.cpp.
References admin_penalty_ms(), request_screen(), s_admin_confirming, s_admin_for_portal, s_admin_lock_ms, s_admin_lock_start, s_admin_note, settings_admin_fail_count(), and UI_SCREEN_ADMIN_UNLOCK.
Referenced by app_main(), and run_wizard().
| void ui_show_prov_confirm | ( | void | ) |
Raise the modal that asks the operator to accept a value a browser proposed, reading the pending proposal from provision.h.
Call after UI_EVENT_PROV_VALUE. Accepting emits UI_EVENT_PROV_VALUE_SET; rejecting emits nothing and drops the proposal, so a caller waiting on the step stays where it is and can be offered another.
Definition at line 856 of file ui.cpp.
References s_addr_modal_dirty.
Referenced by app_main(), and run_wizard().
| void ui_show_splash | ( | void | ) |
Switch to the splash screen.
Definition at line 706 of file ui.cpp.
References request_screen(), and UI_SCREEN_SPLASH.
Referenced by pos_boot().
| void ui_show_tx_status | ( | ui_tx_state_t | state, |
| const char * | info ) |
Switch to the transaction-status screen.
| [in] | state | Transaction state to display. |
| [in] | info | Optional info line (tx hash, error message); copied internally, may be NULL for none. |
Definition at line 898 of file ui.cpp.
References request_screen(), s_tx_info, s_tx_state, and UI_SCREEN_TX_STATUS.
Referenced by app_main(), card_connect(), settle_inflight(), sign_and_broadcast(), and sign_and_broadcast_tron().
| void ui_show_welcome | ( | const char * | sub | ) |
Greet the operator at the start of first-run setup, or after an update.
Shown on a virgin or factory-reset terminal, before the Wi-Fi and admin-code steps, and again on the first boot of a freshly installed image. Emits UI_EVENT_WELCOME_DONE when Start is tapped.
| [in] | sub | Line under the product name, copied internally. NULL keeps the first-run wording ("Let's configure your terminal."). |
Definition at line 807 of file ui.cpp.
References request_screen(), s_welcome_sent, s_welcome_sub, and UI_SCREEN_WELCOME.
Referenced by pos_boot().
| void ui_show_wifi_connecting | ( | const char * | ssid | ) |
Show a "Connecting to <ssid>…" screen while main associates.
Interactive picker only; unattended boot reports through ui_set_boot_status and stays on the splash.
Definition at line 770 of file ui.cpp.
References request_screen(), set_wifi_progress(), and UI_SCREEN_WIFI_CONNECTING.
Referenced by app_main(), run_wizard(), and wifi_picker().
| void ui_show_wifi_list | ( | const net_wifi_ap_t * | aps, |
| uint16_t | n, | ||
| const char * | note ) |
Show the scanned Wi-Fi networks for the user to pick from.
| [in] | aps | Array of scanned APs (copied internally). |
| [in] | n | Number of entries in aps. |
| [in] | note | Optional one-line reason the picker (re)opened, shown above the list; copied internally, NULL for none. Applied on every call, so a stale note cannot survive a later render. |
Definition at line 747 of file ui.cpp.
References request_screen(), s_ap_count, s_aps, s_wifi_note, UI_SCREEN_WIFI_LIST, and WIFI_MAX_APS.
Referenced by app_main(), and wifi_picker().
| void ui_stage_wifi_creds | ( | const char * | ssid, |
| const char * | pass ) |
Load credentials into the same handoff buffers the picker fills.
Lets the setup page hand Wi-Fi credentials to main through the existing UI_EVENT_WIFI_TRY path, so a form submission and a screen tap reach the connect-and-verify loop identically. The caller emits the event afterwards.
| [in] | ssid | Network name. |
| [in] | pass | Passphrase; the caller wipes its own copy. |
Definition at line 842 of file ui.cpp.
References s_wifi_pass, and s_wifi_ssid.
Referenced by wifi_post().
| size_t ui_take_pin | ( | char * | out, |
| size_t | n ) |
Copy the most recently entered PIN out and wipe the UI's copy.
Call once after UI_EVENT_PIN_ENTERED. The internal buffer is secure-wiped on read, so a second call returns 0.
| [out] | out | Destination buffer (NUL-terminated on return). |
| [in] | n | Capacity of out. |
Definition at line 733 of file ui.cpp.
References s_pin, and s_pin_len.
Referenced by app_main(), and run_wizard().
| size_t ui_take_wifi_creds | ( | char * | ssid, |
| size_t | ssid_n, | ||
| char * | pass, | ||
| size_t | pass_n ) |
Fetch the selected SSID + entered password and wipe the UI's copy.
Call once after UI_EVENT_WIFI_TRY.
| [out] | ssid | SSID buffer (>= 33 bytes). |
| [in] | ssid_n | Capacity of ssid. |
| [out] | pass | Password buffer (>= 65 bytes). |
| [in] | pass_n | Capacity of pass. |
Definition at line 827 of file ui.cpp.
References s_wifi_pass, and s_wifi_ssid.
Referenced by app_main(), run_wizard(), and wifi_picker().