2023-05-18 10:48:25 +00:00
|
|
|
#include "subghz_remote_app_i.h"
|
2022-08-01 20:20:04 +00:00
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
static bool subghz_remote_app_custom_event_callback(void* context, uint32_t event) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubGhzRemoteApp* app = context;
|
|
|
|
return scene_manager_handle_custom_event(app->scene_manager, event);
|
2022-06-01 18:40:20 +00:00
|
|
|
}
|
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
static bool subghz_remote_app_back_event_callback(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubGhzRemoteApp* app = context;
|
|
|
|
return scene_manager_handle_back_event(app->scene_manager);
|
2022-06-01 18:40:20 +00:00
|
|
|
}
|
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
static void subghz_remote_app_tick_event_callback(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubGhzRemoteApp* app = context;
|
|
|
|
scene_manager_handle_tick_event(app->scene_manager);
|
2022-08-11 23:55:19 +00:00
|
|
|
}
|
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
SubGhzRemoteApp* subghz_remote_app_alloc() {
|
|
|
|
SubGhzRemoteApp* app = malloc(sizeof(SubGhzRemoteApp));
|
2022-08-25 00:21:44 +00:00
|
|
|
|
2023-05-21 17:37:55 +00:00
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
|
storage_common_migrate(storage, EXT_PATH("unirf"), SUBREM_APP_FOLDER);
|
|
|
|
|
|
|
|
if(!storage_simply_mkdir(storage, SUBREM_APP_FOLDER)) {
|
|
|
|
//FURI_LOG_E(TAG, "Could not create folder %s", SUBREM_APP_FOLDER);
|
|
|
|
}
|
|
|
|
furi_record_close(RECORD_STORAGE);
|
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
furi_hal_power_suppress_charge_enter();
|
2022-06-01 18:40:20 +00:00
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
app->file_path = furi_string_alloc();
|
2023-05-18 16:20:34 +00:00
|
|
|
furi_string_set(app->file_path, SUBREM_APP_FOLDER);
|
2022-06-01 18:40:20 +00:00
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
// GUI
|
|
|
|
app->gui = furi_record_open(RECORD_GUI);
|
2022-06-01 18:40:20 +00:00
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
// View Dispatcher
|
|
|
|
app->view_dispatcher = view_dispatcher_alloc();
|
2023-05-20 12:05:26 +00:00
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
app->scene_manager = scene_manager_alloc(&subrem_scene_handlers, app);
|
|
|
|
view_dispatcher_enable_queue(app->view_dispatcher);
|
2022-06-01 18:40:20 +00:00
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
|
|
|
|
view_dispatcher_set_custom_event_callback(
|
|
|
|
app->view_dispatcher, subghz_remote_app_custom_event_callback);
|
|
|
|
view_dispatcher_set_navigation_event_callback(
|
|
|
|
app->view_dispatcher, subghz_remote_app_back_event_callback);
|
|
|
|
view_dispatcher_set_tick_event_callback(
|
|
|
|
app->view_dispatcher, subghz_remote_app_tick_event_callback, 100);
|
2022-06-01 18:40:20 +00:00
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
2022-06-01 18:40:20 +00:00
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
// Open Notification record
|
|
|
|
app->notifications = furi_record_open(RECORD_NOTIFICATION);
|
2022-06-01 18:40:20 +00:00
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
// SubMenu
|
|
|
|
app->submenu = submenu_alloc();
|
|
|
|
view_dispatcher_add_view(
|
2023-05-30 13:51:07 +00:00
|
|
|
app->view_dispatcher, SubRemViewIDSubmenu, submenu_get_view(app->submenu));
|
2022-06-01 18:40:20 +00:00
|
|
|
|
2023-05-30 13:51:07 +00:00
|
|
|
// Dialog
|
2023-05-18 10:48:25 +00:00
|
|
|
app->dialogs = furi_record_open(RECORD_DIALOGS);
|
2022-06-01 18:40:20 +00:00
|
|
|
|
2023-07-14 09:59:58 +00:00
|
|
|
// TextInput
|
|
|
|
app->text_input = text_input_alloc();
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
app->view_dispatcher, SubRemViewIDTextInput, text_input_get_view(app->text_input));
|
|
|
|
|
|
|
|
// Widget
|
|
|
|
app->widget = widget_alloc();
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
app->view_dispatcher, SubRemViewIDWidget, widget_get_view(app->widget));
|
|
|
|
|
|
|
|
// Popup
|
|
|
|
app->popup = popup_alloc();
|
|
|
|
view_dispatcher_add_view(app->view_dispatcher, SubRemViewIDPopup, popup_get_view(app->popup));
|
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
// Remote view
|
|
|
|
app->subrem_remote_view = subrem_view_remote_alloc();
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
app->view_dispatcher,
|
|
|
|
SubRemViewIDRemote,
|
|
|
|
subrem_view_remote_get_view(app->subrem_remote_view));
|
2022-06-01 18:40:20 +00:00
|
|
|
|
2023-07-14 09:59:58 +00:00
|
|
|
// Edit Menu view
|
|
|
|
app->subrem_edit_menu = subrem_view_edit_menu_alloc();
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
app->view_dispatcher,
|
|
|
|
SubRemViewIDEditMenu,
|
|
|
|
subrem_view_edit_menu_get_view(app->subrem_edit_menu));
|
|
|
|
|
2023-05-21 07:29:58 +00:00
|
|
|
app->map_preset = malloc(sizeof(SubRemMapPreset));
|
2023-05-18 10:48:25 +00:00
|
|
|
for(uint8_t i = 0; i < SubRemSubKeyNameMaxCount; i++) {
|
2023-05-21 07:29:58 +00:00
|
|
|
app->map_preset->subs_preset[i] = subrem_sub_file_preset_alloc();
|
2022-06-01 18:40:20 +00:00
|
|
|
}
|
|
|
|
|
2023-05-21 20:34:42 +00:00
|
|
|
app->txrx = subghz_txrx_alloc();
|
2022-08-14 21:26:49 +00:00
|
|
|
|
2023-05-21 20:34:42 +00:00
|
|
|
subghz_txrx_set_need_save_callback(app->txrx, subrem_save_active_sub, app);
|
2022-08-24 20:14:33 +00:00
|
|
|
|
2023-07-14 09:59:58 +00:00
|
|
|
app->map_not_saved = false;
|
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
scene_manager_next_scene(app->scene_manager, SubRemSceneStart);
|
2023-07-14 09:59:58 +00:00
|
|
|
scene_manager_next_scene(app->scene_manager, SubRemSceneOpenMapFile);
|
2022-08-24 12:28:27 +00:00
|
|
|
|
2022-06-01 18:40:20 +00:00
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
void subghz_remote_app_free(SubGhzRemoteApp* app) {
|
|
|
|
furi_assert(app);
|
|
|
|
|
2022-09-19 02:22:50 +00:00
|
|
|
furi_hal_power_suppress_charge_exit();
|
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
// Submenu
|
2023-05-30 13:51:07 +00:00
|
|
|
view_dispatcher_remove_view(app->view_dispatcher, SubRemViewIDSubmenu);
|
2023-05-18 10:48:25 +00:00
|
|
|
submenu_free(app->submenu);
|
2022-08-01 20:20:04 +00:00
|
|
|
|
2023-05-30 13:51:07 +00:00
|
|
|
// Dialog
|
2023-05-18 10:48:25 +00:00
|
|
|
furi_record_close(RECORD_DIALOGS);
|
2022-06-01 18:40:20 +00:00
|
|
|
|
2023-07-14 09:59:58 +00:00
|
|
|
// TextInput
|
|
|
|
view_dispatcher_remove_view(app->view_dispatcher, SubRemViewIDTextInput);
|
|
|
|
text_input_free(app->text_input);
|
|
|
|
|
|
|
|
// Widget
|
|
|
|
view_dispatcher_remove_view(app->view_dispatcher, SubRemViewIDWidget);
|
|
|
|
widget_free(app->widget);
|
|
|
|
|
|
|
|
// Popup
|
|
|
|
view_dispatcher_remove_view(app->view_dispatcher, SubRemViewIDPopup);
|
|
|
|
popup_free(app->popup);
|
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
// Remote view
|
|
|
|
view_dispatcher_remove_view(app->view_dispatcher, SubRemViewIDRemote);
|
|
|
|
subrem_view_remote_free(app->subrem_remote_view);
|
2022-06-01 18:40:20 +00:00
|
|
|
|
2023-07-14 09:59:58 +00:00
|
|
|
// Edit view
|
|
|
|
view_dispatcher_remove_view(app->view_dispatcher, SubRemViewIDEditMenu);
|
|
|
|
subrem_view_edit_menu_free(app->subrem_edit_menu);
|
|
|
|
|
2023-05-20 12:05:26 +00:00
|
|
|
scene_manager_free(app->scene_manager);
|
|
|
|
view_dispatcher_free(app->view_dispatcher);
|
|
|
|
|
2023-05-21 20:34:42 +00:00
|
|
|
subghz_txrx_free(app->txrx);
|
2022-06-01 18:40:20 +00:00
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
for(uint8_t i = 0; i < SubRemSubKeyNameMaxCount; i++) {
|
2023-05-21 07:29:58 +00:00
|
|
|
subrem_sub_file_preset_free(app->map_preset->subs_preset[i]);
|
2022-09-19 02:22:50 +00:00
|
|
|
}
|
2023-05-21 07:29:58 +00:00
|
|
|
free(app->map_preset);
|
2022-08-23 12:48:08 +00:00
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
// Notifications
|
2022-08-24 12:28:27 +00:00
|
|
|
furi_record_close(RECORD_NOTIFICATION);
|
2023-05-18 10:48:25 +00:00
|
|
|
app->notifications = NULL;
|
|
|
|
|
|
|
|
// Close records
|
|
|
|
furi_record_close(RECORD_GUI);
|
|
|
|
|
|
|
|
// Path strings
|
|
|
|
furi_string_free(app->file_path);
|
2022-08-24 12:28:27 +00:00
|
|
|
|
2022-06-01 18:40:20 +00:00
|
|
|
free(app);
|
|
|
|
}
|
|
|
|
|
2023-03-06 07:32:01 +00:00
|
|
|
int32_t subghz_remote_app(void* p) {
|
2022-06-01 18:40:20 +00:00
|
|
|
UNUSED(p);
|
2023-05-18 10:48:25 +00:00
|
|
|
SubGhzRemoteApp* subghz_remote_app = subghz_remote_app_alloc();
|
2022-08-01 20:20:04 +00:00
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
furi_string_set(subghz_remote_app->file_path, SUBREM_APP_FOLDER);
|
2022-09-14 18:04:04 +00:00
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
view_dispatcher_run(subghz_remote_app->view_dispatcher);
|
2022-06-01 18:40:20 +00:00
|
|
|
|
2023-05-18 10:48:25 +00:00
|
|
|
subghz_remote_app_free(subghz_remote_app);
|
2022-08-24 12:28:27 +00:00
|
|
|
|
2022-06-01 18:40:20 +00:00
|
|
|
return 0;
|
2023-02-20 15:55:53 +00:00
|
|
|
}
|