2021-03-11 09:31:07 +00:00
|
|
|
#include "bt_views.h"
|
|
|
|
|
2021-06-02 14:09:02 +00:00
|
|
|
void bt_view_test_carrier_draw(Canvas* canvas, void* model) {
|
|
|
|
BtViewTestCarrierModel* m = model;
|
2021-03-11 09:31:07 +00:00
|
|
|
canvas_clear(canvas);
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
2021-07-18 18:09:00 +00:00
|
|
|
canvas_draw_str(canvas, 0, 12, "Performing Carrier test");
|
2021-06-02 14:09:02 +00:00
|
|
|
if(m->type == BtStateCarrierTx) {
|
|
|
|
canvas_draw_str(canvas, 0, 24, "Manual Carrier TX");
|
|
|
|
} else if(m->type == BtStateHoppingTx) {
|
|
|
|
canvas_draw_str(canvas, 0, 24, "Carrier TX Hopping mode");
|
|
|
|
} else if(m->type == BtStateCarrierRxRunning) {
|
|
|
|
canvas_draw_str(canvas, 0, 24, "Manual Carrier RX");
|
2021-03-11 09:31:07 +00:00
|
|
|
}
|
|
|
|
char buffer[32];
|
|
|
|
snprintf(buffer, sizeof(buffer), "Channel:%d MHz", m->channel * 2 + 2402);
|
|
|
|
canvas_draw_str(canvas, 0, 36, buffer);
|
2021-06-02 14:09:02 +00:00
|
|
|
if(m->type == BtStateCarrierTx || m->type == BtStateHoppingTx) {
|
|
|
|
snprintf(buffer, sizeof(buffer), "Power:%d dB", m->power - BtPower0dB);
|
|
|
|
} else if(m->type == BtStateCarrierRxRunning) {
|
|
|
|
snprintf(buffer, sizeof(buffer), "RSSI: %3.1f dB", m->rssi);
|
|
|
|
}
|
2021-03-11 09:31:07 +00:00
|
|
|
canvas_draw_str(canvas, 0, 48, buffer);
|
|
|
|
}
|
|
|
|
|
2021-06-02 14:09:02 +00:00
|
|
|
void bt_view_test_packet_rx_draw(Canvas* canvas, void* model) {
|
|
|
|
BtViewTestPacketRxModel* m = model;
|
2021-03-11 09:31:07 +00:00
|
|
|
canvas_clear(canvas);
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
2021-06-02 14:09:02 +00:00
|
|
|
canvas_draw_str(canvas, 0, 12, "Performing packets RX test");
|
|
|
|
if(m->type == BtStatePacketSetup) {
|
|
|
|
canvas_draw_str(canvas, 0, 24, "Setup parameters. Ok to start");
|
|
|
|
} else {
|
|
|
|
canvas_draw_str(canvas, 0, 24, "Receiving packets ...");
|
|
|
|
}
|
2021-03-11 09:31:07 +00:00
|
|
|
char buffer[32];
|
|
|
|
snprintf(buffer, sizeof(buffer), "Channel:%d MHz", m->channel * 2 + 2402);
|
2021-06-02 14:09:02 +00:00
|
|
|
canvas_draw_str(canvas, 0, 36, buffer);
|
|
|
|
snprintf(buffer, sizeof(buffer), "Datarate:%d Mbps", m->datarate);
|
|
|
|
canvas_draw_str(canvas, 0, 48, buffer);
|
|
|
|
if(m->type == BtStatePacketSetup) {
|
|
|
|
snprintf(buffer, sizeof(buffer), "%d packets received", m->packets_received);
|
|
|
|
} else {
|
|
|
|
snprintf(buffer, sizeof(buffer), "RSSI: %3.1f dB", m->rssi);
|
|
|
|
}
|
|
|
|
canvas_draw_str(canvas, 0, 60, buffer);
|
2021-03-11 09:31:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void bt_view_test_packet_tx_draw(Canvas* canvas, void* model) {
|
|
|
|
BtViewTestPacketTxModel* m = model;
|
|
|
|
canvas_clear(canvas);
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
|
canvas_draw_str(canvas, 0, 12, "Packets send TX test");
|
2021-06-02 14:09:02 +00:00
|
|
|
if(m->type == BtStatePacketSetup) {
|
|
|
|
canvas_draw_str(canvas, 0, 24, "Setup parameters. Ok to start");
|
2021-03-11 09:31:07 +00:00
|
|
|
} else {
|
2021-06-02 14:09:02 +00:00
|
|
|
canvas_draw_str(canvas, 0, 24, "Sending packets ...");
|
2021-03-11 09:31:07 +00:00
|
|
|
}
|
|
|
|
char buffer[32];
|
|
|
|
snprintf(buffer, sizeof(buffer), "Channel:%d MHz", m->channel * 2 + 2402);
|
2021-06-02 14:09:02 +00:00
|
|
|
canvas_draw_str(canvas, 0, 36, buffer);
|
|
|
|
snprintf(buffer, sizeof(buffer), "Datarate:%d Mbps", m->datarate);
|
2021-03-11 09:31:07 +00:00
|
|
|
canvas_draw_str(canvas, 0, 48, buffer);
|
2021-06-02 14:09:02 +00:00
|
|
|
if(m->packets_sent && m->type == BtStatePacketSetup) {
|
|
|
|
snprintf(buffer, sizeof(buffer), "%d packets sent", m->packets_sent);
|
|
|
|
canvas_draw_str(canvas, 0, 60, buffer);
|
|
|
|
}
|
2021-03-11 09:31:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void bt_view_app_draw(Canvas* canvas, void* model) {
|
|
|
|
canvas_clear(canvas);
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
|
canvas_draw_str(canvas, 0, 12, "Start BLE app");
|
|
|
|
}
|
|
|
|
|
|
|
|
BtTestChannel bt_switch_channel(InputKey key, BtTestChannel inst_chan) {
|
|
|
|
uint8_t pos = 0;
|
|
|
|
BtTestChannel arr[] = {BtChannel2402, BtChannel2440, BtChannel2480};
|
|
|
|
for(pos = 0; pos < sizeof(arr); pos++) {
|
|
|
|
if(arr[pos] == inst_chan) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(key == InputKeyRight) {
|
|
|
|
pos = (pos + 1) % sizeof(arr);
|
|
|
|
return arr[pos];
|
|
|
|
} else if(key == InputKeyLeft) {
|
|
|
|
if(pos) {
|
|
|
|
return arr[pos - 1];
|
|
|
|
} else {
|
|
|
|
return arr[sizeof(arr) - 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return arr[0];
|
|
|
|
}
|
|
|
|
|
2021-06-02 14:09:02 +00:00
|
|
|
bool bt_view_test_carrier_input(InputEvent* event, void* context) {
|
2021-03-11 09:31:07 +00:00
|
|
|
furi_assert(event);
|
|
|
|
furi_assert(context);
|
|
|
|
Bt* bt = context;
|
|
|
|
if(event->type == InputTypeShort) {
|
|
|
|
if(event->key == InputKeyBack) {
|
2021-06-02 14:09:02 +00:00
|
|
|
if(osTimerIsRunning(bt->update_param_timer)) {
|
|
|
|
osTimerStop(bt->update_param_timer);
|
2021-03-11 09:31:07 +00:00
|
|
|
}
|
2021-06-02 14:09:02 +00:00
|
|
|
BtMessage m = {.type = BtMessageTypeStopTestCarrier};
|
2021-03-11 09:31:07 +00:00
|
|
|
furi_check(osMessageQueuePut(bt->message_queue, &m, 0, osWaitForever) == osOK);
|
|
|
|
view_dispatcher_switch_to_view(bt->view_dispatcher, VIEW_NONE);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if(event->key == InputKeyRight || event->key == InputKeyLeft) {
|
|
|
|
bt->state.param.channel = bt_switch_channel(event->key, bt->state.param.channel);
|
|
|
|
} else if(event->key == InputKeyUp) {
|
|
|
|
if(bt->state.param.power < BtPower6dB) {
|
|
|
|
bt->state.param.power += 2;
|
|
|
|
}
|
|
|
|
} else if(event->key == InputKeyDown) {
|
|
|
|
if(bt->state.param.power > BtPower0dB) {
|
|
|
|
bt->state.param.power -= 2;
|
|
|
|
}
|
|
|
|
} else if(event->key == InputKeyOk) {
|
2021-06-02 14:09:02 +00:00
|
|
|
if(bt->state.type == BtStateCarrierTx) {
|
|
|
|
bt->state.type = BtStateHoppingTx;
|
|
|
|
osTimerStart(bt->update_param_timer, 2000);
|
|
|
|
} else if(bt->state.type == BtStateHoppingTx) {
|
|
|
|
osTimerStop(bt->update_param_timer);
|
|
|
|
bt->state.type = BtStateCarrierRxStart;
|
|
|
|
osTimerStart(bt->update_param_timer, 200);
|
2021-03-11 09:31:07 +00:00
|
|
|
} else {
|
2021-06-02 14:09:02 +00:00
|
|
|
osTimerStop(bt->update_param_timer);
|
|
|
|
bt->state.type = BtStateCarrierTx;
|
2021-03-11 09:31:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
BtMessage m = {
|
2021-06-02 14:09:02 +00:00
|
|
|
.type = BtMessageTypeStartTestCarrier,
|
2021-03-11 09:31:07 +00:00
|
|
|
.param.channel = bt->state.param.channel,
|
|
|
|
.param.power = bt->state.param.power};
|
|
|
|
furi_check(osMessageQueuePut(bt->message_queue, &m, 0, osWaitForever) == osOK);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-02 14:09:02 +00:00
|
|
|
bool bt_view_test_packet_tx_input(InputEvent* event, void* context) {
|
2021-03-11 09:31:07 +00:00
|
|
|
furi_assert(event);
|
|
|
|
furi_assert(context);
|
|
|
|
Bt* bt = context;
|
|
|
|
if(event->type == InputTypeShort) {
|
2021-06-02 14:09:02 +00:00
|
|
|
if(event->key < InputKeyOk) {
|
|
|
|
// Process InputKeyUp, InputKeyDown, InputKeyLeft, InputKeyRight
|
|
|
|
if(event->key == InputKeyRight || event->key == InputKeyLeft) {
|
|
|
|
bt->state.param.channel = bt_switch_channel(event->key, bt->state.param.channel);
|
|
|
|
} else if(event->key == InputKeyUp) {
|
|
|
|
if(bt->state.param.datarate < BtDataRate2M) {
|
|
|
|
bt->state.param.datarate += 1;
|
|
|
|
}
|
|
|
|
} else if(event->key == InputKeyDown) {
|
|
|
|
if(bt->state.param.datarate > BtDataRate1M) {
|
|
|
|
bt->state.param.datarate -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bt->state.type = BtStatePacketSetup;
|
2021-03-11 09:31:07 +00:00
|
|
|
BtMessage m = {
|
2021-06-02 14:09:02 +00:00
|
|
|
.type = BtMessageTypeSetupTestPacketTx,
|
|
|
|
.param.channel = bt->state.param.channel,
|
|
|
|
.param.datarate = bt->state.param.datarate,
|
|
|
|
};
|
|
|
|
furi_check(osMessageQueuePut(bt->message_queue, &m, 0, osWaitForever) == osOK);
|
|
|
|
return true;
|
|
|
|
} else if(event->key == InputKeyOk) {
|
|
|
|
if(bt->state.type == BtStatePacketSetup) {
|
|
|
|
bt->state.type = BtStatePacketStart;
|
|
|
|
} else if(bt->state.type == BtStatePacketStart) {
|
|
|
|
bt->state.type = BtStatePacketSetup;
|
|
|
|
}
|
|
|
|
BtMessage m = {
|
|
|
|
.type = BtMessageTypeStartTestPacketTx,
|
|
|
|
.param.channel = bt->state.param.channel,
|
|
|
|
.param.datarate = bt->state.param.datarate,
|
|
|
|
};
|
2021-03-11 09:31:07 +00:00
|
|
|
furi_check(osMessageQueuePut(bt->message_queue, &m, 0, osWaitForever) == osOK);
|
|
|
|
return true;
|
|
|
|
} else if(event->key == InputKeyBack) {
|
2021-06-02 14:09:02 +00:00
|
|
|
BtMessage m = {
|
|
|
|
.type = BtMessageTypeStopTestPacket,
|
|
|
|
};
|
2021-03-11 09:31:07 +00:00
|
|
|
furi_check(osMessageQueuePut(bt->message_queue, &m, 0, osWaitForever) == osOK);
|
|
|
|
view_dispatcher_switch_to_view(bt->view_dispatcher, VIEW_NONE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-02 14:09:02 +00:00
|
|
|
bool bt_view_test_packet_rx_input(InputEvent* event, void* context) {
|
2021-03-11 09:31:07 +00:00
|
|
|
furi_assert(event);
|
|
|
|
furi_assert(context);
|
|
|
|
Bt* bt = context;
|
|
|
|
if(event->type == InputTypeShort) {
|
|
|
|
if(event->key < InputKeyOk) {
|
|
|
|
// Process InputKeyUp, InputKeyDown, InputKeyLeft, InputKeyRight
|
|
|
|
if(event->key == InputKeyRight || event->key == InputKeyLeft) {
|
|
|
|
bt->state.param.channel = bt_switch_channel(event->key, bt->state.param.channel);
|
|
|
|
} else if(event->key == InputKeyUp) {
|
2021-06-02 14:09:02 +00:00
|
|
|
if(bt->state.param.datarate < BtDataRate2M) {
|
2021-03-11 09:31:07 +00:00
|
|
|
bt->state.param.datarate += 1;
|
|
|
|
}
|
|
|
|
} else if(event->key == InputKeyDown) {
|
2021-06-02 14:09:02 +00:00
|
|
|
if(bt->state.param.datarate > BtDataRate1M) {
|
2021-03-11 09:31:07 +00:00
|
|
|
bt->state.param.datarate -= 1;
|
|
|
|
}
|
|
|
|
}
|
2021-06-02 14:09:02 +00:00
|
|
|
bt->state.type = BtStatePacketSetup;
|
2021-03-11 09:31:07 +00:00
|
|
|
BtMessage m = {
|
2021-06-02 14:09:02 +00:00
|
|
|
.type = BtMessageTypeSetupTestPacketRx,
|
2021-03-11 09:31:07 +00:00
|
|
|
.param.channel = bt->state.param.channel,
|
|
|
|
.param.datarate = bt->state.param.datarate,
|
|
|
|
};
|
|
|
|
furi_check(osMessageQueuePut(bt->message_queue, &m, 0, osWaitForever) == osOK);
|
|
|
|
return true;
|
|
|
|
} else if(event->key == InputKeyOk) {
|
2021-06-02 14:09:02 +00:00
|
|
|
if(bt->state.type == BtStatePacketSetup) {
|
|
|
|
bt->state.type = BtStatePacketStart;
|
|
|
|
osTimerStart(bt->update_param_timer, 200);
|
|
|
|
} else if(bt->state.type == BtStatePacketRunning) {
|
|
|
|
bt->state.type = BtStatePacketSetup;
|
|
|
|
osTimerStop(bt->update_param_timer);
|
|
|
|
}
|
2021-03-11 09:31:07 +00:00
|
|
|
BtMessage m = {
|
2021-06-02 14:09:02 +00:00
|
|
|
.type = BtMessageTypeStartTestPacketRx,
|
2021-03-11 09:31:07 +00:00
|
|
|
.param.channel = bt->state.param.channel,
|
|
|
|
.param.datarate = bt->state.param.datarate,
|
|
|
|
};
|
|
|
|
furi_check(osMessageQueuePut(bt->message_queue, &m, 0, osWaitForever) == osOK);
|
|
|
|
return true;
|
|
|
|
} else if(event->key == InputKeyBack) {
|
2021-06-02 14:09:02 +00:00
|
|
|
if(osTimerIsRunning(bt->update_param_timer)) {
|
|
|
|
osTimerStop(bt->update_param_timer);
|
|
|
|
}
|
2021-03-11 09:31:07 +00:00
|
|
|
BtMessage m = {
|
2021-06-02 14:09:02 +00:00
|
|
|
.type = BtMessageTypeStopTestPacket,
|
2021-03-11 09:31:07 +00:00
|
|
|
};
|
|
|
|
furi_check(osMessageQueuePut(bt->message_queue, &m, 0, osWaitForever) == osOK);
|
|
|
|
view_dispatcher_switch_to_view(bt->view_dispatcher, VIEW_NONE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|