Skip to content

Commit 24686da

Browse files
kavishdevarCopilot
andauthored
android: add ability to launch digital assistant on long press (#180)
* Initial plan * Implement BLE-only mode toggle and basic functionality Co-authored-by: kavishdevar <46088622+kavishdevar@users.noreply.github.com> * Fix BLE-only mode compatibility issues and enhance MAC address handling Co-authored-by: kavishdevar <46088622+kavishdevar@users.noreply.github.com> * Address BLE-only mode feedback: hide renaming, add ear detection warning, ensure default is false Co-authored-by: kavishdevar <46088622+kavishdevar@users.noreply.github.com> * android: add support for invoking digital assistant on long press --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent d9359cd commit 24686da

20 files changed

Lines changed: 805 additions & 281 deletions

android/app/src/main/java/me/kavishdevar/librepods/MainActivity.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ import com.google.accompanist.permissions.ExperimentalPermissionsApi
104104
import com.google.accompanist.permissions.MultiplePermissionsState
105105
import com.google.accompanist.permissions.isGranted
106106
import com.google.accompanist.permissions.rememberMultiplePermissionsState
107+
import me.kavishdevar.librepods.constants.AirPodsNotifications
107108
import me.kavishdevar.librepods.screens.AirPodsSettingsScreen
108109
import me.kavishdevar.librepods.screens.AppSettingsScreen
109110
import me.kavishdevar.librepods.screens.DebugScreen
@@ -114,11 +115,10 @@ import me.kavishdevar.librepods.screens.RenameScreen
114115
import me.kavishdevar.librepods.screens.TroubleshootingScreen
115116
import me.kavishdevar.librepods.services.AirPodsService
116117
import me.kavishdevar.librepods.ui.theme.LibrePodsTheme
117-
import me.kavishdevar.librepods.utils.AirPodsNotifications
118118
import me.kavishdevar.librepods.utils.CrossDevice
119119
import me.kavishdevar.librepods.utils.RadareOffsetFinder
120-
import kotlin.io.encoding.ExperimentalEncodingApi
121120
import kotlin.io.encoding.Base64
121+
import kotlin.io.encoding.ExperimentalEncodingApi
122122

123123
lateinit var serviceConnection: ServiceConnection
124124
lateinit var connectionStatusReceiver: BroadcastReceiver
@@ -187,7 +187,7 @@ class MainActivity : ComponentActivity() {
187187

188188
private fun handleIncomingIntent(intent: Intent) {
189189
val data: Uri? = intent.data
190-
190+
191191
if (data != null && data.scheme == "librepods") {
192192
when (data.host) {
193193
"add-magic-keys" -> {
@@ -198,34 +198,34 @@ class MainActivity : ComponentActivity() {
198198
// Handle your parameters here
199199
Log.d("LibrePods", "Parameter: $param = $value")
200200
}
201-
201+
202202
// Process the magic keys addition
203203
handleAddMagicKeys(data)
204204
}
205205
}
206206
}
207207
}
208-
208+
209209
private fun handleAddMagicKeys(uri: Uri) {
210210
val context = this
211211
val sharedPreferences = getSharedPreferences("settings", Context.MODE_PRIVATE)
212-
212+
213213
val irkHex = uri.getQueryParameter("irk")
214214
val encKeyHex = uri.getQueryParameter("enc_key")
215-
215+
216216
try {
217217
if (irkHex != null && validateHexInput(irkHex)) {
218218
val irkBytes = hexStringToByteArray(irkHex)
219219
val irkBase64 = Base64.encode(irkBytes)
220220
sharedPreferences.edit().putString("IRK", irkBase64).apply()
221221
}
222-
222+
223223
if (encKeyHex != null && validateHexInput(encKeyHex)) {
224224
val encKeyBytes = hexStringToByteArray(encKeyHex)
225225
val encKeyBase64 = Base64.encode(encKeyBytes)
226226
sharedPreferences.edit().putString("ENC_KEY", encKeyBase64).apply()
227227
}
228-
228+
229229
Toast.makeText(this, "Magic keys added successfully!", Toast.LENGTH_SHORT).show()
230230
} catch (e: Exception) {
231231
Toast.makeText(this, "Error processing magic keys: ${e.message}", Toast.LENGTH_LONG).show()
@@ -731,4 +731,4 @@ fun PermissionCard(
731731
}
732732
}
733733
}
734-
}
734+
}

