Skip to content

Commit

Permalink
CFW Settings fixes for Extended Range / Bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
RogueMaster committed May 17, 2023
1 parent d4c5c1d commit dcd0225
Show file tree
Hide file tree
Showing 27 changed files with 53 additions and 78 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool cfw_app_apply(CfwApp* app) {
}

if(app->save_subghz) {
furi_hal_subghz_set_is_extended(app->subghz_extend);
furi_hal_subghz_set_extend_settings(app->subghz_extend, app->subghz_bypass);
}

if(app->save_name) {
Expand All @@ -75,24 +75,28 @@ bool cfw_app_apply(CfwApp* app) {

do {
if(!flipper_format_file_open_always(file, NAMESPOOF_PATH)) break;
if(!flipper_format_write_header_cstr(file, NAMESPOOF_HEADER, NAMESPOOF_VERSION))

if(!flipper_format_write_header_cstr(file, NAMESPOOF_HEADER, 1)) break;

if(!flipper_format_write_comment_cstr(
file, "Changing the value below will change your FlipperZero device name."))
break;
if(!flipper_format_write_comment_cstr(
file,
"Note: This is limited to 8 characters using the following: a-z, A-Z, 0-9, and _"))
break;
if(!flipper_format_write_comment_cstr(
file, "It cannot contain any other characters."))
break;

if(!flipper_format_write_string_cstr(file, "Name", app->device_name)) break;

} while(0);

flipper_format_free(file);
}
}

// if(app->save_level) {
// Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
// int32_t xp = app->xp_level > 1 ? dolphin_get_levels()[app->xp_level - 2] : 0;
// dolphin->state->data.icounter = xp + 1;
// dolphin->state->dirty = true;
// dolphin_state_save(dolphin->state);
// furi_record_close(RECORD_DOLPHIN);
// }

if(app->save_backlight) {
rgb_backlight_save_settings();
}
Expand All @@ -101,10 +105,6 @@ bool cfw_app_apply(CfwApp* app) {
CFW_SETTINGS_SAVE();
}

// if(app->show_slideshow) {
// callback_reboot(NULL);
// }

