new iButton app (#328)
* rename old ibutton app to ibutton-test * more renames * updated onewire library compilation condition * add submenu_clean subroutine * add index for submenu callback * c++ guard for gui modules * add released ibutton app * fix the position of the submenu window if there are too few items * iButton app basis * negative icon position info * fix submenu_clean subroutine * add ibutton app to applications makefile * add onewire key read routine to read mode * rename mode to scene * rename files and folder (mode to scene) * rename ibutton view to view manager * rename get_view to get_view_manager * cpp guards * key read, store and notify features * syntax fix * make iButtonScene functions pure virtual * fix syntax * add text store, add new scene (crc error) * not a key scene * syntax fix * read success scene * app, switching to the previous scene with the number of scenes to be skipped * scene whith menu when key is readed * fix font height calculation, fix offsets * add key write scene * view_dispatcher_remove_view subroutine * generic pause/resume os methods * fix furi_assert usage * key store, worker * fix pointer comparsion * saved keys, saved key action scenes * key delete/confirm delete scenes and routines * use last input subsystem changes * fix syntax * fix new model usage in submenu * fix includes * use vibro pin * use stored key name if valid * emulate scene * random name generator * name and save readed key scenes, new icon * fix icon position * fix text scene exit * fix naming, fix text placement, new info scene * state-driven cyfral decoder * better cyfral decoder * better cyfral decoder * one wire: search command set * metakom decoder * more key types * add next scene to error scenes * universal key reader * use new key reader * syntax fix * warning fix * byte input module template * new thread and insomnia api usage * New element: slightly rounded frame * Use elements_slightly_rounded_frame in text input * Gui test app: byte input usage * Byte input module: data drawing and selection * Byte input: comment currently unused fns * remove volatile qualifier * base byte input realisation * App gui test: remove internal fns visibility * Byne input, final version * test install gcc-arm-none-eabi-10-2020-q4-major * test install gcc-arm-none-eabi-10-2020-q4-major * App iButton: byte input view managment * App iButton: add key manually scenes * App iButton: rename scenes, add popup timeout * App iButton: use new scenes, new fn for rollback to specific prevous scene. * App iButton: remove byte input view on app exit * App iButton: edit key scene * Module byte input: reduce swintch value to uint8_t * Module byte input: switch from switch-case to if, unfortunately we need compile-time constants to use with switch * Icons: new small arrows * Module byte input: new arrangement of elements * OneWire slave lib: fix deattach sequence * App iButton: pulse sequencer * App iButton: add more keys to store * App iButton: split key worker to separate read/write/emulate entitys * App iButton: use new read/emulate entities * fix callback pointer saving * App iButton: use KeyReader error enum instead of KeyWorker error list handling * App iButton: do not use insomnia fns in pulse sequencer * App iButton: use KeyReader error enum in read scene * OneWire slave lib: more READ ROM command variants, call callback only if positive result * GPIO resources: add external gpio * App SD/NFC: removed application * App iButton-test: update to new light api * App iButton: update to new light-api * Outdated apps: add api-light-usage * Gpio: update SD card CS pin settings * API-power: added fns to disable/enable external 3v3 dc-dc * API-gpio: separated SD card detect routines * Resources: removed sd cs pin * SD card: low level init now resets card power supply * App SD-filesystem: use new card detect fns * SD card: fix low level init headers * SD card: more realilable low level init, power reset, exit from command read cycle conditionally * App SD-filesystem: led notifiers, init cycling * SD card: backport to F4 * Api PWM: add c++ guards * App iButton: yellow blink in emulate scene, vibro on * App iButton: one wire keys command set * App iButton: successful write scene * App iButton: key writer * App iButton: syntax fix * App iButton: notify write success * App iButton: fix double scene change * SD card: handle eject in init sequence * SD card: api to set level on detect gpio * SPI: api to set state on bus pins * SD card: set low state on bus pins while power reset * File select: init * File select: fix input consuming * SD Card: fixed dir open api error * SD-card: replace strncpy by strlcpy. Fix buffer overflow error. * API HAL OS: replace CMP based ticks with ARR based one, hard reset lptimer on reconfiguration. * GUI: More stack size for (temporary, wee need to implement sd card api in separate thread) * GUI: File select module. * App iButton-test: remove obsolete app Co-authored-by: rusdacent <rusdacentx0x08@gmail.com> Co-authored-by: coreglitch <mail@s3f.ru> Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
62
applications/ibutton/scene/ibutton-scene-add-type.cpp
Normal file
62
applications/ibutton/scene/ibutton-scene-add-type.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "ibutton-scene-add-type.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexCyfral,
|
||||
SubmenuIndexDallas,
|
||||
SubmenuIndexMetakom,
|
||||
} SubmenuIndex;
|
||||
|
||||
void iButtonSceneAddType::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneAddType::submenu_callback);
|
||||
|
||||
submenu_add_item(submenu, "Cyfral", SubmenuIndexCyfral, callback, app);
|
||||
submenu_add_item(submenu, "Dallas", SubmenuIndexDallas, callback, app);
|
||||
submenu_add_item(submenu, "Metakom", SubmenuIndexMetakom, callback, app);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewSubmenu);
|
||||
}
|
||||
|
||||
bool iButtonSceneAddType::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeMenuSelected) {
|
||||
switch(event->payload.menu_index) {
|
||||
case SubmenuIndexCyfral:
|
||||
app->get_key()->set_type(iButtonKeyType::KeyCyfral);
|
||||
break;
|
||||
case SubmenuIndexDallas:
|
||||
app->get_key()->set_type(iButtonKeyType::KeyDallas);
|
||||
break;
|
||||
case SubmenuIndexMetakom:
|
||||
app->get_key()->set_type(iButtonKeyType::KeyMetakom);
|
||||
break;
|
||||
}
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneAddValue);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneAddType::on_exit(iButtonApp* app) {
|
||||
iButtonAppViewManager* view = app->get_view_manager();
|
||||
Submenu* submenu = view->get_submenu();
|
||||
|
||||
submenu_clean(submenu);
|
||||
}
|
||||
|
||||
void iButtonSceneAddType::submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
12
applications/ibutton/scene/ibutton-scene-add-type.h
Normal file
12
applications/ibutton/scene/ibutton-scene-add-type.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
|
||||
class iButtonSceneAddType : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void submenu_callback(void* context, uint32_t index);
|
||||
};
|
50
applications/ibutton/scene/ibutton-scene-add-value.cpp
Normal file
50
applications/ibutton/scene/ibutton-scene-add-value.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "ibutton-scene-add-value.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
void iButtonSceneAddValue::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
ByteInput* byte_input = view_manager->get_byte_input();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneAddValue::byte_input_callback);
|
||||
|
||||
byte_input_set_result_callback(
|
||||
byte_input,
|
||||
callback,
|
||||
NULL,
|
||||
app,
|
||||
app->get_key()->get_data(),
|
||||
app->get_key()->get_type_data_size());
|
||||
byte_input_set_header_text(byte_input, "Enter the key");
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewByteInput);
|
||||
}
|
||||
|
||||
bool iButtonSceneAddValue::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeByteEditResult) {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneSaveName);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneAddValue::on_exit(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
ByteInput* byte_input = view_manager->get_byte_input();
|
||||
|
||||
byte_input_set_result_callback(byte_input, NULL, NULL, NULL, NULL, 0);
|
||||
byte_input_set_header_text(byte_input, {0});
|
||||
}
|
||||
|
||||
void iButtonSceneAddValue::byte_input_callback(void* context, uint8_t* bytes, uint8_t bytes_count) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeByteEditResult;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
12
applications/ibutton/scene/ibutton-scene-add-value.h
Normal file
12
applications/ibutton/scene/ibutton-scene-add-value.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
|
||||
class iButtonSceneAddValue : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void byte_input_callback(void* context, uint8_t* bytes, uint8_t bytes_count);
|
||||
};
|
93
applications/ibutton/scene/ibutton-scene-delete-confirm.cpp
Normal file
93
applications/ibutton/scene/ibutton-scene-delete-confirm.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "ibutton-scene-delete-confirm.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
void iButtonSceneDeleteConfirm::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneDeleteConfirm::dialog_ex_callback);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
app->set_text_store(
|
||||
"Delete %s?\nID: %02X %02X %02X %02X %02X %02X %02X %02X\nType: Dallas",
|
||||
key->get_name(),
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3],
|
||||
key_data[4],
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7]);
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
app->set_text_store(
|
||||
"Delete %s?\nID: %02X %02X\nType: Cyfral", key->get_name(), key_data[0], key_data[1]);
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
app->set_text_store(
|
||||
"Delete %s?\nID: %02X %02X %02X %02X\nType: Metakom",
|
||||
key->get_name(),
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3]);
|
||||
break;
|
||||
}
|
||||
|
||||
dialog_ex_set_text(dialog_ex, app->get_text_store(), 64, 26, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Back");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "Delete");
|
||||
dialog_ex_set_result_callback(dialog_ex, callback);
|
||||
dialog_ex_set_context(dialog_ex, app);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewDialogEx);
|
||||
}
|
||||
|
||||
bool iButtonSceneDeleteConfirm::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeDialogResult) {
|
||||
if(event->payload.dialog_result == DialogExResultRight) {
|
||||
KeyStore* store = app->get_key_store();
|
||||
store->remove_key(app->get_stored_key_index());
|
||||
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneDeleteSuccess);
|
||||
} else {
|
||||
app->switch_to_previous_scene();
|
||||
}
|
||||
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneDeleteConfirm::on_exit(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
|
||||
app->set_text_store("");
|
||||
|
||||
dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
dialog_ex_set_left_button_text(dialog_ex, NULL);
|
||||
dialog_ex_set_right_button_text(dialog_ex, NULL);
|
||||
dialog_ex_set_result_callback(dialog_ex, NULL);
|
||||
dialog_ex_set_context(dialog_ex, NULL);
|
||||
}
|
||||
|
||||
void iButtonSceneDeleteConfirm::dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
13
applications/ibutton/scene/ibutton-scene-delete-confirm.h
Normal file
13
applications/ibutton/scene/ibutton-scene-delete-confirm.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
|
||||
class iButtonSceneDeleteConfirm : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void dialog_ex_callback(DialogExResult result, void* context);
|
||||
};
|
51
applications/ibutton/scene/ibutton-scene-delete-success.cpp
Normal file
51
applications/ibutton/scene/ibutton-scene-delete-success.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "ibutton-scene-delete-success.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include "../ibutton-key.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
void iButtonSceneDeleteSuccess::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneDeleteSuccess::popup_callback);
|
||||
|
||||
popup_set_icon(popup, 0, 2, I_DolphinMafia_115x62);
|
||||
popup_set_text(popup, "Deleted", 83, 19, AlignLeft, AlignBottom);
|
||||
|
||||
popup_set_callback(popup, callback);
|
||||
popup_set_context(popup, app);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_enable_timeout(popup);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
|
||||
}
|
||||
|
||||
bool iButtonSceneDeleteSuccess::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeBack) {
|
||||
app->search_and_switch_to_previous_scene({iButtonApp::Scene::SceneSavedList});
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneDeleteSuccess::on_exit(iButtonApp* app) {
|
||||
Popup* popup = app->get_view_manager()->get_popup();
|
||||
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, -1, -1, I_DolphinWait_61x59);
|
||||
|
||||
popup_disable_timeout(popup);
|
||||
popup_set_context(popup, NULL);
|
||||
popup_set_callback(popup, NULL);
|
||||
}
|
||||
|
||||
void iButtonSceneDeleteSuccess::popup_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeBack;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
12
applications/ibutton/scene/ibutton-scene-delete-success.h
Normal file
12
applications/ibutton/scene/ibutton-scene-delete-success.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
|
||||
class iButtonSceneDeleteSuccess : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void popup_callback(void* context);
|
||||
};
|
93
applications/ibutton/scene/ibutton-scene-emulate.cpp
Normal file
93
applications/ibutton/scene/ibutton-scene-emulate.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "ibutton-scene-emulate.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include "../ibutton-key.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
void iButtonSceneEmulate::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
const char* key_name = key->get_name();
|
||||
uint8_t line_count = 2;
|
||||
|
||||
// check that stored key has name
|
||||
if(strcmp(key_name, "") != 0) {
|
||||
app->set_text_store("emulating\n%s", key_name);
|
||||
line_count = 2;
|
||||
} else {
|
||||
// if not, show key data
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
app->set_text_store(
|
||||
"emulating\n%02X %02X %02X %02X\n%02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3],
|
||||
key_data[4],
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7]);
|
||||
line_count = 3;
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
app->set_text_store("emulating\n%02X %02X", key_data[0], key_data[1]);
|
||||
line_count = 2;
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
app->set_text_store(
|
||||
"emulating\n%02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3]);
|
||||
line_count = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch(line_count) {
|
||||
case 3:
|
||||
popup_set_header(popup, "iButton", 92, 18, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, app->get_text_store(), 92, 22, AlignCenter, AlignTop);
|
||||
break;
|
||||
|
||||
default:
|
||||
popup_set_header(popup, "iButton", 92, 24, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, app->get_text_store(), 92, 28, AlignCenter, AlignTop);
|
||||
break;
|
||||
}
|
||||
|
||||
popup_set_icon(popup, 10, 10, I_iButtonKey_49x44);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
|
||||
app->get_key_worker()->start_emulate(app->get_key());
|
||||
}
|
||||
|
||||
bool iButtonSceneEmulate::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeTick) {
|
||||
consumed = true;
|
||||
if(app->get_key_worker()->emulated()) {
|
||||
app->notify_yellow_blink();
|
||||
} else {
|
||||
app->notify_red_blink();
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneEmulate::on_exit(iButtonApp* app) {
|
||||
app->get_key_worker()->stop_emulate();
|
||||
|
||||
Popup* popup = app->get_view_manager()->get_popup();
|
||||
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, -1, -1, I_DolphinWait_61x59);
|
||||
}
|
10
applications/ibutton/scene/ibutton-scene-emulate.h
Normal file
10
applications/ibutton/scene/ibutton-scene-emulate.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
#include "../helpers/key-emulator.h"
|
||||
|
||||
class iButtonSceneEmulate : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
};
|
13
applications/ibutton/scene/ibutton-scene-generic.h
Normal file
13
applications/ibutton/scene/ibutton-scene-generic.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "../ibutton-event.h"
|
||||
|
||||
class iButtonApp;
|
||||
|
||||
class iButtonScene {
|
||||
public:
|
||||
virtual void on_enter(iButtonApp* app) = 0;
|
||||
virtual bool on_event(iButtonApp* app, iButtonEvent* event) = 0;
|
||||
virtual void on_exit(iButtonApp* app) = 0;
|
||||
|
||||
private:
|
||||
};
|
82
applications/ibutton/scene/ibutton-scene-info.cpp
Normal file
82
applications/ibutton/scene/ibutton-scene-info.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
#include "ibutton-scene-info.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
void iButtonSceneInfo::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneInfo::dialog_ex_callback);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
app->set_text_store(
|
||||
"%s\n%02X %02X %02X %02X %02X %02X %02X %02X\nDallas",
|
||||
key->get_name(),
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3],
|
||||
key_data[4],
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7]);
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
app->set_text_store(
|
||||
"%s\n%02X %02X %02X %02X\nMetakom",
|
||||
key->get_name(),
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3]);
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
app->set_text_store("%s\n%02X %02X\nCyfral", key->get_name(), key_data[0], key_data[1]);
|
||||
break;
|
||||
}
|
||||
|
||||
dialog_ex_set_text(dialog_ex, app->get_text_store(), 64, 26, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Back");
|
||||
dialog_ex_set_result_callback(dialog_ex, callback);
|
||||
dialog_ex_set_context(dialog_ex, app);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewDialogEx);
|
||||
}
|
||||
|
||||
bool iButtonSceneInfo::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeDialogResult) {
|
||||
app->switch_to_previous_scene();
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneInfo::on_exit(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
|
||||
app->set_text_store("");
|
||||
|
||||
dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
dialog_ex_set_left_button_text(dialog_ex, NULL);
|
||||
dialog_ex_set_result_callback(dialog_ex, NULL);
|
||||
dialog_ex_set_context(dialog_ex, NULL);
|
||||
}
|
||||
|
||||
void iButtonSceneInfo::dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
13
applications/ibutton/scene/ibutton-scene-info.h
Normal file
13
applications/ibutton/scene/ibutton-scene-info.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
|
||||
class iButtonSceneInfo : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void dialog_ex_callback(DialogExResult result, void* context);
|
||||
};
|
75
applications/ibutton/scene/ibutton-scene-read-crc-error.cpp
Normal file
75
applications/ibutton/scene/ibutton-scene-read-crc-error.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "ibutton-scene-read-crc-error.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
void iButtonSceneReadCRCError::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneReadCRCError::dialog_ex_callback);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
|
||||
app->set_text_store(
|
||||
"%02X %02X %02X %02X %02X %02X %02X %02X\nExpected CRC: %X",
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3],
|
||||
key_data[4],
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7],
|
||||
maxim_crc8(key_data, 7));
|
||||
|
||||
dialog_ex_set_header(dialog_ex, "CRC ERROR", 64, 10, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_text(dialog_ex, app->get_text_store(), 64, 19, AlignCenter, AlignTop);
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Back");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "More");
|
||||
dialog_ex_set_result_callback(dialog_ex, callback);
|
||||
dialog_ex_set_context(dialog_ex, app);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewDialogEx);
|
||||
app->notify_error();
|
||||
}
|
||||
|
||||
bool iButtonSceneReadCRCError::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeDialogResult) {
|
||||
if(event->payload.dialog_result == DialogExResultRight) {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadedKeyMenu);
|
||||
} else {
|
||||
app->switch_to_previous_scene();
|
||||
}
|
||||
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneReadCRCError::on_exit(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
|
||||
app->set_text_store("");
|
||||
|
||||
dialog_ex_set_header(dialog_ex, NULL, 0, 0, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
dialog_ex_set_left_button_text(dialog_ex, NULL);
|
||||
dialog_ex_set_result_callback(dialog_ex, NULL);
|
||||
dialog_ex_set_context(dialog_ex, NULL);
|
||||
}
|
||||
|
||||
void iButtonSceneReadCRCError::dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
13
applications/ibutton/scene/ibutton-scene-read-crc-error.h
Normal file
13
applications/ibutton/scene/ibutton-scene-read-crc-error.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
|
||||
class iButtonSceneReadCRCError : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void dialog_ex_callback(DialogExResult result, void* context);
|
||||
};
|
@@ -0,0 +1,75 @@
|
||||
#include "ibutton-scene-read-not-key-error.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
void iButtonSceneReadNotKeyError::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneReadNotKeyError::dialog_ex_callback);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
|
||||
app->set_text_store(
|
||||
"THIS IS NOT A KEY\n%02X %02X %02X %02X %02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3],
|
||||
key_data[4],
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7],
|
||||
maxim_crc8(key_data, 7));
|
||||
|
||||
dialog_ex_set_header(dialog_ex, "ERROR:", 64, 10, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_text(dialog_ex, app->get_text_store(), 64, 19, AlignCenter, AlignTop);
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Back");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "More");
|
||||
dialog_ex_set_result_callback(dialog_ex, callback);
|
||||
dialog_ex_set_context(dialog_ex, app);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewDialogEx);
|
||||
app->notify_error();
|
||||
}
|
||||
|
||||
bool iButtonSceneReadNotKeyError::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeDialogResult) {
|
||||
if(event->payload.dialog_result == DialogExResultRight) {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadedKeyMenu);
|
||||
} else {
|
||||
app->switch_to_previous_scene();
|
||||
}
|
||||
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneReadNotKeyError::on_exit(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
|
||||
app->set_text_store("");
|
||||
|
||||
dialog_ex_set_header(dialog_ex, NULL, 0, 0, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
dialog_ex_set_left_button_text(dialog_ex, NULL);
|
||||
dialog_ex_set_result_callback(dialog_ex, NULL);
|
||||
dialog_ex_set_context(dialog_ex, NULL);
|
||||
}
|
||||
|
||||
void iButtonSceneReadNotKeyError::dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
|
||||
class iButtonSceneReadNotKeyError : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void dialog_ex_callback(DialogExResult result, void* context);
|
||||
};
|
88
applications/ibutton/scene/ibutton-scene-read-success.cpp
Normal file
88
applications/ibutton/scene/ibutton-scene-read-success.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include "ibutton-scene-read-success.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
void iButtonSceneReadSuccess::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneReadSuccess::dialog_ex_callback);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
app->set_text_store(
|
||||
"%02X %02X %02X %02X\n%02X %02X %02X %02X\nDallas",
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3],
|
||||
key_data[4],
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7]);
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
app->set_text_store("%02X %02X\nCyfral", key_data[0], key_data[1]);
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
app->set_text_store(
|
||||
"%02X %02X %02X %02X\nMetakom", key_data[0], key_data[1], key_data[2], key_data[3]);
|
||||
break;
|
||||
}
|
||||
|
||||
dialog_ex_set_text(dialog_ex, app->get_text_store(), 95, 30, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Back");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "More");
|
||||
dialog_ex_set_icon(dialog_ex, 0, 1, I_DolphinExcited_64x63);
|
||||
dialog_ex_set_result_callback(dialog_ex, callback);
|
||||
dialog_ex_set_context(dialog_ex, app);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewDialogEx);
|
||||
app->notify_green_on();
|
||||
app->notify_success();
|
||||
}
|
||||
|
||||
bool iButtonSceneReadSuccess::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeDialogResult) {
|
||||
if(event->payload.dialog_result == DialogExResultRight) {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadedKeyMenu);
|
||||
} else {
|
||||
app->switch_to_previous_scene();
|
||||
}
|
||||
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneReadSuccess::on_exit(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
|
||||
app->set_text_store("");
|
||||
|
||||
dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
dialog_ex_set_left_button_text(dialog_ex, NULL);
|
||||
dialog_ex_set_right_button_text(dialog_ex, NULL);
|
||||
dialog_ex_set_result_callback(dialog_ex, NULL);
|
||||
dialog_ex_set_context(dialog_ex, NULL);
|
||||
dialog_ex_set_icon(dialog_ex, -1, -1, I_ButtonCenter_7x7);
|
||||
app->notify_green_off();
|
||||
}
|
||||
|
||||
void iButtonSceneReadSuccess::dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
13
applications/ibutton/scene/ibutton-scene-read-success.h
Normal file
13
applications/ibutton/scene/ibutton-scene-read-success.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
|
||||
class iButtonSceneReadSuccess : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void dialog_ex_callback(DialogExResult result, void* context);
|
||||
};
|
53
applications/ibutton/scene/ibutton-scene-read.cpp
Normal file
53
applications/ibutton/scene/ibutton-scene-read.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "ibutton-scene-read.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
|
||||
void iButtonSceneRead::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
|
||||
popup_set_header(popup, "iButton", 95, 26, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, "waiting\nfor key ...", 95, 30, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 5, I_DolphinWait_61x59);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
|
||||
app->get_key()->set_name("");
|
||||
|
||||
app->get_key_worker()->start_read();
|
||||
}
|
||||
|
||||
bool iButtonSceneRead::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeTick) {
|
||||
consumed = true;
|
||||
app->notify_red_blink();
|
||||
|
||||
switch(app->get_key_worker()->read(app->get_key())) {
|
||||
case KeyReader::Error::EMPTY:
|
||||
break;
|
||||
case KeyReader::Error::OK:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadSuccess);
|
||||
break;
|
||||
case KeyReader::Error::CRC_ERROR:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadCRCError);
|
||||
break;
|
||||
case KeyReader::Error::NOT_ARE_KEY:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadNotKeyError);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneRead::on_exit(iButtonApp* app) {
|
||||
app->get_key_worker()->stop_read();
|
||||
|
||||
Popup* popup = app->get_view_manager()->get_popup();
|
||||
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, -1, -1, I_DolphinWait_61x59);
|
||||
}
|
11
applications/ibutton/scene/ibutton-scene-read.h
Normal file
11
applications/ibutton/scene/ibutton-scene-read.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
|
||||
class iButtonSceneRead : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
};
|
64
applications/ibutton/scene/ibutton-scene-readed-key-menu.cpp
Normal file
64
applications/ibutton/scene/ibutton-scene-readed-key-menu.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#include "ibutton-scene-readed-key-menu.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexWrite,
|
||||
SubmenuIndexEmulate,
|
||||
SubmenuIndexNameAndSave,
|
||||
} SubmenuIndex;
|
||||
|
||||
void iButtonSceneReadedKeyMenu::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneReadedKeyMenu::submenu_callback);
|
||||
|
||||
submenu_add_item(submenu, "Write", SubmenuIndexWrite, callback, app);
|
||||
submenu_add_item(submenu, "Name and save", SubmenuIndexNameAndSave, callback, app);
|
||||
submenu_add_item(submenu, "Emulate", SubmenuIndexEmulate, callback, app);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewSubmenu);
|
||||
}
|
||||
|
||||
bool iButtonSceneReadedKeyMenu::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeMenuSelected) {
|
||||
switch(event->payload.menu_index) {
|
||||
case SubmenuIndexWrite:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneWrite);
|
||||
break;
|
||||
case SubmenuIndexEmulate:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneEmulate);
|
||||
break;
|
||||
case SubmenuIndexNameAndSave:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneSaveName);
|
||||
break;
|
||||
}
|
||||
consumed = true;
|
||||
} else if(event->type == iButtonEvent::Type::EventTypeBack) {
|
||||
app->search_and_switch_to_previous_scene({iButtonApp::Scene::SceneRead});
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneReadedKeyMenu::on_exit(iButtonApp* app) {
|
||||
iButtonAppViewManager* view = app->get_view_manager();
|
||||
Submenu* submenu = view->get_submenu();
|
||||
|
||||
submenu_clean(submenu);
|
||||
}
|
||||
|
||||
void iButtonSceneReadedKeyMenu::submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
12
applications/ibutton/scene/ibutton-scene-readed-key-menu.h
Normal file
12
applications/ibutton/scene/ibutton-scene-readed-key-menu.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
|
||||
class iButtonSceneReadedKeyMenu : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void submenu_callback(void* context, uint32_t index);
|
||||
};
|
59
applications/ibutton/scene/ibutton-scene-save-name.cpp
Normal file
59
applications/ibutton/scene/ibutton-scene-save-name.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "ibutton-scene-save-name.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include "../ibutton-key.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
void iButtonSceneSaveName::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
TextInput* text_input = view_manager->get_text_input();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneSaveName::text_input_callback);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
const char* key_name = key->get_name();
|
||||
|
||||
if(strcmp(key_name, "") == 0) {
|
||||
app->generate_random_name(app->get_text_store(), app->get_text_store_size());
|
||||
}
|
||||
|
||||
text_input_set_header_text(text_input, "Name the key");
|
||||
text_input_set_result_callback(
|
||||
text_input, callback, app, app->get_text_store(), app->get_text_store_size());
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewTextInput);
|
||||
}
|
||||
|
||||
bool iButtonSceneSaveName::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeTextEditResult) {
|
||||
KeyStore* store = app->get_key_store();
|
||||
uint8_t key_index = store->add_key();
|
||||
iButtonKey* key = app->get_key();
|
||||
|
||||
store->set_key_type(key_index, key->get_key_type());
|
||||
store->set_key_name(key_index, app->get_text_store());
|
||||
store->set_key_data(key_index, key->get_data(), key->get_size());
|
||||
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneSaveSuccess);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneSaveName::on_exit(iButtonApp* app) {
|
||||
TextInput* text_input = app->get_view_manager()->get_text_input();
|
||||
text_input_set_header_text(text_input, "");
|
||||
text_input_set_result_callback(text_input, NULL, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
void iButtonSceneSaveName::text_input_callback(void* context, char* text) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeTextEditResult;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
12
applications/ibutton/scene/ibutton-scene-save-name.h
Normal file
12
applications/ibutton/scene/ibutton-scene-save-name.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
|
||||
class iButtonSceneSaveName : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void text_input_callback(void* context, char* text);
|
||||
};
|
54
applications/ibutton/scene/ibutton-scene-save-success.cpp
Normal file
54
applications/ibutton/scene/ibutton-scene-save-success.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "ibutton-scene-save-success.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include "../ibutton-key.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
void iButtonSceneSaveSuccess::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneSaveSuccess::popup_callback);
|
||||
|
||||
popup_set_icon(popup, 32, 5, I_DolphinNice_96x59);
|
||||
popup_set_text(popup, "Saved!", 13, 22, AlignLeft, AlignBottom);
|
||||
|
||||
popup_set_callback(popup, callback);
|
||||
popup_set_context(popup, app);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_enable_timeout(popup);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
|
||||
}
|
||||
|
||||
bool iButtonSceneSaveSuccess::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeBack) {
|
||||
app->search_and_switch_to_previous_scene(
|
||||
{iButtonApp::Scene::SceneReadedKeyMenu,
|
||||
iButtonApp::Scene::SceneSavedKeyMenu,
|
||||
iButtonApp::Scene::SceneAddType});
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneSaveSuccess::on_exit(iButtonApp* app) {
|
||||
Popup* popup = app->get_view_manager()->get_popup();
|
||||
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, -1, -1, I_DolphinWait_61x59);
|
||||
|
||||
popup_disable_timeout(popup);
|
||||
popup_set_context(popup, NULL);
|
||||
popup_set_callback(popup, NULL);
|
||||
}
|
||||
|
||||
void iButtonSceneSaveSuccess::popup_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeBack;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
12
applications/ibutton/scene/ibutton-scene-save-success.h
Normal file
12
applications/ibutton/scene/ibutton-scene-save-success.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
|
||||
class iButtonSceneSaveSuccess : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void popup_callback(void* context);
|
||||
};
|
71
applications/ibutton/scene/ibutton-scene-saved-key-menu.cpp
Normal file
71
applications/ibutton/scene/ibutton-scene-saved-key-menu.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "ibutton-scene-saved-key-menu.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexWrite,
|
||||
SubmenuIndexEmulate,
|
||||
SubmenuIndexEdit,
|
||||
SubmenuIndexDelete,
|
||||
SubmenuIndexInfo,
|
||||
} SubmenuIndex;
|
||||
|
||||
void iButtonSceneSavedKeyMenu::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneSavedKeyMenu::submenu_callback);
|
||||
|
||||
submenu_add_item(submenu, "Write", SubmenuIndexWrite, callback, app);
|
||||
submenu_add_item(submenu, "Emulate", SubmenuIndexEmulate, callback, app);
|
||||
submenu_add_item(submenu, "Edit", SubmenuIndexEdit, callback, app);
|
||||
submenu_add_item(submenu, "Delete", SubmenuIndexDelete, callback, app);
|
||||
submenu_add_item(submenu, "Info", SubmenuIndexInfo, callback, app);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewSubmenu);
|
||||
}
|
||||
|
||||
bool iButtonSceneSavedKeyMenu::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeMenuSelected) {
|
||||
switch(event->payload.menu_index) {
|
||||
case SubmenuIndexWrite:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneWrite);
|
||||
break;
|
||||
case SubmenuIndexEmulate:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneEmulate);
|
||||
break;
|
||||
case SubmenuIndexEdit:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneAddValue);
|
||||
break;
|
||||
case SubmenuIndexDelete:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneDeleteConfirm);
|
||||
break;
|
||||
case SubmenuIndexInfo:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneInfo);
|
||||
break;
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneSavedKeyMenu::on_exit(iButtonApp* app) {
|
||||
iButtonAppViewManager* view = app->get_view_manager();
|
||||
Submenu* submenu = view->get_submenu();
|
||||
|
||||
submenu_clean(submenu);
|
||||
}
|
||||
|
||||
void iButtonSceneSavedKeyMenu::submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
12
applications/ibutton/scene/ibutton-scene-saved-key-menu.h
Normal file
12
applications/ibutton/scene/ibutton-scene-saved-key-menu.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
|
||||
class iButtonSceneSavedKeyMenu : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void submenu_callback(void* context, uint32_t index);
|
||||
};
|
62
applications/ibutton/scene/ibutton-scene-saved.cpp
Normal file
62
applications/ibutton/scene/ibutton-scene-saved.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "ibutton-scene-saved.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
void iButtonSceneSavedList::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneSavedList::submenu_callback);
|
||||
|
||||
KeyStore* store = app->get_key_store();
|
||||
|
||||
if(store->get_key_count() > 0) {
|
||||
for(uint8_t i = 0; i < store->get_key_count(); i++) {
|
||||
submenu_add_item(submenu, store->get_key_name(i), i, callback, app);
|
||||
}
|
||||
} else {
|
||||
submenu_add_item(submenu, "Empty", 0, NULL, NULL);
|
||||
}
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewSubmenu);
|
||||
}
|
||||
|
||||
bool iButtonSceneSavedList::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeMenuSelected) {
|
||||
uint8_t key_index = event->payload.menu_index;
|
||||
|
||||
// store data
|
||||
iButtonKey* stored_key_data = app->get_key();
|
||||
KeyStore* store = app->get_key_store();
|
||||
|
||||
app->set_stored_key_index(key_index);
|
||||
stored_key_data->set_name(store->get_key_name(key_index));
|
||||
stored_key_data->set_type(store->get_key_type(key_index));
|
||||
stored_key_data->set_data(store->get_key_data(key_index), stored_key_data->get_size());
|
||||
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneSavedKeyMenu);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneSavedList::on_exit(iButtonApp* app) {
|
||||
iButtonAppViewManager* view = app->get_view_manager();
|
||||
Submenu* submenu = view->get_submenu();
|
||||
|
||||
submenu_clean(submenu);
|
||||
}
|
||||
|
||||
void iButtonSceneSavedList::submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
12
applications/ibutton/scene/ibutton-scene-saved.h
Normal file
12
applications/ibutton/scene/ibutton-scene-saved.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
|
||||
class iButtonSceneSavedList : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void submenu_callback(void* context, uint32_t index);
|
||||
};
|
61
applications/ibutton/scene/ibutton-scene-start.cpp
Normal file
61
applications/ibutton/scene/ibutton-scene-start.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "ibutton-scene-start.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexRead,
|
||||
SubmenuIndexSaved,
|
||||
SubmenuIndexAdd,
|
||||
} SubmenuIndex;
|
||||
|
||||
void iButtonSceneStart::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneStart::submenu_callback);
|
||||
|
||||
submenu_add_item(submenu, "Read", SubmenuIndexRead, callback, app);
|
||||
submenu_add_item(submenu, "Saved", SubmenuIndexSaved, callback, app);
|
||||
submenu_add_item(submenu, "Add manually", SubmenuIndexAdd, callback, app);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewSubmenu);
|
||||
}
|
||||
|
||||
bool iButtonSceneStart::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeMenuSelected) {
|
||||
switch(event->payload.menu_index) {
|
||||
case SubmenuIndexRead:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneRead);
|
||||
break;
|
||||
case SubmenuIndexSaved:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneSavedList);
|
||||
break;
|
||||
case SubmenuIndexAdd:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneAddType);
|
||||
break;
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneStart::on_exit(iButtonApp* app) {
|
||||
iButtonAppViewManager* view = app->get_view_manager();
|
||||
Submenu* submenu = view->get_submenu();
|
||||
|
||||
submenu_clean(submenu);
|
||||
}
|
||||
|
||||
void iButtonSceneStart::submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
12
applications/ibutton/scene/ibutton-scene-start.h
Normal file
12
applications/ibutton/scene/ibutton-scene-start.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
|
||||
class iButtonSceneStart : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void submenu_callback(void* context, uint32_t index);
|
||||
};
|
55
applications/ibutton/scene/ibutton-scene-write-success.cpp
Normal file
55
applications/ibutton/scene/ibutton-scene-write-success.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "ibutton-scene-write-success.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include "../ibutton-key.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
void iButtonSceneWriteSuccess::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneWriteSuccess::popup_callback);
|
||||
|
||||
popup_set_icon(popup, 0, 12, I_iButtonDolphinVerySuccess_108x52);
|
||||
popup_set_text(popup, "Successful writing!", 47, 14, AlignLeft, AlignBottom);
|
||||
|
||||
popup_set_callback(popup, callback);
|
||||
popup_set_context(popup, app);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_enable_timeout(popup);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
|
||||
app->notify_green_on();
|
||||
app->notify_success();
|
||||
}
|
||||
|
||||
bool iButtonSceneWriteSuccess::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeBack) {
|
||||
app->search_and_switch_to_previous_scene(
|
||||
{iButtonApp::Scene::SceneReadedKeyMenu, iButtonApp::Scene::SceneStart});
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneWriteSuccess::on_exit(iButtonApp* app) {
|
||||
Popup* popup = app->get_view_manager()->get_popup();
|
||||
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, -1, -1, I_DolphinWait_61x59);
|
||||
|
||||
popup_disable_timeout(popup);
|
||||
popup_set_context(popup, NULL);
|
||||
popup_set_callback(popup, NULL);
|
||||
app->notify_green_off();
|
||||
}
|
||||
|
||||
void iButtonSceneWriteSuccess::popup_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeBack;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
12
applications/ibutton/scene/ibutton-scene-write-success.h
Normal file
12
applications/ibutton/scene/ibutton-scene-write-success.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
|
||||
class iButtonSceneWriteSuccess : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void popup_callback(void* context);
|
||||
};
|
98
applications/ibutton/scene/ibutton-scene-write.cpp
Normal file
98
applications/ibutton/scene/ibutton-scene-write.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
#include "ibutton-scene-write.h"
|
||||
#include "../ibutton-app.h"
|
||||
#include "../ibutton-view-manager.h"
|
||||
#include "../ibutton-event.h"
|
||||
#include "../ibutton-key.h"
|
||||
|
||||
void iButtonSceneWrite::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
const char* key_name = key->get_name();
|
||||
uint8_t line_count = 2;
|
||||
|
||||
// check that stored key has name
|
||||
if(strcmp(key_name, "") != 0) {
|
||||
app->set_text_store("writing\n%s", key_name);
|
||||
line_count = 2;
|
||||
} else {
|
||||
// if not, show key data
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
app->set_text_store(
|
||||
"writing\n%02X %02X %02X %02X\n%02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3],
|
||||
key_data[4],
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7]);
|
||||
line_count = 3;
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
app->set_text_store("writing\n%02X %02X", key_data[0], key_data[1]);
|
||||
line_count = 2;
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
app->set_text_store(
|
||||
"writing\n%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]);
|
||||
line_count = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch(line_count) {
|
||||
case 3:
|
||||
popup_set_header(popup, "iButton", 92, 18, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, app->get_text_store(), 92, 22, AlignCenter, AlignTop);
|
||||
break;
|
||||
|
||||
default:
|
||||
popup_set_header(popup, "iButton", 92, 24, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, app->get_text_store(), 92, 28, AlignCenter, AlignTop);
|
||||
break;
|
||||
}
|
||||
|
||||
popup_set_icon(popup, 10, 10, I_iButtonKey_49x44);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
|
||||
|
||||
app->get_key_worker()->start_write();
|
||||
}
|
||||
|
||||
bool iButtonSceneWrite::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeTick) {
|
||||
consumed = true;
|
||||
KeyWriter::Error result = app->get_key_worker()->write(app->get_key());
|
||||
|
||||
switch(result) {
|
||||
case KeyWriter::Error::SAME_KEY:
|
||||
case KeyWriter::Error::OK:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneWriteSuccess);
|
||||
break;
|
||||
case KeyWriter::Error::NO_DETECT:
|
||||
app->notify_red_blink();
|
||||
break;
|
||||
case KeyWriter::Error::CANNOT_WRITE:
|
||||
app->notify_yellow_blink();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneWrite::on_exit(iButtonApp* app) {
|
||||
Popup* popup = app->get_view_manager()->get_popup();
|
||||
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, -1, -1, I_DolphinWait_61x59);
|
||||
|
||||
app->get_key_worker()->stop_write();
|
||||
}
|
11
applications/ibutton/scene/ibutton-scene-write.h
Normal file
11
applications/ibutton/scene/ibutton-scene-write.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include "ibutton-scene-generic.h"
|
||||
|
||||
class iButtonSceneWrite : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
};
|
Reference in New Issue
Block a user