New LF-RFID app (#534)

* Hal lfrfid: add read timer pulse and period config fns
* New debug application for lfrfid subsystem
* New lfrfid: app, fix naming
* App lfrfid: assets
* Container view module
* App ibutton: remove unused header
* App lfrfid scenes
* App notification, add yield to blocking operations, add speaker volume control
* App lfrfid: reading key scene
* Assets: placeholder icon
* App lfrfid: reworked container view module
* App lfrfid: new scenes
* App lfrfid: write scene
* App lfrfid: write hid
* App lfrfid: emulate scene
* App lfrfid: save name scene
* App lfrfid: add missing file
This commit is contained in:
SG
2021-06-29 00:42:30 +10:00
committed by GitHub
parent 5d746234e9
commit 22e1ecb642
141 changed files with 2504 additions and 1666 deletions

View File

@@ -0,0 +1,36 @@
#include "lfrfid-app-scene-emulate.h"
void LfRfidAppSceneEmulate::on_enter(LfRfidApp* app, bool need_restore) {
string_init(data_string);
uint8_t* data = app->worker.key.get_data();
for(uint8_t i = 0; i < app->worker.key.get_type_data_count(); i++) {
string_cat_printf(data_string, "%02X", data[i]);
}
auto popup = app->view_controller.get<PopupVM>();
popup->set_header("Emulating", 90, 34, AlignCenter, AlignTop);
popup->set_text(string_get_cstr(data_string), 90, 48, AlignCenter, AlignTop);
popup->set_icon(0, 4, I_RFIDDolphinSend_98x60);
app->view_controller.switch_to<PopupVM>();
app->worker.start_emulate();
}
bool LfRfidAppSceneEmulate::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
bool consumed = false;
if(event->type == LfRfidApp::EventType::Tick) {
notification_message(app->notification, &sequence_blink_cyan_10);
}
return consumed;
}
void LfRfidAppSceneEmulate::on_exit(LfRfidApp* app) {
app->view_controller.get<PopupVM>()->clean();
app->worker.stop_emulate();
string_clear(data_string);
}

View File

@@ -0,0 +1,12 @@
#pragma once
#include "../lfrfid-app.h"
class LfRfidAppSceneEmulate : public GenericScene<LfRfidApp> {
public:
void on_enter(LfRfidApp* app, bool need_restore) final;
bool on_event(LfRfidApp* app, LfRfidApp::Event* event) final;
void on_exit(LfRfidApp* app) final;
private:
string_t data_string;
};

View File

