@@ -7,20 +7,6 @@ enum SubGhzSettingIndex {
7
7
SubGhzSettingIndexLock ,
8
8
};
9
9
10
- #define PRESET_COUNT 4
11
- const char * const preset_text [PRESET_COUNT ] = {
12
- "AM270" ,
13
- "AM650" ,
14
- "FM238" ,
15
- "FM476" ,
16
- };
17
- const uint32_t preset_value [PRESET_COUNT ] = {
18
- FuriHalSubGhzPresetOok270Async , /** OOK, bandwidth 270kHz, asynchronous */
19
- FuriHalSubGhzPresetOok650Async , /** OOK, bandwidth 650kHz, asynchronous */
20
- FuriHalSubGhzPreset2FSKDev238Async , /** FM, deviation 2.380371 kHz, asynchronous */
21
- FuriHalSubGhzPreset2FSKDev476Async , /** FM, deviation 4.760742 kHz, asynchronous */
22
- };
23
-
24
10
#define HOPPING_COUNT 2
25
11
const char * const hopping_text [HOPPING_COUNT ] = {
26
12
"OFF" ,
@@ -31,32 +17,31 @@ const uint32_t hopping_value[HOPPING_COUNT] = {
31
17
SubGhzHopperStateRunnig ,
32
18
};
33
19
34
- uint8_t subghz_scene_receiver_config_uint32_value_index (
35
- const uint32_t value ,
36
- const uint32_t values [],
37
- uint8_t values_count ) {
38
- int64_t last_value = INT64_MIN ;
20
+ uint8_t subghz_scene_receiver_config_next_frequency (const uint32_t value , void * context ) {
21
+ furi_assert (context );
22
+ SubGhz * subghz = context ;
39
23
uint8_t index = 0 ;
40
- for (uint8_t i = 0 ; i < values_count ; i ++ ) {
41
- if (( value >= last_value ) && ( value <= values [ i ] )) {
24
+ for (uint8_t i = 0 ; i < subghz_setting_get_frequency_count ( subghz -> setting ) ; i ++ ) {
25
+ if (value == subghz_setting_get_frequency ( subghz -> setting , i )) {
42
26
index = i ;
43
27
break ;
28
+ } else {
29
+ index = subghz_setting_get_frequency_default_index (subghz -> setting );
44
30
}
45
- last_value = values [i ];
46
31
}
47
32
return index ;
48
33
}
49
34
50
- uint8_t subghz_scene_receiver_config_next_frequency (const uint32_t value , void * context ) {
35
+ uint8_t subghz_scene_receiver_config_next_preset (const char * preset_name , void * context ) {
51
36
furi_assert (context );
52
37
SubGhz * subghz = context ;
53
38
uint8_t index = 0 ;
54
- for (uint8_t i = 0 ; i < subghz_setting_get_frequency_count (subghz -> setting ); i ++ ) {
55
- if (value == subghz_setting_get_frequency ( subghz -> setting , i )) {
39
+ for (uint8_t i = 0 ; i < subghz_setting_get_preset_count (subghz -> setting ); i ++ ) {
40
+ if (! strcmp ( subghz_setting_get_preset_name ( subghz -> setting , i ), preset_name )) {
56
41
index = i ;
57
42
break ;
58
43
} else {
59
- index = subghz_setting_get_frequency_default_index (subghz -> setting );
44
+ // index = subghz_setting_get_frequency_default_index(subghz->setting);
60
45
}
61
46
}
62
47
return index ;
@@ -94,7 +79,7 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) {
94
79
subghz_setting_get_frequency (subghz -> setting , index ) / 1000000 ,
95
80
(subghz_setting_get_frequency (subghz -> setting , index ) % 1000000 ) / 10000 );
96
81
variable_item_set_current_value_text (item , text_buf );
97
- subghz -> txrx -> frequency = subghz_setting_get_frequency (subghz -> setting , index );
82
+ subghz -> txrx -> preset -> frequency = subghz_setting_get_frequency (subghz -> setting , index );
98
83
} else {
99
84
variable_item_set_current_value_index (
100
85
item , subghz_setting_get_frequency_default_index (subghz -> setting ));
@@ -104,9 +89,14 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) {
104
89
static void subghz_scene_receiver_config_set_preset (VariableItem * item ) {
105
90
SubGhz * subghz = variable_item_get_context (item );
106
91
uint8_t index = variable_item_get_current_value_index (item );
107
-
108
- variable_item_set_current_value_text (item , preset_text [index ]);
109
- subghz -> txrx -> preset = preset_value [index ];
92
+ variable_item_set_current_value_text (
93
+ item , subghz_setting_get_preset_name (subghz -> setting , index ));
94
+ subghz_preset_init (
95
+ subghz ,
96
+ subghz_setting_get_preset_name (subghz -> setting , index ),
97
+ subghz -> txrx -> preset -> frequency ,
98
+ subghz_setting_get_preset_data (subghz -> setting , index ),
99
+ subghz_setting_get_preset_data_size (subghz -> setting , index ));
110
100
}
111
101
112
102
static void subghz_scene_receiver_config_set_hopping_runing (VariableItem * item ) {
@@ -125,7 +115,7 @@ static void subghz_scene_receiver_config_set_hopping_runing(VariableItem* item)
125
115
(VariableItem * )scene_manager_get_scene_state (
126
116
subghz -> scene_manager , SubGhzSceneReceiverConfig ),
127
117
text_buf );
128
- subghz -> txrx -> frequency = subghz_setting_get_default_frequency (subghz -> setting );
118
+ subghz -> txrx -> preset -> frequency = subghz_setting_get_default_frequency (subghz -> setting );
129
119
variable_item_set_current_value_index (
130
120
(VariableItem * )scene_manager_get_scene_state (
131
121
subghz -> scene_manager , SubGhzSceneReceiverConfig ),
@@ -164,7 +154,8 @@ void subghz_scene_receiver_config_on_enter(void* context) {
164
154
subghz_setting_get_frequency_count (subghz -> setting ),
165
155
subghz_scene_receiver_config_set_frequency ,
166
156
subghz );
167
- value_index = subghz_scene_receiver_config_next_frequency (subghz -> txrx -> frequency , subghz );
157
+ value_index =
158
+ subghz_scene_receiver_config_next_frequency (subghz -> txrx -> preset -> frequency , subghz );
168
159
scene_manager_set_scene_state (
169
160
subghz -> scene_manager , SubGhzSceneReceiverConfig , (uint32_t )item );
170
161
variable_item_set_current_value_index (item , value_index );
@@ -193,13 +184,14 @@ void subghz_scene_receiver_config_on_enter(void* context) {
193
184
item = variable_item_list_add (
194
185
subghz -> variable_item_list ,
195
186
"Modulation:" ,
196
- PRESET_COUNT ,
187
+ subghz_setting_get_preset_count ( subghz -> setting ) ,
197
188
subghz_scene_receiver_config_set_preset ,
198
189
subghz );
199
- value_index = subghz_scene_receiver_config_uint32_value_index (
200
- subghz -> txrx -> preset , preset_value , PRESET_COUNT );
190
+ value_index = subghz_scene_receiver_config_next_preset (
191
+ string_get_cstr ( subghz -> txrx -> preset -> name ), subghz );
201
192
variable_item_set_current_value_index (item , value_index );
202
- variable_item_set_current_value_text (item , preset_text [value_index ]);
193
+ variable_item_set_current_value_text (
194
+ item , subghz_setting_get_preset_name (subghz -> setting , value_index ));
203
195
204
196
if (scene_manager_get_scene_state (subghz -> scene_manager , SubGhzSceneReadRAW ) !=
205
197
SubGhzCustomEventManagerSet ) {
0 commit comments