android/app/src/main/java/me/kavishdevar/librepods/QuickSettingsDialogActivity.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,20 @@ import androidx.compose.ui.graphics.Color
6262
import androidx.compose.ui.graphics.graphicsLayer
6363
import androidx.compose.ui.input.pointer.pointerInput
6464
import androidx.compose.ui.platform.LocalContext
65-
import androidx.compose.ui.platform.LocalDensity
6665
import androidx.compose.ui.res.painterResource
6766
import androidx.compose.ui.text.font.FontWeight
68-
import androidx.compose.ui.unit.Dp
6967
import androidx.compose.ui.unit.dp
7068
import androidx.compose.ui.unit.sp
7169
import kotlinx.coroutines.launch
7270
import me.kavishdevar.librepods.composables.AdaptiveRainbowBrush
73-
import me.kavishdevar.librepods.composables.IconAreaSize
7471
import me.kavishdevar.librepods.composables.ControlCenterNoiseControlSegmentedButton
72+
import me.kavishdevar.librepods.composables.IconAreaSize
7573
import me.kavishdevar.librepods.composables.VerticalVolumeSlider
74+
import me.kavishdevar.librepods.constants.AirPodsNotifications
75+
import me.kavishdevar.librepods.constants.NoiseControlMode
7676
import me.kavishdevar.librepods.services.AirPodsService
7777
import me.kavishdevar.librepods.ui.theme.LibrePodsTheme
7878
import me.kavishdevar.librepods.utils.AACPManager
79-
import me.kavishdevar.librepods.utils.AirPodsNotifications
80-
import me.kavishdevar.librepods.utils.NoiseControlMode
8179
import kotlin.io.encoding.ExperimentalEncodingApi
8280
import kotlin.math.abs
8381

android/app/src/main/java/me/kavishdevar/librepods/composables/BatteryView.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ import androidx.compose.ui.res.stringResource
4747
import androidx.compose.ui.tooling.preview.Preview
4848
import androidx.compose.ui.unit.dp
4949
import me.kavishdevar.librepods.R
50+
import me.kavishdevar.librepods.constants.AirPodsNotifications
51+
import me.kavishdevar.librepods.constants.Battery
52+
import me.kavishdevar.librepods.constants.BatteryComponent
53+
import me.kavishdevar.librepods.constants.BatteryStatus
5054
import me.kavishdevar.librepods.services.AirPodsService
51-
import me.kavishdevar.librepods.utils.AirPodsNotifications
52-
import me.kavishdevar.librepods.utils.Battery
53-
import me.kavishdevar.librepods.utils.BatteryComponent
54-
import me.kavishdevar.librepods.utils.BatteryStatus
5555
import kotlin.io.encoding.ExperimentalEncodingApi
5656

5757
@Composable

android/app/src/main/java/me/kavishdevar/librepods/composables/ControlCenterNoiseControlSegmentedButton.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import androidx.compose.ui.unit.Dp
5656
import androidx.compose.ui.unit.dp
5757
import androidx.compose.ui.unit.sp
5858
import me.kavishdevar.librepods.R
59-
import me.kavishdevar.librepods.utils.NoiseControlMode
59+
import me.kavishdevar.librepods.constants.NoiseControlMode
6060

6161
private val ContainerColor = Color(0x593C3C3E)
6262
private val SelectedIndicatorColorGray = Color(0xFF6C6C6E)

android/app/src/main/java/me/kavishdevar/librepods/composables/IndependentToggle.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,4 @@ fun IndependentToggle(name: String, service: AirPodsService? = null, functionNam
127127
@Composable
128128
fun IndependentTogglePreview() {
129129
IndependentToggle("Test", AirPodsService(), "test", LocalContext.current.getSharedPreferences("preview", 0), true)
130-
}
130+
}

