mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-01-28 22:01:50 +00:00
Simple code cleanup
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#define AIRPODS_PACKETS_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include "enums.h"
|
||||
|
||||
namespace AirPodsPackets
|
||||
{
|
||||
@@ -14,6 +15,24 @@ namespace AirPodsPackets
|
||||
static const QByteArray NOISE_CANCELLATION = HEADER + QByteArray::fromHex("02000000");
|
||||
static const QByteArray TRANSPARENCY = HEADER + QByteArray::fromHex("03000000");
|
||||
static const QByteArray ADAPTIVE = HEADER + QByteArray::fromHex("04000000");
|
||||
|
||||
static const QByteArray getPacketForMode(AirpodsTrayApp::Enums::NoiseControlMode mode)
|
||||
{
|
||||
using NoiseControlMode = AirpodsTrayApp::Enums::NoiseControlMode;
|
||||
switch (mode)
|
||||
{
|
||||
case NoiseControlMode::Off:
|
||||
return OFF;
|
||||
case NoiseControlMode::NoiseCancellation:
|
||||
return NOISE_CANCELLATION;
|
||||
case NoiseControlMode::Transparency:
|
||||
return TRANSPARENCY;
|
||||
case NoiseControlMode::Adaptive:
|
||||
return ADAPTIVE;
|
||||
default:
|
||||
return QByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Conversational Awareness Packets
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
const QList<QBluetoothAddress> connectedDevices = localDevice.connectedDevices();
|
||||
for (const QBluetoothAddress &address : connectedDevices) {
|
||||
QBluetoothDeviceInfo device(address, "", 0);
|
||||
if (device.serviceUuids().contains(QBluetoothUuid("74ec2172-0bad-4d01-8f77-997b2be0722a"))) {
|
||||
if (isAirPodsDevice(device)) {
|
||||
connectToDevice(device);
|
||||
return;
|
||||
}
|
||||
@@ -144,6 +144,11 @@ private:
|
||||
QDBusConnection::systemBus().registerService("me.kavishdevar.aln");
|
||||
}
|
||||
|
||||
bool isAirPodsDevice(const QBluetoothDeviceInfo &device)
|
||||
{
|
||||
return device.serviceUuids().contains(QBluetoothUuid("74ec2172-0bad-4d01-8f77-997b2be0722a"));
|
||||
}
|
||||
|
||||
void notifyAndroidDevice()
|
||||
{
|
||||
if (phoneSocket && phoneSocket->isOpen())
|
||||
@@ -178,7 +183,7 @@ private:
|
||||
if (connected) {
|
||||
const QBluetoothAddress address = QBluetoothAddress(devicePath.split("/").last().replace("_", ":"));
|
||||
QBluetoothDeviceInfo device(address, "", 0);
|
||||
if (device.serviceUuids().contains(QBluetoothUuid("74ec2172-0bad-4d01-8f77-997b2be0722a"))) {
|
||||
if (isAirPodsDevice(device)) {
|
||||
connectToDevice(device);
|
||||
}
|
||||
} else {
|
||||
@@ -219,22 +224,7 @@ public slots:
|
||||
void setNoiseControlMode(NoiseControlMode mode)
|
||||
{
|
||||
LOG_INFO("Setting noise control mode to: " << mode);
|
||||
QByteArray packet;
|
||||
switch (mode)
|
||||
{
|
||||
case NoiseControlMode::Off:
|
||||
packet = AirPodsPackets::NoiseControl::OFF;
|
||||
break;
|
||||
case NoiseControlMode::NoiseCancellation:
|
||||
packet = AirPodsPackets::NoiseControl::NOISE_CANCELLATION;
|
||||
break;
|
||||
case NoiseControlMode::Transparency:
|
||||
packet = AirPodsPackets::NoiseControl::TRANSPARENCY;
|
||||
break;
|
||||
case NoiseControlMode::Adaptive:
|
||||
packet = AirPodsPackets::NoiseControl::ADAPTIVE;
|
||||
break;
|
||||
}
|
||||
QByteArray packet = AirPodsPackets::NoiseControl::getPacketForMode(mode);
|
||||
writePacketToSocket(packet, "Noise control mode packet written: ");
|
||||
}
|
||||
void setNoiseControlMode(int mode)
|
||||
@@ -308,7 +298,7 @@ private slots:
|
||||
connectToDevice(device.address().toString());
|
||||
}
|
||||
LOG_INFO("Device discovered: " << device.name() << " (" << device.address().toString() << ")");
|
||||
if (device.serviceUuids().contains(QBluetoothUuid("74ec2172-0bad-4d01-8f77-997b2be0722a"))) {
|
||||
if (isAirPodsDevice(device)) {
|
||||
LOG_DEBUG("Found AirPods device: " + device.name());
|
||||
connectToDevice(device);
|
||||
}
|
||||
@@ -319,7 +309,7 @@ private slots:
|
||||
discoveryAgent->start();
|
||||
const QList<QBluetoothDeviceInfo> discoveredDevices = discoveryAgent->discoveredDevices();
|
||||
for (const QBluetoothDeviceInfo &device : discoveredDevices) {
|
||||
if (device.serviceUuids().contains(QBluetoothUuid("74ec2172-0bad-4d01-8f77-997b2be0722a"))) {
|
||||
if (isAirPodsDevice(device)) {
|
||||
connectToDevice(device);
|
||||
return;
|
||||
}
|
||||
@@ -330,7 +320,7 @@ private slots:
|
||||
void onDeviceConnected(const QBluetoothAddress &address) {
|
||||
LOG_INFO("Device connected: " << address.toString());
|
||||
QBluetoothDeviceInfo device(address, "", 0);
|
||||
if (device.serviceUuids().contains(QBluetoothUuid("74ec2172-0bad-4d01-8f77-997b2be0722a"))) {
|
||||
if (isAirPodsDevice(device)) {
|
||||
connectToDevice(device);
|
||||
}
|
||||
}
|
||||
@@ -597,7 +587,7 @@ private slots:
|
||||
QString addr = deviceProps["Address"].toString();
|
||||
QBluetoothAddress btAddress(addr);
|
||||
QBluetoothDeviceInfo device(btAddress, "", 0);
|
||||
if (device.serviceUuids().contains(QBluetoothUuid("74ec2172-0bad-4d01-8f77-997b2be0722a"))) {
|
||||
if (isAirPodsDevice(device)) {
|
||||
connectToDevice(device);
|
||||
}
|
||||
}
|
||||
@@ -656,7 +646,7 @@ private slots:
|
||||
for (const QBluetoothAddress &address : connectedDevices) {
|
||||
QBluetoothDeviceInfo device(address, "", 0);
|
||||
LOG_DEBUG("Connected device: " << device.name() << " (" << device.address().toString() << ")");
|
||||
if (device.serviceUuids().contains(QBluetoothUuid("74ec2172-0bad-4d01-8f77-997b2be0722a"))) {
|
||||
if (isAirPodsDevice(device)) {
|
||||
connectToDevice(device);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user