mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-24 03:33:08 +00:00
855f2584ab
* Storage: correct replacement for "/any" path in path holder * Unit tests: storage, blocking file open test * File stream: error getter * Storage: common copy and common remove now executes in external thread * Filesystems: got rid of unused functions * Storage: untangle dependencies, ram-frendly filesystem api * iButton: context assertions * Storage: pubsub messages * Storage: wait for the file to close if it was open * Storage: fix folder copying * Storage: unit test * Storage: pubsub documentation * Fix merge error * Fix memleak in storage test * Storage: remove unused define Co-authored-by: あく <alleteam@gmail.com>
62 lines
2.3 KiB
C++
62 lines
2.3 KiB
C++
#include "ibutton_scene_read.h"
|
|
#include "../ibutton_app.h"
|
|
#include <dolphin/dolphin.h>
|
|
|
|
static void read_callback(void* context) {
|
|
furi_assert(context);
|
|
iButtonApp* app = static_cast<iButtonApp*>(context);
|
|
iButtonEvent event = {.type = iButtonEvent::Type::EventTypeWorkerRead};
|
|
app->get_view_manager()->send_event(&event);
|
|
}
|
|
|
|
void iButtonSceneRead::on_enter(iButtonApp* app) {
|
|
iButtonAppViewManager* view_manager = app->get_view_manager();
|
|
Popup* popup = view_manager->get_popup();
|
|
iButtonKey* key = app->get_key();
|
|
iButtonWorker* worker = app->get_key_worker();
|
|
DOLPHIN_DEED(DolphinDeedIbuttonRead);
|
|
|
|
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);
|
|
ibutton_key_set_name(key, "");
|
|
|
|
ibutton_worker_read_set_callback(worker, read_callback, app);
|
|
ibutton_worker_read_start(worker, key);
|
|
}
|
|
|
|
bool iButtonSceneRead::on_event(iButtonApp* app, iButtonEvent* event) {
|
|
bool consumed = false;
|
|
|
|
if(event->type == iButtonEvent::Type::EventTypeWorkerRead) {
|
|
consumed = true;
|
|
|
|
iButtonKey* key = app->get_key();
|
|
if(ibutton_key_get_type(key) == iButtonKeyDS1990) {
|
|
if(!ibutton_key_dallas_crc_is_valid(key)) {
|
|
app->switch_to_next_scene(iButtonApp::Scene::SceneReadCRCError);
|
|
} else if(!ibutton_key_dallas_is_1990_key(key)) {
|
|
app->switch_to_next_scene(iButtonApp::Scene::SceneReadNotKeyError);
|
|
} else {
|
|
app->switch_to_next_scene(iButtonApp::Scene::SceneReadSuccess);
|
|
}
|
|
} else {
|
|
app->switch_to_next_scene(iButtonApp::Scene::SceneReadSuccess);
|
|
}
|
|
} else if(event->type == iButtonEvent::Type::EventTypeTick) {
|
|
consumed = true;
|
|
app->notify_red_blink();
|
|
}
|
|
|
|
return consumed;
|
|
}
|
|
|
|
void iButtonSceneRead::on_exit(iButtonApp* app) {
|
|
Popup* popup = app->get_view_manager()->get_popup();
|
|
ibutton_worker_stop(app->get_key_worker());
|
|
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
|
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
|
popup_set_icon(popup, 0, 0, NULL);
|
|
}
|