[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:
10
applications/ibutton/ibutton-app.cpp
Executable file → Normal file
10
applications/ibutton/ibutton-app.cpp
Executable file → Normal file
@@ -2,7 +2,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <callback-connector.h>
|
||||
#include <m-string.h>
|
||||
#include <file-worker.h>
|
||||
#include <file-worker-cpp.h>
|
||||
|
||||
const char* iButtonApp::app_folder = "ibutton";
|
||||
const char* iButtonApp::app_extension = ".ibtn";
|
||||
@@ -217,7 +217,7 @@ void iButtonApp::generate_random_name(char* name, uint8_t max_name_size) {
|
||||
|
||||
// file managment
|
||||
bool iButtonApp::save_key(const char* key_name) {
|
||||
FileWorker file_worker;
|
||||
FileWorkerCpp file_worker;
|
||||
string_t key_file_name;
|
||||
bool result = false;
|
||||
|
||||
@@ -274,7 +274,7 @@ bool iButtonApp::save_key(const char* key_name) {
|
||||
}
|
||||
|
||||
bool iButtonApp::load_key_data(string_t key_path) {
|
||||
FileWorker file_worker;
|
||||
FileWorkerCpp file_worker;
|
||||
|
||||
// Open key file
|
||||
if(!file_worker.open(string_get_cstr(key_path), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
@@ -344,7 +344,7 @@ bool iButtonApp::load_key(const char* key_name) {
|
||||
|
||||
bool iButtonApp::load_key() {
|
||||
bool result = false;
|
||||
FileWorker file_worker;
|
||||
FileWorkerCpp file_worker;
|
||||
|
||||
// Input events and views are managed by file_select
|
||||
bool res = file_worker.file_select(
|
||||
@@ -369,7 +369,7 @@ bool iButtonApp::load_key() {
|
||||
bool iButtonApp::delete_key() {
|
||||
string_t file_name;
|
||||
bool result = false;
|
||||
FileWorker file_worker;
|
||||
FileWorkerCpp file_worker;
|
||||
|
||||
string_init_printf(file_name, "%s/%s%s", app_folder, get_key()->get_name(), app_extension);
|
||||
result = file_worker.remove(string_get_cstr(file_name));
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include "key-info.h"
|
||||
#include <string.h>
|
||||
|
||||
const char* lfrfid_key_get_type_string(LfrfidKeyType type) {
|
||||
switch(type) {
|
||||
@@ -16,6 +17,22 @@ const char* lfrfid_key_get_type_string(LfrfidKeyType type) {
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
bool lfrfid_key_get_string_type(const char* string, LfrfidKeyType* type) {
|
||||
bool result = true;
|
||||
|
||||
if(strcmp("EM4100", string) == 0) {
|
||||
*type = LfrfidKeyType::KeyEM4100;
|
||||
} else if(strcmp("H10301", string) == 0) {
|
||||
*type = LfrfidKeyType::KeyH10301;
|
||||
} else if(strcmp("I40134", string) == 0) {
|
||||
*type = LfrfidKeyType::KeyI40134;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t lfrfid_key_get_type_data_count(LfrfidKeyType type) {
|
||||
switch(type) {
|
||||
case LfrfidKeyType::KeyEM4100:
|
||||
|
@@ -11,4 +11,5 @@ enum class LfrfidKeyType : uint8_t {
|
||||
};
|
||||
|
||||
const char* lfrfid_key_get_type_string(LfrfidKeyType type);
|
||||
bool lfrfid_key_get_string_type(const char* string, LfrfidKeyType* type);
|
||||
uint8_t lfrfid_key_get_type_data_count(LfrfidKeyType type);
|
@@ -1,12 +1,9 @@
|
||||
#include "rfid-key.h"
|
||||
#include <furi/check.h>
|
||||
#include <string.h>
|
||||
|
||||
RfidKey::RfidKey() {
|
||||
data.fill(0);
|
||||
|
||||
for(uint8_t i = 0; i < (LFRFID_KEY_NAME_SIZE + 1); i++) {
|
||||
name[i] = 0;
|
||||
}
|
||||
clear();
|
||||
}
|
||||
|
||||
RfidKey::~RfidKey() {
|
||||
@@ -16,18 +13,22 @@ void RfidKey::set_type(LfrfidKeyType _type) {
|
||||
type = _type;
|
||||
}
|
||||
|
||||
void RfidKey::set_data(uint8_t* _data, const uint8_t _data_size) {
|
||||
void RfidKey::set_data(const uint8_t* _data, const uint8_t _data_size) {
|
||||
furi_assert(_data_size <= data.size());
|
||||
for(uint8_t i = 0; i < _data_size; i++) {
|
||||
data[i] = _data[i];
|
||||
}
|
||||
}
|
||||
|
||||
void RfidKey::set_name(const char* _name) {
|
||||
strlcpy(name, _name, get_name_length());
|
||||
}
|
||||
|
||||
LfrfidKeyType RfidKey::get_type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
uint8_t* RfidKey::get_data() {
|
||||
const uint8_t* RfidKey::get_data() {
|
||||
return &data[0];
|
||||
}
|
||||
|
||||
@@ -42,3 +43,23 @@ const uint8_t RfidKey::get_type_data_count() {
|
||||
char* RfidKey::get_name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
uint8_t RfidKey::get_name_length() {
|
||||
return LFRFID_KEY_NAME_SIZE;
|
||||
}
|
||||
|
||||
void RfidKey::clear() {
|
||||
set_name("");
|
||||
set_type(LfrfidKeyType::KeyEM4100);
|
||||
data.fill(0);
|
||||
}
|
||||
|
||||
RfidKey& RfidKey::operator=(const RfidKey& rhs) {
|
||||
if(this == &rhs) return *this;
|
||||
|
||||
set_type(rhs.type);
|
||||
set_name(rhs.name);
|
||||
set_data(&rhs.data[0], get_type_data_count());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
@@ -8,15 +8,17 @@ public:
|
||||
~RfidKey();
|
||||
|
||||
void set_type(LfrfidKeyType type);
|
||||
void set_data(uint8_t* data, const uint8_t data_size);
|
||||
void set_data(const uint8_t* data, const uint8_t data_size);
|
||||
void set_name(const char* name);
|
||||
|
||||
LfrfidKeyType get_type();
|
||||
uint8_t* get_data();
|
||||
|
||||
const uint8_t* get_data();
|
||||
const char* get_type_text();
|
||||
const uint8_t get_type_data_count();
|
||||
|
||||
char* get_name();
|
||||
uint8_t get_name_length();
|
||||
void clear();
|
||||
RfidKey& operator=(const RfidKey& rhs);
|
||||
|
||||
private:
|
||||
std::array<uint8_t, LFRFID_KEY_SIZE> data;
|
||||
|
@@ -111,7 +111,7 @@ void RfidWriter::write_reset() {
|
||||
write_bit(0);
|
||||
}
|
||||
|
||||
void RfidWriter::write_em(uint8_t em_data[5]) {
|
||||
void RfidWriter::write_em(const uint8_t em_data[5]) {
|
||||
ProtocolEMMarin em_card;
|
||||
uint64_t em_encoded_data;
|
||||
em_card.encode(em_data, 5, reinterpret_cast<uint8_t*>(&em_encoded_data), sizeof(uint64_t));
|
||||
@@ -125,7 +125,7 @@ void RfidWriter::write_em(uint8_t em_data[5]) {
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
void RfidWriter::write_hid(uint8_t hid_data[3]) {
|
||||
void RfidWriter::write_hid(const uint8_t hid_data[3]) {
|
||||
ProtocolHID10301 hid_card;
|
||||
uint32_t card_data[3];
|
||||
hid_card.encode(hid_data, 3, reinterpret_cast<uint8_t*>(&card_data), sizeof(card_data) * 3);
|
||||
|
@@ -7,8 +7,8 @@ public:
|
||||
~RfidWriter();
|
||||
void start();
|
||||
void stop();
|
||||
void write_em(uint8_t em_data[5]);
|
||||
void write_hid(uint8_t hid_data[3]);
|
||||
void write_em(const uint8_t em_data[5]);
|
||||
void write_hid(const uint8_t hid_data[3]);
|
||||
|
||||
private:
|
||||
void write_gap(uint32_t gap_time);
|
||||
|
@@ -1,9 +1,9 @@
|
||||
#include "lfrfid-app.h"
|
||||
|
||||
// app enter function
|
||||
extern "C" int32_t lfrfid_app(void* p) {
|
||||
extern "C" int32_t lfrfid_app(void* args) {
|
||||
LfRfidApp* app = new LfRfidApp();
|
||||
app->run();
|
||||
app->run(args);
|
||||
delete app;
|
||||
|
||||
return 0;
|
||||
|
@@ -7,6 +7,20 @@
|
||||
#include "scene/lfrfid-app-scene-write-success.h"
|
||||
#include "scene/lfrfid-app-scene-emulate.h"
|
||||
#include "scene/lfrfid-app-scene-save-name.h"
|
||||
#include "scene/lfrfid-app-scene-save-success.h"
|
||||
#include "scene/lfrfid-app-scene-select-key.h"
|
||||
#include "scene/lfrfid-app-scene-saved-key-menu.h"
|
||||
#include "scene/lfrfid-app-scene-save-data.h"
|
||||
#include "scene/lfrfid-app-scene-save-type.h"
|
||||
#include "scene/lfrfid-app-scene-saved-info.h"
|
||||
#include "scene/lfrfid-app-scene-delete-confirm.h"
|
||||
#include "scene/lfrfid-app-scene-delete-success.h"
|
||||
|
||||
#include <file-worker-cpp.h>
|
||||
#include <path.h>
|
||||
|
||||
const char* LfRfidApp::app_folder = "lfrfid";
|
||||
const char* LfRfidApp::app_extension = ".rfid";
|
||||
|
||||
LfRfidApp::LfRfidApp()
|
||||
: scene_controller{this}
|
||||
@@ -24,14 +38,156 @@ LfRfidApp::~LfRfidApp() {
|
||||
api_hal_power_insomnia_exit();
|
||||
}
|
||||
|
||||
void LfRfidApp::run() {
|
||||
scene_controller.add_scene(SceneType::Start, new LfRfidAppSceneStart());
|
||||
scene_controller.add_scene(SceneType::Read, new LfRfidAppSceneRead());
|
||||
scene_controller.add_scene(SceneType::ReadSuccess, new LfRfidAppSceneReadSuccess());
|
||||
scene_controller.add_scene(SceneType::ReadedMenu, new LfRfidAppSceneReadedMenu());
|
||||
scene_controller.add_scene(SceneType::Write, new LfRfidAppSceneWrite());
|
||||
scene_controller.add_scene(SceneType::WriteSuccess, new LfRfidAppSceneWriteSuccess());
|
||||
scene_controller.add_scene(SceneType::Emulate, new LfRfidAppSceneEmulate());
|
||||
scene_controller.add_scene(SceneType::SaveName, new LfRfidAppSceneSaveName());
|
||||
scene_controller.process(100);
|
||||
void LfRfidApp::run(void* _args) {
|
||||
const char* args = reinterpret_cast<const char*>(_args);
|
||||
|
||||
if(strlen(args)) {
|
||||
load_key_data(args, &worker.key);
|
||||
scene_controller.add_scene(SceneType::Emulate, new LfRfidAppSceneEmulate());
|
||||
scene_controller.process(100, SceneType::Emulate);
|
||||
} else {
|
||||
scene_controller.add_scene(SceneType::Start, new LfRfidAppSceneStart());
|
||||
scene_controller.add_scene(SceneType::Read, new LfRfidAppSceneRead());
|
||||
scene_controller.add_scene(SceneType::ReadSuccess, new LfRfidAppSceneReadSuccess());
|
||||
scene_controller.add_scene(SceneType::ReadedMenu, new LfRfidAppSceneReadedMenu());
|
||||
scene_controller.add_scene(SceneType::Write, new LfRfidAppSceneWrite());
|
||||
scene_controller.add_scene(SceneType::WriteSuccess, new LfRfidAppSceneWriteSuccess());
|
||||
scene_controller.add_scene(SceneType::Emulate, new LfRfidAppSceneEmulate());
|
||||
scene_controller.add_scene(SceneType::SaveName, new LfRfidAppSceneSaveName());
|
||||
scene_controller.add_scene(SceneType::SaveSuccess, new LfRfidAppSceneSaveSuccess());
|
||||
scene_controller.add_scene(SceneType::SelectKey, new LfRfidAppSceneSelectKey());
|
||||
scene_controller.add_scene(SceneType::SavedKeyMenu, new LfRfidAppSceneSavedKeyMenu());
|
||||
scene_controller.add_scene(SceneType::SaveData, new LfRfidAppSceneSaveData());
|
||||
scene_controller.add_scene(SceneType::SaveType, new LfRfidAppSceneSaveType());
|
||||
scene_controller.add_scene(SceneType::SavedInfo, new LfRfidAppSceneSavedInfo());
|
||||
scene_controller.add_scene(SceneType::DeleteConfirm, new LfRfidAppSceneDeleteConfirm());
|
||||
scene_controller.add_scene(SceneType::DeleteSuccess, new LfRfidAppSceneDeleteSuccess());
|
||||
scene_controller.process(100);
|
||||
}
|
||||
}
|
||||
|
||||
bool LfRfidApp::save_key(RfidKey* key) {
|
||||
string_t file_name;
|
||||
bool result = false;
|
||||
|
||||
make_app_folder();
|
||||
|
||||
string_init_printf(file_name, "%s/%s%s", app_folder, key->get_name(), app_extension);
|
||||
result = save_key_data(string_get_cstr(file_name), key);
|
||||
string_clear(file_name);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool LfRfidApp::load_key_from_file_select(bool need_restore) {
|
||||
FileWorkerCpp file_worker;
|
||||
TextStore* filename_ts = new TextStore(64);
|
||||
bool result;
|
||||
|
||||
if(need_restore) {
|
||||
result = file_worker.file_select(
|
||||
app_folder,
|
||||
app_extension,
|
||||
filename_ts->text,
|
||||
filename_ts->text_size,
|
||||
worker.key.get_name());
|
||||
} else {
|
||||
result = file_worker.file_select(
|
||||
app_folder, app_extension, filename_ts->text, filename_ts->text_size, NULL);
|
||||
}
|
||||
|
||||
if(result) {
|
||||
string_t key_str;
|
||||
string_init_printf(key_str, "%s/%s%s", app_folder, filename_ts->text, app_extension);
|
||||
result = load_key_data(string_get_cstr(key_str), &worker.key);
|
||||
string_clear(key_str);
|
||||
}
|
||||
|
||||
delete filename_ts;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool LfRfidApp::delete_key(RfidKey* key) {
|
||||
FileWorkerCpp file_worker;
|
||||
string_t file_name;
|
||||
bool result = false;
|
||||
|
||||
string_init_printf(file_name, "%s/%s%s", app_folder, key->get_name(), app_extension);
|
||||
result = file_worker.remove(string_get_cstr(file_name));
|
||||
string_clear(file_name);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool LfRfidApp::load_key_data(const char* path, RfidKey* key) {
|
||||
FileWorkerCpp file_worker;
|
||||
bool result = false;
|
||||
|
||||
bool res = file_worker.open(path, FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
|
||||
if(res) {
|
||||
string_t str_result;
|
||||
string_init(str_result);
|
||||
|
||||
do {
|
||||
RfidKey loaded_key;
|
||||
LfrfidKeyType loaded_type;
|
||||
|
||||
// load type
|
||||
if(!file_worker.read_until(str_result, ' ')) break;
|
||||
if(!lfrfid_key_get_string_type(string_get_cstr(str_result), &loaded_type)) {
|
||||
file_worker.show_error("Cannot parse\nfile");
|
||||
break;
|
||||
}
|
||||
loaded_key.set_type(loaded_type);
|
||||
|
||||
// load data
|
||||
uint8_t tmp_data[loaded_key.get_type_data_count()];
|
||||
if(!file_worker.read_hex(tmp_data, loaded_key.get_type_data_count())) break;
|
||||
loaded_key.set_data(tmp_data, loaded_key.get_type_data_count());
|
||||
|
||||
*key = loaded_key;
|
||||
result = true;
|
||||
} while(0);
|
||||
|
||||
// load name
|
||||
path_extract_filename_no_ext(path, str_result);
|
||||
key->set_name(string_get_cstr(str_result));
|
||||
|
||||
string_clear(str_result);
|
||||
}
|
||||
|
||||
file_worker.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool LfRfidApp::save_key_data(const char* path, RfidKey* key) {
|
||||
FileWorkerCpp file_worker;
|
||||
bool result = false;
|
||||
|
||||
bool res = file_worker.open(path, FSAM_WRITE, FSOM_CREATE_ALWAYS);
|
||||
|
||||
if(res) {
|
||||
do {
|
||||
// type header
|
||||
const char* key_type = lfrfid_key_get_type_string(key->get_type());
|
||||
char delimeter = ' ';
|
||||
|
||||
if(!file_worker.write(key_type, strlen(key_type))) break;
|
||||
if(!file_worker.write(&delimeter)) break;
|
||||
if(!file_worker.write_hex(key->get_data(), key->get_type_data_count())) break;
|
||||
|
||||
result = true;
|
||||
} while(0);
|
||||
}
|
||||
|
||||
file_worker.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void LfRfidApp::make_app_folder() {
|
||||
FileWorkerCpp file_worker;
|
||||
file_worker.mkdir(app_folder);
|
||||
}
|
@@ -38,6 +38,14 @@ public:
|
||||
WriteSuccess,
|
||||
Emulate,
|
||||
SaveName,
|
||||
SaveSuccess,
|
||||
SelectKey,
|
||||
SavedKeyMenu,
|
||||
SaveData,
|
||||
SaveType,
|
||||
SavedInfo,
|
||||
DeleteConfirm,
|
||||
DeleteSuccess,
|
||||
};
|
||||
|
||||
class Event {
|
||||
@@ -63,5 +71,18 @@ public:
|
||||
RfidWorker worker;
|
||||
|
||||
TextStore text_store;
|
||||
void run();
|
||||
|
||||
void run(void* args);
|
||||
|
||||
static const char* app_folder;
|
||||
static const char* app_extension;
|
||||
|
||||
bool save_key(RfidKey* key);
|
||||
bool load_key_from_file_select(bool need_restore);
|
||||
bool delete_key(RfidKey* key);
|
||||
|
||||
bool load_key_data(const char* path, RfidKey* key);
|
||||
bool save_key_data(const char* path, RfidKey* key);
|
||||
|
||||
void make_app_folder();
|
||||
};
|
@@ -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