Skip to content

Commit a651f81

Browse files
authored
Merge branch 'DarkFlippers:dev' into custom
2 parents 5281dfc + 42ab90b commit a651f81

File tree

20 files changed

+285
-113
lines changed

20 files changed

+285
-113
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
## Main changes
22
- SubGHz:
3+
- Frequency analyzer fixes and improvements:
4+
- Enforce int module (like in OFW) usage due to lack of required hardware on external boards (PathIsolate (+rf switch for multiple paths)) and incorrect usage and/or understanding the purpose of frequency analyzer app by users, it should be used only to get frequency of the remote placed around 1-10cm around flipper's left corner
5+
- Fix possible GSM mobile towers signal interference by limiting upper frequency to 920mhz max
6+
- Fix duplicated frequency lists and use user config for nearest frequency selector too
37
- Protocol improvements:
48
- GangQi fix serial check
59
- Hollarm add more button codes (thanks to @mishamyte for captures)
610
* Apps: **Check out more Apps updates and fixes by following** [this link](https://github.com/xMasterX/all-the-plugins/commits/dev)
711
## Other changes
12+
* OFW PR 3332: Autolock fixes (by @portasynthinca3)
13+
* OFW PR 3885: Add API to enforce ISO15693 mode (by @aaronjamt)
814
* OFW: kerel typo
915
* OFW: Folder rename fails
1016
* OFW: Put errno into TCB

applications/main/subghz/helpers/subghz_frequency_analyzer_worker.c

+39-9
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,8 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) {
132132
uint32_t current_frequency = subghz_setting_get_frequency(instance->setting, i);
133133
// if(furi_hal_subghz_is_frequency_valid(current_frequency) &&
134134
if(subghz_devices_is_frequency_valid(radio_device, current_frequency) &&
135-
(current_frequency != 467750000) && (current_frequency != 464000000) &&
136-
!((instance->ext_radio) &&
137-
((current_frequency == 390000000) || (current_frequency == 312000000) ||
138-
(current_frequency == 312100000) || (current_frequency == 312200000) ||
139-
(current_frequency == 440175000)))) {
135+
(((current_frequency != 467750000) && (current_frequency != 464000000)) &&
136+
(current_frequency <= 920000000))) {
140137
furi_hal_spi_acquire(spi_bus);
141138
cc1101_switch_to_idle(spi_bus);
142139
frequency = cc1101_set_frequency(spi_bus, current_frequency);
@@ -323,18 +320,21 @@ void subghz_frequency_analyzer_worker_start(
323320
furi_assert(instance);
324321
furi_assert(!instance->worker_running);
325322

323+
/*
326324
SubGhzRadioDeviceType radio_type = subghz_txrx_radio_device_get(txrx);
327325
328326
if(radio_type == SubGhzRadioDeviceTypeExternalCC1101) {
329327
instance->spi_bus = &furi_hal_spi_bus_handle_external;
330328
instance->ext_radio = true;
331329
} else if(radio_type == SubGhzRadioDeviceTypeInternal) {
332-
instance->spi_bus = &furi_hal_spi_bus_handle_subghz;
333-
instance->ext_radio = false;
330+
*/
331+
instance->spi_bus = &furi_hal_spi_bus_handle_subghz;
332+
/*
333+
instance->ext_radio = false;
334334
} else {
335-
furi_crash("Unsuported external module");
335+
furi_crash("Wrong subghz radio type");
336336
}
337-
337+
*/
338338
instance->radio_device = subghz_devices_get_by_name(subghz_txrx_radio_device_get_name(txrx));
339339

340340
instance->worker_running = true;
@@ -365,3 +365,33 @@ void subghz_frequency_analyzer_worker_set_trigger_level(
365365
float subghz_frequency_analyzer_worker_get_trigger_level(SubGhzFrequencyAnalyzerWorker* instance) {
366366
return instance->trigger_level;
367367
}
368+
369+
uint32_t subghz_frequency_analyzer_get_nearest_frequency(
370+
SubGhzFrequencyAnalyzerWorker* instance,
371+
uint32_t input) {
372+
uint32_t prev_freq = 0;
373+
uint32_t result = 0;
374+
uint32_t current;
375+
376+
for(size_t i = 0; i < subghz_setting_get_frequency_count(instance->setting); i++) {
377+
current = subghz_setting_get_frequency(instance->setting, i);
378+
if(current == 0) {
379+
continue;
380+
}
381+
if(current == input) {
382+
result = current;
383+
break;
384+
}
385+
if(current > input && prev_freq < input) {
386+
if(current - input < input - prev_freq) {
387+
result = current;
388+
} else {
389+
result = prev_freq;
390+
}
391+
break;
392+
}
393+
prev_freq = current;
394+
}
395+
396+
return result;
397+
}

applications/main/subghz/helpers/subghz_frequency_analyzer_worker.h

+5
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,8 @@ void subghz_frequency_analyzer_worker_set_trigger_level(
7878
* @return RSSI trigger level
7979
*/
8080
float subghz_frequency_analyzer_worker_get_trigger_level(SubGhzFrequencyAnalyzerWorker* instance);
81+
82+
// Round up the frequency
83+
uint32_t subghz_frequency_analyzer_get_nearest_frequency(
84+
SubGhzFrequencyAnalyzerWorker* instance,
85+
uint32_t input);

applications/main/subghz/views/subghz_frequency_analyzer.c

+7-97
Original file line numberDiff line numberDiff line change
@@ -21,71 +21,6 @@
2121
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
2222
#endif
2323

24-
static const uint32_t subghz_frequency_list[] = {
25-
/* 300 - 348 */
26-
300000000,
27-
302757000,
28-
303875000,
29-
303900000,
30-
304250000,
31-
307000000,
32-
307500000,
33-
307800000,
34-
309000000,
35-
310000000,
36-
312000000,
37-
312100000,
38-
312200000,
39-
313000000,
40-
313850000,
41-
314000000,
42-
314350000,
43-
314980000,
44-
315000000,
45-
318000000,
46-
330000000,
47-
345000000,
48-
348000000,
49-
350000000,
50-
51-
/* 387 - 464 */
52-
387000000,
53-
390000000,
54-
418000000,
55-
430000000,
56-
430500000,
57-
431000000,
58-
431500000,
59-
433075000, /* LPD433 first */
60-
433220000,
61-
433420000,
62-
433657070,
63-
433889000,
64-
433920000, /* LPD433 mid */
65-
434075000,
66-
434176948,
67-
434190000,
68-
434390000,
69-
434420000,
70-
434620000,
71-
434775000, /* LPD433 last channels */
72-
438900000,
73-
440175000,
74-
464000000,
75-
467750000,
76-
77-
/* 779 - 928 */
78-
779000000,
79-
868350000,
80-
868400000,
81-
868800000,
82-
868950000,
83-
906400000,
84-
915000000,
85-
925000000,
86-
928000000,
87-
};
88-
8924
typedef enum {
9025
SubGhzFrequencyAnalyzerStatusIDLE,
9126
} SubGhzFrequencyAnalyzerStatus;
@@ -226,7 +161,7 @@ void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel
226161
canvas_set_color(canvas, ColorBlack);
227162
canvas_set_font(canvas, FontSecondary);
228163

229-
canvas_draw_str(canvas, 0, 7, model->is_ext_radio ? "Ext" : "Int");
164+
//canvas_draw_str(canvas, 0, 7, model->is_ext_radio ? "Ext" : "Int");
230165
canvas_draw_str(canvas, 20, 7, "Frequency Analyzer");
231166

232167
// RSSI
@@ -279,34 +214,6 @@ void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel
279214
elements_button_right(canvas, "+T");
280215
}
281216

282-
uint32_t subghz_frequency_find_correct(uint32_t input) {
283-
uint32_t prev_freq = 0;
284-
uint32_t result = 0;
285-
uint32_t current;
286-
287-
for(size_t i = 0; i < ARRAY_SIZE(subghz_frequency_list) - 1; i++) {
288-
current = subghz_frequency_list[i];
289-
if(current == 0) {
290-
continue;
291-
}
292-
if(current == input) {
293-
result = current;
294-
break;
295-
}
296-
if(current > input && prev_freq < input) {
297-
if(current - input < input - prev_freq) {
298-
result = current;
299-
} else {
300-
result = prev_freq;
301-
}
302-
break;
303-
}
304-
prev_freq = current;
305-
}
306-
307-
return result;
308-
}
309-
310217
bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
311218
furi_assert(context);
312219
SubGhzFrequencyAnalyzer* instance = (SubGhzFrequencyAnalyzer*)context;
@@ -365,15 +272,17 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
365272
} else if(
366273
(model->show_frame && model->signal) ||
367274
(!model->show_frame && model->signal)) {
368-
frequency_candidate = subghz_frequency_find_correct(model->frequency);
275+
frequency_candidate = subghz_frequency_analyzer_get_nearest_frequency(
276+
instance->worker, model->frequency);
369277
}
370278

371279
frequency_candidate = frequency_candidate == 0 ||
372280
!subghz_txrx_radio_device_is_frequency_valid(
373281
instance->txrx, frequency_candidate) ||
374282
prev_freq_to_save == frequency_candidate ?
375283
0 :
376-
subghz_frequency_find_correct(frequency_candidate);
284+
subghz_frequency_analyzer_get_nearest_frequency(
285+
instance->worker, frequency_candidate);
377286
if(frequency_candidate > 0 && frequency_candidate != model->frequency_to_save) {
378287
model->frequency_to_save = frequency_candidate;
379288
updated = true;
@@ -446,7 +355,8 @@ void subghz_frequency_analyzer_pair_callback(
446355
SubGhzFrequencyAnalyzerModel * model,
447356
{
448357
bool in_array = false;
449-
uint32_t normal_frequency = subghz_frequency_find_correct(model->frequency);
358+
uint32_t normal_frequency = subghz_frequency_analyzer_get_nearest_frequency(
359+
instance->worker, model->frequency);
450360
for(size_t i = 0; i < MAX_HISTORY; i++) {
451361
if(model->history_frequency[i] == normal_frequency) {
452362
in_array = true;

applications/services/cli/cli_vcp.c

+40
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#include <furi_hal_usb_cdc.h>
33
#include <furi_hal.h>
44
#include <furi.h>
5+
#include <gui/gui.h>
6+
#include <gui/view_port.h>
7+
#include <assets_icons.h>
8+
#include <applications/services/desktop/desktop.h>
59

610
#define TAG "CliVcp"
711

@@ -43,6 +47,13 @@ typedef struct {
4347
FuriHalUsbInterface* usb_if_prev;
4448

4549
uint8_t data_buffer[USB_CDC_PKT_LEN];
50+
51+
// CLI icon
52+
Gui* gui;
53+
ViewPort* view_port;
54+
55+
// Autolocking inhibition
56+
Desktop* desktop;
4657
} CliVcp;
4758

4859
static int32_t vcp_worker(void* context);
@@ -64,6 +75,13 @@ static CliVcp* vcp = NULL;
6475
static const uint8_t ascii_soh = 0x01;
6576
static const uint8_t ascii_eot = 0x04;
6677

78+
static void cli_vcp_icon_draw_callback(Canvas* canvas, void* context) {
79+
furi_assert(canvas);
80+
furi_assert(context);
81+
const Icon* icon = context;
82+
canvas_draw_icon(canvas, 0, 0, icon);
83+
}
84+
6785
static void cli_vcp_init(void) {
6886
if(vcp == NULL) {
6987
vcp = malloc(sizeof(CliVcp));
@@ -103,6 +121,15 @@ static int32_t vcp_worker(void* context) {
103121
FURI_LOG_D(TAG, "Start");
104122
vcp->running = true;
105123

124+
// GUI icon
125+
vcp->desktop = furi_record_open(RECORD_DESKTOP);
126+
const Icon* icon = &I_Console_active_8x8;
127+
vcp->gui = furi_record_open(RECORD_GUI);
128+
vcp->view_port = view_port_alloc();
129+
view_port_set_width(vcp->view_port, icon_get_width(icon));
130+
// casting const away. we know that we cast it right back in the callback
131+
view_port_draw_callback_set(vcp->view_port, cli_vcp_icon_draw_callback, (void*)icon);
132+
106133
while(1) {
107134
uint32_t flags =
108135
furi_thread_flags_wait(VCP_THREAD_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever);
@@ -115,6 +142,8 @@ static int32_t vcp_worker(void* context) {
115142
if(vcp->connected == false) {
116143
vcp->connected = true;
117144
furi_stream_buffer_send(vcp->rx_stream, &ascii_soh, 1, FuriWaitForever);
145+
gui_add_view_port(vcp->gui, vcp->view_port, GuiLayerStatusBarLeft);
146+
desktop_api_add_external_inhibitor(vcp->desktop);
118147
}
119148
}
120149

@@ -126,6 +155,8 @@ static int32_t vcp_worker(void* context) {
126155
vcp->connected = false;
127156
furi_stream_buffer_receive(vcp->tx_stream, vcp->data_buffer, USB_CDC_PKT_LEN, 0);
128157
furi_stream_buffer_send(vcp->rx_stream, &ascii_eot, 1, FuriWaitForever);
158+
gui_remove_view_port(vcp->gui, vcp->view_port);
159+
desktop_api_remove_external_inhibitor(vcp->desktop);
129160
}
130161
}
131162

@@ -190,6 +221,10 @@ static int32_t vcp_worker(void* context) {
190221
}
191222

192223
if(flags & VcpEvtStop) {
224+
if(vcp->connected) {
225+
gui_remove_view_port(vcp->gui, vcp->view_port);
226+
desktop_api_remove_external_inhibitor(vcp->desktop);
227+
}
193228
vcp->connected = false;
194229
vcp->running = false;
195230
furi_hal_cdc_set_callbacks(VCP_IF_NUM, NULL, NULL);
@@ -203,6 +238,11 @@ static int32_t vcp_worker(void* context) {
203238
break;
204239
}
205240
}
241+
242+
view_port_free(vcp->view_port);
243+
furi_record_close(RECORD_DESKTOP);
244+
furi_record_close(RECORD_GUI);
245+
206246
FURI_LOG_D(TAG, "End");
207247
return 0;
208248
}

0 commit comments

Comments
 (0)