mirror of
https://github.com/opentx/opentx.git
synced 2025-07-26 09:45:21 +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) {
|
while (1) {
|
||||||
if (!btRxFifo.pop(byte)) {
|
if (!btRxFifo.pop(byte)) {
|
||||||
|
#if defined(PCBX9E) // X9E BT module can get unresponsive
|
||||||
|
TRACE("NO RESPONSE FROM BT MODULE");
|
||||||
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
TRACE_NOCRLF("%02X ", byte);
|
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()
|
void bluetoothWakeup()
|
||||||
{
|
{
|
||||||
tmr10ms_t now = get_tmr10ms();
|
tmr10ms_t now = get_tmr10ms();
|
||||||
|
@ -267,11 +329,7 @@ void bluetoothWakeup()
|
||||||
}
|
}
|
||||||
strAppend(cur, "\r\n");
|
strAppend(cur, "\r\n");
|
||||||
bluetoothWriteString(command);
|
bluetoothWriteString(command);
|
||||||
#if defined(PCBX9E)
|
|
||||||
bluetoothState = BLUETOOTH_STATE_CONNECTED;
|
|
||||||
#else
|
|
||||||
bluetoothState = BLUETOOTH_STATE_NAME_SENT;
|
bluetoothState = BLUETOOTH_STATE_NAME_SENT;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else if (bluetoothState == BLUETOOTH_STATE_NAME_SENT && !strncmp(line, "OK+", 3)) {
|
else if (bluetoothState == BLUETOOTH_STATE_NAME_SENT && !strncmp(line, "OK+", 3)) {
|
||||||
bluetoothWriteString("AT+TXPW3\r\n");
|
bluetoothWriteString("AT+TXPW3\r\n");
|
||||||
|
@ -317,3 +375,4 @@ void bluetoothWakeup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -19,6 +19,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum BluetoothStates {
|
enum BluetoothStates {
|
||||||
|
#if defined(PCBX9E) && defined(DEBUG)
|
||||||
|
BLUETOOTH_INIT,
|
||||||
|
BLUETOOTH_WAIT_TTM,
|
||||||
|
BLUETOOTH_WAIT_BAUDRATE_CHANGE,
|
||||||
|
#endif
|
||||||
BLUETOOTH_STATE_OFF,
|
BLUETOOTH_STATE_OFF,
|
||||||
BLUETOOTH_STATE_NAME_SENT,
|
BLUETOOTH_STATE_NAME_SENT,
|
||||||
BLUETOOTH_STATE_POWER_SENT,
|
BLUETOOTH_STATE_POWER_SENT,
|
||||||
|
@ -38,6 +43,7 @@ enum BluetoothStates {
|
||||||
extern volatile uint8_t bluetoothState;
|
extern volatile uint8_t bluetoothState;
|
||||||
extern char bluetoothFriend[LEN_BLUETOOTH_FRIEND+1];
|
extern char bluetoothFriend[LEN_BLUETOOTH_FRIEND+1];
|
||||||
|
|
||||||
|
char * bluetoothReadline();
|
||||||
void bluetoothWriteString(const char * command);
|
void bluetoothWriteString(const char * command);
|
||||||
void bluetoothForwardTelemetry(uint8_t data);
|
void bluetoothForwardTelemetry(uint8_t data);
|
||||||
void bluetoothWakeup();
|
void bluetoothWakeup();
|
||||||
|
|
|
@ -1205,11 +1205,14 @@ int cliBlueTooth(const char ** argv)
|
||||||
char command[32];
|
char command[32];
|
||||||
strAppend(strAppend(command, argv[1]), "\r\n");
|
strAppend(strAppend(command, argv[1]), "\r\n");
|
||||||
bluetoothWriteString(command);
|
bluetoothWriteString(command);
|
||||||
|
char * line = bluetoothReadline();
|
||||||
|
serialPrint("<BT %s", line);
|
||||||
}
|
}
|
||||||
else if (toInt(argv, 1, &baudrate) > 0) {
|
else if (toInt(argv, 1, &baudrate) > 0) {
|
||||||
if (baudrate > 0) {
|
if (baudrate > 0) {
|
||||||
bluetoothInit(baudrate);
|
bluetoothInit(baudrate);
|
||||||
serialPrint("BT baudrate set to %d", baudrate);
|
char * line = bluetoothReadline();
|
||||||
|
serialPrint("<BT %s", line);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bluetoothDone();
|
bluetoothDone();
|
||||||
|
|
|
@ -242,7 +242,7 @@ int getSwitchWarningsCount()
|
||||||
#define INTERNAL_MODULE_CHANNELS_ROWS IF_INTERNAL_MODULE_ON(1)
|
#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))
|
#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_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_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)
|
#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) {
|
if (attr) {
|
||||||
g_model.trainerMode = checkIncDec(event, g_model.trainerMode, 0, TRAINER_MODE_MAX(), EE_MODEL, isTrainerModeAvailable);
|
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) {
|
if (attr && checkIncDec_Ret) {
|
||||||
bluetoothState = BLUETOOTH_STATE_OFF;
|
bluetoothState = BLUETOOTH_STATE_OFF;
|
||||||
bluetoothFriend[0] = 0;
|
bluetoothFriend[0] = 0;
|
||||||
|
@ -821,7 +821,7 @@ void menuModelSetup(event_t event)
|
||||||
lcdDrawTextAlignedLeft(y, STR_TRAINER);
|
lcdDrawTextAlignedLeft(y, STR_TRAINER);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if defined(BLUETOOTH)
|
#if defined(BLUETOOTH) && defined(DEBUG)
|
||||||
case ITEM_MODEL_TRAINER_LINE1:
|
case ITEM_MODEL_TRAINER_LINE1:
|
||||||
if (g_model.trainerMode == TRAINER_MODE_MASTER_BLUETOOTH) {
|
if (g_model.trainerMode == TRAINER_MODE_MASTER_BLUETOOTH) {
|
||||||
if (attr) {
|
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
|
#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
|
#endif
|
||||||
|
|
||||||
#if defined(BLUETOOTH)
|
#if defined(BLUETOOTH) && defined(DEBUG)
|
||||||
#define BLUETOOTH_ROWS 0, uint8_t(g_eeGeneral.bluetoothMode == BLUETOOTH_OFF ? -1 : 0),
|
#define BLUETOOTH_ROWS 0, uint8_t(g_eeGeneral.bluetoothMode == BLUETOOTH_OFF ? -1 : 0),
|
||||||
#else
|
#else
|
||||||
#define BLUETOOTH_ROWS
|
#define BLUETOOTH_ROWS
|
||||||
|
@ -198,7 +198,7 @@ void menuRadioHardware(event_t event)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(BLUETOOTH)
|
#if defined(BLUETOOTH) && defined(DEBUG)
|
||||||
case ITEM_RADIO_HARDWARE_BLUETOOTH_MODE:
|
case ITEM_RADIO_HARDWARE_BLUETOOTH_MODE:
|
||||||
lcdDrawText(INDENT_WIDTH, y, STR_BLUETOOTH);
|
lcdDrawText(INDENT_WIDTH, y, STR_BLUETOOTH);
|
||||||
lcdDrawTextAtIndex(HW_SETTINGS_COLUMN, y, STR_BLUETOOTH_MODES, g_eeGeneral.bluetoothMode, attr);
|
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))
|
if (IS_EXTERNAL_MODULE_PRESENT() && (mode == TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE || mode == TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE))
|
||||||
return false;
|
return false;
|
||||||
|
#if defined(DEBUG)
|
||||||
else if (mode == TRAINER_MODE_MASTER_BLUETOOTH || mode == TRAINER_MODE_MASTER_BATTERY_COMPARTMENT)
|
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;
|
return false;
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -146,7 +146,7 @@
|
||||||
#define CASE_SDCARD(x)
|
#define CASE_SDCARD(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(BLUETOOTH)
|
#if defined(BLUETOOTH) && !(defined(PCBX9E) && !defined(DEBUG))
|
||||||
#define CASE_BLUETOOTH(x) x,
|
#define CASE_BLUETOOTH(x) x,
|
||||||
#else
|
#else
|
||||||
#define CASE_BLUETOOTH(x)
|
#define CASE_BLUETOOTH(x)
|
||||||
|
@ -194,7 +194,7 @@
|
||||||
#define CASE_PCBX9E(x)
|
#define CASE_PCBX9E(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(BLUETOOTH)
|
#if defined(BLUETOOTH) && (!defined(PCBX9E) || defined(DEBUG))
|
||||||
#define CASE_BLUETOOTH(x) x,
|
#define CASE_BLUETOOTH(x) x,
|
||||||
#else
|
#else
|
||||||
#define CASE_BLUETOOTH(x)
|
#define CASE_BLUETOOTH(x)
|
||||||
|
|
|
@ -549,6 +549,7 @@ void serial2Stop(void);
|
||||||
|
|
||||||
// BT driver
|
// BT driver
|
||||||
#define BLUETOOTH_DEFAULT_BAUDRATE 115200
|
#define BLUETOOTH_DEFAULT_BAUDRATE 115200
|
||||||
|
#define BLUETOOTH_FACTORY_BAUDRATE 9600
|
||||||
void bluetoothInit(uint32_t baudrate);
|
void bluetoothInit(uint32_t baudrate);
|
||||||
void bluetoothWriteWakeup(void);
|
void bluetoothWriteWakeup(void);
|
||||||
void bluetoothDone(void);
|
void bluetoothDone(void);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue