[Linux] Add One Bud ANC Mode setting

This commit is contained in:
Tim Gromeyer
2025-05-16 14:08:42 +02:00
parent 09e1aa1530
commit 5fe123f544
2 changed files with 53 additions and 0 deletions

View File

@@ -226,6 +226,19 @@ ApplicationWindow {
onCheckedChanged: airPodsTrayApp.notificationsEnabled = checked onCheckedChanged: airPodsTrayApp.notificationsEnabled = checked
} }
Switch {
visible: airPodsTrayApp.airpodsConnected
text: "One Bud ANC Mode"
checked: airPodsTrayApp.oneBudANCMode
onCheckedChanged: airPodsTrayApp.oneBudANCMode = checked
ToolTip {
visible: parent.hovered
text: "Enable ANC when using one AirPod\n(More noise reduction, but uses more battery)"
delay: 500
}
}
Row { Row {
spacing: 5 spacing: 5
Label { Label {

View File

@@ -37,6 +37,7 @@ class AirPodsTrayApp : public QObject {
Q_PROPERTY(bool notificationsEnabled READ notificationsEnabled WRITE setNotificationsEnabled NOTIFY notificationsEnabledChanged) Q_PROPERTY(bool notificationsEnabled READ notificationsEnabled WRITE setNotificationsEnabled NOTIFY notificationsEnabledChanged)
Q_PROPERTY(int retryAttempts READ retryAttempts WRITE setRetryAttempts NOTIFY retryAttemptsChanged) Q_PROPERTY(int retryAttempts READ retryAttempts WRITE setRetryAttempts NOTIFY retryAttemptsChanged)
Q_PROPERTY(bool hideOnStart READ hideOnStart CONSTANT) Q_PROPERTY(bool hideOnStart READ hideOnStart CONSTANT)
Q_PROPERTY(bool oneBudANCMode READ oneBudANCMode WRITE setOneBudANCMode NOTIFY oneBudANCModeChanged)
public: public:
AirPodsTrayApp(bool debugMode, bool hideOnStart, QQmlApplicationEngine *parent = nullptr) AirPodsTrayApp(bool debugMode, bool hideOnStart, QQmlApplicationEngine *parent = nullptr)
@@ -146,6 +147,7 @@ public:
void setNotificationsEnabled(bool enabled) { trayManager->setNotificationsEnabled(enabled); } void setNotificationsEnabled(bool enabled) { trayManager->setNotificationsEnabled(enabled); }
int retryAttempts() const { return m_retryAttempts; } int retryAttempts() const { return m_retryAttempts; }
bool hideOnStart() const { return m_hideOnStart; } bool hideOnStart() const { return m_hideOnStart; }
bool oneBudANCMode() const { return m_oneBudANCMode; }
private: private:
bool debugMode; bool debugMode;
@@ -227,6 +229,29 @@ public slots:
emit conversationalAwarenessChanged(enabled); emit conversationalAwarenessChanged(enabled);
} }
void setOneBudANCMode(bool enabled)
{
if (m_oneBudANCMode == enabled)
{
LOG_INFO("One Bud ANC mode is already " << (enabled ? "enabled" : "disabled"));
return;
}
LOG_INFO("Setting One Bud ANC mode to: " << (enabled ? "enabled" : "disabled"));
QByteArray packet = enabled ? AirPodsPackets::OneBudANCMode::ENABLED
: AirPodsPackets::OneBudANCMode::DISABLED;
if (writePacketToSocket(packet, "One Bud ANC mode packet written: "))
{
m_oneBudANCMode = enabled;
emit oneBudANCModeChanged(enabled);
}
else
{
LOG_ERROR("Failed to send One Bud ANC mode command: socket not open");
}
}
void setRetryAttempts(int attempts) void setRetryAttempts(int attempts)
{ {
if (m_retryAttempts != attempts) if (m_retryAttempts != attempts)
@@ -698,6 +723,19 @@ private slots:
} }
emit airPodsStatusChanged(); emit airPodsStatusChanged();
} }
else if (data.startsWith(AirPodsPackets::OneBudANCMode::HEADER)) {
auto result = AirPodsPackets::OneBudANCMode::parseState(data);
if (result.has_value())
{
m_oneBudANCMode = result.value();
LOG_INFO("One Bud ANC mode received: " << m_conversationalAwareness);
emit oneBudANCModeChanged(m_conversationalAwareness);
}
else
{
LOG_ERROR("Failed to parse One Bud ANC mode");
}
}
else else
{ {
LOG_DEBUG("Unrecognized packet format: " << data.toHex()); LOG_DEBUG("Unrecognized packet format: " << data.toHex());
@@ -927,6 +965,7 @@ signals:
void crossDeviceEnabledChanged(bool enabled); void crossDeviceEnabledChanged(bool enabled);
void notificationsEnabledChanged(bool enabled); void notificationsEnabledChanged(bool enabled);
void retryAttemptsChanged(int attempts); void retryAttemptsChanged(int attempts);
void oneBudANCModeChanged(bool enabled);
private: private:
QBluetoothSocket *socket = nullptr; QBluetoothSocket *socket = nullptr;
@@ -954,6 +993,7 @@ private:
bool m_secoundaryInEar = false; bool m_secoundaryInEar = false;
QByteArray m_magicAccIRK; QByteArray m_magicAccIRK;
QByteArray m_magicAccEncKey; QByteArray m_magicAccEncKey;
bool m_oneBudANCMode = false;
}; };
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {