mirror of
https://github.com/opentx/opentx.git
synced 2025-07-24 16:55:20 +03:00
Neutralise BT on X9E, unless DEBUG is defined (#5148)
* Neutralise BT on X9E, unless DEBUG is defined * Adjust to Bertrand comments
This commit is contained in:
parent
0e139fd0d6
commit
5a8a074f0c
8 changed files with 85 additions and 12 deletions
|
@ -64,6 +64,9 @@ char * bluetoothReadline()
|
|||
|
||||
while (1) {
|
||||
if (!btRxFifo.pop(byte)) {
|
||||
#if defined(PCBX9E) // X9E BT module can get unresponsive
|
||||
TRACE("NO RESPONSE FROM BT MODULE");
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
TRACE_NOCRLF("%02X ", byte);
|
||||
|
@ -218,6 +221,65 @@ void bluetoothReceiveTrainer()
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(PCBX9E) && defined(DEBUG)
|
||||
void bluetoothWakeup(void)
|
||||
{
|
||||
if (!g_eeGeneral.bluetoothMode) {
|
||||
if (bluetoothState != BLUETOOTH_INIT) {
|
||||
bluetoothDone();
|
||||
bluetoothState = BLUETOOTH_INIT;
|
||||
}
|
||||
}
|
||||
else {
|
||||
static tmr10ms_t waitEnd = 0;
|
||||
if (bluetoothState != BLUETOOTH_STATE_IDLE) {
|
||||
|
||||
if (bluetoothState == BLUETOOTH_INIT) {
|
||||
bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE);
|
||||
char command[32];
|
||||
char * cur = strAppend(command, BLUETOOTH_COMMAND_NAME);
|
||||
uint8_t len = ZLEN(g_eeGeneral.bluetoothName);
|
||||
if (len > 0) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
*cur++ = idx2char(g_eeGeneral.bluetoothName[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
cur = strAppend(cur, "Taranis-X9E");
|
||||
}
|
||||
strAppend(cur, "\r\n");
|
||||
bluetoothWriteString(command);
|
||||
bluetoothState = BLUETOOTH_WAIT_TTM;
|
||||
waitEnd = get_tmr10ms() + 25; // 250ms
|
||||
}
|
||||
else if (bluetoothState == BLUETOOTH_WAIT_TTM) {
|
||||
if (get_tmr10ms() > waitEnd) {
|
||||
char * line = bluetoothReadline();
|
||||
if (strncmp(line, "OK+", 3)) {
|
||||
bluetoothState = BLUETOOTH_STATE_IDLE;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
} else if (IS_BLUETOOTH_TRAINER()){
|
||||
bluetoothState = BLUETOOTH_STATE_CONNECTED;
|
||||
bluetoothWriteWakeup();
|
||||
bluetoothSendTrainer();
|
||||
}
|
||||
}
|
||||
}
|
||||
#else //PCBX9E
|
||||
void bluetoothWakeup()
|
||||
{
|
||||
tmr10ms_t now = get_tmr10ms();
|
||||
|
@ -267,11 +329,7 @@ void bluetoothWakeup()
|
|||
}
|
||||
strAppend(cur, "\r\n");
|
||||
bluetoothWriteString(command);
|
||||
#if defined(PCBX9E)
|
||||
bluetoothState = BLUETOOTH_STATE_CONNECTED;
|
||||
#else
|
||||
bluetoothState = BLUETOOTH_STATE_NAME_SENT;
|
||||
#endif
|
||||
}
|
||||
else if (bluetoothState == BLUETOOTH_STATE_NAME_SENT && !strncmp(line, "OK+", 3)) {
|
||||
bluetoothWriteString("AT+TXPW3\r\n");
|
||||
|
@ -317,3 +375,4 @@ void bluetoothWakeup()
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
*/
|
||||
|
||||
enum BluetoothStates {
|
||||
#if defined(PCBX9E) && defined(DEBUG)
|
||||
BLUETOOTH_INIT,
|
||||
BLUETOOTH_WAIT_TTM,
|
||||
BLUETOOTH_WAIT_BAUDRATE_CHANGE,
|
||||
#endif
|
||||
BLUETOOTH_STATE_OFF,
|
||||
BLUETOOTH_STATE_NAME_SENT,
|
||||
BLUETOOTH_STATE_POWER_SENT,
|
||||
|
@ -38,6 +43,7 @@ enum BluetoothStates {
|
|||
extern volatile uint8_t bluetoothState;
|
||||
extern char bluetoothFriend[LEN_BLUETOOTH_FRIEND+1];
|
||||
|
||||
char * bluetoothReadline();
|
||||
void bluetoothWriteString(const char * command);
|
||||
void bluetoothForwardTelemetry(uint8_t data);
|
||||
void bluetoothWakeup();
|
||||
|
|
|
@ -1205,11 +1205,14 @@ int cliBlueTooth(const char ** argv)
|
|||
char command[32];
|
||||
strAppend(strAppend(command, argv[1]), "\r\n");
|
||||
bluetoothWriteString(command);
|
||||
char * line = bluetoothReadline();
|
||||
serialPrint("<BT %s", line);
|
||||
}
|
||||
else if (toInt(argv, 1, &baudrate) > 0) {
|
||||
if (baudrate > 0) {
|
||||
bluetoothInit(baudrate);
|
||||
serialPrint("BT baudrate set to %d", baudrate);
|
||||
char * line = bluetoothReadline();
|
||||
serialPrint("<BT %s", line);
|
||||
}
|
||||
else {
|
||||
bluetoothDone();
|
||||
|
|
|
@ -242,7 +242,7 @@ int getSwitchWarningsCount()
|
|||
#define INTERNAL_MODULE_CHANNELS_ROWS IF_INTERNAL_MODULE_ON(1)
|
||||
#define PORT_CHANNELS_ROWS(x) (x==INTERNAL_MODULE ? INTERNAL_MODULE_CHANNELS_ROWS : (x==EXTERNAL_MODULE ? EXTERNAL_MODULE_CHANNELS_ROWS : 1))
|
||||
|
||||
#if defined(BLUETOOTH)
|
||||
#if defined(BLUETOOTH) && defined(DEBUG)
|
||||
#define TRAINER_LINE1_BLUETOOTH_M_ROWS ((bluetoothFriend[0] == 0 || bluetoothState == BLUETOOTH_STATE_CONNECTED) ? (uint8_t)0 : (uint8_t)1)
|
||||
#define TRAINER_LINE1_ROWS (g_model.trainerMode == TRAINER_MODE_SLAVE ? (uint8_t)1 : (g_model.trainerMode == TRAINER_MODE_MASTER_BLUETOOTH ? TRAINER_LINE1_BLUETOOTH_M_ROWS : (g_model.trainerMode == TRAINER_MODE_SLAVE_BLUETOOTH ? (uint8_t)1 : HIDDEN_ROW)))
|
||||
#define TRAINER_LINE2_ROWS (g_model.trainerMode == TRAINER_MODE_SLAVE ? (uint8_t)2 : HIDDEN_ROW)
|
||||
|
@ -719,7 +719,7 @@ void menuModelSetup(event_t event)
|
|||
if (attr) {
|
||||
g_model.trainerMode = checkIncDec(event, g_model.trainerMode, 0, TRAINER_MODE_MAX(), EE_MODEL, isTrainerModeAvailable);
|
||||
}
|
||||
#if defined(BLUETOOTH)
|
||||
#if defined(BLUETOOTH) && defined(DEBUG)
|
||||
if (attr && checkIncDec_Ret) {
|
||||
bluetoothState = BLUETOOTH_STATE_OFF;
|
||||
bluetoothFriend[0] = 0;
|
||||
|
@ -821,7 +821,7 @@ void menuModelSetup(event_t event)
|
|||
lcdDrawTextAlignedLeft(y, STR_TRAINER);
|
||||
break;
|
||||
|
||||
#if defined(BLUETOOTH)
|
||||
#if defined(BLUETOOTH) && defined(DEBUG)
|
||||
case ITEM_MODEL_TRAINER_LINE1:
|
||||
if (g_model.trainerMode == TRAINER_MODE_MASTER_BLUETOOTH) {
|
||||
if (attr) {
|
||||
|
|
|
@ -77,7 +77,7 @@ enum menuRadioHwItems {
|
|||
#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
|
||||
#endif
|
||||
|
||||
#if defined(BLUETOOTH)
|
||||
#if defined(BLUETOOTH) && defined(DEBUG)
|
||||
#define BLUETOOTH_ROWS 0, uint8_t(g_eeGeneral.bluetoothMode == BLUETOOTH_OFF ? -1 : 0),
|
||||
#else
|
||||
#define BLUETOOTH_ROWS
|
||||
|
@ -198,7 +198,7 @@ void menuRadioHardware(event_t event)
|
|||
break;
|
||||
}
|
||||
|
||||
#if defined(BLUETOOTH)
|
||||
#if defined(BLUETOOTH) && defined(DEBUG)
|
||||
case ITEM_RADIO_HARDWARE_BLUETOOTH_MODE:
|
||||
lcdDrawText(INDENT_WIDTH, y, STR_BLUETOOTH);
|
||||
lcdDrawTextAtIndex(HW_SETTINGS_COLUMN, y, STR_BLUETOOTH_MODES, g_eeGeneral.bluetoothMode, attr);
|
||||
|
|
|
@ -565,7 +565,11 @@ bool isTrainerModeAvailable(int mode)
|
|||
{
|
||||
if (IS_EXTERNAL_MODULE_PRESENT() && (mode == TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE || mode == TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE))
|
||||
return false;
|
||||
#if defined(DEBUG)
|
||||
else if (mode == TRAINER_MODE_MASTER_BLUETOOTH || mode == TRAINER_MODE_MASTER_BATTERY_COMPARTMENT)
|
||||
#else
|
||||
else if (mode == TRAINER_MODE_MASTER_BLUETOOTH || mode == TRAINER_MODE_MASTER_BATTERY_COMPARTMENT || mode == TRAINER_MODE_SLAVE_BLUETOOTH)
|
||||
#endif
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
|
|
|
@ -146,7 +146,7 @@
|
|||
#define CASE_SDCARD(x)
|
||||
#endif
|
||||
|
||||
#if defined(BLUETOOTH)
|
||||
#if defined(BLUETOOTH) && !(defined(PCBX9E) && !defined(DEBUG))
|
||||
#define CASE_BLUETOOTH(x) x,
|
||||
#else
|
||||
#define CASE_BLUETOOTH(x)
|
||||
|
@ -194,7 +194,7 @@
|
|||
#define CASE_PCBX9E(x)
|
||||
#endif
|
||||
|
||||
#if defined(BLUETOOTH)
|
||||
#if defined(BLUETOOTH) && (!defined(PCBX9E) || defined(DEBUG))
|
||||
#define CASE_BLUETOOTH(x) x,
|
||||
#else
|
||||
#define CASE_BLUETOOTH(x)
|
||||
|
|
|
@ -549,6 +549,7 @@ void serial2Stop(void);
|
|||
|
||||
// BT driver
|
||||
#define BLUETOOTH_DEFAULT_BAUDRATE 115200
|
||||
#define BLUETOOTH_FACTORY_BAUDRATE 9600
|
||||
void bluetoothInit(uint32_t baudrate);
|
||||
void bluetoothWriteWakeup(void);
|
||||
void bluetoothDone(void);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue