Bluetooth cosmetics, traces removed etc.

This commit is contained in:
Bertrand Songis
2019-02-19 13:59:06 +01:00
parent f9a851c62e
commit ff5928f778
2 changed files with 2 additions and 40 deletions
+1 -36
View File
@@ -346,67 +346,44 @@ void bluetoothWakeup()
if (now < bluetoothWakeupTime) if (now < bluetoothWakeupTime)
return; return;
if (!usbPlugged()) {
bluetoothWakeupTime += 1000; // 10s
return;
}
bluetoothWakeupTime = now + 5; /* 50ms default */ bluetoothWakeupTime = now + 5; /* 50ms default */
static uint8_t oldbluetooth = 255;
if (oldbluetooth != bluetoothState) {
TRACE("State %d", bluetoothState);
oldbluetooth = bluetoothState;
}
if (g_eeGeneral.bluetoothMode == BLUETOOTH_OFF || (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER && !IS_BLUETOOTH_TRAINER())) { if (g_eeGeneral.bluetoothMode == BLUETOOTH_OFF || (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER && !IS_BLUETOOTH_TRAINER())) {
//TRACE_NOCRLF("A");
if (bluetoothState != BLUETOOTH_STATE_OFF) { if (bluetoothState != BLUETOOTH_STATE_OFF) {
//TRACE_NOCRLF("Z");
bluetoothDone(); bluetoothDone();
bluetoothState = BLUETOOTH_STATE_OFF; bluetoothState = BLUETOOTH_STATE_OFF;
} }
bluetoothWakeupTime = now + 10; /* 100ms */ bluetoothWakeupTime = now + 10; /* 100ms */
} }
else if (bluetoothState == BLUETOOTH_STATE_OFF) { else if (bluetoothState == BLUETOOTH_STATE_OFF) {
//TRACE_NOCRLF("B");
bluetoothInit(BLUETOOTH_FACTORY_BAUDRATE); bluetoothInit(BLUETOOTH_FACTORY_BAUDRATE);
bluetoothState = BLUETOOTH_STATE_FACTORY_BAUDRATE_INIT; bluetoothState = BLUETOOTH_STATE_FACTORY_BAUDRATE_INIT;
} }
if (bluetoothState != BLUETOOTH_STATE_OFF) { if (bluetoothState != BLUETOOTH_STATE_OFF) {
//TRACE_NOCRLF("C");
bluetoothWriteWakeup(); bluetoothWriteWakeup();
if (bluetoothIsWriting()) { if (bluetoothIsWriting()) {
//TRACE_NOCRLF("D");
return; return;
} }
} }
if (bluetoothState == BLUETOOTH_STATE_FACTORY_BAUDRATE_INIT) { if (bluetoothState == BLUETOOTH_STATE_FACTORY_BAUDRATE_INIT) {
//TRACE_NOCRLF("F");
bluetoothWriteString("AT+BAUD4\r\n"); bluetoothWriteString("AT+BAUD4\r\n");
bluetoothState = BLUETOOTH_STATE_BAUDRATE_SENT; bluetoothState = BLUETOOTH_STATE_BAUDRATE_SENT;
bluetoothWakeupTime = now + 10; /* 100ms */ bluetoothWakeupTime = now + 10; /* 100ms */
} }
else if (bluetoothState == BLUETOOTH_STATE_BAUDRATE_SENT) { else if (bluetoothState == BLUETOOTH_STATE_BAUDRATE_SENT) {
//TRACE_NOCRLF("G");
bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE); bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE);
bluetoothState = BLUETOOTH_STATE_BAUDRATE_INIT; bluetoothState = BLUETOOTH_STATE_BAUDRATE_INIT;
bluetoothReadline(false); bluetoothReadline(false);
bluetoothWakeupTime = now + 10; /* 100ms */ bluetoothWakeupTime = now + 10; /* 100ms */
} }
else if (bluetoothState == BLUETOOTH_STATE_CONNECTED) { else if (bluetoothState == BLUETOOTH_STATE_CONNECTED) {
//TRACE_NOCRLF("H");
if (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER && g_model.trainerData.mode == TRAINER_MODE_MASTER_BLUETOOTH) { if (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER && g_model.trainerData.mode == TRAINER_MODE_MASTER_BLUETOOTH) {
//TRACE_NOCRLF("I");
bluetoothReceiveTrainer(); bluetoothReceiveTrainer();
} }
else { else {
//TRACE_NOCRLF("J");
if (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER && g_model.trainerData.mode == TRAINER_MODE_SLAVE_BLUETOOTH) { if (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER && g_model.trainerData.mode == TRAINER_MODE_SLAVE_BLUETOOTH) {
TRACE_NOCRLF("S");
bluetoothSendTrainer(); bluetoothSendTrainer();
bluetoothWakeupTime = now + 2; /* 20ms */ bluetoothWakeupTime = now + 2; /* 20ms */
} }
@@ -414,13 +391,11 @@ void bluetoothWakeup()
} }
} }
else { else {
//TRACE_NOCRLF("L");
char * line = bluetoothReadline(); char * line = bluetoothReadline();
if (line) { if (line) {
TRACE("BT %s", line); TRACE("BT %s", line);
} }
if (bluetoothState == BLUETOOTH_STATE_BAUDRATE_INIT) { if (bluetoothState == BLUETOOTH_STATE_BAUDRATE_INIT) {
//TRACE_NOCRLF("M");
char command[32]; char command[32];
char * cur = strAppend(command, BLUETOOTH_COMMAND_NAME); char * cur = strAppend(command, BLUETOOTH_COMMAND_NAME);
uint8_t len = ZLEN(g_eeGeneral.bluetoothName); uint8_t len = ZLEN(g_eeGeneral.bluetoothName);
@@ -433,7 +408,7 @@ void bluetoothWakeup()
#if defined(PCBHORUS) #if defined(PCBHORUS)
cur = strAppend(cur, "Horus"); cur = strAppend(cur, "Horus");
#else #else
cur = strAppend(cur, "taranis"); cur = strAppend(cur, "taranis"); // TODO capital letter once allowed by BT module
#endif #endif
} }
strAppend(cur, "\r\n"); strAppend(cur, "\r\n");
@@ -441,12 +416,10 @@ void bluetoothWakeup()
bluetoothState = BLUETOOTH_STATE_NAME_SENT; bluetoothState = BLUETOOTH_STATE_NAME_SENT;
} }
else if (bluetoothState == BLUETOOTH_STATE_NAME_SENT && (!strncmp(line, "OK+", 3) || !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))) {
//TRACE_NOCRLF("N");
bluetoothWriteString("AT+TXPW\r\n"); bluetoothWriteString("AT+TXPW\r\n");
bluetoothState = BLUETOOTH_STATE_POWER_SENT; bluetoothState = BLUETOOTH_STATE_POWER_SENT;
} }
else if (bluetoothState == BLUETOOTH_STATE_POWER_SENT && (!strncmp(line, "Central:", 8) || !strncmp(line, "Peripheral:", 11))) { else if (bluetoothState == BLUETOOTH_STATE_POWER_SENT && (!strncmp(line, "Central:", 8) || !strncmp(line, "Peripheral:", 11))) {
//TRACE_NOCRLF("O");
if (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER && g_model.trainerData.mode == TRAINER_MODE_MASTER_BLUETOOTH) if (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER && g_model.trainerData.mode == TRAINER_MODE_MASTER_BLUETOOTH)
bluetoothWriteString("AT+ROLE1\r\n"); bluetoothWriteString("AT+ROLE1\r\n");
else else
@@ -454,35 +427,28 @@ void bluetoothWakeup()
bluetoothState = BLUETOOTH_STATE_ROLE_SENT; bluetoothState = BLUETOOTH_STATE_ROLE_SENT;
} }
else if (bluetoothState == BLUETOOTH_STATE_ROLE_SENT && (!strncmp(line, "Central:", 8) || !strncmp(line, "Peripheral:", 11))) { else if (bluetoothState == BLUETOOTH_STATE_ROLE_SENT && (!strncmp(line, "Central:", 8) || !strncmp(line, "Peripheral:", 11))) {
//TRACE_NOCRLF("P");
bluetoothState = BLUETOOTH_STATE_IDLE; bluetoothState = BLUETOOTH_STATE_IDLE;
} }
else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_REQUESTED) { else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_REQUESTED) {
//TRACE_NOCRLF("Q");
bluetoothWriteString("AT+DISC?\r\n"); bluetoothWriteString("AT+DISC?\r\n");
bluetoothState = BLUETOOTH_STATE_DISCOVER_SENT; bluetoothState = BLUETOOTH_STATE_DISCOVER_SENT;
} }
else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_SENT && !strcmp(line, "OK+DISCS")) { else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_SENT && !strcmp(line, "OK+DISCS")) {
//TRACE_NOCRLF("R");
bluetoothState = BLUETOOTH_STATE_DISCOVER_START; bluetoothState = BLUETOOTH_STATE_DISCOVER_START;
} }
else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_START && !strncmp(line, "OK+DISC:", 8)) { else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_START && !strncmp(line, "OK+DISC:", 8)) {
//TRACE_NOCRLF("S");
strcpy(bluetoothDistantAddr, &line[8]); // TODO quick & dirty strcpy(bluetoothDistantAddr, &line[8]); // TODO quick & dirty
} }
else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_START && !strcmp(line, "OK+DISCE")) { else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_START && !strcmp(line, "OK+DISCE")) {
//TRACE_NOCRLF("T");
bluetoothState = BLUETOOTH_STATE_DISCOVER_END; bluetoothState = BLUETOOTH_STATE_DISCOVER_END;
} }
else if (bluetoothState == BLUETOOTH_STATE_BIND_REQUESTED) { else if (bluetoothState == BLUETOOTH_STATE_BIND_REQUESTED) {
//TRACE_NOCRLF("U");
char command[32]; char command[32];
strAppend(strAppend(strAppend(command, "AT+CON"), bluetoothDistantAddr), "\r\n"); strAppend(strAppend(strAppend(command, "AT+CON"), bluetoothDistantAddr), "\r\n");
bluetoothWriteString(command); bluetoothWriteString(command);
bluetoothState = BLUETOOTH_STATE_CONNECT_SENT; bluetoothState = BLUETOOTH_STATE_CONNECT_SENT;
} }
else if ((bluetoothState == BLUETOOTH_STATE_IDLE || bluetoothState == BLUETOOTH_STATE_DISCONNECTED || bluetoothState == BLUETOOTH_STATE_CONNECT_SENT) && !strncmp(line, "Connected:", 10)) { else if ((bluetoothState == BLUETOOTH_STATE_IDLE || bluetoothState == BLUETOOTH_STATE_DISCONNECTED || bluetoothState == BLUETOOTH_STATE_CONNECT_SENT) && !strncmp(line, "Connected:", 10)) {
//TRACE_NOCRLF("V");
strcpy(bluetoothDistantAddr, &line[10]); // TODO quick & dirty strcpy(bluetoothDistantAddr, &line[10]); // TODO quick & dirty
bluetoothState = BLUETOOTH_STATE_CONNECTED; bluetoothState = BLUETOOTH_STATE_CONNECTED;
if (g_model.trainerData.mode == TRAINER_MODE_SLAVE_BLUETOOTH) { if (g_model.trainerData.mode == TRAINER_MODE_SLAVE_BLUETOOTH) {
@@ -490,7 +456,6 @@ void bluetoothWakeup()
} }
} }
else if (bluetoothState == BLUETOOTH_STATE_DISCONNECTED && !line) { else if (bluetoothState == BLUETOOTH_STATE_DISCONNECTED && !line) {
//TRACE_NOCRLF("W");
char command[32]; char command[32];
strAppend(strAppend(strAppend(command, "AT+CON"), bluetoothDistantAddr), "\r\n"); strAppend(strAppend(strAppend(command, "AT+CON"), bluetoothDistantAddr), "\r\n");
bluetoothWriteString(command); bluetoothWriteString(command);
-3
View File
@@ -1218,9 +1218,6 @@ void menuModelSetup(event_t event)
} }
break; break;
DEF
break;
case ITEM_MODEL_INTERNAL_MODULE_PXX2_RECEIVER_1_PINMAP: case ITEM_MODEL_INTERNAL_MODULE_PXX2_RECEIVER_1_PINMAP:
case ITEM_MODEL_INTERNAL_MODULE_PXX2_RECEIVER_2_PINMAP: case ITEM_MODEL_INTERNAL_MODULE_PXX2_RECEIVER_2_PINMAP:
case ITEM_MODEL_EXTERNAL_MODULE_PXX2_RECEIVER_1_PINMAP: case ITEM_MODEL_EXTERNAL_MODULE_PXX2_RECEIVER_1_PINMAP: