add qr scanning indicator

This commit is contained in:
Michele Balistreri 2024-02-21 18:43:45 +01:00
parent 2e24a892f9
commit 9932b1ee42
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
4 changed files with 26 additions and 4 deletions

View File

@ -14,6 +14,8 @@ typedef enum {
ERR_FULL,
ERR_VERSION,
ERR_MISMATCH,
ERR_DECODE,
ERR_SCAN,
} app_err_t;
#endif

View File

@ -22,7 +22,7 @@ APP_DEF_TASK(ui, UI_STACK_SIZE);
#define FW_MAJOR 0
#define FW_MINOR 6
#define FW_PATCH 2
#define FW_PATCH 3
__attribute__((section(".fw_signature"))) __attribute__((__used__)) const uint8_t FW_SIGNATURE[64];
__attribute__((section(".fw_version"))) __attribute__((__used__)) const uint8_t FW_VERSION[4] = { FW_MAJOR, FW_MINOR, FW_PATCH, 0};

View File

@ -11,18 +11,20 @@
#include "ur/eip4527_decode.h"
#include "ur/auth_decode.h"
const static screen_area_t indicator_area = { .x = 10, .y = 10, .width = 10, .height = 10 };
app_err_t qrscan_decode(struct quirc *qrctx, ur_t* ur) {
struct quirc_code qrcode;
struct quirc_data *qrdata = (struct quirc_data *)qrctx;
if (quirc_count(qrctx) != 1) {
return ERR_RETRY;
return ERR_SCAN;
}
quirc_extract(qrctx, 0, &qrcode);
quirc_decode_error_t err = quirc_decode(&qrcode, qrdata);
return !err ? ur_process_part(ur, qrdata->payload, qrdata->payload_len) : ERR_RETRY;
return !err ? ur_process_part(ur, qrdata->payload, qrdata->payload_len) : ERR_DECODE;
}
app_err_t qrscan_deserialize(ur_t* ur) {
@ -76,6 +78,9 @@ app_err_t qrscan_scan() {
uint8_t* fb;
while (1) {
uint16_t prev_detection = 0;
uint16_t detection = TH_COLOR_QR_NOT_FOUND;
if (camera_next_frame(&fb) != HAL_SUCCESS) {
continue;
}
@ -88,7 +93,10 @@ app_err_t qrscan_scan() {
quirc_end(&qrctx);
if (qrscan_decode(&qrctx, &ur) == ERR_OK) {
app_err_t qrerr = qrscan_decode(&qrctx, &ur);
if (qrerr == ERR_OK) {
detection = TH_COLOR_QR_OK;
hal_inactivity_timer_reset();
if (qrscan_deserialize(&ur) == ERR_OK) {
screen_wait();
@ -96,6 +104,10 @@ app_err_t qrscan_scan() {
} else {
ur.crc = 0;
}
} else if (qrerr == ERR_DECODE) {
detection = TH_COLOR_QR_NOT_DECODED;
} else if (qrerr != ERR_SCAN) {
detection = TH_COLOR_QR_OK;
}
screen_wait();
@ -105,6 +117,11 @@ app_err_t qrscan_scan() {
goto end;
}
if (detection != prev_detection) {
screen_fill_area(&indicator_area, detection);
prev_detection = detection;
}
keypad_key_t k = ui_wait_keypress(0);
if ((k == KEYPAD_KEY_CANCEL) || (k == KEYPAD_KEY_BACK)) {

View File

@ -10,6 +10,9 @@
#define TH_COLOR_FG SCREEN_COLOR_WHITE
#define TH_COLOR_QR_BG TH_COLOR_BG
#define TH_COLOR_QR_NOT_FOUND SCREEN_COLOR_RED
#define TH_COLOR_QR_NOT_DECODED SCREEN_COLOR_ORANGE
#define TH_COLOR_QR_OK SCREEN_COLOR_GREEN
#define TH_COLOR_MENU_BG TH_COLOR_BG
#define TH_COLOR_MENU_FG TH_COLOR_FG