mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-02-25 10:23:34 +00:00
Improved lid state detection
This commit is contained in:
@@ -60,6 +60,12 @@ void BleManager::onDeviceDiscovered(const QBluetoothDeviceInfo &info)
|
|||||||
deviceInfo.address = address;
|
deviceInfo.address = address;
|
||||||
deviceInfo.rawData = data;
|
deviceInfo.rawData = data;
|
||||||
|
|
||||||
|
// Check if pairing mode is paired (0x01) or pairing (0x00)
|
||||||
|
if (data[2] == 0x00)
|
||||||
|
{
|
||||||
|
return; // Skip pairing mode devices (the values are differently structured)
|
||||||
|
}
|
||||||
|
|
||||||
// Parse device model (big-endian: high byte at data[3], low byte at data[4])
|
// Parse device model (big-endian: high byte at data[3], low byte at data[4])
|
||||||
deviceInfo.deviceModel = static_cast<quint16>(data[4]) | (static_cast<quint8>(data[3]) << 8);
|
deviceInfo.deviceModel = static_cast<quint16>(data[4]) | (static_cast<quint8>(data[3]) << 8);
|
||||||
|
|
||||||
@@ -74,7 +80,7 @@ void BleManager::onDeviceDiscovered(const QBluetoothDeviceInfo &info)
|
|||||||
quint8 flagsAndCaseBattery = static_cast<quint8>(data[7]);
|
quint8 flagsAndCaseBattery = static_cast<quint8>(data[7]);
|
||||||
|
|
||||||
// Lid open counter and device color
|
// Lid open counter and device color
|
||||||
deviceInfo.lidOpenCounter = static_cast<quint8>(data[8]);
|
quint8 lidIndicator = static_cast<quint8>(data[8]);
|
||||||
deviceInfo.deviceColor = static_cast<quint8>(data[9]);
|
deviceInfo.deviceColor = static_cast<quint8>(data[9]);
|
||||||
|
|
||||||
deviceInfo.connectionState = static_cast<DeviceInfo::ConnectionState>(data[10]);
|
deviceInfo.connectionState = static_cast<DeviceInfo::ConnectionState>(data[10]);
|
||||||
@@ -93,9 +99,9 @@ void BleManager::onDeviceDiscovered(const QBluetoothDeviceInfo &info)
|
|||||||
|
|
||||||
// Parse charging statuses from flags (uper 4 bits of data[7])
|
// Parse charging statuses from flags (uper 4 bits of data[7])
|
||||||
quint8 flags = (flagsAndCaseBattery >> 4) & 0x0F; // Extracts lower nibble
|
quint8 flags = (flagsAndCaseBattery >> 4) & 0x0F; // Extracts lower nibble
|
||||||
deviceInfo.rightCharging = areValuesFlipped ? (flags & 0x01) != 0 : (flags & 0x02) != 0; //
|
deviceInfo.rightCharging = areValuesFlipped ? (flags & 0x01) != 0 : (flags & 0x02) != 0; // Depending on primary, bit 0 or 1
|
||||||
deviceInfo.leftCharging = areValuesFlipped ? (flags & 0x02) != 0 : (flags & 0x01) != 0; //
|
deviceInfo.leftCharging = areValuesFlipped ? (flags & 0x02) != 0 : (flags & 0x01) != 0; // Depending on primary, bit 1 or 0
|
||||||
deviceInfo.caseCharging = (flags & 0x04) != 0; // Keeping original bit 1 for consistency
|
deviceInfo.caseCharging = (flags & 0x04) != 0; // bit 2
|
||||||
|
|
||||||
// Additional status flags from status byte (data[5])
|
// Additional status flags from status byte (data[5])
|
||||||
deviceInfo.isThisPodInTheCase = (status & 0x40) != 0; // Bit 6
|
deviceInfo.isThisPodInTheCase = (status & 0x40) != 0; // Bit 6
|
||||||
@@ -111,18 +117,11 @@ void BleManager::onDeviceDiscovered(const QBluetoothDeviceInfo &info)
|
|||||||
deviceInfo.isLeftPodMicrophone = primaryLeft ^ deviceInfo.isThisPodInTheCase;
|
deviceInfo.isLeftPodMicrophone = primaryLeft ^ deviceInfo.isThisPodInTheCase;
|
||||||
deviceInfo.isRightPodMicrophone = !primaryLeft ^ deviceInfo.isThisPodInTheCase;
|
deviceInfo.isRightPodMicrophone = !primaryLeft ^ deviceInfo.isThisPodInTheCase;
|
||||||
|
|
||||||
// Determine lid state based on lid open counter
|
deviceInfo.lidOpenCounter = lidIndicator & 0x07; // Extract bits 0-2 (count)
|
||||||
if (deviceInfo.lidOpenCounter >= 0x30 && deviceInfo.lidOpenCounter <= 0x37)
|
quint8 lidState = static_cast<quint8>((lidIndicator >> 3) & 0x01); // Extract bit 3 (lid state)
|
||||||
deviceInfo.lidState = DeviceInfo::LidState::OPEN;
|
if (deviceInfo.isThisPodInTheCase) {
|
||||||
else if (deviceInfo.lidOpenCounter >= 0x38 && deviceInfo.lidOpenCounter <= 0x3F)
|
deviceInfo.lidState = static_cast<DeviceInfo::LidState>(lidState);
|
||||||
deviceInfo.lidState = DeviceInfo::LidState::CLOSED;
|
}
|
||||||
else if (deviceInfo.lidOpenCounter <= 0x03)
|
|
||||||
deviceInfo.lidState = DeviceInfo::LidState::NOT_IN_CASE;
|
|
||||||
else
|
|
||||||
deviceInfo.lidState = DeviceInfo::LidState::UNKNOWN;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Update timestamp
|
// Update timestamp
|
||||||
deviceInfo.lastSeen = QDateTime::currentDateTime();
|
deviceInfo.lastSeen = QDateTime::currentDateTime();
|
||||||
|
|||||||
@@ -38,10 +38,9 @@ public:
|
|||||||
// Lid state enumeration
|
// Lid state enumeration
|
||||||
enum class LidState
|
enum class LidState
|
||||||
{
|
{
|
||||||
OPEN,
|
OPEN = 0x0,
|
||||||
CLOSED,
|
CLOSED = 0x1,
|
||||||
NOT_IN_CASE,
|
UNKNOWN,
|
||||||
UNKNOWN
|
|
||||||
};
|
};
|
||||||
LidState lidState = LidState::UNKNOWN;
|
LidState lidState = LidState::UNKNOWN;
|
||||||
|
|
||||||
|
|||||||
@@ -279,9 +279,6 @@ void BleScanner::onDeviceSelected()
|
|||||||
case DeviceInfo::LidState::CLOSED:
|
case DeviceInfo::LidState::CLOSED:
|
||||||
lidStateStr.append("Closed");
|
lidStateStr.append("Closed");
|
||||||
break;
|
break;
|
||||||
case DeviceInfo::LidState::NOT_IN_CASE:
|
|
||||||
lidStateStr.append("Not in Case");
|
|
||||||
break;
|
|
||||||
case DeviceInfo::LidState::UNKNOWN:
|
case DeviceInfo::LidState::UNKNOWN:
|
||||||
lidStateStr.append("Unknown");
|
lidStateStr.append("Unknown");
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user