Bluetooth rewrite to C++
This commit is contained in:
@@ -201,8 +201,8 @@ enum MenuModelSetupItems {
|
||||
#if defined(PCBX7) || defined(PCBX3)
|
||||
#define ANTENNA_ROW
|
||||
#if defined(BLUETOOTH)
|
||||
#define TRAINER_BLUETOOTH_M_ROW ((bluetoothDistantAddr[0] == '\0' || bluetoothState == BLUETOOTH_STATE_CONNECTED) ? (uint8_t)0 : (uint8_t)1)
|
||||
#define TRAINER_BLUETOOTH_S_ROW (bluetoothDistantAddr[0] == '\0' ? HIDDEN_ROW : LABEL())
|
||||
#define TRAINER_BLUETOOTH_M_ROW ((bluetooth.distantAddr[0] == '\0' || bluetooth.state == BLUETOOTH_STATE_CONNECTED) ? (uint8_t)0 : (uint8_t)1)
|
||||
#define TRAINER_BLUETOOTH_S_ROW (bluetooth.distantAddr[0] == '\0' ? HIDDEN_ROW : LABEL())
|
||||
#define TRAINER_BLUETOOTH_ROW (g_model.trainerData.mode == TRAINER_MODE_MASTER_BLUETOOTH ? TRAINER_BLUETOOTH_M_ROW : (g_model.trainerData.mode == TRAINER_MODE_SLAVE_BLUETOOTH ? TRAINER_BLUETOOTH_S_ROW : HIDDEN_ROW)),
|
||||
#else
|
||||
#define TRAINER_BLUETOOTH_ROW
|
||||
@@ -213,8 +213,8 @@ enum MenuModelSetupItems {
|
||||
#elif defined(PCBXLITES)
|
||||
#define ANTENNA_ROW IF_NOT_PXX2_MODULE(INTERNAL_MODULE, IF_INTERNAL_MODULE_ON(0)),
|
||||
#define IF_BT_TRAINER_ON(x) (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER ? (uint8_t)(x) : HIDDEN_ROW)
|
||||
#define TRAINER_BLUETOOTH_M_ROW ((bluetoothDistantAddr[0] == '\0' || bluetoothState == BLUETOOTH_STATE_CONNECTED) ? (uint8_t)0 : (uint8_t)1)
|
||||
#define TRAINER_BLUETOOTH_S_ROW (bluetoothDistantAddr[0] == '\0' ? HIDDEN_ROW : LABEL())
|
||||
#define TRAINER_BLUETOOTH_M_ROW ((bluetooth.distantAddr[0] == '\0' || bluetooth.state == BLUETOOTH_STATE_CONNECTED) ? (uint8_t)0 : (uint8_t)1)
|
||||
#define TRAINER_BLUETOOTH_S_ROW (bluetooth.distantAddr[0] == '\0' ? HIDDEN_ROW : LABEL())
|
||||
#define TRAINER_BLUETOOTH_ROW (g_model.trainerData.mode == TRAINER_MODE_MASTER_BLUETOOTH ? TRAINER_BLUETOOTH_M_ROW : (g_model.trainerData.mode == TRAINER_MODE_SLAVE_BLUETOOTH ? TRAINER_BLUETOOTH_S_ROW : HIDDEN_ROW))
|
||||
#define TRAINER_CHANNELS_ROW (IS_SLAVE_TRAINER() ? (uint8_t)1 : HIDDEN_ROW)
|
||||
#define TRAINER_PARAMS_ROW (IS_SLAVE_TRAINER() ? (uint8_t)2 : HIDDEN_ROW)
|
||||
@@ -222,8 +222,8 @@ enum MenuModelSetupItems {
|
||||
#elif defined(PCBXLITE)
|
||||
#define ANTENNA_ROW IF_NOT_PXX2_MODULE(INTERNAL_MODULE, IF_INTERNAL_MODULE_ON(0)),
|
||||
#define IF_BT_TRAINER_ON(x) (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER ? (uint8_t)(x) : HIDDEN_ROW)
|
||||
#define TRAINER_BLUETOOTH_M_ROW ((bluetoothDistantAddr[0] == '\0' || bluetoothState == BLUETOOTH_STATE_CONNECTED) ? (uint8_t)0 : (uint8_t)1)
|
||||
#define TRAINER_BLUETOOTH_S_ROW (bluetoothDistantAddr[0] == '\0' ? HIDDEN_ROW : LABEL())
|
||||
#define TRAINER_BLUETOOTH_M_ROW ((bluetooth.distantAddr[0] == '\0' || bluetooth.state == BLUETOOTH_STATE_CONNECTED) ? (uint8_t)0 : (uint8_t)1)
|
||||
#define TRAINER_BLUETOOTH_S_ROW (bluetooth.distantAddr[0] == '\0' ? HIDDEN_ROW : LABEL())
|
||||
#define TRAINER_BLUETOOTH_ROW (g_model.trainerData.mode == TRAINER_MODE_MASTER_BLUETOOTH ? TRAINER_BLUETOOTH_M_ROW : (g_model.trainerData.mode == TRAINER_MODE_SLAVE_BLUETOOTH ? TRAINER_BLUETOOTH_S_ROW : HIDDEN_ROW))
|
||||
#define TRAINER_CHANNELS_ROW (IS_SLAVE_TRAINER() ? (uint8_t)1 : HIDDEN_ROW)
|
||||
#define TRAINER_ROWS IF_BT_TRAINER_ON(LABEL(Trainer)), IF_BT_TRAINER_ON(0), IF_BT_TRAINER_ON(TRAINER_BLUETOOTH_ROW), IF_BT_TRAINER_ON(TRAINER_CHANNELS_ROW)
|
||||
@@ -511,12 +511,12 @@ 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;
|
||||
strncpy(bluetooth.distantAddr, reusableBuffer.moduleSetup.bt.devices[index], LEN_BLUETOOTH_ADDR);
|
||||
bluetooth.state = BLUETOOTH_STATE_BIND_REQUESTED;
|
||||
}
|
||||
else {
|
||||
reusableBuffer.moduleSetup.bt.devicesCount = 0;
|
||||
bluetoothState = BLUETOOTH_STATE_DISCOVER_END;
|
||||
bluetooth.state = BLUETOOTH_STATE_DISCOVER_END;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1178,8 +1178,8 @@ void menuModelSetup(event_t event)
|
||||
g_model.trainerData.mode = checkIncDec(event, g_model.trainerData.mode, 0, TRAINER_MODE_MAX(), EE_MODEL, isTrainerModeAvailable);
|
||||
#if defined(BLUETOOTH)
|
||||
if (checkIncDec_Ret) {
|
||||
bluetoothState = BLUETOOTH_STATE_OFF;
|
||||
bluetoothDistantAddr[0] = 0;
|
||||
bluetooth.state = BLUETOOTH_STATE_OFF;
|
||||
bluetooth.distantAddr[0] = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1192,31 +1192,31 @@ void menuModelSetup(event_t event)
|
||||
if (attr) {
|
||||
s_editMode = 0;
|
||||
}
|
||||
if (bluetoothDistantAddr[0]) {
|
||||
lcdDrawText(INDENT_WIDTH, y+1, bluetoothDistantAddr, TINSIZE);
|
||||
if (bluetooth.distantAddr[0]) {
|
||||
lcdDrawText(INDENT_WIDTH, y+1, bluetooth.distantAddr, TINSIZE);
|
||||
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, BUTTON(TR_CLEAR), attr);
|
||||
if (attr && event == EVT_KEY_FIRST(KEY_ENTER)) {
|
||||
bluetoothState = BLUETOOTH_STATE_OFF;
|
||||
memclear(bluetoothDistantAddr, sizeof(bluetoothDistantAddr));
|
||||
bluetooth.state = BLUETOOTH_STATE_OFF;
|
||||
memclear(bluetooth.distantAddr, sizeof(bluetooth.distantAddr));
|
||||
}
|
||||
}
|
||||
else {
|
||||
lcdDrawText(INDENT_WIDTH, y, "---");
|
||||
if (bluetoothState < BLUETOOTH_STATE_IDLE)
|
||||
if (bluetooth.state < BLUETOOTH_STATE_IDLE)
|
||||
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, STR_BUTTON_INIT, attr);
|
||||
else
|
||||
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, STR_BUTTON_DISCOVER, attr);
|
||||
if (attr && event == EVT_KEY_FIRST(KEY_ENTER)) {
|
||||
if (bluetoothState < BLUETOOTH_STATE_IDLE) {
|
||||
bluetoothState = BLUETOOTH_STATE_OFF;
|
||||
if (bluetooth.state < BLUETOOTH_STATE_IDLE) {
|
||||
bluetooth.state = BLUETOOTH_STATE_OFF;
|
||||
}
|
||||
else {
|
||||
reusableBuffer.moduleSetup.bt.devicesCount = 0;
|
||||
bluetoothState = BLUETOOTH_STATE_DISCOVER_REQUESTED;
|
||||
bluetooth.state = BLUETOOTH_STATE_DISCOVER_REQUESTED;
|
||||
}
|
||||
}
|
||||
|
||||
if (bluetoothState == BLUETOOTH_STATE_DISCOVER_START && reusableBuffer.moduleSetup.bt.devicesCount > 0) {
|
||||
if (bluetooth.state == 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];
|
||||
@@ -1227,11 +1227,11 @@ void menuModelSetup(event_t event)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (bluetoothDistantAddr[0])
|
||||
lcdDrawText(INDENT_WIDTH, y+1, bluetoothDistantAddr, TINSIZE);
|
||||
if (bluetooth.distantAddr[0])
|
||||
lcdDrawText(INDENT_WIDTH, y+1, bluetooth.distantAddr, TINSIZE);
|
||||
else
|
||||
lcdDrawText(INDENT_WIDTH, y, "---");
|
||||
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, bluetoothState == BLUETOOTH_STATE_CONNECTED ? "Connected" : "!Connected");
|
||||
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, bluetooth.state == BLUETOOTH_STATE_CONNECTED ? "Connected" : "!Connected");
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user