android/app/src/main/java/me/kavishdevar/librepods/composables/NoiseControlSettings.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ import androidx.compose.ui.unit.dp
7373
import androidx.compose.ui.unit.sp
7474
import androidx.compose.ui.zIndex
7575
import me.kavishdevar.librepods.R
76+
import me.kavishdevar.librepods.constants.AirPodsNotifications
77+
import me.kavishdevar.librepods.constants.NoiseControlMode
7678
import me.kavishdevar.librepods.services.AirPodsService
7779
import me.kavishdevar.librepods.utils.AACPManager
78-
import me.kavishdevar.librepods.utils.AirPodsNotifications
79-
import me.kavishdevar.librepods.utils.NoiseControlMode
8080
import kotlin.io.encoding.ExperimentalEncodingApi
8181
import kotlin.math.roundToInt
8282

android/app/src/main/java/me/kavishdevar/librepods/composables/PressAndHoldSettings.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package me.kavishdevar.librepods.composables
2020

21+
import android.content.Context
2122
import androidx.compose.animation.animateColorAsState
2223
import androidx.compose.animation.core.tween
2324
import androidx.compose.foundation.background
@@ -57,6 +58,7 @@ import androidx.compose.ui.unit.dp
5758
import androidx.compose.ui.unit.sp
5859
import androidx.navigation.NavController
5960
import me.kavishdevar.librepods.R
61+
import me.kavishdevar.librepods.constants.StemAction
6062

