add qr scanning indicator
This commit is contained in:
parent
2e24a892f9
commit
9932b1ee42
|
@ -14,6 +14,8 @@ typedef enum {
|
||||||
ERR_FULL,
|
ERR_FULL,
|
||||||
ERR_VERSION,
|
ERR_VERSION,
|
||||||
ERR_MISMATCH,
|
ERR_MISMATCH,
|
||||||
|
ERR_DECODE,
|
||||||
|
ERR_SCAN,
|
||||||
} app_err_t;
|
} app_err_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -22,7 +22,7 @@ APP_DEF_TASK(ui, UI_STACK_SIZE);
|
||||||
|
|
||||||
#define FW_MAJOR 0
|
#define FW_MAJOR 0
|
||||||
#define FW_MINOR 6
|
#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_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};
|
__attribute__((section(".fw_version"))) __attribute__((__used__)) const uint8_t FW_VERSION[4] = { FW_MAJOR, FW_MINOR, FW_PATCH, 0};
|
||||||
|
|
|
@ -11,18 +11,20 @@
|
||||||
#include "ur/eip4527_decode.h"
|
#include "ur/eip4527_decode.h"
|
||||||
#include "ur/auth_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) {
|
app_err_t qrscan_decode(struct quirc *qrctx, ur_t* ur) {
|
||||||
struct quirc_code qrcode;
|
struct quirc_code qrcode;
|
||||||
struct quirc_data *qrdata = (struct quirc_data *)qrctx;
|
struct quirc_data *qrdata = (struct quirc_data *)qrctx;
|
||||||
|
|
||||||
if (quirc_count(qrctx) != 1) {
|
if (quirc_count(qrctx) != 1) {
|
||||||
return ERR_RETRY;
|
return ERR_SCAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
quirc_extract(qrctx, 0, &qrcode);
|
quirc_extract(qrctx, 0, &qrcode);
|
||||||
quirc_decode_error_t err = quirc_decode(&qrcode, qrdata);
|
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) {
|
app_err_t qrscan_deserialize(ur_t* ur) {
|
||||||
|
@ -76,6 +78,9 @@ app_err_t qrscan_scan() {
|
||||||
uint8_t* fb;
|
uint8_t* fb;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
uint16_t prev_detection = 0;
|
||||||
|
uint16_t detection = TH_COLOR_QR_NOT_FOUND;
|
||||||
|
|
||||||
if (camera_next_frame(&fb) != HAL_SUCCESS) {
|
if (camera_next_frame(&fb) != HAL_SUCCESS) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +93,10 @@ app_err_t qrscan_scan() {
|
||||||
|
|
||||||
quirc_end(&qrctx);
|
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();
|
hal_inactivity_timer_reset();
|
||||||
if (qrscan_deserialize(&ur) == ERR_OK) {
|
if (qrscan_deserialize(&ur) == ERR_OK) {
|
||||||
screen_wait();
|
screen_wait();
|
||||||
|
@ -96,6 +104,10 @@ app_err_t qrscan_scan() {
|
||||||
} else {
|
} else {
|
||||||
ur.crc = 0;
|
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();
|
screen_wait();
|
||||||
|
@ -105,6 +117,11 @@ app_err_t qrscan_scan() {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (detection != prev_detection) {
|
||||||
|
screen_fill_area(&indicator_area, detection);
|
||||||
|
prev_detection = detection;
|
||||||
|
}
|
||||||
|
|
||||||
keypad_key_t k = ui_wait_keypress(0);
|
keypad_key_t k = ui_wait_keypress(0);
|
||||||
|
|
||||||
if ((k == KEYPAD_KEY_CANCEL) || (k == KEYPAD_KEY_BACK)) {
|
if ((k == KEYPAD_KEY_CANCEL) || (k == KEYPAD_KEY_BACK)) {
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
#define TH_COLOR_FG SCREEN_COLOR_WHITE
|
#define TH_COLOR_FG SCREEN_COLOR_WHITE
|
||||||
|
|
||||||
#define TH_COLOR_QR_BG TH_COLOR_BG
|
#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_BG TH_COLOR_BG
|
||||||
#define TH_COLOR_MENU_FG TH_COLOR_FG
|
#define TH_COLOR_MENU_FG TH_COLOR_FG
|
||||||
|
|
Loading…
Reference in New Issue