[Taranis X9E] Bluetooth can be stopped and device name is now
configurable
This commit is contained in:
@@ -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) {
|
||||
|
||||
+14
-4
@@ -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 \
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<len; i++) {
|
||||
btTxFifo.push(idx2char(g_eeGeneral.bluetoothName[i]));
|
||||
}
|
||||
bluetoothState = BLUETOOTH_WAIT_TTM;
|
||||
waitEnd = get_tmr10ms() + 25; // 250ms
|
||||
}
|
||||
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(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
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user