2021-09-10 03:29:57 +03:00
|
|
|
#include "../subghz_i.h"
|
|
|
|
|
2021-10-10 17:35:10 +03:00
|
|
|
#define PRESET_COUNT 4
|
2021-09-10 03:29:57 +03:00
|
|
|
const char* const preset_text[PRESET_COUNT] = {
|
|
|
|
"AM270",
|
|
|
|
"AM650",
|
2021-10-10 17:35:10 +03:00
|
|
|
"FM238",
|
|
|
|
"FM476",
|
2021-09-10 03:29:57 +03:00
|
|
|
};
|
|
|
|
const uint32_t preset_value[PRESET_COUNT] = {
|
|
|
|
FuriHalSubGhzPresetOok270Async, /** OOK, bandwidth 270kHz, asynchronous */
|
|
|
|
FuriHalSubGhzPresetOok650Async, /** OOK, bandwidth 650kHz, asynchronous */
|
2021-10-10 17:35:10 +03:00
|
|
|
FuriHalSubGhzPreset2FSKDev238Async, /** FM, deviation 2.380371 kHz, asynchronous */
|
|
|
|
FuriHalSubGhzPreset2FSKDev476Async, /** FM, deviation 4.760742 kHz, asynchronous */
|
2021-09-10 03:29:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#define HOPPING_COUNT 2
|
|
|
|
const char* const hopping_text[HOPPING_COUNT] = {
|
|
|
|
"OFF",
|
|
|
|
"ON",
|
|
|
|
};
|
|
|
|
const uint32_t hopping_value[HOPPING_COUNT] = {
|
|
|
|
SubGhzHopperStateOFF,
|
|
|
|
SubGhzHopperStateRunnig,
|
|
|
|
};
|
|
|
|
|
|
|
|
uint8_t subghz_scene_receiver_config_uint32_value_index(
|
|
|
|
const uint32_t value,
|
|
|
|
const uint32_t values[],
|
|
|
|
uint8_t values_count) {
|
|
|
|
int64_t last_value = INT64_MIN;
|
|
|
|
uint8_t index = 0;
|
|
|
|
for(uint8_t i = 0; i < values_count; i++) {
|
|
|
|
if((value >= last_value) && (value <= values[i])) {
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
last_value = values[i];
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2022-04-14 17:05:40 +03:00
|
|
|
uint8_t subghz_scene_receiver_config_next_frequency(const uint32_t value, void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubGhz* subghz = context;
|
|
|
|
int64_t last_value = INT64_MIN;
|
|
|
|
uint8_t index = 0;
|
|
|
|
for(uint8_t i = 0; i < subghz_setting_get_frequency_count(subghz->setting); i++) {
|
|
|
|
if((value >= last_value) && (value <= subghz_setting_get_frequency(subghz->setting, i))) {
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
last_value = subghz_setting_get_frequency(subghz->setting, i);
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2021-09-10 03:29:57 +03: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);
|
|
|
|
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);
|
|
|
|
|
|
|
|
if(subghz->txrx->hopper_state == SubGhzHopperStateOFF) {
|
2022-04-14 17:05:40 +03:00
|
|
|
char text_buf[10] = {0};
|
|
|
|
sprintf(
|
|
|
|
text_buf,
|
|
|
|
"%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);
|
|
|
|
subghz->txrx->frequency = subghz_setting_get_frequency(subghz->setting, index);
|
2021-10-25 17:37:14 +03:00
|
|
|
} else {
|
2022-04-14 17:05:40 +03:00
|
|
|
variable_item_set_current_value_index(
|
|
|
|
item, subghz_setting_get_frequency_default_index(subghz->setting));
|
2021-09-10 03:29:57 +03: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);
|
|
|
|
|
|
|
|
variable_item_set_current_value_text(item, preset_text[index]);
|
|
|
|
subghz->txrx->preset = preset_value[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void subghz_scene_receiver_config_set_hopping_runing(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) {
|
2022-04-14 17:05:40 +03:00
|
|
|
char text_buf[10] = {0};
|
|
|
|
sprintf(
|
|
|
|
text_buf,
|
|
|
|
"%lu.%02lu",
|
2022-04-15 19:31:25 +03:00
|
|
|
subghz_setting_get_default_frequency(subghz->setting) / 1000000,
|
|
|
|
(subghz_setting_get_default_frequency(subghz->setting) % 1000000) / 10000);
|
2021-09-10 03:29:57 +03:00
|
|
|
variable_item_set_current_value_text(
|
|
|
|
(VariableItem*)scene_manager_get_scene_state(
|
|
|
|
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
2022-04-14 17:05:40 +03:00
|
|
|
text_buf);
|
2022-04-15 19:31:25 +03:00
|
|
|
subghz->txrx->frequency = subghz_setting_get_default_frequency(subghz->setting);
|
2021-10-25 17:37:14 +03:00
|
|
|
variable_item_set_current_value_index(
|
|
|
|
(VariableItem*)scene_manager_get_scene_state(
|
|
|
|
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
2022-04-14 17:05:40 +03:00
|
|
|
subghz_setting_get_frequency_default_index(subghz->setting));
|
2021-09-10 03:29:57 +03:00
|
|
|
} else {
|
|
|
|
variable_item_set_current_value_text(
|
|
|
|
(VariableItem*)scene_manager_get_scene_state(
|
|
|
|
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
|
|
|
" -----");
|
2021-10-25 17:37:14 +03:00
|
|
|
variable_item_set_current_value_index(
|
|
|
|
(VariableItem*)scene_manager_get_scene_state(
|
|
|
|
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
2022-04-14 17:05:40 +03:00
|
|
|
subghz_setting_get_frequency_default_index(subghz->setting));
|
2021-09-10 03:29:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
subghz->txrx->hopper_state = hopping_value[index];
|
|
|
|
}
|
|
|
|
|
2021-09-21 12:34:16 +03:00
|
|
|
void subghz_scene_receiver_config_on_enter(void* context) {
|
2021-09-10 03:29:57 +03:00
|
|
|
SubGhz* subghz = context;
|
|
|
|
VariableItem* item;
|
|
|
|
uint8_t value_index;
|
|
|
|
|
|
|
|
item = variable_item_list_add(
|
|
|
|
subghz->variable_item_list,
|
|
|
|
"Frequency:",
|
2022-04-14 17:05:40 +03:00
|
|
|
subghz_setting_get_frequency_count(subghz->setting),
|
2021-09-10 03:29:57 +03:00
|
|
|
subghz_scene_receiver_config_set_frequency,
|
|
|
|
subghz);
|
2022-04-14 17:05:40 +03:00
|
|
|
value_index = subghz_scene_receiver_config_next_frequency(subghz->txrx->frequency, subghz);
|
2021-09-10 03:29:57 +03:00
|
|
|
scene_manager_set_scene_state(
|
|
|
|
subghz->scene_manager, SubGhzSceneReceiverConfig, (uint32_t)item);
|
|
|
|
variable_item_set_current_value_index(item, value_index);
|
2022-04-14 17:05:40 +03:00
|
|
|
char text_buf[10] = {0};
|
|
|
|
sprintf(
|
|
|
|
text_buf,
|
|
|
|
"%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 03:29:57 +03:00
|
|
|
|
2021-10-27 20:37:11 +03:00
|
|
|
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
|
2022-03-03 12:48:56 +03:00
|
|
|
SubGhzCustomEventManagerSet) {
|
2021-10-25 17:37:14 +03:00
|
|
|
item = variable_item_list_add(
|
|
|
|
subghz->variable_item_list,
|
|
|
|
"Hopping:",
|
|
|
|
HOPPING_COUNT,
|
|
|
|
subghz_scene_receiver_config_set_hopping_runing,
|
|
|
|
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]);
|
|
|
|
}
|
2021-09-10 03:29:57 +03:00
|
|
|
|
|
|
|
item = variable_item_list_add(
|
|
|
|
subghz->variable_item_list,
|
|
|
|
"Modulation:",
|
|
|
|
PRESET_COUNT,
|
|
|
|
subghz_scene_receiver_config_set_preset,
|
|
|
|
subghz);
|
|
|
|
value_index = subghz_scene_receiver_config_uint32_value_index(
|
|
|
|
subghz->txrx->preset, preset_value, PRESET_COUNT);
|
|
|
|
variable_item_set_current_value_index(item, value_index);
|
|
|
|
variable_item_set_current_value_text(item, preset_text[value_index]);
|
|
|
|
|
2022-03-03 12:48:56 +03:00
|
|
|
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList);
|
2021-09-10 03:29:57 +03:00
|
|
|
}
|
|
|
|
|
2021-09-21 12:34:16 +03:00
|
|
|
bool subghz_scene_receiver_config_on_event(void* context, SceneManagerEvent event) {
|
2021-09-10 03:29:57 +03:00
|
|
|
//SubGhz* subghz = context;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-21 12:34:16 +03:00
|
|
|
void subghz_scene_receiver_config_on_exit(void* context) {
|
2021-09-10 03:29:57 +03:00
|
|
|
SubGhz* subghz = context;
|
2022-01-21 20:32:03 +03:00
|
|
|
variable_item_list_reset(subghz->variable_item_list);
|
2021-10-27 20:37:11 +03:00
|
|
|
scene_manager_set_scene_state(
|
2022-03-03 12:48:56 +03:00
|
|
|
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet);
|
2021-09-10 03:29:57 +03:00
|
|
|
}
|