[FL-2904, FL-2900, FL-2890] WS: add app WeatherStation (#1833)
* WeatherStation: start * SubGhz: rename protocol magellen -> magellan * WeatherStation: err Unresolved symbols: {'subghz_protocol_decoder_base_get_string'} * WeatherStation: fix Unresolved symbols: {'subghz_protocol_decoder_base_get_string'} * Subghz: add set protocol_items * WeatherStation: adding your protocols * WS: add Infactory protocol * WS: add history * WS: add setting * WS: add lock * WS: add hopper frequency * WS: fix history * WS fix string_t -> FuriString* * WS: add images * WS: history record update when receiving data from the sensor again * WS: add receiver info, delete extra code * WS: add protocol ThermoPRO_TX4 * [FL-2900] SubGhz: Move icons in Sub-GHz * WS: add Notification * [FL-2890] SubGhz: Rename *_user files in resources to _user.example * WS: add about scene * WS: removing redundant code * WS: add protocol Nexus-TH * WS: add protocol GT_WT03 * WS: fix notification and rename "Weather Station" -> "Read Weather Station" * SubGhz: partial unit tests fix * SubGhz: fix unit_test * SubGhz: remove dead code * SubGhz: rename SubGhzPresetDefinition into SubGhzRadioPreset, cleanup subghz types. Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -69,12 +69,3 @@ typedef enum {
|
||||
SubGhzViewIdTestCarrier,
|
||||
SubGhzViewIdTestPacket,
|
||||
} SubGhzViewId;
|
||||
|
||||
struct SubGhzPresetDefinition {
|
||||
FuriString* name;
|
||||
uint32_t frequency;
|
||||
uint8_t* data;
|
||||
size_t data_size;
|
||||
};
|
||||
|
||||
typedef struct SubGhzPresetDefinition SubGhzPresetDefinition;
|
||||
|
@@ -28,8 +28,8 @@ static bool subghz_scene_receiver_info_update_parser(void* context) {
|
||||
subghz->txrx->decoder_result,
|
||||
subghz_history_get_raw_data(subghz->txrx->history, subghz->txrx->idx_menu_chosen));
|
||||
|
||||
SubGhzPresetDefinition* preset =
|
||||
subghz_history_get_preset_def(subghz->txrx->history, subghz->txrx->idx_menu_chosen);
|
||||
SubGhzRadioPreset* preset =
|
||||
subghz_history_get_radio_preset(subghz->txrx->history, subghz->txrx->idx_menu_chosen);
|
||||
subghz_preset_init(
|
||||
subghz,
|
||||
furi_string_get_cstr(preset->name),
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#include <dolphin/dolphin.h>
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
#include <lib/toolbox/stream/stream.h>
|
||||
#include <lib/subghz/protocols/registry.h>
|
||||
#include <lib/subghz/protocols/protocol_items.h>
|
||||
|
||||
#define TAG "SubGhzSetType"
|
||||
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include "subghz/types.h"
|
||||
#include "subghz_i.h"
|
||||
#include <lib/toolbox/path.h>
|
||||
#include <lib/subghz/protocols/protocol_items.h>
|
||||
|
||||
bool subghz_custom_event_callback(void* context, uint32_t event) {
|
||||
furi_assert(context);
|
||||
@@ -169,7 +170,7 @@ SubGhz* subghz_alloc() {
|
||||
//init Worker & Protocol & History & KeyBoard
|
||||
subghz->lock = SubGhzLockOff;
|
||||
subghz->txrx = malloc(sizeof(SubGhzTxRx));
|
||||
subghz->txrx->preset = malloc(sizeof(SubGhzPresetDefinition));
|
||||
subghz->txrx->preset = malloc(sizeof(SubGhzRadioPreset));
|
||||
subghz->txrx->preset->name = furi_string_alloc();
|
||||
subghz_preset_init(
|
||||
subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0);
|
||||
@@ -186,6 +187,8 @@ SubGhz* subghz_alloc() {
|
||||
subghz->txrx->environment, EXT_PATH("subghz/assets/came_atomo"));
|
||||
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
subghz->txrx->environment, EXT_PATH("subghz/assets/nice_flor_s"));
|
||||
subghz_environment_set_protocol_registry(
|
||||
subghz->txrx->environment, (void*)&subghz_protocol_registry);
|
||||
subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment);
|
||||
subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable);
|
||||
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#include <lib/subghz/receiver.h>
|
||||
#include <lib/subghz/transmitter.h>
|
||||
#include <lib/subghz/subghz_file_encoder_worker.h>
|
||||
#include <lib/subghz/protocols/protocol_items.h>
|
||||
|
||||
#include "helpers/subghz_chat.h"
|
||||
|
||||
@@ -164,6 +165,7 @@ void subghz_cli_command_tx(Cli* cli, FuriString* args, void* context) {
|
||||
stream_write_cstring(stream, furi_string_get_cstr(flipper_format_string));
|
||||
|
||||
SubGhzEnvironment* environment = subghz_environment_alloc();
|
||||
subghz_environment_set_protocol_registry(environment, (void*)&subghz_protocol_registry);
|
||||
|
||||
SubGhzTransmitter* transmitter = subghz_transmitter_alloc_init(environment, "Princeton");
|
||||
subghz_transmitter_deserialize(transmitter, flipper_format);
|
||||
@@ -257,6 +259,7 @@ void subghz_cli_command_rx(Cli* cli, FuriString* args, void* context) {
|
||||
environment, EXT_PATH("subghz/assets/came_atomo"));
|
||||
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/nice_flor_s"));
|
||||
subghz_environment_set_protocol_registry(environment, (void*)&subghz_protocol_registry);
|
||||
|
||||
SubGhzReceiver* receiver = subghz_receiver_alloc_init(environment);
|
||||
subghz_receiver_set_filter(receiver, SubGhzProtocolFlag_Decodable);
|
||||
@@ -376,6 +379,7 @@ void subghz_cli_command_decode_raw(Cli* cli, FuriString* args, void* context) {
|
||||
environment, EXT_PATH("subghz/assets/came_atomo"));
|
||||
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/nice_flor_s"));
|
||||
subghz_environment_set_protocol_registry(environment, (void*)&subghz_protocol_registry);
|
||||
|
||||
SubGhzReceiver* receiver = subghz_receiver_alloc_init(environment);
|
||||
subghz_receiver_set_filter(receiver, SubGhzProtocolFlag_Decodable);
|
||||
|
@@ -11,7 +11,7 @@ typedef struct {
|
||||
FuriString* item_str;
|
||||
FlipperFormat* flipper_string;
|
||||
uint8_t type;
|
||||
SubGhzPresetDefinition* preset;
|
||||
SubGhzRadioPreset* preset;
|
||||
} SubGhzHistoryItem;
|
||||
|
||||
ARRAY_DEF(SubGhzHistoryItemArray, SubGhzHistoryItem, M_POD_OPLIST)
|
||||
@@ -60,7 +60,7 @@ uint32_t subghz_history_get_frequency(SubGhzHistory* instance, uint16_t idx) {
|
||||
return item->preset->frequency;
|
||||
}
|
||||
|
||||
SubGhzPresetDefinition* subghz_history_get_preset_def(SubGhzHistory* instance, uint16_t idx) {
|
||||
SubGhzRadioPreset* subghz_history_get_radio_preset(SubGhzHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
|
||||
return item->preset;
|
||||
@@ -138,7 +138,7 @@ void subghz_history_get_text_item_menu(SubGhzHistory* instance, FuriString* outp
|
||||
bool subghz_history_add_to_history(
|
||||
SubGhzHistory* instance,
|
||||
void* context,
|
||||
SubGhzPresetDefinition* preset) {
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(instance);
|
||||
furi_assert(context);
|
||||
|
||||
@@ -158,7 +158,7 @@ bool subghz_history_add_to_history(
|
||||
FuriString* text;
|
||||
text = furi_string_alloc();
|
||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_push_raw(instance->history->data);
|
||||
item->preset = malloc(sizeof(SubGhzPresetDefinition));
|
||||
item->preset = malloc(sizeof(SubGhzRadioPreset));
|
||||
item->type = decoder_base->protocol->type;
|
||||
item->preset->frequency = preset->frequency;
|
||||
item->preset->name = furi_string_alloc();
|
||||
|
@@ -5,7 +5,7 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
#include "helpers/subghz_types.h"
|
||||
#include <lib/subghz/types.h>
|
||||
|
||||
typedef struct SubGhzHistory SubGhzHistory;
|
||||
|
||||
@@ -35,7 +35,7 @@ void subghz_history_reset(SubGhzHistory* instance);
|
||||
*/
|
||||
uint32_t subghz_history_get_frequency(SubGhzHistory* instance, uint16_t idx);
|
||||
|
||||
SubGhzPresetDefinition* subghz_history_get_preset_def(SubGhzHistory* instance, uint16_t idx);
|
||||
SubGhzRadioPreset* subghz_history_get_radio_preset(SubGhzHistory* instance, uint16_t idx);
|
||||
|
||||
/** Get preset to history[idx]
|
||||
*
|
||||
@@ -88,13 +88,13 @@ bool subghz_history_get_text_space_left(SubGhzHistory* instance, FuriString* out
|
||||
*
|
||||
* @param instance - SubGhzHistory instance
|
||||
* @param context - SubGhzProtocolCommon context
|
||||
* @param preset - SubGhzPresetDefinition preset
|
||||
* @param preset - SubGhzRadioPreset preset
|
||||
* @return bool;
|
||||
*/
|
||||
bool subghz_history_add_to_history(
|
||||
SubGhzHistory* instance,
|
||||
void* context,
|
||||
SubGhzPresetDefinition* preset);
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/** Get SubGhzProtocolCommonLoad to load into the protocol decoder bin data
|
||||
*
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "helpers/subghz_types.h"
|
||||
#include <lib/subghz/types.h>
|
||||
#include "subghz.h"
|
||||
#include "views/receiver.h"
|
||||
#include "views/transmitter.h"
|
||||
@@ -11,8 +12,6 @@
|
||||
#include "views/subghz_test_carrier.h"
|
||||
#include "views/subghz_test_packet.h"
|
||||
|
||||
// #include <furi.h>
|
||||
// #include <furi_hal.h>
|
||||
#include <gui/gui.h>
|
||||
#include <dialogs/dialogs.h>
|
||||
#include <gui/scene_manager.h>
|
||||
@@ -24,14 +23,12 @@
|
||||
#include <gui/modules/widget.h>
|
||||
|
||||
#include <subghz/scenes/subghz_scene.h>
|
||||
|
||||
#include <lib/subghz/subghz_worker.h>
|
||||
|
||||
#include <lib/subghz/subghz_setting.h>
|
||||
#include <lib/subghz/receiver.h>
|
||||
#include <lib/subghz/transmitter.h>
|
||||
|
||||
#include "subghz_history.h"
|
||||
#include "subghz_setting.h"
|
||||
|
||||
#include <gui/modules/variable_item_list.h>
|
||||
#include <lib/toolbox/path.h>
|
||||
@@ -49,7 +46,7 @@ struct SubGhzTxRx {
|
||||
SubGhzProtocolDecoderBase* decoder_result;
|
||||
FlipperFormat* fff_data;
|
||||
|
||||
SubGhzPresetDefinition* preset;
|
||||
SubGhzRadioPreset* preset;
|
||||
SubGhzHistory* history;
|
||||
uint16_t idx_menu_chosen;
|
||||
SubGhzTxRxState txrx_state;
|
||||
|
@@ -1,567 +0,0 @@
|
||||
#include "subghz_setting.h"
|
||||
#include "subghz_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <m-list.h>
|
||||
#include "furi_hal_subghz_configs.h"
|
||||
|
||||
#define TAG "SubGhzSetting"
|
||||
|
||||
#define SUBGHZ_SETTING_FILE_TYPE "Flipper SubGhz Setting File"
|
||||
#define SUBGHZ_SETTING_FILE_VERSION 1
|
||||
|
||||
#define FREQUENCY_FLAG_DEFAULT (1 << 31)
|
||||
#define FREQUENCY_MASK (0xFFFFFFFF ^ FREQUENCY_FLAG_DEFAULT)
|
||||
|
||||
/* Default */
|
||||
static const uint32_t subghz_frequency_list[] = {
|
||||
/* 300 - 348 */
|
||||
300000000,
|
||||
303875000,
|
||||
304250000,
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
|
||||
/* 387 - 464 */
|
||||
390000000,
|
||||
418000000,
|
||||
433075000, /* LPD433 first */
|
||||
433420000,
|
||||
433920000 | FREQUENCY_FLAG_DEFAULT, /* LPD433 mid */
|
||||
434420000,
|
||||
434775000, /* LPD433 last channels */
|
||||
438900000,
|
||||
|
||||
/* 779 - 928 */
|
||||
868350000,
|
||||
915000000,
|
||||
925000000,
|
||||
0,
|
||||
};
|
||||
|
||||
static const uint32_t subghz_hopper_frequency_list[] = {
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
390000000,
|
||||
433920000,
|
||||
868350000,
|
||||
0,
|
||||
};
|
||||
|
||||
/* Europe and Russia */
|
||||
static const uint32_t subghz_frequency_list_region_eu_ru[] = {
|
||||
/* 300 - 348 */
|
||||
300000000,
|
||||
303875000,
|
||||
304250000,
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
|
||||
/* 387 - 464 */
|
||||
390000000,
|
||||
418000000,
|
||||
433075000, /* LPD433 first */
|
||||
433420000,
|
||||
433920000 | FREQUENCY_FLAG_DEFAULT, /* LPD433 mid */
|
||||
434420000,
|
||||
434775000, /* LPD433 last channels */
|
||||
438900000,
|
||||
|
||||
/* 779 - 928 */
|
||||
868350000,
|
||||
915000000,
|
||||
925000000,
|
||||
0,
|
||||
};
|
||||
static const uint32_t subghz_hopper_frequency_list_region_eu_ru[] = {
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
390000000,
|
||||
433920000,
|
||||
868350000,
|
||||
0,
|
||||
};
|
||||
|
||||
/* Region 0 */
|
||||
static const uint32_t subghz_frequency_list_region_us_ca_au[] = {
|
||||
/* 300 - 348 */
|
||||
300000000,
|
||||
303875000,
|
||||
304250000,
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
|
||||
/* 387 - 464 */
|
||||
390000000,
|
||||
418000000,
|
||||
433075000, /* LPD433 first */
|
||||
433420000,
|
||||
433920000 | FREQUENCY_FLAG_DEFAULT, /* LPD433 mid */
|
||||
434420000,
|
||||
434775000, /* LPD433 last channels */
|
||||
438900000,
|
||||
|
||||
/* 779 - 928 */
|
||||
868350000,
|
||||
915000000,
|
||||
925000000,
|
||||
0,
|
||||
};
|
||||
static const uint32_t subghz_hopper_frequency_list_region_us_ca_au[] = {
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
390000000,
|
||||
433920000,
|
||||
868350000,
|
||||
0,
|
||||
};
|
||||
|
||||
static const uint32_t subghz_frequency_list_region_jp[] = {
|
||||
/* 300 - 348 */
|
||||
300000000,
|
||||
303875000,
|
||||
304250000,
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
|
||||
/* 387 - 464 */
|
||||
390000000,
|
||||
418000000,
|
||||
433075000, /* LPD433 first */
|
||||
433420000,
|
||||
433920000 | FREQUENCY_FLAG_DEFAULT, /* LPD433 mid */
|
||||
434420000,
|
||||
434775000, /* LPD433 last channels */
|
||||
438900000,
|
||||
|
||||
/* 779 - 928 */
|
||||
868350000,
|
||||
915000000,
|
||||
925000000,
|
||||
0,
|
||||
};
|
||||
static const uint32_t subghz_hopper_frequency_list_region_jp[] = {
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
390000000,
|
||||
433920000,
|
||||
868350000,
|
||||
0,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
FuriString* custom_preset_name;
|
||||
uint8_t* custom_preset_data;
|
||||
size_t custom_preset_data_size;
|
||||
} SubGhzSettingCustomPresetItem;
|
||||
|
||||
ARRAY_DEF(SubGhzSettingCustomPresetItemArray, SubGhzSettingCustomPresetItem, M_POD_OPLIST)
|
||||
|
||||
#define M_OPL_SubGhzSettingCustomPresetItemArray_t() \
|
||||
ARRAY_OPLIST(SubGhzSettingCustomPresetItemArray, M_POD_OPLIST)
|
||||
|
||||
LIST_DEF(FrequencyList, uint32_t)
|
||||
|
||||
#define M_OPL_FrequencyList_t() LIST_OPLIST(FrequencyList)
|
||||
|
||||
typedef struct {
|
||||
SubGhzSettingCustomPresetItemArray_t data;
|
||||
} SubGhzSettingCustomPresetStruct;
|
||||
|
||||
struct SubGhzSetting {
|
||||
FrequencyList_t frequencies;
|
||||
FrequencyList_t hopper_frequencies;
|
||||
SubGhzSettingCustomPresetStruct* preset;
|
||||
};
|
||||
|
||||
SubGhzSetting* subghz_setting_alloc(void) {
|
||||
SubGhzSetting* instance = malloc(sizeof(SubGhzSetting));
|
||||
FrequencyList_init(instance->frequencies);
|
||||
FrequencyList_init(instance->hopper_frequencies);
|
||||
instance->preset = malloc(sizeof(SubGhzSettingCustomPresetStruct));
|
||||
SubGhzSettingCustomPresetItemArray_init(instance->preset->data);
|
||||
return instance;
|
||||
}
|
||||
|
||||
static void subghz_setting_preset_reset(SubGhzSetting* instance) {
|
||||
for
|
||||
M_EACH(item, instance->preset->data, SubGhzSettingCustomPresetItemArray_t) {
|
||||
furi_string_free(item->custom_preset_name);
|
||||
free(item->custom_preset_data);
|
||||
}
|
||||
SubGhzSettingCustomPresetItemArray_reset(instance->preset->data);
|
||||
}
|
||||
|
||||
void subghz_setting_free(SubGhzSetting* instance) {
|
||||
furi_assert(instance);
|
||||
FrequencyList_clear(instance->frequencies);
|
||||
FrequencyList_clear(instance->hopper_frequencies);
|
||||
for
|
||||
M_EACH(item, instance->preset->data, SubGhzSettingCustomPresetItemArray_t) {
|
||||
furi_string_free(item->custom_preset_name);
|
||||
free(item->custom_preset_data);
|
||||
}
|
||||
SubGhzSettingCustomPresetItemArray_clear(instance->preset->data);
|
||||
free(instance->preset);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
static void subghz_setting_load_default_preset(
|
||||
SubGhzSetting* instance,
|
||||
const char* preset_name,
|
||||
const uint8_t* preset_data,
|
||||
const uint8_t preset_pa_table[8]) {
|
||||
furi_assert(instance);
|
||||
furi_assert(preset_data);
|
||||
uint32_t preset_data_count = 0;
|
||||
SubGhzSettingCustomPresetItem* item =
|
||||
SubGhzSettingCustomPresetItemArray_push_raw(instance->preset->data);
|
||||
|
||||
item->custom_preset_name = furi_string_alloc();
|
||||
furi_string_set(item->custom_preset_name, preset_name);
|
||||
|
||||
while(preset_data[preset_data_count]) {
|
||||
preset_data_count += 2;
|
||||
}
|
||||
preset_data_count += 2;
|
||||
item->custom_preset_data_size = sizeof(uint8_t) * preset_data_count + sizeof(uint8_t) * 8;
|
||||
item->custom_preset_data = malloc(item->custom_preset_data_size);
|
||||
//load preset register
|
||||
memcpy(&item->custom_preset_data[0], &preset_data[0], preset_data_count);
|
||||
//load pa table
|
||||
memcpy(&item->custom_preset_data[preset_data_count], &preset_pa_table[0], 8);
|
||||
}
|
||||
|
||||
static void subghz_setting_load_default_region(
|
||||
SubGhzSetting* instance,
|
||||
const uint32_t frequencies[],
|
||||
const uint32_t hopper_frequencies[]) {
|
||||
furi_assert(instance);
|
||||
|
||||
FrequencyList_reset(instance->frequencies);
|
||||
FrequencyList_reset(instance->hopper_frequencies);
|
||||
subghz_setting_preset_reset(instance);
|
||||
|
||||
while(*frequencies) {
|
||||
FrequencyList_push_back(instance->frequencies, *frequencies);
|
||||
frequencies++;
|
||||
}
|
||||
|
||||
while(*hopper_frequencies) {
|
||||
FrequencyList_push_back(instance->hopper_frequencies, *hopper_frequencies);
|
||||
hopper_frequencies++;
|
||||
}
|
||||
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"AM270",
|
||||
(uint8_t*)furi_hal_subghz_preset_ook_270khz_async_regs,
|
||||
furi_hal_subghz_preset_ook_async_patable);
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"AM650",
|
||||
(uint8_t*)furi_hal_subghz_preset_ook_650khz_async_regs,
|
||||
furi_hal_subghz_preset_ook_async_patable);
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"FM238",
|
||||
(uint8_t*)furi_hal_subghz_preset_2fsk_dev2_38khz_async_regs,
|
||||
furi_hal_subghz_preset_2fsk_async_patable);
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"FM476",
|
||||
(uint8_t*)furi_hal_subghz_preset_2fsk_dev47_6khz_async_regs,
|
||||
furi_hal_subghz_preset_2fsk_async_patable);
|
||||
}
|
||||
|
||||
void subghz_setting_load_default(SubGhzSetting* instance) {
|
||||
switch(furi_hal_version_get_hw_region()) {
|
||||
case FuriHalVersionRegionEuRu:
|
||||
subghz_setting_load_default_region(
|
||||
instance,
|
||||
subghz_frequency_list_region_eu_ru,
|
||||
subghz_hopper_frequency_list_region_eu_ru);
|
||||
break;
|
||||
case FuriHalVersionRegionUsCaAu:
|
||||
subghz_setting_load_default_region(
|
||||
instance,
|
||||
subghz_frequency_list_region_us_ca_au,
|
||||
subghz_hopper_frequency_list_region_us_ca_au);
|
||||
break;
|
||||
case FuriHalVersionRegionJp:
|
||||
subghz_setting_load_default_region(
|
||||
instance, subghz_frequency_list_region_jp, subghz_hopper_frequency_list_region_jp);
|
||||
break;
|
||||
|
||||
default:
|
||||
subghz_setting_load_default_region(
|
||||
instance, subghz_frequency_list, subghz_hopper_frequency_list);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_setting_load(SubGhzSetting* instance, const char* file_path) {
|
||||
furi_assert(instance);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
|
||||
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
uint32_t temp_data32;
|
||||
bool temp_bool;
|
||||
|
||||
subghz_setting_load_default(instance);
|
||||
|
||||
if(file_path) {
|
||||
do {
|
||||
if(!flipper_format_file_open_existing(fff_data_file, file_path)) {
|
||||
FURI_LOG_E(TAG, "Error open file %s", file_path);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
|
||||
FURI_LOG_E(TAG, "Missing or incorrect header");
|
||||
break;
|
||||
}
|
||||
|
||||
if((!strcmp(furi_string_get_cstr(temp_str), SUBGHZ_SETTING_FILE_TYPE)) &&
|
||||
temp_data32 == SUBGHZ_SETTING_FILE_VERSION) {
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Type or version mismatch");
|
||||
break;
|
||||
}
|
||||
|
||||
// Standard frequencies (optional)
|
||||
temp_bool = true;
|
||||
flipper_format_read_bool(fff_data_file, "Add_standard_frequencies", &temp_bool, 1);
|
||||
if(!temp_bool) {
|
||||
FURI_LOG_I(TAG, "Removing standard frequencies");
|
||||
FrequencyList_reset(instance->frequencies);
|
||||
FrequencyList_reset(instance->hopper_frequencies);
|
||||
} else {
|
||||
FURI_LOG_I(TAG, "Keeping standard frequencies");
|
||||
}
|
||||
|
||||
// Load frequencies
|
||||
if(!flipper_format_rewind(fff_data_file)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
while(flipper_format_read_uint32(
|
||||
fff_data_file, "Frequency", (uint32_t*)&temp_data32, 1)) {
|
||||
if(furi_hal_subghz_is_frequency_valid(temp_data32)) {
|
||||
FURI_LOG_I(TAG, "Frequency loaded %lu", temp_data32);
|
||||
FrequencyList_push_back(instance->frequencies, temp_data32);
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Frequency not supported %lu", temp_data32);
|
||||
}
|
||||
}
|
||||
|
||||
// Load hopper frequencies
|
||||
if(!flipper_format_rewind(fff_data_file)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
while(flipper_format_read_uint32(
|
||||
fff_data_file, "Hopper_frequency", (uint32_t*)&temp_data32, 1)) {
|
||||
if(furi_hal_subghz_is_frequency_valid(temp_data32)) {
|
||||
FURI_LOG_I(TAG, "Hopper frequency loaded %lu", temp_data32);
|
||||
FrequencyList_push_back(instance->hopper_frequencies, temp_data32);
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Hopper frequency not supported %lu", temp_data32);
|
||||
}
|
||||
}
|
||||
|
||||
// Default frequency (optional)
|
||||
if(!flipper_format_rewind(fff_data_file)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
if(flipper_format_read_uint32(fff_data_file, "Default_frequency", &temp_data32, 1)) {
|
||||
for
|
||||
M_EACH(frequency, instance->frequencies, FrequencyList_t) {
|
||||
*frequency &= FREQUENCY_MASK;
|
||||
if(*frequency == temp_data32) {
|
||||
*frequency |= FREQUENCY_FLAG_DEFAULT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// custom preset (optional)
|
||||
if(!flipper_format_rewind(fff_data_file)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
while(flipper_format_read_string(fff_data_file, "Custom_preset_name", temp_str)) {
|
||||
FURI_LOG_I(TAG, "Custom preset loaded %s", furi_string_get_cstr(temp_str));
|
||||
subghz_setting_load_custom_preset(
|
||||
instance, furi_string_get_cstr(temp_str), fff_data_file);
|
||||
}
|
||||
|
||||
} while(false);
|
||||
}
|
||||
|
||||
furi_string_free(temp_str);
|
||||
flipper_format_free(fff_data_file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
if(!FrequencyList_size(instance->frequencies) ||
|
||||
!FrequencyList_size(instance->hopper_frequencies)) {
|
||||
FURI_LOG_E(TAG, "Error loading user settings, loading default settings");
|
||||
subghz_setting_load_default(instance);
|
||||
}
|
||||
}
|
||||
|
||||
size_t subghz_setting_get_frequency_count(SubGhzSetting* instance) {
|
||||
furi_assert(instance);
|
||||
return FrequencyList_size(instance->frequencies);
|
||||
}
|
||||
|
||||
size_t subghz_setting_get_hopper_frequency_count(SubGhzSetting* instance) {
|
||||
furi_assert(instance);
|
||||
return FrequencyList_size(instance->hopper_frequencies);
|
||||
}
|
||||
|
||||
size_t subghz_setting_get_preset_count(SubGhzSetting* instance) {
|
||||
furi_assert(instance);
|
||||
return SubGhzSettingCustomPresetItemArray_size(instance->preset->data);
|
||||
}
|
||||
|
||||
const char* subghz_setting_get_preset_name(SubGhzSetting* instance, size_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzSettingCustomPresetItem* item =
|
||||
SubGhzSettingCustomPresetItemArray_get(instance->preset->data, idx);
|
||||
return furi_string_get_cstr(item->custom_preset_name);
|
||||
}
|
||||
|
||||
int subghz_setting_get_inx_preset_by_name(SubGhzSetting* instance, const char* preset_name) {
|
||||
furi_assert(instance);
|
||||
size_t idx = 0;
|
||||
for
|
||||
M_EACH(item, instance->preset->data, SubGhzSettingCustomPresetItemArray_t) {
|
||||
if(strcmp(furi_string_get_cstr(item->custom_preset_name), preset_name) == 0) {
|
||||
return idx;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
furi_crash("SubGhz: No name preset.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool subghz_setting_load_custom_preset(
|
||||
SubGhzSetting* instance,
|
||||
const char* preset_name,
|
||||
FlipperFormat* fff_data_file) {
|
||||
furi_assert(instance);
|
||||
furi_assert(preset_name);
|
||||
uint32_t temp_data32;
|
||||
SubGhzSettingCustomPresetItem* item =
|
||||
SubGhzSettingCustomPresetItemArray_push_raw(instance->preset->data);
|
||||
item->custom_preset_name = furi_string_alloc();
|
||||
furi_string_set(item->custom_preset_name, preset_name);
|
||||
do {
|
||||
if(!flipper_format_get_value_count(fff_data_file, "Custom_preset_data", &temp_data32))
|
||||
break;
|
||||
if(!temp_data32 || (temp_data32 % 2)) {
|
||||
FURI_LOG_E(TAG, "Integrity error Custom_preset_data");
|
||||
break;
|
||||
}
|
||||
item->custom_preset_data_size = sizeof(uint8_t) * temp_data32;
|
||||
item->custom_preset_data = malloc(item->custom_preset_data_size);
|
||||
if(!flipper_format_read_hex(
|
||||
fff_data_file,
|
||||
"Custom_preset_data",
|
||||
item->custom_preset_data,
|
||||
item->custom_preset_data_size)) {
|
||||
FURI_LOG_E(TAG, "Missing Custom_preset_data");
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
} while(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool subghz_setting_delete_custom_preset(SubGhzSetting* instance, const char* preset_name) {
|
||||
furi_assert(instance);
|
||||
furi_assert(preset_name);
|
||||
SubGhzSettingCustomPresetItemArray_it_t it;
|
||||
SubGhzSettingCustomPresetItemArray_it_last(it, instance->preset->data);
|
||||
while(!SubGhzSettingCustomPresetItemArray_end_p(it)) {
|
||||
SubGhzSettingCustomPresetItem* item = SubGhzSettingCustomPresetItemArray_ref(it);
|
||||
if(strcmp(furi_string_get_cstr(item->custom_preset_name), preset_name) == 0) {
|
||||
furi_string_free(item->custom_preset_name);
|
||||
free(item->custom_preset_data);
|
||||
SubGhzSettingCustomPresetItemArray_remove(instance->preset->data, it);
|
||||
return true;
|
||||
}
|
||||
SubGhzSettingCustomPresetItemArray_previous(it);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t* subghz_setting_get_preset_data(SubGhzSetting* instance, size_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzSettingCustomPresetItem* item =
|
||||
SubGhzSettingCustomPresetItemArray_get(instance->preset->data, idx);
|
||||
return item->custom_preset_data;
|
||||
}
|
||||
|
||||
size_t subghz_setting_get_preset_data_size(SubGhzSetting* instance, size_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzSettingCustomPresetItem* item =
|
||||
SubGhzSettingCustomPresetItemArray_get(instance->preset->data, idx);
|
||||
return item->custom_preset_data_size;
|
||||
}
|
||||
|
||||
uint8_t* subghz_setting_get_preset_data_by_name(SubGhzSetting* instance, const char* preset_name) {
|
||||
furi_assert(instance);
|
||||
SubGhzSettingCustomPresetItem* item = SubGhzSettingCustomPresetItemArray_get(
|
||||
instance->preset->data, subghz_setting_get_inx_preset_by_name(instance, preset_name));
|
||||
return item->custom_preset_data;
|
||||
}
|
||||
|
||||
uint32_t subghz_setting_get_frequency(SubGhzSetting* instance, size_t idx) {
|
||||
furi_assert(instance);
|
||||
uint32_t* ret = FrequencyList_get(instance->frequencies, idx);
|
||||
if(ret) {
|
||||
return (*ret) & FREQUENCY_MASK;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t subghz_setting_get_hopper_frequency(SubGhzSetting* instance, size_t idx) {
|
||||
furi_assert(instance);
|
||||
uint32_t* ret = FrequencyList_get(instance->hopper_frequencies, idx);
|
||||
if(ret) {
|
||||
return *ret;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t subghz_setting_get_frequency_default_index(SubGhzSetting* instance) {
|
||||
furi_assert(instance);
|
||||
for(size_t i = 0; i < FrequencyList_size(instance->frequencies); i++) {
|
||||
uint32_t frequency = *FrequencyList_get(instance->frequencies, i);
|
||||
if(frequency & FREQUENCY_FLAG_DEFAULT) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t subghz_setting_get_default_frequency(SubGhzSetting* instance) {
|
||||
furi_assert(instance);
|
||||
return subghz_setting_get_frequency(
|
||||
instance, subghz_setting_get_frequency_default_index(instance));
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <math.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
|
||||
#define SUBGHZ_SETTING_DEFAULT_PRESET_COUNT 4
|
||||
|
||||
typedef struct SubGhzSetting SubGhzSetting;
|
||||
|
||||
SubGhzSetting* subghz_setting_alloc(void);
|
||||
|
||||
void subghz_setting_free(SubGhzSetting* instance);
|
||||
|
||||
void subghz_setting_load(SubGhzSetting* instance, const char* file_path);
|
||||
|
||||
size_t subghz_setting_get_frequency_count(SubGhzSetting* instance);
|
||||
|
||||
size_t subghz_setting_get_hopper_frequency_count(SubGhzSetting* instance);
|
||||
|
||||
size_t subghz_setting_get_preset_count(SubGhzSetting* instance);
|
||||
|
||||
const char* subghz_setting_get_preset_name(SubGhzSetting* instance, size_t idx);
|
||||
|
||||
int subghz_setting_get_inx_preset_by_name(SubGhzSetting* instance, const char* preset_name);
|
||||
|
||||
uint8_t* subghz_setting_get_preset_data(SubGhzSetting* instance, size_t idx);
|
||||
|
||||
size_t subghz_setting_get_preset_data_size(SubGhzSetting* instance, size_t idx);
|
||||
|
||||
uint8_t* subghz_setting_get_preset_data_by_name(SubGhzSetting* instance, const char* preset_name);
|
||||
|
||||
bool subghz_setting_load_custom_preset(
|
||||
SubGhzSetting* instance,
|
||||
const char* preset_name,
|
||||
FlipperFormat* fff_data_file);
|
||||
|
||||
bool subghz_setting_delete_custom_preset(SubGhzSetting* instance, const char* preset_name);
|
||||
|
||||
uint32_t subghz_setting_get_frequency(SubGhzSetting* instance, size_t idx);
|
||||
|
||||
uint32_t subghz_setting_get_hopper_frequency(SubGhzSetting* instance, size_t idx);
|
||||
|
||||
uint32_t subghz_setting_get_frequency_default_index(SubGhzSetting* instance);
|
||||
|
||||
uint32_t subghz_setting_get_default_frequency(SubGhzSetting* instance);
|
@@ -192,7 +192,7 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
|
||||
} else {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
}
|
||||
canvas_draw_icon(canvas, 1, 2 + i * FRAME_HEIGHT, ReceiverItemIcons[item_menu->type]);
|
||||
canvas_draw_icon(canvas, 4, 2 + i * FRAME_HEIGHT, ReceiverItemIcons[item_menu->type]);
|
||||
canvas_draw_str(canvas, 15, 9 + i * FRAME_HEIGHT, furi_string_get_cstr(str_buff));
|
||||
furi_string_reset(str_buff);
|
||||
}
|
||||
|
Reference in New Issue
Block a user