|
| 1 | +#include "../picopass_i.h" |
| 2 | +#include <dolphin/dolphin.h> |
| 3 | + |
| 4 | +void picopass_scene_formats_on_enter(void* context) { |
| 5 | + Picopass* picopass = context; |
| 6 | + PluginWiegand* plugin = picopass->plugin_wiegand; |
| 7 | + PicopassDevice* dev = picopass->dev; |
| 8 | + PicopassDeviceData dev_data = dev->dev_data; |
| 9 | + PicopassPacs pacs = dev_data.pacs; |
| 10 | + |
| 11 | + FuriString* str = picopass->text_box_store; |
| 12 | + furi_string_reset(str); |
| 13 | + |
| 14 | + // Convert from byte array to uint64_t |
| 15 | + uint64_t credential = 0; |
| 16 | + memcpy(&credential, pacs.credential, sizeof(pacs.credential)); |
| 17 | + credential = __builtin_bswap64(credential); |
| 18 | + |
| 19 | + if(plugin) { |
| 20 | + FuriString* description = furi_string_alloc(); |
| 21 | + size_t format_count = plugin->count(pacs.bitLength, credential); |
| 22 | + for(size_t i = 0; i < format_count; i++) { |
| 23 | + plugin->description(pacs.bitLength, credential, i, description); |
| 24 | + |
| 25 | + furi_string_cat_printf(str, "%s\n", furi_string_get_cstr(description)); |
| 26 | + } |
| 27 | + furi_string_free(description); |
| 28 | + } |
| 29 | + |
| 30 | + text_box_set_font(picopass->text_box, TextBoxFontHex); |
| 31 | + text_box_set_text(picopass->text_box, furi_string_get_cstr(picopass->text_box_store)); |
| 32 | + view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewTextBox); |
| 33 | +} |
| 34 | + |
| 35 | +bool picopass_scene_formats_on_event(void* context, SceneManagerEvent event) { |
| 36 | + Picopass* picopass = context; |
| 37 | + bool consumed = false; |
| 38 | + |
| 39 | + if(event.type == SceneManagerEventTypeCustom) { |
| 40 | + if(event.event == GuiButtonTypeLeft) { |
| 41 | + consumed = scene_manager_previous_scene(picopass->scene_manager); |
| 42 | + } |
| 43 | + } else if(event.type == SceneManagerEventTypeBack) { |
| 44 | + consumed = scene_manager_previous_scene(picopass->scene_manager); |
| 45 | + } |
| 46 | + return consumed; |
| 47 | +} |
| 48 | + |
| 49 | +void picopass_scene_formats_on_exit(void* context) { |
| 50 | + Picopass* picopass = context; |
| 51 | + |
| 52 | + // Clear views |
| 53 | + text_box_reset(picopass->text_box); |
| 54 | +} |
0 commit comments