mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-15 01:08:35 -07:00
Add magspoof
This commit is contained in:
30
applications/external/magspoof/scenes/mag_scene.c
vendored
Normal file
30
applications/external/magspoof/scenes/mag_scene.c
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "mag_scene.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const mag_on_enter_handlers[])(void*) = {
|
||||
#include "mag_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const mag_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "mag_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const mag_on_exit_handlers[])(void* context) = {
|
||||
#include "mag_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers mag_scene_handlers = {
|
||||
.on_enter_handlers = mag_on_enter_handlers,
|
||||
.on_event_handlers = mag_on_event_handlers,
|
||||
.on_exit_handlers = mag_on_exit_handlers,
|
||||
.scene_num = MagSceneNum,
|
||||
};
|
||||
29
applications/external/magspoof/scenes/mag_scene.h
vendored
Normal file
29
applications/external/magspoof/scenes/mag_scene.h
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) MagScene##id,
|
||||
typedef enum {
|
||||
#include "mag_scene_config.h"
|
||||
MagSceneNum,
|
||||
} MagScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers mag_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "mag_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) \
|
||||
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
|
||||
#include "mag_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||
#include "mag_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
40
applications/external/magspoof/scenes/mag_scene_about.c
vendored
Normal file
40
applications/external/magspoof/scenes/mag_scene_about.c
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "../mag_i.h"
|
||||
|
||||
void mag_scene_about_on_enter(void* context) {
|
||||
Mag* mag = context;
|
||||
Widget* widget = mag->widget;
|
||||
|
||||
FuriString* tmp_str;
|
||||
tmp_str = furi_string_alloc();
|
||||
|
||||
furi_string_cat_printf(tmp_str, "Version: %s\n", MAG_VERSION_APP);
|
||||
furi_string_cat_printf(tmp_str, "Developer: %s\n", MAG_DEVELOPER);
|
||||
furi_string_cat_printf(tmp_str, "GitHub: %s\n\n", MAG_GITHUB);
|
||||
|
||||
furi_string_cat_printf(
|
||||
tmp_str,
|
||||
"Unfinished port of Samy Kamkar's MagSpoof. Confer GitHub for updates; in the interim, use responsibly and at your own risk.");
|
||||
|
||||
// TODO: Add credits
|
||||
|
||||
widget_add_text_scroll_element(widget, 0, 0, 128, 64, furi_string_get_cstr(tmp_str));
|
||||
furi_string_free(tmp_str);
|
||||
|
||||
view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewWidget);
|
||||
}
|
||||
|
||||
bool mag_scene_about_on_event(void* context, SceneManagerEvent event) {
|
||||
Mag* mag = context;
|
||||
SceneManager* scene_manager = mag->scene_manager;
|
||||
bool consumed = false;
|
||||
|
||||
UNUSED(event);
|
||||
UNUSED(scene_manager);
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void mag_scene_about_on_exit(void* context) {
|
||||
Mag* mag = context;
|
||||
widget_reset(mag->widget);
|
||||
}
|
||||
15
applications/external/magspoof/scenes/mag_scene_config.h
vendored
Normal file
15
applications/external/magspoof/scenes/mag_scene_config.h
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
ADD_SCENE(mag, start, Start)
|
||||
ADD_SCENE(mag, about, About)
|
||||
ADD_SCENE(mag, emulate, Emulate)
|
||||
ADD_SCENE(mag, emulate_config, EmulateConfig)
|
||||
ADD_SCENE(mag, file_select, FileSelect)
|
||||
ADD_SCENE(mag, saved_menu, SavedMenu)
|
||||
ADD_SCENE(mag, saved_info, SavedInfo)
|
||||
ADD_SCENE(mag, input_name, InputName)
|
||||
ADD_SCENE(mag, input_value, InputValue)
|
||||
ADD_SCENE(mag, save_success, SaveSuccess)
|
||||
ADD_SCENE(mag, delete_success, DeleteSuccess)
|
||||
ADD_SCENE(mag, delete_confirm, DeleteConfirm)
|
||||
ADD_SCENE(mag, exit_confirm, ExitConfirm)
|
||||
ADD_SCENE(mag, under_construction, UnderConstruction)
|
||||
ADD_SCENE(mag, read, Read)
|
||||
49
applications/external/magspoof/scenes/mag_scene_delete_confirm.c
vendored
Normal file
49
applications/external/magspoof/scenes/mag_scene_delete_confirm.c
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "../mag_i.h"
|
||||
#include "../mag_device.h"
|
||||
|
||||
void mag_scene_delete_confirm_on_enter(void* context) {
|
||||
Mag* mag = context;
|
||||
Widget* widget = mag->widget;
|
||||
MagDevice* mag_dev = mag->mag_dev;
|
||||
|
||||
FuriString* tmp_str;
|
||||
tmp_str = furi_string_alloc();
|
||||
|
||||
furi_string_printf(tmp_str, "\e#Delete %s?\e#", mag_dev->dev_name);
|
||||
|
||||
//TODO: print concise summary of data on card? Would need to vary by card/track type
|
||||
|
||||
widget_add_text_box_element(
|
||||
widget, 0, 0, 128, 27, AlignCenter, AlignCenter, furi_string_get_cstr(tmp_str), true);
|
||||
widget_add_button_element(widget, GuiButtonTypeLeft, "Cancel", mag_widget_callback, mag);
|
||||
widget_add_button_element(widget, GuiButtonTypeRight, "Delete", mag_widget_callback, mag);
|
||||
|
||||
view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewWidget);
|
||||
|
||||
furi_string_free(tmp_str);
|
||||
}
|
||||
|
||||
bool mag_scene_delete_confirm_on_event(void* context, SceneManagerEvent event) {
|
||||
Mag* mag = context;
|
||||
SceneManager* scene_manager = mag->scene_manager;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GuiButtonTypeRight) {
|
||||
consumed = true;
|
||||
if(mag_device_delete(mag->mag_dev, true)) {
|
||||
scene_manager_next_scene(scene_manager, MagSceneDeleteSuccess);
|
||||
}
|
||||
} else if(event.event == GuiButtonTypeLeft) {
|
||||
consumed = true;
|
||||
scene_manager_previous_scene(scene_manager);
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void mag_scene_delete_confirm_on_exit(void* context) {
|
||||
Mag* mag = context;
|
||||
widget_reset(mag->widget);
|
||||
}
|
||||
39
applications/external/magspoof/scenes/mag_scene_delete_success.c
vendored
Normal file
39
applications/external/magspoof/scenes/mag_scene_delete_success.c
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "../mag_i.h"
|
||||
|
||||
void mag_scene_delete_success_on_enter(void* context) {
|
||||
Mag* mag = context;
|
||||
Popup* popup = mag->popup;
|
||||
|
||||
popup_set_icon(popup, 0, 2, &I_DolphinMafia_115x62);
|
||||
popup_set_header(popup, "Deleted", 83, 19, AlignLeft, AlignBottom);
|
||||
|
||||
popup_set_callback(popup, mag_popup_timeout_callback);
|
||||
popup_set_context(popup, mag);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_enable_timeout(popup);
|
||||
|
||||
view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewPopup);
|
||||
}
|
||||
|
||||
bool mag_scene_delete_success_on_event(void* context, SceneManagerEvent event) {
|
||||
Mag* mag = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == MagEventPopupClosed) {
|
||||
consumed = true;
|
||||
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
mag->scene_manager, MagSceneFileSelect);
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void mag_scene_delete_success_on_exit(void* context) {
|
||||
Mag* mag = context;
|
||||
Popup* popup = mag->popup;
|
||||
|
||||
popup_reset(popup);
|
||||
}
|
||||
93
applications/external/magspoof/scenes/mag_scene_emulate.c
vendored
Normal file
93
applications/external/magspoof/scenes/mag_scene_emulate.c
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "../mag_i.h"
|
||||
#include "../helpers/mag_helpers.h"
|
||||
|
||||
#define TAG "MagSceneEmulate"
|
||||
|
||||
void cat_trackstr(FuriString* str, uint8_t calls, uint8_t i, FuriString* trackstr) {
|
||||
furi_string_cat_printf(
|
||||
str,
|
||||
"%sTrack %d:%s%s\n",
|
||||
(calls == 0) ? "" : "\n", // if first line, don't prepend a "\n"
|
||||
(i + 1),
|
||||
furi_string_empty(trackstr) ? " " : "\n",
|
||||
furi_string_empty(trackstr) ? "< empty >" : furi_string_get_cstr(trackstr));
|
||||
}
|
||||
|
||||
void mag_scene_emulate_on_enter(void* context) {
|
||||
Mag* mag = context;
|
||||
Widget* widget = mag->widget;
|
||||
|
||||
FuriString* tmp_str;
|
||||
tmp_str = furi_string_alloc();
|
||||
|
||||
// Use strlcpy instead perhaps, to truncate to screen width, then add ellipses if needed?
|
||||
furi_string_printf(tmp_str, "%s\r\n", mag->mag_dev->dev_name);
|
||||
|
||||
// TODO: Display other relevant config settings (namely RFID vs GPIO)?
|
||||
|
||||
widget_add_icon_element(widget, 1, 1, &I_mag_file_10px);
|
||||
widget_add_string_element(
|
||||
widget, 13, 2, AlignLeft, AlignTop, FontPrimary, furi_string_get_cstr(tmp_str));
|
||||
furi_string_reset(tmp_str);
|
||||
|
||||
FURI_LOG_D(TAG, "%d", mag->setting->reverse);
|
||||
|
||||
// print relevant data
|
||||
uint8_t cat_count = 0;
|
||||
for(uint8_t i = 0; i < MAG_DEV_TRACKS; i++) {
|
||||
FuriString* trackstr = mag->mag_dev->dev_data.track[i].str;
|
||||
|
||||
// still messy / dumb way to do this, but slightly cleaner than before.
|
||||
// will clean up more later
|
||||
switch(mag->setting->track) {
|
||||
case MagTrackStateOne:
|
||||
if(i == 0) cat_trackstr(tmp_str, cat_count++, i, trackstr);
|
||||
break;
|
||||
case MagTrackStateTwo:
|
||||
if(i == 1) cat_trackstr(tmp_str, cat_count++, i, trackstr);
|
||||
break;
|
||||
case MagTrackStateThree:
|
||||
if(i == 2) cat_trackstr(tmp_str, cat_count++, i, trackstr);
|
||||
break;
|
||||
case MagTrackStateOneAndTwo:
|
||||
if((i == 0) | (i == 1)) cat_trackstr(tmp_str, cat_count++, i, trackstr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
widget_add_text_scroll_element(widget, 0, 15, 128, 49, furi_string_get_cstr(tmp_str));
|
||||
|
||||
widget_add_button_element(widget, GuiButtonTypeLeft, "Config", mag_widget_callback, mag);
|
||||
widget_add_button_element(widget, GuiButtonTypeRight, "Send", mag_widget_callback, mag);
|
||||
view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewWidget);
|
||||
furi_string_free(tmp_str);
|
||||
}
|
||||
|
||||
bool mag_scene_emulate_on_event(void* context, SceneManagerEvent event) {
|
||||
Mag* mag = context;
|
||||
SceneManager* scene_manager = mag->scene_manager;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case GuiButtonTypeLeft:
|
||||
consumed = true;
|
||||
scene_manager_next_scene(scene_manager, MagSceneEmulateConfig);
|
||||
break;
|
||||
case GuiButtonTypeRight:
|
||||
consumed = true;
|
||||
notification_message(mag->notifications, &sequence_blink_start_cyan);
|
||||
mag_spoof(mag);
|
||||
notification_message(mag->notifications, &sequence_blink_stop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void mag_scene_emulate_on_exit(void* context) {
|
||||
Mag* mag = context;
|
||||
notification_message(mag->notifications, &sequence_blink_stop);
|
||||
widget_reset(mag->widget);
|
||||
}
|
||||
264
applications/external/magspoof/scenes/mag_scene_emulate_config.c
vendored
Normal file
264
applications/external/magspoof/scenes/mag_scene_emulate_config.c
vendored
Normal file
@@ -0,0 +1,264 @@
|
||||
#include "../mag_i.h"
|
||||
|
||||
#define TAG "MagSceneEmulateConfig"
|
||||
|
||||
enum MagSettingIndex {
|
||||
MagSettingIndexTx,
|
||||
MagSettingIndexTrack,
|
||||
MagSettingIndexReverse,
|
||||
MagSettingIndexClock,
|
||||
MagSettingIndexInterpacket,
|
||||
};
|
||||
|
||||
#define TX_COUNT 7
|
||||
const char* const tx_text[TX_COUNT] = {
|
||||
"RFID",
|
||||
"GPIO",
|
||||
"Piezo",
|
||||
"LF + P",
|
||||
"NFC",
|
||||
"434MHz",
|
||||
"868MHz",
|
||||
};
|
||||
const uint32_t tx_value[TX_COUNT] = {
|
||||
MagTxStateRFID,
|
||||
MagTxStateGPIO,
|
||||
MagTxStatePiezo,
|
||||
MagTxStateLF_P,
|
||||
MagTxStateNFC,
|
||||
MagTxCC1101_434,
|
||||
MagTxCC1101_868,
|
||||
};
|
||||
|
||||
#define TRACK_COUNT 4
|
||||
const char* const track_text[TRACK_COUNT] = {
|
||||
"1 + 2",
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
};
|
||||
const uint32_t track_value[TRACK_COUNT] = {
|
||||
MagTrackStateOneAndTwo,
|
||||
MagTrackStateOne,
|
||||
MagTrackStateTwo,
|
||||
MagTrackStateThree,
|
||||
};
|
||||
|
||||
#define REVERSE_COUNT 2
|
||||
const char* const reverse_text[REVERSE_COUNT] = {
|
||||
"OFF",
|
||||
"ON",
|
||||
};
|
||||
const uint32_t reverse_value[REVERSE_COUNT] = {
|
||||
MagReverseStateOff,
|
||||
MagReverseStateOn,
|
||||
};
|
||||
|
||||
#define CLOCK_COUNT 15
|
||||
const char* const clock_text[CLOCK_COUNT] = {
|
||||
"200us",
|
||||
"220us",
|
||||
"240us",
|
||||
"250us",
|
||||
"260us",
|
||||
"280us",
|
||||
"300us",
|
||||
"325us",
|
||||
"350us",
|
||||
"375us",
|
||||
"400us",
|
||||
"450us",
|
||||
"500us",
|
||||
"600us",
|
||||
"700us",
|
||||
};
|
||||
const uint32_t clock_value[CLOCK_COUNT] = {
|
||||
200,
|
||||
220,
|
||||
240,
|
||||
250,
|
||||
260,
|
||||
280,
|
||||
300,
|
||||
325,
|
||||
350,
|
||||
375,
|
||||
400,
|
||||
450,
|
||||
500,
|
||||
600,
|
||||
700,
|
||||
};
|
||||
|
||||
#define INTERPACKET_COUNT 13
|
||||
const char* const interpacket_text[INTERPACKET_COUNT] = {
|
||||
"0us",
|
||||
"2us",
|
||||
"4us",
|
||||
"6us",
|
||||
"8us",
|
||||
"10us",
|
||||
"12us",
|
||||
"14us",
|
||||
"16us",
|
||||
"18us",
|
||||
"20us",
|
||||
"25us",
|
||||
"30us",
|
||||
};
|
||||
const uint32_t interpacket_value[INTERPACKET_COUNT] = {
|
||||
0,
|
||||
2,
|
||||
4,
|
||||
6,
|
||||
8,
|
||||
10,
|
||||
12,
|
||||
14,
|
||||
16,
|
||||
18,
|
||||
20,
|
||||
25,
|
||||
30,
|
||||
};
|
||||
|
||||
static void mag_scene_emulate_config_set_tx(VariableItem* item) {
|
||||
Mag* mag = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, tx_text[index]);
|
||||
|
||||
mag->setting->tx = tx_value[index];
|
||||
};
|
||||
|
||||
static void mag_scene_emulate_config_set_track(VariableItem* item) {
|
||||
Mag* mag = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
if(mag->setting->reverse == MagReverseStateOff) {
|
||||
variable_item_set_current_value_text(item, track_text[index]);
|
||||
mag->setting->track = track_value[index];
|
||||
} else if(mag->setting->reverse == MagReverseStateOn) {
|
||||
variable_item_set_current_value_index(
|
||||
item, value_index_uint32(MagTrackStateOneAndTwo, track_value, TRACK_COUNT));
|
||||
}
|
||||
|
||||
// TODO: Check there is data in selected track?
|
||||
// Only display track options with data?
|
||||
};
|
||||
|
||||
static void mag_scene_emulate_config_set_reverse(VariableItem* item) {
|
||||
Mag* mag = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
if(mag->setting->track == MagTrackStateOneAndTwo) {
|
||||
// only allow reverse track to be set when playing both 1 and 2
|
||||
variable_item_set_current_value_text(item, reverse_text[index]);
|
||||
mag->setting->reverse = reverse_value[index];
|
||||
//FURI_LOG_D(TAG, "%s", reverse_text[index]);
|
||||
//FURI_LOG_D(TAG, "%d", mag->setting->reverse);
|
||||
} else {
|
||||
variable_item_set_current_value_index(
|
||||
item, value_index_uint32(MagReverseStateOff, reverse_value, REVERSE_COUNT));
|
||||
}
|
||||
};
|
||||
|
||||
static void mag_scene_emulate_config_set_clock(VariableItem* item) {
|
||||
Mag* mag = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, clock_text[index]);
|
||||
|
||||
mag->setting->us_clock = clock_value[index];
|
||||
};
|
||||
|
||||
static void mag_scene_emulate_config_set_interpacket(VariableItem* item) {
|
||||
Mag* mag = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, interpacket_text[index]);
|
||||
|
||||
mag->setting->us_interpacket = interpacket_value[index];
|
||||
};
|
||||
|
||||
void mag_scene_emulate_config_on_enter(void* context) {
|
||||
// TODO: retrieve current values from struct, rather than setting to default on setup
|
||||
|
||||
Mag* mag = context;
|
||||
VariableItem* item;
|
||||
uint8_t value_index;
|
||||
|
||||
// TX
|
||||
item = variable_item_list_add(
|
||||
mag->variable_item_list, "TX via:", TX_COUNT, mag_scene_emulate_config_set_tx, mag);
|
||||
value_index = value_index_uint32(mag->setting->tx, tx_value, TX_COUNT);
|
||||
scene_manager_set_scene_state(mag->scene_manager, MagSceneEmulateConfig, (uint32_t)item);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, tx_text[value_index]);
|
||||
|
||||
// Track
|
||||
item = variable_item_list_add(
|
||||
mag->variable_item_list, "Track:", TRACK_COUNT, mag_scene_emulate_config_set_track, mag);
|
||||
value_index = value_index_uint32(mag->setting->track, track_value, TRACK_COUNT);
|
||||
scene_manager_set_scene_state(mag->scene_manager, MagSceneEmulateConfig, (uint32_t)item);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, track_text[value_index]);
|
||||
|
||||
// Reverse
|
||||
//FURI_LOG_D(TAG, "%d", mag->setting->reverse);
|
||||
item = variable_item_list_add(
|
||||
mag->variable_item_list,
|
||||
"Reverse:",
|
||||
REVERSE_COUNT,
|
||||
mag_scene_emulate_config_set_reverse,
|
||||
mag);
|
||||
value_index = value_index_uint32(mag->setting->reverse, reverse_value, REVERSE_COUNT);
|
||||
scene_manager_set_scene_state(mag->scene_manager, MagSceneEmulateConfig, (uint32_t)item);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, reverse_text[value_index]);
|
||||
|
||||
// Clock
|
||||
item = variable_item_list_add(
|
||||
mag->variable_item_list, "Clock:", CLOCK_COUNT, mag_scene_emulate_config_set_clock, mag);
|
||||
value_index = value_index_uint32(mag->setting->us_clock, clock_value, CLOCK_COUNT);
|
||||
scene_manager_set_scene_state(mag->scene_manager, MagSceneEmulateConfig, (uint32_t)item);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, clock_text[value_index]);
|
||||
|
||||
// Interpacket
|
||||
/*
|
||||
item = variable_item_list_add(
|
||||
mag->variable_item_list,
|
||||
"Interpacket:",
|
||||
INTERPACKET_COUNT,
|
||||
mag_scene_emulate_config_set_interpacket,
|
||||
mag);
|
||||
value_index =
|
||||
value_index_uint32(mag->setting->us_interpacket, interpacket_value, INTERPACKET_COUNT);
|
||||
scene_manager_set_scene_state(mag->scene_manager, MagSceneEmulateConfig, (uint32_t)item);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, interpacket_text[value_index]);*/
|
||||
UNUSED(mag_scene_emulate_config_set_interpacket);
|
||||
|
||||
view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewVariableItemList);
|
||||
}
|
||||
|
||||
bool mag_scene_emulate_config_on_event(void* context, SceneManagerEvent event) {
|
||||
Mag* mag = context;
|
||||
SceneManager* scene_manager = mag->scene_manager;
|
||||
bool consumed = false;
|
||||
|
||||
UNUSED(mag);
|
||||
UNUSED(scene_manager);
|
||||
UNUSED(event);
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void mag_scene_emulate_config_on_exit(void* context) {
|
||||
Mag* mag = context;
|
||||
variable_item_list_set_selected_item(mag->variable_item_list, 0);
|
||||
variable_item_list_reset(mag->variable_item_list);
|
||||
// mag_last_settings_save?
|
||||
// scene_manager_set_scene_state? Using subghz_scene_reciever_config as framework/inspo
|
||||
}
|
||||
20
applications/external/magspoof/scenes/mag_scene_exit_confirm.c
vendored
Normal file
20
applications/external/magspoof/scenes/mag_scene_exit_confirm.c
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "../mag_i.h"
|
||||
|
||||
void mag_scene_exit_confirm_on_enter(void* context) {
|
||||
Mag* mag = context;
|
||||
UNUSED(mag);
|
||||
}
|
||||
|
||||
bool mag_scene_exit_confirm_on_event(void* context, SceneManagerEvent event) {
|
||||
Mag* mag = context;
|
||||
UNUSED(mag);
|
||||
UNUSED(event);
|
||||
bool consumed = false;
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void mag_scene_exit_confirm_on_exit(void* context) {
|
||||
Mag* mag = context;
|
||||
UNUSED(mag);
|
||||
}
|
||||
24
applications/external/magspoof/scenes/mag_scene_file_select.c
vendored
Normal file
24
applications/external/magspoof/scenes/mag_scene_file_select.c
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "../mag_i.h"
|
||||
#include "../mag_device.h"
|
||||
|
||||
void mag_scene_file_select_on_enter(void* context) {
|
||||
Mag* mag = context;
|
||||
//UNUSED(mag);
|
||||
mag_device_set_loading_callback(mag->mag_dev, mag_show_loading_popup, mag);
|
||||
if(mag_file_select(mag->mag_dev)) {
|
||||
scene_manager_next_scene(mag->scene_manager, MagSceneSavedMenu);
|
||||
} else {
|
||||
scene_manager_search_and_switch_to_previous_scene(mag->scene_manager, MagSceneStart);
|
||||
}
|
||||
mag_device_set_loading_callback(mag->mag_dev, NULL, mag);
|
||||
}
|
||||
|
||||
bool mag_scene_file_select_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
UNUSED(event);
|
||||
return false;
|
||||
}
|
||||
|
||||
void mag_scene_file_select_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
}
|
||||
82
applications/external/magspoof/scenes/mag_scene_input_name.c
vendored
Normal file
82
applications/external/magspoof/scenes/mag_scene_input_name.c
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
#include <lib/toolbox/random_name.h>
|
||||
#include "../mag_i.h"
|
||||
|
||||
void mag_scene_input_name_on_enter(void* context) {
|
||||
Mag* mag = context;
|
||||
TextInput* text_input = mag->text_input;
|
||||
FuriString* folder_path;
|
||||
folder_path = furi_string_alloc();
|
||||
|
||||
//TODO: compatible types / etc
|
||||
//bool name_is_empty = furi_string_empty(mag->mag_dev->dev_name);
|
||||
bool name_is_empty = true;
|
||||
|
||||
if(name_is_empty) {
|
||||
furi_string_set(mag->file_path, MAG_APP_FOLDER);
|
||||
set_random_name(mag->text_store, MAG_TEXT_STORE_SIZE);
|
||||
furi_string_set(folder_path, MAG_APP_FOLDER);
|
||||
} else {
|
||||
// TODO: compatible types etc
|
||||
//mag_text_store_set(mag, "%s", furi_string_get_cstr(mag->mag_dev->dev_name));
|
||||
path_extract_dirname(furi_string_get_cstr(mag->file_path), folder_path);
|
||||
}
|
||||
|
||||
text_input_set_header_text(text_input, "Name the card");
|
||||
text_input_set_result_callback(
|
||||
text_input,
|
||||
mag_text_input_callback,
|
||||
mag,
|
||||
mag->text_store,
|
||||
MAG_DEV_NAME_MAX_LEN,
|
||||
name_is_empty);
|
||||
|
||||
FURI_LOG_I("", "%s %s", furi_string_get_cstr(folder_path), mag->text_store);
|
||||
|
||||
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
||||
furi_string_get_cstr(folder_path),
|
||||
MAG_APP_EXTENSION,
|
||||
furi_string_get_cstr(mag->file_name));
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
|
||||
furi_string_free(folder_path);
|
||||
|
||||
view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewTextInput);
|
||||
}
|
||||
|
||||
bool mag_scene_input_name_on_event(void* context, SceneManagerEvent event) {
|
||||
Mag* mag = context;
|
||||
SceneManager* scene_manager = mag->scene_manager;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == MagEventNext) {
|
||||
consumed = true;
|
||||
//if(!furi_string_empty(mag->file_name)) {
|
||||
// mag_delete_key(mag);
|
||||
//}
|
||||
|
||||
furi_string_set(mag->file_name, mag->text_store);
|
||||
|
||||
if(mag_device_save(mag->mag_dev, furi_string_get_cstr(mag->file_name))) {
|
||||
scene_manager_next_scene(scene_manager, MagSceneSaveSuccess);
|
||||
} else {
|
||||
//scene_manager_search_and_switch_to_previous_scene(
|
||||
// scene_manager, MagSceneReadKeyMenu);
|
||||
// TODO: Replace with appropriate scene! No read scene prior if adding manually...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void mag_scene_input_name_on_exit(void* context) {
|
||||
Mag* mag = context;
|
||||
TextInput* text_input = mag->text_input;
|
||||
|
||||
void* validator_context = text_input_get_validator_callback_context(text_input);
|
||||
text_input_set_validator(text_input, NULL, NULL);
|
||||
validator_is_file_free((ValidatorIsFile*)validator_context);
|
||||
|
||||
text_input_reset(text_input);
|
||||
}
|
||||
37
applications/external/magspoof/scenes/mag_scene_input_value.c
vendored
Normal file
37
applications/external/magspoof/scenes/mag_scene_input_value.c
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "../mag_i.h"
|
||||
|
||||
void mag_scene_input_value_on_enter(void* context) {
|
||||
Mag* mag = context;
|
||||
Mag_TextInput* mag_text_input = mag->mag_text_input;
|
||||
|
||||
// TODO: retrieve stored/existing data if editing rather than adding anew?
|
||||
mag_text_store_set(mag, furi_string_get_cstr(mag->mag_dev->dev_data.track[1].str));
|
||||
|
||||
mag_text_input_set_header_text(mag_text_input, "Enter track data (WIP)");
|
||||
mag_text_input_set_result_callback(
|
||||
mag_text_input, mag_text_input_callback, mag, mag->text_store, MAG_TEXT_STORE_SIZE, true);
|
||||
|
||||
view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewMagTextInput);
|
||||
}
|
||||
|
||||
bool mag_scene_input_value_on_event(void* context, SceneManagerEvent event) {
|
||||
Mag* mag = context;
|
||||
SceneManager* scene_manager = mag->scene_manager;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == MagEventNext) {
|
||||
consumed = true;
|
||||
|
||||
furi_string_set(mag->mag_dev->dev_data.track[1].str, mag->text_store);
|
||||
scene_manager_next_scene(scene_manager, MagSceneInputName);
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void mag_scene_input_value_on_exit(void* context) {
|
||||
Mag* mag = context;
|
||||
UNUSED(mag);
|
||||
}
|
||||
185
applications/external/magspoof/scenes/mag_scene_read.c
vendored
Normal file
185
applications/external/magspoof/scenes/mag_scene_read.c
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
// Creator: Hummus@FlipperGang
|
||||
|
||||
#include "../mag_i.h"
|
||||
#include "../helpers/mag_helpers.h"
|
||||
|
||||
#include "mag_scene_read.h"
|
||||
|
||||
#define TAG "MagSceneRead"
|
||||
|
||||
void uart_callback(UartIrqEvent event, uint8_t data, void* context) {
|
||||
Mag* mag = context;
|
||||
if(event == UartIrqEventRXNE) {
|
||||
furi_stream_buffer_send(mag->uart_rx_stream, &data, 1, 0);
|
||||
furi_thread_flags_set(furi_thread_get_id(mag->uart_rx_thread), WorkerEvtRxDone);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t uart_worker(void* context) {
|
||||
Mag* mag = context;
|
||||
mag->uart_rx_stream = furi_stream_buffer_alloc(UART_RX_BUF_SIZE, 1);
|
||||
mag->uart_text_box_store_strlen = 0;
|
||||
|
||||
while(1) {
|
||||
uint32_t events =
|
||||
furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever);
|
||||
// furi_check((events & FuriFlagError) == 0);
|
||||
|
||||
if(events & WorkerEvtStop) break;
|
||||
if(events & WorkerEvtRxDone) {
|
||||
FURI_LOG_D(TAG, "WorkerEvtRxDone");
|
||||
// notification_message(mag->notifications, &sequence_success);
|
||||
size_t len = furi_stream_buffer_receive(
|
||||
mag->uart_rx_stream, mag->uart_rx_buf, UART_RX_BUF_SIZE, 200);
|
||||
FURI_LOG_D(TAG, "UART RX len: %d", len);
|
||||
|
||||
if(len > 0) {
|
||||
// If text box store gets too big, then truncate it
|
||||
mag->uart_text_box_store_strlen += len;
|
||||
|
||||
if(mag->uart_text_box_store_strlen >= UART_TERMINAL_TEXT_BOX_STORE_SIZE - 1) {
|
||||
furi_string_right(
|
||||
mag->uart_text_box_store, mag->uart_text_box_store_strlen / 2);
|
||||
mag->uart_text_box_store_strlen =
|
||||
furi_string_size(mag->uart_text_box_store) + len;
|
||||
}
|
||||
|
||||
// Add '\0' to the end of the string, and then add the new data
|
||||
mag->uart_rx_buf[len] = '\0';
|
||||
furi_string_cat_printf(mag->uart_text_box_store, "%s", mag->uart_rx_buf);
|
||||
|
||||
FURI_LOG_D(TAG, "UART RX buf: %*.s", len, mag->uart_rx_buf);
|
||||
FURI_LOG_D(
|
||||
TAG, "UART RX store: %s", furi_string_get_cstr(mag->uart_text_box_store));
|
||||
}
|
||||
|
||||
FURI_LOG_D(TAG, "UARTEventRxData");
|
||||
|
||||
view_dispatcher_send_custom_event(mag->view_dispatcher, UARTEventRxData);
|
||||
}
|
||||
}
|
||||
|
||||
furi_stream_buffer_free(mag->uart_rx_stream);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void update_widgets(Mag* mag) {
|
||||
// Clear widget from all elements
|
||||
widget_reset(mag->widget);
|
||||
|
||||
// Titlebar
|
||||
widget_add_icon_element(mag->widget, 38, -1, &I_mag_file_10px);
|
||||
widget_add_string_element(mag->widget, 64, 0, AlignCenter, AlignTop, FontPrimary, "READ");
|
||||
widget_add_icon_element(mag->widget, 81, -1, &I_mag_file_10px);
|
||||
|
||||
// Text box
|
||||
widget_add_text_scroll_element(
|
||||
mag->widget, 0, 10, 128, 40, furi_string_get_cstr(mag->uart_text_box_store));
|
||||
|
||||
// Buttons
|
||||
widget_add_button_element(mag->widget, GuiButtonTypeLeft, "Clear", mag_widget_callback, mag);
|
||||
widget_add_button_element(mag->widget, GuiButtonTypeRight, "Parse", mag_widget_callback, mag);
|
||||
}
|
||||
|
||||
void mag_scene_read_on_enter(void* context) {
|
||||
Mag* mag = context;
|
||||
FuriString* message = furi_string_alloc();
|
||||
furi_string_printf(message, "Please swipe a card!\n");
|
||||
mag->uart_text_box_store = message;
|
||||
|
||||
view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewWidget);
|
||||
|
||||
update_widgets(mag);
|
||||
|
||||
// Initialize UART
|
||||
// furi_hal_console_disable();
|
||||
furi_hal_uart_deinit(FuriHalUartIdUSART1);
|
||||
furi_hal_uart_init(FuriHalUartIdUSART1, 9600);
|
||||
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, uart_callback, mag);
|
||||
FURI_LOG_D(TAG, "UART initialized");
|
||||
|
||||
mag->uart_rx_thread = furi_thread_alloc();
|
||||
furi_thread_set_name(mag->uart_rx_thread, "UartRx");
|
||||
furi_thread_set_stack_size(mag->uart_rx_thread, 1024);
|
||||
furi_thread_set_context(mag->uart_rx_thread, mag);
|
||||
furi_thread_set_callback(mag->uart_rx_thread, uart_worker);
|
||||
|
||||
furi_thread_start(mag->uart_rx_thread);
|
||||
FURI_LOG_D(TAG, "UART worker started");
|
||||
}
|
||||
|
||||
bool mag_scene_read_on_event(void* context, SceneManagerEvent event) {
|
||||
Mag* mag = context;
|
||||
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
FURI_LOG_D(TAG, "Custom event: %ld", event.event);
|
||||
|
||||
switch(event.event) {
|
||||
case GuiButtonTypeLeft: // Clear
|
||||
consumed = true;
|
||||
// Clear text box store
|
||||
furi_string_reset(mag->uart_text_box_store);
|
||||
mag->uart_text_box_store_strlen = 0;
|
||||
break;
|
||||
|
||||
case GuiButtonTypeRight: // Parse
|
||||
consumed = true;
|
||||
FURI_LOG_D(TAG, "Trying to parse");
|
||||
MagDevice* mag_dev = mag->mag_dev;
|
||||
|
||||
bool res = mag_device_parse_card_string(mag_dev, mag->uart_text_box_store);
|
||||
furi_string_reset(mag->uart_text_box_store);
|
||||
if(res) {
|
||||
notification_message(mag->notifications, &sequence_success);
|
||||
|
||||
furi_string_printf(
|
||||
mag->uart_text_box_store,
|
||||
"Track 1: %.*s\nTrack 2: %.*s\nTrack 3: %.*s",
|
||||
mag_dev->dev_data.track[0].len,
|
||||
furi_string_get_cstr(mag_dev->dev_data.track[0].str),
|
||||
mag_dev->dev_data.track[1].len,
|
||||
furi_string_get_cstr(mag_dev->dev_data.track[1].str),
|
||||
mag_dev->dev_data.track[2].len,
|
||||
furi_string_get_cstr(mag_dev->dev_data.track[2].str));
|
||||
|
||||
// Switch to saved menu scene
|
||||
scene_manager_next_scene(mag->scene_manager, MagSceneSavedMenu);
|
||||
|
||||
} else {
|
||||
furi_string_printf(mag->uart_text_box_store, "Failed to parse! Try again\n");
|
||||
notification_message(mag->notifications, &sequence_error);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
update_widgets(mag);
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void mag_scene_read_on_exit(void* context) {
|
||||
Mag* mag = context;
|
||||
// notification_message(mag->notifications, &sequence_blink_stop);
|
||||
widget_reset(mag->widget);
|
||||
// view_dispatcher_remove_view(mag->view_dispatcher, MagViewWidget);
|
||||
|
||||
// Stop UART worker
|
||||
FURI_LOG_D(TAG, "Stopping UART worker");
|
||||
furi_thread_flags_set(furi_thread_get_id(mag->uart_rx_thread), WorkerEvtStop);
|
||||
furi_thread_join(mag->uart_rx_thread);
|
||||
furi_thread_free(mag->uart_rx_thread);
|
||||
FURI_LOG_D(TAG, "UART worker stopped");
|
||||
|
||||
furi_string_free(mag->uart_text_box_store);
|
||||
|
||||
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
|
||||
furi_hal_uart_deinit(FuriHalUartIdUSART1);
|
||||
// furi_hal_console_enable();
|
||||
|
||||
notification_message(mag->notifications, &sequence_blink_stop);
|
||||
}
|
||||
20
applications/external/magspoof/scenes/mag_scene_read.h
vendored
Normal file
20
applications/external/magspoof/scenes/mag_scene_read.h
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/modules/text_box.h>
|
||||
|
||||
#define UART_RX_BUF_SIZE (320)
|
||||
#define UART_TERMINAL_TEXT_BOX_STORE_SIZE (4096)
|
||||
#define UART_TERMINAL_TEXT_INPUT_STORE_SIZE (512)
|
||||
#define UART_CH (FuriHalUartIdUSART1)
|
||||
#define UART_BAUDRATE (9600)
|
||||
|
||||
typedef enum {
|
||||
WorkerEvtStop = (1 << 0),
|
||||
WorkerEvtRxDone = (1 << 1),
|
||||
} WorkerEvtFlags;
|
||||
|
||||
typedef enum {
|
||||
UARTEventRxData = 100,
|
||||
} UARTEvents;
|
||||
|
||||
#define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone)
|
||||
43
applications/external/magspoof/scenes/mag_scene_save_success.c
vendored
Normal file
43
applications/external/magspoof/scenes/mag_scene_save_success.c
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "../mag_i.h"
|
||||
|
||||
void mag_scene_save_success_on_enter(void* context) {
|
||||
Mag* mag = context;
|
||||
Popup* popup = mag->popup;
|
||||
|
||||
// Clear state of data enter scene
|
||||
//scene_manager_set_scene_state(mag->scene_manager, LfRfidSceneSaveData, 0);
|
||||
mag_text_store_clear(mag);
|
||||
|
||||
popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59);
|
||||
popup_set_header(popup, "Saved!", 5, 7, AlignLeft, AlignTop);
|
||||
popup_set_context(popup, mag);
|
||||
popup_set_callback(popup, mag_popup_timeout_callback);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_enable_timeout(popup);
|
||||
|
||||
view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewPopup);
|
||||
}
|
||||
|
||||
bool mag_scene_save_success_on_event(void* context, SceneManagerEvent event) {
|
||||
Mag* mag = context;
|
||||
bool consumed = false;
|
||||
|
||||
if((event.type == SceneManagerEventTypeBack) ||
|
||||
((event.type == SceneManagerEventTypeCustom) && (event.event == MagEventPopupClosed))) {
|
||||
bool result =
|
||||
scene_manager_search_and_switch_to_previous_scene(mag->scene_manager, MagSceneStart);
|
||||
if(!result) {
|
||||
scene_manager_search_and_switch_to_another_scene(
|
||||
mag->scene_manager, MagSceneFileSelect);
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void mag_scene_save_success_on_exit(void* context) {
|
||||
Mag* mag = context;
|
||||
|
||||
popup_reset(mag->popup);
|
||||
}
|
||||
50
applications/external/magspoof/scenes/mag_scene_saved_info.c
vendored
Normal file
50
applications/external/magspoof/scenes/mag_scene_saved_info.c
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "../mag_i.h"
|
||||
|
||||
void mag_scene_saved_info_on_enter(void* context) {
|
||||
Mag* mag = context;
|
||||
Widget* widget = mag->widget;
|
||||
|
||||
FuriString* tmp_str;
|
||||
tmp_str = furi_string_alloc();
|
||||
|
||||
// Use strlcpy instead perhaps, to truncate to screen width, then add ellipses if needed?
|
||||
furi_string_printf(tmp_str, "%s\r\n", mag->mag_dev->dev_name);
|
||||
|
||||
widget_add_icon_element(widget, 1, 1, &I_mag_file_10px);
|
||||
widget_add_string_element(
|
||||
widget, 13, 2, AlignLeft, AlignTop, FontPrimary, furi_string_get_cstr(tmp_str));
|
||||
furi_string_reset(tmp_str);
|
||||
|
||||
for(uint8_t i = 0; i < MAG_DEV_TRACKS; i++) {
|
||||
FuriString* trackstr = mag->mag_dev->dev_data.track[i].str;
|
||||
|
||||
furi_string_cat_printf(
|
||||
tmp_str,
|
||||
"Track %d:%s%s%s",
|
||||
(i + 1),
|
||||
furi_string_empty(trackstr) ? " " : "\n",
|
||||
furi_string_empty(trackstr) ? "< empty >" : furi_string_get_cstr(trackstr),
|
||||
(i + 1 == MAG_DEV_TRACKS) ? "" : "\n\n");
|
||||
}
|
||||
|
||||
widget_add_text_scroll_element(widget, 0, 15, 128, 49, furi_string_get_cstr(tmp_str));
|
||||
|
||||
view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewWidget);
|
||||
furi_string_free(tmp_str);
|
||||
}
|
||||
|
||||
bool mag_scene_saved_info_on_event(void* context, SceneManagerEvent event) {
|
||||
Mag* mag = context;
|
||||
SceneManager* scene_manager = mag->scene_manager;
|
||||
bool consumed = false;
|
||||
|
||||
UNUSED(event);
|
||||
UNUSED(scene_manager);
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void mag_scene_saved_info_on_exit(void* context) {
|
||||
Mag* mag = context;
|
||||
widget_reset(mag->widget);
|
||||
}
|
||||
83
applications/external/magspoof/scenes/mag_scene_saved_menu.c
vendored
Normal file
83
applications/external/magspoof/scenes/mag_scene_saved_menu.c
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
#include "../mag_i.h"
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexEmulate,
|
||||
//SubmenuIndexEdit,
|
||||
SubmenuIndexDelete,
|
||||
SubmenuIndexInfo,
|
||||
};
|
||||
|
||||
void mag_scene_saved_menu_submenu_callback(void* context, uint32_t index) {
|
||||
Mag* mag = context;
|
||||
|
||||
view_dispatcher_send_custom_event(mag->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void mag_scene_saved_menu_on_enter(void* context) {
|
||||
Mag* mag = context;
|
||||
Submenu* submenu = mag->submenu;
|
||||
|
||||
notification_message(mag->notifications, &sequence_blink_cyan_10);
|
||||
|
||||
// messy code to quickly check which tracks are available for emulation/display
|
||||
// there's likely a better spot to do this, but the MagDevice functions don't have access to the full mag struct...
|
||||
bool is_empty_t1 = furi_string_empty(mag->mag_dev->dev_data.track[0].str);
|
||||
bool is_empty_t2 = furi_string_empty(mag->mag_dev->dev_data.track[1].str);
|
||||
bool is_empty_t3 = furi_string_empty(mag->mag_dev->dev_data.track[2].str);
|
||||
|
||||
if(!is_empty_t1 && !is_empty_t2) {
|
||||
mag->setting->track = MagTrackStateOneAndTwo;
|
||||
} else if(!is_empty_t1) {
|
||||
mag->setting->track = MagTrackStateOne;
|
||||
} else if(!is_empty_t2) {
|
||||
mag->setting->track = MagTrackStateTwo;
|
||||
} else if(!is_empty_t3) {
|
||||
mag->setting->track = MagTrackStateThree;
|
||||
} // TODO: what happens if no track data present?
|
||||
|
||||
submenu_add_item(
|
||||
submenu, "Emulate (WIP)", SubmenuIndexEmulate, mag_scene_saved_menu_submenu_callback, mag);
|
||||
//submenu_add_item(
|
||||
// submenu, "Edit (WIP)", SubmenuIndexEdit, mag_scene_saved_menu_submenu_callback, mag);
|
||||
submenu_add_item(
|
||||
submenu, "Delete", SubmenuIndexDelete, mag_scene_saved_menu_submenu_callback, mag);
|
||||
submenu_add_item(
|
||||
submenu, "Info", SubmenuIndexInfo, mag_scene_saved_menu_submenu_callback, mag);
|
||||
|
||||
submenu_set_selected_item(
|
||||
mag->submenu, scene_manager_get_scene_state(mag->scene_manager, MagSceneSavedMenu));
|
||||
|
||||
view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewSubmenu);
|
||||
}
|
||||
|
||||
bool mag_scene_saved_menu_on_event(void* context, SceneManagerEvent event) {
|
||||
Mag* mag = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
scene_manager_set_scene_state(mag->scene_manager, MagSceneSavedMenu, event.event);
|
||||
|
||||
// TODO: replace with actual next scenes once built
|
||||
if(event.event == SubmenuIndexEmulate) {
|
||||
scene_manager_next_scene(mag->scene_manager, MagSceneEmulate);
|
||||
consumed = true;
|
||||
//} else if(event.event == SubmenuIndexEdit) {
|
||||
// scene_manager_next_scene(mag->scene_manager, MagSceneUnderConstruction);
|
||||
// consumed = true;
|
||||
} else if(event.event == SubmenuIndexDelete) {
|
||||
scene_manager_next_scene(mag->scene_manager, MagSceneDeleteConfirm);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexInfo) {
|
||||
scene_manager_next_scene(mag->scene_manager, MagSceneSavedInfo);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void mag_scene_saved_menu_on_exit(void* context) {
|
||||
Mag* mag = context;
|
||||
|
||||
submenu_reset(mag->submenu);
|
||||
}
|
||||
71
applications/external/magspoof/scenes/mag_scene_start.c
vendored
Normal file
71
applications/external/magspoof/scenes/mag_scene_start.c
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "../mag_i.h"
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexSaved,
|
||||
SubmenuIndexRead,
|
||||
//SubmenuIndexAddManually,
|
||||
SubmenuIndexAbout,
|
||||
} SubmenuIndex;
|
||||
|
||||
static void mag_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||
Mag* mag = context;
|
||||
|
||||
view_dispatcher_send_custom_event(mag->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void mag_scene_start_on_enter(void* context) {
|
||||
Mag* mag = context;
|
||||
Submenu* submenu = mag->submenu;
|
||||
|
||||
submenu_add_item(submenu, "Saved", SubmenuIndexSaved, mag_scene_start_submenu_callback, mag);
|
||||
submenu_add_item(submenu, "Read", SubmenuIndexRead, mag_scene_start_submenu_callback, mag);
|
||||
//submenu_add_item(
|
||||
// submenu, "Add Manually", SubmenuIndexAddManually, mag_scene_start_submenu_callback, mag);
|
||||
submenu_add_item(submenu, "About", SubmenuIndexAbout, mag_scene_start_submenu_callback, mag);
|
||||
|
||||
submenu_set_selected_item(
|
||||
submenu, scene_manager_get_scene_state(mag->scene_manager, MagSceneStart));
|
||||
|
||||
// clear key
|
||||
furi_string_reset(mag->file_name);
|
||||
|
||||
view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewSubmenu);
|
||||
}
|
||||
|
||||
bool mag_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
Mag* mag = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case SubmenuIndexSaved:
|
||||
furi_string_set(mag->file_path, MAG_APP_FOLDER);
|
||||
scene_manager_next_scene(mag->scene_manager, MagSceneFileSelect);
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
case SubmenuIndexRead:
|
||||
scene_manager_next_scene(mag->scene_manager, MagSceneRead);
|
||||
consumed = true;
|
||||
break;
|
||||
//case SubmenuIndexAddManually:
|
||||
// scene_manager_next_scene(mag->scene_manager, MagSceneInputValue);
|
||||
// consumed = true;
|
||||
// break;
|
||||
case SubmenuIndexAbout:
|
||||
scene_manager_next_scene(mag->scene_manager, MagSceneAbout);
|
||||
consumed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
scene_manager_set_scene_state(mag->scene_manager, MagSceneStart, event.event);
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void mag_scene_start_on_exit(void* context) {
|
||||
Mag* mag = context;
|
||||
|
||||
submenu_reset(mag->submenu);
|
||||
}
|
||||
40
applications/external/magspoof/scenes/mag_scene_under_construction.c
vendored
Normal file
40
applications/external/magspoof/scenes/mag_scene_under_construction.c
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "../mag_i.h"
|
||||
|
||||
void mag_scene_under_construction_on_enter(void* context) {
|
||||
Mag* mag = context;
|
||||
Widget* widget = mag->widget;
|
||||
|
||||
FuriString* tmp_str;
|
||||
tmp_str = furi_string_alloc();
|
||||
|
||||
widget_add_button_element(widget, GuiButtonTypeLeft, "Back", mag_widget_callback, mag);
|
||||
|
||||
furi_string_printf(tmp_str, "Under construction!");
|
||||
widget_add_string_element(
|
||||
widget, 64, 4, AlignCenter, AlignTop, FontPrimary, furi_string_get_cstr(tmp_str));
|
||||
furi_string_reset(tmp_str);
|
||||
|
||||
view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewWidget);
|
||||
furi_string_free(tmp_str);
|
||||
}
|
||||
|
||||
bool mag_scene_under_construction_on_event(void* context, SceneManagerEvent event) {
|
||||
Mag* mag = context;
|
||||
SceneManager* scene_manager = mag->scene_manager;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GuiButtonTypeLeft) {
|
||||
consumed = true;
|
||||
|
||||
scene_manager_previous_scene(scene_manager);
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void mag_scene_under_construction_on_exit(void* context) {
|
||||
Mag* mag = context;
|
||||
widget_reset(mag->widget);
|
||||
}
|
||||
Reference in New Issue
Block a user