mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-03-17 03:32:33 +00:00
Add connection state
This commit is contained in:
@@ -77,6 +77,8 @@ void BleManager::onDeviceDiscovered(const QBluetoothDeviceInfo &info)
|
|||||||
deviceInfo.lidOpenCounter = static_cast<quint8>(data[8]);
|
deviceInfo.lidOpenCounter = 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]);
|
||||||
|
|
||||||
// Determine primary pod (bit 5 of status) and value flipping
|
// Determine primary pod (bit 5 of status) and value flipping
|
||||||
bool primaryLeft = (status & 0x20) != 0; // Bit 5: 1 = left primary, 0 = right primary
|
bool primaryLeft = (status & 0x20) != 0; // Bit 5: 1 = left primary, 0 = right primary
|
||||||
bool areValuesFlipped = !primaryLeft; // Flipped when right pod is primary
|
bool areValuesFlipped = !primaryLeft; // Flipped when right pod is primary
|
||||||
@@ -119,6 +121,9 @@ void BleManager::onDeviceDiscovered(const QBluetoothDeviceInfo &info)
|
|||||||
else
|
else
|
||||||
deviceInfo.lidState = DeviceInfo::LidState::UNKNOWN;
|
deviceInfo.lidState = DeviceInfo::LidState::UNKNOWN;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Update timestamp
|
// Update timestamp
|
||||||
deviceInfo.lastSeen = QDateTime::currentDateTime();
|
deviceInfo.lastSeen = QDateTime::currentDateTime();
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,19 @@ public:
|
|||||||
};
|
};
|
||||||
LidState lidState = LidState::UNKNOWN;
|
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
|
QDateTime lastSeen; // Timestamp of last detection
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -128,6 +128,11 @@ BleScanner::BleScanner(QWidget *parent) : QMainWindow(parent)
|
|||||||
bothPodsInCaseLabel = new QLabel(this);
|
bothPodsInCaseLabel = new QLabel(this);
|
||||||
detailsLayout->addWidget(bothPodsInCaseLabel, 14, 1);
|
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);
|
mainLayout->addWidget(detailsGroup);
|
||||||
detailsGroup->setVisible(false);
|
detailsGroup->setVisible(false);
|
||||||
|
|
||||||
@@ -302,6 +307,7 @@ void BleScanner::onDeviceSelected()
|
|||||||
thisPodInCaseLabel->setText(device.isThisPodInTheCase ? "Yes" : "No");
|
thisPodInCaseLabel->setText(device.isThisPodInTheCase ? "Yes" : "No");
|
||||||
onePodInCaseLabel->setText(device.isOnePodInCase ? "Yes" : "No");
|
onePodInCaseLabel->setText(device.isOnePodInCase ? "Yes" : "No");
|
||||||
bothPodsInCaseLabel->setText(device.areBothPodsInCase ? "Yes" : "No");
|
bothPodsInCaseLabel->setText(device.areBothPodsInCase ? "Yes" : "No");
|
||||||
|
connectionStateLabel->setText(getConnectionStateName(device.connectionState));
|
||||||
|
|
||||||
detailsGroup->setVisible(true);
|
detailsGroup->setVisible(true);
|
||||||
}
|
}
|
||||||
@@ -368,4 +374,27 @@ QString BleScanner::getColorName(quint8 colorId)
|
|||||||
default:
|
default:
|
||||||
return "Unknown";
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -27,6 +27,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QString getModelName(quint16 modelId);
|
QString getModelName(quint16 modelId);
|
||||||
QString getColorName(quint8 colorId);
|
QString getColorName(quint8 colorId);
|
||||||
|
QString getConnectionStateName(DeviceInfo::ConnectionState state);
|
||||||
|
|
||||||
BleManager *bleManager;
|
BleManager *bleManager;
|
||||||
QTimer *refreshTimer;
|
QTimer *refreshTimer;
|
||||||
@@ -54,6 +55,7 @@ private:
|
|||||||
QLabel *thisPodInCaseLabel;
|
QLabel *thisPodInCaseLabel;
|
||||||
QLabel *onePodInCaseLabel;
|
QLabel *onePodInCaseLabel;
|
||||||
QLabel *bothPodsInCaseLabel;
|
QLabel *bothPodsInCaseLabel;
|
||||||
|
QLabel *connectionStateLabel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BLESCANNER_H
|
#endif // BLESCANNER_H
|
||||||
Reference in New Issue
Block a user