unleashed-firmware/applications/main/subghz/scenes/subghz_scene_receiver_config.c

468 lines
17 KiB
C
Raw Normal View History

#include "../subghz_i.h"
#include <lib/toolbox/value_index.h>
enum SubGhzSettingIndex {
SubGhzSettingIndexFrequency,
SubGhzSettingIndexHopping,
SubGhzSettingIndexModulation,
SubGhzSettingIndexBinRAW,
2023-04-07 08:49:10 +00:00
SubGhzSettingIndexIgnoreStarline,
SubGhzSettingIndexIgnoreCars,
SubGhzSettingIndexIgnoreMagellan,
SubGhzSettingIndexSound,
SubGhzSettingIndexLock,
2023-02-20 15:55:53 +00:00
SubGhzSettingIndexRAWThresholdRSSI,
};
#define RAW_THRESHOLD_RSSI_COUNT 11
2023-02-20 15:55:53 +00:00
const char* const raw_threshold_rssi_text[RAW_THRESHOLD_RSSI_COUNT] = {
"-----",
"-85.0",
"-80.0",
"-75.0",
"-70.0",
"-65.0",
"-60.0",
"-55.0",
"-50.0",
"-45.0",
"-40.0",
};
2023-02-20 15:55:53 +00:00
const float raw_threshold_rssi_value[RAW_THRESHOLD_RSSI_COUNT] = {
-90.0f,
-85.0f,
-80.0f,
-75.0f,
-70.0f,
-65.0f,
-60.0f,
-55.0f,
-50.0f,
-45.0f,
-40.0f,
};
#define HOPPING_COUNT 2
const char* const hopping_text[HOPPING_COUNT] = {
"OFF",
"ON",
};
const uint32_t hopping_value[HOPPING_COUNT] = {
SubGhzHopperStateOFF,
2023-02-20 15:55:53 +00:00
SubGhzHopperStateRunning,
};
#define SPEAKER_COUNT 2
const char* const speaker_text[SPEAKER_COUNT] = {
"OFF",
"ON",
};
const uint32_t speaker_value[SPEAKER_COUNT] = {
SubGhzSpeakerStateShutdown,
SubGhzSpeakerStateEnable,
};
#define BIN_RAW_COUNT 2
const char* const bin_raw_text[BIN_RAW_COUNT] = {
"OFF",
"ON",
};
const uint32_t bin_raw_value[BIN_RAW_COUNT] = {
SubGhzProtocolFlag_Decodable,
SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_BinRAW,
};
#define STARLINE_COUNT 2
const char* const starline_text[STARLINE_COUNT] = {
2023-04-04 19:42:55 +00:00
"OFF",
"ON",
};
#define AUTO_ALARMS_COUNT 2
const char* const auto_alarms_text[AUTO_ALARMS_COUNT] = {
"OFF",
"ON",
};
#define MAGELLAN_COUNT 2
const char* const magellan_text[MAGELLAN_COUNT] = {
"OFF",
"ON",
2023-04-04 19:42:55 +00:00
};
uint8_t subghz_scene_receiver_config_next_frequency(const uint32_t value, void* context) {
furi_assert(context);
SubGhz* subghz = context;
uint8_t index = 0;
2023-05-09 12:11:54 +00:00
for(uint8_t i = 0;
i < subghz_setting_get_frequency_count(subghz_txrx_get_setting(subghz->txrx));
i++) {
if(value == subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), i)) {
index = i;
break;
} else {
2023-05-09 12:11:54 +00:00
index =
subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx));
}
}
return index;
}
uint8_t subghz_scene_receiver_config_next_preset(const char* preset_name, void* context) {
furi_assert(context);
SubGhz* subghz = context;
uint8_t index = 0;
2023-05-09 12:11:54 +00:00
for(uint8_t i = 0; i < subghz_setting_get_preset_count(subghz_txrx_get_setting(subghz->txrx));
i++) {
if(!strcmp(
subghz_setting_get_preset_name(subghz_txrx_get_setting(subghz->txrx), i),
preset_name)) {
index = i;
break;
} else {
2023-05-09 12:11:54 +00:00
// index = subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx));
}
}
return index;
}
uint8_t subghz_scene_receiver_config_hopper_value_index(
const uint32_t value,
const uint32_t values[],
uint8_t values_count,
void* context) {
furi_assert(context);
UNUSED(values_count);
SubGhz* subghz = context;
if(value == values[0]) {
return 0;
} else {
variable_item_set_current_value_text(
(VariableItem*)scene_manager_get_scene_state(
subghz->scene_manager, SubGhzSceneReceiverConfig),
" -----");
return 1;
}
}
static void subghz_scene_receiver_config_set_frequency(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
2023-05-09 16:10:56 +00:00
if(subghz_txrx_hopper_get_state(subghz->txrx) == SubGhzHopperStateOFF) {
char text_buf[10] = {0};
snprintf(
text_buf,
sizeof(text_buf),
"%lu.%02lu",
2023-05-09 12:11:54 +00:00
subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), index) / 1000000,
(subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), index) %
1000000) /
10000);
variable_item_set_current_value_text(item, text_buf);
2023-05-09 12:11:54 +00:00
2023-05-09 16:10:56 +00:00
SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx);
2023-05-09 12:11:54 +00:00
2023-05-09 16:10:56 +00:00
subghz_txrx_set_preset(
2023-05-09 12:11:54 +00:00
subghz->txrx,
furi_string_get_cstr(preset.name),
subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), index),
preset.data,
preset.data_size);
2023-05-09 16:10:56 +00:00
preset = subghz_txrx_get_preset(subghz->txrx);
2023-05-09 12:11:54 +00:00
subghz->last_settings->frequency = preset.frequency;
subghz_setting_set_default_frequency(
2023-05-09 12:11:54 +00:00
subghz_txrx_get_setting(subghz->txrx), preset.frequency);
} else {
variable_item_set_current_value_index(
2023-05-09 12:11:54 +00:00
item,
subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx)));
}
}
static void subghz_scene_receiver_config_set_preset(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
2023-05-09 12:11:54 +00:00
const char* preset_name =
subghz_setting_get_preset_name(subghz_txrx_get_setting(subghz->txrx), index);
2022-09-27 22:01:09 +00:00
variable_item_set_current_value_text(item, preset_name);
//subghz->last_settings->preset = index;
2023-05-09 16:10:56 +00:00
SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx);
2022-09-27 22:01:09 +00:00
2023-05-09 16:10:56 +00:00
subghz_txrx_set_preset(
subghz->txrx,
2022-09-27 22:01:09 +00:00
preset_name,
2023-05-09 12:11:54 +00:00
preset.frequency,
subghz_setting_get_preset_data(subghz_txrx_get_setting(subghz->txrx), index),
subghz_setting_get_preset_data_size(subghz_txrx_get_setting(subghz->txrx), index));
}
static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, hopping_text[index]);
if(hopping_value[index] == SubGhzHopperStateOFF) {
char text_buf[10] = {0};
snprintf(
text_buf,
sizeof(text_buf),
"%lu.%02lu",
2023-05-09 12:11:54 +00:00
subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)) / 1000000,
(subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)) %
1000000) /
10000);
variable_item_set_current_value_text(
(VariableItem*)scene_manager_get_scene_state(
subghz->scene_manager, SubGhzSceneReceiverConfig),
text_buf);
2023-05-09 16:10:56 +00:00
SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx);
subghz_txrx_set_preset(
2023-05-09 12:11:54 +00:00
subghz->txrx,
furi_string_get_cstr(preset.name),
subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)),
preset.data,
preset.data_size);
variable_item_set_current_value_index(
(VariableItem*)scene_manager_get_scene_state(
subghz->scene_manager, SubGhzSceneReceiverConfig),
2023-05-09 12:11:54 +00:00
subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx)));
} else {
variable_item_set_current_value_text(
(VariableItem*)scene_manager_get_scene_state(
subghz->scene_manager, SubGhzSceneReceiverConfig),
" -----");
variable_item_set_current_value_index(
(VariableItem*)scene_manager_get_scene_state(
subghz->scene_manager, SubGhzSceneReceiverConfig),
2023-05-09 12:11:54 +00:00
subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx)));
}
2023-05-09 16:10:56 +00:00
subghz_txrx_hopper_set_state(subghz->txrx, hopping_value[index]);
}
static void subghz_scene_receiver_config_set_speaker(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, speaker_text[index]);
2023-05-09 16:10:56 +00:00
subghz_txrx_speaker_set_state(subghz->txrx, speaker_value[index]);
}
static void subghz_scene_receiver_config_set_bin_raw(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, bin_raw_text[index]);
2023-05-09 12:58:56 +00:00
subghz->filter = bin_raw_value[index];
subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter);
}
static void subghz_scene_receiver_config_set_raw_threshold_rssi(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
2023-02-20 15:55:53 +00:00
variable_item_set_current_value_text(item, raw_threshold_rssi_text[index]);
2023-05-05 23:00:26 +00:00
subghz_threshold_rssi_set(subghz->threshold_rssi, raw_threshold_rssi_value[index]);
}
2023-04-04 19:42:55 +00:00
static void subghz_scene_receiver_config_set_starline(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, starline_text[index]);
subghz->ignore_starline = (index == 1);
}
static void subghz_scene_receiver_config_set_auto_alarms(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, auto_alarms_text[index]);
subghz->ignore_auto_alarms = (index == 1);
}
static void subghz_scene_receiver_config_set_magellan(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, magellan_text[index]);
subghz->ignore_magellan = (index == 1);
2023-04-04 19:42:55 +00:00
}
static void subghz_scene_receiver_config_var_list_enter_callback(void* context, uint32_t index) {
furi_assert(context);
SubGhz* subghz = context;
if(index == SubGhzSettingIndexLock) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubGhzCustomEventSceneSettingLock);
}
}
void subghz_scene_receiver_config_on_enter(void* context) {
SubGhz* subghz = context;
VariableItem* item;
uint8_t value_index;
2023-05-09 16:10:56 +00:00
SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx);
item = variable_item_list_add(
subghz->variable_item_list,
"Frequency:",
2023-05-09 12:11:54 +00:00
subghz_setting_get_frequency_count(subghz_txrx_get_setting(subghz->txrx)),
subghz_scene_receiver_config_set_frequency,
subghz);
2023-05-09 12:11:54 +00:00
value_index = subghz_scene_receiver_config_next_frequency(preset.frequency, subghz);
2022-09-28 03:02:23 +00:00
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReceiverConfig, (uint32_t)item);
variable_item_set_current_value_index(item, value_index);
char text_buf[10] = {0};
snprintf(
text_buf,
sizeof(text_buf),
"%lu.%02lu",
2023-05-09 12:11:54 +00:00
subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), value_index) / 1000000,
(subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), value_index) %
1000000) /
10000);
variable_item_set_current_value_text(item, text_buf);
item = variable_item_list_add(
subghz->variable_item_list,
"Modulation:",
2023-05-09 12:11:54 +00:00
subghz_setting_get_preset_count(subghz_txrx_get_setting(subghz->txrx)),
subghz_scene_receiver_config_set_preset,
subghz);
2023-05-09 12:11:54 +00:00
value_index =
subghz_scene_receiver_config_next_preset(furi_string_get_cstr(preset.name), subghz);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(
2023-05-09 12:11:54 +00:00
item, subghz_setting_get_preset_name(subghz_txrx_get_setting(subghz->txrx), value_index));
2022-09-14 13:01:30 +00:00
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
SubGhzCustomEventManagerSet) {
2022-09-27 22:01:09 +00:00
// Hopping
item = variable_item_list_add(
subghz->variable_item_list,
"Hopping:",
HOPPING_COUNT,
subghz_scene_receiver_config_set_hopping_running,
subghz);
value_index = subghz_scene_receiver_config_hopper_value_index(
2023-05-09 16:10:56 +00:00
subghz_txrx_hopper_get_state(subghz->txrx), hopping_value, HOPPING_COUNT, subghz);
2022-09-27 22:01:09 +00:00
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, hopping_text[value_index]);
}
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
SubGhzCustomEventManagerSet) {
item = variable_item_list_add(
subghz->variable_item_list,
"Bin RAW:",
BIN_RAW_COUNT,
subghz_scene_receiver_config_set_bin_raw,
subghz);
2023-05-09 12:58:56 +00:00
value_index = value_index_uint32(subghz->filter, bin_raw_value, BIN_RAW_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, bin_raw_text[value_index]);
}
2023-04-04 19:42:55 +00:00
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
SubGhzCustomEventManagerSet) {
item = variable_item_list_add(
subghz->variable_item_list,
"Ignore Starline:",
STARLINE_COUNT,
2023-04-04 19:42:55 +00:00
subghz_scene_receiver_config_set_starline,
subghz);
value_index = subghz->ignore_starline;
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, starline_text[value_index]);
item = variable_item_list_add(
subghz->variable_item_list,
"Ignore Cars:",
AUTO_ALARMS_COUNT,
subghz_scene_receiver_config_set_auto_alarms,
subghz);
value_index = subghz->ignore_auto_alarms;
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, auto_alarms_text[value_index]);
item = variable_item_list_add(
subghz->variable_item_list,
"Ignore Magellan:",
MAGELLAN_COUNT,
subghz_scene_receiver_config_set_magellan,
subghz);
value_index = subghz->ignore_magellan;
2023-04-04 19:42:55 +00:00
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, magellan_text[value_index]);
2023-04-04 19:42:55 +00:00
}
// Enable speaker, will send all incoming noises and signals to speaker so you can listen how your remote sounds like :)
item = variable_item_list_add(
subghz->variable_item_list,
"Sound:",
SPEAKER_COUNT,
subghz_scene_receiver_config_set_speaker,
subghz);
value_index =
2023-05-09 16:10:56 +00:00
value_index_uint32(subghz_txrx_speaker_get_state(subghz->txrx), speaker_value, SPEAKER_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, speaker_text[value_index]);
2022-09-14 13:01:30 +00:00
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
SubGhzCustomEventManagerSet) {
2022-09-27 22:01:09 +00:00
// Lock keyboard
variable_item_list_add(subghz->variable_item_list, "Lock Keyboard", 1, NULL, NULL);
variable_item_list_set_enter_callback(
subghz->variable_item_list,
subghz_scene_receiver_config_var_list_enter_callback,
subghz);
}
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) ==
SubGhzCustomEventManagerSet) {
item = variable_item_list_add(
subghz->variable_item_list,
"RSSI Threshold:",
RAW_THRESHOLD_RSSI_COUNT,
subghz_scene_receiver_config_set_raw_threshold_rssi,
subghz);
value_index = value_index_float(
2023-05-05 23:00:26 +00:00
subghz_threshold_rssi_get(subghz->threshold_rssi),
raw_threshold_rssi_value,
RAW_THRESHOLD_RSSI_COUNT);
variable_item_set_current_value_index(item, value_index);
2023-02-20 15:55:53 +00:00
variable_item_set_current_value_text(item, raw_threshold_rssi_text[value_index]);
}
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList);
}
bool subghz_scene_receiver_config_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventSceneSettingLock) {
subghz_lock(subghz);
scene_manager_previous_scene(subghz->scene_manager);
consumed = true;
}
}
return consumed;
}
void subghz_scene_receiver_config_on_exit(void* context) {
SubGhz* subghz = context;
2022-09-28 03:02:23 +00:00
variable_item_list_set_selected_item(subghz->variable_item_list, 0);
variable_item_list_reset(subghz->variable_item_list);
2022-09-28 01:49:06 +00:00
subghz_last_settings_save(subghz->last_settings);
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet);
}