diff --git a/app-common/src/main/java/eu/darken/capod/pods/core/apple/misc/FakeAirPodsGen1.kt b/app-common/src/main/java/eu/darken/capod/pods/core/apple/misc/FakeAirPodsGen1.kt index 449bca60..52672f44 100644 --- a/app-common/src/main/java/eu/darken/capod/pods/core/apple/misc/FakeAirPodsGen1.kt +++ b/app-common/src/main/java/eu/darken/capod/pods/core/apple/misc/FakeAirPodsGen1.kt @@ -6,10 +6,7 @@ import eu.darken.capod.common.debug.logging.logTag import eu.darken.capod.common.isBitSet import eu.darken.capod.common.lowerNibble import eu.darken.capod.common.upperNibble -import eu.darken.capod.pods.core.DualPodDevice -import eu.darken.capod.pods.core.HasCase -import eu.darken.capod.pods.core.HasDualMicrophone -import eu.darken.capod.pods.core.PodDevice +import eu.darken.capod.pods.core.* import eu.darken.capod.pods.core.apple.ApplePods import eu.darken.capod.pods.core.apple.ApplePodsFactory import eu.darken.capod.pods.core.apple.protocol.ProximityPairing @@ -31,7 +28,7 @@ data class FakeAirPodsGen1 constructor( override val confidence: Float = PodDevice.BASE_CONFIDENCE, private val rssiAverage: Int? = null, private val cachedBatteryPercentage: Float? = null, -) : ApplePods, DualPodDevice, HasDualMicrophone, HasCase { +) : ApplePods, DualPodDevice, HasEarDetectionDual, HasChargeDetectionDual, HasCase { override val model: PodDevice.Model = PodDevice.Model.FAKE_AIRPODS_GEN1 @@ -79,22 +76,32 @@ data class FakeAirPodsGen1 constructor( } } - val isThisPodInThecase: Boolean + private val isThisPodInThecase: Boolean get() = rawStatus.isBitSet(6) - /** - * The data flip bit is set if the left pod is primary. - * For the pod that is in the case, this is flipped again though. - */ - override val isLeftPodMicrophone: Boolean - get() = rawStatus.isBitSet(5) xor isThisPodInThecase + override val isLeftPodInEar: Boolean + get() = when (areValuesFlipped xor isThisPodInThecase) { + true -> rawStatus.isBitSet(3) + false -> rawStatus.isBitSet(1) + } - /** - * The data flip bit is UNset if the right pod is primary. - * For the pod that is in the case, this is flipped again though. - */ - override val isRightPodMicrophone: Boolean - get() = !rawStatus.isBitSet(5) xor isThisPodInThecase + override val isRightPodInEar: Boolean + get() = when (areValuesFlipped xor isThisPodInThecase) { + true -> rawStatus.isBitSet(1) + false -> rawStatus.isBitSet(3) + } + + override val isLeftPodCharging: Boolean + get() = when (areValuesFlipped) { + false -> rawFlags.isBitSet(0) + true -> rawFlags.isBitSet(1) + } + + override val isRightPodCharging: Boolean + get() = when (areValuesFlipped) { + false -> rawFlags.isBitSet(1) + true -> rawFlags.isBitSet(0) + } override val batteryCasePercent: Float? get() = when (val value = rawCaseBattery.toInt()) { diff --git a/app-common/src/test/java/eu/darken/capod/pods/core/apple/misc/FakeAirPodsGen1Test.kt b/app-common/src/test/java/eu/darken/capod/pods/core/apple/misc/FakeAirPodsGen1Test.kt index 25e62a3a..7f077a5a 100644 --- a/app-common/src/test/java/eu/darken/capod/pods/core/apple/misc/FakeAirPodsGen1Test.kt +++ b/app-common/src/test/java/eu/darken/capod/pods/core/apple/misc/FakeAirPodsGen1Test.kt @@ -24,6 +24,12 @@ class FakeAirPodsGen1Test : BaseAirPodsTest() { batteryLeftPodPercent shouldBe 1.0f batteryRightPodPercent shouldBe 1.0f + isLeftPodInEar shouldBe false + isRightPodInEar shouldBe false + + isLeftPodCharging shouldBe true + isRightPodCharging shouldBe true + isCaseCharging shouldBe false batteryCasePercent shouldBe 0.7f