@@ -0,0 +1,117 @@
#include "lfrfid-app-scene-read-success.h"
#include "../view/elements/button-element.h"
#include "../view/elements/icon-element.h"
#include "../view/elements/string-element.h"
void LfRfidAppSceneReadSuccess::on_enter(LfRfidApp* app, bool need_restore) {
string_init(string[0]);
string_init(string[1]);
string_init(string[2]);
auto container = app->view_controller.get<ContainerVM>();
auto button = container->add<ButtonElement>();
button->set_type(ButtonElement::Type::Left, "Retry");
button->set_callback(app, LfRfidAppSceneReadSuccess::back_callback);
button = container->add<ButtonElement>();
button->set_type(ButtonElement::Type::Right, "More");
button->set_callback(app, LfRfidAppSceneReadSuccess::more_callback);
auto icon = container->add<IconElement>();
icon->set_icon(3, 12, I_RFIDBigChip_37x36);
auto header = container->add<StringElement>();
header->set_text(app->worker.key.get_type_text(), 89, 3, AlignCenter);
auto line_1_text = container->add<StringElement>();
auto line_2_text = container->add<StringElement>();
auto line_3_text = container->add<StringElement>();
auto line_1_value = container->add<StringElement>();
auto line_2_value = container->add<StringElement>();
auto line_3_value = container->add<StringElement>();
uint8_t* data = app->worker.key.get_data();
switch(app->worker.key.get_type()) {
case LfrfidKeyType::KeyEM4100:
line_1_text->set_text("HEX:", 65, 23, AlignRight, AlignBottom, FontSecondary);
line_2_text->set_text("Mod:", 65, 35, AlignRight, AlignBottom, FontSecondary);
line_3_text->set_text("ID:", 65, 47, AlignRight, AlignBottom, FontSecondary);
for(uint8_t i = 0; i < app->worker.key.get_type_data_count(); i++) {
string_cat_printf(string[0], "%02X", data[i]);
}
string_printf(string[1], "Manchester");
string_printf(string[2], "%03u,%05u", data[2], (uint16_t)((data[3] << 8) | (data[4])));
line_1_value->set_text(
string_get_cstr(string[0]), 68, 23, AlignLeft, AlignBottom, FontSecondary);
line_2_value->set_text(
string_get_cstr(string[1]), 68, 35, AlignLeft, AlignBottom, FontSecondary);
line_3_value->set_text(
string_get_cstr(string[2]), 68, 47, AlignLeft, AlignBottom, FontSecondary);
break;
case LfrfidKeyType::KeyH10301:
line_1_text->set_text("HEX:", 65, 23, AlignRight, AlignBottom, FontSecondary);
line_2_text->set_text("FC:", 65, 35, AlignRight, AlignBottom, FontSecondary);
line_3_text->set_text("Card:", 65, 47, AlignRight, AlignBottom, FontSecondary);
for(uint8_t i = 0; i < app->worker.key.get_type_data_count(); i++) {
string_cat_printf(string[0], "%02X", data[i]);
}
string_printf(string[1], "%u", data[0]);
string_printf(string[2], "%u", (uint16_t)((data[1] << 8) | (data[2])));
line_1_value->set_text(
string_get_cstr(string[0]), 68, 23, AlignLeft, AlignBottom, FontSecondary);
line_2_value->set_text(
string_get_cstr(string[1]), 68, 35, AlignLeft, AlignBottom, FontSecondary);
line_3_value->set_text(
string_get_cstr(string[2]), 68, 47, AlignLeft, AlignBottom, FontSecondary);
break;
case LfrfidKeyType::KeyI40134:
//TODO implement when we can read Indala
break;
}
app->view_controller.switch_to<ContainerVM>();
notification_message_block(app->notification, &sequence_set_green_255);
}
bool LfRfidAppSceneReadSuccess::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
bool consumed = false;
if(event->type == LfRfidApp::EventType::Next) {
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::ReadedMenu);
consumed = true;
}
return consumed;
}
void LfRfidAppSceneReadSuccess::on_exit(LfRfidApp* app) {
notification_message_block(app->notification, &sequence_reset_green);
app->view_controller.get<ContainerVM>()->clean();
string_clear(string[0]);
string_clear(string[1]);
string_clear(string[2]);
}
void LfRfidAppSceneReadSuccess::back_callback(void* context) {
LfRfidApp* app = static_cast<LfRfidApp*>(context);
LfRfidApp::Event event;
event.type = LfRfidApp::EventType::Back;
app->view_controller.send_event(&event);
}
void LfRfidAppSceneReadSuccess::more_callback(void* context) {
LfRfidApp* app = static_cast<LfRfidApp*>(context);
LfRfidApp::Event event;
event.type = LfRfidApp::EventType::Next;
app->view_controller.send_event(&event);
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include "../lfrfid-app.h"
class LfRfidAppSceneReadSuccess : public GenericScene<LfRfidApp> {
public:
void on_enter(LfRfidApp* app, bool need_restore) final;
bool on_event(LfRfidApp* app, LfRfidApp::Event* event) final;
void on_exit(LfRfidApp* app) final;
private:
static void back_callback(void* context);
static void more_callback(void* context);
string_t string[3];
};

View File

@@ -0,0 +1,31 @@
#include "lfrfid-app-scene-read.h"
void LfRfidAppSceneRead::on_enter(LfRfidApp* app, bool need_restore) {
auto popup = app->view_controller.get<PopupVM>();
popup->set_header("Reading\nLF RFID", 70, 34, AlignLeft, AlignTop);
popup->set_icon(0, 4, I_RFIDDolphinReceive_98x60);
app->view_controller.switch_to<PopupVM>();
app->worker.start_read();
}
bool LfRfidAppSceneRead::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
bool consumed = false;
if(event->type == LfRfidApp::EventType::Tick) {
if(app->worker.read()) {
notification_message(app->notification, &sequence_success);
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::ReadSuccess);
} else {
notification_message(app->notification, &sequence_blink_red_10);
}
}
return consumed;
}
void LfRfidAppSceneRead::on_exit(LfRfidApp* app) {
app->view_controller.get<PopupVM>()->clean();
app->worker.stop_read();
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "../lfrfid-app.h"
class LfRfidAppSceneRead : public GenericScene<LfRfidApp> {
public:
void on_enter(LfRfidApp* app, bool need_restore) final;
bool on_event(LfRfidApp* app, LfRfidApp::Event* event) final;
void on_exit(LfRfidApp* app) final;
};

View File

@@ -0,0 +1,60 @@
#include "lfrfid-app-scene-readed-menu.h"
typedef enum {
SubmenuWrite,
SubmenuNameAndSave,
SubmenuEmulate,
} SubmenuIndex;
void LfRfidAppSceneReadedMenu::on_enter(LfRfidApp* app, bool need_restore) {
auto submenu = app->view_controller.get<SubmenuVM>();
submenu->add_item("Write", SubmenuWrite, submenu_callback, app);
submenu->add_item("Name and Save", SubmenuNameAndSave, submenu_callback, app);
submenu->add_item("Emulate", SubmenuEmulate, submenu_callback, app);
if(need_restore) {
submenu->set_selected_item(submenu_item_selected);
}
app->view_controller.switch_to<SubmenuVM>();
}
bool LfRfidAppSceneReadedMenu::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
bool consumed = false;
if(event->type == LfRfidApp::EventType::MenuSelected) {
submenu_item_selected = event->payload.menu_index;
switch(event->payload.menu_index) {
case SubmenuWrite:
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::Write);
break;
case SubmenuNameAndSave:
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::SaveName);
break;
case SubmenuEmulate:
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::Emulate);
break;
}
consumed = true;
} else if(event->type == LfRfidApp::EventType::Back) {
app->scene_controller.search_and_switch_to_previous_scene({LfRfidApp::SceneType::Start});
consumed = true;
}
return consumed;
}
void LfRfidAppSceneReadedMenu::on_exit(LfRfidApp* app) {
app->view_controller.get<SubmenuVM>()->clean();
}
void LfRfidAppSceneReadedMenu::submenu_callback(void* context, uint32_t index) {
LfRfidApp* app = static_cast<LfRfidApp*>(context);
LfRfidApp::Event event;
event.type = LfRfidApp::EventType::MenuSelected;
event.payload.menu_index = index;
app->view_controller.send_event(&event);
}

