mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-04-28 17:17:54 +00:00
[Linux] Use enum to represnet noise control mode
This commit is contained in:
@@ -52,6 +52,18 @@ class AirPodsTrayApp : public QObject {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum NoiseControlMode : quint8
|
||||||
|
{
|
||||||
|
Off = 0,
|
||||||
|
NoiseCancellation = 1,
|
||||||
|
Transparency = 2,
|
||||||
|
Adaptive = 3,
|
||||||
|
|
||||||
|
MinValue = Off,
|
||||||
|
MaxValue = Adaptive,
|
||||||
|
};
|
||||||
|
Q_ENUM(NoiseControlMode)
|
||||||
|
|
||||||
AirPodsTrayApp(bool debugMode) : debugMode(debugMode) {
|
AirPodsTrayApp(bool debugMode) : debugMode(debugMode) {
|
||||||
if (debugMode) {
|
if (debugMode) {
|
||||||
QLoggingCategory::setFilterRules("airpodsApp.debug=true");
|
QLoggingCategory::setFilterRules("airpodsApp.debug=true");
|
||||||
@@ -79,6 +91,11 @@ public:
|
|||||||
QAction *adaptiveAction = new QAction("Adaptive", trayMenu);
|
QAction *adaptiveAction = new QAction("Adaptive", trayMenu);
|
||||||
QAction *noiseCancellationAction = new QAction("Noise Cancellation", trayMenu);
|
QAction *noiseCancellationAction = new QAction("Noise Cancellation", trayMenu);
|
||||||
|
|
||||||
|
offAction->setData(NoiseControlMode::Off);
|
||||||
|
transparencyAction->setData(NoiseControlMode::Transparency);
|
||||||
|
adaptiveAction->setData(NoiseControlMode::Adaptive);
|
||||||
|
noiseCancellationAction->setData(NoiseControlMode::NoiseCancellation);
|
||||||
|
|
||||||
offAction->setCheckable(true);
|
offAction->setCheckable(true);
|
||||||
transparencyAction->setCheckable(true);
|
transparencyAction->setCheckable(true);
|
||||||
adaptiveAction->setCheckable(true);
|
adaptiveAction->setCheckable(true);
|
||||||
@@ -95,10 +112,14 @@ public:
|
|||||||
noiseControlGroup->addAction(adaptiveAction);
|
noiseControlGroup->addAction(adaptiveAction);
|
||||||
noiseControlGroup->addAction(noiseCancellationAction);
|
noiseControlGroup->addAction(noiseCancellationAction);
|
||||||
|
|
||||||
connect(offAction, &QAction::triggered, this, [this]() { setNoiseControlMode(0); });
|
connect(offAction, &QAction::triggered, this, [this]()
|
||||||
connect(transparencyAction, &QAction::triggered, this, [this]() { setNoiseControlMode(2); });
|
{ setNoiseControlMode(NoiseControlMode::Off); });
|
||||||
connect(adaptiveAction, &QAction::triggered, this, [this]() { setNoiseControlMode(3); });
|
connect(transparencyAction, &QAction::triggered, this, [this]()
|
||||||
connect(noiseCancellationAction, &QAction::triggered, this, [this]() { setNoiseControlMode(1); });
|
{ setNoiseControlMode(NoiseControlMode::Transparency); });
|
||||||
|
connect(adaptiveAction, &QAction::triggered, this, [this]()
|
||||||
|
{ setNoiseControlMode(NoiseControlMode::Adaptive); });
|
||||||
|
connect(noiseCancellationAction, &QAction::triggered, this, [this]()
|
||||||
|
{ setNoiseControlMode(NoiseControlMode::NoiseCancellation); });
|
||||||
|
|
||||||
connect(this, &AirPodsTrayApp::noiseControlModeChanged, this, &AirPodsTrayApp::updateNoiseControlMenu);
|
connect(this, &AirPodsTrayApp::noiseControlModeChanged, this, &AirPodsTrayApp::updateNoiseControlMenu);
|
||||||
connect(this, &AirPodsTrayApp::batteryStatusChanged, this, &AirPodsTrayApp::updateBatteryTooltip);
|
connect(this, &AirPodsTrayApp::batteryStatusChanged, this, &AirPodsTrayApp::updateBatteryTooltip);
|
||||||
@@ -274,20 +295,20 @@ public slots:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNoiseControlMode(int mode) {
|
void setNoiseControlMode(NoiseControlMode mode) {
|
||||||
LOG_INFO("Setting noise control mode to: " << mode);
|
LOG_INFO("Setting noise control mode to: " << mode);
|
||||||
QByteArray packet;
|
QByteArray packet;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 0:
|
case Off:
|
||||||
packet = QByteArray::fromHex("0400040009000D01000000");
|
packet = QByteArray::fromHex("0400040009000D01000000");
|
||||||
break;
|
break;
|
||||||
case 1:
|
case NoiseCancellation:
|
||||||
packet = QByteArray::fromHex("0400040009000D02000000");
|
packet = QByteArray::fromHex("0400040009000D02000000");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case Transparency:
|
||||||
packet = QByteArray::fromHex("0400040009000D03000000");
|
packet = QByteArray::fromHex("0400040009000D03000000");
|
||||||
break;
|
break;
|
||||||
case 3:
|
case Adaptive:
|
||||||
packet = QByteArray::fromHex("0400040009000D04000000");
|
packet = QByteArray::fromHex("0400040009000D04000000");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -310,24 +331,10 @@ public slots:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateNoiseControlMenu(int mode) {
|
void updateNoiseControlMenu(NoiseControlMode mode) {
|
||||||
QList<QAction *> actions = trayMenu->actions();
|
QList<QAction *> actions = trayMenu->actions();
|
||||||
for (QAction *action : actions) {
|
for (QAction *action : actions) {
|
||||||
action->setChecked(false);
|
action->setChecked(action->data().toInt() == mode);
|
||||||
}
|
|
||||||
switch (mode) {
|
|
||||||
case 0:
|
|
||||||
actions[0]->setChecked(true);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
actions[3]->setChecked(true);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
actions[1]->setChecked(true);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
actions[2]->setChecked(true);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -577,12 +584,16 @@ public slots:
|
|||||||
void parseData(const QByteArray &data) {
|
void parseData(const QByteArray &data) {
|
||||||
LOG_DEBUG("Received: " << data.toHex());
|
LOG_DEBUG("Received: " << data.toHex());
|
||||||
if (data.size() == 11 && data.startsWith(QByteArray::fromHex("0400040009000D"))) {
|
if (data.size() == 11 && data.startsWith(QByteArray::fromHex("0400040009000D"))) {
|
||||||
int mode = data[7] - 1;
|
quint8 rawMode = data[7] - 1;
|
||||||
LOG_INFO("Noise control mode: " << mode);
|
if (rawMode >= NoiseControlMode::MinValue && rawMode <= NoiseControlMode::MaxValue)
|
||||||
if (mode >= 0 && mode <= 3) {
|
{
|
||||||
|
NoiseControlMode mode = static_cast<NoiseControlMode>(rawMode);
|
||||||
|
LOG_INFO("Noise control mode: " << rawMode);
|
||||||
emit noiseControlModeChanged(mode);
|
emit noiseControlModeChanged(mode);
|
||||||
} else {
|
}
|
||||||
LOG_ERROR("Invalid noise control mode value received: " << mode);
|
else
|
||||||
|
{
|
||||||
|
LOG_ERROR("Invalid noise control mode value received: " << rawMode);
|
||||||
}
|
}
|
||||||
} else if (data.size() == 8 && data.startsWith(QByteArray::fromHex("040004000600"))) {
|
} else if (data.size() == 8 && data.startsWith(QByteArray::fromHex("040004000600"))) {
|
||||||
char primary = data[6];
|
char primary = data[6];
|
||||||
@@ -873,7 +884,7 @@ public slots:
|
|||||||
}
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void noiseControlModeChanged(int mode);
|
void noiseControlModeChanged(NoiseControlMode mode);
|
||||||
void earDetectionStatusChanged(const QString &status);
|
void earDetectionStatusChanged(const QString &status);
|
||||||
void batteryStatusChanged(const QString &status);
|
void batteryStatusChanged(const QString &status);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user