[FL-2139] SubGhz: refactoring GUI SubGhz (#910)

* SubGhz: refactoring GUI ReadRAW
* SubGhz: replacing memcpy with strcpy
* SubGhz: fix button name "Mode",  fix delete scene, fix show name when loading a key
* SubGhz: refactoring GUI SubGhz
* scene_manager: add exit from last scene API
* subghz: stop scene manager before stopping view dispatcher

Co-authored-by: gornekich <n.gorbadey@gmail.com>
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Skorpionm
2021-12-22 17:01:20 +04:00
committed by GitHub
parent 51aa169c3b
commit 3a86da5526
24 changed files with 580 additions and 159 deletions

View File

@@ -7,6 +7,7 @@ ADD_SCENE(subghz, save_success, SaveSuccess)
ADD_SCENE(subghz, saved, Saved)
ADD_SCENE(subghz, transmitter, Transmitter)
ADD_SCENE(subghz, show_error, ShowError)
ADD_SCENE(subghz, show_error_sub, ShowErrorSub)
ADD_SCENE(subghz, show_only_rx, ShowOnlyRx)
ADD_SCENE(subghz, saved_menu, SavedMenu)
ADD_SCENE(subghz, delete, Delete)
@@ -18,4 +19,6 @@ ADD_SCENE(subghz, test_packet, TestPacket)
ADD_SCENE(subghz, set_type, SetType)
ADD_SCENE(subghz, frequency_analyzer, FrequencyAnalyzer)
ADD_SCENE(subghz, read_raw, ReadRAW)
ADD_SCENE(subghz, more_raw, MoreRAW)
ADD_SCENE(subghz, delete_raw, DeleteRAW)
ADD_SCENE(subghz, need_saving, NeedSaving)

View File

@@ -50,7 +50,7 @@ bool subghz_scene_delete_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneDelete) {
memcpy(subghz->file_name_tmp, subghz->file_name, strlen(subghz->file_name) + 1);
strcpy(subghz->file_name_tmp, subghz->file_name);
if(subghz_delete_file(subghz)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneDeleteSuccess);
} else {

View File

@@ -0,0 +1,79 @@
#include "../subghz_i.h"
#include "../helpers/subghz_custom_event.h"
void subghz_scene_delete_raw_callback(GuiButtonType result, InputType type, void* context) {
furi_assert(context);
SubGhz* subghz = context;
if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubghzCustomEventSceneDeleteRAW);
} else if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubghzCustomEventSceneDeleteRAWBack);
}
}
void subghz_scene_delete_raw_on_enter(void* context) {
SubGhz* subghz = context;
string_t frequency_str;
string_t modulation_str;
string_t text;
string_init(frequency_str);
string_init(modulation_str);
string_init(text);
string_printf(text, "Delete\n%s?", subghz->file_name);
widget_add_string_multiline_element(
subghz->widget, 64, 0, AlignCenter, AlignTop, FontPrimary, string_get_cstr(text));
widget_add_string_element(
subghz->widget, 38, 25, AlignLeft, AlignTop, FontSecondary, "RAW signal");
subghz_get_frequency_modulation(subghz, frequency_str, modulation_str);
widget_add_string_element(
subghz->widget, 35, 37, AlignLeft, AlignTop, FontSecondary, string_get_cstr(frequency_str));
widget_add_string_element(
subghz->widget,
72,
37,
AlignLeft,
AlignTop,
FontSecondary,
string_get_cstr(modulation_str));
string_clear(frequency_str);
string_clear(modulation_str);
string_clear(text);
widget_add_button_element(
subghz->widget, GuiButtonTypeRight, "Delete", subghz_scene_delete_raw_callback, subghz);
widget_add_button_element(
subghz->widget, GuiButtonTypeLeft, "Back", subghz_scene_delete_raw_callback, subghz);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewWidget);
}
bool subghz_scene_delete_raw_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneDeleteRAW) {
strcpy(subghz->file_name_tmp, subghz->file_name);
if(subghz_delete_file(subghz)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneDeleteSuccess);
} else {
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
}
return true;
} else if(event.event == SubghzCustomEventSceneDeleteRAWBack) {
return scene_manager_previous_scene(subghz->scene_manager);
}
}
return false;
}
void subghz_scene_delete_raw_on_exit(void* context) {
SubGhz* subghz = context;
widget_clear(subghz->widget);
}

View File

