Add connection state

This commit is contained in:
Tim Gromeyer
2025-03-23 21:49:27 +01:00
parent cb625d0889
commit 06f7b6bdb8
4 changed files with 49 additions and 0 deletions

View File

@@ -77,6 +77,8 @@ void BleManager::onDeviceDiscovered(const QBluetoothDeviceInfo &info)
deviceInfo.lidOpenCounter = static_cast<quint8>(data[8]);
deviceInfo.deviceColor = static_cast<quint8>(data[9]);
deviceInfo.connectionState = static_cast<DeviceInfo::ConnectionState>(data[10]);
// Determine primary pod (bit 5 of status) and value flipping
bool primaryLeft = (status & 0x20) != 0; // Bit 5: 1 = left primary, 0 = right primary
bool areValuesFlipped = !primaryLeft; // Flipped when right pod is primary
@@ -119,6 +121,9 @@ void BleManager::onDeviceDiscovered(const QBluetoothDeviceInfo &info)
else
deviceInfo.lidState = DeviceInfo::LidState::UNKNOWN;
// Update timestamp
deviceInfo.lastSeen = QDateTime::currentDateTime();

View File

@@ -45,6 +45,19 @@ public:
};
LidState lidState = LidState::UNKNOWN;
// Connection state enumeration
enum class ConnectionState : uint8_t
{
DISCONNECTED = 0x00,
IDLE = 0x04,
MUSIC = 0x05,
CALL = 0x06,
RINGING = 0x07,
HANGING_UP = 0x09,
UNKNOWN = 0xFF // Using 0xFF for representing null in the original
};
ConnectionState connectionState = ConnectionState::UNKNOWN;
QDateTime lastSeen; // Timestamp of last detection
};

View File

@@ -128,6 +128,11 @@ BleScanner::BleScanner(QWidget *parent) : QMainWindow(parent)
bothPodsInCaseLabel = new QLabel(this);
detailsLayout->addWidget(bothPodsInCaseLabel, 14, 1);
// Row 15: Connection State
detailsLayout->addWidget(new QLabel("Connection State:"), 15, 0);
connectionStateLabel = new QLabel(this);
detailsLayout->addWidget(connectionStateLabel, 15, 1);
mainLayout->addWidget(detailsGroup);
detailsGroup->setVisible(false);
@@ -302,6 +307,7 @@ void BleScanner::onDeviceSelected()
thisPodInCaseLabel->setText(device.isThisPodInTheCase ? "Yes" : "No");
onePodInCaseLabel->setText(device.isOnePodInCase ? "Yes" : "No");
bothPodsInCaseLabel->setText(device.areBothPodsInCase ? "Yes" : "No");
connectionStateLabel->setText(getConnectionStateName(device.connectionState));
detailsGroup->setVisible(true);
}
@@ -368,4 +374,27 @@ QString BleScanner::getColorName(quint8 colorId)
default:
return "Unknown";
}
}
QString BleScanner::getConnectionStateName(DeviceInfo::ConnectionState state)
{
using ConnectionState = DeviceInfo::ConnectionState;
switch (state)
{
case ConnectionState::DISCONNECTED:
return QString("Disconnected");
case ConnectionState::IDLE:
return QString("Idle");
case ConnectionState::MUSIC:
return QString("Playing Music");
case ConnectionState::CALL:
return QString("On Call");
case ConnectionState::RINGING:
return QString("Ringing");
case ConnectionState::HANGING_UP:
return QString("Hanging Up");
case ConnectionState::UNKNOWN:
default:
return QString("Unknown");
}
}

View File

@@ -27,6 +27,7 @@ private slots:
private:
QString getModelName(quint16 modelId);
QString getColorName(quint8 colorId);
QString getConnectionStateName(DeviceInfo::ConnectionState state);
BleManager *bleManager;
QTimer *refreshTimer;
@@ -54,6 +55,7 @@ private:
QLabel *thisPodInCaseLabel;
QLabel *onePodInCaseLabel;
QLabel *bothPodsInCaseLabel;
QLabel *connectionStateLabel;
};
#endif // BLESCANNER_H