Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FL-3743] SubGhz: UI update #3352

Merged
merged 7 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions applications/main/subghz/helpers/subghz_custom_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef enum {
//SubGhzCustomEvent
SubGhzCustomEventSceneDeleteSuccess = 100,
SubGhzCustomEventSceneDelete,
SubGhzCustomEventSceneDeleteBack,
SubGhzCustomEventSceneDeleteRAW,
SubGhzCustomEventSceneDeleteRAWBack,

Expand Down Expand Up @@ -70,5 +71,6 @@ typedef enum {
SubGhzCustomEventViewTransmitterBack,
SubGhzCustomEventViewTransmitterSendStart,
SubGhzCustomEventViewTransmitterSendStop,
SubGhzCustomEventViewTransmitterSendSave,
SubGhzCustomEventViewTransmitterError,
} SubGhzCustomEvent;
54 changes: 33 additions & 21 deletions applications/main/subghz/scenes/subghz_scene_delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,57 @@ void subghz_scene_delete_callback(GuiButtonType result, InputType type, void* co
SubGhz* subghz = context;
if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneDelete);
} else if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubGhzCustomEventSceneDeleteBack);
}
}

void subghz_scene_delete_on_enter(void* context) {
SubGhz* subghz = context;

FuriString* frequency_str;
FuriString* modulation_str;
FuriString* text_out;
FuriString* text;
text_out = furi_string_alloc();
text = furi_string_alloc();

path_extract_filename(subghz->file_path, text, true);
furi_string_cat_printf(text_out, "\e#Delete %s?\e#\n", furi_string_get_cstr(text));

furi_string_reset(text);
subghz_protocol_decoder_base_get_string(subghz_txrx_get_decoder(subghz->txrx), text);

size_t dot = furi_string_search_char(text, '\r');
if(dot > 0) {
furi_string_left(text, dot);
}
furi_string_cat_printf(text_out, "%s\n", furi_string_get_cstr(text));

furi_string_free(text);

frequency_str = furi_string_alloc();
modulation_str = furi_string_alloc();
text = furi_string_alloc();

subghz_txrx_get_frequency_and_modulation(subghz->txrx, frequency_str, modulation_str);
widget_add_string_element(
subghz->widget,
78,
0,
AlignLeft,
AlignTop,
FontSecondary,
furi_string_get_cstr(frequency_str));

widget_add_string_element(
subghz->widget,
113,
0,
AlignLeft,
AlignTop,
FontSecondary,
furi_string_cat_printf(
text_out,
"%s %s",
furi_string_get_cstr(frequency_str),
furi_string_get_cstr(modulation_str));
subghz_protocol_decoder_base_get_string(subghz_txrx_get_decoder(subghz->txrx), text);
widget_add_string_multiline_element(
subghz->widget, 0, 0, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(text));

widget_add_text_box_element(
subghz->widget, 0, 0, 128, 54, AlignCenter, AlignTop, furi_string_get_cstr(text_out), false);

furi_string_free(frequency_str);
furi_string_free(modulation_str);
furi_string_free(text);
furi_string_free(text_out);

widget_add_button_element(
subghz->widget, GuiButtonTypeRight, "Delete", subghz_scene_delete_callback, subghz);
widget_add_button_element(
subghz->widget, GuiButtonTypeLeft, "Cancel", subghz_scene_delete_callback, subghz);

view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
}
Expand All @@ -63,6 +73,8 @@ bool subghz_scene_delete_on_event(void* context, SceneManagerEvent event) {
subghz->scene_manager, SubGhzSceneStart);
}
return true;
} else if(event.event == SubGhzCustomEventSceneDeleteBack) {
return scene_manager_previous_scene(subghz->scene_manager);
}
}
return false;
Expand Down
43 changes: 16 additions & 27 deletions applications/main/subghz/scenes/subghz_scene_delete_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,37 @@ void subghz_scene_delete_raw_on_enter(void* context) {
SubGhz* subghz = context;
FuriString* frequency_str;
FuriString* modulation_str;

frequency_str = furi_string_alloc();
modulation_str = furi_string_alloc();

char delete_str[SUBGHZ_MAX_LEN_NAME + 16];
FuriString* text_out;
FuriString* file_name;
text_out = furi_string_alloc();
file_name = furi_string_alloc();

path_extract_filename(subghz->file_path, file_name, true);
snprintf(delete_str, sizeof(delete_str), "\e#Delete %s?\e#", furi_string_get_cstr(file_name));
furi_string_cat_printf(
text_out, "\e#Delete %s?\e#\nRAW signal\n", furi_string_get_cstr(file_name));
furi_string_free(file_name);

widget_add_text_box_element(
subghz->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, delete_str, false);

widget_add_string_element(
subghz->widget, 38, 25, AlignLeft, AlignTop, FontSecondary, "RAW signal");
frequency_str = furi_string_alloc();
modulation_str = furi_string_alloc();
subghz_txrx_get_frequency_and_modulation(subghz->txrx, frequency_str, modulation_str);
widget_add_string_element(
subghz->widget,
35,
37,
AlignLeft,
AlignTop,
FontSecondary,
furi_string_get_cstr(frequency_str));

widget_add_string_element(
subghz->widget,
72,
37,
AlignLeft,
AlignTop,
FontSecondary,
furi_string_cat_printf(
text_out,
"%s %s",
furi_string_get_cstr(frequency_str),
furi_string_get_cstr(modulation_str));

widget_add_text_box_element(
subghz->widget, 0, 0, 128, 54, AlignCenter, AlignTop, furi_string_get_cstr(text_out), false);

furi_string_free(frequency_str);
furi_string_free(modulation_str);
furi_string_free(text_out);

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);
subghz->widget, GuiButtonTypeLeft, "Cancel", subghz_scene_delete_raw_callback, subghz);

