-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support airpods max 2 & fix airpods max
- Loading branch information
1 parent
858b86a
commit 663e2d3
Showing
4 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app-common/src/main/java/eu/darken/capod/pods/core/apple/airpods/AirPodsMax2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package eu.darken.capod.pods.core.apple.airpods | ||
|
||
import eu.darken.capod.common.bluetooth.BleScanResult | ||
import eu.darken.capod.common.debug.logging.logTag | ||
import eu.darken.capod.common.isBitSet | ||
import eu.darken.capod.pods.core.HasChargeDetection | ||
import eu.darken.capod.pods.core.HasEarDetection | ||
import eu.darken.capod.pods.core.PodDevice | ||
import eu.darken.capod.pods.core.apple.ApplePods | ||
import eu.darken.capod.pods.core.apple.HasAppleColor | ||
import eu.darken.capod.pods.core.apple.SingleApplePods | ||
import eu.darken.capod.pods.core.apple.SingleApplePodsFactory | ||
import eu.darken.capod.pods.core.apple.protocol.ProximityPairing | ||
import java.time.Instant | ||
import javax.inject.Inject | ||
|
||
data class AirPodsMax2( | ||
override val identifier: PodDevice.Id = PodDevice.Id(), | ||
override val seenLastAt: Instant = Instant.now(), | ||
override val seenFirstAt: Instant = Instant.now(), | ||
override val seenCounter: Int = 1, | ||
override val scanResult: BleScanResult, | ||
override val proximityMessage: ProximityPairing.Message, | ||
override val reliability: Float = PodDevice.BASE_CONFIDENCE, | ||
private val rssiAverage: Int? = null, | ||
) : SingleApplePods, HasEarDetection, HasChargeDetection, HasAppleColor { | ||
|
||
override val model: PodDevice.Model = PodDevice.Model.AIRPODS_MAX2 | ||
|
||
override val rssi: Int | ||
get() = rssiAverage ?: super<SingleApplePods>.rssi | ||
|
||
override val isHeadsetBeingCharged: Boolean | ||
get() = rawFlags.isBitSet(0) | ||
|
||
override val isBeingWorn: Boolean | ||
get() = rawStatus.isBitSet(5) | ||
|
||
class Factory @Inject constructor() : SingleApplePodsFactory(TAG) { | ||
|
||
override fun isResponsible(message: ProximityPairing.Message): Boolean = message.run { | ||
getModelInfo().dirty == DEVICE_CODE_DIRTY && length == ProximityPairing.PAIRING_MESSAGE_LENGTH | ||
} | ||
|
||
override fun create(scanResult: BleScanResult, message: ProximityPairing.Message): ApplePods { | ||
var basic = AirPodsMax2(scanResult = scanResult, proximityMessage = message) | ||
val result = searchHistory(basic) | ||
|
||
if (result != null) basic = basic.copy(identifier = result.id) | ||
updateHistory(basic) | ||
|
||
if (result == null) return basic | ||
|
||
return basic.copy( | ||
identifier = result.id, | ||
seenFirstAt = result.seenFirstAt, | ||
seenLastAt = scanResult.receivedAt, | ||
seenCounter = result.seenCounter, | ||
reliability = result.reliability, | ||
rssiAverage = result.rssiSmoothed(basic.rssi), | ||
) | ||
} | ||
} | ||
|
||
companion object { | ||
private val DEVICE_CODE_DIRTY = 0x201F.toUByte() | ||
private val TAG = logTag("PodDevice", "Apple", "AirPods", "Max2") | ||
} | ||
} |