diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index 2471d1f10..5d848a7f6 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -1095,6 +1095,10 @@ GeneralSettings::GeneralSettings() speakerVolume = 12; } + if (IS_TARANIS_X9E(board)) { + strcpy(bluetoothName, "Taranis"); + } + templateSetup = g.profile[g.id()].channelOrder(); stickMode = g.profile[g.id()].defaultMode(); diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 6125dcf82..ed13efde5 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -1174,6 +1174,8 @@ class GeneralSettings { unsigned int mAhWarn; unsigned int mAhUsed; unsigned int globalTimer; + bool bluetoothEnable; + char bluetoothName[10+1]; unsigned int btBaudrate; unsigned int sticksGain; unsigned int rotarySteps; diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index e1cdb86e5..530d744a3 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -3444,6 +3444,11 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, BoardEnum bo internalField.Append(new ZCharField<3>(generalData.sliderName[i])); } } + + if (IS_TARANIS_X9E(board) && version >= 217) { + internalField.Append(new BoolField<8>(generalData.bluetoothEnable)); + internalField.Append(new ZCharField<10>(generalData.bluetoothName)); + } } } diff --git a/companion/src/generaledit/calibration.cpp b/companion/src/generaledit/calibration.cpp index bc024b859..cb9eb2510 100644 --- a/companion/src/generaledit/calibration.cpp +++ b/companion/src/generaledit/calibration.cpp @@ -159,6 +159,16 @@ CalibrationPanel::CalibrationPanel(QWidget * parent, GeneralSettings & generalSe ui->serialPortLabel->hide(); } + if (IS_TARANIS_X9E(firmware->getBoard())) { + ui->bluetoothEnable->setChecked(generalSettings.bluetoothEnable); + ui->bluetoothName->setField(generalSettings.bluetoothName, 10, this); + } + else { + ui->bluetoothLabel->hide(); + ui->bluetoothEnable->hide(); + ui->bluetoothName->hide(); + } + disableMouseScrolling(); } @@ -208,6 +218,12 @@ void CalibrationPanel::on_CurrentCalib_SB_editingFinished() emit modified(); } +void CalibrationPanel::on_bluetoothEnable_stateChanged(int) +{ + generalSettings.bluetoothEnable = ui->bluetoothEnable->isChecked(); + emit modified(); +} + void CalibrationPanel::setValues() { ui->battCalibDSB->setValue((double)generalSettings.vBatCalib/10); diff --git a/companion/src/generaledit/calibration.h b/companion/src/generaledit/calibration.h index b2ceee604..a15265b0c 100644 --- a/companion/src/generaledit/calibration.h +++ b/companion/src/generaledit/calibration.h @@ -29,6 +29,7 @@ class CalibrationPanel : public GeneralPanel void on_PPM_MultiplierDSB_editingFinished(); void on_CurrentCalib_SB_editingFinished(); + void on_bluetoothEnable_stateChanged(int); void on_ana1Neg_editingFinished(); void on_ana2Neg_editingFinished(); diff --git a/companion/src/generaledit/calibration.ui b/companion/src/generaledit/calibration.ui index 0c832a7c0..456a5251a 100644 --- a/companion/src/generaledit/calibration.ui +++ b/companion/src/generaledit/calibration.ui @@ -7,13 +7,36 @@ 0 0 805 - 1188 + 1269 Form - + + + + + + + + -9999 + + + 9999 + + + + + + + Serial Port + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + @@ -83,13 +106,6 @@ - - - - 3 - - - @@ -138,13 +154,23 @@ - - - - Serial Port + + + + - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + -9999 + + + 9999 + + + + + + + Stick 3 @@ -206,7 +232,7 @@ - + @@ -347,20 +373,13 @@ - + PPM 1 - - - - Stick 3 - - - @@ -427,7 +446,7 @@ - + PPM 2 @@ -529,19 +548,6 @@ - - - - - - - -9999 - - - 9999 - - - @@ -555,14 +561,14 @@ - + Battery - + @@ -584,14 +590,14 @@ - + PPM Multiplier - + @@ -610,7 +616,7 @@ - + @@ -629,7 +635,7 @@ - + @@ -648,7 +654,7 @@ - + @@ -667,21 +673,7 @@ - - - - PPM 3 - - - - - - - PPM 4 - - - - + -49 @@ -691,7 +683,21 @@ - + + + + PPM 3 + + + + + + + PPM 4 + + + + Current @@ -711,30 +717,17 @@ - - + + + + + - - -9999 - - - 9999 - - - - - - + - - -9999 - - - 9999 - @@ -763,6 +756,19 @@ + + + + + + + -9999 + + + 9999 + + + @@ -815,16 +821,6 @@ - - - - Negative span - - - Qt::AlignCenter - - - @@ -838,6 +834,23 @@ + + + + Negative span + + + Qt::AlignCenter + + + + + + + 3 + + + @@ -855,13 +868,6 @@ - - - - 3 - - - @@ -876,6 +882,13 @@ + + + + 3 + + + @@ -890,8 +903,8 @@ - - + + 3 @@ -904,20 +917,6 @@ - - - - 3 - - - - - - - Thr - - - @@ -932,6 +931,20 @@ + + + + Thr + + + + + + + 3 + + + @@ -939,8 +952,8 @@ - - + + 3 @@ -953,8 +966,8 @@ - - + + 3 @@ -973,8 +986,8 @@ - - + + 3 @@ -1000,8 +1013,8 @@ - - + + 3 @@ -1027,8 +1040,8 @@ - - + + 3 @@ -1054,8 +1067,8 @@ - - + + 3 @@ -1081,8 +1094,8 @@ - - + + 3 @@ -1095,8 +1108,8 @@ - - + + 3 @@ -1109,8 +1122,8 @@ - - + + 3 @@ -1123,8 +1136,8 @@ - - + + 3 @@ -1137,8 +1150,8 @@ - - + + 3 @@ -1151,8 +1164,8 @@ - - + + 3 @@ -1165,20 +1178,6 @@ - - - - 3 - - - - - - - SN - - - @@ -1192,7 +1191,7 @@ - + @@ -1205,7 +1204,14 @@ - + + + + SN + + + + 1 @@ -1218,6 +1224,13 @@ + + + + 3 + + + @@ -1232,15 +1245,8 @@ - - - - 3 - - - - - + + @@ -1252,8 +1258,8 @@ - - + + @@ -1291,19 +1297,6 @@ - - - - - - - - - - - - - @@ -1534,6 +1527,41 @@ + + + + Bluetooth + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + + + + + + + + 10 + + + + + + + + + 3 + + + diff --git a/radio/src/gui/Taranis/menu_general_hardware.cpp b/radio/src/gui/Taranis/menu_general_hardware.cpp index 3ebbfbf7b..7df9327b7 100755 --- a/radio/src/gui/Taranis/menu_general_hardware.cpp +++ b/radio/src/gui/Taranis/menu_general_hardware.cpp @@ -70,6 +70,7 @@ enum menuGeneralHwItems { CASE_REV9E(ITEM_SETUP_HW_SP) CASE_REV9E(ITEM_SETUP_HW_SQ) CASE_REV9E(ITEM_SETUP_HW_SR) + CASE_REV9E(ITEM_SETUP_HW_BLUETOOTH) ITEM_SETUP_HW_UART3_MODE, ITEM_SETUP_HW_MAX }; @@ -86,13 +87,15 @@ enum menuGeneralHwItems { #if defined(REV9E) #define SWITCHES_ROWS NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1 + #define BLUETOOTH_ROWS 1, #else #define SWITCHES_ROWS NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1 + #define BLUETOOTH_ROWS #endif void menuGeneralHardware(uint8_t event) { - MENU(STR_HARDWARE, menuTabGeneral, e_Hardware, ITEM_SETUP_HW_MAX, { LABEL(Sticks), 0, 0, 0, 0, LABEL(Pots), POTS_ROWS, LABEL(Switches), SWITCHES_ROWS, 0 }); + MENU(STR_HARDWARE, menuTabGeneral, e_Hardware, ITEM_SETUP_HW_MAX, { LABEL(Sticks), 0, 0, 0, 0, LABEL(Pots), POTS_ROWS, LABEL(Switches), SWITCHES_ROWS, BLUETOOTH_ROWS 0 }); uint8_t sub = m_posVert; @@ -205,6 +208,14 @@ void menuGeneralHardware(uint8_t event) } break; } +#if defined(REV9E) + case ITEM_SETUP_HW_BLUETOOTH: + lcd_putsLeft(y, "Bluetooth"); + menu_lcd_onoff(HW_SETTINGS_COLUMN, y, g_eeGeneral.bluetoothEnable, m_posHorz == 0 ? attr : 0); + if (m_posHorz == 0) g_eeGeneral.bluetoothEnable = checkIncDecGen(event, g_eeGeneral.bluetoothEnable, 0, 1); + editName(HW_SETTINGS_COLUMN+5*FW, y, g_eeGeneral.bluetoothName, LEN_BLUETOOTH_NAME, event, m_posHorz == 1 ? attr : 0); + break; +#endif case ITEM_SETUP_HW_UART3_MODE: g_eeGeneral.uart3Mode = selectMenuItem(HW_SETTINGS_COLUMN, y, STR_UART3MODE, STR_UART3MODES, g_eeGeneral.uart3Mode, 0, UART_MODE_MAX, attr, event); if (attr && checkIncDec_Ret) { diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index ca476c55b..f8743bfef 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -381,10 +381,19 @@ enum BeeperMode { UART_MODE_MAX = UART_MODE_COUNT-1 }; - #define LEN_SWITCH_NAME 3 - #define LEN_ANA_NAME 3 - + #define LEN_SWITCH_NAME 3 + #define LEN_ANA_NAME 3 + #define LEN_BLUETOOTH_NAME 10 #define HAS_WIRELESS_TRAINER_HARDWARE() (g_eeGeneral.uart3Mode==UART_MODE_SBUS_TRAINER/* || g_eeGeneral.uart3Mode==UART_MODE_CPPM_TRAINER*/) + + #if defined(REV9E) + #define BLUETOOTH_FIELDS \ + uint8_t bluetoothEnable; \ + char bluetoothName[LEN_BLUETOOTH_NAME]; + #else + #define BLUETOOTH_FIELDS + #endif + #define EXTRA_GENERAL_FIELDS \ EXTRA_GENERAL_FIELDS_ARM \ uint8_t uart3Mode:6; \ @@ -395,7 +404,8 @@ enum BeeperMode { CustomFunctionData customFn[NUM_CFN]; \ swconfig_t switchConfig; \ char switchNames[NUM_SWITCHES][LEN_SWITCH_NAME]; \ - char anaNames[NUM_STICKS+NUM_POTS][LEN_ANA_NAME]; + char anaNames[NUM_STICKS+NUM_POTS][LEN_ANA_NAME]; \ + BLUETOOTH_FIELDS #elif defined(CPUARM) #define EXTRA_GENERAL_FIELDS \ EXTRA_GENERAL_FIELDS_ARM \ diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 70730aeb7..9e2be0714 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -306,6 +306,11 @@ void generalDefault() } #endif +#if defined(PCBTARANIS) && defined(REV9E) + const int8_t defaultName[] = { 20, -1, -18, -1, -14, -9, -19 }; + memcpy(g_eeGeneral.bluetoothName, defaultName, sizeof(defaultName)); +#endif + g_eeGeneral.chkSum = 0xFFFF; } diff --git a/radio/src/targets/taranis/bluetooth_driver.cpp b/radio/src/targets/taranis/bluetooth_driver.cpp index 0c558fa6c..d2d43c15c 100755 --- a/radio/src/targets/taranis/bluetooth_driver.cpp +++ b/radio/src/targets/taranis/bluetooth_driver.cpp @@ -15,6 +15,25 @@ Fifo<64> btTxFifo; Fifo<64> btRxFifo; +enum BluetoothState +{ + BLUETOOTH_INIT, + BLUETOOTH_WAIT_TTM, + BLUETOOTH_WAIT_BAUDRATE_CHANGE, + BLUETOOTH_OK, +}; + +enum BluetoothWriteState +{ + BLUETOOTH_WRITE_IDLE, + BLUETOOTH_WRITE_INIT, + BLUETOOTH_WRITING, + BLUETOOTH_WRITE_DONE +}; + +volatile uint8_t bluetoothState = BLUETOOTH_INIT; +volatile uint8_t bluetoothWriteState = BLUETOOTH_WRITE_IDLE; + void bluetoothInit(uint32_t baudrate) { GPIO_InitTypeDef GPIO_InitStructure; @@ -48,6 +67,7 @@ void bluetoothInit(uint32_t baudrate) GPIO_PinAFConfig(BT_GPIO_TXRX, BT_GPIO_PinSource_TX, BT_GPIO_AF); GPIO_PinAFConfig(BT_GPIO_TXRX, BT_GPIO_PinSource_RX, BT_GPIO_AF); + USART_DeInit(BT_USART); USART_InitStructure.USART_BaudRate = baudrate; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_StopBits = USART_StopBits_1; @@ -69,24 +89,10 @@ void bluetoothInit(uint32_t baudrate) GPIO_ResetBits(BT_GPIO_EN, BT_GPIO_PIN_EN); // open bluetooth } -enum BluetoothState +void bluetoothDone() { - BLUETOOTH_INIT, - BLUETOOTH_WAIT_TTM, - BLUETOOTH_WAIT_BAUDRATE_CHANGE, - BLUETOOTH_OK, -}; - -enum BluetoothWriteState -{ - BLUETOOTH_WRITE_IDLE, - BLUETOOTH_WRITE_INIT, - BLUETOOTH_WRITING, - BLUETOOTH_WRITE_DONE -}; - -volatile uint8_t bluetoothState = BLUETOOTH_INIT; -volatile uint8_t bluetoothWriteState = BLUETOOTH_WRITE_IDLE; + GPIO_SetBits(BT_GPIO_EN, BT_GPIO_PIN_EN); // close bluetooth +} extern "C" void USART6_IRQHandler(void) { @@ -144,54 +150,66 @@ void bluetoothWriteWakeup(void) void bluetoothWakeup(void) { - if (bluetoothState != BLUETOOTH_OK) { - static tmr10ms_t waitEnd = 0; - - if (bluetoothState == BLUETOOTH_INIT) { - const char btMessage[] = "TTM:REN-Taranis"; - bluetoothWriteString(btMessage); - bluetoothState = BLUETOOTH_WAIT_TTM; - waitEnd = get_tmr10ms() + 25/*250*s*/; - } - else if (bluetoothState == BLUETOOTH_WAIT_TTM) { - if (get_tmr10ms() > waitEnd) { - char ttm[] = "TTM:REN"; - int index = 0; - uint8_t c; - bool found = false; - while (btRxFifo.pop(c)) { - if (c == ttm[index]) { - index++; - if (index == sizeof(ttm)-1) { - found = true; - break; - } - } - else { - index = 0; - } - } - if (found) { - bluetoothState = BLUETOOTH_OK; - } - else { - bluetoothInit(9600); - const char btMessage[] = "TTM:BPS-115200"; - bluetoothWriteString(btMessage); - bluetoothState = BLUETOOTH_WAIT_BAUDRATE_CHANGE; - waitEnd = get_tmr10ms() + 250; - } - } - } - else if (bluetoothState == BLUETOOTH_WAIT_BAUDRATE_CHANGE) { - if (get_tmr10ms() > waitEnd) { - bluetoothInit(115200); - bluetoothState = BLUETOOTH_OK; - } + if (!g_eeGeneral.bluetoothEnable) { + if (bluetoothState != BLUETOOTH_INIT) { + bluetoothDone(); + bluetoothState = BLUETOOTH_INIT; } } + else { + if (bluetoothState != BLUETOOTH_OK) { + static tmr10ms_t waitEnd = 0; - bluetoothWriteWakeup(); + if (bluetoothState == BLUETOOTH_INIT) { + bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE); + const char btMessage[] = "TTM:REN-"; + bluetoothWriteString(btMessage); + uint8_t len = ZLEN(g_eeGeneral.bluetoothName); + for (int i=0; i waitEnd) { + char ttm[] = "TTM:REN"; + int index = 0; + uint8_t c; + bool found = false; + while (btRxFifo.pop(c)) { + if (c == ttm[index]) { + index++; + if (index == sizeof(ttm)-1) { + found = true; + break; + } + } + else { + index = 0; + } + } + if (found) { + bluetoothState = BLUETOOTH_OK; + } + else { + bluetoothInit(BLUETOOTH_FACTORY_BAUDRATE); + const char btMessage[] = "TTM:BPS-115200"; + bluetoothWriteString(btMessage); + bluetoothState = BLUETOOTH_WAIT_BAUDRATE_CHANGE; + waitEnd = get_tmr10ms() + 250; // 2.5s + } + } + } + else if (bluetoothState == BLUETOOTH_WAIT_BAUDRATE_CHANGE) { + if (get_tmr10ms() > waitEnd) { + bluetoothState = BLUETOOTH_INIT; + } + } + } + + bluetoothWriteWakeup(); + } } uint8_t bluetoothReady() @@ -212,8 +230,3 @@ int bluetoothRead(void * buffer, int len) } return result; } - -void bluetoothDone() -{ - GPIO_SetBits(BT_GPIO_EN, BT_GPIO_PIN_EN); // close bluetooth -} diff --git a/radio/src/targets/taranis/board_taranis.h b/radio/src/targets/taranis/board_taranis.h index 5849ab10b..7b068335d 100644 --- a/radio/src/targets/taranis/board_taranis.h +++ b/radio/src/targets/taranis/board_taranis.h @@ -330,6 +330,7 @@ void uart3Stop(void); // BT driver #define BLUETOOTH_DEFAULT_BAUDRATE 115200 +#define BLUETOOTH_FACTORY_BAUDRATE 9600 uint8_t bluetoothReady(); void bluetoothInit(uint32_t baudrate); void bluetoothWrite(const void * buffer, int len);