flipperzero-firmware/applications/main/lfrfid/scenes/lfrfid_scene_read.c
Sergey Gavrilov 4bf29827f8
M*LIB: non-inlined strings, FuriString primitive (#1795)
* Quicksave 1
* Header stage complete
* Source stage complete
* Lint & merge fixes
* Includes
* Documentation step 1
* FBT: output free size considering BT STACK
* Documentation step 2
* py lint
* Fix music player plugin
* unit test stage 1: string allocator, mem, getters, setters, appends, compare, search.
* unit test: string equality
* unit test: string replace
* unit test: string start_with, end_with
* unit test: string trim
* unit test: utf-8
* Rename
* Revert fw_size changes
* Simplify CLI backspace handling
* Simplify CLI character insert
* Merge fixes
* Furi: correct filenaming and spelling
* Bt: remove furi string include

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2022-10-06 00:15:23 +09:00

110 lines
3.9 KiB
C

#include "../lfrfid_i.h"
#include <dolphin/dolphin.h>
static const NotificationSequence sequence_blink_set_yellow = {
&message_blink_set_color_yellow,
NULL,
};
static const NotificationSequence sequence_blink_set_green = {
&message_blink_set_color_green,
NULL,
};
static const NotificationSequence sequence_blink_set_cyan = {
&message_blink_set_color_cyan,
NULL,
};
static void
lfrfid_read_callback(LFRFIDWorkerReadResult result, ProtocolId protocol, void* context) {
LfRfid* app = context;
uint32_t event = 0;
if(result == LFRFIDWorkerReadSenseStart) {
event = LfRfidEventReadSenseStart;
} else if(result == LFRFIDWorkerReadSenseEnd) {
event = LfRfidEventReadSenseEnd;
} else if(result == LFRFIDWorkerReadSenseCardStart) {
event = LfRfidEventReadSenseCardStart;
} else if(result == LFRFIDWorkerReadSenseCardEnd) {
event = LfRfidEventReadSenseCardEnd;
} else if(result == LFRFIDWorkerReadDone) {
event = LfRfidEventReadDone;
app->protocol_id_next = protocol;
} else if(result == LFRFIDWorkerReadStartASK) {
event = LfRfidEventReadStartASK;
} else if(result == LFRFIDWorkerReadStartPSK) {
event = LfRfidEventReadStartPSK;
} else {
return;
}
view_dispatcher_send_custom_event(app->view_dispatcher, event);
}
void lfrfid_scene_read_on_enter(void* context) {
LfRfid* app = context;
DOLPHIN_DEED(DolphinDeedRfidRead);
if(app->read_type == LFRFIDWorkerReadTypePSKOnly) {
lfrfid_view_read_set_read_mode(app->read_view, LfRfidReadPskOnly);
} else if(app->read_type == LFRFIDWorkerReadTypeASKOnly) {
lfrfid_view_read_set_read_mode(app->read_view, LfRfidReadAskOnly);
}
lfrfid_worker_start_thread(app->lfworker);
lfrfid_worker_read_start(app->lfworker, app->read_type, lfrfid_read_callback, app);
notification_message(app->notifications, &sequence_blink_start_cyan);
view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewRead);
}
bool lfrfid_scene_read_on_event(void* context, SceneManagerEvent event) {
LfRfid* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == LfRfidEventReadSenseStart) {
notification_message(app->notifications, &sequence_blink_set_yellow);
consumed = true;
} else if(event.event == LfRfidEventReadSenseCardStart) {
notification_message(app->notifications, &sequence_blink_set_green);
consumed = true;
} else if(
(event.event == LfRfidEventReadSenseEnd) ||
(event.event == LfRfidEventReadSenseCardEnd)) {
notification_message(app->notifications, &sequence_blink_set_cyan);
consumed = true;
} else if(event.event == LfRfidEventReadDone) {
app->protocol_id = app->protocol_id_next;
DOLPHIN_DEED(DolphinDeedRfidReadSuccess);
notification_message(app->notifications, &sequence_success);
furi_string_reset(app->file_name);
scene_manager_next_scene(app->scene_manager, LfRfidSceneReadSuccess);
consumed = true;
} else if(event.event == LfRfidEventReadStartPSK) {
if(app->read_type == LFRFIDWorkerReadTypeAuto) {
lfrfid_view_read_set_read_mode(app->read_view, LfRfidReadPsk);
}
consumed = true;
} else if(event.event == LfRfidEventReadStartASK) {
if(app->read_type == LFRFIDWorkerReadTypeAuto) {
lfrfid_view_read_set_read_mode(app->read_view, LfRfidReadAsk);
}
consumed = true;
}
}
return consumed;
}
void lfrfid_scene_read_on_exit(void* context) {
LfRfid* app = context;
notification_message(app->notifications, &sequence_blink_stop);
popup_reset(app->popup);
lfrfid_worker_stop(app->lfworker);
lfrfid_worker_stop_thread(app->lfworker);
}