@@ -26,8 +26,11 @@ bool subghz_scene_delete_success_on_event(void* context, SceneManagerEvent event
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneDeleteSuccess) {
return scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
if(!scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneSaved)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaved);
}
return true;
}
}
return false;

View File

@@ -0,0 +1,60 @@
#include "../subghz_i.h"
enum SubmenuIndex {
SubmenuIndexEdit,
SubmenuIndexDelete,
};
void subghz_scene_more_raw_submenu_callback(void* context, uint32_t index) {
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, index);
}
void subghz_scene_more_raw_on_enter(void* context) {
SubGhz* subghz = context;
submenu_add_item(
subghz->submenu,
"Edit name",
SubmenuIndexEdit,
subghz_scene_more_raw_submenu_callback,
subghz);
submenu_add_item(
subghz->submenu,
"Delete",
SubmenuIndexDelete,
subghz_scene_more_raw_submenu_callback,
subghz);
submenu_set_selected_item(
subghz->submenu, scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneMoreRAW));
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewMenu);
}
bool subghz_scene_more_raw_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubmenuIndexDelete) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubghzCustomEventManagerNoSet);
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneMoreRAW, SubmenuIndexDelete);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneDeleteRAW);
return true;
} else if(event.event == SubmenuIndexEdit) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneMoreRAW, SubmenuIndexEdit);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
return true;
}
}
return false;
}
void subghz_scene_more_raw_on_exit(void* context) {
SubGhz* subghz = context;
submenu_clean(subghz->submenu);
}

View File

