Skip to content

Commit

Permalink
SubGhz App: change load custom presets
Browse files Browse the repository at this point in the history
  • Loading branch information
gid9798 committed Jun 13, 2023
1 parent d1c970b commit c4baf31
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 47 deletions.
83 changes: 37 additions & 46 deletions applications/main/subghz/subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,42 @@ static void subghz_rpc_command_callback(RpcAppSystemEvent event, void* context)
}
}

static void subghz_load_custom_presets(SubGhzSetting* setting) {
furi_assert(setting);

const char* presets[][2] = {
{"FM95",
"02 0D 0B 06 08 32 07 04 14 00 13 02 12 04 11 83 10 67 15 24 18 18 19 16 1D 91 1C 00 1B 07 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00"},

// #2-FSK 200khz BW / 135kHz Filter/ 15.86Khz Deviation + Ramping
{"FM15k",
"02 0D 03 47 08 32 0B 06 15 32 14 00 13 00 12 00 11 32 10 A7 18 18 19 1D 1D 92 1C 00 1B 04 20 FB 22 17 21 B6 00 00 00 12 0E 34 60 C5 C1 C0"},

// Pagers
{"Pagers",
"02 0D 07 04 08 32 0B 06 10 64 11 93 12 0C 13 02 14 00 15 15 18 18 19 16 1B 07 1C 00 1D 91 20 FB 21 56 22 10 00 00 C0 00 00 00 00 00 00 00"},

// # HND - FM preset
{"HND_1",
"02 0D 0B 06 08 32 07 04 14 00 13 02 12 04 11 36 10 69 15 32 18 18 19 16 1D 91 1C 00 1B 07 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00"},
};

FlipperFormat* fff_temp = flipper_format_string_alloc();

for(uint8_t i = 0; i < COUNT_OF(presets); i++) {
flipper_format_insert_or_update_string_cstr(fff_temp, "Custom_preset_data", presets[i][1]);

flipper_format_rewind(fff_temp);
subghz_setting_load_custom_preset(setting, presets[i][0], fff_temp);
}

flipper_format_free(fff_temp);

#ifdef FURI_DEBUG
subghz_setting_customs_presets_to_log(setting);
#endif
}

