Skip to content

Commit

Permalink
Merge branch 'DarkFlippers:dev' into custom
Browse files Browse the repository at this point in the history
  • Loading branch information
derskythe authored Sep 22, 2024
2 parents 5281dfc + 42ab90b commit a651f81
Show file tree
Hide file tree
Showing 20 changed files with 285 additions and 113 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
## Main changes
- SubGHz:
- Frequency analyzer fixes and improvements:
- 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
- Fix possible GSM mobile towers signal interference by limiting upper frequency to 920mhz max
- Fix duplicated frequency lists and use user config for nearest frequency selector too
- Protocol improvements:
- GangQi fix serial check
- Hollarm add more button codes (thanks to @mishamyte for captures)
* Apps: **Check out more Apps updates and fixes by following** [this link](https://github.com/xMasterX/all-the-plugins/commits/dev)
## Other changes
* OFW PR 3332: Autolock fixes (by @portasynthinca3)
* OFW PR 3885: Add API to enforce ISO15693 mode (by @aaronjamt)
* OFW: kerel typo
* OFW: Folder rename fails
* OFW: Put errno into TCB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,8 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) {
uint32_t current_frequency = subghz_setting_get_frequency(instance->setting, i);
// if(furi_hal_subghz_is_frequency_valid(current_frequency) &&
if(subghz_devices_is_frequency_valid(radio_device, current_frequency) &&
(current_frequency != 467750000) && (current_frequency != 464000000) &&
!((instance->ext_radio) &&
((current_frequency == 390000000) || (current_frequency == 312000000) ||
(current_frequency == 312100000) || (current_frequency == 312200000) ||
(current_frequency == 440175000)))) {
(((current_frequency != 467750000) && (current_frequency != 464000000)) &&
(current_frequency <= 920000000))) {
furi_hal_spi_acquire(spi_bus);
cc1101_switch_to_idle(spi_bus);
frequency = cc1101_set_frequency(spi_bus, current_frequency);
Expand Down Expand Up @@ -323,18 +320,21 @@ void subghz_frequency_analyzer_worker_start(
furi_assert(instance);
furi_assert(!instance->worker_running);

/*
SubGhzRadioDeviceType radio_type = subghz_txrx_radio_device_get(txrx);
if(radio_type == SubGhzRadioDeviceTypeExternalCC1101) {
instance->spi_bus = &furi_hal_spi_bus_handle_external;
instance->ext_radio = true;
} else if(radio_type == SubGhzRadioDeviceTypeInternal) {
instance->spi_bus = &furi_hal_spi_bus_handle_subghz;
instance->ext_radio = false;
*/
instance->spi_bus = &furi_hal_spi_bus_handle_subghz;
/*
instance->ext_radio = false;
} else {
furi_crash("Unsuported external module");
furi_crash("Wrong subghz radio type");
}

*/
instance->radio_device = subghz_devices_get_by_name(subghz_txrx_radio_device_get_name(txrx));

instance->worker_running = true;
Expand Down Expand Up @@ -365,3 +365,33 @@ void subghz_frequency_analyzer_worker_set_trigger_level(
float subghz_frequency_analyzer_worker_get_trigger_level(SubGhzFrequencyAnalyzerWorker* instance) {
return instance->trigger_level;
}

uint32_t subghz_frequency_analyzer_get_nearest_frequency(
SubGhzFrequencyAnalyzerWorker* instance,
uint32_t input) {
uint32_t prev_freq = 0;
uint32_t result = 0;
uint32_t current;

for(size_t i = 0; i < subghz_setting_get_frequency_count(instance->setting); i++) {
current = subghz_setting_get_frequency(instance->setting, i);
if(current == 0) {
continue;
}
if(current == input) {
result = current;
break;
}
if(current > input && prev_freq < input) {
if(current - input < input - prev_freq) {
result = current;
} else {
result = prev_freq;
}
break;
}
prev_freq = current;
}

return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ void subghz_frequency_analyzer_worker_set_trigger_level(
* @return RSSI trigger level
*/
float subghz_frequency_analyzer_worker_get_trigger_level(SubGhzFrequencyAnalyzerWorker* instance);

// Round up the frequency
uint32_t subghz_frequency_analyzer_get_nearest_frequency(
SubGhzFrequencyAnalyzerWorker* instance,
uint32_t input);
104 changes: 7 additions & 97 deletions applications/main/subghz/views/subghz_frequency_analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,71 +21,6 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#endif

static const uint32_t subghz_frequency_list[] = {
/* 300 - 348 */
300000000,
302757000,
303875000,
303900000,
304250000,
307000000,
307500000,
307800000,
309000000,
310000000,
312000000,
312100000,
312200000,
313000000,
313850000,
314000000,
314350000,
314980000,
315000000,
318000000,
330000000,
345000000,
348000000,
350000000,

/* 387 - 464 */
387000000,
390000000,
418000000,
430000000,
430500000,
431000000,
431500000,
433075000, /* LPD433 first */
433220000,
433420000,
433657070,
433889000,
433920000, /* LPD433 mid */
434075000,
434176948,
434190000,
434390000,
434420000,
434620000,
434775000, /* LPD433 last channels */
438900000,
440175000,
464000000,
467750000,

/* 779 - 928 */
779000000,
868350000,
868400000,
868800000,
868950000,
906400000,
915000000,
925000000,
928000000,
};

typedef enum {
SubGhzFrequencyAnalyzerStatusIDLE,
} SubGhzFrequencyAnalyzerStatus;
Expand Down Expand Up @@ -226,7 +161,7 @@ void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontSecondary);

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

// RSSI
Expand Down Expand Up @@ -279,34 +214,6 @@ void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel
elements_button_right(canvas, "+T");
}

uint32_t subghz_frequency_find_correct(uint32_t input) {
uint32_t prev_freq = 0;
uint32_t result = 0;
uint32_t current;

for(size_t i = 0; i < ARRAY_SIZE(subghz_frequency_list) - 1; i++) {
current = subghz_frequency_list[i];
if(current == 0) {
continue;
}
if(current == input) {
result = current;
break;
}
if(current > input && prev_freq < input) {
if(current - input < input - prev_freq) {
result = current;
} else {
result = prev_freq;
}
break;
}
prev_freq = current;
}

return result;
}

bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
furi_assert(context);
SubGhzFrequencyAnalyzer* instance = (SubGhzFrequencyAnalyzer*)context;
Expand Down Expand Up @@ -365,15 +272,17 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
} else if(
(model->show_frame && model->signal) ||
(!model->show_frame && model->signal)) {
frequency_candidate = subghz_frequency_find_correct(model->frequency);
frequency_candidate = subghz_frequency_analyzer_get_nearest_frequency(
instance->worker, model->frequency);
}

frequency_candidate = frequency_candidate == 0 ||
!subghz_txrx_radio_device_is_frequency_valid(
instance->txrx, frequency_candidate) ||
prev_freq_to_save == frequency_candidate ?
0 :
subghz_frequency_find_correct(frequency_candidate);
subghz_frequency_analyzer_get_nearest_frequency(
instance->worker, frequency_candidate);
if(frequency_candidate > 0 && frequency_candidate != model->frequency_to_save) {
model->frequency_to_save = frequency_candidate;
updated = true;
Expand Down Expand Up @@ -446,7 +355,8 @@ void subghz_frequency_analyzer_pair_callback(
SubGhzFrequencyAnalyzerModel * model,
{
bool in_array = false;
uint32_t normal_frequency = subghz_frequency_find_correct(model->frequency);
uint32_t normal_frequency = subghz_frequency_analyzer_get_nearest_frequency(
instance->worker, model->frequency);
for(size_t i = 0; i < MAX_HISTORY; i++) {
if(model->history_frequency[i] == normal_frequency) {
in_array = true;
Expand Down
40 changes: 40 additions & 0 deletions applications/services/cli/cli_vcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include <furi_hal_usb_cdc.h>
#include <furi_hal.h>
#include <furi.h>
#include <gui/gui.h>
#include <gui/view_port.h>
#include <assets_icons.h>
#include <applications/services/desktop/desktop.h>

#define TAG "CliVcp"

Expand Down Expand Up @@ -43,6 +47,13 @@ typedef struct {
FuriHalUsbInterface* usb_if_prev;

uint8_t data_buffer[USB_CDC_PKT_LEN];

// CLI icon
Gui* gui;
ViewPort* view_port;

// Autolocking inhibition
Desktop* desktop;
} CliVcp;

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

static void cli_vcp_icon_draw_callback(Canvas* canvas, void* context) {
furi_assert(canvas);
furi_assert(context);
const Icon* icon = context;
canvas_draw_icon(canvas, 0, 0, icon);
}

static void cli_vcp_init(void) {
if(vcp == NULL) {
vcp = malloc(sizeof(CliVcp));
Expand Down Expand Up @@ -103,6 +121,15 @@ static int32_t vcp_worker(void* context) {
FURI_LOG_D(TAG, "Start");
vcp->running = true;

// GUI icon
vcp->desktop = furi_record_open(RECORD_DESKTOP);
const Icon* icon = &I_Console_active_8x8;
vcp->gui = furi_record_open(RECORD_GUI);
vcp->view_port = view_port_alloc();
view_port_set_width(vcp->view_port, icon_get_width(icon));
// casting const away. we know that we cast it right back in the callback
view_port_draw_callback_set(vcp->view_port, cli_vcp_icon_draw_callback, (void*)icon);

while(1) {
uint32_t flags =
furi_thread_flags_wait(VCP_THREAD_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever);
Expand All @@ -115,6 +142,8 @@ static int32_t vcp_worker(void* context) {
if(vcp->connected == false) {
vcp->connected = true;
furi_stream_buffer_send(vcp->rx_stream, &ascii_soh, 1, FuriWaitForever);
gui_add_view_port(vcp->gui, vcp->view_port, GuiLayerStatusBarLeft);
desktop_api_add_external_inhibitor(vcp->desktop);
}
}

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

Expand Down Expand Up @@ -190,6 +221,10 @@ static int32_t vcp_worker(void* context) {
}

if(flags & VcpEvtStop) {
if(vcp->connected) {
gui_remove_view_port(vcp->gui, vcp->view_port);
desktop_api_remove_external_inhibitor(vcp->desktop);
}
vcp->connected = false;
vcp->running = false;
furi_hal_cdc_set_callbacks(VCP_IF_NUM, NULL, NULL);
Expand All @@ -203,6 +238,11 @@ static int32_t vcp_worker(void* context) {
break;
}
}

view_port_free(vcp->view_port);
furi_record_close(RECORD_DESKTOP);
furi_record_close(RECORD_GUI);

FURI_LOG_D(TAG, "End");
return 0;
}
Expand Down
Loading

0 comments on commit a651f81

Please sign in to comment.