diff --git a/radio/src/gui/colorlcd/trainer_bluetooth.cpp b/radio/src/gui/colorlcd/trainer_bluetooth.cpp index d3ea146c5..e61173646 100644 --- a/radio/src/gui/colorlcd/trainer_bluetooth.cpp +++ b/radio/src/gui/colorlcd/trainer_bluetooth.cpp @@ -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; +} diff --git a/radio/src/gui/colorlcd/trainer_bluetooth.h b/radio/src/gui/colorlcd/trainer_bluetooth.h index 9aa5d785e..6e39e0d20 100644 --- a/radio/src/gui/colorlcd/trainer_bluetooth.h +++ b/radio/src/gui/colorlcd/trainer_bluetooth.h @@ -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(); }; diff --git a/radio/src/translations.cpp b/radio/src/translations.cpp index cd9c3ea2c..ff406244a 100644 --- a/radio/src/translations.cpp +++ b/radio/src/translations.cpp @@ -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; diff --git a/radio/src/translations.h b/radio/src/translations.h index 932a11ef9..cfb982689 100644 --- a/radio/src/translations.h +++ b/radio/src/translations.h @@ -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 diff --git a/radio/src/translations/cn.h b/radio/src/translations/cn.h index 015a4c84b..ebc5d06b4 100644 --- a/radio/src/translations/cn.h +++ b/radio/src/translations/cn.h @@ -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 "选择一个模板文件夹:" diff --git a/radio/src/translations/cz.h b/radio/src/translations/cz.h index 0f3d6ff8f..dc3ea81eb 100644 --- a/radio/src/translations/cz.h +++ b/radio/src/translations/cz.h @@ -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" diff --git a/radio/src/translations/de.h b/radio/src/translations/de.h index b24787478..0ac49fc71 100644 --- a/radio/src/translations/de.h +++ b/radio/src/translations/de.h @@ -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" diff --git a/radio/src/translations/en.h b/radio/src/translations/en.h index 24ab2c3b3..a2ee68413 100644 --- a/radio/src/translations/en.h +++ b/radio/src/translations/en.h @@ -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" diff --git a/radio/src/translations/es.h b/radio/src/translations/es.h index 5342d23b3..86ece725f 100644 --- a/radio/src/translations/es.h +++ b/radio/src/translations/es.h @@ -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" diff --git a/radio/src/translations/fi.h b/radio/src/translations/fi.h index 4fc94ed04..28b31e87b 100644 --- a/radio/src/translations/fi.h +++ b/radio/src/translations/fi.h @@ -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" diff --git a/radio/src/translations/fr.h b/radio/src/translations/fr.h index 74d3d29a2..2f5290d1d 100644 --- a/radio/src/translations/fr.h +++ b/radio/src/translations/fr.h @@ -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é" diff --git a/radio/src/translations/it.h b/radio/src/translations/it.h index 9d0d3706a..9deeae29f 100644 --- a/radio/src/translations/it.h +++ b/radio/src/translations/it.h @@ -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" diff --git a/radio/src/translations/nl.h b/radio/src/translations/nl.h index 1a174deeb..8c6d51a1a 100644 --- a/radio/src/translations/nl.h +++ b/radio/src/translations/nl.h @@ -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) diff --git a/radio/src/translations/pl.h b/radio/src/translations/pl.h index baeb1ec0a..64862ebcf 100644 --- a/radio/src/translations/pl.h +++ b/radio/src/translations/pl.h @@ -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" diff --git a/radio/src/translations/pt.h b/radio/src/translations/pt.h index 6581acd82..d3de990d2 100644 --- a/radio/src/translations/pt.h +++ b/radio/src/translations/pt.h @@ -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" diff --git a/radio/src/translations/se.h b/radio/src/translations/se.h index c149def60..d33b35e9f 100644 --- a/radio/src/translations/se.h +++ b/radio/src/translations/se.h @@ -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"