@@ -6,6 +6,32 @@
#define RAW_FILE_NAME "Raw_temp"
bool subghz_scene_read_raw_update_filename(SubGhz* subghz) {
bool ret = false;
//set the path to read the file
if(strcmp(
subghz_protocol_raw_get_last_file_name(
(SubGhzProtocolRAW*)subghz->txrx->protocol_result),
"")) {
string_t temp_str;
string_init_printf(
temp_str,
"%s",
subghz_protocol_raw_get_last_file_name(
(SubGhzProtocolRAW*)subghz->txrx->protocol_result));
path_extract_filename_no_ext(string_get_cstr(temp_str), temp_str);
strcpy(subghz->file_name, string_get_cstr(temp_str));
string_printf(
temp_str, "%s/%s%s", SUBGHZ_APP_PATH_FOLDER, subghz->file_name, SUBGHZ_APP_EXTENSION);
subghz_protocol_raw_set_last_file_name(
(SubGhzProtocolRAW*)subghz->txrx->protocol_result, string_get_cstr(temp_str));
string_clear(temp_str);
ret = true;
}
return ret;
}
static void subghz_scene_read_raw_update_statusbar(void* context) {
furi_assert(context);
SubGhz* subghz = context;
@@ -40,15 +66,24 @@ void subghz_scene_read_raw_callback_end_tx(void* context) {
void subghz_scene_read_raw_on_enter(void* context) {
SubGhz* subghz = context;
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateBack) {
switch(subghz->txrx->rx_key_state) {
case SubGhzRxKeyStateBack:
subghz_read_raw_set_status(subghz->subghz_read_raw, SubghzReadRAWStatusIDLE, "");
} else if(subghz->txrx->rx_key_state == SubGhzRxKeyStateRAWLoad) {
break;
case SubGhzRxKeyStateRAWLoad:
subghz_read_raw_set_status(
subghz->subghz_read_raw, SubghzReadRAWStatusTX, subghz->file_name);
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey;
} else {
subghz->subghz_read_raw, SubghzReadRAWStatusLoadKeyTX, subghz->file_name);
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
break;
case SubGhzRxKeyStateRAWSave:
subghz_read_raw_set_status(
subghz->subghz_read_raw, SubghzReadRAWStatusSaveKey, subghz->file_name);
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
break;
default:
subghz_read_raw_set_status(subghz->subghz_read_raw, SubghzReadRAWStatusStart, "");
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
break;
}
subghz_scene_read_raw_update_statusbar(subghz);
@@ -96,53 +131,64 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
//Restore default setting
subghz->txrx->frequency = subghz_frequencies[subghz_frequencies_433_92];
subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
if(!scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneSaved)) {
if(!scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart)) {
scene_manager_stop(subghz->scene_manager);
view_dispatcher_stop(subghz->view_dispatcher);
}
}
}
return true;
break;
case SubghzCustomEventViewReadRAWTXRXStop:
//Stop TX
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
subghz_tx_stop(subghz);
subghz_sleep(subghz);
}
//Stop RX
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
subghz_rx_end(subghz);
subghz_sleep(subghz);
};
subghz->state_notifications = SubGhzNotificationStateIDLE;
return true;
break;
case SubghzCustomEventViewReadRAWConfig:
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubghzCustomEventManagerSet);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
return true;
break;
case SubghzCustomEventViewReadRAWErase:
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
return true;
break;
case SubghzCustomEventViewReadRAWVibro:
notification_message(subghz->notifications, &sequence_single_vibro);
return true;
break;
case SubghzCustomEventViewReadRAWSendStart:
//set the path to read the file
if(strcmp(
subghz_protocol_raw_get_last_file_name(
(SubGhzProtocolRAW*)subghz->txrx->protocol_result),
"")) {
string_t temp_str;
string_init_printf(
temp_str,
"%s",
subghz_protocol_raw_get_last_file_name(
(SubGhzProtocolRAW*)subghz->txrx->protocol_result));
path_extract_filename_no_ext(string_get_cstr(temp_str), temp_str);
strlcpy(
subghz->file_name,
string_get_cstr(temp_str),
strlen(string_get_cstr(temp_str)) + 1);
string_printf(
temp_str,
"%s/%s%s",
SUBGHZ_APP_PATH_FOLDER,
subghz->file_name,
SUBGHZ_APP_EXTENSION);
subghz_protocol_raw_set_last_file_name(
(SubGhzProtocolRAW*)subghz->txrx->protocol_result, string_get_cstr(temp_str));
string_clear(temp_str);
case SubghzCustomEventViewReadRAWMore:
if(subghz_scene_read_raw_update_filename(subghz)) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubghzCustomEventManagerSet);
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneMoreRAW);
return true;
} else {
furi_crash(NULL);
}
break;
case SubghzCustomEventViewReadRAWSendStart:
if(subghz_scene_read_raw_update_filename(subghz)) {
//start send
subghz->state_notifications = SubGhzNotificationStateIDLE;
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
@@ -154,12 +200,12 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
} else {
subghz->state_notifications = SubGhzNotificationStateTX;
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey;
}
}
}
return true;
break;
case SubghzCustomEventViewReadRAWSendStop:
subghz->state_notifications = SubGhzNotificationStateIDLE;
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
@@ -169,6 +215,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
subghz_read_raw_stop_send(subghz->subghz_read_raw);
return true;
break;
case SubghzCustomEventViewReadRAWIDLE:
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
subghz_rx_end(subghz);
@@ -182,8 +229,8 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
return true;
break;
case SubghzCustomEventViewReadRAWREC:
case SubghzCustomEventViewReadRAWREC:
if(subghz->txrx->rx_key_state != SubGhzRxKeyStateIDLE) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
} else {
@@ -199,42 +246,17 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
subghz_rx(subghz, subghz->txrx->frequency);
}
subghz->state_notifications = SubGhzNotificationStateRX;
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey;
} else {
string_set(subghz->error_str, "No SD card");
string_set(subghz->error_str, "Function requires\nan SD card.");
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
}
}
return true;
break;
case SubghzCustomEventViewReadRAWSave:
if(strcmp(
subghz_protocol_raw_get_last_file_name(
(SubGhzProtocolRAW*)subghz->txrx->protocol_result),
"")) {
string_t temp_str;
string_init_printf(
temp_str,
"%s",
subghz_protocol_raw_get_last_file_name(
(SubGhzProtocolRAW*)subghz->txrx->protocol_result));
path_extract_filename_no_ext(string_get_cstr(temp_str), temp_str);
strlcpy(
subghz->file_name,
string_get_cstr(temp_str),
strlen(string_get_cstr(temp_str)) + 1);
//set the path to read the file
string_printf(
temp_str,
"%s/%s%s",
SUBGHZ_APP_PATH_FOLDER,
subghz->file_name,
SUBGHZ_APP_EXTENSION);
subghz_protocol_raw_set_last_file_name(
(SubGhzProtocolRAW*)subghz->txrx->protocol_result, string_get_cstr(temp_str));
string_clear(temp_str);
if(subghz_scene_read_raw_update_filename(subghz)) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubghzCustomEventManagerSet);
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack;

View File

