Bluetooth fixes (reconnection issues, telemetry mode not working) (#5186)
Bluetooth fixes (reconnection issues, telemetry mode not working)
This commit is contained in:
+153
-94
@@ -37,17 +37,21 @@ extern Fifo<uint8_t, 64> btTxFifo;
|
|||||||
extern Fifo<uint8_t, 64> btRxFifo;
|
extern Fifo<uint8_t, 64> btRxFifo;
|
||||||
|
|
||||||
volatile uint8_t bluetoothState;
|
volatile uint8_t bluetoothState;
|
||||||
char bluetoothFriend[LEN_BLUETOOTH_FRIEND+1];
|
char bluetoothLocalAddr[LEN_BLUETOOTH_ADDR+1];
|
||||||
|
char bluetoothDistantAddr[LEN_BLUETOOTH_ADDR+1];
|
||||||
uint8_t bluetoothBuffer[BLUETOOTH_LINE_LENGTH+1];
|
uint8_t bluetoothBuffer[BLUETOOTH_LINE_LENGTH+1];
|
||||||
uint8_t bluetoothBufferIndex = 0;
|
uint8_t bluetoothBufferIndex = 0;
|
||||||
tmr10ms_t bluetoothWakeupTime = 0;
|
tmr10ms_t bluetoothWakeupTime = 0;
|
||||||
|
|
||||||
void bluetoothWrite(const uint8_t * data, uint8_t length)
|
void bluetoothWrite(const uint8_t * data, uint8_t length)
|
||||||
{
|
{
|
||||||
|
TRACE_NOCRLF("BT>");
|
||||||
for (int i=0; i<length; i++) {
|
for (int i=0; i<length; i++) {
|
||||||
TRACE_NOCRLF("%02X ", data[i]);
|
TRACE_NOCRLF(" %02X", data[i]);
|
||||||
btTxFifo.push(data[i]);
|
btTxFifo.push(data[i]);
|
||||||
}
|
}
|
||||||
|
TRACE_NOCRLF("\r\n");
|
||||||
|
bluetoothWriteWakeup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void bluetoothWriteString(const char * str)
|
void bluetoothWriteString(const char * str)
|
||||||
@@ -56,9 +60,10 @@ void bluetoothWriteString(const char * str)
|
|||||||
while (*str != 0) {
|
while (*str != 0) {
|
||||||
btTxFifo.push(*str++);
|
btTxFifo.push(*str++);
|
||||||
}
|
}
|
||||||
|
bluetoothWriteWakeup();
|
||||||
}
|
}
|
||||||
|
|
||||||
char * bluetoothReadline()
|
char * bluetoothReadline(bool error_reset)
|
||||||
{
|
{
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
|
|
||||||
@@ -71,12 +76,30 @@ char * bluetoothReadline()
|
|||||||
}
|
}
|
||||||
TRACE_NOCRLF("%02X ", byte);
|
TRACE_NOCRLF("%02X ", byte);
|
||||||
if (byte == '\n') {
|
if (byte == '\n') {
|
||||||
bluetoothBuffer[bluetoothBufferIndex] = '\0';
|
if (bluetoothBufferIndex > 2 && bluetoothBuffer[bluetoothBufferIndex-1] == '\r') {
|
||||||
bluetoothBufferIndex = 0;
|
bluetoothBuffer[bluetoothBufferIndex-1] = '\0';
|
||||||
TRACE("BT< %s", bluetoothBuffer);
|
bluetoothBufferIndex = 0;
|
||||||
return (char *)bluetoothBuffer;
|
TRACE("BT< %s", bluetoothBuffer);
|
||||||
|
if (error_reset && !strcmp((char *)bluetoothBuffer, "ERROR")) {
|
||||||
|
TRACE("BT Reset...");
|
||||||
|
bluetoothDone();
|
||||||
|
bluetoothState = BLUETOOTH_STATE_OFF;
|
||||||
|
bluetoothWakeupTime = get_tmr10ms() + 100; /* 1s */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!strncmp((char *)bluetoothBuffer, "Central:", 8))
|
||||||
|
strcpy(bluetoothLocalAddr, (char *)bluetoothBuffer+8);
|
||||||
|
else if (!strncmp((char *)bluetoothBuffer, "Peripheral:", 11))
|
||||||
|
strcpy(bluetoothLocalAddr, (char *)bluetoothBuffer+11);
|
||||||
|
return (char *)bluetoothBuffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bluetoothBufferIndex = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (byte != '\r') {
|
else {
|
||||||
bluetoothBuffer[bluetoothBufferIndex++] = byte;
|
bluetoothBuffer[bluetoothBufferIndex++] = byte;
|
||||||
bluetoothBufferIndex &= (BLUETOOTH_LINE_LENGTH-1);
|
bluetoothBufferIndex &= (BLUETOOTH_LINE_LENGTH-1);
|
||||||
}
|
}
|
||||||
@@ -96,6 +119,22 @@ void bluetoothProcessTrainerFrame(const uint8_t * bluetoothBuffer)
|
|||||||
ppmInputValidityTimer = PPM_IN_VALID_TIMEOUT;
|
ppmInputValidityTimer = PPM_IN_VALID_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bluetoothAppendTrainerByte(uint8_t data)
|
||||||
|
{
|
||||||
|
if (bluetoothBufferIndex < BLUETOOTH_LINE_LENGTH) {
|
||||||
|
bluetoothBuffer[bluetoothBufferIndex++] = data;
|
||||||
|
// we check for "DisConnected", but the first byte could be altered (if received in state STATE_DATA_XOR)
|
||||||
|
if (data == '\n') {
|
||||||
|
if (!strncmp((char *)&bluetoothBuffer[bluetoothBufferIndex-13], "isConnected", 11)) {
|
||||||
|
TRACE("BT< DisConnected");
|
||||||
|
bluetoothState = BLUETOOTH_STATE_DISCONNECTED;
|
||||||
|
bluetoothBufferIndex = 0;
|
||||||
|
bluetoothWakeupTime += 200; // 1s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void bluetoothProcessTrainerByte(uint8_t data)
|
void bluetoothProcessTrainerByte(uint8_t data)
|
||||||
{
|
{
|
||||||
static uint8_t dataState = STATE_DATA_IDLE;
|
static uint8_t dataState = STATE_DATA_IDLE;
|
||||||
@@ -107,13 +146,7 @@ void bluetoothProcessTrainerByte(uint8_t data)
|
|||||||
bluetoothBufferIndex = 0;
|
bluetoothBufferIndex = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (bluetoothBufferIndex < BLUETOOTH_PACKET_SIZE) {
|
bluetoothAppendTrainerByte(data);
|
||||||
bluetoothBuffer[bluetoothBufferIndex++] = data;
|
|
||||||
}
|
|
||||||
if (data == '\n' && !strncmp((char *)bluetoothBuffer, "DisConnected", 12)) {
|
|
||||||
bluetoothState = BLUETOOTH_STATE_IDLE;
|
|
||||||
bluetoothBufferIndex = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -125,15 +158,13 @@ void bluetoothProcessTrainerByte(uint8_t data)
|
|||||||
dataState = STATE_DATA_IN_FRAME ;
|
dataState = STATE_DATA_IN_FRAME ;
|
||||||
bluetoothBufferIndex = 0;
|
bluetoothBufferIndex = 0;
|
||||||
}
|
}
|
||||||
else if (bluetoothBufferIndex < BLUETOOTH_PACKET_SIZE) {
|
else {
|
||||||
bluetoothBuffer[bluetoothBufferIndex++] = data;
|
bluetoothAppendTrainerByte(data);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE_DATA_XOR:
|
case STATE_DATA_XOR:
|
||||||
if (telemetryRxBufferCount < BLUETOOTH_PACKET_SIZE) {
|
bluetoothAppendTrainerByte(data ^ STUFF_MASK);
|
||||||
bluetoothBuffer[bluetoothBufferIndex++] = data ^ STUFF_MASK;
|
|
||||||
}
|
|
||||||
dataState = STATE_DATA_IN_FRAME;
|
dataState = STATE_DATA_IN_FRAME;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -142,6 +173,9 @@ void bluetoothProcessTrainerByte(uint8_t data)
|
|||||||
bluetoothBufferIndex = 0;
|
bluetoothBufferIndex = 0;
|
||||||
dataState = STATE_DATA_START;
|
dataState = STATE_DATA_START;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
bluetoothAppendTrainerByte(data);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +234,7 @@ void bluetoothSendTrainer()
|
|||||||
void bluetoothForwardTelemetry(uint8_t data)
|
void bluetoothForwardTelemetry(uint8_t data)
|
||||||
{
|
{
|
||||||
bluetoothBuffer[bluetoothBufferIndex++] = data;
|
bluetoothBuffer[bluetoothBufferIndex++] = data;
|
||||||
if (bluetoothBufferIndex == BLUETOOTH_LINE_LENGTH || (data == START_STOP && bluetoothBufferIndex > 2*FRSKY_SPORT_PACKET_SIZE)) {
|
if (data == START_STOP && bluetoothBufferIndex >= 2*FRSKY_SPORT_PACKET_SIZE) {
|
||||||
bluetoothWrite(bluetoothBuffer, bluetoothBufferIndex);
|
bluetoothWrite(bluetoothBuffer, bluetoothBufferIndex);
|
||||||
bluetoothBufferIndex = 0;
|
bluetoothBufferIndex = 0;
|
||||||
}
|
}
|
||||||
@@ -272,14 +306,15 @@ void bluetoothWakeup(void)
|
|||||||
bluetoothState = BLUETOOTH_INIT;
|
bluetoothState = BLUETOOTH_INIT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (IS_BLUETOOTH_TRAINER()){
|
}
|
||||||
|
else if (IS_BLUETOOTH_TRAINER()){
|
||||||
bluetoothState = BLUETOOTH_STATE_CONNECTED;
|
bluetoothState = BLUETOOTH_STATE_CONNECTED;
|
||||||
bluetoothWriteWakeup();
|
bluetoothWriteWakeup();
|
||||||
bluetoothSendTrainer();
|
bluetoothSendTrainer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else //PCBX9E
|
#else // PCBX9E
|
||||||
void bluetoothWakeup()
|
void bluetoothWakeup()
|
||||||
{
|
{
|
||||||
tmr10ms_t now = get_tmr10ms();
|
tmr10ms_t now = get_tmr10ms();
|
||||||
@@ -287,92 +322,116 @@ void bluetoothWakeup()
|
|||||||
if (now < bluetoothWakeupTime)
|
if (now < bluetoothWakeupTime)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (g_eeGeneral.bluetoothMode == BLUETOOTH_OFF || !IS_BLUETOOTH_TRAINER()) {
|
bluetoothWakeupTime = now + 5; /* 50ms default */
|
||||||
|
|
||||||
|
if (g_eeGeneral.bluetoothMode == BLUETOOTH_OFF || (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER && !IS_BLUETOOTH_TRAINER())) {
|
||||||
if (bluetoothState != BLUETOOTH_STATE_OFF) {
|
if (bluetoothState != BLUETOOTH_STATE_OFF) {
|
||||||
bluetoothDone();
|
bluetoothDone();
|
||||||
bluetoothState = BLUETOOTH_STATE_OFF;
|
bluetoothState = BLUETOOTH_STATE_OFF;
|
||||||
}
|
}
|
||||||
bluetoothWakeupTime = now + 10;
|
bluetoothWakeupTime = now + 10; /* 100ms */
|
||||||
}
|
}
|
||||||
else {
|
else if (bluetoothState == BLUETOOTH_STATE_OFF) {
|
||||||
bluetoothWakeupTime = now + 2;
|
bluetoothInit(BLUETOOTH_FACTORY_BAUDRATE);
|
||||||
|
bluetoothState = BLUETOOTH_STATE_FACTORY_BAUDRATE_INIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bluetoothState != BLUETOOTH_STATE_OFF) {
|
||||||
bluetoothWriteWakeup();
|
bluetoothWriteWakeup();
|
||||||
if (bluetoothState == BLUETOOTH_STATE_CONNECTED) {
|
if (bluetoothIsWriting()) {
|
||||||
if (g_model.trainerMode == TRAINER_MODE_MASTER_BLUETOOTH) {
|
return;
|
||||||
bluetoothReceiveTrainer();
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
bluetoothSendTrainer();
|
if (bluetoothState == BLUETOOTH_STATE_FACTORY_BAUDRATE_INIT) {
|
||||||
char * line = bluetoothReadline();
|
bluetoothWriteString("AT+BAUD4\r\n");
|
||||||
if (!strcmp(line, "ERROR")) {
|
bluetoothState = BLUETOOTH_STATE_BAUDRATE_SENT;
|
||||||
bluetoothState = BLUETOOTH_STATE_IDLE;
|
}
|
||||||
}
|
else if (bluetoothState == BLUETOOTH_STATE_BAUDRATE_SENT) {
|
||||||
}
|
bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE);
|
||||||
|
bluetoothState = BLUETOOTH_STATE_BAUDRATE_INIT;
|
||||||
|
bluetoothReadline(false);
|
||||||
|
}
|
||||||
|
else if (bluetoothState == BLUETOOTH_STATE_CONNECTED) {
|
||||||
|
if (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER && g_model.trainerMode == TRAINER_MODE_MASTER_BLUETOOTH) {
|
||||||
|
bluetoothReceiveTrainer();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char * line = bluetoothReadline();
|
if (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER && g_model.trainerMode == TRAINER_MODE_SLAVE_BLUETOOTH) {
|
||||||
if (bluetoothState == BLUETOOTH_STATE_OFF && IS_BLUETOOTH_TRAINER()) {
|
bluetoothSendTrainer();
|
||||||
char command[32];
|
bluetoothWakeupTime = now + 2; /* 20ms */
|
||||||
char * cur = strAppend(command, BLUETOOTH_COMMAND_NAME);
|
}
|
||||||
uint8_t len = ZLEN(g_eeGeneral.bluetoothName);
|
bluetoothReadline(); // to deal with "ERROR"
|
||||||
if (len > 0) {
|
}
|
||||||
for (int i = 0; i < len; i++) {
|
}
|
||||||
*cur++ = idx2char(g_eeGeneral.bluetoothName[i]);
|
else {
|
||||||
}
|
char * line = bluetoothReadline();
|
||||||
|
if (bluetoothState == BLUETOOTH_STATE_BAUDRATE_INIT) {
|
||||||
|
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 {
|
}
|
||||||
|
else {
|
||||||
#if defined(PCBHORUS)
|
#if defined(PCBHORUS)
|
||||||
cur = strAppend(cur, "Horus");
|
cur = strAppend(cur, "Horus");
|
||||||
#else
|
#else
|
||||||
cur = strAppend(cur, "Taranis");
|
cur = strAppend(cur, "Taranis");
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
strAppend(cur, "\r\n");
|
|
||||||
bluetoothWriteString(command);
|
|
||||||
bluetoothState = BLUETOOTH_STATE_NAME_SENT;
|
|
||||||
}
|
}
|
||||||
else if (bluetoothState == BLUETOOTH_STATE_NAME_SENT && !strncmp(line, "OK+", 3)) {
|
strAppend(cur, "\r\n");
|
||||||
bluetoothWriteString("AT+TXPW3\r\n");
|
bluetoothWriteString(command);
|
||||||
bluetoothState = BLUETOOTH_STATE_POWER_SENT;
|
bluetoothState = BLUETOOTH_STATE_NAME_SENT;
|
||||||
}
|
}
|
||||||
else if (bluetoothState == BLUETOOTH_STATE_POWER_SENT && (!strncmp(line, "Central:", 8) || !strncmp(line, "Peripheral:", 11))) {
|
else if (bluetoothState == BLUETOOTH_STATE_NAME_SENT && (!strncmp(line, "OK+", 3) || !strncmp(line, "Central:", 8) || !strncmp(line, "Peripheral:", 11))) {
|
||||||
if (g_model.trainerMode == TRAINER_MODE_MASTER_BLUETOOTH)
|
bluetoothWriteString("AT+TXPW3\r\n");
|
||||||
bluetoothWriteString("AT+ROLE1\r\n");
|
bluetoothState = BLUETOOTH_STATE_POWER_SENT;
|
||||||
else
|
}
|
||||||
bluetoothWriteString("AT+ROLE0\r\n");
|
else if (bluetoothState == BLUETOOTH_STATE_POWER_SENT && (!strncmp(line, "Central:", 8) || !strncmp(line, "Peripheral:", 11))) {
|
||||||
bluetoothState = BLUETOOTH_STATE_ROLE_SENT;
|
if (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER && g_model.trainerMode == TRAINER_MODE_MASTER_BLUETOOTH)
|
||||||
}
|
bluetoothWriteString("AT+ROLE1\r\n");
|
||||||
else if (bluetoothState == BLUETOOTH_STATE_ROLE_SENT && (!strncmp(line, "Central:", 8) || !strncmp(line, "Peripheral:", 11))) {
|
else
|
||||||
bluetoothState = BLUETOOTH_STATE_IDLE;
|
bluetoothWriteString("AT+ROLE0\r\n");
|
||||||
}
|
bluetoothState = BLUETOOTH_STATE_ROLE_SENT;
|
||||||
else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_REQUESTED) {
|
}
|
||||||
bluetoothWriteString("AT+DISC?\r\n");
|
else if (bluetoothState == BLUETOOTH_STATE_ROLE_SENT && (!strncmp(line, "Central:", 8) || !strncmp(line, "Peripheral:", 11))) {
|
||||||
bluetoothState = BLUETOOTH_STATE_DISCOVER_SENT;
|
bluetoothState = BLUETOOTH_STATE_IDLE;
|
||||||
}
|
}
|
||||||
else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_SENT && !strcmp(line, "OK+DISCS")) {
|
else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_REQUESTED) {
|
||||||
bluetoothState = BLUETOOTH_STATE_DISCOVER_START;
|
bluetoothWriteString("AT+DISC?\r\n");
|
||||||
}
|
bluetoothState = BLUETOOTH_STATE_DISCOVER_SENT;
|
||||||
else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_START && !strncmp(line, "OK+DISC:", 8)) {
|
}
|
||||||
TRACE("STOP");
|
else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_SENT && !strcmp(line, "OK+DISCS")) {
|
||||||
strcpy(bluetoothFriend, &line[8]); // TODO quick & dirty
|
bluetoothState = BLUETOOTH_STATE_DISCOVER_START;
|
||||||
}
|
}
|
||||||
else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_START && !strcmp(line, "OK+DISCE")) {
|
else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_START && !strncmp(line, "OK+DISC:", 8)) {
|
||||||
bluetoothState = BLUETOOTH_STATE_DISCOVER_END;
|
strcpy(bluetoothDistantAddr, &line[8]); // TODO quick & dirty
|
||||||
}
|
}
|
||||||
else if (bluetoothState == BLUETOOTH_STATE_BIND_REQUESTED) {
|
else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_START && !strcmp(line, "OK+DISCE")) {
|
||||||
char command[32];
|
bluetoothState = BLUETOOTH_STATE_DISCOVER_END;
|
||||||
strAppend(strAppend(strAppend(command, "AT+CON"), bluetoothFriend), "\r\n");
|
}
|
||||||
bluetoothWriteString(command);
|
else if (bluetoothState == BLUETOOTH_STATE_BIND_REQUESTED) {
|
||||||
bluetoothState = BLUETOOTH_STATE_BIND_SENT;
|
char command[32];
|
||||||
}
|
strAppend(strAppend(strAppend(command, "AT+CON"), bluetoothDistantAddr), "\r\n");
|
||||||
else if ((bluetoothState == BLUETOOTH_STATE_IDLE || bluetoothState == BLUETOOTH_STATE_BIND_SENT) && !strncmp(line, "Connected:", 10)) {
|
bluetoothWriteString(command);
|
||||||
strcpy(bluetoothFriend, &line[10]); // TODO quick & dirty
|
bluetoothState = BLUETOOTH_STATE_CONNECT_SENT;
|
||||||
bluetoothState = BLUETOOTH_STATE_CONNECTED;
|
}
|
||||||
if (g_model.trainerMode == TRAINER_MODE_SLAVE_BLUETOOTH) {
|
else if ((bluetoothState == BLUETOOTH_STATE_IDLE || bluetoothState == BLUETOOTH_STATE_DISCONNECTED || bluetoothState == BLUETOOTH_STATE_CONNECT_SENT) && !strncmp(line, "Connected:", 10)) {
|
||||||
bluetoothWakeupTime += 500; // it seems a 5s delay is needed before sending the 1st frame
|
strcpy(bluetoothDistantAddr, &line[10]); // TODO quick & dirty
|
||||||
}
|
bluetoothState = BLUETOOTH_STATE_CONNECTED;
|
||||||
|
if (g_model.trainerMode == TRAINER_MODE_SLAVE_BLUETOOTH) {
|
||||||
|
bluetoothWakeupTime += 500; // it seems a 5s delay is needed before sending the 1st frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (bluetoothState == BLUETOOTH_STATE_DISCONNECTED && !line) {
|
||||||
|
char command[32];
|
||||||
|
strAppend(strAppend(strAppend(command, "AT+CON"), bluetoothDistantAddr), "\r\n");
|
||||||
|
bluetoothWriteString(command);
|
||||||
|
bluetoothWakeupTime = now + 200; /* 2s */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+10
-5
@@ -25,6 +25,9 @@ enum BluetoothStates {
|
|||||||
BLUETOOTH_WAIT_BAUDRATE_CHANGE,
|
BLUETOOTH_WAIT_BAUDRATE_CHANGE,
|
||||||
#endif
|
#endif
|
||||||
BLUETOOTH_STATE_OFF,
|
BLUETOOTH_STATE_OFF,
|
||||||
|
BLUETOOTH_STATE_FACTORY_BAUDRATE_INIT,
|
||||||
|
BLUETOOTH_STATE_BAUDRATE_SENT,
|
||||||
|
BLUETOOTH_STATE_BAUDRATE_INIT,
|
||||||
BLUETOOTH_STATE_NAME_SENT,
|
BLUETOOTH_STATE_NAME_SENT,
|
||||||
BLUETOOTH_STATE_POWER_SENT,
|
BLUETOOTH_STATE_POWER_SENT,
|
||||||
BLUETOOTH_STATE_ROLE_SENT,
|
BLUETOOTH_STATE_ROLE_SENT,
|
||||||
@@ -34,16 +37,18 @@ enum BluetoothStates {
|
|||||||
BLUETOOTH_STATE_DISCOVER_START,
|
BLUETOOTH_STATE_DISCOVER_START,
|
||||||
BLUETOOTH_STATE_DISCOVER_END,
|
BLUETOOTH_STATE_DISCOVER_END,
|
||||||
BLUETOOTH_STATE_BIND_REQUESTED,
|
BLUETOOTH_STATE_BIND_REQUESTED,
|
||||||
BLUETOOTH_STATE_BIND_SENT,
|
BLUETOOTH_STATE_CONNECT_SENT,
|
||||||
BLUETOOTH_STATE_CONNECTED
|
BLUETOOTH_STATE_CONNECTED,
|
||||||
|
BLUETOOTH_STATE_DISCONNECTED,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LEN_BLUETOOTH_FRIEND 16
|
#define LEN_BLUETOOTH_ADDR 16
|
||||||
|
|
||||||
extern volatile uint8_t bluetoothState;
|
extern volatile uint8_t bluetoothState;
|
||||||
extern char bluetoothFriend[LEN_BLUETOOTH_FRIEND+1];
|
extern char bluetoothLocalAddr[LEN_BLUETOOTH_ADDR+1];
|
||||||
|
extern char bluetoothDistantAddr[LEN_BLUETOOTH_ADDR+1];
|
||||||
|
|
||||||
char * bluetoothReadline();
|
char * bluetoothReadline(bool error_reset=true);
|
||||||
void bluetoothWriteString(const char * command);
|
void bluetoothWriteString(const char * command);
|
||||||
void bluetoothForwardTelemetry(uint8_t data);
|
void bluetoothForwardTelemetry(uint8_t data);
|
||||||
void bluetoothWakeup();
|
void bluetoothWakeup();
|
||||||
|
|||||||
@@ -95,8 +95,11 @@ enum MenuModelSetupItems {
|
|||||||
#if defined(PCBX7)
|
#if defined(PCBX7)
|
||||||
ITEM_MODEL_TRAINER_LABEL,
|
ITEM_MODEL_TRAINER_LABEL,
|
||||||
ITEM_MODEL_TRAINER_MODE,
|
ITEM_MODEL_TRAINER_MODE,
|
||||||
ITEM_MODEL_TRAINER_LINE1,
|
#if defined(BLUETOOTH)
|
||||||
ITEM_MODEL_TRAINER_LINE2,
|
ITEM_MODEL_TRAINER_BLUETOOTH,
|
||||||
|
#endif
|
||||||
|
ITEM_MODEL_TRAINER_CHANNELS,
|
||||||
|
ITEM_MODEL_TRAINER_PARAMS,
|
||||||
#endif
|
#endif
|
||||||
ITEM_MODEL_SETUP_MAX
|
ITEM_MODEL_SETUP_MAX
|
||||||
};
|
};
|
||||||
@@ -153,13 +156,15 @@ enum MenuModelSetupItems {
|
|||||||
|
|
||||||
#if defined(PCBX7)
|
#if defined(PCBX7)
|
||||||
#if defined(BLUETOOTH)
|
#if defined(BLUETOOTH)
|
||||||
#define TRAINER_LINE1_BLUETOOTH_M_ROWS ((bluetoothFriend[0] == 0 || bluetoothState == BLUETOOTH_STATE_CONNECTED) ? (uint8_t)0 : (uint8_t)1)
|
#define TRAINER_BLUETOOTH_M_ROW ((bluetoothDistantAddr[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_BLUETOOTH_S_ROW (bluetoothDistantAddr[0] == '\0' ? HIDDEN_ROW : LABEL())
|
||||||
|
#define TRAINER_BLUETOOTH_ROW (g_model.trainerMode == TRAINER_MODE_MASTER_BLUETOOTH ? TRAINER_BLUETOOTH_M_ROW : (g_model.trainerMode == TRAINER_MODE_SLAVE_BLUETOOTH ? TRAINER_BLUETOOTH_S_ROW : HIDDEN_ROW)),
|
||||||
#else
|
#else
|
||||||
#define TRAINER_LINE1_ROWS (g_model.trainerMode == TRAINER_MODE_SLAVE ? (uint8_t)1 : HIDDEN_ROW)
|
#define TRAINER_BLUETOOTH_ROW
|
||||||
#endif
|
#endif
|
||||||
#define TRAINER_LINE2_ROWS (g_model.trainerMode == TRAINER_MODE_SLAVE ? (uint8_t)2 : HIDDEN_ROW)
|
#define TRAINER_CHANNELS_ROW (IS_SLAVE_TRAINER() ? (uint8_t)1 : HIDDEN_ROW)
|
||||||
#define TRAINER_ROWS LABEL(Trainer), 0, TRAINER_LINE1_ROWS, TRAINER_LINE2_ROWS
|
#define TRAINER_PARAMS_ROW (IS_SLAVE_TRAINER() ? (uint8_t)2 : HIDDEN_ROW)
|
||||||
|
#define TRAINER_ROWS LABEL(Trainer), 0, TRAINER_BLUETOOTH_ROW TRAINER_CHANNELS_ROW, TRAINER_PARAMS_ROW
|
||||||
#else
|
#else
|
||||||
#define TRAINER_ROWS
|
#define TRAINER_ROWS
|
||||||
#endif
|
#endif
|
||||||
@@ -803,22 +808,21 @@ void menuModelSetup(event_t event)
|
|||||||
#if defined(BLUETOOTH)
|
#if defined(BLUETOOTH)
|
||||||
if (checkIncDec_Ret) {
|
if (checkIncDec_Ret) {
|
||||||
bluetoothState = BLUETOOTH_STATE_OFF;
|
bluetoothState = BLUETOOTH_STATE_OFF;
|
||||||
bluetoothFriend[0] = 0;
|
bluetoothDistantAddr[0] = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PCBX7)
|
#if defined(PCBX7) && defined(BLUETOOTH)
|
||||||
case ITEM_MODEL_TRAINER_LINE1:
|
case ITEM_MODEL_TRAINER_BLUETOOTH:
|
||||||
#if defined(BLUETOOTH)
|
|
||||||
if (g_model.trainerMode == TRAINER_MODE_MASTER_BLUETOOTH) {
|
if (g_model.trainerMode == TRAINER_MODE_MASTER_BLUETOOTH) {
|
||||||
if (attr) {
|
if (attr) {
|
||||||
s_editMode = 0;
|
s_editMode = 0;
|
||||||
}
|
}
|
||||||
if (bluetoothFriend[0]) {
|
if (bluetoothDistantAddr[0]) {
|
||||||
lcdDrawText(INDENT_WIDTH, y+1, bluetoothFriend, TINSIZE);
|
lcdDrawText(INDENT_WIDTH, y+1, bluetoothDistantAddr, TINSIZE);
|
||||||
if (bluetoothState != BLUETOOTH_STATE_CONNECTED) {
|
if (bluetoothState != BLUETOOTH_STATE_CONNECTED) {
|
||||||
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, BUTTON("Bind"), menuHorizontalPosition == 0 ? attr : 0);
|
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, BUTTON("Bind"), menuHorizontalPosition == 0 ? attr : 0);
|
||||||
lcdDrawText(MODEL_SETUP_2ND_COLUMN+5*FW, y, BUTTON("Clear"), menuHorizontalPosition == 1 ? attr : 0);
|
lcdDrawText(MODEL_SETUP_2ND_COLUMN+5*FW, y, BUTTON("Clear"), menuHorizontalPosition == 1 ? attr : 0);
|
||||||
@@ -829,7 +833,7 @@ void menuModelSetup(event_t event)
|
|||||||
if (attr && event == EVT_KEY_FIRST(KEY_ENTER)) {
|
if (attr && event == EVT_KEY_FIRST(KEY_ENTER)) {
|
||||||
if (bluetoothState == BLUETOOTH_STATE_CONNECTED || menuHorizontalPosition == 1) {
|
if (bluetoothState == BLUETOOTH_STATE_CONNECTED || menuHorizontalPosition == 1) {
|
||||||
bluetoothState = BLUETOOTH_STATE_OFF;
|
bluetoothState = BLUETOOTH_STATE_OFF;
|
||||||
bluetoothFriend[0] = 0;
|
bluetoothDistantAddr[0] = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bluetoothState = BLUETOOTH_STATE_BIND_REQUESTED;
|
bluetoothState = BLUETOOTH_STATE_BIND_REQUESTED;
|
||||||
@@ -849,11 +853,19 @@ void menuModelSetup(event_t event)
|
|||||||
bluetoothState = BLUETOOTH_STATE_DISCOVER_REQUESTED;
|
bluetoothState = BLUETOOTH_STATE_DISCOVER_REQUESTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
// no break
|
else {
|
||||||
|
if (bluetoothDistantAddr[0])
|
||||||
|
lcdDrawText(INDENT_WIDTH, y+1, bluetoothDistantAddr, TINSIZE);
|
||||||
|
else
|
||||||
|
lcdDrawText(INDENT_WIDTH, y, "---");
|
||||||
|
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, bluetoothState == BLUETOOTH_STATE_CONNECTED ? "Connected" : "!Connected");
|
||||||
|
}
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(PCBX7)
|
||||||
|
case ITEM_MODEL_TRAINER_CHANNELS:
|
||||||
case ITEM_MODEL_INTERNAL_MODULE_CHANNELS:
|
case ITEM_MODEL_INTERNAL_MODULE_CHANNELS:
|
||||||
#endif
|
#endif
|
||||||
#if defined(PCBSKY9X)
|
#if defined(PCBSKY9X)
|
||||||
@@ -889,7 +901,7 @@ void menuModelSetup(event_t event)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PCBX7)
|
#if defined(PCBX7)
|
||||||
case ITEM_MODEL_TRAINER_LINE2:
|
case ITEM_MODEL_TRAINER_PARAMS:
|
||||||
case ITEM_MODEL_INTERNAL_MODULE_BIND:
|
case ITEM_MODEL_INTERNAL_MODULE_BIND:
|
||||||
#endif
|
#endif
|
||||||
#if defined(PCBSKY9X)
|
#if defined(PCBSKY9X)
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ enum MenuRadioHardwareItems {
|
|||||||
ITEM_RADIO_HARDWARE_SH,
|
ITEM_RADIO_HARDWARE_SH,
|
||||||
#if defined(BLUETOOTH)
|
#if defined(BLUETOOTH)
|
||||||
ITEM_RADIO_HARDWARE_BLUETOOTH_MODE,
|
ITEM_RADIO_HARDWARE_BLUETOOTH_MODE,
|
||||||
|
ITEM_RADIO_HARDWARE_BLUETOOTH_LOCAL_ADDR,
|
||||||
|
ITEM_RADIO_HARDWARE_BLUETOOTH_DISTANT_ADDR,
|
||||||
ITEM_RADIO_HARDWARE_BLUETOOTH_NAME,
|
ITEM_RADIO_HARDWARE_BLUETOOTH_NAME,
|
||||||
#endif
|
#endif
|
||||||
ITEM_RADIO_HARDWARE_JITTER_FILTER,
|
ITEM_RADIO_HARDWARE_JITTER_FILTER,
|
||||||
@@ -122,7 +124,7 @@ enum MenuRadioHardwareItems {
|
|||||||
#define POTS_ROWS NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1
|
#define POTS_ROWS 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
|
#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
|
||||||
#if defined(BLUETOOTH)
|
#if defined(BLUETOOTH)
|
||||||
#define BLUETOOTH_ROWS 0, uint8_t(g_eeGeneral.bluetoothMode == BLUETOOTH_OFF ? -1 : 0),
|
#define BLUETOOTH_ROWS 0, uint8_t(g_eeGeneral.bluetoothMode == BLUETOOTH_OFF ? HIDDEN_ROW : -1), uint8_t(g_eeGeneral.bluetoothMode == BLUETOOTH_OFF ? HIDDEN_ROW : -1), uint8_t(g_eeGeneral.bluetoothMode == BLUETOOTH_OFF ? HIDDEN_ROW : 0),
|
||||||
#else
|
#else
|
||||||
#define BLUETOOTH_ROWS
|
#define BLUETOOTH_ROWS
|
||||||
#endif
|
#endif
|
||||||
@@ -214,6 +216,16 @@ void menuRadioHardware(event_t event)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ITEM_RADIO_HARDWARE_BLUETOOTH_LOCAL_ADDR:
|
||||||
|
lcdDrawTextAlignedLeft(y, INDENT "Local addr");
|
||||||
|
lcdDrawText(HW_SETTINGS_COLUMN2, y, bluetoothLocalAddr[0] == '\0' ? "---" : bluetoothLocalAddr);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ITEM_RADIO_HARDWARE_BLUETOOTH_DISTANT_ADDR:
|
||||||
|
lcdDrawTextAlignedLeft(y, INDENT "Dist addr");
|
||||||
|
lcdDrawText(HW_SETTINGS_COLUMN2, y, bluetoothDistantAddr[0] == '\0' ? "---" : bluetoothDistantAddr);
|
||||||
|
break;
|
||||||
|
|
||||||
case ITEM_RADIO_HARDWARE_BLUETOOTH_NAME:
|
case ITEM_RADIO_HARDWARE_BLUETOOTH_NAME:
|
||||||
lcdDrawText(INDENT_WIDTH, y, STR_NAME);
|
lcdDrawText(INDENT_WIDTH, y, STR_NAME);
|
||||||
editName(HW_SETTINGS_COLUMN2, y, g_eeGeneral.bluetoothName, LEN_BLUETOOTH_NAME, event, attr);
|
editName(HW_SETTINGS_COLUMN2, y, g_eeGeneral.bluetoothName, LEN_BLUETOOTH_NAME, event, attr);
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ int getSwitchWarningsCount()
|
|||||||
#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) && defined(DEBUG)
|
#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 ((bluetoothDistantAddr[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)
|
||||||
#else
|
#else
|
||||||
@@ -724,7 +724,7 @@ void menuModelSetup(event_t event)
|
|||||||
#if defined(BLUETOOTH) && defined(DEBUG)
|
#if defined(BLUETOOTH) && defined(DEBUG)
|
||||||
if (attr && checkIncDec_Ret) {
|
if (attr && checkIncDec_Ret) {
|
||||||
bluetoothState = BLUETOOTH_STATE_OFF;
|
bluetoothState = BLUETOOTH_STATE_OFF;
|
||||||
bluetoothFriend[0] = 0;
|
bluetoothDistantAddr[0] = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
@@ -829,8 +829,8 @@ void menuModelSetup(event_t event)
|
|||||||
if (attr) {
|
if (attr) {
|
||||||
s_editMode = 0;
|
s_editMode = 0;
|
||||||
}
|
}
|
||||||
if (bluetoothFriend[0]) {
|
if (bluetoothDistantAddr[0]) {
|
||||||
lcdDrawText(INDENT_WIDTH, y+1, bluetoothFriend, TINSIZE);
|
lcdDrawText(INDENT_WIDTH, y+1, bluetoothDistantAddr, TINSIZE);
|
||||||
if (bluetoothState != BLUETOOTH_STATE_CONNECTED) {
|
if (bluetoothState != BLUETOOTH_STATE_CONNECTED) {
|
||||||
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, BUTTON("Bind"), menuHorizontalPosition == 0 ? attr : 0);
|
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, BUTTON("Bind"), menuHorizontalPosition == 0 ? attr : 0);
|
||||||
lcdDrawText(MODEL_SETUP_2ND_COLUMN+5*FW, y, BUTTON("Clear"), menuHorizontalPosition == 1 ? attr : 0);
|
lcdDrawText(MODEL_SETUP_2ND_COLUMN+5*FW, y, BUTTON("Clear"), menuHorizontalPosition == 1 ? attr : 0);
|
||||||
@@ -841,7 +841,7 @@ void menuModelSetup(event_t event)
|
|||||||
if (attr && event == EVT_KEY_FIRST(KEY_ENTER)) {
|
if (attr && event == EVT_KEY_FIRST(KEY_ENTER)) {
|
||||||
if (bluetoothState == BLUETOOTH_STATE_CONNECTED || menuHorizontalPosition == 1) {
|
if (bluetoothState == BLUETOOTH_STATE_CONNECTED || menuHorizontalPosition == 1) {
|
||||||
bluetoothState = BLUETOOTH_STATE_OFF;
|
bluetoothState = BLUETOOTH_STATE_OFF;
|
||||||
bluetoothFriend[0] = 0;
|
bluetoothDistantAddr[0] = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bluetoothState = BLUETOOTH_STATE_BIND_REQUESTED;
|
bluetoothState = BLUETOOTH_STATE_BIND_REQUESTED;
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ int getSwitchWarningsCount()
|
|||||||
#define POT_WARN_ITEMS() ((g_model.potsWarnMode) ? uint8_t(NAVIGATION_LINE_BY_LINE|(NUM_POTS-1)) : (uint8_t)0)
|
#define POT_WARN_ITEMS() ((g_model.potsWarnMode) ? uint8_t(NAVIGATION_LINE_BY_LINE|(NUM_POTS-1)) : (uint8_t)0)
|
||||||
#define SLIDER_WARN_ITEMS() ((g_model.potsWarnMode) ? uint8_t(NAVIGATION_LINE_BY_LINE|(NUM_SLIDERS-1)) : (uint8_t)0)
|
#define SLIDER_WARN_ITEMS() ((g_model.potsWarnMode) ? uint8_t(NAVIGATION_LINE_BY_LINE|(NUM_SLIDERS-1)) : (uint8_t)0)
|
||||||
|
|
||||||
#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 ((bluetoothDistantAddr[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)
|
||||||
|
|
||||||
@@ -649,7 +649,7 @@ bool menuModelSetup(event_t event)
|
|||||||
g_model.trainerMode = editChoice(MODEL_SETUP_2ND_COLUMN, y, STR_VTRAINERMODES, g_model.trainerMode, 0, TRAINER_MODE_MAX(), attr, event);
|
g_model.trainerMode = editChoice(MODEL_SETUP_2ND_COLUMN, y, STR_VTRAINERMODES, g_model.trainerMode, 0, TRAINER_MODE_MAX(), attr, event);
|
||||||
if (attr && checkIncDec_Ret) {
|
if (attr && checkIncDec_Ret) {
|
||||||
bluetoothState = BLUETOOTH_STATE_OFF;
|
bluetoothState = BLUETOOTH_STATE_OFF;
|
||||||
bluetoothFriend[0] = 0;
|
bluetoothDistantAddr[0] = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -750,8 +750,8 @@ bool menuModelSetup(event_t event)
|
|||||||
if (attr) {
|
if (attr) {
|
||||||
s_editMode = 0;
|
s_editMode = 0;
|
||||||
}
|
}
|
||||||
if (bluetoothFriend[0]) {
|
if (bluetoothDistantAddr[0]) {
|
||||||
lcdDrawText(MENUS_MARGIN_LEFT + INDENT_WIDTH, y, bluetoothFriend);
|
lcdDrawText(MENUS_MARGIN_LEFT + INDENT_WIDTH, y, bluetoothDistantAddr);
|
||||||
if (bluetoothState != BLUETOOTH_STATE_CONNECTED) {
|
if (bluetoothState != BLUETOOTH_STATE_CONNECTED) {
|
||||||
drawButton(MODEL_SETUP_2ND_COLUMN, y, "Bind", menuHorizontalPosition == 0 ? attr : 0);
|
drawButton(MODEL_SETUP_2ND_COLUMN, y, "Bind", menuHorizontalPosition == 0 ? attr : 0);
|
||||||
drawButton(MODEL_SETUP_2ND_COLUMN+60, y, "Clear", menuHorizontalPosition == 1 ? attr : 0);
|
drawButton(MODEL_SETUP_2ND_COLUMN+60, y, "Clear", menuHorizontalPosition == 1 ? attr : 0);
|
||||||
@@ -762,7 +762,7 @@ bool menuModelSetup(event_t event)
|
|||||||
if (attr && event == EVT_KEY_FIRST(KEY_ENTER)) {
|
if (attr && event == EVT_KEY_FIRST(KEY_ENTER)) {
|
||||||
if (bluetoothState == BLUETOOTH_STATE_CONNECTED || menuHorizontalPosition == 1) {
|
if (bluetoothState == BLUETOOTH_STATE_CONNECTED || menuHorizontalPosition == 1) {
|
||||||
bluetoothState = BLUETOOTH_STATE_OFF;
|
bluetoothState = BLUETOOTH_STATE_OFF;
|
||||||
bluetoothFriend[0] = 0;
|
bluetoothDistantAddr[0] = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bluetoothState = BLUETOOTH_STATE_BIND_REQUESTED;
|
bluetoothState = BLUETOOTH_STATE_BIND_REQUESTED;
|
||||||
|
|||||||
@@ -587,6 +587,10 @@ bool isTrainerModeAvailable(int mode)
|
|||||||
{
|
{
|
||||||
if (mode == TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE || mode == TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE || mode == TRAINER_MODE_MASTER_BATTERY_COMPARTMENT)
|
if (mode == TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE || mode == TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE || mode == TRAINER_MODE_MASTER_BATTERY_COMPARTMENT)
|
||||||
return false;
|
return false;
|
||||||
|
#if defined(BLUETOOTH)
|
||||||
|
else if (g_eeGeneral.bluetoothMode != BLUETOOTH_TRAINER && (mode == TRAINER_MODE_MASTER_BLUETOOTH || mode == TRAINER_MODE_SLAVE_BLUETOOTH))
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -227,11 +227,14 @@
|
|||||||
#if defined(BLUETOOTH)
|
#if defined(BLUETOOTH)
|
||||||
#if defined(X9E)
|
#if defined(X9E)
|
||||||
#define IS_BLUETOOTH_TRAINER() (g_model.trainerMode == TRAINER_MODE_SLAVE_BLUETOOTH)
|
#define IS_BLUETOOTH_TRAINER() (g_model.trainerMode == TRAINER_MODE_SLAVE_BLUETOOTH)
|
||||||
|
#define IS_SLAVE_TRAINER() (g_model.trainerMode == TRAINER_MODE_SLAVE)
|
||||||
#else
|
#else
|
||||||
#define IS_BLUETOOTH_TRAINER() (g_model.trainerMode == TRAINER_MODE_MASTER_BLUETOOTH || g_model.trainerMode == TRAINER_MODE_SLAVE_BLUETOOTH)
|
#define IS_BLUETOOTH_TRAINER() (g_model.trainerMode == TRAINER_MODE_MASTER_BLUETOOTH || g_model.trainerMode == TRAINER_MODE_SLAVE_BLUETOOTH)
|
||||||
|
#define IS_SLAVE_TRAINER() (g_model.trainerMode == TRAINER_MODE_SLAVE || g_model.trainerMode == TRAINER_MODE_SLAVE_BLUETOOTH)
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#define IS_BLUETOOTH_TRAINER() false
|
#define IS_BLUETOOTH_TRAINER() false
|
||||||
|
#define IS_SLAVE_TRAINER() (g_model.trainerMode == TRAINER_MODE_SLAVE)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CPUARM)
|
#if defined(CPUARM)
|
||||||
|
|||||||
@@ -86,6 +86,10 @@ void bluetoothInit(uint32_t baudrate)
|
|||||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||||
NVIC_Init(&NVIC_InitStructure);
|
NVIC_Init(&NVIC_InitStructure);
|
||||||
|
|
||||||
|
btRxFifo.clear();
|
||||||
|
btTxFifo.clear();
|
||||||
|
bluetoothWriteState = BLUETOOTH_WRITE_IDLE;
|
||||||
|
|
||||||
GPIO_ResetBits(BT_EN_GPIO, BT_EN_GPIO_PIN); // open bluetooth
|
GPIO_ResetBits(BT_EN_GPIO, BT_EN_GPIO_PIN); // open bluetooth
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,3 +141,8 @@ void bluetoothWriteWakeup(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t bluetoothIsWriting(void)
|
||||||
|
{
|
||||||
|
return bluetoothWriteState != BLUETOOTH_WRITE_IDLE;
|
||||||
|
}
|
||||||
|
|||||||
@@ -526,9 +526,11 @@ void serial2Stop(void);
|
|||||||
int sbusGetByte(uint8_t * byte);
|
int sbusGetByte(uint8_t * byte);
|
||||||
|
|
||||||
// BT driver
|
// BT driver
|
||||||
|
#define BLUETOOTH_FACTORY_BAUDRATE 57600
|
||||||
#define BLUETOOTH_DEFAULT_BAUDRATE 115200
|
#define BLUETOOTH_DEFAULT_BAUDRATE 115200
|
||||||
void bluetoothInit(uint32_t baudrate);
|
void bluetoothInit(uint32_t baudrate);
|
||||||
void bluetoothWriteWakeup(void);
|
void bluetoothWriteWakeup(void);
|
||||||
|
uint8_t bluetoothIsWriting(void);
|
||||||
void bluetoothDone(void);
|
void bluetoothDone(void);
|
||||||
|
|
||||||
extern uint8_t currentTrainerMode;
|
extern uint8_t currentTrainerMode;
|
||||||
|
|||||||
@@ -549,9 +549,14 @@ void serial2Stop(void);
|
|||||||
|
|
||||||
// BT driver
|
// BT driver
|
||||||
#define BLUETOOTH_DEFAULT_BAUDRATE 115200
|
#define BLUETOOTH_DEFAULT_BAUDRATE 115200
|
||||||
|
#if defined(PCBX9E)
|
||||||
#define BLUETOOTH_FACTORY_BAUDRATE 9600
|
#define BLUETOOTH_FACTORY_BAUDRATE 9600
|
||||||
|
#else
|
||||||
|
#define BLUETOOTH_FACTORY_BAUDRATE 57600
|
||||||
|
#endif
|
||||||
void bluetoothInit(uint32_t baudrate);
|
void bluetoothInit(uint32_t baudrate);
|
||||||
void bluetoothWriteWakeup(void);
|
void bluetoothWriteWakeup(void);
|
||||||
|
uint8_t bluetoothIsWriting(void);
|
||||||
void bluetoothDone(void);
|
void bluetoothDone(void);
|
||||||
|
|
||||||
// LED driver
|
// LED driver
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ NOINLINE void processFrskyTelemetryData(uint8_t data)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(BLUETOOTH)
|
#if defined(BLUETOOTH)
|
||||||
if (g_eeGeneral.bluetoothMode == BLUETOOTH_TELEMETRY) {
|
if (g_eeGeneral.bluetoothMode == BLUETOOTH_TELEMETRY && bluetoothState == BLUETOOTH_STATE_CONNECTED) {
|
||||||
bluetoothForwardTelemetry(data);
|
bluetoothForwardTelemetry(data);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user