From 2ba3e8f3a4b0be7a38123cecccbaa18c98df17d4 Mon Sep 17 00:00:00 2001 From: Sprite Date: Fri, 28 Jul 2023 02:24:54 +0800 Subject: [PATCH] Fix lid switch detection for AirPods Pro 2 (#46) --- Source/Core/AppleCP.cpp | 3 +-- Source/Core/AppleCP.h | 9 +++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/Core/AppleCP.cpp b/Source/Core/AppleCP.cpp index f076854..e4aef01 100644 --- a/Source/Core/AppleCP.cpp +++ b/Source/Core/AppleCP.cpp @@ -120,8 +120,7 @@ bool AirPods::IsBothPodsInCase() const bool AirPods::IsLidOpened() const { - return lidState == 1 || lidState == 2 || lidState == 3 || lidState == 4 || lidState == 5 || - lidState == 6 || lidState == 7 || lidState == 0; + return lid.closed == 0; } bool AirPods::IsCaseCharging() const diff --git a/Source/Core/AppleCP.h b/Source/Core/AppleCP.h index c149431..a8129e5 100644 --- a/Source/Core/AppleCP.h +++ b/Source/Core/AppleCP.h @@ -147,8 +147,13 @@ class AirPods : Header uint8_t caseCharging : 1; // If it's charging (value != 0) uint8_t unk9 : 1; } battery; - uint8_t lidState; // 1/2/3/4/5/6/7/0 == opened, 9/a/b/c/d/e/f/8 == closed - Color color; // Untested because I don't have a device other than white + struct { + uint8_t switchCount : 3; // This count increases if the lid opened or closed once, and + // resets if overflow or no longer broadcasting advertisements + uint8_t closed : 1; + uint8_t unk10 : 4; + } lid; + Color color; // Untested because I don't have a device other than white uint8_t unk11[1]; uint8_t unk12[16]; // Hash or encrypted payload };