diff --git a/linux/ble/blemanager.cpp b/linux/ble/blemanager.cpp index 3d4c70e..1b5d0bd 100644 --- a/linux/ble/blemanager.cpp +++ b/linux/ble/blemanager.cpp @@ -60,6 +60,12 @@ void BleManager::onDeviceDiscovered(const QBluetoothDeviceInfo &info) deviceInfo.address = address; 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]) deviceInfo.deviceModel = static_cast(data[4]) | (static_cast(data[3]) << 8); @@ -74,7 +80,7 @@ void BleManager::onDeviceDiscovered(const QBluetoothDeviceInfo &info) quint8 flagsAndCaseBattery = static_cast(data[7]); // Lid open counter and device color - deviceInfo.lidOpenCounter = static_cast(data[8]); + quint8 lidIndicator = static_cast(data[8]); deviceInfo.deviceColor = static_cast(data[9]); deviceInfo.connectionState = static_cast(data[10]); @@ -93,9 +99,9 @@ void BleManager::onDeviceDiscovered(const QBluetoothDeviceInfo &info) // Parse charging statuses from flags (uper 4 bits of data[7]) quint8 flags = (flagsAndCaseBattery >> 4) & 0x0F; // Extracts lower nibble - deviceInfo.rightCharging = areValuesFlipped ? (flags & 0x01) != 0 : (flags & 0x02) != 0; // - deviceInfo.leftCharging = areValuesFlipped ? (flags & 0x02) != 0 : (flags & 0x01) != 0; // - deviceInfo.caseCharging = (flags & 0x04) != 0; // Keeping original bit 1 for consistency + 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; // Depending on primary, bit 1 or 0 + deviceInfo.caseCharging = (flags & 0x04) != 0; // bit 2 // Additional status flags from status byte (data[5]) deviceInfo.isThisPodInTheCase = (status & 0x40) != 0; // Bit 6 @@ -111,18 +117,11 @@ void BleManager::onDeviceDiscovered(const QBluetoothDeviceInfo &info) deviceInfo.isLeftPodMicrophone = primaryLeft ^ deviceInfo.isThisPodInTheCase; deviceInfo.isRightPodMicrophone = !primaryLeft ^ deviceInfo.isThisPodInTheCase; - // Determine lid state based on lid open counter - if (deviceInfo.lidOpenCounter >= 0x30 && deviceInfo.lidOpenCounter <= 0x37) - deviceInfo.lidState = DeviceInfo::LidState::OPEN; - else if (deviceInfo.lidOpenCounter >= 0x38 && deviceInfo.lidOpenCounter <= 0x3F) - deviceInfo.lidState = DeviceInfo::LidState::CLOSED; - else if (deviceInfo.lidOpenCounter <= 0x03) - deviceInfo.lidState = DeviceInfo::LidState::NOT_IN_CASE; - else - deviceInfo.lidState = DeviceInfo::LidState::UNKNOWN; - - - + deviceInfo.lidOpenCounter = lidIndicator & 0x07; // Extract bits 0-2 (count) + quint8 lidState = static_cast((lidIndicator >> 3) & 0x01); // Extract bit 3 (lid state) + if (deviceInfo.isThisPodInTheCase) { + deviceInfo.lidState = static_cast(lidState); + } // Update timestamp deviceInfo.lastSeen = QDateTime::currentDateTime(); diff --git a/linux/ble/blemanager.h b/linux/ble/blemanager.h index aed7323..380d814 100644 --- a/linux/ble/blemanager.h +++ b/linux/ble/blemanager.h @@ -38,10 +38,9 @@ public: // Lid state enumeration enum class LidState { - OPEN, - CLOSED, - NOT_IN_CASE, - UNKNOWN + OPEN = 0x0, + CLOSED = 0x1, + UNKNOWN, }; LidState lidState = LidState::UNKNOWN; diff --git a/linux/ble/blescanner.cpp b/linux/ble/blescanner.cpp index 9c38b88..2ce149d 100644 --- a/linux/ble/blescanner.cpp +++ b/linux/ble/blescanner.cpp @@ -279,9 +279,6 @@ void BleScanner::onDeviceSelected() case DeviceInfo::LidState::CLOSED: lidStateStr.append("Closed"); break; - case DeviceInfo::LidState::NOT_IN_CASE: - lidStateStr.append("Not in Case"); - break; case DeviceInfo::LidState::UNKNOWN: lidStateStr.append("Unknown"); break;