6163
@Composable
6264
fun PressAndHoldSettings(navController: NavController) {
@@ -70,6 +72,24 @@ fun PressAndHoldSettings(navController: NavController) {
7072
val animatedLeftBackgroundColor by animateColorAsState(targetValue = leftBackgroundColor, animationSpec = animationSpec)
7173
val animatedRightBackgroundColor by animateColorAsState(targetValue = rightBackgroundColor, animationSpec = animationSpec)
7274

75+
val context = LocalContext.current
76+
val sharedPreferences = context.getSharedPreferences("settings", Context.MODE_PRIVATE)
77+
78+
val leftAction = sharedPreferences.getString("left_long_press_action", StemAction.CYCLE_NOISE_CONTROL_MODES.name)
79+
val rightAction = sharedPreferences.getString("right_long_press_action", StemAction.CYCLE_NOISE_CONTROL_MODES.name)
80+
81+
val leftActionText = when (StemAction.valueOf(leftAction ?: StemAction.CYCLE_NOISE_CONTROL_MODES.name)) {
82+
StemAction.CYCLE_NOISE_CONTROL_MODES -> stringResource(R.string.noise_control)
83+
StemAction.DIGITAL_ASSISTANT -> "Digital Assistant"
84+
else -> "INVALID!!"
85+
}
86+
87+
val rightActionText = when (StemAction.valueOf(rightAction ?: StemAction.CYCLE_NOISE_CONTROL_MODES.name)) {
88+
StemAction.CYCLE_NOISE_CONTROL_MODES -> stringResource(R.string.noise_control)
89+
StemAction.DIGITAL_ASSISTANT -> "Digital Assistant"
90+
else -> "INVALID!!"
91+
}
92+
7393
Text(
7494
text = stringResource(R.string.press_and_hold_airpods).uppercase(),
7595
style = TextStyle(
@@ -122,7 +142,7 @@ fun PressAndHoldSettings(navController: NavController) {
122142
)
123143
Spacer(modifier = Modifier.weight(1f))
124144
Text(
125-
text = stringResource(R.string.noise_control),
145+
text = leftActionText,
126146
style = TextStyle(
127147
fontSize = 18.sp,
128148
color = textColor.copy(alpha = 0.6f),
@@ -182,7 +202,7 @@ fun PressAndHoldSettings(navController: NavController) {
182202
)
183203
Spacer(modifier = Modifier.weight(1f))
184204
Text(
185-
text = stringResource(R.string.noise_control),
205+
text = rightActionText,
186206
style = TextStyle(
187207
fontSize = 18.sp,
188208
color = textColor.copy(alpha = 0.6f),

android/app/src/main/java/me/kavishdevar/librepods/utils/Packets.kt renamed to android/app/src/main/java/me/kavishdevar/librepods/constants/Packets.kt

Lines changed: 2 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,18 @@
1616
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19-
20-
@file:Suppress("unused")
21-
22-
package me.kavishdevar.librepods.utils
19+
package me.kavishdevar.librepods.constants
2320

2421
import android.os.Parcelable
2522
import android.util.Log
2623
import kotlinx.parcelize.Parcelize
2724

2825
enum class Enums(val value: ByteArray) {
2926
NOISE_CANCELLATION(Capabilities.NOISE_CANCELLATION),
30-
CONVERSATION_AWARENESS(Capabilities.CONVERSATION_AWARENESS),
31-
CUSTOMIZABLE_ADAPTIVE_TRANSPARENCY(Capabilities.CUSTOMIZABLE_ADAPTIVE_TRANSPARENCY),
3227
PREFIX(byteArrayOf(0x04, 0x00, 0x04, 0x00)),
3328
SETTINGS(byteArrayOf(0x09, 0x00)),
34-
SUFFIX(byteArrayOf(0x00, 0x00, 0x00)),
35-
NOTIFICATION_FILTER(byteArrayOf(0x0f)),
36-
HANDSHAKE(byteArrayOf(0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)),
37-
SPECIFIC_FEATURES(byteArrayOf(0x4d)),
38-
SET_SPECIFIC_FEATURES(PREFIX.value + SPECIFIC_FEATURES.value + byteArrayOf(0x00,
39-
0xff.toByte(), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)),
40-
REQUEST_NOTIFICATIONS(PREFIX.value + NOTIFICATION_FILTER.value + byteArrayOf(0x00, 0xff.toByte(), 0xff.toByte(), 0xff.toByte(), 0xff.toByte())),
4129
NOISE_CANCELLATION_PREFIX(PREFIX.value + SETTINGS.value + NOISE_CANCELLATION.value),
42-
NOISE_CANCELLATION_OFF(NOISE_CANCELLATION_PREFIX.value + Capabilities.NoiseCancellation.OFF.value + SUFFIX.value),
43-
NOISE_CANCELLATION_ON(NOISE_CANCELLATION_PREFIX.value + Capabilities.NoiseCancellation.ON.value + SUFFIX.value),
44-
NOISE_CANCELLATION_TRANSPARENCY(NOISE_CANCELLATION_PREFIX.value + Capabilities.NoiseCancellation.TRANSPARENCY.value + SUFFIX.value),
45-
NOISE_CANCELLATION_ADAPTIVE(NOISE_CANCELLATION_PREFIX.value + Capabilities.NoiseCancellation.ADAPTIVE.value + SUFFIX.value),
46-
SET_CONVERSATION_AWARENESS_OFF(PREFIX.value + SETTINGS.value + CONVERSATION_AWARENESS.value + Capabilities.ConversationAwareness.OFF.value + SUFFIX.value),
47-
SET_CONVERSATION_AWARENESS_ON(PREFIX.value + SETTINGS.value + CONVERSATION_AWARENESS.value + Capabilities.ConversationAwareness.ON.value + SUFFIX.value),
4830
CONVERSATION_AWARENESS_RECEIVE_PREFIX(PREFIX.value + byteArrayOf(0x4b, 0x00, 0x02, 0x00)),
49-
START_HEAD_TRACKING(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x17, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x08, 0xA1.toByte(), 0x02, 0x42, 0x0B, 0x08, 0x0E, 0x10, 0x02, 0x1A, 0x05, 0x01, 0x40, 0x9C.toByte(), 0x00, 0x00)),
50-
STOP_HEAD_TRACKING(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x17, 0x00, 0x00, 0x00, 0x10, 0x00, 0x11, 0x00, 0x08, 0x7E.toByte(), 0x10, 0x02, 0x42, 0x0B, 0x08, 0x4E.toByte(), 0x10, 0x02, 0x1A, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00));
5131
}
5232

5333
object BatteryComponent {
@@ -156,7 +136,7 @@ class AirPodsNotifications {
156136
}
157137

158138
val name: String =
159-
when (status) {
139+
when (status) {
160140
1 -> "OFF"
161141
2 -> "ON"
162142
3 -> "TRANSPARENCY"
@@ -251,103 +231,10 @@ class AirPodsNotifications {
251231
class Capabilities {
252232
companion object {
253233
val NOISE_CANCELLATION = byteArrayOf(0x0d)
254-
val CONVERSATION_AWARENESS = byteArrayOf(0x28)
255-
val CUSTOMIZABLE_ADAPTIVE_TRANSPARENCY = byteArrayOf(0x01, 0x02)
256234
val EAR_DETECTION = byteArrayOf(0x06)
257235
}
258-
259-
enum class NoiseCancellation(val value: ByteArray) {
260-
OFF(byteArrayOf(0x01)),
261-
ON(byteArrayOf(0x02)),
262-
TRANSPARENCY(byteArrayOf(0x03)),
263-
ADAPTIVE(byteArrayOf(0x04));
264-
}
265-
266-
enum class ConversationAwareness(val value: ByteArray) {
267-
OFF(byteArrayOf(0x02)),
268-
ON(byteArrayOf(0x01));
269-
}
270-
}
271-
272-
enum class LongPressPackets(val value: ByteArray) {
273-
ENABLE_EVERYTHING(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0F, 0x00, 0x00, 0x00)),
274-
275-
DISABLE_OFF_FROM_EVERYTHING(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0e, 0x00, 0x00, 0x00)),
276-
DISABLE_OFF_FROM_TRANSPARENCY_AND_ADAPTIVE(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0c, 0x00, 0x00, 0x00)),
277-
DISABLE_OFF_FROM_TRANSPARENCY_AND_ANC(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x06, 0x00, 0x00, 0x00)),
278-
DISABLE_OFF_FROM_ADAPTIVE_AND_ANC(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0a, 0x00, 0x00, 0x00)),
279-
280-
ENABLE_OFF_FROM_TRANSPARENCY_AND_ANC(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x07, 0x00, 0x00, 0x00)),
281-
ENABLE_OFF_FROM_ADAPTIVE_AND_ANC(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0b, 0x00, 0x00, 0x00)),
282-
ENABLE_OFF_FROM_TRANSPARENCY_AND_ADAPTIVE(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0d, 0x00, 0x00, 0x00)),
283-
284-
DISABLE_TRANSPARENCY_FROM_EVERYTHING(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0b, 0x00, 0x00, 0x00)),
285-
DISABLE_TRANSPARENCY_FROM_OFF_AND_ANC(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x03, 0x00, 0x00, 0x00)),
286-
DISABLE_TRANSPARENCY_FROM_ADAPTIVE_AND_ANC(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0a, 0x00, 0x00, 0x00)),
287-
DISABLE_TRANSPARENCY_FROM_OFF_AND_ADAPTIVE(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x09, 0x00, 0x00, 0x00)),
288-
289-
ENABLE_TRANSPARENCY_FROM_OFF_AND_ANC(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x07, 0x00, 0x00, 0x00)),
290-
ENABLE_TRANSPARENCY_FROM_ADAPTIVE_AND_ANC(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0e, 0x00, 0x00, 0x00)),
291-
ENABLE_TRANSPARENCY_FROM_OFF_AND_ADAPTIVE(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0d, 0x00, 0x00, 0x00)),
292-
293-
DISABLE_ANC_FROM_EVERYTHING(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0D, 0x00, 0x00, 0x00)),
294-
DISABLE_ANC_FROM_OFF_AND_TRANSPARENCY(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x05, 0x00, 0x00, 0x00)),
295-
DISABLE_ANC_FROM_ADAPTIVE_AND_TRANSPARENCY(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0c, 0x00, 0x00, 0x00)),
296-
DISABLE_ANC_FROM_OFF_AND_ADAPTIVE(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x09, 0x00, 0x00, 0x00)),
297-
298-
ENABLE_ANC_FROM_OFF_AND_TRANSPARENCY(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x07, 0x00, 0x00, 0x00)),
299-
ENABLE_ANC_FROM_ADAPTIVE_AND_TRANSPARENCY(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0e, 0x00, 0x00, 0x00)),
300-
ENABLE_ANC_FROM_OFF_AND_ADAPTIVE(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0b, 0x00, 0x00, 0x00)),
301-
302-
DISABLE_ADAPTIVE_FROM_EVERYTHING(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x07, 0x00, 0x00, 0x00)),
303-
DISABLE_ADAPTIVE_FROM_OFF_AND_TRANSPARENCY(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x05, 0x00, 0x00, 0x00)),
304-
DISABLE_ADAPTIVE_FROM_TRANSPARENCY_AND_ANC(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x06, 0x00, 0x00, 0x00)),
305-
DISABLE_ADAPTIVE_FROM_OFF_AND_ANC(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x03, 0x00, 0x00, 0x00)),
306-
307-
ENABLE_ADAPTIVE_FROM_OFF_AND_TRANSPARENCY(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0d, 0x00, 0x00, 0x00)),
308-
ENABLE_ADAPTIVE_FROM_TRANSPARENCY_AND_ANC(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0e, 0x00, 0x00, 0x00)),
309-
ENABLE_ADAPTIVE_FROM_OFF_AND_ANC(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0b, 0x00, 0x00, 0x00)),
310-
311-
ENABLE_EVERYTHING_OFF_DISABLED(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0E, 0x00, 0x00, 0x00)),
312-
DISABLE_TRANSPARENCY_OFF_DISABLED(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0A, 0x00, 0x00, 0x00)),
313-
DISABLE_ADAPTIVE_OFF_DISABLED(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x06, 0x00, 0x00, 0x00)),
314-
DISABLE_ANC_OFF_DISABLED(byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A, 0x0C, 0x00, 0x00, 0x00)),
315236
}
316237

