Extra BT Info + M/BT Working
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
|
||||
#include "trainer_bluetooth.h"
|
||||
#include "opentx.h"
|
||||
#include "bluetooth.h"
|
||||
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||
|
||||
@@ -47,8 +47,6 @@ BTDiscoverMenu::BTDiscoverMenu() :
|
||||
setTitle(STR_BT_SELECT_DEVICE);
|
||||
// TODO: set minimum height
|
||||
|
||||
reusableBuffer.moduleSetup.bt.devicesCount = 0;
|
||||
bluetooth.state = BLUETOOTH_STATE_DISCOVER_REQUESTED;
|
||||
}
|
||||
|
||||
void BTDiscoverMenu::checkEvents()
|
||||
@@ -83,15 +81,19 @@ BluetoothTrainerWindow::BluetoothTrainerWindow(Window* parent) :
|
||||
FlexGridLayout grid(col_dsc, row_dsc, 2);
|
||||
|
||||
auto line = newLine(&grid);
|
||||
state = new StaticText(line, rect_t{}, "", 0, COLOR_THEME_PRIMARY1);
|
||||
state = new StaticText(line, rect_t{}, "", 0, COLOR_THEME_PRIMARY1);
|
||||
r_addr = new StaticText(line, rect_t{}, "", 0, COLOR_THEME_PRIMARY1);
|
||||
|
||||
auto lclline = newLine(&grid);
|
||||
new StaticText(lclline, rect_t{}, STR_BLUETOOTH_LOCAL_ADDR, 0, COLOR_THEME_PRIMARY1);
|
||||
new StaticText(lclline, rect_t{}, bluetooth.localAddr, 0, COLOR_THEME_PRIMARY1);
|
||||
|
||||
btn_line = newLine(&grid);
|
||||
grid.nextCell();
|
||||
|
||||
btn = new TextButton(btn_line, rect_t{}, "");
|
||||
btn->setWidth(LV_DPI_DEF / 2);
|
||||
btn->padAll(lv_dpx(4));
|
||||
/*btn->setWidth(LV_DPI_DEF);
|
||||
btn->padAll(lv_dpx(10));*/
|
||||
}
|
||||
|
||||
void BluetoothTrainerWindow::setMaster(bool master)
|
||||
@@ -107,10 +109,39 @@ void BluetoothTrainerWindow::setMaster(bool master)
|
||||
|
||||
static const char _empty_addr[] = "---";
|
||||
|
||||
void BluetoothTrainerWindow::checkEvents()
|
||||
{
|
||||
if(bluetooth.state != lastbtstate ||
|
||||
reusableBuffer.moduleSetup.bt.devicesCount != devcount)
|
||||
refresh();
|
||||
lastbtstate = bluetooth.state;
|
||||
devcount = reusableBuffer.moduleSetup.bt.devicesCount;
|
||||
}
|
||||
|
||||
void BluetoothTrainerWindow::refresh()
|
||||
{
|
||||
if (is_master) {
|
||||
if (bluetooth.distantAddr[0]) {
|
||||
if (bluetooth.state == BLUETOOTH_STATE_DISCOVER_SENT) {
|
||||
btn->setText(STR_BLUETOOTH_SCANNING);
|
||||
btn->setPressHandler([=]() {
|
||||
startScan(); // Allow restart scan if stuck here
|
||||
return 0;});
|
||||
} else if (bluetooth.state == BLUETOOTH_STATE_DISCOVER_START) {
|
||||
if(reusableBuffer.moduleSetup.bt.devicesCount && !menuopened) { // On first item found, open menu
|
||||
auto btdm = new BTDiscoverMenu();
|
||||
btdm->setCloseHandler([=]() {
|
||||
menuopened = false;
|
||||
if(bluetooth.state != BLUETOOTH_STATE_BIND_REQUESTED)
|
||||
bluetooth.state = BLUETOOTH_STATE_IDLE;
|
||||
});
|
||||
menuopened = true;
|
||||
}
|
||||
} else if (bluetooth.state == BLUETOOTH_STATE_DISCOVER_END) {
|
||||
if(reusableBuffer.moduleSetup.bt.devicesCount == 0) {
|
||||
new MessageDialog(this, STR_BLUETOOTH, STR_BLUETOOTH_NODEVICES);
|
||||
bluetooth.state = BLUETOOTH_STATE_OFF;
|
||||
}
|
||||
} else if (bluetooth.distantAddr[0]) {
|
||||
r_addr->setText(bluetooth.distantAddr);
|
||||
btn->setText(STR_CLEAR);
|
||||
btn->setPressHandler([]() {
|
||||
@@ -129,7 +160,7 @@ void BluetoothTrainerWindow::refresh()
|
||||
r_addr->setText(_empty_addr);
|
||||
btn->setText(STR_DISCOVER);
|
||||
btn->setPressHandler([=]() {
|
||||
new BTDiscoverMenu();
|
||||
startScan();
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
@@ -138,8 +169,17 @@ void BluetoothTrainerWindow::refresh()
|
||||
if (bluetooth.state == BLUETOOTH_STATE_CONNECTED) {
|
||||
state->setText(STR_CONNECTED);
|
||||
if (!is_master) r_addr->setText(bluetooth.distantAddr);
|
||||
} else {
|
||||
} else if (bluetooth.state != BLUETOOTH_STATE_DISCOVER_REQUESTED ||
|
||||
bluetooth.state != BLUETOOTH_STATE_DISCOVER_SENT ||
|
||||
!is_master) {
|
||||
state->setText(STR_NOT_CONNECTED);
|
||||
if (!is_master) r_addr->setText(_empty_addr);
|
||||
}
|
||||
}
|
||||
|
||||
void BluetoothTrainerWindow::startScan()
|
||||
{
|
||||
reusableBuffer.moduleSetup.bt.devicesCount = 0;
|
||||
devcount = 0;
|
||||
bluetooth.state = BLUETOOTH_STATE_DISCOVER_REQUESTED;
|
||||
}
|
||||
|
||||
@@ -24,19 +24,26 @@
|
||||
#include "form.h"
|
||||
#include "static.h"
|
||||
#include "button.h"
|
||||
#include "bluetooth.h"
|
||||
|
||||
class BluetoothTrainerWindow : public FormGroup
|
||||
{
|
||||
bool is_master = true;
|
||||
bool menuopened = false;
|
||||
uint8_t lastbtstate=BLUETOOTH_STATE_OFF;
|
||||
uint8_t devcount=0;
|
||||
StaticText* state;
|
||||
StaticText* r_addr;
|
||||
StaticText* l_addr;
|
||||
|
||||
Window* btn_line;
|
||||
TextButton* btn;
|
||||
|
||||
void startScan();
|
||||
|
||||
public:
|
||||
BluetoothTrainerWindow(Window* parent);
|
||||
|
||||
void setMaster(bool master);
|
||||
void checkEvents() override;
|
||||
void refresh();
|
||||
};
|
||||
|
||||
@@ -963,6 +963,8 @@ const char STR_BLUETOOTH_INIT[] = TR_BLUETOOTH_INIT;
|
||||
const char STR_BLUETOOTH_DIST_ADDR[] = TR_BLUETOOTH_DIST_ADDR;
|
||||
const char STR_BLUETOOTH_LOCAL_ADDR[] = TR_BLUETOOTH_LOCAL_ADDR;
|
||||
const char STR_BLUETOOTH_PIN_CODE[] = TR_BLUETOOTH_PIN_CODE;
|
||||
const char STR_BLUETOOTH_NODEVICES[] = TR_BLUETOOTH_NODEVICES;
|
||||
const char STR_BLUETOOTH_SCANNING[] = TR_BLUETOOTH_SCANNING;
|
||||
#endif
|
||||
|
||||
const char STR_ABOUTUS[] = TR_ABOUTUS;
|
||||
|
||||
@@ -205,6 +205,8 @@ extern const char STR_BLUETOOTH_INIT[];
|
||||
extern const char STR_BLUETOOTH_DIST_ADDR[];
|
||||
extern const char STR_BLUETOOTH_LOCAL_ADDR[];
|
||||
extern const char STR_BLUETOOTH_PIN_CODE[];
|
||||
extern const char STR_BLUETOOTH_NODEVICES[];
|
||||
extern const char STR_BLUETOOTH_SCANNING[];
|
||||
extern const char* STR_BLUETOOTH_MODES[];
|
||||
|
||||
#define NO_INDENT(x) (x) + LEN_INDENT
|
||||
|
||||
@@ -665,6 +665,8 @@
|
||||
#define TR_BLUETOOTH_DIST_ADDR "目标地址"
|
||||
#define TR_BLUETOOTH_LOCAL_ADDR "本机地址"
|
||||
#define TR_BLUETOOTH_PIN_CODE "PIN码"
|
||||
#define TR_BLUETOOTH_NODEVICES "No Devices Found"
|
||||
#define TR_BLUETOOTH_SCANNING "Scanning..."
|
||||
#define TR_BLUETOOTH_BAUDRATE "蓝牙带宽"
|
||||
#define TR_BLUETOOTH_MODES "---","回传","教练"
|
||||
#define TR_SELECT_TEMPLATE_FOLDER "选择一个模板文件夹:"
|
||||
|
||||
@@ -740,6 +740,8 @@
|
||||
#define TR_BLUETOOTH_DIST_ADDR "Vzdál. addr"
|
||||
#define TR_BLUETOOTH_LOCAL_ADDR "Lokál. addr"
|
||||
#define TR_BLUETOOTH_PIN_CODE TR("PIN kód", "PIN kód")
|
||||
#define TR_BLUETOOTH_NODEVICES "No Devices Found"
|
||||
#define TR_BLUETOOTH_SCANNING "Scanning..."
|
||||
#define TR_BLUETOOTH_BAUDRATE "Baudrate BT"
|
||||
#if defined(PCBX9E)
|
||||
#define TR_BLUETOOTH_MODES "---","Povoleno"
|
||||
|
||||
@@ -723,6 +723,8 @@
|
||||
#define TR_BLUETOOTH_DIST_ADDR "Dist addr"
|
||||
#define TR_BLUETOOTH_LOCAL_ADDR "Local addr"
|
||||
#define TR_BLUETOOTH_PIN_CODE "PIN Code"
|
||||
#define TR_BLUETOOTH_NODEVICES "No Devices Found"
|
||||
#define TR_BLUETOOTH_SCANNING "Scanning..."
|
||||
#define TR_BLUETOOTH_BAUDRATE "BT Baudrate"
|
||||
#if defined(PCBX9E)
|
||||
#define TR_BLUETOOTH_MODES "---","Aktiviert"
|
||||
|
||||
@@ -724,6 +724,8 @@
|
||||
#define TR_BLUETOOTH_DIST_ADDR "Dist addr"
|
||||
#define TR_BLUETOOTH_LOCAL_ADDR "Local addr"
|
||||
#define TR_BLUETOOTH_PIN_CODE "PIN code"
|
||||
#define TR_BLUETOOTH_NODEVICES "No Devices Found"
|
||||
#define TR_BLUETOOTH_SCANNING "Scanning..."
|
||||
#define TR_BLUETOOTH_BAUDRATE "BT Baudrate"
|
||||
#if defined(PCBX9E)
|
||||
#define TR_BLUETOOTH_MODES "---","Enabled"
|
||||
|
||||
@@ -724,6 +724,8 @@
|
||||
#define TR_BLUETOOTH_DIST_ADDR "Dir. remota"
|
||||
#define TR_BLUETOOTH_LOCAL_ADDR "Dir. local"
|
||||
#define TR_BLUETOOTH_PIN_CODE "Código PIN"
|
||||
#define TR_BLUETOOTH_NODEVICES "No Devices Found"
|
||||
#define TR_BLUETOOTH_SCANNING "Scanning..."
|
||||
#define TR_BLUETOOTH_BAUDRATE "Velocidad BT"
|
||||
#if defined(PCBX9E)
|
||||
#define TR_BLUETOOTH_MODES "---","Activo"
|
||||
|
||||
@@ -725,6 +725,8 @@
|
||||
#define TR_BLUETOOTH_DIST_ADDR "Dist addr"
|
||||
#define TR_BLUETOOTH_LOCAL_ADDR "Local addr"
|
||||
#define TR_BLUETOOTH_PIN_CODE "Pin-koodi"
|
||||
#define TR_BLUETOOTH_NODEVICES "No Devices Found"
|
||||
#define TR_BLUETOOTH_SCANNING "Scanning..."
|
||||
#define TR_BAUDRATE "BT Baudrate"
|
||||
#if defined(PCBX9E)
|
||||
#define TR_BLUETOOTH_MODES "---","Enabled"
|
||||
|
||||
@@ -743,6 +743,8 @@
|
||||
#define TR_BLUETOOTH_DIST_ADDR "Addr dist."
|
||||
#define TR_BLUETOOTH_LOCAL_ADDR "Addr locale"
|
||||
#define TR_BLUETOOTH_PIN_CODE "Code PIN"
|
||||
#define TR_BLUETOOTH_NODEVICES "No Devices Found"
|
||||
#define TR_BLUETOOTH_SCANNING "Scanning..."
|
||||
#define TR_BAUDRATE "Baudrate BT"
|
||||
#if defined(PCBX9E)
|
||||
#define TR_BLUETOOTH_MODES "---","Activé"
|
||||
|
||||
@@ -723,6 +723,8 @@
|
||||
#define TR_BLUETOOTH_DIST_ADDR "Ind. Dist."
|
||||
#define TR_BLUETOOTH_LOCAL_ADDR "Ind. Loc."
|
||||
#define TR_BLUETOOTH_PIN_CODE "Codice PIN"
|
||||
#define TR_BLUETOOTH_NODEVICES "No Devices Found"
|
||||
#define TR_BLUETOOTH_SCANNING "Scanning..."
|
||||
#define TR_BLUETOOTH_BAUDRATE "Baudrate BT"
|
||||
#if defined(PCBX9E)
|
||||
#define TR_BLUETOOTH_MODES "---","Attivo"
|
||||
|
||||
@@ -729,6 +729,8 @@
|
||||
#define TR_BLUETOOTH_DIST_ADDR "Dist addr"
|
||||
#define TR_BLUETOOTH_LOCAL_ADDR "Local addr"
|
||||
#define TR_BLUETOOTH_PIN_CODE "PIN code"
|
||||
#define TR_BLUETOOTH_NODEVICES "No Devices Found"
|
||||
#define TR_BLUETOOTH_SCANNING "Scanning..."
|
||||
#define TR_BLUETOOTH_BAUDRATE "BT Baudrate"
|
||||
#define LEN_BLUETOOTH_MODES "\011"
|
||||
#if defined(PCBX9E)
|
||||
|
||||
@@ -719,6 +719,8 @@
|
||||
#define TR_BLUETOOTH_DIST_ADDR "Dist addr"
|
||||
#define TR_BLUETOOTH_LOCAL_ADDR "Local addr"
|
||||
#define TR_BLUETOOTH_PIN_CODE "PIN code"
|
||||
#define TR_BLUETOOTH_NODEVICES "No Devices Found"
|
||||
#define TR_BLUETOOTH_SCANNING "Scanning..."
|
||||
#define TR_BLUETOOTH_BAUDRATE "Prędkość BT"
|
||||
#if defined(PCBX9E)
|
||||
#define TR_BLUETOOTH_MODES "---","Enabled"
|
||||
|
||||
@@ -724,6 +724,8 @@
|
||||
#define TR_BLUETOOTH_DIST_ADDR "Dist addr"
|
||||
#define TR_BLUETOOTH_LOCAL_ADDR "Local addr"
|
||||
#define TR_BLUETOOTH_PIN_CODE "PIN code"
|
||||
#define TR_BLUETOOTH_NODEVICES "No Devices Found"
|
||||
#define TR_BLUETOOTH_SCANNING "Scanning..."
|
||||
#define TR_BLUETOOTH_BAUDRATE "BT Baudrate"
|
||||
#if defined(PCBX9E)
|
||||
#define TR_BLUETOOTH_MODES "---","Enabled"
|
||||
|
||||
@@ -741,6 +741,8 @@
|
||||
#define TR_BLUETOOTH_DIST_ADDR "Dist addr"
|
||||
#define TR_BLUETOOTH_LOCAL_ADDR "Lokal addr"
|
||||
#define TR_BLUETOOTH_PIN_CODE "PIN-kod"
|
||||
#define TR_BLUETOOTH_NODEVICES "No Devices Found"
|
||||
#define TR_BLUETOOTH_SCANNING "Scanning..."
|
||||
#define TR_BAUDRATE "BT baudrate"
|
||||
#if defined(PCBX9E)
|
||||
#define TR_BLUETOOTH_MODES "---","Enabled"
|
||||
|
||||
Reference in New Issue
Block a user