view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
}
Expand Down
16 changes: 8 additions & 8 deletions applications/main/subghz/scenes/subghz_scene_need_saving.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ void subghz_scene_need_saving_callback(GuiButtonType result, InputType type, voi
void subghz_scene_need_saving_on_enter(void* context) {
SubGhz* subghz = context;

widget_add_string_multiline_element(
subghz->widget, 64, 13, AlignCenter, AlignCenter, FontPrimary, "Exit to Sub-GHz Menu?");
widget_add_string_multiline_element(
widget_add_text_box_element(
subghz->widget,
64,
32,
0,
0,
128,
54,
AlignCenter,
AlignCenter,
FontSecondary,
"All unsaved data\nwill be lost!");
AlignTop,
"\e#Exit to Sub-GHz Menu?\e#\nAll unsaved data will be lost",
false);

widget_add_button_element(
subghz->widget, GuiButtonTypeRight, "Stay", subghz_scene_need_saving_callback, subghz);
Expand Down
105 changes: 39 additions & 66 deletions applications/main/subghz/scenes/subghz_scene_receiver_info.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
#include "../subghz_i.h"
#include "../helpers/subghz_custom_event.h"
#include "../views/transmitter.h"

void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, void* context) {
void subghz_scene_receiver_info_callback(SubGhzCustomEvent event, void* context) {
furi_assert(context);
SubGhz* subghz = context;

if((result == GuiButtonTypeCenter) && (type == InputTypePress)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubGhzCustomEventSceneReceiverInfoTxStart);
} else if((result == GuiButtonTypeCenter) && (type == InputTypeRelease)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubGhzCustomEventSceneReceiverInfoTxStop);
} else if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubGhzCustomEventSceneReceiverInfoSave);
}
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
}

static bool subghz_scene_receiver_info_update_parser(void* context) {
Expand All @@ -37,74 +28,52 @@ static bool subghz_scene_receiver_info_update_parser(void* context) {
preset->data,
preset->data_size);

FuriString* key_str = furi_string_alloc();
FuriString* frequency_str = furi_string_alloc();
FuriString* modulation_str = furi_string_alloc();

subghz_protocol_decoder_base_get_string(subghz_txrx_get_decoder(subghz->txrx), key_str);
subghz_txrx_get_frequency_and_modulation(subghz->txrx, frequency_str, modulation_str);
subghz_view_transmitter_add_data_to_show(
subghz->subghz_transmitter,
furi_string_get_cstr(key_str),
furi_string_get_cstr(frequency_str),
furi_string_get_cstr(modulation_str),
subghz_txrx_protocol_is_transmittable(subghz->txrx, true));

furi_string_free(frequency_str);
furi_string_free(modulation_str);
furi_string_free(key_str);

subghz_view_transmitter_set_radio_device_type(
subghz->subghz_transmitter, subghz_txrx_radio_device_get(subghz->txrx));
subghz_view_transmitter_set_model_type(
subghz->subghz_transmitter, SubGhzViewTransmitterModelTypeInfo);

return true;
}
return false;
}

