[FL-2230] SubGhz: protocol API refactoring (#969)

* SubGhz: protocols library refactoring
* SubGhz: new architecture and refactoring
* SubGhz: simplify protocol structure, remove unused types
* SubGhz: rename Subghz to SubGhz
* SubGhz: add environment concept

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
This commit is contained in:
Skorpionm
2022-03-03 13:48:56 +04:00
committed by GitHub
parent 052237f8c9
commit 3164184bbc
173 changed files with 9836 additions and 8486 deletions

View File

@@ -7,29 +7,29 @@
#include <furi_hal.h>
#include <input/input.h>
struct SubghzTestCarrier {
struct SubGhzTestCarrier {
View* view;
osTimerId_t timer;
SubghzTestCarrierCallback callback;
SubGhzTestCarrierCallback callback;
void* context;
};
typedef enum {
SubghzTestCarrierModelStatusRx,
SubghzTestCarrierModelStatusTx,
} SubghzTestCarrierModelStatus;
SubGhzTestCarrierModelStatusRx,
SubGhzTestCarrierModelStatusTx,
} SubGhzTestCarrierModelStatus;
typedef struct {
uint8_t frequency;
uint32_t real_frequency;
FuriHalSubGhzPath path;
float rssi;
SubghzTestCarrierModelStatus status;
} SubghzTestCarrierModel;
SubGhzTestCarrierModelStatus status;
} SubGhzTestCarrierModel;
void subghz_test_carrier_set_callback(
SubghzTestCarrier* subghz_test_carrier,
SubghzTestCarrierCallback callback,
SubGhzTestCarrier* subghz_test_carrier,
SubGhzTestCarrierCallback callback,
void* context) {
furi_assert(subghz_test_carrier);
furi_assert(callback);
@@ -37,7 +37,7 @@ void subghz_test_carrier_set_callback(
subghz_test_carrier->context = context;
}
void subghz_test_carrier_draw(Canvas* canvas, SubghzTestCarrierModel* model) {
void subghz_test_carrier_draw(Canvas* canvas, SubGhzTestCarrierModel* model) {
char buffer[64];
canvas_set_color(canvas, ColorBlack);
@@ -67,7 +67,7 @@ void subghz_test_carrier_draw(Canvas* canvas, SubghzTestCarrierModel* model) {
}
snprintf(buffer, sizeof(buffer), "Path: %d - %s", model->path, path_name);
canvas_draw_str(canvas, 0, 31, buffer);
if(model->status == SubghzTestCarrierModelStatusRx) {
if(model->status == SubGhzTestCarrierModelStatusRx) {
snprintf(
buffer,
sizeof(buffer),
@@ -82,14 +82,14 @@ void subghz_test_carrier_draw(Canvas* canvas, SubghzTestCarrierModel* model) {
bool subghz_test_carrier_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzTestCarrier* subghz_test_carrier = context;
SubGhzTestCarrier* subghz_test_carrier = context;
if(event->key == InputKeyBack || event->type != InputTypeShort) {
return false;
}
with_view_model(
subghz_test_carrier->view, (SubghzTestCarrierModel * model) {
subghz_test_carrier->view, (SubGhzTestCarrierModel * model) {
furi_hal_subghz_idle();
if(event->key == InputKeyLeft) {
@@ -101,10 +101,10 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
} else if(event->key == InputKeyUp) {
if(model->path < FuriHalSubGhzPath868) model->path++;
} else if(event->key == InputKeyOk) {
if(model->status == SubghzTestCarrierModelStatusTx) {
model->status = SubghzTestCarrierModelStatusRx;
if(model->status == SubGhzTestCarrierModelStatusTx) {
model->status = SubGhzTestCarrierModelStatusRx;
} else {
model->status = SubghzTestCarrierModelStatusTx;
model->status = SubGhzTestCarrierModelStatusTx;
}
}
@@ -112,7 +112,7 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
furi_hal_subghz_set_path(model->path);
if(model->status == SubghzTestCarrierModelStatusRx) {
if(model->status == SubGhzTestCarrierModelStatusRx) {
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_subghz_rx();
} else {
@@ -121,7 +121,7 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
if(!furi_hal_subghz_tx()) {
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
subghz_test_carrier->callback(
SubghzTestCarrierEventOnlyRx, subghz_test_carrier->context);
SubGhzTestCarrierEventOnlyRx, subghz_test_carrier->context);
}
}
@@ -133,7 +133,7 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
void subghz_test_carrier_enter(void* context) {
furi_assert(context);
SubghzTestCarrier* subghz_test_carrier = context;
SubGhzTestCarrier* subghz_test_carrier = context;
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
@@ -141,13 +141,13 @@ void subghz_test_carrier_enter(void* context) {
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
with_view_model(
subghz_test_carrier->view, (SubghzTestCarrierModel * model) {
subghz_test_carrier->view, (SubGhzTestCarrierModel * model) {
model->frequency = subghz_frequencies_433_92_testing; // 433
model->real_frequency =
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
model->path = FuriHalSubGhzPathIsolate; // isolate
model->rssi = 0.0f;
model->status = SubghzTestCarrierModelStatusRx;
model->status = SubGhzTestCarrierModelStatusRx;
return true;
});
@@ -158,7 +158,7 @@ void subghz_test_carrier_enter(void* context) {
void subghz_test_carrier_exit(void* context) {
furi_assert(context);
SubghzTestCarrier* subghz_test_carrier = context;
SubGhzTestCarrier* subghz_test_carrier = context;
osTimerStop(subghz_test_carrier->timer);
@@ -168,11 +168,11 @@ void subghz_test_carrier_exit(void* context) {
void subghz_test_carrier_rssi_timer_callback(void* context) {
furi_assert(context);
SubghzTestCarrier* subghz_test_carrier = context;
SubGhzTestCarrier* subghz_test_carrier = context;
with_view_model(
subghz_test_carrier->view, (SubghzTestCarrierModel * model) {
if(model->status == SubghzTestCarrierModelStatusRx) {
subghz_test_carrier->view, (SubGhzTestCarrierModel * model) {
if(model->status == SubGhzTestCarrierModelStatusRx) {
model->rssi = furi_hal_subghz_get_rssi();
return true;
}
@@ -180,13 +180,13 @@ void subghz_test_carrier_rssi_timer_callback(void* context) {
});
}
SubghzTestCarrier* subghz_test_carrier_alloc() {
SubghzTestCarrier* subghz_test_carrier = malloc(sizeof(SubghzTestCarrier));
SubGhzTestCarrier* subghz_test_carrier_alloc() {
SubGhzTestCarrier* subghz_test_carrier = malloc(sizeof(SubGhzTestCarrier));
// View allocation and configuration
subghz_test_carrier->view = view_alloc();
view_allocate_model(
subghz_test_carrier->view, ViewModelTypeLocking, sizeof(SubghzTestCarrierModel));
subghz_test_carrier->view, ViewModelTypeLocking, sizeof(SubGhzTestCarrierModel));
view_set_context(subghz_test_carrier->view, subghz_test_carrier);
view_set_draw_callback(subghz_test_carrier->view, (ViewDrawCallback)subghz_test_carrier_draw);
view_set_input_callback(subghz_test_carrier->view, subghz_test_carrier_input);
@@ -199,14 +199,14 @@ SubghzTestCarrier* subghz_test_carrier_alloc() {
return subghz_test_carrier;
}
void subghz_test_carrier_free(SubghzTestCarrier* subghz_test_carrier) {
void subghz_test_carrier_free(SubGhzTestCarrier* subghz_test_carrier) {
furi_assert(subghz_test_carrier);
osTimerDelete(subghz_test_carrier->timer);
view_free(subghz_test_carrier->view);
free(subghz_test_carrier);
}
View* subghz_test_carrier_get_view(SubghzTestCarrier* subghz_test_carrier) {
View* subghz_test_carrier_get_view(SubGhzTestCarrier* subghz_test_carrier) {
furi_assert(subghz_test_carrier);
return subghz_test_carrier->view;
}