Remove old devices

This commit is contained in:
Tim Gromeyer
2025-03-15 11:46:50 +01:00
parent 9e40e6e3fd
commit cb625d0889
4 changed files with 42 additions and 25 deletions

View File

@@ -5,6 +5,9 @@
#include <QBluetoothDeviceDiscoveryAgent>
#include <QMap>
#include <QString>
#include <QDateTime>
class QTimer;
class DeviceInfo
{
@@ -41,6 +44,8 @@ public:
UNKNOWN
};
LidState lidState = LidState::UNKNOWN;
QDateTime lastSeen; // Timestamp of last detection
};
class BleManager : public QObject
@@ -58,10 +63,15 @@ private slots:
void onDeviceDiscovered(const QBluetoothDeviceInfo &info);
void onScanFinished();
void onErrorOccurred(QBluetoothDeviceDiscoveryAgent::Error error);
void pruneOldDevices();
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