Skip to content

Commit

Permalink
scene to show parsed formats
Browse files Browse the repository at this point in the history
  • Loading branch information
bettse committed Apr 14, 2024
1 parent 8b3fb58 commit 93cd7ea
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 5 deletions.
3 changes: 2 additions & 1 deletion plugin_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

#include <stdint.h>
#include <stddef.h>
#include <furi.h>

#define PLUGIN_APP_ID "plugin_wiegand"
#define PLUGIN_API_VERSION 1

typedef struct {
const char* name;
int (*count)(uint8_t, uint64_t);
int (*description)(uint8_t, uint64_t, size_t);
void (*description)(uint8_t, uint64_t, size_t, FuriString*);
} PluginWiegand;
11 changes: 7 additions & 4 deletions plugin_wiegand.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
static int wiegand_format_count(uint8_t bit_length, uint64_t bits) {
UNUSED(bit_length);
UNUSED(bits);
return 1337;
return 0;
}

static int wiegand_format_description(uint8_t bit_length, uint64_t bits, size_t index) {
static void wiegand_format_description(
uint8_t bit_length,
uint64_t bits,
size_t index,
FuriString* description) {
UNUSED(bit_length);
UNUSED(bits);
UNUSED(index);

return 0;
UNUSED(description);
}

/* Actual implementation of app<>plugin interface */
Expand Down
19 changes: 19 additions & 0 deletions scenes/seader_scene_card_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum SubmenuIndex {
SubmenuIndexSaveRFID,
SubmenuIndexSaveSR,
SubmenuIndexSaveMFC,
SubmenuIndexParse,
};

void seader_scene_card_menu_submenu_callback(void* context, uint32_t index) {
Expand All @@ -17,6 +18,7 @@ void seader_scene_card_menu_submenu_callback(void* context, uint32_t index) {
void seader_scene_card_menu_on_enter(void* context) {
Seader* seader = context;
SeaderCredential* credential = seader->credential;
PluginWiegand* plugin = seader->plugin_wiegand;
Submenu* submenu = seader->submenu;

submenu_add_item(
Expand Down Expand Up @@ -44,6 +46,18 @@ void seader_scene_card_menu_on_enter(void* context) {
submenu_add_item(
submenu, "Save MFC", SubmenuIndexSaveMFC, seader_scene_card_menu_submenu_callback, seader);

if(plugin) {
size_t format_count = plugin->count(credential->bit_length, credential->credential);
if(format_count > 0) {
submenu_add_item(
submenu,
"Parse",
SubmenuIndexParse,
seader_scene_card_menu_submenu_callback,
seader);
}
}

submenu_set_selected_item(
seader->submenu,
scene_manager_get_scene_state(seader->scene_manager, SeaderSceneCardMenu));
Expand Down Expand Up @@ -85,6 +99,11 @@ bool seader_scene_card_menu_on_event(void* context, SceneManagerEvent event) {
seader->credential->save_format = SeaderCredentialSaveFormatMFC;
scene_manager_next_scene(seader->scene_manager, SeaderSceneSaveName);
consumed = true;
} else if(event.event == SubmenuIndexParse) {
scene_manager_set_scene_state(
seader->scene_manager, SeaderSceneCardMenu, SubmenuIndexParse);
scene_manager_next_scene(seader->scene_manager, SeaderSceneFormats);
consumed = true;
}
} else if(event.type == SceneManagerEventTypeBack) {
consumed = scene_manager_search_and_switch_to_previous_scene(
Expand Down
1 change: 1 addition & 0 deletions scenes/seader_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ ADD_SCENE(seader, delete_success, DeleteSuccess)
ADD_SCENE(seader, credential_info, CredentialInfo)
ADD_SCENE(seader, sam_info, SamInfo)
ADD_SCENE(seader, virtual_credential, VirtualCredential)
ADD_SCENE(seader, formats, Formats)
47 changes: 47 additions & 0 deletions scenes/seader_scene_formats.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "../seader_i.h"
#include <dolphin/dolphin.h>

void seader_scene_formats_on_enter(void* context) {
Seader* seader = context;
PluginWiegand* plugin = seader->plugin_wiegand;
SeaderCredential* credential = seader->credential;

FuriString* str = seader->text_box_store;
furi_string_reset(str);

if(plugin) {
FuriString* description = furi_string_alloc();
size_t format_count = plugin->count(credential->bit_length, credential->credential);
for(size_t i = 0; i < format_count; i++) {
plugin->description(credential->bit_length, credential->credential, i, description);

furi_string_cat_printf(str, "%s\n", furi_string_get_cstr(description));
}
furi_string_free(description);
}

text_box_set_font(seader->text_box, TextBoxFontHex);
text_box_set_text(seader->text_box, furi_string_get_cstr(seader->text_box_store));
view_dispatcher_switch_to_view(seader->view_dispatcher, SeaderViewTextBox);
}

bool seader_scene_formats_on_event(void* context, SceneManagerEvent event) {
Seader* seader = context;
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == GuiButtonTypeLeft) {
consumed = scene_manager_previous_scene(seader->scene_manager);
}
} else if(event.type == SceneManagerEventTypeBack) {
consumed = scene_manager_previous_scene(seader->scene_manager);
}
return consumed;
}

void seader_scene_formats_on_exit(void* context) {
Seader* seader = context;

// Clear views
text_box_reset(seader->text_box);
}
10 changes: 10 additions & 0 deletions seader.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,22 @@ Seader* seader_alloc() {
seader->plugin_manager =
plugin_manager_alloc(PLUGIN_APP_ID, PLUGIN_API_VERSION, firmware_api_interface);

seader->plugin_wiegand = NULL;
if(plugin_manager_load_all(seader->plugin_manager, APP_DATA_PATH("plugins")) !=
PluginManagerErrorNone) {
FURI_LOG_E(TAG, "Failed to load all libs");
} else {
uint32_t plugin_count = plugin_manager_get_count(seader->plugin_manager);
FURI_LOG_I(TAG, "Loaded %lu plugin(s)", plugin_count);

for(uint32_t i = 0; i < plugin_count; i++) {
const PluginWiegand* plugin = plugin_manager_get_ep(seader->plugin_manager, i);
FURI_LOG_I(TAG, "plugin name: %s", plugin->name);
if(strcmp(plugin->name, PLUGIN_APP_ID) == 0) {
// Have to cast to drop "const" qualifier
seader->plugin_wiegand = (PluginWiegand*)plugin;
}
}
}

return seader;
Expand Down

0 comments on commit 93cd7ea

Please sign in to comment.