View File

@@ -0,0 +1,13 @@
#pragma once
#include "../lfrfid-app.h"
class LfRfidAppSceneReadedMenu : public GenericScene<LfRfidApp> {
public:
void on_enter(LfRfidApp* app, bool need_restore) final;
bool on_event(LfRfidApp* app, LfRfidApp::Event* event) final;
void on_exit(LfRfidApp* app) final;
private:
static void submenu_callback(void* context, uint32_t index);
uint32_t submenu_item_selected = 0;
};

View File

@@ -0,0 +1,48 @@
#include "lfrfid-app-scene-save-name.h"
#include "../helpers/rfid-name-generator.h"
void LfRfidAppSceneSaveName::on_enter(LfRfidApp* app, bool need_restore) {
const char* key_name = app->worker.key.get_name();
if(strcmp(key_name, "") == 0) {
rfid_generate_random_name(app->text_store.text, app->text_store.text_size);
} else {
app->text_store.set("%s", key_name);
}
auto text_input = app->view_controller.get<TextInputVM>();
text_input->set_header_text("Name the card");
text_input->set_result_callback(
save_callback, app, app->text_store.text, LFRFID_KEY_NAME_SIZE);
app->view_controller.switch_to<TextInputVM>();
}
bool LfRfidAppSceneSaveName::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
bool consumed = false;
if(event->type == LfRfidApp::EventType::Next) {
/*if(app->save_key(app->get_text_store())) {
app->switch_to_next_scene(iButtonApp::Scene::SceneSaveSuccess);
} else {
app->search_and_switch_to_previous_scene(
{iButtonApp::Scene::SceneReadedKeyMenu,
iButtonApp::Scene::SceneSavedKeyMenu,
iButtonApp::Scene::SceneAddType});
}*/
}
return consumed;
}
void LfRfidAppSceneSaveName::on_exit(LfRfidApp* app) {
app->view_controller.get<TextInputVM>()->clean();
}
void LfRfidAppSceneSaveName::save_callback(void* context) {
LfRfidApp* app = static_cast<LfRfidApp*>(context);
LfRfidApp::Event event;
event.type = LfRfidApp::EventType::Next;
app->view_controller.send_event(&event);
}