317-
//enum class LongPressMode {
318-
// OFF, TRANSPARENCY, ADAPTIVE, ANC
319-
//}
320-
//
321-
//data class LongPressPacket(val modes: Set<LongPressMode>) {
322-
// val value: ByteArray
323-
// get() {
324-
// val baseArray = byteArrayOf(0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x1A)
325-
// val modeByte = calculateModeByte()
326-
// return baseArray + byteArrayOf(modeByte, 0x00, 0x00, 0x00)
327-
// }
328-
//
329-
// private fun calculateModeByte(): Byte {
330-
// var modeByte: Byte = 0x00
331-
// modes.forEach { mode ->
332-
// modeByte = when (mode) {
333-
// LongPressMode.OFF -> (modeByte + 0x01).toByte()
334-
// LongPressMode.TRANSPARENCY -> (modeByte + 0x02).toByte()
335-
// LongPressMode.ADAPTIVE -> (modeByte + 0x04).toByte()
336-
// LongPressMode.ANC -> (modeByte + 0x08).toByte()
337-
// }
338-
// }
339-
// return modeByte
340-
// }
341-
//}
342-
//
343-
//fun determinePacket(changedIndex: Int, newEnabled: Boolean, oldModes: Set<LongPressMode>, newModes: Set<LongPressMode>): ByteArray? {
344-
// return if (newEnabled) {
345-
// LongPressPacket(oldModes + newModes.elementAt(changedIndex)).value
346-
// } else {
347-
// LongPressPacket(oldModes - newModes.elementAt(changedIndex)).value
348-
// }
349-
//}
350-
351238
fun isHeadTrackingData(data: ByteArray): Boolean {
352239
if (data.size <= 60) return false
353240

0 commit comments

Comments
 (0)