From aace40d55d3d769986636e97a1dcffe3a36c63f3 Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 10 Mar 2020 17:25:29 +0100 Subject: [PATCH] 2.4 BT hardware config (#7434) Bluetooth added to Radio / Hardware Config --- radio/src/gui/colorlcd/radio_hardware.cpp | 71 +++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/radio/src/gui/colorlcd/radio_hardware.cpp b/radio/src/gui/colorlcd/radio_hardware.cpp index 33b68c992..36558e19e 100644 --- a/radio/src/gui/colorlcd/radio_hardware.cpp +++ b/radio/src/gui/colorlcd/radio_hardware.cpp @@ -81,6 +81,68 @@ RadioHardwarePage::RadioHardwarePage(): { } +#if defined(BLUETOOTH) +class BluetoothConfigWindow : public FormGroup +{ + public: + BluetoothConfigWindow(FormWindow * parent, const rect_t &rect) : + FormGroup(parent, rect, FORWARD_SCROLL | FORM_FORWARD_FOCUS) + { + update(); + } + + void update() + { + FormGridLayout grid; +#if LCD_W > LCD_H + grid.setLabelWidth(180); +#else + grid.setLabelWidth(130); +#endif + clear(); + + new StaticText(this, grid.getLabelSlot(true), STR_MODE); + btMode = new Choice(this, grid.getFieldSlot(), STR_BLUETOOTH_MODES, BLUETOOTH_OFF, BLUETOOTH_TRAINER, GET_DEFAULT(g_eeGeneral.bluetoothMode), [=](int32_t newValue) { + g_eeGeneral.bluetoothMode = newValue; + update(); + SET_DIRTY(); + btMode->setFocus(); + }); + grid.nextLine(); + + if (g_eeGeneral.bluetoothMode != BLUETOOTH_OFF) { + // Pin code (displayed for information only, not editable) + if (g_eeGeneral.bluetoothMode == BLUETOOTH_TELEMETRY) { + new StaticText(this, grid.getLabelSlot(true), STR_BLUETOOTH_PIN_CODE); + new StaticText(this, grid.getFieldSlot(), "000000"); + grid.nextLine(); + } + + // Local MAC + new StaticText(this, grid.getLabelSlot(true), STR_BLUETOOTH_LOCAL_ADDR); + new StaticText(this, grid.getFieldSlot(), bluetooth.localAddr[0] == '\0' ? "---" : bluetooth.localAddr); + grid.nextLine(); + + // Remote MAC + new StaticText(this, grid.getLabelSlot(true), STR_BLUETOOTH_DIST_ADDR); + new StaticText(this, grid.getFieldSlot(), bluetooth.distantAddr[0] == '\0' ? "---" : bluetooth.distantAddr); + grid.nextLine(); + + // BT radio name + new StaticText(this, grid.getLabelSlot(true), STR_NAME); + new TextEdit(this, grid.getFieldSlot(), g_eeGeneral.bluetoothName, LEN_BLUETOOTH_NAME); + grid.nextLine(); + } + + getParent()->moveWindowsTop(top(), adjustHeight()); + getParent()->invalidate(); // TODO should be automatically done + } + + protected: + Choice * btMode = nullptr; +}; +#endif + void RadioHardwarePage::build(FormWindow * window) { FormGridLayout grid; @@ -173,6 +235,15 @@ void RadioHardwarePage::build(FormWindow * window) grid.nextLine(); #endif +#if defined(BLUETOOTH) + // Bluetooth mode + { + new Subtitle(window, grid.getLineSlot(), STR_BLUETOOTH); + grid.nextLine(); + grid.addWindow(new BluetoothConfigWindow(window, {0, grid.getWindowHeight(), LCD_W, 0})); + } +#endif + // ADC filter new StaticText(window, grid.getLabelSlot(), STR_JITTER_FILTER); new CheckBox(window, grid.getFieldSlot(), GET_SET_INVERTED(g_eeGeneral.jitterFilter));