mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-24 19:53:08 +00:00
a7ab4b9c32
* Added new image DolphinSaved_113x58.png for all "saved" pages * New image DolphinDone_80x58.png added * Replaced dolphins on all scenes accroding to new UI specs * New success dolphin image added * Success scene image replaced * Changed image and text for update initial scene * Image and text adjusted for "Original restored" scene * Removed old DolphinNice_96x59.png image * New image for LFRFID scene * Removed unused image * New UI image added to assets * Replaced warning dolphin on mf_classic write initial fail scene * Removed old image * Changed image on scenes to a new one * New dolphin mafia image * Replaced dolphin mafia image to a new one * Removed DolphinMafia_115x62.png * New check symbol on completed state for detect_reader * Adjusted layout elements position * Removed second switching to popup view in order to achieve control in support callbacks In general now we show generic scene and after that in on_enter callback we can redefine it for particular protocol * CardDetected event now also triggers on_event callback * Now on AuthRequest we throw CardDetected custom event * Added callback for read_on_event * Now we show different screen while reading and unlocking * Fixed missing asstes for some scenes * Update DolphinMafia_119x62.png * Adjusted all the scenes with DolphinMafia image * Scenes with save image adjusted * Removed unnecessary assets DolphinMafia_119x62.png and DolphinSaved_113x58.png * All common dolphins moved to Dolphin folder * Moved DolphinReadingSuccess_59x63.png to Dolphin folder * Set proper led color for detect and read scenes * Added new notification sequence for semi_success results * Use new sequence for semi_success nfc reads * Different events are now throwed depending on read result * Added handling of incomplete event for ultralight cards * Replaced image for iButton scene * Updated API for f18 * Fixed issue with unlock retry sequence * Fix after review * Success notification replaced to semi success in case of incomplete mf classic reading * New text for read scene * New read result sound notification logic for mf classic cards * Change MIFARE name accroding to new requirements * New QR code image for MFKey app * Update nfc_scene_mf_classic_mfkey_complete.c scene according to new UI requirements * Update detect_reader.c and check_big_20x17.png * New nfc save confirm scene added * Implemented new flow for 'Detect Reader button' after partial mf classic read according to new UI * UID for 15693 tags now shown on the new line * Fix nfc unit tests * Revert "Fix nfc unit tests" This reverts commit685ed6bfad
. * Rolled back all Mifare renamings in library files * Revert "Change MIFARE name accroding to new requirements" This reverts commitcfb974dc1f
. * Now Mifare word is changed only on the app level without changes to lib level Co-authored-by: あく <alleteam@gmail.com> Co-authored-by: gornekich <n.gorbadey@gmail.com>
194 lines
6.1 KiB
C
194 lines
6.1 KiB
C
#include "detect_reader.h"
|
|
#include <assets_icons.h>
|
|
#include <gui/elements.h>
|
|
|
|
#define DETECT_READER_UID_MAX_LEN (10)
|
|
|
|
struct DetectReader {
|
|
View* view;
|
|
DetectReaderDoneCallback callback;
|
|
void* context;
|
|
};
|
|
|
|
typedef struct {
|
|
uint16_t nonces;
|
|
uint16_t nonces_max;
|
|
DetectReaderState state;
|
|
FuriString* uid_str;
|
|
} DetectReaderViewModel;
|
|
|
|
static void detect_reader_draw_callback(Canvas* canvas, void* model) {
|
|
DetectReaderViewModel* m = model;
|
|
char text[32] = {};
|
|
|
|
// Draw header and icon
|
|
canvas_draw_icon(canvas, 0, 16, &I_Modern_reader_18x34);
|
|
if(m->state == DetectReaderStateStart) {
|
|
snprintf(text, sizeof(text), "Touch the reader");
|
|
canvas_draw_icon(canvas, 21, 13, &I_Move_flipper_26x39);
|
|
if(furi_string_size(m->uid_str)) {
|
|
elements_multiline_text_aligned(
|
|
canvas, 64, 64, AlignCenter, AlignBottom, furi_string_get_cstr(m->uid_str));
|
|
}
|
|
} else if(m->state == DetectReaderStateReaderDetected) {
|
|
snprintf(text, sizeof(text), "Move the Flipper away");
|
|
canvas_draw_icon(canvas, 24, 25, &I_Release_arrow_18x15);
|
|
} else if(m->state == DetectReaderStateReaderLost) {
|
|
snprintf(text, sizeof(text), "Touch the reader again");
|
|
canvas_draw_icon(canvas, 21, 13, &I_Move_flipper_26x39);
|
|
}
|
|
|
|
canvas_draw_str_aligned(canvas, 64, 0, AlignCenter, AlignTop, text);
|
|
|
|
// Draw collected nonces
|
|
if(m->state == DetectReaderStateStart) {
|
|
canvas_set_font(canvas, FontPrimary);
|
|
canvas_draw_str_aligned(canvas, 51, 22, AlignLeft, AlignTop, "Emulating...");
|
|
canvas_set_font(canvas, FontSecondary);
|
|
canvas_draw_str_aligned(canvas, 51, 35, AlignLeft, AlignTop, "MIFARE MFkey32");
|
|
} else {
|
|
if(m->state == DetectReaderStateDone) {
|
|
canvas_set_font(canvas, FontPrimary);
|
|
canvas_draw_str_aligned(canvas, 51, 22, AlignLeft, AlignTop, "Completed!");
|
|
canvas_draw_icon(canvas, 24, 23, &I_check_big_20x17);
|
|
} else {
|
|
canvas_set_font(canvas, FontPrimary);
|
|
canvas_draw_str_aligned(canvas, 51, 22, AlignLeft, AlignTop, "Collecting...");
|
|
}
|
|
canvas_set_font(canvas, FontSecondary);
|
|
snprintf(text, sizeof(text), "Nonce pairs: %d/%d", m->nonces, m->nonces_max);
|
|
canvas_draw_str_aligned(canvas, 51, 35, AlignLeft, AlignTop, text);
|
|
}
|
|
// Draw button
|
|
if(m->nonces > 0) {
|
|
elements_button_center(canvas, "Done");
|
|
}
|
|
}
|
|
|
|
static bool detect_reader_input_callback(InputEvent* event, void* context) {
|
|
DetectReader* detect_reader = context;
|
|
furi_assert(detect_reader->callback);
|
|
bool consumed = false;
|
|
|
|
uint8_t nonces = 0;
|
|
with_view_model(
|
|
detect_reader->view, DetectReaderViewModel * model, { nonces = model->nonces; }, false);
|
|
|
|
if(event->type == InputTypeShort) {
|
|
if(event->key == InputKeyOk) {
|
|
if(nonces > 0) {
|
|
detect_reader->callback(detect_reader->context);
|
|
consumed = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return consumed;
|
|
}
|
|
|
|
DetectReader* detect_reader_alloc() {
|
|
DetectReader* detect_reader = malloc(sizeof(DetectReader));
|
|
detect_reader->view = view_alloc();
|
|
view_allocate_model(detect_reader->view, ViewModelTypeLocking, sizeof(DetectReaderViewModel));
|
|
view_set_draw_callback(detect_reader->view, detect_reader_draw_callback);
|
|
view_set_input_callback(detect_reader->view, detect_reader_input_callback);
|
|
view_set_context(detect_reader->view, detect_reader);
|
|
|
|
with_view_model(
|
|
detect_reader->view,
|
|
DetectReaderViewModel * model,
|
|
{ model->uid_str = furi_string_alloc(); },
|
|
false);
|
|
|
|
return detect_reader;
|
|
}
|
|
|
|
void detect_reader_free(DetectReader* detect_reader) {
|
|
furi_assert(detect_reader);
|
|
|
|
with_view_model(
|
|
detect_reader->view,
|
|
DetectReaderViewModel * model,
|
|
{ furi_string_free(model->uid_str); },
|
|
false);
|
|
|
|
view_free(detect_reader->view);
|
|
free(detect_reader);
|
|
}
|
|
|
|
void detect_reader_reset(DetectReader* detect_reader) {
|
|
furi_assert(detect_reader);
|
|
|
|
with_view_model(
|
|
detect_reader->view,
|
|
DetectReaderViewModel * model,
|
|
{
|
|
model->nonces = 0;
|
|
model->nonces_max = 0;
|
|
model->state = DetectReaderStateStart;
|
|
furi_string_reset(model->uid_str);
|
|
},
|
|
false);
|
|
}
|
|
|
|
View* detect_reader_get_view(DetectReader* detect_reader) {
|
|
furi_assert(detect_reader);
|
|
|
|
return detect_reader->view;
|
|
}
|
|
|
|
void detect_reader_set_callback(
|
|
DetectReader* detect_reader,
|
|
DetectReaderDoneCallback callback,
|
|
void* context) {
|
|
furi_assert(detect_reader);
|
|
furi_assert(callback);
|
|
|
|
detect_reader->callback = callback;
|
|
detect_reader->context = context;
|
|
}
|
|
|
|
void detect_reader_set_nonces_max(DetectReader* detect_reader, uint16_t nonces_max) {
|
|
furi_assert(detect_reader);
|
|
|
|
with_view_model(
|
|
detect_reader->view,
|
|
DetectReaderViewModel * model,
|
|
{ model->nonces_max = nonces_max; },
|
|
false);
|
|
}
|
|
|
|
void detect_reader_set_nonces_collected(DetectReader* detect_reader, uint16_t nonces_collected) {
|
|
furi_assert(detect_reader);
|
|
|
|
with_view_model(
|
|
detect_reader->view,
|
|
DetectReaderViewModel * model,
|
|
{
|
|
model->nonces = nonces_collected;
|
|
model->state = DetectReaderStateReaderDetected;
|
|
},
|
|
false);
|
|
}
|
|
|
|
void detect_reader_set_state(DetectReader* detect_reader, DetectReaderState state) {
|
|
furi_assert(detect_reader);
|
|
with_view_model(
|
|
detect_reader->view, DetectReaderViewModel * model, { model->state = state; }, true);
|
|
}
|
|
|
|
void detect_reader_set_uid(DetectReader* detect_reader, uint8_t* uid, uint8_t uid_len) {
|
|
furi_assert(detect_reader);
|
|
furi_assert(uid);
|
|
furi_assert(uid_len < DETECT_READER_UID_MAX_LEN);
|
|
with_view_model(
|
|
detect_reader->view,
|
|
DetectReaderViewModel * model,
|
|
{
|
|
furi_string_set_str(model->uid_str, "UID:");
|
|
for(size_t i = 0; i < uid_len; i++) {
|
|
furi_string_cat_printf(model->uid_str, " %02X", uid[i]);
|
|
}
|
|
},
|
|
true);
|
|
}
|