View File

@@ -0,0 +1,12 @@
#pragma once
#include "../lfrfid-app.h"
class LfRfidAppSceneSaveName : public GenericScene<LfRfidApp> {
public:
void on_enter(LfRfidApp* app, bool need_restore) final;
bool on_event(LfRfidApp* app, LfRfidApp::Event* event) final;
void on_exit(LfRfidApp* app) final;
private:
static void save_callback(void* context);
};

View File

@@ -0,0 +1,54 @@
#include "lfrfid-app-scene-start.h"
typedef enum {
SubmenuRead,
SubmenuSaved,
SubmenuAddManually,
} SubmenuIndex;
void LfRfidAppSceneStart::on_enter(LfRfidApp* app, bool need_restore) {
auto submenu = app->view_controller.get<SubmenuVM>();
submenu->add_item("Read", SubmenuRead, submenu_callback, app);
submenu->add_item("Saved", SubmenuSaved, submenu_callback, app);
submenu->add_item("Add manually", SubmenuAddManually, submenu_callback, app);
if(need_restore) {
submenu->set_selected_item(submenu_item_selected);
}
app->view_controller.switch_to<SubmenuVM>();
}
bool LfRfidAppSceneStart::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
bool consumed = false;
if(event->type == LfRfidApp::EventType::MenuSelected) {
submenu_item_selected = event->payload.menu_index;
switch(event->payload.menu_index) {
case SubmenuRead:
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::Read);
break;
case SubmenuSaved:
break;
case SubmenuAddManually:
break;
}
consumed = true;
}
return consumed;
}
void LfRfidAppSceneStart::on_exit(LfRfidApp* app) {
app->view_controller.get<SubmenuVM>()->clean();
}
void LfRfidAppSceneStart::submenu_callback(void* context, uint32_t index) {
LfRfidApp* app = static_cast<LfRfidApp*>(context);
LfRfidApp::Event event;
event.type = LfRfidApp::EventType::MenuSelected;
event.payload.menu_index = index;
app->view_controller.send_event(&event);
}

View File

@@ -0,0 +1,13 @@
#pragma once
#include "../lfrfid-app.h"
class LfRfidAppSceneStart : public GenericScene<LfRfidApp> {
public:
void on_enter(LfRfidApp* app, bool need_restore) final;
bool on_event(LfRfidApp* app, LfRfidApp::Event* event) final;
void on_exit(LfRfidApp* app) final;
private:
static void submenu_callback(void* context, uint32_t index);
uint32_t submenu_item_selected = 0;
};

View File

