Skip to content

Commit

Permalink
Show region information in sub-GHz app (flipperdevices#2249)
Browse files Browse the repository at this point in the history
* Show region info in sub-GHz app
* SubGhz: reset widget on region info scene exit
* Format sources

Co-authored-by: あく <[email protected]>
  • Loading branch information
ntfshard and skotopes authored Jan 6, 2023
1 parent c24bea6 commit 2c450bd
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 8 deletions.
6 changes: 3 additions & 3 deletions applications/main/nfc/scenes/nfc_scene_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ enum SubmenuIndex {
SubmenuIndexDetectReader,
SubmenuIndexSaved,
SubmenuIndexExtraAction,
SubmenuIndexAddManualy,
SubmenuIndexAddManually,
SubmenuIndexDebug,
};

Expand All @@ -28,7 +28,7 @@ void nfc_scene_start_on_enter(void* context) {
submenu_add_item(
submenu, "Extra Actions", SubmenuIndexExtraAction, nfc_scene_start_submenu_callback, nfc);
submenu_add_item(
submenu, "Add Manually", SubmenuIndexAddManualy, nfc_scene_start_submenu_callback, nfc);
submenu, "Add Manually", SubmenuIndexAddManually, nfc_scene_start_submenu_callback, nfc);

if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
submenu_add_item(
Expand Down Expand Up @@ -68,7 +68,7 @@ bool nfc_scene_start_on_event(void* context, SceneManagerEvent event) {
} else if(event.event == SubmenuIndexExtraAction) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneExtraActions);
consumed = true;
} else if(event.event == SubmenuIndexAddManualy) {
} else if(event.event == SubmenuIndexAddManually) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneSetType);
consumed = true;
} else if(event.event == SubmenuIndexDebug) {
Expand Down
1 change: 1 addition & 0 deletions applications/main/subghz/scenes/subghz_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ ADD_SCENE(subghz, more_raw, MoreRAW)
ADD_SCENE(subghz, delete_raw, DeleteRAW)
ADD_SCENE(subghz, need_saving, NeedSaving)
ADD_SCENE(subghz, rpc, Rpc)
ADD_SCENE(subghz, region_info, RegionInfo)
39 changes: 39 additions & 0 deletions applications/main/subghz/scenes/subghz_scene_region_info.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "../subghz_i.h"

#include <furi_hal_region.h>

void subghz_scene_region_info_on_enter(void* context) {
SubGhz* subghz = context;
const FuriHalRegion* const region = furi_hal_region_get();
FuriString* buffer;
buffer = furi_string_alloc();
if(region) {
furi_string_cat_printf(buffer, "Region: %s, bands:\n", region->country_code);
for(uint16_t i = 0; i < region->bands_count; ++i) {
furi_string_cat_printf(
buffer,
" %lu-%lu kHz\n",
region->bands[i].start / 1000,
region->bands[i].end / 1000);
}
} else {
furi_string_cat_printf(buffer, "Region: N/A\n");
}

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

furi_string_free(buffer);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
}

bool subghz_scene_region_info_on_event(void* context, SceneManagerEvent event) {
UNUSED(context);
UNUSED(event);
return false;
}

void subghz_scene_region_info_on_exit(void* context) {
SubGhz* subghz = context;
widget_reset(subghz->widget);
}
20 changes: 16 additions & 4 deletions applications/main/subghz/scenes/subghz_scene_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ enum SubmenuIndex {
SubmenuIndexRead = 10,
SubmenuIndexSaved,
SubmenuIndexTest,
SubmenuIndexAddManualy,
SubmenuIndexAddManually,
SubmenuIndexFrequencyAnalyzer,
SubmenuIndexReadRAW,
SubmenuIndexShowRegionInfo
};

void subghz_scene_start_submenu_callback(void* context, uint32_t index) {
Expand All @@ -33,7 +34,7 @@ void subghz_scene_start_on_enter(void* context) {
submenu_add_item(
subghz->submenu,
"Add Manually",
SubmenuIndexAddManualy,
SubmenuIndexAddManually,
subghz_scene_start_submenu_callback,
subghz);
submenu_add_item(
Expand All @@ -42,6 +43,12 @@ void subghz_scene_start_on_enter(void* context) {
SubmenuIndexFrequencyAnalyzer,
subghz_scene_start_submenu_callback,
subghz);
submenu_add_item(
subghz->submenu,
"Region Information",
SubmenuIndexShowRegionInfo,
subghz_scene_start_submenu_callback,
subghz);
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
submenu_add_item(
subghz->submenu, "Test", SubmenuIndexTest, subghz_scene_start_submenu_callback, subghz);
Expand Down Expand Up @@ -76,9 +83,9 @@ bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) {
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexSaved);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaved);
return true;
} else if(event.event == SubmenuIndexAddManualy) {
} else if(event.event == SubmenuIndexAddManually) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexAddManualy);
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexAddManually);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetType);
return true;
} else if(event.event == SubmenuIndexFrequencyAnalyzer) {
Expand All @@ -92,6 +99,11 @@ bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) {
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexTest);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTest);
return true;
} else if(event.event == SubmenuIndexShowRegionInfo) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexShowRegionInfo);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneRegionInfo);
return true;
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ enum SubmenuIndex {
SubmenuIndexRead,
SubmenuIndexRunScript,
SubmenuIndexSaved,
SubmenuIndexAddManualy,
SubmenuIndexAddManually,
SubmenuIndexDebug,
};

Expand Down

0 comments on commit 2c450bd

Please sign in to comment.