SubGhz* subghz_alloc(bool alloc_for_tx_only) {
SubGhz* subghz = malloc(sizeof(SubGhz));

Expand Down Expand Up @@ -177,52 +213,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {

SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx);

// Custom Presets load without using config file
if(!alloc_for_tx_only) {
FlipperFormat* temp_fm_preset = flipper_format_string_alloc();
flipper_format_write_string_cstr(
temp_fm_preset,
(const char*)"Custom_preset_data",
(const char*)"02 0D 0B 06 08 32 07 04 14 00 13 02 12 04 11 83 10 67 15 24 18 18 19 16 1D 91 1C 00 1B 07 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00");
flipper_format_rewind(temp_fm_preset);
subghz_setting_load_custom_preset(setting, (const char*)"FM95", temp_fm_preset);

flipper_format_free(temp_fm_preset);

// #2-FSK 200khz BW / 135kHz Filter/ 15.86Khz Deviation + Ramping
FlipperFormat* temp_fm_preset2 = flipper_format_string_alloc();
flipper_format_write_string_cstr(
temp_fm_preset2,
(const char*)"Custom_preset_data",
(const char*)"02 0D 03 47 08 32 0B 06 15 32 14 00 13 00 12 00 11 32 10 A7 18 18 19 1D 1D 92 1C 00 1B 04 20 FB 22 17 21 B6 00 00 00 12 0E 34 60 C5 C1 C0");
flipper_format_rewind(temp_fm_preset2);
subghz_setting_load_custom_preset(setting, (const char*)"FM15k", temp_fm_preset2);

flipper_format_free(temp_fm_preset2);

// Pagers
FlipperFormat* temp_fm_preset3 = flipper_format_string_alloc();
flipper_format_write_string_cstr(
temp_fm_preset3,
(const char*)"Custom_preset_data",
(const char*)"02 0D 07 04 08 32 0B 06 10 64 11 93 12 0C 13 02 14 00 15 15 18 18 19 16 1B 07 1C 00 1D 91 20 FB 21 56 22 10 00 00 C0 00 00 00 00 00 00 00");
flipper_format_rewind(temp_fm_preset3);
subghz_setting_load_custom_preset(setting, (const char*)"Pagers", temp_fm_preset3);

flipper_format_free(temp_fm_preset3);

// # HND - FM preset
FlipperFormat* temp_fm_preset4 = flipper_format_string_alloc();
flipper_format_write_string_cstr(
temp_fm_preset4,
(const char*)"Custom_preset_data",
(const char*)"02 0D 0B 06 08 32 07 04 14 00 13 02 12 04 11 36 10 69 15 32 18 18 19 16 1D 91 1C 00 1B 07 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00");
flipper_format_rewind(temp_fm_preset4);
subghz_setting_load_custom_preset(setting, (const char*)"HND_1", temp_fm_preset4);

flipper_format_free(temp_fm_preset4);
}
// custom presets loading - end
subghz_load_custom_presets(setting);

// Load last used values for Read, Read RAW, etc. or default
subghz->last_settings = subghz_last_settings_alloc();
Expand Down
3 changes: 2 additions & 1 deletion firmware/targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,30.1,,
Version,+,30.2,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
Expand Down Expand Up @@ -2784,6 +2784,7 @@ Function,+,subghz_receiver_search_decoder_base_by_name,SubGhzProtocolDecoderBase
Function,+,subghz_receiver_set_filter,void,"SubGhzReceiver*, SubGhzProtocolFlag"
Function,+,subghz_receiver_set_rx_callback,void,"SubGhzReceiver*, SubGhzReceiverCallback, void*"
Function,+,subghz_setting_alloc,SubGhzSetting*,
Function,-,subghz_setting_customs_presets_to_log,uint8_t,SubGhzSetting*
Function,+,subghz_setting_delete_custom_preset,_Bool,"SubGhzSetting*, const char*"
Function,+,subghz_setting_free,void,SubGhzSetting*
Function,+,subghz_setting_get_default_frequency,uint32_t,SubGhzSetting*
Expand Down
32 changes: 32 additions & 0 deletions lib/subghz/subghz_setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,35 @@ uint32_t subghz_setting_get_default_frequency(SubGhzSetting* instance) {
return subghz_setting_get_frequency(
instance, subghz_setting_get_frequency_default_index(instance));
}

uint8_t subghz_setting_customs_presets_to_log(SubGhzSetting* instance) {
furi_assert(instance);
#ifndef FURI_DEBUG
FURI_LOG_I(TAG, "Logging loaded presets allow only Debug build");
#else
uint8_t count = 0;
FuriString* temp = furi_string_alloc();

FURI_LOG_I(TAG, "Loaded presets");
for
M_EACH(item, instance->preset->data, SubGhzSettingCustomPresetItemArray_t) {
furi_string_reset(temp);

for(uint8_t i = 0; i < item->custom_preset_data_size; i++) {
furi_string_cat_printf(temp, "%02u ", item->custom_preset_data[i]);
}

FURI_LOG_I(
TAG, "%u - %s", count + 1, furi_string_get_cstr(item->custom_preset_name));
FURI_LOG_I(TAG, " Size: %u", item->custom_preset_data_size);
FURI_LOG_I(TAG, " Data: %s", furi_string_get_cstr(temp));

count++;
}

furi_string_free(temp);

return count;
#endif
return 0;
}
2 changes: 2 additions & 0 deletions lib/subghz/subghz_setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ uint32_t subghz_setting_get_default_frequency(SubGhzSetting* instance);

void subghz_setting_set_default_frequency(SubGhzSetting* instance, uint32_t frequency_to_setup);

uint8_t subghz_setting_customs_presets_to_log(SubGhzSetting* instance);

#ifdef __cplusplus
}
#endif

2 comments on commit c4baf31

@ALEEF02
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the deviation in FM95? 9.5 KHz?

@EvanCarroll
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ALEEF02 asked here, #680

Please sign in to comment.