@@ -0,0 +1,38 @@
#include "lfrfid-app-scene-write-success.h"
void LfRfidAppSceneWriteSuccess::on_enter(LfRfidApp* app, bool need_restore) {
auto popup = app->view_controller.get<PopupVM>();
popup->set_header("Successfully\nwritten!", 94, 3, AlignCenter, AlignTop);
popup->set_icon(0, 6, I_RFIDDolphinSuccess_108x57);
popup->set_context(app);
popup->set_callback(LfRfidAppSceneWriteSuccess::timeout_callback);
popup->set_timeout(1500);
popup->enable_timeout();
app->view_controller.switch_to<PopupVM>();
notification_message_block(app->notification, &sequence_set_green_255);
}
bool LfRfidAppSceneWriteSuccess::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
bool consumed = false;
if(event->type == LfRfidApp::EventType::Back) {
app->scene_controller.search_and_switch_to_previous_scene(
{LfRfidApp::SceneType::ReadedMenu});
consumed = true;
}
return consumed;
}
void LfRfidAppSceneWriteSuccess::on_exit(LfRfidApp* app) {
notification_message_block(app->notification, &sequence_reset_green);
app->view_controller.get<PopupVM>()->clean();
}
void LfRfidAppSceneWriteSuccess::timeout_callback(void* context) {
LfRfidApp* app = static_cast<LfRfidApp*>(context);
LfRfidApp::Event event;
event.type = LfRfidApp::EventType::Back;
app->view_controller.send_event(&event);
}

View File

@@ -0,0 +1,12 @@
#pragma once
#include "../lfrfid-app.h"
class LfRfidAppSceneWriteSuccess : public GenericScene<LfRfidApp> {
public:
void on_enter(LfRfidApp* app, bool need_restore) final;
bool on_event(LfRfidApp* app, LfRfidApp::Event* event) final;
void on_exit(LfRfidApp* app) final;
private:
static void timeout_callback(void* context);
};

View File

@@ -0,0 +1,62 @@
#include "lfrfid-app-scene-write.h"
void LfRfidAppSceneWrite::on_enter(LfRfidApp* app, bool need_restore) {
card_not_supported = false;
string_init(data_string);
uint8_t* data = app->worker.key.get_data();
for(uint8_t i = 0; i < app->worker.key.get_type_data_count(); i++) {
string_cat_printf(data_string, "%02X", data[i]);
}
auto popup = app->view_controller.get<PopupVM>();
popup->set_header("Writing", 90, 34, AlignCenter, AlignTop);
popup->set_text(string_get_cstr(data_string), 90, 48, AlignCenter, AlignTop);
popup->set_icon(0, 4, I_RFIDDolphinSend_98x60);
app->view_controller.switch_to<PopupVM>();
app->worker.start_write();
}
bool LfRfidAppSceneWrite::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
bool consumed = false;
if(event->type == LfRfidApp::EventType::Tick) {
RfidWorker::WriteResult result = app->worker.write();
switch(result) {
case RfidWorker::WriteResult::Nothing:
notification_message(app->notification, &sequence_blink_yellow_10);
break;
case RfidWorker::WriteResult::Ok:
notification_message(app->notification, &sequence_success);
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::WriteSuccess);
break;
case RfidWorker::WriteResult::NotWritable:
if(!card_not_supported) {
auto popup = app->view_controller.get<PopupVM>();
popup->set_icon(0, 0, I_Empty_1x1);
popup->set_header("Still trying to write", 64, 7, AlignCenter, AlignTop);
popup->set_text(
"This card may be protected\nor does not support this\ntype of writing",
64,
23,
AlignCenter,
AlignTop);
card_not_supported = true;
}
notification_message(app->notification, &sequence_blink_red_10);
break;
}
}
return consumed;
}
void LfRfidAppSceneWrite::on_exit(LfRfidApp* app) {
app->view_controller.get<PopupVM>()->clean();
app->worker.stop_write();
string_clear(data_string);
}

View File

@@ -0,0 +1,13 @@
#pragma once
#include "../lfrfid-app.h"
class LfRfidAppSceneWrite : public GenericScene<LfRfidApp> {
public:
void on_enter(LfRfidApp* app, bool need_restore) final;
bool on_event(LfRfidApp* app, LfRfidApp::Event* event) final;
void on_exit(LfRfidApp* app) final;
private:
string_t data_string;
bool card_not_supported;
};