[FL-1371] New LF-RFID app. Second encounter. (#547)
* File worker: file operations helper. * Notification app: removed yield * File worker: write operations, calls to system file widgets * App ibutton: use file worker * Lfrfid: generic key loading, add path helper and hex conversion to lib * FileWorker: plain C verison * FileWorker: add to lib.mk * FileWorker: add to C sources, instead of CPP * Lfrfid: save scene * App lfrfid: add key scene, saved key menu * App lfrfid: saved key info scene * App lfrfid: delete key scene
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
#include "lfrfid-app-scene-delete-confirm.h"
|
||||
#include "../view/elements/button-element.h"
|
||||
#include "../view/elements/icon-element.h"
|
||||
#include "../view/elements/string-element.h"
|
||||
|
||||
void LfRfidAppSceneDeleteConfirm::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
string_init(string_data);
|
||||
string_init(string_decrypted);
|
||||
string_init(string_header);
|
||||
|
||||
auto container = app->view_controller.get<ContainerVM>();
|
||||
|
||||
auto button = container->add<ButtonElement>();
|
||||
button->set_type(ButtonElement::Type::Left, "Back");
|
||||
button->set_callback(app, LfRfidAppSceneDeleteConfirm::back_callback);
|
||||
|
||||
button = container->add<ButtonElement>();
|
||||
button->set_type(ButtonElement::Type::Right, "Delete");
|
||||
button->set_callback(app, LfRfidAppSceneDeleteConfirm::delete_callback);
|
||||
|
||||
auto line_1 = container->add<StringElement>();
|
||||
auto line_2 = container->add<StringElement>();
|
||||
auto line_3 = container->add<StringElement>();
|
||||
auto line_4 = container->add<StringElement>();
|
||||
|
||||
RfidKey& key = app->worker.key;
|
||||
const uint8_t* data = key.get_data();
|
||||
|
||||
for(uint8_t i = 0; i < key.get_type_data_count(); i++) {
|
||||
if(i != 0) {
|
||||
string_cat_printf(string_data, " ");
|
||||
}
|
||||
string_cat_printf(string_data, "%02X", data[i]);
|
||||
}
|
||||
|
||||
string_printf(string_header, "Delete %s?", key.get_name());
|
||||
line_1->set_text(
|
||||
string_get_cstr(string_header), 64, 19, AlignCenter, AlignBottom, FontPrimary);
|
||||
line_2->set_text(
|
||||
string_get_cstr(string_data), 64, 29, AlignCenter, AlignBottom, FontSecondary);
|
||||
|
||||
switch(key.get_type()) {
|
||||
case LfrfidKeyType::KeyEM4100:
|
||||
string_printf(
|
||||
string_decrypted, "%03u,%05u", data[2], (uint16_t)((data[3] << 8) | (data[4])));
|
||||
|
||||
break;
|
||||
case LfrfidKeyType::KeyH10301:
|
||||
case LfrfidKeyType::KeyI40134:
|
||||
string_printf(
|
||||
string_decrypted, "FC: %u ID: %u", data[0], (uint16_t)((data[1] << 8) | (data[2])));
|
||||
break;
|
||||
}
|
||||
line_3->set_text(
|
||||
string_get_cstr(string_decrypted), 64, 39, AlignCenter, AlignBottom, FontSecondary);
|
||||
|
||||
line_4->set_text(
|
||||
lfrfid_key_get_type_string(key.get_type()),
|
||||
64,
|
||||
49,
|
||||
AlignCenter,
|
||||
AlignBottom,
|
||||
FontSecondary);
|
||||
|
||||
app->view_controller.switch_to<ContainerVM>();
|
||||
}
|
||||
|
||||
bool LfRfidAppSceneDeleteConfirm::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == LfRfidApp::EventType::Next) {
|
||||
app->delete_key(&app->worker.key);
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::DeleteSuccess);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void LfRfidAppSceneDeleteConfirm::on_exit(LfRfidApp* app) {
|
||||
app->view_controller.get<ContainerVM>()->clean();
|
||||
string_clear(string_data);
|
||||
string_clear(string_decrypted);
|
||||
string_clear(string_header);
|
||||
}
|
||||
|
||||
void LfRfidAppSceneDeleteConfirm::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 LfRfidAppSceneDeleteConfirm::delete_callback(void* context) {
|
||||
LfRfidApp* app = static_cast<LfRfidApp*>(context);
|
||||
LfRfidApp::Event event;
|
||||
event.type = LfRfidApp::EventType::Next;
|
||||
app->view_controller.send_event(&event);
|
||||
}
|
||||
17
applications/lfrfid/scene/lfrfid-app-scene-delete-confirm.h
Normal file
17
applications/lfrfid/scene/lfrfid-app-scene-delete-confirm.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "../lfrfid-app.h"
|
||||
|
||||
class LfRfidAppSceneDeleteConfirm : 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 delete_callback(void* context);
|
||||
|
||||
string_t string_header;
|
||||
string_t string_data;
|
||||
string_t string_decrypted;
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "lfrfid-app-scene-delete-success.h"
|
||||
|
||||
void LfRfidAppSceneDeleteSuccess::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
auto popup = app->view_controller.get<PopupVM>();
|
||||
|
||||
popup->set_icon(0, 2, I_DolphinMafia_115x62);
|
||||
popup->set_text("Deleted", 83, 19, AlignLeft, AlignBottom);
|
||||
popup->set_context(app);
|
||||
popup->set_callback(LfRfidAppSceneDeleteSuccess::timeout_callback);
|
||||
popup->set_timeout(1500);
|
||||
popup->enable_timeout();
|
||||
|
||||
app->view_controller.switch_to<PopupVM>();
|
||||
}
|
||||
|
||||
bool LfRfidAppSceneDeleteSuccess::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::SelectKey});
|
||||
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void LfRfidAppSceneDeleteSuccess::on_exit(LfRfidApp* app) {
|
||||
app->view_controller.get<PopupVM>()->clean();
|
||||
}
|
||||
|
||||
void LfRfidAppSceneDeleteSuccess::timeout_callback(void* context) {
|
||||
LfRfidApp* app = static_cast<LfRfidApp*>(context);
|
||||
LfRfidApp::Event event;
|
||||
event.type = LfRfidApp::EventType::Back;
|
||||
app->view_controller.send_event(&event);
|
||||
}
|
||||
12
applications/lfrfid/scene/lfrfid-app-scene-delete-success.h
Normal file
12
applications/lfrfid/scene/lfrfid-app-scene-delete-success.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "../lfrfid-app.h"
|
||||
|
||||
class LfRfidAppSceneDeleteSuccess : 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);
|
||||
};
|
||||
@@ -3,7 +3,7 @@
|
||||
void LfRfidAppSceneEmulate::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
string_init(data_string);
|
||||
|
||||
uint8_t* data = app->worker.key.get_data();
|
||||
const 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]);
|
||||
@@ -11,8 +11,12 @@ void LfRfidAppSceneEmulate::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
|
||||
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_header("LF emulating", 89, 30, AlignCenter, AlignTop);
|
||||
if(strlen(app->worker.key.get_name())) {
|
||||
popup->set_text(app->worker.key.get_name(), 89, 43, AlignCenter, AlignTop);
|
||||
} else {
|
||||
popup->set_text(string_get_cstr(data_string), 89, 43, AlignCenter, AlignTop);
|
||||
}
|
||||
popup->set_icon(0, 4, I_RFIDDolphinSend_98x60);
|
||||
|
||||
app->view_controller.switch_to<PopupVM>();
|
||||
|
||||
@@ -32,7 +32,7 @@ void LfRfidAppSceneReadSuccess::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
auto line_2_value = container->add<StringElement>();
|
||||
auto line_3_value = container->add<StringElement>();
|
||||
|
||||
uint8_t* data = app->worker.key.get_data();
|
||||
const uint8_t* data = app->worker.key.get_data();
|
||||
|
||||
switch(app->worker.key.get_type()) {
|
||||
case LfrfidKeyType::KeyEM4100:
|
||||
|
||||
58
applications/lfrfid/scene/lfrfid-app-scene-save-data.cpp
Normal file
58
applications/lfrfid/scene/lfrfid-app-scene-save-data.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "lfrfid-app-scene-save-data.h"
|
||||
|
||||
static void print_buffer(const uint8_t* buffer) {
|
||||
for(uint8_t i = 0; i < LFRFID_KEY_SIZE; i++) {
|
||||
printf("%02X", buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void LfRfidAppSceneSaveData::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
auto byte_input = app->view_controller.get<ByteInputVM>();
|
||||
RfidKey& key = app->worker.key;
|
||||
|
||||
printf("k: ");
|
||||
print_buffer(key.get_data());
|
||||
printf(" o: ");
|
||||
print_buffer(old_key_data);
|
||||
printf(" n: ");
|
||||
print_buffer(new_key_data);
|
||||
printf("\r\n");
|
||||
if(need_restore) printf("restored\r\n");
|
||||
|
||||
if(need_restore) {
|
||||
key.set_data(old_key_data, key.get_type_data_count());
|
||||
} else {
|
||||
memcpy(old_key_data, key.get_data(), key.get_type_data_count());
|
||||
}
|
||||
|
||||
memcpy(new_key_data, key.get_data(), key.get_type_data_count());
|
||||
byte_input->set_header_text("Enter the data in hex");
|
||||
|
||||
byte_input->set_result_callback(
|
||||
save_callback, NULL, app, new_key_data, app->worker.key.get_type_data_count());
|
||||
|
||||
app->view_controller.switch_to<ByteInputVM>();
|
||||
}
|
||||
|
||||
bool LfRfidAppSceneSaveData::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
|
||||
bool consumed = false;
|
||||
RfidKey& key = app->worker.key;
|
||||
|
||||
if(event->type == LfRfidApp::EventType::Next) {
|
||||
key.set_data(new_key_data, key.get_type_data_count());
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::SaveName);
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void LfRfidAppSceneSaveData::on_exit(LfRfidApp* app) {
|
||||
app->view_controller.get<ByteInputVM>()->clean();
|
||||
}
|
||||
|
||||
void LfRfidAppSceneSaveData::save_callback(void* context, uint8_t* bytes, uint8_t bytes_count) {
|
||||
LfRfidApp* app = static_cast<LfRfidApp*>(context);
|
||||
LfRfidApp::Event event;
|
||||
event.type = LfRfidApp::EventType::Next;
|
||||
app->view_controller.send_event(&event);
|
||||
}
|
||||
33
applications/lfrfid/scene/lfrfid-app-scene-save-data.h
Normal file
33
applications/lfrfid/scene/lfrfid-app-scene-save-data.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
#include "../lfrfid-app.h"
|
||||
|
||||
class LfRfidAppSceneSaveData : 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, uint8_t* bytes, uint8_t bytes_count);
|
||||
uint8_t old_key_data[LFRFID_KEY_SIZE] = {
|
||||
0xAA,
|
||||
0xAA,
|
||||
0xAA,
|
||||
0xAA,
|
||||
0xAA,
|
||||
0xAA,
|
||||
0xAA,
|
||||
0xAA,
|
||||
};
|
||||
|
||||
uint8_t new_key_data[LFRFID_KEY_SIZE] = {
|
||||
0xBB,
|
||||
0xBB,
|
||||
0xBB,
|
||||
0xBB,
|
||||
0xBB,
|
||||
0xBB,
|
||||
0xBB,
|
||||
0xBB,
|
||||
};
|
||||
};
|
||||
@@ -14,7 +14,7 @@ void LfRfidAppSceneSaveName::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
text_input->set_header_text("Name the card");
|
||||
|
||||
text_input->set_result_callback(
|
||||
save_callback, app, app->text_store.text, LFRFID_KEY_NAME_SIZE);
|
||||
save_callback, app, app->text_store.text, app->worker.key.get_name_length());
|
||||
|
||||
app->view_controller.switch_to<TextInputVM>();
|
||||
}
|
||||
@@ -23,14 +23,18 @@ 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);
|
||||
if(strlen(app->worker.key.get_name())) {
|
||||
app->delete_key(&app->worker.key);
|
||||
}
|
||||
|
||||
app->worker.key.set_name(app->text_store.text);
|
||||
|
||||
if(app->save_key(&app->worker.key)) {
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::SaveSuccess);
|
||||
} else {
|
||||
app->search_and_switch_to_previous_scene(
|
||||
{iButtonApp::Scene::SceneReadedKeyMenu,
|
||||
iButtonApp::Scene::SceneSavedKeyMenu,
|
||||
iButtonApp::Scene::SceneAddType});
|
||||
}*/
|
||||
app->scene_controller.search_and_switch_to_previous_scene(
|
||||
{LfRfidApp::SceneType::ReadedMenu});
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
|
||||
46
applications/lfrfid/scene/lfrfid-app-scene-save-success.cpp
Normal file
46
applications/lfrfid/scene/lfrfid-app-scene-save-success.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "lfrfid-app-scene-save-success.h"
|
||||
|
||||
void LfRfidAppSceneSaveSuccess::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
auto popup = app->view_controller.get<PopupVM>();
|
||||
|
||||
popup->set_icon(32, 5, I_DolphinNice_96x59);
|
||||
popup->set_text("Saved!", 13, 22, AlignLeft, AlignBottom);
|
||||
popup->set_context(app);
|
||||
popup->set_callback(LfRfidAppSceneSaveSuccess::timeout_callback);
|
||||
popup->set_timeout(1500);
|
||||
popup->enable_timeout();
|
||||
|
||||
app->view_controller.switch_to<PopupVM>();
|
||||
}
|
||||
|
||||
bool LfRfidAppSceneSaveSuccess::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == LfRfidApp::EventType::Back) {
|
||||
bool result = app->scene_controller.has_previous_scene(
|
||||
{LfRfidApp::SceneType::ReadedMenu, LfRfidApp::SceneType::SelectKey});
|
||||
|
||||
if(result) {
|
||||
app->scene_controller.search_and_switch_to_previous_scene(
|
||||
{LfRfidApp::SceneType::ReadedMenu, LfRfidApp::SceneType::SelectKey});
|
||||
} else {
|
||||
app->scene_controller.search_and_switch_to_another_scene(
|
||||
{LfRfidApp::SceneType::SaveType}, LfRfidApp::SceneType::SelectKey);
|
||||
}
|
||||
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void LfRfidAppSceneSaveSuccess::on_exit(LfRfidApp* app) {
|
||||
app->view_controller.get<PopupVM>()->clean();
|
||||
}
|
||||
|
||||
void LfRfidAppSceneSaveSuccess::timeout_callback(void* context) {
|
||||
LfRfidApp* app = static_cast<LfRfidApp*>(context);
|
||||
LfRfidApp::Event event;
|
||||
event.type = LfRfidApp::EventType::Back;
|
||||
app->view_controller.send_event(&event);
|
||||
}
|
||||
12
applications/lfrfid/scene/lfrfid-app-scene-save-success.h
Normal file
12
applications/lfrfid/scene/lfrfid-app-scene-save-success.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "../lfrfid-app.h"
|
||||
|
||||
class LfRfidAppSceneSaveSuccess : 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);
|
||||
};
|
||||
46
applications/lfrfid/scene/lfrfid-app-scene-save-type.cpp
Normal file
46
applications/lfrfid/scene/lfrfid-app-scene-save-type.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "lfrfid-app-scene-save-type.h"
|
||||
|
||||
void LfRfidAppSceneSaveType::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
auto submenu = app->view_controller.get<SubmenuVM>();
|
||||
|
||||
for(uint8_t i = 0; i <= static_cast<uint8_t>(LfrfidKeyType::KeyI40134); i++) {
|
||||
submenu->add_item(
|
||||
lfrfid_key_get_type_string(static_cast<LfrfidKeyType>(i)), i, submenu_callback, app);
|
||||
}
|
||||
|
||||
if(need_restore) {
|
||||
submenu->set_selected_item(submenu_item_selected);
|
||||
}
|
||||
|
||||
app->view_controller.switch_to<SubmenuVM>();
|
||||
|
||||
// clear key name
|
||||
app->worker.key.set_name("");
|
||||
}
|
||||
|
||||
bool LfRfidAppSceneSaveType::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == LfRfidApp::EventType::MenuSelected) {
|
||||
submenu_item_selected = event->payload.menu_index;
|
||||
app->worker.key.set_type(static_cast<LfrfidKeyType>(event->payload.menu_index));
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::SaveData);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void LfRfidAppSceneSaveType::on_exit(LfRfidApp* app) {
|
||||
app->view_controller.get<SubmenuVM>()->clean();
|
||||
}
|
||||
|
||||
void LfRfidAppSceneSaveType::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);
|
||||
}
|
||||
13
applications/lfrfid/scene/lfrfid-app-scene-save-type.h
Normal file
13
applications/lfrfid/scene/lfrfid-app-scene-save-type.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "../lfrfid-app.h"
|
||||
|
||||
class LfRfidAppSceneSaveType : 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;
|
||||
};
|
||||
77
applications/lfrfid/scene/lfrfid-app-scene-saved-info.cpp
Normal file
77
applications/lfrfid/scene/lfrfid-app-scene-saved-info.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "lfrfid-app-scene-saved-info.h"
|
||||
#include "../view/elements/button-element.h"
|
||||
#include "../view/elements/icon-element.h"
|
||||
#include "../view/elements/string-element.h"
|
||||
|
||||
void LfRfidAppSceneSavedInfo::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
string_init(string_data);
|
||||
string_init(string_decrypted);
|
||||
|
||||
auto container = app->view_controller.get<ContainerVM>();
|
||||
|
||||
auto button = container->add<ButtonElement>();
|
||||
button->set_type(ButtonElement::Type::Left, "Back");
|
||||
button->set_callback(app, LfRfidAppSceneSavedInfo::back_callback);
|
||||
|
||||
auto line_1 = container->add<StringElement>();
|
||||
auto line_2 = container->add<StringElement>();
|
||||
auto line_3 = container->add<StringElement>();
|
||||
auto line_4 = container->add<StringElement>();
|
||||
|
||||
RfidKey& key = app->worker.key;
|
||||
const uint8_t* data = key.get_data();
|
||||
|
||||
for(uint8_t i = 0; i < key.get_type_data_count(); i++) {
|
||||
if(i != 0) {
|
||||
string_cat_printf(string_data, " ");
|
||||
}
|
||||
string_cat_printf(string_data, "%02X", data[i]);
|
||||
}
|
||||
|
||||
line_1->set_text(key.get_name(), 64, 17, AlignCenter, AlignBottom, FontSecondary);
|
||||
line_2->set_text(string_get_cstr(string_data), 64, 29, AlignCenter, AlignBottom, FontPrimary);
|
||||
|
||||
switch(key.get_type()) {
|
||||
case LfrfidKeyType::KeyEM4100:
|
||||
string_printf(
|
||||
string_decrypted, "%03u,%05u", data[2], (uint16_t)((data[3] << 8) | (data[4])));
|
||||
|
||||
break;
|
||||
case LfrfidKeyType::KeyH10301:
|
||||
case LfrfidKeyType::KeyI40134:
|
||||
string_printf(
|
||||
string_decrypted, "FC: %u ID: %u", data[0], (uint16_t)((data[1] << 8) | (data[2])));
|
||||
break;
|
||||
}
|
||||
line_3->set_text(
|
||||
string_get_cstr(string_decrypted), 64, 39, AlignCenter, AlignBottom, FontSecondary);
|
||||
|
||||
line_4->set_text(
|
||||
lfrfid_key_get_type_string(key.get_type()),
|
||||
64,
|
||||
49,
|
||||
AlignCenter,
|
||||
AlignBottom,
|
||||
FontSecondary);
|
||||
|
||||
app->view_controller.switch_to<ContainerVM>();
|
||||
}
|
||||
|
||||
bool LfRfidAppSceneSavedInfo::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
|
||||
bool consumed = false;
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void LfRfidAppSceneSavedInfo::on_exit(LfRfidApp* app) {
|
||||
app->view_controller.get<ContainerVM>()->clean();
|
||||
string_clear(string_data);
|
||||
string_clear(string_decrypted);
|
||||
}
|
||||
|
||||
void LfRfidAppSceneSavedInfo::back_callback(void* context) {
|
||||
LfRfidApp* app = static_cast<LfRfidApp*>(context);
|
||||
LfRfidApp::Event event;
|
||||
event.type = LfRfidApp::EventType::Back;
|
||||
app->view_controller.send_event(&event);
|
||||
}
|
||||
15
applications/lfrfid/scene/lfrfid-app-scene-saved-info.h
Normal file
15
applications/lfrfid/scene/lfrfid-app-scene-saved-info.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "../lfrfid-app.h"
|
||||
|
||||
class LfRfidAppSceneSavedInfo : 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);
|
||||
|
||||
string_t string_data;
|
||||
string_t string_decrypted;
|
||||
};
|
||||
@@ -0,0 +1,67 @@
|
||||
#include "lfrfid-app-scene-saved-key-menu.h"
|
||||
|
||||
typedef enum {
|
||||
SubmenuEmulate,
|
||||
SubmenuWrite,
|
||||
SubmenuEdit,
|
||||
SubmenuDelete,
|
||||
SubmenuInfo,
|
||||
} SubmenuIndex;
|
||||
|
||||
void LfRfidAppSceneSavedKeyMenu::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
auto submenu = app->view_controller.get<SubmenuVM>();
|
||||
|
||||
submenu->add_item("Emulate", SubmenuEmulate, submenu_callback, app);
|
||||
submenu->add_item("Write", SubmenuWrite, submenu_callback, app);
|
||||
submenu->add_item("Edit", SubmenuEdit, submenu_callback, app);
|
||||
submenu->add_item("Delete", SubmenuDelete, submenu_callback, app);
|
||||
submenu->add_item("Info", SubmenuInfo, submenu_callback, app);
|
||||
|
||||
if(need_restore) {
|
||||
submenu->set_selected_item(submenu_item_selected);
|
||||
}
|
||||
|
||||
app->view_controller.switch_to<SubmenuVM>();
|
||||
}
|
||||
|
||||
bool LfRfidAppSceneSavedKeyMenu::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 SubmenuEmulate:
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::Emulate);
|
||||
break;
|
||||
case SubmenuWrite:
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::Write);
|
||||
break;
|
||||
case SubmenuEdit:
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::SaveData);
|
||||
break;
|
||||
case SubmenuDelete:
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::DeleteConfirm);
|
||||
break;
|
||||
case SubmenuInfo:
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::SavedInfo);
|
||||
break;
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void LfRfidAppSceneSavedKeyMenu::on_exit(LfRfidApp* app) {
|
||||
app->view_controller.get<SubmenuVM>()->clean();
|
||||
}
|
||||
|
||||
void LfRfidAppSceneSavedKeyMenu::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);
|
||||
}
|
||||
13
applications/lfrfid/scene/lfrfid-app-scene-saved-key-menu.h
Normal file
13
applications/lfrfid/scene/lfrfid-app-scene-saved-key-menu.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "../lfrfid-app.h"
|
||||
|
||||
class LfRfidAppSceneSavedKeyMenu : 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;
|
||||
};
|
||||
18
applications/lfrfid/scene/lfrfid-app-scene-select-key.cpp
Normal file
18
applications/lfrfid/scene/lfrfid-app-scene-select-key.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "lfrfid-app-scene-select-key.h"
|
||||
|
||||
void LfRfidAppSceneSelectKey::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
if(app->load_key_from_file_select(need_restore)) {
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::SavedKeyMenu);
|
||||
} else {
|
||||
app->scene_controller.switch_to_previous_scene();
|
||||
}
|
||||
}
|
||||
|
||||
bool LfRfidAppSceneSelectKey::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
|
||||
bool consumed = false;
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void LfRfidAppSceneSelectKey::on_exit(LfRfidApp* app) {
|
||||
}
|
||||
9
applications/lfrfid/scene/lfrfid-app-scene-select-key.h
Normal file
9
applications/lfrfid/scene/lfrfid-app-scene-select-key.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include "../lfrfid-app.h"
|
||||
|
||||
class LfRfidAppSceneSelectKey : 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;
|
||||
};
|
||||
@@ -16,7 +16,11 @@ void LfRfidAppSceneStart::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
if(need_restore) {
|
||||
submenu->set_selected_item(submenu_item_selected);
|
||||
}
|
||||
|
||||
app->view_controller.switch_to<SubmenuVM>();
|
||||
|
||||
// clear key
|
||||
app->worker.key.clear();
|
||||
}
|
||||
|
||||
bool LfRfidAppSceneStart::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
|
||||
@@ -29,8 +33,10 @@ bool LfRfidAppSceneStart::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::Read);
|
||||
break;
|
||||
case SubmenuSaved:
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::SelectKey);
|
||||
break;
|
||||
case SubmenuAddManually:
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::SaveType);
|
||||
break;
|
||||
}
|
||||
consumed = true;
|
||||
|
||||
@@ -4,7 +4,7 @@ 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();
|
||||
const 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]);
|
||||
@@ -12,8 +12,12 @@ void LfRfidAppSceneWrite::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
|
||||
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_header("LF writing", 89, 30, AlignCenter, AlignTop);
|
||||
if(strlen(app->worker.key.get_name())) {
|
||||
popup->set_text(app->worker.key.get_name(), 89, 43, AlignCenter, AlignTop);
|
||||
} else {
|
||||
popup->set_text(string_get_cstr(data_string), 89, 43, AlignCenter, AlignTop);
|
||||
}
|
||||
popup->set_icon(0, 4, I_RFIDDolphinSend_98x60);
|
||||
|
||||
app->view_controller.switch_to<PopupVM>();
|
||||
|
||||
Reference in New Issue
Block a user