[FL-2627] Flipper applications: SDK, build and debug system (#1387)
* Added support for running applications from SD card (FAPs - Flipper Application Packages) * Added plugin_dist target for fbt to build FAPs * All apps of type FlipperAppType.EXTERNAL and FlipperAppType.PLUGIN are built as FAPs by default * Updated VSCode configuration for new fbt features - re-deploy stock configuration to use them * Added debugging support for FAPs with fbt debug & VSCode * Added public firmware API with automated versioning Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: SG <who.just.the.doctor@gmail.com> Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
30
applications/plugins/picopass/scenes/picopass_scene.c
Normal file
30
applications/plugins/picopass/scenes/picopass_scene.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "picopass_scene.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const picopass_on_enter_handlers[])(void*) = {
|
||||
#include "picopass_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 picopass_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "picopass_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 picopass_on_exit_handlers[])(void* context) = {
|
||||
#include "picopass_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers picopass_scene_handlers = {
|
||||
.on_enter_handlers = picopass_on_enter_handlers,
|
||||
.on_event_handlers = picopass_on_event_handlers,
|
||||
.on_exit_handlers = picopass_on_exit_handlers,
|
||||
.scene_num = PicopassSceneNum,
|
||||
};
|
29
applications/plugins/picopass/scenes/picopass_scene.h
Normal file
29
applications/plugins/picopass/scenes/picopass_scene.h
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) PicopassScene##id,
|
||||
typedef enum {
|
||||
#include "picopass_scene_config.h"
|
||||
PicopassSceneNum,
|
||||
} PicopassScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers picopass_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "picopass_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 "picopass_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 "picopass_scene_config.h"
|
||||
#undef ADD_SCENE
|
@@ -0,0 +1,65 @@
|
||||
#include "../picopass_i.h"
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexSave,
|
||||
SubmenuIndexSaveAsLF,
|
||||
};
|
||||
|
||||
void picopass_scene_card_menu_submenu_callback(void* context, uint32_t index) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
view_dispatcher_send_custom_event(picopass->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void picopass_scene_card_menu_on_enter(void* context) {
|
||||
Picopass* picopass = context;
|
||||
Submenu* submenu = picopass->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu, "Save", SubmenuIndexSave, picopass_scene_card_menu_submenu_callback, picopass);
|
||||
if(picopass->dev->dev_data.pacs.record.valid) {
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Save as LF",
|
||||
SubmenuIndexSaveAsLF,
|
||||
picopass_scene_card_menu_submenu_callback,
|
||||
picopass);
|
||||
}
|
||||
submenu_set_selected_item(
|
||||
picopass->submenu,
|
||||
scene_manager_get_scene_state(picopass->scene_manager, PicopassSceneCardMenu));
|
||||
|
||||
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewMenu);
|
||||
}
|
||||
|
||||
bool picopass_scene_card_menu_on_event(void* context, SceneManagerEvent event) {
|
||||
Picopass* picopass = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubmenuIndexSave) {
|
||||
scene_manager_set_scene_state(
|
||||
picopass->scene_manager, PicopassSceneCardMenu, SubmenuIndexSave);
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneSaveName);
|
||||
picopass->dev->format = PicopassDeviceSaveFormatHF;
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexSaveAsLF) {
|
||||
scene_manager_set_scene_state(
|
||||
picopass->scene_manager, PicopassSceneCardMenu, SubmenuIndexSaveAsLF);
|
||||
picopass->dev->format = PicopassDeviceSaveFormatLF;
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneSaveName);
|
||||
consumed = true;
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
picopass->scene_manager, PicopassSceneStart);
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void picopass_scene_card_menu_on_exit(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
submenu_reset(picopass->submenu);
|
||||
}
|
13
applications/plugins/picopass/scenes/picopass_scene_config.h
Normal file
13
applications/plugins/picopass/scenes/picopass_scene_config.h
Normal file
@@ -0,0 +1,13 @@
|
||||
ADD_SCENE(picopass, start, Start)
|
||||
ADD_SCENE(picopass, read_card, ReadCard)
|
||||
ADD_SCENE(picopass, read_card_success, ReadCardSuccess)
|
||||
ADD_SCENE(picopass, card_menu, CardMenu)
|
||||
ADD_SCENE(picopass, save_name, SaveName)
|
||||
ADD_SCENE(picopass, save_success, SaveSuccess)
|
||||
ADD_SCENE(picopass, saved_menu, SavedMenu)
|
||||
ADD_SCENE(picopass, file_select, FileSelect)
|
||||
ADD_SCENE(picopass, device_info, DeviceInfo)
|
||||
ADD_SCENE(picopass, delete, Delete)
|
||||
ADD_SCENE(picopass, delete_success, DeleteSuccess)
|
||||
ADD_SCENE(picopass, write_card, WriteCard)
|
||||
ADD_SCENE(picopass, write_card_success, WriteCardSuccess)
|
58
applications/plugins/picopass/scenes/picopass_scene_delete.c
Normal file
58
applications/plugins/picopass/scenes/picopass_scene_delete.c
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "../picopass_i.h"
|
||||
|
||||
void picopass_scene_delete_widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
Picopass* picopass = context;
|
||||
if(type == InputTypeShort) {
|
||||
view_dispatcher_send_custom_event(picopass->view_dispatcher, result);
|
||||
}
|
||||
}
|
||||
|
||||
void picopass_scene_delete_on_enter(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
// Setup Custom Widget view
|
||||
char temp_str[64];
|
||||
snprintf(temp_str, sizeof(temp_str), "\e#Delete %s?\e#", picopass->dev->dev_name);
|
||||
widget_add_text_box_element(
|
||||
picopass->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, temp_str, false);
|
||||
widget_add_button_element(
|
||||
picopass->widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Back",
|
||||
picopass_scene_delete_widget_callback,
|
||||
picopass);
|
||||
widget_add_button_element(
|
||||
picopass->widget,
|
||||
GuiButtonTypeRight,
|
||||
"Delete",
|
||||
picopass_scene_delete_widget_callback,
|
||||
picopass);
|
||||
|
||||
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewWidget);
|
||||
}
|
||||
|
||||
bool picopass_scene_delete_on_event(void* context, SceneManagerEvent event) {
|
||||
Picopass* picopass = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GuiButtonTypeLeft) {
|
||||
return scene_manager_previous_scene(picopass->scene_manager);
|
||||
} else if(event.event == GuiButtonTypeRight) {
|
||||
if(picopass_device_delete(picopass->dev, true)) {
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneDeleteSuccess);
|
||||
} else {
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
picopass->scene_manager, PicopassSceneStart);
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void picopass_scene_delete_on_exit(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
widget_reset(picopass->widget);
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
#include "../picopass_i.h"
|
||||
|
||||
void picopass_scene_delete_success_popup_callback(void* context) {
|
||||
Picopass* picopass = context;
|
||||
view_dispatcher_send_custom_event(picopass->view_dispatcher, PicopassCustomEventViewExit);
|
||||
}
|
||||
|
||||
void picopass_scene_delete_success_on_enter(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
// Setup view
|
||||
Popup* popup = picopass->popup;
|
||||
popup_set_icon(popup, 0, 2, &I_DolphinMafia_115x62);
|
||||
popup_set_header(popup, "Deleted", 83, 19, AlignLeft, AlignBottom);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_set_context(popup, picopass);
|
||||
popup_set_callback(popup, picopass_scene_delete_success_popup_callback);
|
||||
popup_enable_timeout(popup);
|
||||
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewPopup);
|
||||
}
|
||||
|
||||
bool picopass_scene_delete_success_on_event(void* context, SceneManagerEvent event) {
|
||||
Picopass* picopass = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == PicopassCustomEventViewExit) {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
picopass->scene_manager, PicopassSceneStart);
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void picopass_scene_delete_success_on_exit(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
// Clear view
|
||||
popup_reset(picopass->popup);
|
||||
}
|
@@ -0,0 +1,82 @@
|
||||
#include "../picopass_i.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
void picopass_scene_device_info_widget_callback(
|
||||
GuiButtonType result,
|
||||
InputType type,
|
||||
void* context) {
|
||||
Picopass* picopass = context;
|
||||
if(type == InputTypeShort) {
|
||||
view_dispatcher_send_custom_event(picopass->view_dispatcher, result);
|
||||
}
|
||||
}
|
||||
|
||||
void picopass_scene_device_info_on_enter(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
string_t credential_str;
|
||||
string_t wiegand_str;
|
||||
string_init(credential_str);
|
||||
string_init(wiegand_str);
|
||||
|
||||
DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
|
||||
|
||||
// Setup view
|
||||
PicopassPacs* pacs = &picopass->dev->dev_data.pacs;
|
||||
Widget* widget = picopass->widget;
|
||||
|
||||
size_t bytesLength = 1 + pacs->record.bitLength / 8;
|
||||
string_set_str(credential_str, "");
|
||||
for(uint8_t i = PICOPASS_BLOCK_LEN - bytesLength; i < PICOPASS_BLOCK_LEN; i++) {
|
||||
string_cat_printf(credential_str, " %02X", pacs->credential[i]);
|
||||
}
|
||||
|
||||
if(pacs->record.valid) {
|
||||
string_cat_printf(
|
||||
wiegand_str, "FC: %u CN: %u", pacs->record.FacilityCode, pacs->record.CardNumber);
|
||||
} else {
|
||||
string_cat_printf(wiegand_str, "%d bits", pacs->record.bitLength);
|
||||
}
|
||||
|
||||
widget_add_string_element(
|
||||
widget, 64, 12, AlignCenter, AlignCenter, FontPrimary, string_get_cstr(wiegand_str));
|
||||
widget_add_string_element(
|
||||
widget, 64, 32, AlignCenter, AlignCenter, FontSecondary, string_get_cstr(credential_str));
|
||||
|
||||
string_clear(credential_str);
|
||||
string_clear(wiegand_str);
|
||||
|
||||
widget_add_button_element(
|
||||
picopass->widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Back",
|
||||
picopass_scene_device_info_widget_callback,
|
||||
picopass);
|
||||
|
||||
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewWidget);
|
||||
}
|
||||
|
||||
bool picopass_scene_device_info_on_event(void* context, SceneManagerEvent event) {
|
||||
Picopass* picopass = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GuiButtonTypeLeft) {
|
||||
consumed = scene_manager_previous_scene(picopass->scene_manager);
|
||||
} else if(event.event == PicopassCustomEventViewExit) {
|
||||
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewWidget);
|
||||
consumed = true;
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewWidget);
|
||||
consumed = true;
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void picopass_scene_device_info_on_exit(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
// Clear views
|
||||
widget_reset(picopass->widget);
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
#include "../picopass_i.h"
|
||||
#include "../picopass_device.h"
|
||||
|
||||
void picopass_scene_file_select_on_enter(void* context) {
|
||||
Picopass* picopass = context;
|
||||
// Process file_select return
|
||||
picopass_device_set_loading_callback(picopass->dev, picopass_show_loading_popup, picopass);
|
||||
if(picopass_file_select(picopass->dev)) {
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneSavedMenu);
|
||||
} else {
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
picopass->scene_manager, PicopassSceneStart);
|
||||
}
|
||||
picopass_device_set_loading_callback(picopass->dev, NULL, picopass);
|
||||
}
|
||||
|
||||
bool picopass_scene_file_select_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
UNUSED(event);
|
||||
return false;
|
||||
}
|
||||
|
||||
void picopass_scene_file_select_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
#include "../picopass_i.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
void picopass_read_card_worker_callback(PicopassWorkerEvent event, void* context) {
|
||||
UNUSED(event);
|
||||
Picopass* picopass = context;
|
||||
view_dispatcher_send_custom_event(picopass->view_dispatcher, PicopassCustomEventWorkerExit);
|
||||
}
|
||||
|
||||
void picopass_scene_read_card_on_enter(void* context) {
|
||||
Picopass* picopass = context;
|
||||
DOLPHIN_DEED(DolphinDeedNfcRead);
|
||||
|
||||
// Setup view
|
||||
Popup* popup = picopass->popup;
|
||||
popup_set_header(popup, "Detecting\npicopass\ncard", 68, 30, AlignLeft, AlignTop);
|
||||
popup_set_icon(popup, 0, 3, &I_RFIDDolphinReceive_97x61);
|
||||
|
||||
// Start worker
|
||||
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewPopup);
|
||||
picopass_worker_start(
|
||||
picopass->worker,
|
||||
PicopassWorkerStateDetect,
|
||||
&picopass->dev->dev_data,
|
||||
picopass_read_card_worker_callback,
|
||||
picopass);
|
||||
|
||||
picopass_blink_start(picopass);
|
||||
}
|
||||
|
||||
bool picopass_scene_read_card_on_event(void* context, SceneManagerEvent event) {
|
||||
Picopass* picopass = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == PicopassCustomEventWorkerExit) {
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneReadCardSuccess);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void picopass_scene_read_card_on_exit(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
// Stop worker
|
||||
picopass_worker_stop(picopass->worker);
|
||||
// Clear view
|
||||
popup_reset(picopass->popup);
|
||||
|
||||
picopass_blink_stop(picopass);
|
||||
}
|
@@ -0,0 +1,111 @@
|
||||
#include "../picopass_i.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
void picopass_scene_read_card_success_widget_callback(
|
||||
GuiButtonType result,
|
||||
InputType type,
|
||||
void* context) {
|
||||
furi_assert(context);
|
||||
Picopass* picopass = context;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
view_dispatcher_send_custom_event(picopass->view_dispatcher, result);
|
||||
}
|
||||
}
|
||||
|
||||
void picopass_scene_read_card_success_on_enter(void* context) {
|
||||
Picopass* picopass = context;
|
||||
string_t credential_str;
|
||||
string_t wiegand_str;
|
||||
string_init(credential_str);
|
||||
string_init(wiegand_str);
|
||||
|
||||
DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
|
||||
|
||||
// Send notification
|
||||
notification_message(picopass->notifications, &sequence_success);
|
||||
|
||||
// Setup view
|
||||
PicopassPacs* pacs = &picopass->dev->dev_data.pacs;
|
||||
Widget* widget = picopass->widget;
|
||||
|
||||
if(pacs->record.bitLength == 0) {
|
||||
string_cat_printf(wiegand_str, "Read Failed");
|
||||
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Retry",
|
||||
picopass_scene_read_card_success_widget_callback,
|
||||
picopass);
|
||||
|
||||
widget_add_string_element(
|
||||
widget, 64, 12, AlignCenter, AlignCenter, FontPrimary, string_get_cstr(wiegand_str));
|
||||
} else {
|
||||
size_t bytesLength = 1 + pacs->record.bitLength / 8;
|
||||
string_set_str(credential_str, "");
|
||||
for(uint8_t i = PICOPASS_BLOCK_LEN - bytesLength; i < PICOPASS_BLOCK_LEN; i++) {
|
||||
string_cat_printf(credential_str, " %02X", pacs->credential[i]);
|
||||
}
|
||||
|
||||
if(pacs->record.valid) {
|
||||
string_cat_printf(
|
||||
wiegand_str, "FC: %u CN: %u", pacs->record.FacilityCode, pacs->record.CardNumber);
|
||||
} else {
|
||||
string_cat_printf(wiegand_str, "%d bits", pacs->record.bitLength);
|
||||
}
|
||||
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Retry",
|
||||
picopass_scene_read_card_success_widget_callback,
|
||||
picopass);
|
||||
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeRight,
|
||||
"More",
|
||||
picopass_scene_read_card_success_widget_callback,
|
||||
picopass);
|
||||
|
||||
widget_add_string_element(
|
||||
widget, 64, 12, AlignCenter, AlignCenter, FontPrimary, string_get_cstr(wiegand_str));
|
||||
widget_add_string_element(
|
||||
widget,
|
||||
64,
|
||||
32,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
FontSecondary,
|
||||
string_get_cstr(credential_str));
|
||||
}
|
||||
string_clear(credential_str);
|
||||
string_clear(wiegand_str);
|
||||
|
||||
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewWidget);
|
||||
}
|
||||
|
||||
bool picopass_scene_read_card_success_on_event(void* context, SceneManagerEvent event) {
|
||||
Picopass* picopass = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GuiButtonTypeLeft) {
|
||||
consumed = scene_manager_previous_scene(picopass->scene_manager);
|
||||
} else if(event.event == GuiButtonTypeRight) {
|
||||
// Clear device name
|
||||
picopass_device_set_name(picopass->dev, "");
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneCardMenu);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void picopass_scene_read_card_success_on_exit(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
// Clear view
|
||||
widget_reset(picopass->widget);
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
#include "../picopass_i.h"
|
||||
#include "m-string.h"
|
||||
#include <lib/toolbox/random_name.h>
|
||||
#include <gui/modules/validators.h>
|
||||
#include <toolbox/path.h>
|
||||
|
||||
void picopass_scene_save_name_text_input_callback(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
view_dispatcher_send_custom_event(picopass->view_dispatcher, PicopassCustomEventTextInputDone);
|
||||
}
|
||||
|
||||
void picopass_scene_save_name_on_enter(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
// Setup view
|
||||
TextInput* text_input = picopass->text_input;
|
||||
bool dev_name_empty = false;
|
||||
if(!strcmp(picopass->dev->dev_name, "")) {
|
||||
set_random_name(picopass->text_store, sizeof(picopass->text_store));
|
||||
dev_name_empty = true;
|
||||
} else {
|
||||
picopass_text_store_set(picopass, picopass->dev->dev_name);
|
||||
}
|
||||
text_input_set_header_text(text_input, "Name the card");
|
||||
text_input_set_result_callback(
|
||||
text_input,
|
||||
picopass_scene_save_name_text_input_callback,
|
||||
picopass,
|
||||
picopass->text_store,
|
||||
PICOPASS_DEV_NAME_MAX_LEN,
|
||||
dev_name_empty);
|
||||
|
||||
string_t folder_path;
|
||||
string_init(folder_path);
|
||||
|
||||
if(string_end_with_str_p(picopass->dev->load_path, PICOPASS_APP_EXTENSION)) {
|
||||
path_extract_dirname(string_get_cstr(picopass->dev->load_path), folder_path);
|
||||
} else {
|
||||
string_set_str(folder_path, PICOPASS_APP_FOLDER);
|
||||
}
|
||||
|
||||
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
||||
string_get_cstr(folder_path), PICOPASS_APP_EXTENSION, picopass->dev->dev_name);
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
|
||||
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewTextInput);
|
||||
|
||||
string_clear(folder_path);
|
||||
}
|
||||
|
||||
bool picopass_scene_save_name_on_event(void* context, SceneManagerEvent event) {
|
||||
Picopass* picopass = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == PicopassCustomEventTextInputDone) {
|
||||
if(strcmp(picopass->dev->dev_name, "")) {
|
||||
// picopass_device_delete(picopass->dev, true);
|
||||
}
|
||||
strlcpy(
|
||||
picopass->dev->dev_name, picopass->text_store, strlen(picopass->text_store) + 1);
|
||||
if(picopass_device_save(picopass->dev, picopass->text_store)) {
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneSaveSuccess);
|
||||
consumed = true;
|
||||
} else {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
picopass->scene_manager, PicopassSceneStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void picopass_scene_save_name_on_exit(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
// Clear view
|
||||
void* validator_context = text_input_get_validator_callback_context(picopass->text_input);
|
||||
text_input_set_validator(picopass->text_input, NULL, NULL);
|
||||
validator_is_file_free(validator_context);
|
||||
|
||||
text_input_reset(picopass->text_input);
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
#include "../picopass_i.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
void picopass_scene_save_success_popup_callback(void* context) {
|
||||
Picopass* picopass = context;
|
||||
view_dispatcher_send_custom_event(picopass->view_dispatcher, PicopassCustomEventViewExit);
|
||||
}
|
||||
|
||||
void picopass_scene_save_success_on_enter(void* context) {
|
||||
Picopass* picopass = context;
|
||||
DOLPHIN_DEED(DolphinDeedNfcSave);
|
||||
|
||||
// Setup view
|
||||
Popup* popup = picopass->popup;
|
||||
popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59);
|
||||
popup_set_header(popup, "Saved!", 13, 22, AlignLeft, AlignBottom);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_set_context(popup, picopass);
|
||||
popup_set_callback(popup, picopass_scene_save_success_popup_callback);
|
||||
popup_enable_timeout(popup);
|
||||
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewPopup);
|
||||
}
|
||||
|
||||
bool picopass_scene_save_success_on_event(void* context, SceneManagerEvent event) {
|
||||
Picopass* picopass = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == PicopassCustomEventViewExit) {
|
||||
if(scene_manager_has_previous_scene(picopass->scene_manager, PicopassSceneCardMenu)) {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
picopass->scene_manager, PicopassSceneCardMenu);
|
||||
} else {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
picopass->scene_manager, PicopassSceneStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void picopass_scene_save_success_on_exit(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
// Clear view
|
||||
popup_reset(picopass->popup);
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
#include "../picopass_i.h"
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexDelete,
|
||||
SubmenuIndexInfo,
|
||||
SubmenuIndexWrite,
|
||||
};
|
||||
|
||||
void picopass_scene_saved_menu_submenu_callback(void* context, uint32_t index) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
view_dispatcher_send_custom_event(picopass->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void picopass_scene_saved_menu_on_enter(void* context) {
|
||||
Picopass* picopass = context;
|
||||
Submenu* submenu = picopass->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Delete",
|
||||
SubmenuIndexDelete,
|
||||
picopass_scene_saved_menu_submenu_callback,
|
||||
picopass);
|
||||
submenu_add_item(
|
||||
submenu, "Info", SubmenuIndexInfo, picopass_scene_saved_menu_submenu_callback, picopass);
|
||||
submenu_add_item(
|
||||
submenu, "Write", SubmenuIndexWrite, picopass_scene_saved_menu_submenu_callback, picopass);
|
||||
|
||||
submenu_set_selected_item(
|
||||
picopass->submenu,
|
||||
scene_manager_get_scene_state(picopass->scene_manager, PicopassSceneSavedMenu));
|
||||
|
||||
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewMenu);
|
||||
}
|
||||
|
||||
bool picopass_scene_saved_menu_on_event(void* context, SceneManagerEvent event) {
|
||||
Picopass* picopass = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
scene_manager_set_scene_state(
|
||||
picopass->scene_manager, PicopassSceneSavedMenu, event.event);
|
||||
|
||||
if(event.event == SubmenuIndexDelete) {
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneDelete);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexInfo) {
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneDeviceInfo);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexWrite) {
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteCard);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void picopass_scene_saved_menu_on_exit(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
submenu_reset(picopass->submenu);
|
||||
}
|
50
applications/plugins/picopass/scenes/picopass_scene_start.c
Normal file
50
applications/plugins/picopass/scenes/picopass_scene_start.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "../picopass_i.h"
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexRead,
|
||||
SubmenuIndexRunScript,
|
||||
SubmenuIndexSaved,
|
||||
SubmenuIndexAddManualy,
|
||||
SubmenuIndexDebug,
|
||||
};
|
||||
|
||||
void picopass_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||
Picopass* picopass = context;
|
||||
view_dispatcher_send_custom_event(picopass->view_dispatcher, index);
|
||||
}
|
||||
void picopass_scene_start_on_enter(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
Submenu* submenu = picopass->submenu;
|
||||
submenu_add_item(
|
||||
submenu, "Read Card", SubmenuIndexRead, picopass_scene_start_submenu_callback, picopass);
|
||||
submenu_add_item(
|
||||
submenu, "Saved", SubmenuIndexSaved, picopass_scene_start_submenu_callback, picopass);
|
||||
|
||||
submenu_set_selected_item(
|
||||
submenu, scene_manager_get_scene_state(picopass->scene_manager, PicopassSceneStart));
|
||||
picopass_device_clear(picopass->dev);
|
||||
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewMenu);
|
||||
}
|
||||
|
||||
bool picopass_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
Picopass* picopass = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubmenuIndexRead) {
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneReadCard);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexSaved) {
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneFileSelect);
|
||||
consumed = true;
|
||||
}
|
||||
scene_manager_set_scene_state(picopass->scene_manager, PicopassSceneStart, event.event);
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void picopass_scene_start_on_exit(void* context) {
|
||||
Picopass* picopass = context;
|
||||
submenu_reset(picopass->submenu);
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
#include "../picopass_i.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
void picopass_write_card_worker_callback(PicopassWorkerEvent event, void* context) {
|
||||
UNUSED(event);
|
||||
Picopass* picopass = context;
|
||||
view_dispatcher_send_custom_event(picopass->view_dispatcher, PicopassCustomEventWorkerExit);
|
||||
}
|
||||
|
||||
void picopass_scene_write_card_on_enter(void* context) {
|
||||
Picopass* picopass = context;
|
||||
DOLPHIN_DEED(DolphinDeedNfcSave);
|
||||
|
||||
// Setup view
|
||||
Popup* popup = picopass->popup;
|
||||
popup_set_header(popup, "Writing\npicopass\ncard", 68, 30, AlignLeft, AlignTop);
|
||||
popup_set_icon(popup, 0, 3, &I_RFIDDolphinSend_97x61);
|
||||
|
||||
// Start worker
|
||||
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewPopup);
|
||||
picopass_worker_start(
|
||||
picopass->worker,
|
||||
PicopassWorkerStateWrite,
|
||||
&picopass->dev->dev_data,
|
||||
picopass_write_card_worker_callback,
|
||||
picopass);
|
||||
|
||||
picopass_blink_start(picopass);
|
||||
}
|
||||
|
||||
bool picopass_scene_write_card_on_event(void* context, SceneManagerEvent event) {
|
||||
Picopass* picopass = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == PicopassCustomEventWorkerExit) {
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteCardSuccess);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void picopass_scene_write_card_on_exit(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
// Stop worker
|
||||
picopass_worker_stop(picopass->worker);
|
||||
// Clear view
|
||||
popup_reset(picopass->popup);
|
||||
|
||||
picopass_blink_stop(picopass);
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
#include "../picopass_i.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
void picopass_scene_write_card_success_widget_callback(
|
||||
GuiButtonType result,
|
||||
InputType type,
|
||||
void* context) {
|
||||
furi_assert(context);
|
||||
Picopass* picopass = context;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
view_dispatcher_send_custom_event(picopass->view_dispatcher, result);
|
||||
}
|
||||
}
|
||||
|
||||
void picopass_scene_write_card_success_on_enter(void* context) {
|
||||
Picopass* picopass = context;
|
||||
Widget* widget = picopass->widget;
|
||||
|
||||
DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
|
||||
|
||||
// Send notification
|
||||
notification_message(picopass->notifications, &sequence_success);
|
||||
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Retry",
|
||||
picopass_scene_write_card_success_widget_callback,
|
||||
picopass);
|
||||
|
||||
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewWidget);
|
||||
}
|
||||
|
||||
bool picopass_scene_write_card_success_on_event(void* context, SceneManagerEvent event) {
|
||||
Picopass* picopass = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GuiButtonTypeLeft) {
|
||||
consumed = scene_manager_previous_scene(picopass->scene_manager);
|
||||
} else if(event.event == GuiButtonTypeRight) {
|
||||
// Clear device name
|
||||
picopass_device_set_name(picopass->dev, "");
|
||||
scene_manager_next_scene(picopass->scene_manager, PicopassSceneCardMenu);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void picopass_scene_write_card_success_on_exit(void* context) {
|
||||
Picopass* picopass = context;
|
||||
|
||||
// Clear view
|
||||
widget_reset(picopass->widget);
|
||||
}
|
Reference in New Issue
Block a user