if(app->require_reboot) {
popup_set_header(app->popup, "Rebooting...", 64, 26, AlignCenter, AlignCenter);
popup_set_text(app->popup, "Applying changes...", 64, 40, AlignCenter, AlignCenter);
Expand Down Expand Up @@ -166,41 +166,9 @@ CfwApp* cfw_app_alloc() {
view_dispatcher_add_view(app->view_dispatcher, CfwAppViewPopup, popup_get_view(app->popup));

// Settings init

CfwSettings* cfw_settings = CFW_SETTINGS();

// app->asset_pack_index = 0;
// CharList_init(app->asset_pack_names);
Storage* storage = furi_record_open(RECORD_STORAGE);
// File* folder = storage_file_alloc(storage);
// FileInfo info;
// char* name = malloc(CFW_ASSETS_PACK_NAME_LEN);
// if(storage_dir_open(folder, CFW_ASSETS_PATH)) {
// while(storage_dir_read(folder, &info, name, CFW_ASSETS_PACK_NAME_LEN)) {
// if(info.flags & FSF_DIRECTORY) {
// char* copy = malloc(CFW_ASSETS_PACK_NAME_LEN);
// strlcpy(copy, name, CFW_ASSETS_PACK_NAME_LEN);
// uint idx = 0;
// if(strcmp(copy, "NSFW") != 0) {
// for(; idx < CharList_size(app->asset_pack_names); idx++) {
// char* comp = *CharList_get(app->asset_pack_names, idx);
// if(strcasecmp(copy, comp) < 0 && strcmp(comp, "NSFW") != 0) {
// break;
// }
// }
// }
// CharList_push_at(app->asset_pack_names, idx, copy);
// if(app->asset_pack_index != 0) {
// if(idx < app->asset_pack_index) app->asset_pack_index++;
// } else {
// if(strcmp(copy, CFW_settings->asset_pack) == 0)
// app->asset_pack_index = idx + 1;
// }
// }
// }
// }
// free(name);
// storage_file_free(folder);

CharList_init(app->mainmenu_app_names);
CharList_init(app->mainmenu_app_paths);
Expand Down Expand Up @@ -247,7 +215,7 @@ CfwApp* cfw_app_alloc() {
flipper_format_free(file);
furi_record_close(RECORD_STORAGE);

app->subghz_extend = furi_hal_subghz_get_is_extended();
furi_hal_subghz_get_extend_settings(&app->subghz_extend, &app->subghz_bypass);

strlcpy(app->device_name, furi_hal_version_get_name_ptr(), FURI_HAL_VERSION_ARRAY_NAME_LENGTH);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ typedef struct {
TextInput* text_input;
Popup* popup;

// CharList_t asset_pack_names;
// uint8_t asset_pack_index;
CharList_t mainmenu_app_names;
CharList_t mainmenu_app_paths;
uint8_t mainmenu_app_index;
Expand All @@ -51,18 +49,16 @@ typedef struct {
uint8_t subghz_hopper_index;
char subghz_freq_buffer[CFW_SUBGHZ_FREQ_BUFFER_SIZE];
bool subghz_extend;
bool subghz_bypass;
char device_name[FURI_HAL_VERSION_ARRAY_NAME_LENGTH];
// int32_t xp_level;
FuriString* version_tag;

bool save_mainmenu_apps;
bool save_subghz_frequencies;
bool save_subghz;
bool save_name;
// bool save_level;
bool save_backlight;
bool save_settings;
// bool show_slideshow;
bool require_reboot;
} CfwApp;

Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
enum VarItemListIndex {
VarItemListIndexSubghzFrequencies,
VarItemListIndexSubghzExtend,
VarItemListIndexSubghzBypass,
};

void cfw_app_scene_protocols_var_item_list_callback(void* context, uint32_t index) {
Expand All @@ -17,6 +18,13 @@ static void cfw_app_scene_protocols_subghz_extend_changed(VariableItem* item) {
app->save_subghz = true;
}

static void cfw_app_scene_protocols_subghz_bypass_changed(VariableItem* item) {
CfwApp* app = variable_item_get_context(item);
app->subghz_bypass = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, app->subghz_bypass ? "ON" : "OFF");
app->save_subghz = true;
}

void cfw_app_scene_protocols_on_enter(void* context) {
CfwApp* app = context;
CfwSettings* cfw_settings = CFW_SETTINGS();
Expand All @@ -30,6 +38,11 @@ void cfw_app_scene_protocols_on_enter(void* context) {
variable_item_set_current_value_index(item, app->subghz_extend);
variable_item_set_current_value_text(item, app->subghz_extend ? "ON" : "OFF");

item = variable_item_list_add(
var_item_list, "SubGHz Bypass", 2, cfw_app_scene_protocols_subghz_bypass_changed, app);
variable_item_set_current_value_index(item, app->subghz_bypass);
variable_item_set_current_value_text(item, app->subghz_bypass ? "ON" : "OFF");

variable_item_list_set_enter_callback(
var_item_list, cfw_app_scene_protocols_var_item_list_callback, app);

Expand Down
4 changes: 2 additions & 2 deletions firmware/targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1479,8 +1479,8 @@ Function,-,furi_hal_subghz_dump_state,void,
Function,+,furi_hal_subghz_enable_ext_power,_Bool,
Function,+,furi_hal_subghz_flush_rx,void,
Function,+,furi_hal_subghz_flush_tx,void,
Function,+,furi_hal_subghz_get_extend_settings,void,"_Bool*, _Bool*"
Function,+,furi_hal_subghz_get_external_power_disable,_Bool,
Function,+,furi_hal_subghz_get_is_extended,_Bool,
Function,+,furi_hal_subghz_get_lqi,uint8_t,
Function,+,furi_hal_subghz_get_radio_type,SubGhzRadioType,
Function,+,furi_hal_subghz_get_rolling_counter_mult,uint8_t,
Expand All @@ -1504,10 +1504,10 @@ Function,+,furi_hal_subghz_rx,void,
Function,+,furi_hal_subghz_rx_pipe_not_empty,_Bool,
Function,+,furi_hal_subghz_select_radio_type,void,SubGhzRadioType
Function,+,furi_hal_subghz_set_async_mirror_pin,void,const GpioPin*
Function,+,furi_hal_subghz_set_extend_settings,void,"_Bool, _Bool"
Function,+,furi_hal_subghz_set_external_power_disable,void,_Bool
Function,+,furi_hal_subghz_set_frequency,uint32_t,uint32_t
Function,+,furi_hal_subghz_set_frequency_and_path,uint32_t,uint32_t
Function,+,furi_hal_subghz_set_is_extended,void,_Bool
Function,+,furi_hal_subghz_set_path,void,FuriHalSubGhzPath
Function,+,furi_hal_subghz_set_rolling_counter_mult,void,uint8_t
Function,+,furi_hal_subghz_set_timestamp_file_names,void,_Bool
Expand Down
27 changes: 12 additions & 15 deletions firmware/targets/f7/furi_hal/furi_hal_subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,21 +448,22 @@ uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value) {
return value;
}

bool furi_hal_subghz_get_is_extended() {
bool is_extended = false;
void furi_hal_subghz_get_extend_settings(bool* extend, bool* bypass) {
*extend = false;
*bypass = false;
Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* file = flipper_format_file_alloc(storage);

if(flipper_format_file_open_existing(file, "/ext/subghz/assets/extend_range.txt")) {
flipper_format_read_bool(file, "use_ext_range_at_own_risk", &is_extended, 1);
flipper_format_read_bool(file, "use_ext_range_at_own_risk", extend, 1);
flipper_format_read_bool(file, "ignore_default_tx_region", bypass, 1);
}

flipper_format_free(file);
furi_record_close(RECORD_STORAGE);
return is_extended;
}

void furi_hal_subghz_set_is_extended(bool is_extended) {
void furi_hal_subghz_set_extend_settings(bool extend, bool bypass) {
Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* file = flipper_format_file_alloc(storage);

Expand All @@ -472,7 +473,11 @@ void furi_hal_subghz_set_is_extended(bool is_extended) {
if(!flipper_format_write_comment_cstr(
file, "Whether to allow extended ranges that can break your flipper"))
break;
if(!flipper_format_write_bool(file, "use_ext_range_at_own_risk", &is_extended, 1)) break;
if(!flipper_format_write_bool(file, "use_ext_range_at_own_risk", &extend, 1)) break;
if(!flipper_format_write_comment_cstr(
file, "Whether to ignore the default TX region settings"))
break;
if(!flipper_format_write_bool(file, "ignore_default_tx_region", &bypass, 1)) break;
} while(0);

flipper_format_free(file);
Expand All @@ -483,15 +488,7 @@ bool furi_hal_subghz_is_tx_allowed(uint32_t value) {
//checking regional settings
bool is_extended = false;
bool is_allowed = false;

Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
if(flipper_format_file_open_existing(fff_data_file, "/ext/subghz/assets/extend_range.txt")) {
flipper_format_read_bool(fff_data_file, "use_ext_range_at_own_risk", &is_extended, 1);
flipper_format_read_bool(fff_data_file, "ignore_default_tx_region", &is_allowed, 1);
}
flipper_format_free(fff_data_file);
furi_record_close(RECORD_STORAGE);
furi_hal_subghz_get_extend_settings(&is_extended, &is_allowed);

switch(furi_hal_version_get_hw_region()) {
case FuriHalVersionRegionEuRu:
Expand Down
10 changes: 6 additions & 4 deletions firmware/targets/f7/furi_hal/furi_hal_subghz.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,17 @@ uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value);

/** Read extend and bypass settings values into out params
*
* @return is_extended bool
* @param extend pointer to bool for extend
* @param bypass pointer to bool for bypass
*/
bool furi_hal_subghz_get_is_extended();
void furi_hal_subghz_get_extend_settings(bool* extend, bool* bypass);

/** Set extend and bypass settings values to file
*
* @param is_extended bool for extend
* @param extend bool for extend
* @param bypass bool for bypass
*/
void furi_hal_subghz_set_is_extended(bool is_extended);
void furi_hal_subghz_set_extend_settings(bool extend, bool bypass);

/** Сheck if transmission is allowed on this frequency with your current config
*
Expand Down
4 changes: 2 additions & 2 deletions firmware/targets/f7/src/recovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ void flipper_boot_recovery_exec() {
}

if(!counter) {
furi_hal_rtc_set_flag(FuriHalRtcFlagResetPin);
furi_hal_rtc_set_flag(FuriHalRtcFlagFactoryReset);
furi_hal_rtc_set_pin_fails(0);
furi_hal_rtc_reset_flag(FuriHalRtcFlagLock);
}
}
}
3 changes: 1 addition & 2 deletions firmware/targets/furi_hal_include/furi_hal_rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ typedef enum {
FuriHalRtcFlagHandOrient = (1 << 4),
FuriHalRtcFlagLegacySleep = (1 << 5),
FuriHalRtcFlagStealthMode = (1 << 6),
FuriHalRtcFlagResetPin = (1 << 7),
} FuriHalRtcFlag;

typedef enum {
Expand Down Expand Up @@ -258,4 +257,4 @@ uint32_t furi_hal_rtc_datetime_to_timestamp(FuriHalRtcDateTime* datetime);

#ifdef __cplusplus
}
#endif
#endif

0 comments on commit dcd0225

Please sign in to comment.