[FL-1254] ViewDispatcher improvements, SubGhz cli and certification preparation (#482)
* Add more more frequencees and change ok key bahavior to toggle * GUI: add queue support to ViewDispatcher * SubGhz: basic cli * SubGHz: pt send cli * SubGhz: carrier cli commands. * Fix irda test data merge artifacts
This commit is contained in:
@@ -1,6 +1,70 @@
|
||||
#include "subghz_i.h"
|
||||
|
||||
osThreadId subghz_thread_id = NULL;
|
||||
const SubGhzFrequency subghz_frequencies[] = {
|
||||
/* 301 */
|
||||
{
|
||||
.frequency = 301000000,
|
||||
.path = ApiHalSubGhzPath315,
|
||||
},
|
||||
/* 315 */
|
||||
{
|
||||
.frequency = 315000000,
|
||||
.path = ApiHalSubGhzPath315,
|
||||
},
|
||||
/* 346 - 385 */
|
||||
{
|
||||
.frequency = 346000000,
|
||||
.path = ApiHalSubGhzPath315,
|
||||
},
|
||||
{
|
||||
.frequency = 385000000,
|
||||
.path = ApiHalSubGhzPath315,
|
||||
},
|
||||
/* LPD433 first, mid, last channels */
|
||||
{
|
||||
.frequency = 433075000,
|
||||
.path = ApiHalSubGhzPath433,
|
||||
},
|
||||
{
|
||||
.frequency = 433920000,
|
||||
.path = ApiHalSubGhzPath433,
|
||||
},
|
||||
{
|
||||
.frequency = 434775000,
|
||||
.path = ApiHalSubGhzPath433,
|
||||
},
|
||||
/* 438.9 - 781 */
|
||||
{
|
||||
.frequency = 438900000,
|
||||
.path = ApiHalSubGhzPath433,
|
||||
},
|
||||
{
|
||||
.frequency = 463000000,
|
||||
.path = ApiHalSubGhzPath433,
|
||||
},
|
||||
{
|
||||
.frequency = 781000000,
|
||||
.path = ApiHalSubGhzPath868,
|
||||
},
|
||||
/* 868.35 */
|
||||
{
|
||||
.frequency = 868350000,
|
||||
.path = ApiHalSubGhzPath868,
|
||||
},
|
||||
/* 915 */
|
||||
{
|
||||
.frequency = 915000000,
|
||||
.path = ApiHalSubGhzPath868,
|
||||
},
|
||||
/* 925 */
|
||||
{
|
||||
.frequency = 925000000,
|
||||
.path = ApiHalSubGhzPath868,
|
||||
},
|
||||
};
|
||||
|
||||
const uint32_t subghz_frequencies_count = sizeof(subghz_frequencies) / sizeof(SubGhzFrequency);
|
||||
const uint32_t subghz_frequencies_433_92 = 5;
|
||||
|
||||
void subghz_menu_callback(void* context, uint32_t index) {
|
||||
furi_assert(context);
|
||||
@@ -17,21 +81,18 @@ void subghz_menu_callback(void* context, uint32_t index) {
|
||||
}
|
||||
|
||||
uint32_t subghz_exit(void* context) {
|
||||
osThreadResume(subghz_thread_id);
|
||||
return VIEW_NONE;
|
||||
}
|
||||
|
||||
SubGhz* subghz_alloc() {
|
||||
SubGhz* subghz = furi_alloc(sizeof(SubGhz));
|
||||
|
||||
// Thread id
|
||||
subghz_thread_id = osThreadGetId();
|
||||
|
||||
// GUI
|
||||
subghz->gui = furi_record_open("gui");
|
||||
|
||||
// View Dispatcher
|
||||
subghz->view_dispatcher = view_dispatcher_alloc();
|
||||
view_dispatcher_enable_queue(subghz->view_dispatcher);
|
||||
view_dispatcher_attach_to_gui(
|
||||
subghz->view_dispatcher, subghz->gui, ViewDispatcherTypeFullscreen);
|
||||
|
||||
@@ -99,7 +160,7 @@ void subghz_free(SubGhz* subghz) {
|
||||
int32_t subghz_app(void* context) {
|
||||
SubGhz* subghz = subghz_alloc();
|
||||
|
||||
osThreadSuspend(subghz_thread_id);
|
||||
view_dispatcher_run(subghz->view_dispatcher);
|
||||
|
||||
subghz_free(subghz);
|
||||
|
||||
|
104
applications/subghz/subghz_cli.c
Normal file
104
applications/subghz/subghz_cli.c
Normal file
@@ -0,0 +1,104 @@
|
||||
#include "subghz_cli.h"
|
||||
#include <furi.h>
|
||||
#include <api-hal.h>
|
||||
|
||||
void subghz_cli_init() {
|
||||
Cli* cli = furi_record_open("cli");
|
||||
|
||||
cli_add_command(cli, "subghz_tx_carrier", subghz_cli_command_tx_carrier, NULL);
|
||||
cli_add_command(cli, "subghz_rx_carrier", subghz_cli_command_rx_carrier, NULL);
|
||||
cli_add_command(cli, "subghz_tx_pt", subghz_cli_command_tx_pt, NULL);
|
||||
cli_add_command(cli, "subghz_rx_pt", subghz_cli_command_rx_pt, NULL);
|
||||
|
||||
furi_record_close("cli");
|
||||
}
|
||||
|
||||
void subghz_cli_command_tx_carrier(Cli* cli, string_t args, void* context) {
|
||||
uint32_t frequency;
|
||||
int ret = sscanf(string_get_cstr(args), "%lu", &frequency);
|
||||
if(ret != 1) {
|
||||
printf("sscanf returned %d, frequency: %lu\r\n", ret, frequency);
|
||||
cli_print_usage("subghz_tx_carrier", "<Frequency in HZ>", string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
|
||||
if(frequency < 300000000 || frequency > 925000000) {
|
||||
printf("Frequency must be in 300000000...925000000 range, not %lu\r\n", frequency);
|
||||
return;
|
||||
}
|
||||
|
||||
api_hal_subghz_reset();
|
||||
api_hal_subghz_load_preset(ApiHalSubGhzPresetOokAsync);
|
||||
frequency = api_hal_subghz_set_frequency(frequency);
|
||||
printf("Transmitting at frequency %lu Hz\r\n", frequency);
|
||||
printf("Press CTRL+C to stop\r\n");
|
||||
if(frequency < 400) {
|
||||
api_hal_subghz_set_path(ApiHalSubGhzPath315);
|
||||
} else if(frequency < 500) {
|
||||
api_hal_subghz_set_path(ApiHalSubGhzPath433);
|
||||
} else {
|
||||
api_hal_subghz_set_path(ApiHalSubGhzPath868);
|
||||
}
|
||||
|
||||
hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
hal_gpio_write(&gpio_cc1101_g0, false);
|
||||
|
||||
api_hal_subghz_tx();
|
||||
|
||||
while(!cli_cmd_interrupt_received(cli)) {
|
||||
osDelay(250);
|
||||
}
|
||||
|
||||
api_hal_subghz_reset();
|
||||
api_hal_subghz_set_path(ApiHalSubGhzPathIsolate);
|
||||
hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
void subghz_cli_command_rx_carrier(Cli* cli, string_t args, void* context) {
|
||||
uint32_t frequency;
|
||||
int ret = sscanf(string_get_cstr(args), "%lu", &frequency);
|
||||
if(ret != 1) {
|
||||
printf("sscanf returned %d, frequency: %lu\r\n", ret, frequency);
|
||||
cli_print_usage("subghz_tx_carrier", "<Frequency in HZ>", string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
|
||||
if(frequency < 300000000 || frequency > 925000000) {
|
||||
printf("Frequency must be in 300000000...925000000 range, not %lu\r\n", frequency);
|
||||
return;
|
||||
}
|
||||
|
||||
api_hal_subghz_reset();
|
||||
api_hal_subghz_load_preset(ApiHalSubGhzPresetOokAsync);
|
||||
frequency = api_hal_subghz_set_frequency(frequency);
|
||||
printf("Receiving at frequency %lu Hz\r\n", frequency);
|
||||
printf("Press CTRL+C to stop\r\n");
|
||||
if(frequency < 400) {
|
||||
api_hal_subghz_set_path(ApiHalSubGhzPath315);
|
||||
} else if(frequency < 500) {
|
||||
api_hal_subghz_set_path(ApiHalSubGhzPath433);
|
||||
} else {
|
||||
api_hal_subghz_set_path(ApiHalSubGhzPath868);
|
||||
}
|
||||
|
||||
hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
api_hal_subghz_rx();
|
||||
|
||||
while(!cli_cmd_interrupt_received(cli)) {
|
||||
osDelay(250);
|
||||
printf("RSSI: %03.1fdbm\r", api_hal_subghz_get_rssi());
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
api_hal_subghz_reset();
|
||||
api_hal_subghz_set_path(ApiHalSubGhzPathIsolate);
|
||||
}
|
||||
|
||||
void subghz_cli_command_tx_pt(Cli* cli, string_t args, void* context) {
|
||||
printf("Not implemented\r\n");
|
||||
}
|
||||
|
||||
void subghz_cli_command_rx_pt(Cli* cli, string_t args, void* context) {
|
||||
printf("Not implemented\r\n");
|
||||
}
|
13
applications/subghz/subghz_cli.h
Normal file
13
applications/subghz/subghz_cli.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
|
||||
void subghz_cli_init();
|
||||
|
||||
void subghz_cli_command_tx_carrier(Cli* cli, string_t args, void* context);
|
||||
|
||||
void subghz_cli_command_rx_carrier(Cli* cli, string_t args, void* context);
|
||||
|
||||
void subghz_cli_command_tx_pt(Cli* cli, string_t args, void* context);
|
||||
|
||||
void subghz_cli_command_rx_pt(Cli* cli, string_t args, void* context);
|
@@ -11,37 +11,14 @@
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
|
||||
static const uint32_t subghz_frequencies[] = {
|
||||
301000000,
|
||||
315000000,
|
||||
346000000,
|
||||
385000000,
|
||||
433920000,
|
||||
438900000,
|
||||
463000000,
|
||||
781000000,
|
||||
868000000,
|
||||
868350000,
|
||||
915000000,
|
||||
925000000,
|
||||
};
|
||||
typedef struct {
|
||||
uint32_t frequency;
|
||||
uint8_t path;
|
||||
} SubGhzFrequency;
|
||||
|
||||
static const ApiHalSubGhzPath subghz_frequencies_paths[] = {
|
||||
ApiHalSubGhzPath2, /* 301000000 */
|
||||
ApiHalSubGhzPath2, /* 315000000 */
|
||||
ApiHalSubGhzPath2, /* 346000000 */
|
||||
ApiHalSubGhzPath2, /* 385000000 */
|
||||
ApiHalSubGhzPath1, /* 433920000 */
|
||||
ApiHalSubGhzPath1, /* 438900000 */
|
||||
ApiHalSubGhzPath1, /* 463000000 */
|
||||
ApiHalSubGhzPath3, /* 781000000 */
|
||||
ApiHalSubGhzPath3, /* 868000000 */
|
||||
ApiHalSubGhzPath3, /* 868350000 */
|
||||
ApiHalSubGhzPath3, /* 915000000 */
|
||||
ApiHalSubGhzPath3, /* 925000000 */
|
||||
};
|
||||
|
||||
static const uint32_t subghz_frequencies_count = sizeof(subghz_frequencies) / sizeof(uint32_t);
|
||||
extern const SubGhzFrequency subghz_frequencies[];
|
||||
extern const uint32_t subghz_frequencies_count;
|
||||
extern const uint32_t subghz_frequencies_433_92;
|
||||
|
||||
struct SubGhz {
|
||||
Gui* gui;
|
||||
|
@@ -55,11 +55,11 @@ void subghz_static_draw(Canvas* canvas, SubghzStaticModel* model) {
|
||||
char* path_name = "Unknown";
|
||||
if(model->path == ApiHalSubGhzPathIsolate) {
|
||||
path_name = "isolate";
|
||||
} else if(model->path == ApiHalSubGhzPath1) {
|
||||
} else if(model->path == ApiHalSubGhzPath433) {
|
||||
path_name = "433MHz";
|
||||
} else if(model->path == ApiHalSubGhzPath2) {
|
||||
} else if(model->path == ApiHalSubGhzPath315) {
|
||||
path_name = "315MHz";
|
||||
} else if(model->path == ApiHalSubGhzPath3) {
|
||||
} else if(model->path == ApiHalSubGhzPath868) {
|
||||
path_name = "868MHz";
|
||||
}
|
||||
snprintf(buffer, sizeof(buffer), "Path: %d - %s", model->path, path_name);
|
||||
@@ -91,13 +91,13 @@ bool subghz_static_input(InputEvent* event, void* context) {
|
||||
} else if(event->key == InputKeyUp) {
|
||||
if(model->button < 3) model->button++;
|
||||
}
|
||||
model->path = subghz_frequencies_paths[model->frequency];
|
||||
model->path = subghz_frequencies[model->frequency].path;
|
||||
}
|
||||
|
||||
if(reconfigure) {
|
||||
api_hal_subghz_idle();
|
||||
model->real_frequency =
|
||||
api_hal_subghz_set_frequency(subghz_frequencies[model->frequency]);
|
||||
api_hal_subghz_set_frequency(subghz_frequencies[model->frequency].frequency);
|
||||
api_hal_subghz_set_path(model->path);
|
||||
api_hal_subghz_tx();
|
||||
}
|
||||
@@ -152,10 +152,10 @@ void subghz_static_enter(void* context) {
|
||||
|
||||
with_view_model(
|
||||
subghz_static->view, (SubghzStaticModel * model) {
|
||||
model->frequency = 4;
|
||||
model->frequency = subghz_frequencies_433_92;
|
||||
model->real_frequency =
|
||||
api_hal_subghz_set_frequency(subghz_frequencies[model->frequency]);
|
||||
model->path = subghz_frequencies_paths[model->frequency];
|
||||
api_hal_subghz_set_frequency(subghz_frequencies[model->frequency].frequency);
|
||||
model->path = subghz_frequencies[model->frequency].path;
|
||||
model->button = 0;
|
||||
api_hal_subghz_set_path(model->path);
|
||||
return true;
|
||||
|
@@ -45,11 +45,11 @@ void subghz_test_basic_draw(Canvas* canvas, SubghzTestBasicModel* model) {
|
||||
char* path_name = "Unknown";
|
||||
if(model->path == ApiHalSubGhzPathIsolate) {
|
||||
path_name = "isolate";
|
||||
} else if(model->path == ApiHalSubGhzPath1) {
|
||||
} else if(model->path == ApiHalSubGhzPath433) {
|
||||
path_name = "433MHz";
|
||||
} else if(model->path == ApiHalSubGhzPath2) {
|
||||
} else if(model->path == ApiHalSubGhzPath315) {
|
||||
path_name = "315MHz";
|
||||
} else if(model->path == ApiHalSubGhzPath3) {
|
||||
} else if(model->path == ApiHalSubGhzPath868) {
|
||||
path_name = "868MHz";
|
||||
}
|
||||
snprintf(buffer, sizeof(buffer), "Path: %d - %s", model->path, path_name);
|
||||
@@ -88,22 +88,20 @@ bool subghz_test_basic_input(InputEvent* event, void* context) {
|
||||
} else if(event->key == InputKeyDown) {
|
||||
if(model->path > 0) model->path--;
|
||||
} else if(event->key == InputKeyUp) {
|
||||
if(model->path < ApiHalSubGhzPath3) model->path++;
|
||||
if(model->path < ApiHalSubGhzPath868) model->path++;
|
||||
} else if(event->key == InputKeyOk) {
|
||||
if(model->status == SubghzTestBasicModelStatusTx) {
|
||||
model->status = SubghzTestBasicModelStatusRx;
|
||||
} else {
|
||||
model->status = SubghzTestBasicModelStatusTx;
|
||||
}
|
||||
}
|
||||
|
||||
model->real_frequency =
|
||||
api_hal_subghz_set_frequency(subghz_frequencies[model->frequency]);
|
||||
api_hal_subghz_set_frequency(subghz_frequencies[model->frequency].frequency);
|
||||
api_hal_subghz_set_path(model->path);
|
||||
}
|
||||
|
||||
if(event->key == InputKeyOk) {
|
||||
if(event->type == InputTypePress) {
|
||||
model->status = SubghzTestBasicModelStatusTx;
|
||||
} else if(event->type == InputTypeRelease) {
|
||||
model->status = SubghzTestBasicModelStatusRx;
|
||||
}
|
||||
}
|
||||
|
||||
if(model->status == SubghzTestBasicModelStatusRx) {
|
||||
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
api_hal_subghz_rx();
|
||||
@@ -131,9 +129,9 @@ void subghz_test_basic_enter(void* context) {
|
||||
|
||||
with_view_model(
|
||||
subghz_test_basic->view, (SubghzTestBasicModel * model) {
|
||||
model->frequency = 4; // 433
|
||||
model->frequency = subghz_frequencies_433_92; // 433
|
||||
model->real_frequency =
|
||||
api_hal_subghz_set_frequency(subghz_frequencies[model->frequency]);
|
||||
api_hal_subghz_set_frequency(subghz_frequencies[model->frequency].frequency);
|
||||
model->path = ApiHalSubGhzPathIsolate; // isolate
|
||||
model->rssi = 0.0f;
|
||||
model->status = SubghzTestBasicModelStatusRx;
|
||||
|
@@ -53,11 +53,11 @@ void subghz_test_packet_draw(Canvas* canvas, SubghzTestPacketModel* model) {
|
||||
char* path_name = "Unknown";
|
||||
if(model->path == ApiHalSubGhzPathIsolate) {
|
||||
path_name = "isolate";
|
||||
} else if(model->path == ApiHalSubGhzPath1) {
|
||||
} else if(model->path == ApiHalSubGhzPath433) {
|
||||
path_name = "433MHz";
|
||||
} else if(model->path == ApiHalSubGhzPath2) {
|
||||
} else if(model->path == ApiHalSubGhzPath315) {
|
||||
path_name = "315MHz";
|
||||
} else if(model->path == ApiHalSubGhzPath3) {
|
||||
} else if(model->path == ApiHalSubGhzPath868) {
|
||||
path_name = "868MHz";
|
||||
}
|
||||
snprintf(buffer, sizeof(buffer), "Path: %d - %s", model->path, path_name);
|
||||
@@ -96,22 +96,20 @@ bool subghz_test_packet_input(InputEvent* event, void* context) {
|
||||
} else if(event->key == InputKeyDown) {
|
||||
if(model->path > 0) model->path--;
|
||||
} else if(event->key == InputKeyUp) {
|
||||
if(model->path < ApiHalSubGhzPath3) model->path++;
|
||||
if(model->path < ApiHalSubGhzPath868) model->path++;
|
||||
} else if(event->key == InputKeyOk) {
|
||||
if(model->status == SubghzTestPacketModelStatusTx) {
|
||||
model->status = SubghzTestPacketModelStatusRx;
|
||||
} else {
|
||||
model->status = SubghzTestPacketModelStatusTx;
|
||||
}
|
||||
}
|
||||
|
||||
model->real_frequency =
|
||||
api_hal_subghz_set_frequency(subghz_frequencies[model->frequency]);
|
||||
api_hal_subghz_set_frequency(subghz_frequencies[model->frequency].frequency);
|
||||
api_hal_subghz_set_path(model->path);
|
||||
}
|
||||
|
||||
if(event->key == InputKeyOk) {
|
||||
if(event->type == InputTypePress) {
|
||||
model->status = SubghzTestPacketModelStatusTx;
|
||||
} else if(event->type == InputTypeRelease) {
|
||||
model->status = SubghzTestPacketModelStatusRx;
|
||||
}
|
||||
}
|
||||
|
||||
if(model->status == SubghzTestPacketModelStatusRx) {
|
||||
api_hal_subghz_rx();
|
||||
osTimerStart(subghz_test_packet->timer, 1024 / 4);
|
||||
@@ -138,9 +136,9 @@ void subghz_test_packet_enter(void* context) {
|
||||
|
||||
with_view_model(
|
||||
subghz_test_packet->view, (SubghzTestPacketModel * model) {
|
||||
model->frequency = 4; // 433
|
||||
model->frequency = subghz_frequencies_433_92;
|
||||
model->real_frequency =
|
||||
api_hal_subghz_set_frequency(subghz_frequencies[model->frequency]);
|
||||
api_hal_subghz_set_frequency(subghz_frequencies[model->frequency].frequency);
|
||||
model->path = ApiHalSubGhzPathIsolate; // isolate
|
||||
model->rssi = 0.0f;
|
||||
model->status = SubghzTestPacketModelStatusRx;
|
||||
|
Reference in New Issue
Block a user