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:
parent
5294b58ca8
commit
a721e8d7be
5 changed files with 69 additions and 52 deletions
|
@ -34,7 +34,7 @@
|
||||||
#define BLUETOOTH_LINE_LENGTH 32
|
#define BLUETOOTH_LINE_LENGTH 32
|
||||||
|
|
||||||
extern Fifo<uint8_t, 64> btTxFifo;
|
extern Fifo<uint8_t, 64> btTxFifo;
|
||||||
extern Fifo<uint8_t, 64> btRxFifo;
|
extern Fifo<uint8_t, 128> btRxFifo;
|
||||||
|
|
||||||
volatile uint8_t bluetoothState;
|
volatile uint8_t bluetoothState;
|
||||||
char bluetoothLocalAddr[LEN_BLUETOOTH_ADDR+1];
|
char bluetoothLocalAddr[LEN_BLUETOOTH_ADDR+1];
|
||||||
|
@ -442,11 +442,14 @@ void bluetoothWakeup()
|
||||||
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)) {
|
||||||
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;
|
bluetoothState = BLUETOOTH_STATE_DISCOVER_END;
|
||||||
}
|
} */
|
||||||
else if (bluetoothState == BLUETOOTH_STATE_BIND_REQUESTED) {
|
else if (bluetoothState == BLUETOOTH_STATE_BIND_REQUESTED) {
|
||||||
char command[32];
|
char command[32];
|
||||||
strAppend(strAppend(strAppend(command, "AT+CON"), bluetoothDistantAddr), "\r\n");
|
strAppend(strAppend(strAppend(command, "AT+CON"), bluetoothDistantAddr), "\r\n");
|
||||||
|
|
|
@ -43,6 +43,7 @@ enum BluetoothStates {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LEN_BLUETOOTH_ADDR 16
|
#define LEN_BLUETOOTH_ADDR 16
|
||||||
|
#define MAX_BLUETOOTH_DISTANT_ADDR 6
|
||||||
|
|
||||||
extern volatile uint8_t bluetoothState;
|
extern volatile uint8_t bluetoothState;
|
||||||
extern char bluetoothLocalAddr[LEN_BLUETOOTH_ADDR+1];
|
extern char bluetoothLocalAddr[LEN_BLUETOOTH_ADDR+1];
|
||||||
|
|
|
@ -446,7 +446,18 @@ void startRegisterDialog(uint8_t module)
|
||||||
POPUP_INPUT("", runPopupRegister);
|
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)
|
void menuModelSetup(event_t event)
|
||||||
{
|
{
|
||||||
|
@ -1128,21 +1139,10 @@ void menuModelSetup(event_t event)
|
||||||
}
|
}
|
||||||
if (bluetoothDistantAddr[0]) {
|
if (bluetoothDistantAddr[0]) {
|
||||||
lcdDrawText(INDENT_WIDTH, y+1, bluetoothDistantAddr, TINSIZE);
|
lcdDrawText(INDENT_WIDTH, y+1, bluetoothDistantAddr, TINSIZE);
|
||||||
if (bluetoothState != BLUETOOTH_STATE_CONNECTED) {
|
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, BUTTON("Clear"), attr);
|
||||||
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 (attr && event == EVT_KEY_FIRST(KEY_ENTER)) {
|
||||||
if (bluetoothState == BLUETOOTH_STATE_CONNECTED || menuHorizontalPosition == 1) {
|
bluetoothState = BLUETOOTH_STATE_OFF;
|
||||||
bluetoothState = BLUETOOTH_STATE_OFF;
|
memclear(bluetoothDistantAddr, sizeof(bluetoothDistantAddr));
|
||||||
bluetoothDistantAddr[0] = 0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
bluetoothState = BLUETOOTH_STATE_BIND_REQUESTED;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1152,10 +1152,22 @@ void menuModelSetup(event_t event)
|
||||||
else
|
else
|
||||||
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, BUTTON("Discover"), attr);
|
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, BUTTON("Discover"), attr);
|
||||||
if (attr && event == EVT_KEY_FIRST(KEY_ENTER)) {
|
if (attr && event == EVT_KEY_FIRST(KEY_ENTER)) {
|
||||||
if (bluetoothState < BLUETOOTH_STATE_IDLE)
|
if (bluetoothState < BLUETOOTH_STATE_IDLE) {
|
||||||
bluetoothState = BLUETOOTH_STATE_OFF;
|
bluetoothState = BLUETOOTH_STATE_OFF;
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
|
reusableBuffer.moduleSetup.bt.devicesCount = 0;
|
||||||
bluetoothState = BLUETOOTH_STATE_DISCOVER_REQUESTED;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1105,6 +1105,10 @@ void opentxResume();
|
||||||
#define SD_SCREEN_FILE_LENGTH 64
|
#define SD_SCREEN_FILE_LENGTH 64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(BLUETOOTH)
|
||||||
|
#include "bluetooth.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
union ReusableBuffer
|
union ReusableBuffer
|
||||||
{
|
{
|
||||||
// ARM 334 bytes
|
// ARM 334 bytes
|
||||||
|
@ -1121,35 +1125,36 @@ union ReusableBuffer
|
||||||
#endif
|
#endif
|
||||||
} modelsel;
|
} modelsel;
|
||||||
|
|
||||||
// 65 bytes
|
|
||||||
struct {
|
struct {
|
||||||
char msg[64];
|
char msg[64];
|
||||||
uint8_t r9mPower;
|
uint8_t r9mPower;
|
||||||
union {
|
struct {
|
||||||
struct {
|
union {
|
||||||
union {
|
uint8_t registerStep;
|
||||||
uint8_t registerStep;
|
uint8_t bindStep;
|
||||||
uint8_t bindStep;
|
uint8_t resetStep;
|
||||||
uint8_t resetStep;
|
};
|
||||||
};
|
char registrationId[PXX2_LEN_REGISTRATION_ID];
|
||||||
char registrationId[PXX2_LEN_REGISTRATION_ID];
|
uint32_t bindWaitTimeout;
|
||||||
uint32_t bindWaitTimeout;
|
uint8_t registerPopupVerticalPosition;
|
||||||
uint8_t registerPopupVerticalPosition;
|
uint8_t registerPopupHorizontalPosition;
|
||||||
uint8_t registerPopupHorizontalPosition;
|
int8_t registerPopupEditMode;
|
||||||
int8_t registerPopupEditMode;
|
char registerRxName[PXX2_LEN_RX_NAME];
|
||||||
char registerRxName[PXX2_LEN_RX_NAME];
|
uint8_t registerLoopIndex; // will be removed later
|
||||||
uint8_t registerLoopIndex; // will be removed later
|
char bindCandidateReceiversNames[PXX2_MAX_RECEIVERS_PER_MODULE][PXX2_LEN_RX_NAME + 1];
|
||||||
char bindCandidateReceiversNames[PXX2_MAX_RECEIVERS_PER_MODULE][PXX2_LEN_RX_NAME + 1];
|
uint8_t bindCandidateReceiversCount;
|
||||||
uint8_t bindCandidateReceiversCount;
|
uint8_t bindReceiverIndex;
|
||||||
uint8_t bindReceiverIndex;
|
union {
|
||||||
union {
|
uint8_t bindSelectedReceiverIndex;
|
||||||
uint8_t bindSelectedReceiverIndex;
|
uint8_t shareReceiverIndex;
|
||||||
uint8_t shareReceiverIndex;
|
uint8_t resetReceiverIndex;
|
||||||
uint8_t resetReceiverIndex;
|
};
|
||||||
};
|
uint8_t resetReceiverFlags;
|
||||||
uint8_t resetReceiverFlags;
|
} pxx2;
|
||||||
} pxx2;
|
struct {
|
||||||
};
|
char devices[MAX_BLUETOOTH_DISTANT_ADDR][LEN_BLUETOOTH_ADDR+1];
|
||||||
|
uint8_t devicesCount;
|
||||||
|
} bt;
|
||||||
} moduleSetup;
|
} moduleSetup;
|
||||||
|
|
||||||
// 103 bytes
|
// 103 bytes
|
||||||
|
@ -1381,10 +1386,6 @@ extern JitterMeter<uint16_t> avgJitter[NUM_ANALOGS];
|
||||||
#include "gps.h"
|
#include "gps.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(BLUETOOTH)
|
|
||||||
#include "bluetooth.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(JACK_DETECT_GPIO)
|
#if defined(JACK_DETECT_GPIO)
|
||||||
enum JackMode {
|
enum JackMode {
|
||||||
JACK_UNSELECTED_MODE,
|
JACK_UNSELECTED_MODE,
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
|
|
||||||
Fifo<uint8_t, 64> btTxFifo;
|
Fifo<uint8_t, 64> btTxFifo;
|
||||||
Fifo<uint8_t, 64> btRxFifo;
|
Fifo<uint8_t, 128> btRxFifo;
|
||||||
|
|
||||||
#if defined(PCBX7) || defined(PCBXLITE)
|
#if defined(PCBX7) || defined(PCBXLITE)
|
||||||
volatile uint8_t btChipPresent = 0;
|
volatile uint8_t btChipPresent = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue