[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:
parent
1a1c5fa05d
commit
84f46e670a
@ -42,6 +42,7 @@ int32_t notification_app(void* p);
|
||||
|
||||
// On system start hooks declaration
|
||||
void nfc_cli_init();
|
||||
void subghz_cli_init();
|
||||
|
||||
const FlipperApplication FLIPPER_SERVICES[] = {
|
||||
#ifdef SRV_CLI
|
||||
@ -204,10 +205,13 @@ const FlipperOnStartHook FLIPPER_ON_SYSTEM_START[] = {
|
||||
#ifdef APP_NFC
|
||||
nfc_cli_init,
|
||||
#endif
|
||||
#ifdef APP_SUBGHZ
|
||||
subghz_cli_init,
|
||||
#endif
|
||||
};
|
||||
|
||||
const size_t FLIPPER_ON_SYSTEM_START_COUNT =
|
||||
sizeof(FLIPPER_ON_SYSTEM_START_COUNT) / sizeof(FlipperOnStartHook);
|
||||
sizeof(FLIPPER_ON_SYSTEM_START) / sizeof(FlipperOnStartHook);
|
||||
|
||||
// Plugin menu
|
||||
const FlipperApplication FLIPPER_PLUGINS[] = {
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "view_dispatcher_i.h"
|
||||
#include "gui_i.h"
|
||||
|
||||
ViewDispatcher* view_dispatcher_alloc() {
|
||||
ViewDispatcher* view_dispatcher = furi_alloc(sizeof(ViewDispatcher));
|
||||
@ -36,6 +35,34 @@ void view_dispatcher_free(ViewDispatcher* view_dispatcher) {
|
||||
free(view_dispatcher);
|
||||
}
|
||||
|
||||
void view_dispatcher_enable_queue(ViewDispatcher* view_dispatcher) {
|
||||
furi_assert(view_dispatcher);
|
||||
furi_assert(view_dispatcher->queue == NULL);
|
||||
view_dispatcher->queue = osMessageQueueNew(8, sizeof(ViewDispatcherMessage), NULL);
|
||||
}
|
||||
|
||||
void view_dispatcher_run(ViewDispatcher* view_dispatcher) {
|
||||
furi_assert(view_dispatcher);
|
||||
furi_assert(view_dispatcher->queue);
|
||||
|
||||
ViewDispatcherMessage message;
|
||||
while(osMessageQueueGet(view_dispatcher->queue, &message, NULL, osWaitForever) == osOK) {
|
||||
if(message.type == ViewDispatcherMessageTypeStop) {
|
||||
break;
|
||||
} else if(message.type == ViewDispatcherMessageTypeInput) {
|
||||
view_dispatcher_handle_input(view_dispatcher, &message.input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void view_dispatcher_stop(ViewDispatcher* view_dispatcher) {
|
||||
furi_assert(view_dispatcher);
|
||||
furi_assert(view_dispatcher->queue);
|
||||
ViewDispatcherMessage message;
|
||||
message.type = ViewDispatcherMessageTypeStop;
|
||||
furi_check(osMessageQueuePut(view_dispatcher->queue, &message, 0, osWaitForever) == osOK);
|
||||
}
|
||||
|
||||
void view_dispatcher_add_view(ViewDispatcher* view_dispatcher, uint32_t view_id, View* view) {
|
||||
furi_assert(view_dispatcher);
|
||||
furi_assert(view);
|
||||
@ -126,6 +153,17 @@ void view_dispatcher_draw_callback(Canvas* canvas, void* context) {
|
||||
|
||||
void view_dispatcher_input_callback(InputEvent* event, void* context) {
|
||||
ViewDispatcher* view_dispatcher = context;
|
||||
if(view_dispatcher->queue) {
|
||||
ViewDispatcherMessage message;
|
||||
message.type = ViewDispatcherMessageTypeInput;
|
||||
message.input = *event;
|
||||
furi_check(osMessageQueuePut(view_dispatcher->queue, &message, 0, osWaitForever) == osOK);
|
||||
} else {
|
||||
view_dispatcher_handle_input(view_dispatcher, event);
|
||||
}
|
||||
}
|
||||
|
||||
void view_dispatcher_handle_input(ViewDispatcher* view_dispatcher, InputEvent* event) {
|
||||
bool is_consumed = false;
|
||||
if(view_dispatcher->current_view) {
|
||||
is_consumed = view_input(view_dispatcher->current_view, event);
|
||||
@ -160,6 +198,9 @@ void view_dispatcher_set_current_view(ViewDispatcher* view_dispatcher, View* vie
|
||||
view_port_update(view_dispatcher->view_port);
|
||||
} else {
|
||||
view_port_enabled_set(view_dispatcher->view_port, false);
|
||||
if(view_dispatcher->queue) {
|
||||
view_dispatcher_stop(view_dispatcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief ViewDispatcher view_port placement
|
||||
/** ViewDispatcher view_port placement
|
||||
*/
|
||||
typedef enum {
|
||||
ViewDispatcherTypeNone, /**< Special layer for internal use only */
|
||||
@ -18,42 +17,54 @@ typedef enum {
|
||||
|
||||
typedef struct ViewDispatcher ViewDispatcher;
|
||||
|
||||
/**
|
||||
* @brief Allocate ViewDispatcher
|
||||
/** Allocate ViewDispatcher instance
|
||||
* @return pointer to ViewDispatcher instance
|
||||
*/
|
||||
ViewDispatcher* view_dispatcher_alloc();
|
||||
|
||||
/**
|
||||
* @brief Free ViewDispatcher
|
||||
/** Free ViewDispatcher instance
|
||||
* @param view_dispatcher pointer to ViewDispatcher
|
||||
*/
|
||||
void view_dispatcher_free(ViewDispatcher* view_dispatcher);
|
||||
|
||||
/**
|
||||
* @brief Add view to ViewDispatcher
|
||||
/** Enable queue support
|
||||
* If queue enabled all input events will be dispatched throw internal queue
|
||||
* @param view_dispatcher ViewDispatcher instance
|
||||
*/
|
||||
void view_dispatcher_enable_queue(ViewDispatcher* view_dispatcher);
|
||||
|
||||
/** Run ViewDispatcher
|
||||
* Use only after queue enabled
|
||||
* @param view_dispatcher ViewDispatcher instance
|
||||
*/
|
||||
void view_dispatcher_run(ViewDispatcher* view_dispatcher);
|
||||
|
||||
/** Stop ViewDispatcher
|
||||
* Use only after queue enabled
|
||||
* @param view_dispatcher ViewDispatcher instance
|
||||
*/
|
||||
void view_dispatcher_stop(ViewDispatcher* view_dispatcher);
|
||||
|
||||
/** Add view to ViewDispatcher
|
||||
* @param view_dispatcher, ViewDispatcher instance
|
||||
* @param view_id View id to register
|
||||
* @param view View instance
|
||||
*/
|
||||
void view_dispatcher_add_view(ViewDispatcher* view_dispatcher, uint32_t view_id, View* view);
|
||||
|
||||
/**
|
||||
* @brief Remove view from ViewDispatcher
|
||||
/** Remove view from ViewDispatcher
|
||||
* @param view_dispatcher ViewDispatcher instance
|
||||
* @param view_id View id to remove
|
||||
*/
|
||||
void view_dispatcher_remove_view(ViewDispatcher* view_dispatcher, uint32_t view_id);
|
||||
|
||||
/**
|
||||
* @brief Switch to View
|
||||
/** Switch to View
|
||||
* @param view_dispatcher ViewDispatcher instance
|
||||
* @param view_id View id to register
|
||||
*/
|
||||
void view_dispatcher_switch_to_view(ViewDispatcher* view_dispatcher, uint32_t view_id);
|
||||
|
||||
/**
|
||||
* @brief Attach ViewDispatcher to GUI
|
||||
/** Attach ViewDispatcher to GUI
|
||||
* @param view_dispatcher ViewDispatcher instance
|
||||
* @param gui GUI instance to attach to
|
||||
*/
|
||||
|
@ -1,25 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi.h>
|
||||
#include <m-dict.h>
|
||||
|
||||
#include "view_dispatcher.h"
|
||||
#include "view_i.h"
|
||||
#include <furi.h>
|
||||
#include <m-dict.h>
|
||||
#include "gui_i.h"
|
||||
|
||||
DICT_DEF2(ViewDict, uint32_t, M_DEFAULT_OPLIST, View*, M_PTR_OPLIST)
|
||||
|
||||
struct ViewDispatcher {
|
||||
osMessageQueueId_t queue;
|
||||
Gui* gui;
|
||||
ViewPort* view_port;
|
||||
ViewDict_t views;
|
||||
View* current_view;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
ViewDispatcherMessageTypeInput,
|
||||
ViewDispatcherMessageTypeStop,
|
||||
} ViewDispatcherMessageType;
|
||||
|
||||
typedef struct {
|
||||
ViewDispatcherMessageType type;
|
||||
union {
|
||||
InputEvent input;
|
||||
};
|
||||
} ViewDispatcherMessage;
|
||||
|
||||
/* ViewPort Draw Callback */
|
||||
void view_dispatcher_draw_callback(Canvas* canvas, void* context);
|
||||
|
||||
/* ViewPort Input Callback */
|
||||
void view_dispatcher_input_callback(InputEvent* event, void* context);
|
||||
|
||||
/* Input handler */
|
||||
void view_dispatcher_handle_input(ViewDispatcher* view_dispatcher, InputEvent* event);
|
||||
|
||||
/* Set current view, dispatches view enter and exit */
|
||||
void view_dispatcher_set_current_view(ViewDispatcher* view_dispatcher, View* view);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -16,9 +16,9 @@ typedef enum {
|
||||
/** Switchable Radio Paths */
|
||||
typedef enum {
|
||||
ApiHalSubGhzPathIsolate, /** Isolate Radio from antenna */
|
||||
ApiHalSubGhzPath1, /** Path 1: SW1RF1-SW2RF2, LCLCL */
|
||||
ApiHalSubGhzPath2, /** Path 2: SW1RF2-SW2RF1, LCLCLCL */
|
||||
ApiHalSubGhzPath3, /** Path 3: SW1RF3-SW2RF3, LCLC */
|
||||
ApiHalSubGhzPath433, /** Center Frquency: 433MHz. Path 1: SW1RF1-SW2RF2, LCLCL */
|
||||
ApiHalSubGhzPath315, /** Center Frquency: 315MHz. Path 2: SW1RF2-SW2RF1, LCLCLCL */
|
||||
ApiHalSubGhzPath868, /** Center Frquency: 868MHz. Path 3: SW1RF3-SW2RF3, LCLC */
|
||||
} ApiHalSubGhzPath;
|
||||
|
||||
/** Initialize and switch to power save mode
|
||||
|
@ -171,13 +171,13 @@ uint32_t api_hal_subghz_set_frequency(uint32_t value) {
|
||||
}
|
||||
|
||||
void api_hal_subghz_set_path(ApiHalSubGhzPath path) {
|
||||
if (path == ApiHalSubGhzPath1) {
|
||||
if (path == ApiHalSubGhzPath433) {
|
||||
hal_gpio_write(&gpio_rf_sw_0, 0);
|
||||
hal_gpio_write(&gpio_rf_sw_1, 1);
|
||||
} else if (path == ApiHalSubGhzPath2) {
|
||||
} else if (path == ApiHalSubGhzPath315) {
|
||||
hal_gpio_write(&gpio_rf_sw_0, 1);
|
||||
hal_gpio_write(&gpio_rf_sw_1, 0);
|
||||
} else if (path == ApiHalSubGhzPath3) {
|
||||
} else if (path == ApiHalSubGhzPath868) {
|
||||
hal_gpio_write(&gpio_rf_sw_0, 1);
|
||||
hal_gpio_write(&gpio_rf_sw_1, 1);
|
||||
} else if (path == ApiHalSubGhzPathIsolate) {
|
||||
|
@ -172,13 +172,13 @@ uint32_t api_hal_subghz_set_frequency(uint32_t value) {
|
||||
|
||||
void api_hal_subghz_set_path(ApiHalSubGhzPath path) {
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
if (path == ApiHalSubGhzPath1) {
|
||||
if (path == ApiHalSubGhzPath433) {
|
||||
hal_gpio_write(&gpio_rf_sw_0, 0);
|
||||
cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
|
||||
} else if (path == ApiHalSubGhzPath2) {
|
||||
} else if (path == ApiHalSubGhzPath315) {
|
||||
hal_gpio_write(&gpio_rf_sw_0, 1);
|
||||
cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW);
|
||||
} else if (path == ApiHalSubGhzPath3) {
|
||||
} else if (path == ApiHalSubGhzPath868) {
|
||||
hal_gpio_write(&gpio_rf_sw_0, 1);
|
||||
cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
|
||||
} else if (path == ApiHalSubGhzPathIsolate) {
|
||||
|
Loading…
Reference in New Issue
Block a user