2021-09-10 00:29:57 +00:00
|
|
|
#include "../subghz_i.h"
|
|
|
|
|
2022-09-14 13:01:30 +00:00
|
|
|
#include <lib/subghz/protocols/raw.h>
|
|
|
|
|
2022-09-28 00:31:29 +00:00
|
|
|
#define TAG "SubGhzSceneReceiverConfig"
|
|
|
|
|
2022-07-03 16:03:36 +00:00
|
|
|
enum SubGhzSettingIndex {
|
|
|
|
SubGhzSettingIndexFrequency,
|
|
|
|
SubGhzSettingIndexHopping,
|
|
|
|
SubGhzSettingIndexModulation,
|
2022-09-14 13:01:30 +00:00
|
|
|
SubGhzSettingIndexDetectRaw,
|
|
|
|
SubGhzSettingIndexRSSIThreshold,
|
2022-07-03 16:03:36 +00:00
|
|
|
SubGhzSettingIndexLock,
|
|
|
|
};
|
|
|
|
|
2021-09-10 00:29:57 +00:00
|
|
|
#define HOPPING_COUNT 2
|
|
|
|
const char* const hopping_text[HOPPING_COUNT] = {
|
|
|
|
"OFF",
|
|
|
|
"ON",
|
|
|
|
};
|
|
|
|
const uint32_t hopping_value[HOPPING_COUNT] = {
|
|
|
|
SubGhzHopperStateOFF,
|
|
|
|
SubGhzHopperStateRunnig,
|
|
|
|
};
|
|
|
|
|
2022-09-14 13:01:30 +00:00
|
|
|
#define DETECT_RAW_COUNT 2
|
|
|
|
const char* const detect_raw_text[DETECT_RAW_COUNT] = {
|
|
|
|
"OFF",
|
|
|
|
"ON",
|
|
|
|
};
|
|
|
|
|
2022-10-02 03:38:34 +00:00
|
|
|
const SubGhzProtocolFlag detect_raw_value[DETECT_RAW_COUNT] = {
|
|
|
|
SubGhzProtocolFlag_Decodable,
|
|
|
|
SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_RAW,
|
|
|
|
};
|
|
|
|
|
2022-09-14 13:01:30 +00:00
|
|
|
#define RSSI_THRESHOLD_COUNT 7
|
|
|
|
const char* const rssi_threshold_text[RSSI_THRESHOLD_COUNT] = {
|
|
|
|
"-72db",
|
|
|
|
"-67db",
|
|
|
|
"-62db",
|
|
|
|
"-57db",
|
|
|
|
"-52db",
|
|
|
|
"-47db",
|
|
|
|
"-42db",
|
|
|
|
};
|
|
|
|
|
|
|
|
const int rssi_threshold_value[RSSI_THRESHOLD_COUNT] = {
|
|
|
|
-72,
|
|
|
|
-67,
|
|
|
|
-62,
|
|
|
|
-57,
|
|
|
|
-52,
|
|
|
|
-47,
|
|
|
|
-42,
|
|
|
|
};
|
|
|
|
|
2022-07-26 14:16:59 +00:00
|
|
|
uint8_t subghz_scene_receiver_config_next_frequency(const uint32_t value, void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubGhz* subghz = context;
|
2021-09-10 00:29:57 +00:00
|
|
|
uint8_t index = 0;
|
2022-07-26 14:16:59 +00:00
|
|
|
for(uint8_t i = 0; i < subghz_setting_get_frequency_count(subghz->setting); i++) {
|
|
|
|
if(value == subghz_setting_get_frequency(subghz->setting, i)) {
|
2021-09-10 00:29:57 +00:00
|
|
|
index = i;
|
|
|
|
break;
|
2022-07-26 14:16:59 +00:00
|
|
|
} else {
|
|
|
|
index = subghz_setting_get_frequency_default_index(subghz->setting);
|
2021-09-10 00:29:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2022-07-26 14:16:59 +00:00
|
|
|
uint8_t subghz_scene_receiver_config_next_preset(const char* preset_name, void* context) {
|
2022-04-14 14:05:40 +00:00
|
|
|
furi_assert(context);
|
|
|
|
SubGhz* subghz = context;
|
|
|
|
uint8_t index = 0;
|
2022-07-26 14:16:59 +00:00
|
|
|
for(uint8_t i = 0; i < subghz_setting_get_preset_count(subghz->setting); i++) {
|
|
|
|
if(!strcmp(subghz_setting_get_preset_name(subghz->setting, i), preset_name)) {
|
2022-04-14 14:05:40 +00:00
|
|
|
index = i;
|
|
|
|
break;
|
2022-06-09 07:39:12 +00:00
|
|
|
} else {
|
2022-07-26 14:16:59 +00:00
|
|
|
// index = subghz_setting_get_frequency_default_index(subghz->setting);
|
2022-04-14 14:05:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2021-09-10 00:29:57 +00:00
|
|
|
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);
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(values_count);
|
2021-09-10 00:29:57 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-02 03:38:34 +00:00
|
|
|
uint8_t subghz_scene_receiver_config_detect_raw_value_index(
|
|
|
|
const SubGhzProtocolFlag value,
|
|
|
|
const SubGhzProtocolFlag values[],
|
|
|
|
uint8_t values_count) {
|
|
|
|
uint8_t index = 0;
|
|
|
|
for(uint8_t i = 0; i < values_count; i++) {
|
|
|
|
if(value == values[i]) {
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2022-09-14 13:01:30 +00:00
|
|
|
uint8_t subghz_scene_receiver_config_rssi_threshold_value_index(
|
|
|
|
const int value,
|
|
|
|
const int values[],
|
|
|
|
uint8_t values_count) {
|
|
|
|
uint8_t index = 0;
|
|
|
|
for(uint8_t i = 0; i < values_count; i++) {
|
|
|
|
if(value == values[i]) {
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2021-09-10 00:29:57 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
if(subghz->txrx->hopper_state == SubGhzHopperStateOFF) {
|
2022-04-14 14:05:40 +00:00
|
|
|
char text_buf[10] = {0};
|
2022-08-03 16:00:17 +00:00
|
|
|
snprintf(
|
2022-04-14 14:05:40 +00:00
|
|
|
text_buf,
|
2022-08-03 16:00:17 +00:00
|
|
|
sizeof(text_buf),
|
2022-04-14 14:05:40 +00:00
|
|
|
"%lu.%02lu",
|
|
|
|
subghz_setting_get_frequency(subghz->setting, index) / 1000000,
|
|
|
|
(subghz_setting_get_frequency(subghz->setting, index) % 1000000) / 10000);
|
|
|
|
variable_item_set_current_value_text(item, text_buf);
|
2022-07-26 14:16:59 +00:00
|
|
|
subghz->txrx->preset->frequency = subghz_setting_get_frequency(subghz->setting, index);
|
2022-09-27 22:01:09 +00:00
|
|
|
subghz->last_settings->frequency = subghz->txrx->preset->frequency;
|
|
|
|
subghz_setting_set_default_frequency(subghz->setting, subghz->txrx->preset->frequency);
|
2021-10-25 14:37:14 +00:00
|
|
|
} else {
|
2022-04-14 14:05:40 +00:00
|
|
|
variable_item_set_current_value_index(
|
|
|
|
item, subghz_setting_get_frequency_default_index(subghz->setting));
|
2021-09-10 00:29:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2022-09-27 22:01:09 +00:00
|
|
|
const char* preset_name = subghz_setting_get_preset_name(subghz->setting, index);
|
|
|
|
variable_item_set_current_value_text(item, preset_name);
|
|
|
|
subghz->last_settings->preset = index;
|
|
|
|
|
2022-07-26 14:16:59 +00:00
|
|
|
subghz_preset_init(
|
|
|
|
subghz,
|
2022-09-27 22:01:09 +00:00
|
|
|
preset_name,
|
2022-07-26 14:16:59 +00:00
|
|
|
subghz->txrx->preset->frequency,
|
|
|
|
subghz_setting_get_preset_data(subghz->setting, index),
|
|
|
|
subghz_setting_get_preset_data_size(subghz->setting, index));
|
2021-09-10 00:29:57 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 13:01:30 +00:00
|
|
|
static void subghz_scene_receiver_config_set_rssi_threshold(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, rssi_threshold_text[index]);
|
|
|
|
subghz_protocol_decoder_raw_set_rssi_threshold(
|
|
|
|
subghz_receiver_search_decoder_base_by_name(
|
|
|
|
subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME),
|
|
|
|
rssi_threshold_value[index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void subghz_scene_receiver_config_set_detect_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, detect_raw_text[index]);
|
2022-10-02 03:38:34 +00:00
|
|
|
subghz_receiver_set_filter(subghz->txrx->receiver, detect_raw_value[index]);
|
2022-09-14 14:12:27 +00:00
|
|
|
|
2022-10-02 03:38:34 +00:00
|
|
|
subghz_protocol_decoder_raw_set_auto_mode(
|
|
|
|
subghz_receiver_search_decoder_base_by_name(
|
|
|
|
subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME),
|
|
|
|
(index == 1));
|
2022-09-14 13:01:30 +00:00
|
|
|
}
|
|
|
|
|
2022-08-17 16:40:09 +00:00
|
|
|
static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) {
|
2021-09-10 00:29:57 +00:00
|
|
|
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) {
|
2022-04-14 14:05:40 +00:00
|
|
|
char text_buf[10] = {0};
|
2022-08-03 16:00:17 +00:00
|
|
|
snprintf(
|
2022-04-14 14:05:40 +00:00
|
|
|
text_buf,
|
2022-08-03 16:00:17 +00:00
|
|
|
sizeof(text_buf),
|
2022-04-14 14:05:40 +00:00
|
|
|
"%lu.%02lu",
|
2022-04-15 16:31:25 +00:00
|
|
|
subghz_setting_get_default_frequency(subghz->setting) / 1000000,
|
|
|
|
(subghz_setting_get_default_frequency(subghz->setting) % 1000000) / 10000);
|
2021-09-10 00:29:57 +00:00
|
|
|
variable_item_set_current_value_text(
|
|
|
|
(VariableItem*)scene_manager_get_scene_state(
|
|
|
|
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
2022-04-14 14:05:40 +00:00
|
|
|
text_buf);
|
2022-07-26 14:16:59 +00:00
|
|
|
subghz->txrx->preset->frequency = subghz_setting_get_default_frequency(subghz->setting);
|
2021-10-25 14:37:14 +00:00
|
|
|
variable_item_set_current_value_index(
|
|
|
|
(VariableItem*)scene_manager_get_scene_state(
|
|
|
|
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
2022-04-14 14:05:40 +00:00
|
|
|
subghz_setting_get_frequency_default_index(subghz->setting));
|
2021-09-10 00:29:57 +00:00
|
|
|
} else {
|
|
|
|
variable_item_set_current_value_text(
|
|
|
|
(VariableItem*)scene_manager_get_scene_state(
|
|
|
|
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
|
|
|
" -----");
|
2021-10-25 14:37:14 +00:00
|
|
|
variable_item_set_current_value_index(
|
|
|
|
(VariableItem*)scene_manager_get_scene_state(
|
|
|
|
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
2022-04-14 14:05:40 +00:00
|
|
|
subghz_setting_get_frequency_default_index(subghz->setting));
|
2021-09-10 00:29:57 +00:00
|
|
|
}
|
|
|
|
|
2022-09-16 19:08:45 +00:00
|
|
|
subghz->txrx->hopper_state = hopping_value[index];
|
2021-09-10 00:29:57 +00:00
|
|
|
}
|
|
|
|
|
2022-07-03 16:03:36 +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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
void subghz_scene_receiver_config_on_enter(void* context) {
|
2021-09-10 00:29:57 +00:00
|
|
|
SubGhz* subghz = context;
|
|
|
|
VariableItem* item;
|
|
|
|
uint8_t value_index;
|
|
|
|
|
2022-09-28 00:31:29 +00:00
|
|
|
#if FURI_DEBUG
|
|
|
|
FURI_LOG_D(
|
|
|
|
TAG,
|
|
|
|
"last frequency: %d, preset: %d",
|
|
|
|
subghz->last_settings->frequency,
|
|
|
|
subghz->last_settings->preset);
|
|
|
|
#endif
|
2021-09-10 00:29:57 +00:00
|
|
|
item = variable_item_list_add(
|
|
|
|
subghz->variable_item_list,
|
|
|
|
"Frequency:",
|
2022-04-14 14:05:40 +00:00
|
|
|
subghz_setting_get_frequency_count(subghz->setting),
|
2021-09-10 00:29:57 +00:00
|
|
|
subghz_scene_receiver_config_set_frequency,
|
|
|
|
subghz);
|
2022-07-26 14:16:59 +00:00
|
|
|
value_index =
|
|
|
|
subghz_scene_receiver_config_next_frequency(subghz->txrx->preset->frequency, subghz);
|
2022-09-28 03:02:23 +00:00
|
|
|
scene_manager_set_scene_state(
|
|
|
|
subghz->scene_manager, SubGhzSceneReceiverConfig, (uint32_t)item);
|
2021-09-10 00:29:57 +00:00
|
|
|
variable_item_set_current_value_index(item, value_index);
|
2022-04-14 14:05:40 +00:00
|
|
|
char text_buf[10] = {0};
|
2022-08-03 16:00:17 +00:00
|
|
|
snprintf(
|
2022-04-14 14:05:40 +00:00
|
|
|
text_buf,
|
2022-08-03 16:00:17 +00:00
|
|
|
sizeof(text_buf),
|
2022-04-14 14:05:40 +00:00
|
|
|
"%lu.%02lu",
|
|
|
|
subghz_setting_get_frequency(subghz->setting, value_index) / 1000000,
|
|
|
|
(subghz_setting_get_frequency(subghz->setting, value_index) % 1000000) / 10000);
|
|
|
|
variable_item_set_current_value_text(item, text_buf);
|
2021-09-10 00:29:57 +00:00
|
|
|
|
|
|
|
item = variable_item_list_add(
|
|
|
|
subghz->variable_item_list,
|
|
|
|
"Modulation:",
|
2022-07-26 14:16:59 +00:00
|
|
|
subghz_setting_get_preset_count(subghz->setting),
|
2021-09-10 00:29:57 +00:00
|
|
|
subghz_scene_receiver_config_set_preset,
|
|
|
|
subghz);
|
2022-07-26 14:16:59 +00:00
|
|
|
value_index = subghz_scene_receiver_config_next_preset(
|
|
|
|
string_get_cstr(subghz->txrx->preset->name), subghz);
|
2021-09-10 00:29:57 +00:00
|
|
|
variable_item_set_current_value_index(item, value_index);
|
2022-07-26 14:16:59 +00:00
|
|
|
variable_item_set_current_value_text(
|
|
|
|
item, subghz_setting_get_preset_name(subghz->setting, value_index));
|
2021-09-10 00:29:57 +00:00
|
|
|
|
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(
|
|
|
|
subghz->txrx->hopper_state, hopping_value, HOPPING_COUNT, subghz);
|
|
|
|
variable_item_set_current_value_index(item, value_index);
|
|
|
|
variable_item_set_current_value_text(item, hopping_text[value_index]);
|
|
|
|
|
|
|
|
// Detect Raw
|
2022-09-14 13:01:30 +00:00
|
|
|
item = variable_item_list_add(
|
|
|
|
subghz->variable_item_list,
|
|
|
|
"Detect Raw:",
|
|
|
|
DETECT_RAW_COUNT,
|
|
|
|
subghz_scene_receiver_config_set_detect_raw,
|
|
|
|
subghz);
|
2022-10-02 03:38:34 +00:00
|
|
|
value_index = subghz_scene_receiver_config_detect_raw_value_index(
|
|
|
|
subghz_receiver_get_filter(subghz->txrx->receiver),
|
|
|
|
detect_raw_value,
|
|
|
|
DETECT_RAW_COUNT);
|
2022-09-14 13:01:30 +00:00
|
|
|
variable_item_set_current_value_index(item, value_index);
|
|
|
|
variable_item_set_current_value_text(item, detect_raw_text[value_index]);
|
|
|
|
|
2022-09-27 22:01:09 +00:00
|
|
|
// RSSI
|
2022-09-14 13:01:30 +00:00
|
|
|
item = variable_item_list_add(
|
|
|
|
subghz->variable_item_list,
|
|
|
|
"RSSI for Raw:",
|
|
|
|
RSSI_THRESHOLD_COUNT,
|
|
|
|
subghz_scene_receiver_config_set_rssi_threshold,
|
|
|
|
subghz);
|
|
|
|
value_index = subghz_scene_receiver_config_rssi_threshold_value_index(
|
|
|
|
subghz_protocol_encoder_get_rssi_threshold(subghz_receiver_search_decoder_base_by_name(
|
|
|
|
subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME)),
|
|
|
|
rssi_threshold_value,
|
|
|
|
RSSI_THRESHOLD_COUNT);
|
|
|
|
variable_item_set_current_value_index(item, value_index);
|
|
|
|
variable_item_set_current_value_text(item, rssi_threshold_text[value_index]);
|
|
|
|
|
2022-09-27 22:01:09 +00:00
|
|
|
// Lock keyboard
|
2022-07-03 16:03:36 +00:00
|
|
|
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);
|
|
|
|
}
|
2022-09-14 13:01:30 +00:00
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList);
|
2021-09-10 00:29:57 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
bool subghz_scene_receiver_config_on_event(void* context, SceneManagerEvent event) {
|
2022-07-03 16:03:36 +00:00
|
|
|
SubGhz* subghz = context;
|
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
if(event.event == SubGhzCustomEventSceneSettingLock) {
|
|
|
|
subghz->lock = SubGhzLockOn;
|
|
|
|
scene_manager_previous_scene(subghz->scene_manager);
|
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return consumed;
|
2021-09-10 00:29:57 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
void subghz_scene_receiver_config_on_exit(void* context) {
|
2021-09-10 00:29:57 +00:00
|
|
|
SubGhz* subghz = context;
|
2022-09-28 03:02:23 +00:00
|
|
|
variable_item_list_set_selected_item(subghz->variable_item_list, 0);
|
2022-01-21 17:32:03 +00:00
|
|
|
variable_item_list_reset(subghz->variable_item_list);
|
2022-09-28 01:49:06 +00:00
|
|
|
subghz_last_settings_save(subghz->last_settings);
|
2021-10-27 17:37:11 +00:00
|
|
|
scene_manager_set_scene_state(
|
2022-03-03 09:48:56 +00:00
|
|
|
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet);
|
2021-09-10 00:29:57 +00:00
|
|
|
}
|