2022-09-08 16:40:33 +00:00
|
|
|
#include "../lfrfid_i.h"
|
|
|
|
|
2024-03-29 03:32:43 +00:00
|
|
|
#define RAW_READ_TIME_MS (5000UL)
|
2022-09-08 16:40:33 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* string_file_name;
|
2022-09-08 16:40:33 +00:00
|
|
|
FuriTimer* timer;
|
|
|
|
bool is_psk;
|
|
|
|
bool error;
|
|
|
|
} LfRfidReadRawState;
|
|
|
|
|
|
|
|
static void lfrfid_read_callback(LFRFIDWorkerReadRawResult result, void* context) {
|
|
|
|
LfRfid* app = context;
|
|
|
|
|
|
|
|
if(result == LFRFIDWorkerReadRawFileError) {
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, LfRfidEventReadError);
|
|
|
|
} else if(result == LFRFIDWorkerReadRawOverrun) {
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, LfRfidEventReadOverrun);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void timer_callback(void* context) {
|
|
|
|
LfRfid* app = context;
|
|
|
|
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, LfRfidEventReadDone);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lfrfid_scene_raw_read_on_enter(void* context) {
|
|
|
|
LfRfid* app = context;
|
|
|
|
Popup* popup = app->popup;
|
|
|
|
|
2024-03-29 03:32:43 +00:00
|
|
|
popup_set_icon(popup, 0, 0, &I_NFC_dolphin_emulation_51x64);
|
|
|
|
popup_set_header(popup, "Reading ASK", 91, 16, AlignCenter, AlignTop);
|
|
|
|
popup_set_text(popup, "Don't move\nfor 5 sec.", 91, 29, AlignCenter, AlignTop);
|
2022-09-08 16:40:33 +00:00
|
|
|
|
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewPopup);
|
|
|
|
|
2024-03-29 03:32:43 +00:00
|
|
|
LfRfidReadRawState* state = malloc(sizeof(LfRfidReadRawState));
|
|
|
|
state->string_file_name = furi_string_alloc();
|
2022-09-08 16:40:33 +00:00
|
|
|
state->timer = furi_timer_alloc(timer_callback, FuriTimerTypeOnce, app);
|
2024-03-29 03:32:43 +00:00
|
|
|
|
|
|
|
scene_manager_set_scene_state(app->scene_manager, LfRfidSceneRawRead, (uint32_t)state);
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_printf(
|
2022-09-08 16:40:33 +00:00
|
|
|
state->string_file_name,
|
|
|
|
"%s/%s%s",
|
|
|
|
LFRFID_SD_FOLDER,
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_get_cstr(app->raw_file_name),
|
2022-09-08 16:40:33 +00:00
|
|
|
LFRFID_APP_RAW_ASK_EXTENSION);
|
2024-03-29 03:32:43 +00:00
|
|
|
|
|
|
|
lfrfid_make_app_folder(app);
|
|
|
|
|
|
|
|
lfrfid_worker_start_thread(app->lfworker);
|
2022-09-08 16:40:33 +00:00
|
|
|
lfrfid_worker_read_raw_start(
|
|
|
|
app->lfworker,
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_get_cstr(state->string_file_name),
|
2022-09-08 16:40:33 +00:00
|
|
|
LFRFIDWorkerReadTypeASKOnly,
|
|
|
|
lfrfid_read_callback,
|
|
|
|
app);
|
|
|
|
|
2024-03-29 03:32:43 +00:00
|
|
|
furi_timer_start(state->timer, RAW_READ_TIME_MS);
|
2022-09-08 16:40:33 +00:00
|
|
|
notification_message(app->notifications, &sequence_blink_start_cyan);
|
|
|
|
|
|
|
|
state->is_psk = false;
|
|
|
|
state->error = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool lfrfid_scene_raw_read_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
LfRfid* app = context;
|
|
|
|
Popup* popup = app->popup;
|
|
|
|
LfRfidReadRawState* state =
|
|
|
|
(LfRfidReadRawState*)scene_manager_get_scene_state(app->scene_manager, LfRfidSceneRawRead);
|
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
furi_assert(state);
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
2024-03-29 03:32:43 +00:00
|
|
|
if(event.event == LfRfidEventReadError || event.event == LfRfidEventReadOverrun) {
|
2022-09-08 16:40:33 +00:00
|
|
|
furi_timer_stop(state->timer);
|
2024-03-29 03:32:43 +00:00
|
|
|
|
|
|
|
popup_set_icon(popup, 83, 22, &I_WarningDolphinFlip_45x42);
|
|
|
|
popup_set_header(popup, "RAW Reading error!", 64, 0, AlignCenter, AlignTop);
|
|
|
|
popup_set_text(
|
|
|
|
popup, "This may be\ncaused by SD\ncard issues", 0, 13, AlignLeft, AlignTop);
|
|
|
|
|
|
|
|
notification_message(app->notifications, &sequence_blink_start_red);
|
|
|
|
state->error = true;
|
|
|
|
|
2022-09-08 16:40:33 +00:00
|
|
|
} else if(event.event == LfRfidEventReadDone) {
|
|
|
|
if(!state->error) {
|
|
|
|
if(state->is_psk) {
|
|
|
|
notification_message(app->notifications, &sequence_success);
|
|
|
|
scene_manager_next_scene(app->scene_manager, LfRfidSceneRawSuccess);
|
2024-03-29 03:32:43 +00:00
|
|
|
|
2022-09-08 16:40:33 +00:00
|
|
|
} else {
|
|
|
|
lfrfid_worker_stop(app->lfworker);
|
2024-03-29 03:32:43 +00:00
|
|
|
lfrfid_worker_stop_thread(app->lfworker);
|
|
|
|
|
|
|
|
state->is_psk = true;
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_printf(
|
2022-09-08 16:40:33 +00:00
|
|
|
state->string_file_name,
|
|
|
|
"%s/%s%s",
|
|
|
|
LFRFID_SD_FOLDER,
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_get_cstr(app->raw_file_name),
|
2022-09-08 16:40:33 +00:00
|
|
|
LFRFID_APP_RAW_PSK_EXTENSION);
|
2024-03-29 03:32:43 +00:00
|
|
|
|
|
|
|
lfrfid_worker_start_thread(app->lfworker);
|
2022-09-08 16:40:33 +00:00
|
|
|
lfrfid_worker_read_raw_start(
|
|
|
|
app->lfworker,
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_get_cstr(state->string_file_name),
|
2022-09-08 16:40:33 +00:00
|
|
|
LFRFIDWorkerReadTypePSKOnly,
|
|
|
|
lfrfid_read_callback,
|
|
|
|
app);
|
2024-03-29 03:32:43 +00:00
|
|
|
|
|
|
|
furi_timer_start(state->timer, RAW_READ_TIME_MS);
|
|
|
|
|
|
|
|
popup_set_header(popup, "Reading PSK", 91, 16, AlignCenter, AlignTop);
|
|
|
|
notification_message(app->notifications, &sequence_blink_start_yellow);
|
2022-09-08 16:40:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-03-29 03:32:43 +00:00
|
|
|
|
|
|
|
consumed = true;
|
2022-09-08 16:40:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lfrfid_scene_raw_read_on_exit(void* context) {
|
|
|
|
LfRfid* app = context;
|
|
|
|
LfRfidReadRawState* state =
|
|
|
|
(LfRfidReadRawState*)scene_manager_get_scene_state(app->scene_manager, LfRfidSceneRawRead);
|
|
|
|
|
|
|
|
lfrfid_worker_stop(app->lfworker);
|
|
|
|
lfrfid_worker_stop_thread(app->lfworker);
|
|
|
|
|
2024-03-29 03:32:43 +00:00
|
|
|
furi_timer_free(state->timer);
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(state->string_file_name);
|
2022-09-08 16:40:33 +00:00
|
|
|
free(state);
|
2024-03-29 03:32:43 +00:00
|
|
|
|
|
|
|
popup_reset(app->popup);
|
|
|
|
notification_message(app->notifications, &sequence_blink_stop);
|
2022-09-08 16:40:33 +00:00
|
|
|
}
|