Skip to content

Commit

Permalink
picopass: apply card to back view (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
bettse authored Feb 6, 2024
1 parent 9a26cf8 commit d6f32ef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions scenes/picopass_scene_elite_dict_attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down
19 changes: 15 additions & 4 deletions views/dict_attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <gui/elements.h>

typedef enum {
DictAttackStateStart,
DictAttackStateRead,
DictAttackStateCardRemoved,
} DictAttackState;
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions views/dict_attack.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdint.h>
#include <gui/view.h>
#include <gui/modules/widget.h>
#include <picopass_icons.h>

typedef struct DictAttack DictAttack;

Expand Down

0 comments on commit d6f32ef

Please sign in to comment.