void subghz_scene_receiver_info_on_enter(void* context) {
SubGhz* subghz = context;

if(subghz_scene_receiver_info_update_parser(subghz)) {
FuriString* frequency_str = furi_string_alloc();
FuriString* modulation_str = furi_string_alloc();
FuriString* text = furi_string_alloc();

subghz_txrx_get_frequency_and_modulation(subghz->txrx, frequency_str, modulation_str);
widget_add_string_element(
subghz->widget,
78,
0,
AlignLeft,
AlignTop,
FontSecondary,
furi_string_get_cstr(frequency_str));

widget_add_string_element(
subghz->widget,
113,
0,
AlignLeft,
AlignTop,
FontSecondary,
furi_string_get_cstr(modulation_str));
subghz_protocol_decoder_base_get_string(subghz_txrx_get_decoder(subghz->txrx), text);
widget_add_string_multiline_element(
subghz->widget, 0, 0, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(text));

furi_string_free(frequency_str);
furi_string_free(modulation_str);
furi_string_free(text);

if(subghz_txrx_protocol_is_serializable(subghz->txrx)) {
widget_add_button_element(
subghz->widget,
GuiButtonTypeRight,
"Save",
subghz_scene_receiver_info_callback,
subghz);
}
if(subghz_txrx_protocol_is_transmittable(subghz->txrx, true)) {
widget_add_button_element(
subghz->widget,
GuiButtonTypeCenter,
"Send",
subghz_scene_receiver_info_callback,
subghz);
}
} else {
widget_add_icon_element(subghz->widget, 83, 22, &I_WarningDolphinFlip_45x42);
widget_add_string_element(
subghz->widget, 13, 8, AlignLeft, AlignBottom, FontSecondary, "Error history parse.");
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubGhzCustomEventSceneShowErrorSub);
}

view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
subghz_view_transmitter_set_callback(
subghz->subghz_transmitter, subghz_scene_receiver_info_callback, subghz);

subghz->state_notifications = SubGhzNotificationStateIDLE;
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdTransmitter);
}

bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventSceneReceiverInfoTxStart) {
if(event.event == SubGhzCustomEventViewTransmitterSendStart) {
if(!subghz_scene_receiver_info_update_parser(subghz)) {
return false;
}
Expand All @@ -120,7 +89,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
subghz->state_notifications = SubGhzNotificationStateTx;
}
return true;
} else if(event.event == SubGhzCustomEventSceneReceiverInfoTxStop) {
} else if(event.event == SubGhzCustomEventViewTransmitterSendStop) {
//CC1101 Stop Tx -> Start RX
subghz->state_notifications = SubGhzNotificationStateIDLE;

Expand All @@ -129,7 +98,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
subghz_txrx_hopper_unpause(subghz->txrx);
subghz->state_notifications = SubGhzNotificationStateRx;
return true;
} else if(event.event == SubGhzCustomEventSceneReceiverInfoSave) {
} else if(event.event == SubGhzCustomEventViewTransmitterSendSave) {
//CC1101 Stop RX -> Save
subghz->state_notifications = SubGhzNotificationStateIDLE;
subghz_txrx_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF);
Expand All @@ -144,7 +113,11 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
}
return true;
} else if(event.event == SubGhzCustomEventSceneShowErrorSub) {
furi_string_set(subghz->error_str, "Error history parse.");
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub);
}

} else if(event.type == SceneManagerEventTypeTick) {
if(subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF) {
subghz_txrx_hopper_update(subghz->txrx);
Expand Down
10 changes: 7 additions & 3 deletions applications/main/subghz/scenes/subghz_scene_region_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ void subghz_scene_region_info_on_enter(void* context) {
SubGhz* subghz = context;
const FuriHalRegion* const region = furi_hal_region_get();
FuriString* buffer = furi_string_alloc();

if(region) {
furi_string_cat_printf(buffer, "Region: %s, bands:\n", region->country_code);
furi_string_cat_printf(buffer, "Region: %s\nBands:\n", region->country_code);
for(uint16_t i = 0; i < region->bands_count; ++i) {
furi_string_cat_printf(
buffer,
" %lu-%lu kHz\n",
"%lu-%lu kHz\n",
region->bands[i].start / 1000,
region->bands[i].end / 1000);
}
Expand All @@ -20,7 +21,10 @@ void subghz_scene_region_info_on_enter(void* context) {
}

widget_add_string_multiline_element(
subghz->widget, 0, 0, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(buffer));
subghz->widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "Region Information");

widget_add_string_multiline_element(
subghz->widget, 0, 13, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(buffer));

furi_string_free(buffer);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
Expand Down
2 changes: 1 addition & 1 deletion applications/main/subghz/scenes/subghz_scene_save_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet);
} else {
subghz_file_name_clear(subghz);
furi_string_reset(subghz->file_path_tmp);
}

scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveSuccess);
Expand Down
2 changes: 2 additions & 0 deletions applications/main/subghz/scenes/subghz_scene_saved.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ bool subghz_scene_saved_on_event(void* context, SceneManagerEvent event) {
}

void subghz_scene_saved_on_exit(void* context) {
SubGhz* subghz = context;
scene_manager_set_scene_state(subghz->scene_manager, SubGhzSceneSavedMenu, 0);
UNUSED(context);
}
Loading