1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-26 01:35:21 +03:00

Bluetooth popup menu added. Works far better now.

This commit is contained in:
Bertrand Songis 2019-04-18 18:04:24 +02:00
parent 5294b58ca8
commit a721e8d7be
5 changed files with 69 additions and 52 deletions

View file

@ -34,7 +34,7 @@
#define BLUETOOTH_LINE_LENGTH 32
extern Fifo<uint8_t, 64> btTxFifo;
extern Fifo<uint8_t, 64> btRxFifo;
extern Fifo<uint8_t, 128> btRxFifo;
volatile uint8_t bluetoothState;
char bluetoothLocalAddr[LEN_BLUETOOTH_ADDR+1];
@ -442,11 +442,14 @@ void bluetoothWakeup()
bluetoothState = BLUETOOTH_STATE_DISCOVER_START;
}
else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_START && !strncmp(line, "OK+DISC:", 8)) {
strcpy(bluetoothDistantAddr, &line[8]); // TODO quick & dirty
if (strlen(line) < 8 + LEN_BLUETOOTH_ADDR && reusableBuffer.moduleSetup.bt.devicesCount < MAX_BLUETOOTH_DISTANT_ADDR) {
strncpy(reusableBuffer.moduleSetup.bt.devices[reusableBuffer.moduleSetup.bt.devicesCount], &line[8], LEN_BLUETOOTH_ADDR);
++reusableBuffer.moduleSetup.bt.devicesCount;
}
else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_START && !strcmp(line, "OK+DISCE")) {
}
/* else if (bluetoothState == BLUETOOTH_STATE_DISCOVER_START && !strcmp(line, "OK+DISCE")) {
bluetoothState = BLUETOOTH_STATE_DISCOVER_END;
}
} */
else if (bluetoothState == BLUETOOTH_STATE_BIND_REQUESTED) {
char command[32];
strAppend(strAppend(strAppend(command, "AT+CON"), bluetoothDistantAddr), "\r\n");

View file

@ -43,6 +43,7 @@ enum BluetoothStates {
};
#define LEN_BLUETOOTH_ADDR 16
#define MAX_BLUETOOTH_DISTANT_ADDR 6
extern volatile uint8_t bluetoothState;
extern char bluetoothLocalAddr[LEN_BLUETOOTH_ADDR+1];

View file

@ -446,7 +446,18 @@ void startRegisterDialog(uint8_t module)
POPUP_INPUT("", runPopupRegister);
}
void onBluetoothConnectMenu(const char * result)
{
if (result != STR_EXIT) {
uint8_t index = (result - reusableBuffer.moduleSetup.bt.devices[0]) / sizeof(reusableBuffer.moduleSetup.bt.devices[0]);
strncpy(bluetoothDistantAddr, reusableBuffer.moduleSetup.bt.devices[index], LEN_BLUETOOTH_ADDR);
bluetoothState = BLUETOOTH_STATE_BIND_REQUESTED;
}
else {
reusableBuffer.moduleSetup.bt.devicesCount = 0;
bluetoothState = BLUETOOTH_STATE_DISCOVER_END;
}
}
void menuModelSetup(event_t event)
{
@ -1128,21 +1139,10 @@ void menuModelSetup(event_t event)
}
if (bluetoothDistantAddr[0]) {
lcdDrawText(INDENT_WIDTH, y+1, bluetoothDistantAddr, TINSIZE);
if (bluetoothState != BLUETOOTH_STATE_CONNECTED) {
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);
}
else {
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, BUTTON("Clear"), attr);
}
if (attr && event == EVT_KEY_FIRST(KEY_ENTER)) {
if (bluetoothState == BLUETOOTH_STATE_CONNECTED || menuHorizontalPosition == 1) {
bluetoothState = BLUETOOTH_STATE_OFF;
bluetoothDistantAddr[0] = 0;
}
else {
bluetoothState = BLUETOOTH_STATE_BIND_REQUESTED;
}
memclear(bluetoothDistantAddr, sizeof(bluetoothDistantAddr));
}
}
else {
@ -1152,12 +1152,24 @@ void menuModelSetup(event_t event)
else
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, BUTTON("Discover"), attr);
if (attr && event == EVT_KEY_FIRST(KEY_ENTER)) {
if (bluetoothState < BLUETOOTH_STATE_IDLE)
if (bluetoothState < BLUETOOTH_STATE_IDLE) {
bluetoothState = BLUETOOTH_STATE_OFF;
else
}
else {
reusableBuffer.moduleSetup.bt.devicesCount = 0;
bluetoothState = BLUETOOTH_STATE_DISCOVER_REQUESTED;
}
}
if (bluetoothState == BLUETOOTH_STATE_DISCOVER_START && reusableBuffer.moduleSetup.bt.devicesCount > 0) {
popupMenuItemsCount = min<uint8_t>(reusableBuffer.moduleSetup.bt.devicesCount, 6);
for (uint8_t i=0; i<popupMenuItemsCount; i++) {
popupMenuItems[i] = reusableBuffer.moduleSetup.bt.devices[i];
}
popupMenuTitle = "Select device...";
POPUP_MENU_START(onBluetoothConnectMenu);
}
}
}
else {
if (bluetoothDistantAddr[0])

View file

@ -1105,6 +1105,10 @@ void opentxResume();
#define SD_SCREEN_FILE_LENGTH 64
#endif
#if defined(BLUETOOTH)
#include "bluetooth.h"
#endif
union ReusableBuffer
{
// ARM 334 bytes
@ -1121,11 +1125,9 @@ union ReusableBuffer
#endif
} modelsel;
// 65 bytes
struct {
char msg[64];
uint8_t r9mPower;
union {
struct {
union {
uint8_t registerStep;
@ -1149,7 +1151,10 @@ union ReusableBuffer
};
uint8_t resetReceiverFlags;
} pxx2;
};
struct {
char devices[MAX_BLUETOOTH_DISTANT_ADDR][LEN_BLUETOOTH_ADDR+1];
uint8_t devicesCount;
} bt;
} moduleSetup;
// 103 bytes
@ -1381,10 +1386,6 @@ extern JitterMeter<uint16_t> avgJitter[NUM_ANALOGS];
#include "gps.h"
#endif
#if defined(BLUETOOTH)
#include "bluetooth.h"
#endif
#if defined(JACK_DETECT_GPIO)
enum JackMode {
JACK_UNSELECTED_MODE,

View file

@ -21,7 +21,7 @@
#include "opentx.h"
Fifo<uint8_t, 64> btTxFifo;
Fifo<uint8_t, 64> btRxFifo;
Fifo<uint8_t, 128> btRxFifo;
#if defined(PCBX7) || defined(PCBXLITE)
volatile uint8_t btChipPresent = 0;