Skip to content

Commit f3ed3bb

Browse files
authored
[Linux] Add One Bud ANC Mode setting (#128)
2 parents fd917d3 + 5fe123f commit f3ed3bb

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

linux/Main.qml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,19 @@ ApplicationWindow {
226226
onCheckedChanged: airPodsTrayApp.notificationsEnabled = checked
227227
}
228228

229+
Switch {
230+
visible: airPodsTrayApp.airpodsConnected
231+
text: "One Bud ANC Mode"
232+
checked: airPodsTrayApp.oneBudANCMode
233+
onCheckedChanged: airPodsTrayApp.oneBudANCMode = checked
234+
235+
ToolTip {
236+
visible: parent.hovered
237+
text: "Enable ANC when using one AirPod\n(More noise reduction, but uses more battery)"
238+
delay: 500
239+
}
240+
}
241+
229242
Row {
230243
spacing: 5
231244
Label {

linux/main.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class AirPodsTrayApp : public QObject {
3737
Q_PROPERTY(bool notificationsEnabled READ notificationsEnabled WRITE setNotificationsEnabled NOTIFY notificationsEnabledChanged)
3838
Q_PROPERTY(int retryAttempts READ retryAttempts WRITE setRetryAttempts NOTIFY retryAttemptsChanged)
3939
Q_PROPERTY(bool hideOnStart READ hideOnStart CONSTANT)
40+
Q_PROPERTY(bool oneBudANCMode READ oneBudANCMode WRITE setOneBudANCMode NOTIFY oneBudANCModeChanged)
4041

4142
public:
4243
AirPodsTrayApp(bool debugMode, bool hideOnStart, QQmlApplicationEngine *parent = nullptr)
@@ -146,6 +147,7 @@ class AirPodsTrayApp : public QObject {
146147
void setNotificationsEnabled(bool enabled) { trayManager->setNotificationsEnabled(enabled); }
147148
int retryAttempts() const { return m_retryAttempts; }
148149
bool hideOnStart() const { return m_hideOnStart; }
150+
bool oneBudANCMode() const { return m_oneBudANCMode; }
149151

150152
private:
151153
bool debugMode;
@@ -227,6 +229,29 @@ public slots:
227229
emit conversationalAwarenessChanged(enabled);
228230
}
229231

232+
void setOneBudANCMode(bool enabled)
233+
{
234+
if (m_oneBudANCMode == enabled)
235+
{
236+
LOG_INFO("One Bud ANC mode is already " << (enabled ? "enabled" : "disabled"));
237+
return;
238+
}
239+
240+
LOG_INFO("Setting One Bud ANC mode to: " << (enabled ? "enabled" : "disabled"));
241+
QByteArray packet = enabled ? AirPodsPackets::OneBudANCMode::ENABLED
242+
: AirPodsPackets::OneBudANCMode::DISABLED;
243+
244+
if (writePacketToSocket(packet, "One Bud ANC mode packet written: "))
245+
{
246+
m_oneBudANCMode = enabled;
247+
emit oneBudANCModeChanged(enabled);
248+
}
249+
else
250+
{
251+
LOG_ERROR("Failed to send One Bud ANC mode command: socket not open");
252+
}
253+
}
254+
230255
void setRetryAttempts(int attempts)
231256
{
232257
if (m_retryAttempts != attempts)
@@ -440,6 +465,7 @@ private slots:
440465
trayManager->showNotification(
441466
tr("AirPods Disconnected"),
442467
tr("Your AirPods have been disconnected"));
468+
trayManager->resetTrayIcon();
443469
}
444470

445471
void bluezDeviceDisconnected(const QString &address, const QString &name)
@@ -697,6 +723,19 @@ private slots:
697723
}
698724
emit airPodsStatusChanged();
699725
}
726+
else if (data.startsWith(AirPodsPackets::OneBudANCMode::HEADER)) {
727+
auto result = AirPodsPackets::OneBudANCMode::parseState(data);
728+
if (result.has_value())
729+
{
730+
m_oneBudANCMode = result.value();
731+
LOG_INFO("One Bud ANC mode received: " << m_conversationalAwareness);
732+
emit oneBudANCModeChanged(m_conversationalAwareness);
733+
}
734+
else
735+
{
736+
LOG_ERROR("Failed to parse One Bud ANC mode");
737+
}
738+
}
700739
else
701740
{
702741
LOG_DEBUG("Unrecognized packet format: " << data.toHex());
@@ -926,6 +965,7 @@ private slots:
926965
void crossDeviceEnabledChanged(bool enabled);
927966
void notificationsEnabledChanged(bool enabled);
928967
void retryAttemptsChanged(int attempts);
968+
void oneBudANCModeChanged(bool enabled);
929969

930970
private:
931971
QBluetoothSocket *socket = nullptr;
@@ -953,6 +993,7 @@ private slots:
953993
bool m_secoundaryInEar = false;
954994
QByteArray m_magicAccIRK;
955995
QByteArray m_magicAccEncKey;
996+
bool m_oneBudANCMode = false;
956997
};
957998

958999
int main(int argc, char *argv[]) {

linux/trayiconmanager.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ class TrayIconManager : public QObject
3333
}
3434
}
3535

36+
void resetTrayIcon()
37+
{
38+
trayIcon->setIcon(QIcon(":/icons/assets/airpods.png"));
39+
trayIcon->setToolTip("");
40+
}
41+
3642
signals:
3743
void notificationsEnabledChanged(bool enabled);
3844

0 commit comments

Comments
 (0)