[FL-2627] Flipper applications: SDK, build and debug system (#1387)
* Added support for running applications from SD card (FAPs - Flipper Application Packages) * Added plugin_dist target for fbt to build FAPs * All apps of type FlipperAppType.EXTERNAL and FlipperAppType.PLUGIN are built as FAPs by default * Updated VSCode configuration for new fbt features - re-deploy stock configuration to use them * Added debugging support for FAPs with fbt debug & VSCode * Added public firmware API with automated versioning Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: SG <who.just.the.doctor@gmail.com> Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
188
applications/debug/bt_debug_app/views/bt_carrier_test.c
Normal file
188
applications/debug/bt_debug_app/views/bt_carrier_test.c
Normal file
@@ -0,0 +1,188 @@
|
||||
#include "bt_carrier_test.h"
|
||||
#include "bt_test.h"
|
||||
#include "bt_test_types.h"
|
||||
#include "furi_hal_bt.h"
|
||||
|
||||
struct BtCarrierTest {
|
||||
BtTest* bt_test;
|
||||
BtTestParam* bt_param_channel;
|
||||
BtTestMode mode;
|
||||
BtTestChannel channel;
|
||||
BtTestPower power;
|
||||
FuriTimer* timer;
|
||||
};
|
||||
|
||||
static BtTestParamValue bt_param_mode[] = {
|
||||
{.value = BtTestModeRx, .str = "Rx"},
|
||||
{.value = BtTestModeTx, .str = "Tx"},
|
||||
{.value = BtTestModeTxHopping, .str = "Hopping Tx"},
|
||||
};
|
||||
|
||||
static BtTestParamValue bt_param_channel[] = {
|
||||
{.value = BtTestChannel2402, .str = "2402 MHz"},
|
||||
{.value = BtTestChannel2440, .str = "2440 MHz"},
|
||||
{.value = BtTestChannel2480, .str = "2480 MHz"},
|
||||
};
|
||||
|
||||
static BtTestParamValue bt_param_power[] = {
|
||||
{.value = BtPower0dB, .str = "0 dB"},
|
||||
{.value = BtPower2dB, .str = "2 dB"},
|
||||
{.value = BtPower4dB, .str = "4 dB"},
|
||||
{.value = BtPower6dB, .str = "6 dB"},
|
||||
};
|
||||
|
||||
static void bt_carrier_test_start(BtCarrierTest* bt_carrier_test) {
|
||||
furi_assert(bt_carrier_test);
|
||||
if(bt_carrier_test->mode == BtTestModeRx) {
|
||||
furi_hal_bt_start_packet_rx(bt_carrier_test->channel, 1);
|
||||
furi_timer_start(bt_carrier_test->timer, furi_kernel_get_tick_frequency() / 4);
|
||||
} else if(bt_carrier_test->mode == BtTestModeTxHopping) {
|
||||
furi_hal_bt_start_tone_tx(bt_carrier_test->channel, bt_carrier_test->power);
|
||||
furi_timer_start(bt_carrier_test->timer, furi_kernel_get_tick_frequency() * 2);
|
||||
} else if(bt_carrier_test->mode == BtTestModeTx) {
|
||||
furi_hal_bt_start_tone_tx(bt_carrier_test->channel, bt_carrier_test->power);
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_carrier_test_switch_channel(BtCarrierTest* bt_carrier_test) {
|
||||
furi_assert(bt_carrier_test);
|
||||
furi_hal_bt_stop_tone_tx();
|
||||
uint8_t channel_i = 0;
|
||||
if(bt_carrier_test->channel == BtTestChannel2402) {
|
||||
bt_carrier_test->channel = BtTestChannel2440;
|
||||
channel_i = 1;
|
||||
} else if(bt_carrier_test->channel == BtTestChannel2440) {
|
||||
bt_carrier_test->channel = BtTestChannel2480;
|
||||
channel_i = 2;
|
||||
} else if(bt_carrier_test->channel == BtTestChannel2480) {
|
||||
bt_carrier_test->channel = BtTestChannel2402;
|
||||
channel_i = 0;
|
||||
}
|
||||
furi_hal_bt_start_tone_tx(bt_carrier_test->channel, bt_carrier_test->power);
|
||||
bt_test_set_current_value_index(bt_carrier_test->bt_param_channel, channel_i);
|
||||
bt_test_set_current_value_text(
|
||||
bt_carrier_test->bt_param_channel, bt_param_channel[channel_i].str);
|
||||
}
|
||||
|
||||
static void bt_carrier_test_stop(BtCarrierTest* bt_carrier_test) {
|
||||
furi_assert(bt_carrier_test);
|
||||
if(bt_carrier_test->mode == BtTestModeTxHopping) {
|
||||
furi_hal_bt_stop_tone_tx();
|
||||
furi_timer_stop(bt_carrier_test->timer);
|
||||
} else if(bt_carrier_test->mode == BtTestModeTx) {
|
||||
furi_hal_bt_stop_tone_tx();
|
||||
} else if(bt_carrier_test->mode == BtTestModeRx) {
|
||||
furi_hal_bt_stop_packet_test();
|
||||
furi_timer_stop(bt_carrier_test->timer);
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t bt_carrier_test_param_changed(BtTestParam* param, BtTestParamValue* param_val) {
|
||||
furi_assert(param);
|
||||
uint8_t index = bt_test_get_current_value_index(param);
|
||||
bt_test_set_current_value_text(param, param_val[index].str);
|
||||
return param_val[index].value;
|
||||
}
|
||||
|
||||
static void bt_carrier_test_mode_changed(BtTestParam* param) {
|
||||
BtCarrierTest* bt_carrier_test = bt_test_get_context(param);
|
||||
bt_carrier_test_stop(bt_carrier_test);
|
||||
bt_carrier_test->mode = bt_carrier_test_param_changed(param, bt_param_mode);
|
||||
}
|
||||
|
||||
static void bt_carrier_test_channel_changed(BtTestParam* param) {
|
||||
BtCarrierTest* bt_carrier_test = bt_test_get_context(param);
|
||||
bt_carrier_test_stop(bt_carrier_test);
|
||||
bt_carrier_test->channel = bt_carrier_test_param_changed(param, bt_param_channel);
|
||||
}
|
||||
|
||||
static void bt_carrier_test_param_channel(BtTestParam* param) {
|
||||
BtCarrierTest* bt_carrier_test = bt_test_get_context(param);
|
||||
bt_carrier_test_stop(bt_carrier_test);
|
||||
bt_carrier_test->power = bt_carrier_test_param_changed(param, bt_param_power);
|
||||
}
|
||||
|
||||
static void bt_carrier_test_change_state_callback(BtTestState state, void* context) {
|
||||
furi_assert(context);
|
||||
BtCarrierTest* bt_carrier_test = context;
|
||||
furi_hal_bt_stop_tone_tx();
|
||||
if(state == BtTestStateStarted) {
|
||||
bt_carrier_test_start(bt_carrier_test);
|
||||
} else if(state == BtTestStateStopped) {
|
||||
bt_carrier_test_stop(bt_carrier_test);
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_carrier_test_exit_callback(void* context) {
|
||||
furi_assert(context);
|
||||
BtCarrierTest* bt_carrier_test = context;
|
||||
bt_carrier_test_stop(bt_carrier_test);
|
||||
}
|
||||
|
||||
static void bt_test_carrier_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
BtCarrierTest* bt_carrier_test = context;
|
||||
if(bt_carrier_test->mode == BtTestModeRx) {
|
||||
bt_test_set_rssi(bt_carrier_test->bt_test, furi_hal_bt_get_rssi());
|
||||
} else if(bt_carrier_test->mode == BtTestModeTxHopping) {
|
||||
bt_carrier_test_switch_channel(bt_carrier_test);
|
||||
}
|
||||
}
|
||||
|
||||
BtCarrierTest* bt_carrier_test_alloc() {
|
||||
BtCarrierTest* bt_carrier_test = malloc(sizeof(BtCarrierTest));
|
||||
bt_carrier_test->bt_test = bt_test_alloc();
|
||||
bt_test_set_context(bt_carrier_test->bt_test, bt_carrier_test);
|
||||
bt_test_set_change_state_callback(
|
||||
bt_carrier_test->bt_test, bt_carrier_test_change_state_callback);
|
||||
bt_test_set_back_callback(bt_carrier_test->bt_test, bt_carrier_test_exit_callback);
|
||||
|
||||
BtTestParam* param;
|
||||
param = bt_test_param_add(
|
||||
bt_carrier_test->bt_test,
|
||||
"Mode",
|
||||
COUNT_OF(bt_param_mode),
|
||||
bt_carrier_test_mode_changed,
|
||||
bt_carrier_test);
|
||||
bt_test_set_current_value_index(param, 0);
|
||||
bt_test_set_current_value_text(param, bt_param_mode[0].str);
|
||||
bt_carrier_test->mode = BtTestModeRx;
|
||||
|
||||
param = bt_test_param_add(
|
||||
bt_carrier_test->bt_test,
|
||||
"Channel",
|
||||
COUNT_OF(bt_param_channel),
|
||||
bt_carrier_test_channel_changed,
|
||||
bt_carrier_test);
|
||||
bt_test_set_current_value_index(param, 0);
|
||||
bt_test_set_current_value_text(param, bt_param_channel[0].str);
|
||||
bt_carrier_test->channel = BtTestChannel2402;
|
||||
bt_carrier_test->bt_param_channel = param;
|
||||
|
||||
param = bt_test_param_add(
|
||||
bt_carrier_test->bt_test,
|
||||
"Power",
|
||||
COUNT_OF(bt_param_power),
|
||||
bt_carrier_test_param_channel,
|
||||
bt_carrier_test);
|
||||
bt_test_set_current_value_index(param, 0);
|
||||
bt_test_set_current_value_text(param, bt_param_power[0].str);
|
||||
bt_carrier_test->power = BtPower0dB;
|
||||
|
||||
bt_carrier_test->timer =
|
||||
furi_timer_alloc(bt_test_carrier_timer_callback, FuriTimerTypePeriodic, bt_carrier_test);
|
||||
|
||||
return bt_carrier_test;
|
||||
}
|
||||
|
||||
void bt_carrier_test_free(BtCarrierTest* bt_carrier_test) {
|
||||
furi_assert(bt_carrier_test);
|
||||
bt_test_free(bt_carrier_test->bt_test);
|
||||
furi_timer_free(bt_carrier_test->timer);
|
||||
free(bt_carrier_test);
|
||||
}
|
||||
|
||||
View* bt_carrier_test_get_view(BtCarrierTest* bt_carrier_test) {
|
||||
furi_assert(bt_carrier_test);
|
||||
return bt_test_get_view(bt_carrier_test->bt_test);
|
||||
}
|
10
applications/debug/bt_debug_app/views/bt_carrier_test.h
Normal file
10
applications/debug/bt_debug_app/views/bt_carrier_test.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include <gui/view.h>
|
||||
|
||||
typedef struct BtCarrierTest BtCarrierTest;
|
||||
|
||||
BtCarrierTest* bt_carrier_test_alloc();
|
||||
|
||||
void bt_carrier_test_free(BtCarrierTest* bt_carrier_test);
|
||||
|
||||
View* bt_carrier_test_get_view(BtCarrierTest* bt_carrier_test);
|
155
applications/debug/bt_debug_app/views/bt_packet_test.c
Normal file
155
applications/debug/bt_debug_app/views/bt_packet_test.c
Normal file
@@ -0,0 +1,155 @@
|
||||
#include "bt_packet_test.h"
|
||||
#include "bt_test.h"
|
||||
#include "bt_test_types.h"
|
||||
#include "furi_hal_bt.h"
|
||||
|
||||
struct BtPacketTest {
|
||||
BtTest* bt_test;
|
||||
BtTestMode mode;
|
||||
BtTestChannel channel;
|
||||
BtTestDataRate data_rate;
|
||||
FuriTimer* timer;
|
||||
};
|
||||
|
||||
static BtTestParamValue bt_param_mode[] = {
|
||||
{.value = BtTestModeRx, .str = "Rx"},
|
||||
{.value = BtTestModeTx, .str = "Tx"},
|
||||
};
|
||||
|
||||
static BtTestParamValue bt_param_channel[] = {
|
||||
{.value = BtTestChannel2402, .str = "2402 MHz"},
|
||||
{.value = BtTestChannel2440, .str = "2440 MHz"},
|
||||
{.value = BtTestChannel2480, .str = "2480 MHz"},
|
||||
};
|
||||
|
||||
static BtTestParamValue bt_param_data_rate[] = {
|
||||
{.value = BtDataRate1M, .str = "1 Mbps"},
|
||||
{.value = BtDataRate2M, .str = "2 Mbps"},
|
||||
};
|
||||
|
||||
static void bt_packet_test_start(BtPacketTest* bt_packet_test) {
|
||||
furi_assert(bt_packet_test);
|
||||
if(bt_packet_test->mode == BtTestModeRx) {
|
||||
furi_hal_bt_start_packet_rx(bt_packet_test->channel, bt_packet_test->data_rate);
|
||||
furi_timer_start(bt_packet_test->timer, furi_kernel_get_tick_frequency() / 4);
|
||||
} else if(bt_packet_test->mode == BtTestModeTx) {
|
||||
furi_hal_bt_start_packet_tx(bt_packet_test->channel, 1, bt_packet_test->data_rate);
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_packet_test_stop(BtPacketTest* bt_packet_test) {
|
||||
furi_assert(bt_packet_test);
|
||||
if(bt_packet_test->mode == BtTestModeTx) {
|
||||
furi_hal_bt_stop_packet_test();
|
||||
bt_test_set_packets_tx(bt_packet_test->bt_test, furi_hal_bt_get_transmitted_packets());
|
||||
} else if(bt_packet_test->mode == BtTestModeRx) {
|
||||
bt_test_set_packets_rx(bt_packet_test->bt_test, furi_hal_bt_stop_packet_test());
|
||||
furi_timer_stop(bt_packet_test->timer);
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t bt_packet_test_param_changed(BtTestParam* param, BtTestParamValue* param_val) {
|
||||
furi_assert(param);
|
||||
uint8_t index = bt_test_get_current_value_index(param);
|
||||
bt_test_set_current_value_text(param, param_val[index].str);
|
||||
return param_val[index].value;
|
||||
}
|
||||
|
||||
static void bt_packet_test_mode_changed(BtTestParam* param) {
|
||||
BtPacketTest* bt_packet_test = bt_test_get_context(param);
|
||||
bt_packet_test_stop(bt_packet_test);
|
||||
bt_packet_test->mode = bt_packet_test_param_changed(param, bt_param_mode);
|
||||
}
|
||||
|
||||
static void bt_packet_test_channel_changed(BtTestParam* param) {
|
||||
BtPacketTest* bt_packet_test = bt_test_get_context(param);
|
||||
bt_packet_test_stop(bt_packet_test);
|
||||
bt_packet_test->channel = bt_packet_test_param_changed(param, bt_param_channel);
|
||||
}
|
||||
|
||||
static void bt_packet_test_param_channel(BtTestParam* param) {
|
||||
BtPacketTest* bt_packet_test = bt_test_get_context(param);
|
||||
bt_packet_test_stop(bt_packet_test);
|
||||
bt_packet_test->data_rate = bt_packet_test_param_changed(param, bt_param_data_rate);
|
||||
}
|
||||
|
||||
static void bt_packet_test_change_state_callback(BtTestState state, void* context) {
|
||||
furi_assert(context);
|
||||
BtPacketTest* bt_packet_test = context;
|
||||
if(state == BtTestStateStarted) {
|
||||
bt_packet_test_start(bt_packet_test);
|
||||
} else if(state == BtTestStateStopped) {
|
||||
bt_packet_test_stop(bt_packet_test);
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_packet_test_exit_callback(void* context) {
|
||||
furi_assert(context);
|
||||
BtPacketTest* bt_packet_test = context;
|
||||
bt_packet_test_stop(bt_packet_test);
|
||||
}
|
||||
|
||||
static void bt_test_packet_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
BtPacketTest* bt_packet_test = context;
|
||||
if(bt_packet_test->mode == BtTestModeRx) {
|
||||
bt_test_set_rssi(bt_packet_test->bt_test, furi_hal_bt_get_rssi());
|
||||
}
|
||||
}
|
||||
|
||||
BtPacketTest* bt_packet_test_alloc() {
|
||||
BtPacketTest* bt_packet_test = malloc(sizeof(BtPacketTest));
|
||||
bt_packet_test->bt_test = bt_test_alloc();
|
||||
bt_test_set_context(bt_packet_test->bt_test, bt_packet_test);
|
||||
bt_test_set_change_state_callback(
|
||||
bt_packet_test->bt_test, bt_packet_test_change_state_callback);
|
||||
bt_test_set_back_callback(bt_packet_test->bt_test, bt_packet_test_exit_callback);
|
||||
|
||||
BtTestParam* param;
|
||||
param = bt_test_param_add(
|
||||
bt_packet_test->bt_test,
|
||||
"Mode",
|
||||
COUNT_OF(bt_param_mode),
|
||||
bt_packet_test_mode_changed,
|
||||
bt_packet_test);
|
||||
bt_test_set_current_value_index(param, 0);
|
||||
bt_test_set_current_value_text(param, bt_param_mode[0].str);
|
||||
bt_packet_test->mode = BtTestModeRx;
|
||||
|
||||
param = bt_test_param_add(
|
||||
bt_packet_test->bt_test,
|
||||
"Channel",
|
||||
COUNT_OF(bt_param_channel),
|
||||
bt_packet_test_channel_changed,
|
||||
bt_packet_test);
|
||||
bt_test_set_current_value_index(param, 0);
|
||||
bt_test_set_current_value_text(param, bt_param_channel[0].str);
|
||||
bt_packet_test->channel = BtTestChannel2402;
|
||||
|
||||
param = bt_test_param_add(
|
||||
bt_packet_test->bt_test,
|
||||
"Data rate",
|
||||
COUNT_OF(bt_param_data_rate),
|
||||
bt_packet_test_param_channel,
|
||||
bt_packet_test);
|
||||
bt_test_set_current_value_index(param, 0);
|
||||
bt_test_set_current_value_text(param, bt_param_data_rate[0].str);
|
||||
bt_packet_test->data_rate = BtDataRate1M;
|
||||
|
||||
bt_packet_test->timer =
|
||||
furi_timer_alloc(bt_test_packet_timer_callback, FuriTimerTypePeriodic, bt_packet_test);
|
||||
|
||||
return bt_packet_test;
|
||||
}
|
||||
|
||||
void bt_packet_test_free(BtPacketTest* bt_packet_test) {
|
||||
furi_assert(bt_packet_test);
|
||||
bt_test_free(bt_packet_test->bt_test);
|
||||
furi_timer_free(bt_packet_test->timer);
|
||||
free(bt_packet_test);
|
||||
}
|
||||
|
||||
View* bt_packet_test_get_view(BtPacketTest* bt_packet_test) {
|
||||
furi_assert(bt_packet_test);
|
||||
return bt_test_get_view(bt_packet_test->bt_test);
|
||||
}
|
10
applications/debug/bt_debug_app/views/bt_packet_test.h
Normal file
10
applications/debug/bt_debug_app/views/bt_packet_test.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include <gui/view.h>
|
||||
|
||||
typedef struct BtPacketTest BtPacketTest;
|
||||
|
||||
BtPacketTest* bt_packet_test_alloc();
|
||||
|
||||
void bt_packet_test_free(BtPacketTest* bt_packet_test);
|
||||
|
||||
View* bt_packet_test_get_view(BtPacketTest* bt_packet_test);
|
422
applications/debug/bt_debug_app/views/bt_test.c
Normal file
422
applications/debug/bt_debug_app/views/bt_test.c
Normal file
@@ -0,0 +1,422 @@
|
||||
#include "bt_test.h"
|
||||
|
||||
#include <gui/canvas.h>
|
||||
#include <gui/elements.h>
|
||||
#include <m-array.h>
|
||||
#include <m-string.h>
|
||||
#include <furi.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct BtTestParam {
|
||||
const char* label;
|
||||
uint8_t current_value_index;
|
||||
string_t current_value_text;
|
||||
uint8_t values_count;
|
||||
BtTestParamChangeCallback change_callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
ARRAY_DEF(BtTestParamArray, BtTestParam, M_POD_OPLIST);
|
||||
|
||||
struct BtTest {
|
||||
View* view;
|
||||
BtTestChangeStateCallback change_state_callback;
|
||||
BtTestBackCallback back_callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
BtTestState state;
|
||||
BtTestParamArray_t params;
|
||||
uint8_t position;
|
||||
uint8_t window_position;
|
||||
const char* message;
|
||||
float rssi;
|
||||
uint32_t packets_num_rx;
|
||||
uint32_t packets_num_tx;
|
||||
} BtTestModel;
|
||||
|
||||
#define BT_TEST_START_MESSAGE "Ok - Start"
|
||||
#define BT_TEST_STOP_MESSAGE "Ok - Stop"
|
||||
|
||||
static void bt_test_process_up(BtTest* bt_test);
|
||||
static void bt_test_process_down(BtTest* bt_test);
|
||||
static void bt_test_process_left(BtTest* bt_test);
|
||||
static void bt_test_process_right(BtTest* bt_test);
|
||||
static void bt_test_process_ok(BtTest* bt_test);
|
||||
static void bt_test_process_back(BtTest* bt_test);
|
||||
|
||||
static void bt_test_draw_callback(Canvas* canvas, void* _model) {
|
||||
BtTestModel* model = _model;
|
||||
char info_str[32];
|
||||
|
||||
const uint8_t param_height = 16;
|
||||
const uint8_t param_width = 123;
|
||||
|
||||
canvas_clear(canvas);
|
||||
|
||||
uint8_t position = 0;
|
||||
BtTestParamArray_it_t it;
|
||||
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
for(BtTestParamArray_it(it, model->params); !BtTestParamArray_end_p(it);
|
||||
BtTestParamArray_next(it)) {
|
||||
uint8_t param_position = position - model->window_position;
|
||||
uint8_t params_on_screen = 3;
|
||||
uint8_t y_offset = 0;
|
||||
|
||||
if(param_position < params_on_screen) {
|
||||
const BtTestParam* param = BtTestParamArray_cref(it);
|
||||
uint8_t param_y = y_offset + (param_position * param_height);
|
||||
uint8_t param_text_y = param_y + param_height - 4;
|
||||
|
||||
if(position == model->position) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
elements_slightly_rounded_box(
|
||||
canvas, 0, param_y + 1, param_width, param_height - 2);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
} else {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
}
|
||||
|
||||
canvas_draw_str(canvas, 6, param_text_y, param->label);
|
||||
|
||||
if(param->current_value_index > 0) {
|
||||
canvas_draw_str(canvas, 50, param_text_y, "<");
|
||||
}
|
||||
|
||||
canvas_draw_str(canvas, 61, param_text_y, string_get_cstr(param->current_value_text));
|
||||
|
||||
if(param->current_value_index < (param->values_count - 1)) {
|
||||
canvas_draw_str(canvas, 113, param_text_y, ">");
|
||||
}
|
||||
}
|
||||
|
||||
position++;
|
||||
}
|
||||
|
||||
elements_scrollbar(canvas, model->position, BtTestParamArray_size(model->params));
|
||||
canvas_draw_str(canvas, 6, 60, model->message);
|
||||
if(model->state == BtTestStateStarted) {
|
||||
if(model->rssi != 0.0f) {
|
||||
snprintf(info_str, sizeof(info_str), "RSSI:%3.1f dB", (double)model->rssi);
|
||||
canvas_draw_str_aligned(canvas, 124, 60, AlignRight, AlignBottom, info_str);
|
||||
}
|
||||
} else if(model->state == BtTestStateStopped) {
|
||||
if(model->packets_num_rx) {
|
||||
snprintf(info_str, sizeof(info_str), "%ld pack rcv", model->packets_num_rx);
|
||||
canvas_draw_str_aligned(canvas, 124, 60, AlignRight, AlignBottom, info_str);
|
||||
} else if(model->packets_num_tx) {
|
||||
snprintf(info_str, sizeof(info_str), "%ld pack sent", model->packets_num_tx);
|
||||
canvas_draw_str_aligned(canvas, 124, 60, AlignRight, AlignBottom, info_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool bt_test_input_callback(InputEvent* event, void* context) {
|
||||
BtTest* bt_test = context;
|
||||
furi_assert(bt_test);
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == InputTypeShort) {
|
||||
switch(event->key) {
|
||||
case InputKeyUp:
|
||||
consumed = true;
|
||||
bt_test_process_up(bt_test);
|
||||
break;
|
||||
case InputKeyDown:
|
||||
consumed = true;
|
||||
bt_test_process_down(bt_test);
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
consumed = true;
|
||||
bt_test_process_left(bt_test);
|
||||
break;
|
||||
case InputKeyRight:
|
||||
consumed = true;
|
||||
bt_test_process_right(bt_test);
|
||||
break;
|
||||
case InputKeyOk:
|
||||
consumed = true;
|
||||
bt_test_process_ok(bt_test);
|
||||
break;
|
||||
case InputKeyBack:
|
||||
consumed = false;
|
||||
bt_test_process_back(bt_test);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void bt_test_process_up(BtTest* bt_test) {
|
||||
with_view_model(
|
||||
bt_test->view, (BtTestModel * model) {
|
||||
uint8_t params_on_screen = 3;
|
||||
if(model->position > 0) {
|
||||
model->position--;
|
||||
if(((model->position - model->window_position) < 1) &&
|
||||
model->window_position > 0) {
|
||||
model->window_position--;
|
||||
}
|
||||
} else {
|
||||
model->position = BtTestParamArray_size(model->params) - 1;
|
||||
if(model->position > (params_on_screen - 1)) {
|
||||
model->window_position = model->position - (params_on_screen - 1);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void bt_test_process_down(BtTest* bt_test) {
|
||||
with_view_model(
|
||||
bt_test->view, (BtTestModel * model) {
|
||||
uint8_t params_on_screen = 3;
|
||||
if(model->position < (BtTestParamArray_size(model->params) - 1)) {
|
||||
model->position++;
|
||||
if((model->position - model->window_position) > (params_on_screen - 2) &&
|
||||
model->window_position <
|
||||
(BtTestParamArray_size(model->params) - params_on_screen)) {
|
||||
model->window_position++;
|
||||
}
|
||||
} else {
|
||||
model->position = 0;
|
||||
model->window_position = 0;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
BtTestParam* bt_test_get_selected_param(BtTestModel* model) {
|
||||
BtTestParam* param = NULL;
|
||||
|
||||
BtTestParamArray_it_t it;
|
||||
uint8_t position = 0;
|
||||
for(BtTestParamArray_it(it, model->params); !BtTestParamArray_end_p(it);
|
||||
BtTestParamArray_next(it)) {
|
||||
if(position == model->position) {
|
||||
break;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
|
||||
param = BtTestParamArray_ref(it);
|
||||
|
||||
furi_assert(param);
|
||||
return param;
|
||||
}
|
||||
|
||||
void bt_test_process_left(BtTest* bt_test) {
|
||||
BtTestParam* param;
|
||||
with_view_model(
|
||||
bt_test->view, (BtTestModel * model) {
|
||||
param = bt_test_get_selected_param(model);
|
||||
if(param->current_value_index > 0) {
|
||||
param->current_value_index--;
|
||||
if(param->change_callback) {
|
||||
model->state = BtTestStateStopped;
|
||||
model->message = BT_TEST_START_MESSAGE;
|
||||
model->rssi = 0.0f;
|
||||
model->packets_num_rx = 0;
|
||||
model->packets_num_tx = 0;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if(param->change_callback) {
|
||||
param->change_callback(param);
|
||||
}
|
||||
}
|
||||
|
||||
void bt_test_process_right(BtTest* bt_test) {
|
||||
BtTestParam* param;
|
||||
with_view_model(
|
||||
bt_test->view, (BtTestModel * model) {
|
||||
param = bt_test_get_selected_param(model);
|
||||
if(param->current_value_index < (param->values_count - 1)) {
|
||||
param->current_value_index++;
|
||||
if(param->change_callback) {
|
||||
model->state = BtTestStateStopped;
|
||||
model->message = BT_TEST_START_MESSAGE;
|
||||
model->rssi = 0.0f;
|
||||
model->packets_num_rx = 0;
|
||||
model->packets_num_tx = 0;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if(param->change_callback) {
|
||||
param->change_callback(param);
|
||||
}
|
||||
}
|
||||
|
||||
void bt_test_process_ok(BtTest* bt_test) {
|
||||
BtTestState state;
|
||||
with_view_model(
|
||||
bt_test->view, (BtTestModel * model) {
|
||||
if(model->state == BtTestStateStarted) {
|
||||
model->state = BtTestStateStopped;
|
||||
model->message = BT_TEST_START_MESSAGE;
|
||||
model->rssi = 0.0f;
|
||||
model->packets_num_rx = 0;
|
||||
model->packets_num_tx = 0;
|
||||
} else if(model->state == BtTestStateStopped) {
|
||||
model->state = BtTestStateStarted;
|
||||
model->message = BT_TEST_STOP_MESSAGE;
|
||||
}
|
||||
state = model->state;
|
||||
return true;
|
||||
});
|
||||
if(bt_test->change_state_callback) {
|
||||
bt_test->change_state_callback(state, bt_test->context);
|
||||
}
|
||||
}
|
||||
|
||||
void bt_test_process_back(BtTest* bt_test) {
|
||||
with_view_model(
|
||||
bt_test->view, (BtTestModel * model) {
|
||||
model->state = BtTestStateStopped;
|
||||
model->rssi = 0.0f;
|
||||
model->packets_num_rx = 0;
|
||||
model->packets_num_tx = 0;
|
||||
return false;
|
||||
});
|
||||
if(bt_test->back_callback) {
|
||||
bt_test->back_callback(bt_test->context);
|
||||
}
|
||||
}
|
||||
|
||||
BtTest* bt_test_alloc() {
|
||||
BtTest* bt_test = malloc(sizeof(BtTest));
|
||||
bt_test->view = view_alloc();
|
||||
view_set_context(bt_test->view, bt_test);
|
||||
view_allocate_model(bt_test->view, ViewModelTypeLocking, sizeof(BtTestModel));
|
||||
view_set_draw_callback(bt_test->view, bt_test_draw_callback);
|
||||
view_set_input_callback(bt_test->view, bt_test_input_callback);
|
||||
|
||||
with_view_model(
|
||||
bt_test->view, (BtTestModel * model) {
|
||||
model->state = BtTestStateStopped;
|
||||
model->message = "Ok - Start";
|
||||
BtTestParamArray_init(model->params);
|
||||
model->position = 0;
|
||||
model->window_position = 0;
|
||||
model->rssi = 0.0f;
|
||||
model->packets_num_tx = 0;
|
||||
model->packets_num_rx = 0;
|
||||
return true;
|
||||
});
|
||||
|
||||
return bt_test;
|
||||
}
|
||||
|
||||
void bt_test_free(BtTest* bt_test) {
|
||||
furi_assert(bt_test);
|
||||
|
||||
with_view_model(
|
||||
bt_test->view, (BtTestModel * model) {
|
||||
BtTestParamArray_it_t it;
|
||||
for(BtTestParamArray_it(it, model->params); !BtTestParamArray_end_p(it);
|
||||
BtTestParamArray_next(it)) {
|
||||
string_clear(BtTestParamArray_ref(it)->current_value_text);
|
||||
}
|
||||
BtTestParamArray_clear(model->params);
|
||||
return false;
|
||||
});
|
||||
view_free(bt_test->view);
|
||||
free(bt_test);
|
||||
}
|
||||
|
||||
View* bt_test_get_view(BtTest* bt_test) {
|
||||
furi_assert(bt_test);
|
||||
return bt_test->view;
|
||||
}
|
||||
|
||||
BtTestParam* bt_test_param_add(
|
||||
BtTest* bt_test,
|
||||
const char* label,
|
||||
uint8_t values_count,
|
||||
BtTestParamChangeCallback change_callback,
|
||||
void* context) {
|
||||
BtTestParam* param = NULL;
|
||||
furi_assert(label);
|
||||
furi_assert(bt_test);
|
||||
|
||||
with_view_model(
|
||||
bt_test->view, (BtTestModel * model) {
|
||||
param = BtTestParamArray_push_new(model->params);
|
||||
param->label = label;
|
||||
param->values_count = values_count;
|
||||
param->change_callback = change_callback;
|
||||
param->context = context;
|
||||
param->current_value_index = 0;
|
||||
string_init(param->current_value_text);
|
||||
return true;
|
||||
});
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
void bt_test_set_rssi(BtTest* bt_test, float rssi) {
|
||||
furi_assert(bt_test);
|
||||
with_view_model(
|
||||
bt_test->view, (BtTestModel * model) {
|
||||
model->rssi = rssi;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void bt_test_set_packets_tx(BtTest* bt_test, uint32_t packets_num) {
|
||||
furi_assert(bt_test);
|
||||
with_view_model(
|
||||
bt_test->view, (BtTestModel * model) {
|
||||
model->packets_num_tx = packets_num;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void bt_test_set_packets_rx(BtTest* bt_test, uint32_t packets_num) {
|
||||
furi_assert(bt_test);
|
||||
with_view_model(
|
||||
bt_test->view, (BtTestModel * model) {
|
||||
model->packets_num_rx = packets_num;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void bt_test_set_change_state_callback(BtTest* bt_test, BtTestChangeStateCallback callback) {
|
||||
furi_assert(bt_test);
|
||||
furi_assert(callback);
|
||||
bt_test->change_state_callback = callback;
|
||||
}
|
||||
|
||||
void bt_test_set_back_callback(BtTest* bt_test, BtTestBackCallback callback) {
|
||||
furi_assert(bt_test);
|
||||
furi_assert(callback);
|
||||
bt_test->back_callback = callback;
|
||||
}
|
||||
|
||||
void bt_test_set_context(BtTest* bt_test, void* context) {
|
||||
furi_assert(bt_test);
|
||||
bt_test->context = context;
|
||||
}
|
||||
|
||||
void bt_test_set_current_value_index(BtTestParam* param, uint8_t current_value_index) {
|
||||
param->current_value_index = current_value_index;
|
||||
}
|
||||
|
||||
void bt_test_set_current_value_text(BtTestParam* param, const char* current_value_text) {
|
||||
string_set_str(param->current_value_text, current_value_text);
|
||||
}
|
||||
|
||||
uint8_t bt_test_get_current_value_index(BtTestParam* param) {
|
||||
return param->current_value_index;
|
||||
}
|
||||
|
||||
void* bt_test_get_context(BtTestParam* param) {
|
||||
return param->context;
|
||||
}
|
46
applications/debug/bt_debug_app/views/bt_test.h
Normal file
46
applications/debug/bt_debug_app/views/bt_test.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
#include <gui/view.h>
|
||||
|
||||
typedef enum {
|
||||
BtTestStateStarted,
|
||||
BtTestStateStopped,
|
||||
} BtTestState;
|
||||
|
||||
typedef struct BtTest BtTest;
|
||||
typedef void (*BtTestChangeStateCallback)(BtTestState state, void* context);
|
||||
typedef void (*BtTestBackCallback)(void* context);
|
||||
typedef struct BtTestParam BtTestParam;
|
||||
typedef void (*BtTestParamChangeCallback)(BtTestParam* param);
|
||||
|
||||
BtTest* bt_test_alloc();
|
||||
|
||||
void bt_test_free(BtTest* bt_test);
|
||||
|
||||
View* bt_test_get_view(BtTest* bt_test);
|
||||
|
||||
BtTestParam* bt_test_param_add(
|
||||
BtTest* bt_test,
|
||||
const char* label,
|
||||
uint8_t values_count,
|
||||
BtTestParamChangeCallback change_callback,
|
||||
void* context);
|
||||
|
||||
void bt_test_set_change_state_callback(BtTest* bt_test, BtTestChangeStateCallback callback);
|
||||
|
||||
void bt_test_set_back_callback(BtTest* bt_test, BtTestBackCallback callback);
|
||||
|
||||
void bt_test_set_context(BtTest* bt_test, void* context);
|
||||
|
||||
void bt_test_set_rssi(BtTest* bt_test, float rssi);
|
||||
|
||||
void bt_test_set_packets_tx(BtTest* bt_test, uint32_t packets_num);
|
||||
|
||||
void bt_test_set_packets_rx(BtTest* bt_test, uint32_t packets_num);
|
||||
|
||||
void bt_test_set_current_value_index(BtTestParam* param, uint8_t current_value_index);
|
||||
|
||||
void bt_test_set_current_value_text(BtTestParam* param, const char* current_value_text);
|
||||
|
||||
uint8_t bt_test_get_current_value_index(BtTestParam* param);
|
||||
|
||||
void* bt_test_get_context(BtTestParam* param);
|
30
applications/debug/bt_debug_app/views/bt_test_types.h
Normal file
30
applications/debug/bt_debug_app/views/bt_test_types.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum {
|
||||
BtTestModeRx,
|
||||
BtTestModeTx,
|
||||
BtTestModeTxHopping,
|
||||
} BtTestMode;
|
||||
|
||||
typedef enum {
|
||||
BtTestChannel2402 = 0,
|
||||
BtTestChannel2440 = 19,
|
||||
BtTestChannel2480 = 39,
|
||||
} BtTestChannel;
|
||||
|
||||
typedef enum {
|
||||
BtPower0dB = 0x19,
|
||||
BtPower2dB = 0x1B,
|
||||
BtPower4dB = 0x1D,
|
||||
BtPower6dB = 0x1F,
|
||||
} BtTestPower;
|
||||
|
||||
typedef enum {
|
||||
BtDataRate1M = 1,
|
||||
BtDataRate2M = 2,
|
||||
} BtTestDataRate;
|
||||
|
||||
typedef struct {
|
||||
uint32_t value;
|
||||
const char* str;
|
||||
} BtTestParamValue;
|
Reference in New Issue
Block a user