@@ -56,6 +56,7 @@ void subghz_scene_add_to_history_callback(SubGhzProtocolCommon* parser, void* co
subghz_scene_receiver_update_statusbar(subghz);
}
string_clear(str_buff);
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey;
}
void subghz_scene_receiver_on_enter(void* context) {
@@ -64,6 +65,10 @@ void subghz_scene_receiver_on_enter(void* context) {
string_t str_buff;
string_init(str_buff);
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateIDLE) {
subghz_history_clean(subghz->txrx->history);
}
//Load history to receiver
subghz_receiver_exit(subghz->subghz_receiver);
for(uint8_t i = 0; i < subghz_history_get_item(subghz->txrx->history); i++) {
@@ -73,6 +78,7 @@ void subghz_scene_receiver_on_enter(void* context) {
subghz->subghz_receiver,
string_get_cstr(str_buff),
subghz_history_get_type_protocol(subghz->txrx->history, i));
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey;
}
string_clear(str_buff);
subghz_scene_receiver_update_statusbar(subghz);
@@ -99,20 +105,26 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case SubghzCustomEventViewReceverBack:
// Stop CC1101 Rx
subghz->state_notifications = SubGhzNotificationStateIDLE;
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
subghz_rx_end(subghz);
subghz_sleep(subghz);
};
subghz_history_clean(subghz->txrx->history);
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
subghz->txrx->frequency = subghz_frequencies[subghz_frequencies_433_92];
subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
subghz->txrx->idx_menu_chosen = 0;
subghz_parser_enable_dump(subghz->txrx->parser, NULL, subghz);
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateExit;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
} else {
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
}
return true;
break;
case SubghzCustomEventViewReceverOK:

View File

@@ -20,7 +20,7 @@ void subghz_scene_save_name_on_enter(void* context) {
set_random_name(subghz->file_name, sizeof(subghz->file_name));
} else {
memcpy(subghz->file_name_tmp, subghz->file_name, strlen(subghz->file_name) + 1);
strcpy(subghz->file_name_tmp, subghz->file_name);
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) ==
SubghzCustomEventManagerSet) {
subghz_get_next_name_file(subghz);
@@ -42,8 +42,11 @@ void subghz_scene_save_name_on_enter(void* context) {
bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.type == SceneManagerEventTypeBack) {
strcpy(subghz->file_name, subghz->file_name_tmp);
scene_manager_previous_scene(subghz->scene_manager);
return true;
} else if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneSaveName) {
if(strcmp(subghz->file_name, "")) {
if(strcmp(subghz->file_name_tmp, "")) {
@@ -56,13 +59,15 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) {
SubghzCustomEventManagerSet) {
subghz_protocol_raw_set_last_file_name(
(SubGhzProtocolRAW*)subghz->txrx->protocol_result, subghz->file_name);
} else {
subghz_file_name_clear(subghz);
}
subghz_file_name_clear(subghz);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveSuccess);
return true;
} else {
string_set(subghz->error_str, "No name file");
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub);
return true;
}
}

View File

@@ -26,10 +26,13 @@ bool subghz_scene_save_success_on_event(void* context, SceneManagerEvent event)
if(event.event == SubghzCustomEventSceneSaveSuccess) {
if(!scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneReceiver)) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWSave;
if(!scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneReadRAW)) {
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
if(!scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneSaved)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaved);
}
}
}
return true;

View File

@@ -19,7 +19,7 @@ bool subghz_scene_set_type_submenu_to_find_protocol(void* context, const char* p
subghz->txrx->protocol_result = subghz_parser_get_by_name(subghz->txrx->parser, protocol_name);
if(subghz->txrx->protocol_result == NULL) {
string_set(subghz->error_str, "Protocol not found");
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub);
return false;
}
return true;
@@ -177,7 +177,8 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
generated_protocol = true;
} else {
generated_protocol = false;
string_set(subghz->error_str, "No manufactory key");
string_set(
subghz->error_str, "Function requires\nan SD card with\nfresh databases.");
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
}
}

View File

