mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-06-29 21:52:03 -07:00
Merge branch 'subrem_new_app' into subghz_remote_new
This commit is contained in:
@@ -179,11 +179,12 @@ void subghz_scene_decode_raw_on_enter(void* context) {
|
||||
furi_string_get_cstr(item_time),
|
||||
subghz_history_get_type_protocol(subghz->history, i));
|
||||
}
|
||||
furi_string_free(item_name);
|
||||
furi_string_free(item_time);
|
||||
subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->idx_menu_chosen);
|
||||
}
|
||||
|
||||
furi_string_free(item_name);
|
||||
furi_string_free(item_time);
|
||||
|
||||
subghz_scene_receiver_update_statusbar(subghz);
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdReceiver);
|
||||
|
||||
@@ -25,8 +25,23 @@ typedef enum {
|
||||
SubRemViewIDRemote,
|
||||
} SubRemViewID;
|
||||
|
||||
typedef enum {
|
||||
SubRemLoadSubStateNotSet,
|
||||
SubRemLoadSubStatePreloaded,
|
||||
SubRemLoadSubStateError,
|
||||
SubRemLoadSubStateErrorNoFile,
|
||||
SubRemLoadSubStateErrorFreq,
|
||||
SubRemLoadSubStateErrorMod,
|
||||
SubRemLoadSubStateErrorProtocol,
|
||||
SubRemLoadSubStateOK,
|
||||
} SubRemLoadSubState;
|
||||
|
||||
typedef enum {
|
||||
SubRemLoadMapStateBack = 0,
|
||||
SubRemLoadMapStateError,
|
||||
SubRemLoadMapStateErrorOpenError,
|
||||
SubRemLoadMapStateErrorStorage,
|
||||
SubRemLoadMapStateErrorBrokenFile,
|
||||
SubRemLoadMapStateNotAllOK,
|
||||
SubRemLoadMapStateOK,
|
||||
} SubRemLoadMapState;
|
||||
@@ -18,7 +18,7 @@ void subrem_scene_openmapfile_on_enter(void* context) {
|
||||
dialog_message_free(message);
|
||||
#endif
|
||||
}
|
||||
if(load_state == SubRemLoadMapStateOK) {
|
||||
if(load_state == SubRemLoadMapStateOK || load_state == SubRemLoadMapStateNotAllOK) {
|
||||
scene_manager_next_scene(app->scene_manager, SubRemSceneRemote);
|
||||
} else {
|
||||
// TODO: Map Preset Reset
|
||||
|
||||
@@ -34,8 +34,10 @@ void subrem_scene_start_on_enter(void* context) {
|
||||
// subrem_scene_start_submenu_callback,
|
||||
// app);
|
||||
|
||||
submenu_set_selected_item(
|
||||
submenu, scene_manager_get_scene_state(app->scene_manager, SubRemSceneStart));
|
||||
// TODO: set scene state in subrem alloc
|
||||
// submenu_set_selected_item(
|
||||
// submenu, scene_manager_get_scene_state(app->scene_manager, SubRemSceneStart));
|
||||
submenu_set_selected_item(submenu, SubmenuIndexSubRemOpenMapFile);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, SubRemViewSubmenu);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ SubGhzRemoteApp* subghz_remote_app_alloc() {
|
||||
|
||||
// View Dispatcher
|
||||
app->view_dispatcher = view_dispatcher_alloc();
|
||||
|
||||
app->scene_manager = scene_manager_alloc(&subrem_scene_handlers, app);
|
||||
view_dispatcher_enable_queue(app->view_dispatcher);
|
||||
|
||||
@@ -127,6 +128,9 @@ void subghz_remote_app_free(SubGhzRemoteApp* app) {
|
||||
view_dispatcher_remove_view(app->view_dispatcher, SubRemViewIDRemote);
|
||||
subrem_view_remote_free(app->subrem_remote_view);
|
||||
|
||||
scene_manager_free(app->scene_manager);
|
||||
view_dispatcher_free(app->view_dispatcher);
|
||||
|
||||
subghz_receiver_free(app->receiver);
|
||||
subghz_environment_free(app->environment);
|
||||
subghz_setting_free(app->setting);
|
||||
|
||||
@@ -51,6 +51,7 @@ SubRemSubFilePreset* subrem_sub_file_preset_alloc() {
|
||||
sub_preset->label = furi_string_alloc_set_str("N/A");
|
||||
|
||||
sub_preset->type = SubGhzProtocolTypeUnknown;
|
||||
sub_preset->load_state = SubRemLoadSubStateNotSet;
|
||||
|
||||
return sub_preset;
|
||||
}
|
||||
@@ -77,6 +78,7 @@ static void subrem_sub_file_preset_reset(SubRemSubFilePreset* sub_preset) {
|
||||
stream_clean(fff_data_stream);
|
||||
|
||||
sub_preset->type = SubGhzProtocolTypeUnknown;
|
||||
sub_preset->load_state = SubRemLoadSubStateNotSet;
|
||||
}
|
||||
|
||||
void subrem_map_preset_reset(SubGhzRemoteApp* app) {
|
||||
@@ -108,6 +110,7 @@ static bool subrem_map_preset_load(SubGhzRemoteApp* app, FlipperFormat* fff_data
|
||||
#endif
|
||||
path_extract_filename(sub_preset->file_path, sub_preset->label, true);
|
||||
} else {
|
||||
// Preload seccesful
|
||||
FURI_LOG_I(
|
||||
TAG,
|
||||
"%-5s: %s %s",
|
||||
@@ -115,6 +118,7 @@ static bool subrem_map_preset_load(SubGhzRemoteApp* app, FlipperFormat* fff_data
|
||||
furi_string_get_cstr(sub_preset->label),
|
||||
furi_string_get_cstr(sub_preset->file_path));
|
||||
ret = true;
|
||||
sub_preset->load_state = SubRemLoadSubStatePreloaded;
|
||||
}
|
||||
flipper_format_rewind(fff_data_file);
|
||||
}
|
||||
@@ -129,23 +133,31 @@ bool subrem_save_protocol_to_file(FlipperFormat* flipper_format, const char* dev
|
||||
Stream* flipper_format_stream = flipper_format_get_raw_stream(flipper_format);
|
||||
|
||||
bool saved = false;
|
||||
uint32_t repeat = 200;
|
||||
FuriString* file_dir = furi_string_alloc();
|
||||
|
||||
path_extract_dirname(dev_file_name, file_dir);
|
||||
do {
|
||||
//removing additional fields
|
||||
// removing additional fields
|
||||
flipper_format_delete_key(flipper_format, "Repeat");
|
||||
//flipper_format_delete_key(flipper_format, "Manufacture");
|
||||
// flipper_format_delete_key(flipper_format, "Manufacture");
|
||||
|
||||
if(!storage_simply_remove(storage, dev_file_name)) {
|
||||
break;
|
||||
}
|
||||
|
||||
//ToDo check Write
|
||||
stream_seek(flipper_format_stream, 0, StreamOffsetFromStart);
|
||||
stream_save_to_file(flipper_format_stream, storage, dev_file_name, FSOM_CREATE_ALWAYS);
|
||||
|
||||
if(!flipper_format_insert_or_update_uint32(flipper_format, "Repeat", &repeat, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable Repeat");
|
||||
break;
|
||||
}
|
||||
|
||||
saved = true;
|
||||
} while(0);
|
||||
|
||||
furi_string_free(file_dir);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
return saved;
|
||||
@@ -260,21 +272,26 @@ bool subrem_tx_stop_sub(SubGhzRemoteApp* app, bool forced) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool subrem_map_preset_check(SubGhzRemoteApp* app, FlipperFormat* fff_data_file) {
|
||||
static SubRemLoadMapState
|
||||
subrem_map_preset_check(SubGhzRemoteApp* app, FlipperFormat* fff_data_file) {
|
||||
furi_assert(app);
|
||||
FuriString* temp_str = furi_string_alloc();
|
||||
uint32_t temp_data32;
|
||||
bool ret = false;
|
||||
bool sub_preset_loaded = false;
|
||||
bool all_loaded = true;
|
||||
SubRemLoadMapState ret = SubRemLoadMapStateErrorBrokenFile;
|
||||
SubRemLoadSubState sub_preset_loaded;
|
||||
SubRemSubFilePreset* sub_preset;
|
||||
|
||||
uint32_t repeat = 200;
|
||||
for(uint8_t i = 0; i < SubRemSubKeyNameMaxCount; i++) {
|
||||
sub_preset = app->subs_preset[i];
|
||||
sub_preset_loaded = false;
|
||||
if(furi_string_empty(sub_preset->file_path)) {
|
||||
// FURI_LOG_I(TAG, "Empty file path");
|
||||
continue;
|
||||
}
|
||||
|
||||
sub_preset_loaded = SubRemLoadSubStateErrorNoFile;
|
||||
|
||||
repeat = 200;
|
||||
do {
|
||||
if(!flipper_format_file_open_existing(
|
||||
fff_data_file, furi_string_get_cstr(sub_preset->file_path))) {
|
||||
@@ -296,6 +313,7 @@ static bool subrem_map_preset_check(SubGhzRemoteApp* app, FlipperFormat* fff_dat
|
||||
}
|
||||
|
||||
//Load frequency
|
||||
sub_preset_loaded = SubRemLoadSubStateErrorFreq;
|
||||
if(!flipper_format_read_uint32(fff_data_file, "Frequency", &temp_data32, 1)) {
|
||||
FURI_LOG_W(TAG, "Cannot read frequency. Set default frequency");
|
||||
sub_preset->freq_preset.frequency =
|
||||
@@ -308,6 +326,7 @@ static bool subrem_map_preset_check(SubGhzRemoteApp* app, FlipperFormat* fff_dat
|
||||
}
|
||||
|
||||
//Load preset
|
||||
sub_preset_loaded = SubRemLoadSubStateErrorMod;
|
||||
if(!flipper_format_read_string(fff_data_file, "Preset", temp_str)) {
|
||||
FURI_LOG_E(TAG, "Missing Preset");
|
||||
break;
|
||||
@@ -320,6 +339,7 @@ static bool subrem_map_preset_check(SubGhzRemoteApp* app, FlipperFormat* fff_dat
|
||||
}
|
||||
|
||||
//Load protocol
|
||||
sub_preset_loaded = SubRemLoadSubStateErrorProtocol;
|
||||
if(!flipper_format_read_string(fff_data_file, "Protocol", temp_str)) {
|
||||
FURI_LOG_E(TAG, "Missing Protocol");
|
||||
break;
|
||||
@@ -361,8 +381,14 @@ static bool subrem_map_preset_check(SubGhzRemoteApp* app, FlipperFormat* fff_dat
|
||||
FURI_LOG_E(TAG, "Protocol does not support transmission");
|
||||
}
|
||||
|
||||
sub_preset_loaded = true;
|
||||
ret |= true;
|
||||
if(!flipper_format_insert_or_update_uint32(fff_data, "Repeat", &repeat, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable Repeat");
|
||||
break;
|
||||
}
|
||||
|
||||
sub_preset_loaded = SubRemLoadSubStateOK;
|
||||
ret = SubRemLoadMapStateNotAllOK;
|
||||
|
||||
#if FURI_DEBUG
|
||||
FURI_LOG_I(TAG, "%-16s - protocol Loaded", furi_string_get_cstr(sub_preset->label));
|
||||
#endif
|
||||
@@ -371,9 +397,15 @@ static bool subrem_map_preset_check(SubGhzRemoteApp* app, FlipperFormat* fff_dat
|
||||
// TODO:
|
||||
// Load file state logic
|
||||
// Label depending on the state
|
||||
// Move to remote scene
|
||||
|
||||
if(!sub_preset_loaded) {
|
||||
if(sub_preset_loaded != SubRemLoadSubStateOK) {
|
||||
furi_string_set_str(sub_preset->label, "N/A");
|
||||
all_loaded = false;
|
||||
}
|
||||
|
||||
if(ret != SubRemLoadMapStateErrorBrokenFile && all_loaded) {
|
||||
ret = SubRemLoadMapStateOK;
|
||||
}
|
||||
|
||||
flipper_format_file_close(fff_data_file);
|
||||
@@ -383,7 +415,7 @@ static bool subrem_map_preset_check(SubGhzRemoteApp* app, FlipperFormat* fff_dat
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool subrem_map_file_load(SubGhzRemoteApp* app, const char* file_path) {
|
||||
SubRemLoadMapState subrem_map_file_load(SubGhzRemoteApp* app, const char* file_path) {
|
||||
furi_assert(app);
|
||||
furi_assert(file_path);
|
||||
#if FURI_DEBUG
|
||||
@@ -391,7 +423,7 @@ bool subrem_map_file_load(SubGhzRemoteApp* app, const char* file_path) {
|
||||
#endif
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
|
||||
bool ret = false;
|
||||
SubRemLoadMapState ret = SubRemLoadMapStateErrorOpenError;
|
||||
#if FURI_DEBUG
|
||||
FURI_LOG_I(TAG, "Open Map File..");
|
||||
#endif
|
||||
@@ -399,20 +431,23 @@ bool subrem_map_file_load(SubGhzRemoteApp* app, const char* file_path) {
|
||||
|
||||
if(!flipper_format_file_open_existing(fff_data_file, file_path)) {
|
||||
FURI_LOG_E(TAG, "Could not open MAP file %s", file_path);
|
||||
ret = SubRemLoadMapStateErrorOpenError;
|
||||
} else {
|
||||
if(!subrem_map_preset_load(app, fff_data_file)) {
|
||||
FURI_LOG_E(TAG, "Could no Sub file path in MAP file");
|
||||
// ret = // error for popup
|
||||
} else if(
|
||||
(flipper_format_file_close(fff_data_file)) &&
|
||||
(subrem_map_preset_check(app, fff_data_file))) {
|
||||
FURI_LOG_I(TAG, "Load Map File Seccesful");
|
||||
ret = true;
|
||||
} else if(!flipper_format_file_close(fff_data_file)) {
|
||||
ret = SubRemLoadMapStateErrorOpenError;
|
||||
} else {
|
||||
ret = subrem_map_preset_check(app, fff_data_file);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Popup for error or return error type
|
||||
if(!ret) {
|
||||
if(ret == SubRemLoadMapStateOK) {
|
||||
FURI_LOG_I(TAG, "Load Map File Seccesful");
|
||||
} else if(ret == SubRemLoadMapStateNotAllOK) {
|
||||
FURI_LOG_I(TAG, "Load Map File Seccesful [Not all files]");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Broken Map File");
|
||||
}
|
||||
|
||||
@@ -420,7 +455,6 @@ bool subrem_map_file_load(SubGhzRemoteApp* app, const char* file_path) {
|
||||
flipper_format_free(fff_data_file);
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -436,10 +470,8 @@ SubRemLoadMapState subrem_load_from_file(SubGhzRemoteApp* app) {
|
||||
|
||||
// Input events and views are managed by file_select
|
||||
if(!dialog_file_browser_show(app->dialogs, app->file_path, app->file_path, &browser_options)) {
|
||||
} else if(subrem_map_file_load(app, furi_string_get_cstr(app->file_path))) {
|
||||
ret = SubRemLoadMapStateOK;
|
||||
} else {
|
||||
ret = SubRemLoadMapStateError;
|
||||
ret = subrem_map_file_load(app, furi_string_get_cstr(app->file_path));
|
||||
}
|
||||
|
||||
furi_string_free(file_path);
|
||||
|
||||
@@ -42,6 +42,7 @@ typedef struct {
|
||||
FuriString* protocaol_name;
|
||||
FuriString* label;
|
||||
SubGhzProtocolType type;
|
||||
SubRemLoadSubState load_state;
|
||||
} SubRemSubFilePreset;
|
||||
|
||||
SubRemSubFilePreset* subrem_sub_file_preset_alloc();
|
||||
@@ -70,8 +71,6 @@ typedef struct {
|
||||
bool tx_running;
|
||||
|
||||
uint8_t chusen_sub;
|
||||
|
||||
// TODO: LoadFileError
|
||||
} SubGhzRemoteApp;
|
||||
|
||||
SubRemLoadMapState subrem_load_from_file(SubGhzRemoteApp* app);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <input/input.h>
|
||||
#include <gui/elements.h>
|
||||
|
||||
#define SUBREM_VIEW_REMOTE_MAX_LABEL_LENGTH 16
|
||||
#define SUBREM_VIEW_REMOTE_MAX_LABEL_LENGTH 12
|
||||
|
||||
struct SubRemViewRemote {
|
||||
View* view;
|
||||
|
||||
Reference in New Issue
Block a user