[Linux] Read AirPods state from BLE broadcast when not connected (#138)

* Fix possible build error

* [Linux] Read AirPods state from BLE broadcast when not connected

* SImplify

* Remove old code

* Remove old code

* Maintain charging state when state is unknown

* Simplify

* Remove unused var
This commit is contained in:
Tim Gromeyer
2025-06-04 13:10:55 +02:00
committed by GitHub
parent 5dc7e512ae
commit c4633d6871
14 changed files with 416 additions and 617 deletions

View File

@@ -6,10 +6,11 @@
#include <QMap>
#include <QString>
#include <QDateTime>
#include "enums.h"
class QTimer;
class DeviceInfo
class BleInfo
{
public:
QString name;
@@ -20,20 +21,24 @@ public:
bool leftCharging = false;
bool rightCharging = false;
bool caseCharging = false;
quint16 deviceModel = 0;
AirpodsTrayApp::Enums::AirPodsModel modelName = AirpodsTrayApp::Enums::AirPodsModel::Unknown;
quint8 lidOpenCounter = 0;
quint8 deviceColor = 0;
QString color = "Unknown"; // Default color
quint8 status = 0;
QByteArray rawData;
QByteArray encryptedPayload; // 16 bytes of encrypted payload
// Additional status flags from Kotlin version
bool isLeftPodInEar = false;
bool isRightPodInEar = false;
bool isPrimaryInEar = false;
bool isSecondaryInEar = false;
bool isLeftPodMicrophone = false;
bool isRightPodMicrophone = false;
bool isThisPodInTheCase = false;
bool isOnePodInCase = false;
bool areBothPodsInCase = false;
bool primaryLeft = true; // True if left pod is primary, false if right pod is primary
// Lid state enumeration
enum class LidState
@@ -41,8 +46,7 @@ public:
OPEN = 0x0,
CLOSED = 0x1,
UNKNOWN,
};
LidState lidState = LidState::UNKNOWN;
} lidState = LidState::UNKNOWN;
// Connection state enumeration
enum class ConnectionState : uint8_t
@@ -54,8 +58,7 @@ public:
RINGING = 0x07,
HANGING_UP = 0x09,
UNKNOWN = 0xFF // Using 0xFF for representing null in the original
};
ConnectionState connectionState = ConnectionState::UNKNOWN;
} connectionState = ConnectionState::UNKNOWN;
QDateTime lastSeen; // Timestamp of last detection
};
@@ -69,21 +72,17 @@ public:
void startScan();
void stopScan();
const QMap<QString, DeviceInfo> &getDevices() const;
private slots:
void onDeviceDiscovered(const QBluetoothDeviceInfo &info);
void onScanFinished();
void onErrorOccurred(QBluetoothDeviceDiscoveryAgent::Error error);
void pruneOldDevices();
signals:
void deviceFound(const BleInfo &device);
private:
QBluetoothDeviceDiscoveryAgent *discoveryAgent;
QMap<QString, DeviceInfo> devices;
QTimer *pruneTimer; // Timer for periodic pruning
static const int PRUNE_INTERVAL_MS = 5000; // Check every 5 seconds
static const int DEVICE_TIMEOUT_MS = 10000; // Remove after 10 seconds
};
#endif // BLEMANAGER_H