Bluetooth popup menu added. Works far better now.
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
bluetoothState = BLUETOOTH_STATE_OFF;
|
||||
memclear(bluetoothDistantAddr, sizeof(bluetoothDistantAddr));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -1152,10 +1152,22 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+31
-30
@@ -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,35 +1125,36 @@ union ReusableBuffer
|
||||
#endif
|
||||
} modelsel;
|
||||
|
||||
// 65 bytes
|
||||
struct {
|
||||
char msg[64];
|
||||
uint8_t r9mPower;
|
||||
union {
|
||||
struct {
|
||||
union {
|
||||
uint8_t registerStep;
|
||||
uint8_t bindStep;
|
||||
uint8_t resetStep;
|
||||
};
|
||||
char registrationId[PXX2_LEN_REGISTRATION_ID];
|
||||
uint32_t bindWaitTimeout;
|
||||
uint8_t registerPopupVerticalPosition;
|
||||
uint8_t registerPopupHorizontalPosition;
|
||||
int8_t registerPopupEditMode;
|
||||
char registerRxName[PXX2_LEN_RX_NAME];
|
||||
uint8_t registerLoopIndex; // will be removed later
|
||||
char bindCandidateReceiversNames[PXX2_MAX_RECEIVERS_PER_MODULE][PXX2_LEN_RX_NAME + 1];
|
||||
uint8_t bindCandidateReceiversCount;
|
||||
uint8_t bindReceiverIndex;
|
||||
union {
|
||||
uint8_t bindSelectedReceiverIndex;
|
||||
uint8_t shareReceiverIndex;
|
||||
uint8_t resetReceiverIndex;
|
||||
};
|
||||
uint8_t resetReceiverFlags;
|
||||
} pxx2;
|
||||
};
|
||||
struct {
|
||||
union {
|
||||
uint8_t registerStep;
|
||||
uint8_t bindStep;
|
||||
uint8_t resetStep;
|
||||
};
|
||||
char registrationId[PXX2_LEN_REGISTRATION_ID];
|
||||
uint32_t bindWaitTimeout;
|
||||
uint8_t registerPopupVerticalPosition;
|
||||
uint8_t registerPopupHorizontalPosition;
|
||||
int8_t registerPopupEditMode;
|
||||
char registerRxName[PXX2_LEN_RX_NAME];
|
||||
uint8_t registerLoopIndex; // will be removed later
|
||||
char bindCandidateReceiversNames[PXX2_MAX_RECEIVERS_PER_MODULE][PXX2_LEN_RX_NAME + 1];
|
||||
uint8_t bindCandidateReceiversCount;
|
||||
uint8_t bindReceiverIndex;
|
||||
union {
|
||||
uint8_t bindSelectedReceiverIndex;
|
||||
uint8_t shareReceiverIndex;
|
||||
uint8_t resetReceiverIndex;
|
||||
};
|
||||
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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user