@@ -1,31 +1,74 @@
#include "../subghz_i.h"
#include "../helpers/subghz_custom_event.h"
void subghz_scene_show_error_popup_callback(void* context) {
void subghz_scene_show_error_callback(GuiButtonType result, InputType type, void* context) {
furi_assert(context);
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneShowError);
if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubghzCustomEventSceneShowErrorOk);
} else if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubghzCustomEventSceneShowErrorBack);
}
}
void subghz_scene_show_error_on_enter(void* context) {
SubGhz* subghz = context;
// Setup view
Popup* popup = subghz->popup;
popup_set_icon(popup, 32, 12, &I_DolphinFirstStart7_61x51);
popup_set_header(popup, string_get_cstr(subghz->error_str), 64, 8, AlignCenter, AlignBottom);
popup_set_timeout(popup, 1500);
popup_set_context(popup, subghz);
popup_set_callback(popup, subghz_scene_show_error_popup_callback);
popup_enable_timeout(popup);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewPopup);
widget_add_icon_element(subghz->widget, 0, 0, &I_SDQuestion_35x43);
widget_add_string_multiline_element(
subghz->widget,
81,
24,
AlignCenter,
AlignCenter,
FontSecondary,
string_get_cstr(subghz->error_str));
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneShowError) ==
SubghzCustomEventManagerSet) {
widget_add_button_element(
subghz->widget, GuiButtonTypeRight, "Ok", subghz_scene_show_error_callback, subghz);
}
widget_add_button_element(
subghz->widget, GuiButtonTypeLeft, "Back", subghz_scene_show_error_callback, subghz);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewWidget);
}
bool subghz_scene_show_error_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneShowError) {
if(event.type == SceneManagerEventTypeBack) {
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneShowError) ==
SubghzCustomEventManagerSet) {
return false;
} else {
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
}
return true;
} else if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneShowErrorOk) {
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneShowError) ==
SubghzCustomEventManagerSet) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneStart);
}
return true;
} else if(event.event == SubghzCustomEventSceneShowErrorBack) {
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneShowError) ==
SubghzCustomEventManagerSet) {
//exit app
if(!scene_manager_previous_scene(subghz->scene_manager)) {
scene_manager_stop(subghz->scene_manager);
view_dispatcher_stop(subghz->view_dispatcher);
}
} else {
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
}
return true;
}
}
@@ -34,15 +77,8 @@ bool subghz_scene_show_error_on_event(void* context, SceneManagerEvent event) {
void subghz_scene_show_error_on_exit(void* context) {
SubGhz* subghz = context;
// Clear view
Popup* popup = subghz->popup;
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
popup_set_icon(popup, 0, 0, NULL);
popup_set_callback(popup, NULL);
popup_set_context(popup, NULL);
popup_set_timeout(popup, 0);
popup_disable_timeout(popup);
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneShowError, SubghzCustomEventManagerNoSet);
widget_clear(subghz->widget);
string_reset(subghz->error_str);
}

View File

@@ -0,0 +1,48 @@
#include "../subghz_i.h"
#include "../helpers/subghz_custom_event.h"
void subghz_scene_show_error_sub_popup_callback(void* context) {
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneShowErrorSub);
}
void subghz_scene_show_error_sub_on_enter(void* context) {
SubGhz* subghz = context;
// Setup view
Popup* popup = subghz->popup;
popup_set_icon(popup, 32, 12, &I_DolphinFirstStart7_61x51);
popup_set_header(popup, string_get_cstr(subghz->error_str), 64, 8, AlignCenter, AlignBottom);
popup_set_timeout(popup, 1500);
popup_set_context(popup, subghz);
popup_set_callback(popup, subghz_scene_show_error_sub_popup_callback);
popup_enable_timeout(popup);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewPopup);
}
bool subghz_scene_show_error_sub_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneShowErrorSub) {
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
return true;
}
}
return false;
}
void subghz_scene_show_error_sub_on_exit(void* context) {
SubGhz* subghz = context;
// Clear view
Popup* popup = subghz->popup;
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
popup_set_icon(popup, 0, 0, NULL);
popup_set_callback(popup, NULL);
popup_set_context(popup, NULL);
popup_set_timeout(popup, 0);
popup_disable_timeout(popup);
string_reset(subghz->error_str);
}

View File

@@ -53,8 +53,12 @@ void subghz_scene_start_on_enter(void* context) {
bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.type == SceneManagerEventTypeBack) {
//exit app
scene_manager_stop(subghz->scene_manager);
view_dispatcher_stop(subghz->view_dispatcher);
return true;
} else if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubmenuIndexReadRAW) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexReadRAW);

View File

@@ -94,7 +94,7 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) {
return true;
} else if(event.event == SubghzCustomEventViewTransmitterError) {
string_set(subghz->error_str, "Protocol not found");
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub);
}
} else if(event.type == SceneManagerEventTypeTick) {
if(subghz->state_notifications == SubGhzNotificationStateTX) {