From d6f32ef64fcb048f08a03207034da6231f450d0d Mon Sep 17 00:00:00 2001 From: Eric Betts Date: Tue, 6 Feb 2024 14:14:17 -0800 Subject: [PATCH] picopass: apply card to back view (#118) --- scenes/picopass_scene_elite_dict_attack.c | 4 ++-- views/dict_attack.c | 19 +++++++++++++++---- views/dict_attack.h | 1 + 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/scenes/picopass_scene_elite_dict_attack.c b/scenes/picopass_scene_elite_dict_attack.c index 86ad89ab9c0..527c501e40b 100644 --- a/scenes/picopass_scene_elite_dict_attack.c +++ b/scenes/picopass_scene_elite_dict_attack.c @@ -40,7 +40,6 @@ static bool picopass_elite_dict_attack_change_dict(Picopass* picopass) { PICOPASS_KEY_LEN); scene_state = PicopassSceneEliteDictAttackDictElite; } - picopass->dict_attack_ctx.card_detected = true; picopass->dict_attack_ctx.total_keys = keys_dict_get_total_keys(picopass->dict); picopass->dict_attack_ctx.current_key = 0; picopass->dict_attack_ctx.name = picopass_dict_name[scene_state]; @@ -153,7 +152,8 @@ void picopass_scene_elite_dict_attack_on_enter(void* context) { PICOPASS_KEY_LEN); state = PicopassSceneEliteDictAttackDictStandard; } - picopass->dict_attack_ctx.card_detected = true; + dict_attack_reset(picopass->dict_attack); + picopass->dict_attack_ctx.card_detected = false; picopass->dict_attack_ctx.total_keys = keys_dict_get_total_keys(picopass->dict); picopass->dict_attack_ctx.current_key = 0; picopass->dict_attack_ctx.name = picopass_dict_name[state]; diff --git a/views/dict_attack.c b/views/dict_attack.c index ae187389e9e..4684d1b3c8b 100644 --- a/views/dict_attack.c +++ b/views/dict_attack.c @@ -3,6 +3,7 @@ #include typedef enum { + DictAttackStateStart, DictAttackStateRead, DictAttackStateCardRemoved, } DictAttackState; @@ -29,7 +30,12 @@ typedef struct { static void dict_attack_draw_callback(Canvas* canvas, void* model) { DictAttackViewModel* m = model; - if(m->state == DictAttackStateCardRemoved) { + if(m->state == DictAttackStateStart) { + canvas_draw_icon(canvas, 0, 8, &I_RFIDDolphinReceive_97x61); + canvas_set_font(canvas, FontPrimary); + elements_multiline_text_aligned( + canvas, 128, 40, AlignRight, AlignCenter, "Apply card to\nthe back"); + } else if(m->state == DictAttackStateCardRemoved) { canvas_set_font(canvas, FontPrimary); canvas_draw_str_aligned(canvas, 64, 4, AlignCenter, AlignTop, "Lost the tag!"); canvas_set_font(canvas, FontSecondary); @@ -78,8 +84,8 @@ static void dict_attack_draw_callback(Canvas* canvas, void* model) { m->sectors_read, m->sectors_total); canvas_draw_str_aligned(canvas, 0, 43, AlignLeft, AlignTop, draw_str); + elements_button_center(canvas, "Skip"); } - elements_button_center(canvas, "Skip"); } static bool dict_attack_input_callback(InputEvent* event, void* context) { @@ -126,7 +132,7 @@ void dict_attack_reset(DictAttack* dict_attack) { dict_attack->view, DictAttackViewModel * model, { - model->state = DictAttackStateRead; + model->state = DictAttackStateStart; model->sectors_total = 1; model->sectors_read = 0; model->sector_current = 0; @@ -181,7 +187,12 @@ void dict_attack_set_card_removed(DictAttack* dict_attack) { with_view_model( dict_attack->view, DictAttackViewModel * model, - { model->state = DictAttackStateCardRemoved; }, + { + // Only mark card as removed it if had been Read + if(model->state == DictAttackStateRead) { + model->state = DictAttackStateCardRemoved; + } + }, true); } diff --git a/views/dict_attack.h b/views/dict_attack.h index 5f9872da22a..998ac295e20 100644 --- a/views/dict_attack.h +++ b/views/dict_attack.h @@ -2,6 +2,7 @@ #include #include #include +#include typedef struct DictAttack DictAttack;