Skip to content

Commit de82cdd

Browse files
authored
android(fix): parse and send hearing aid data properly (#286)
1 parent a06c673 commit de82cdd

File tree

2 files changed

+73
-106
lines changed

2 files changed

+73
-106
lines changed

android/app/src/main/java/me/kavishdevar/librepods/screens/HearingAidAdjustmentsScreen.kt

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,10 @@ fun HearingAidAdjustmentsScreen(@Suppress("unused") navController: NavController
9696
val toneSliderValue = remember { mutableFloatStateOf(0.5f) }
9797
val ambientNoiseReductionSliderValue = remember { mutableFloatStateOf(0.0f) }
9898
val conversationBoostEnabled = remember { mutableStateOf(false) }
99-
val eq = remember { mutableStateOf(FloatArray(8)) }
99+
val leftEQ = remember { mutableStateOf(FloatArray(8)) }
100+
val rightEQ = remember { mutableStateOf(FloatArray(8)) }
100101
val ownVoiceAmplification = remember { mutableFloatStateOf(0.5f) }
101102

102-
val phoneMediaEQ = remember { mutableStateOf(FloatArray(8) { 0.5f }) }
103-
val phoneEQEnabled = remember { mutableStateOf(false) }
104-
val mediaEQEnabled = remember { mutableStateOf(false) }
105-
106103
val initialLoadComplete = remember { mutableStateOf(false) }
107104

108105
val initialReadSucceeded = remember { mutableStateOf(false) }
@@ -111,8 +108,8 @@ fun HearingAidAdjustmentsScreen(@Suppress("unused") navController: NavController
111108
val hearingAidSettings = remember {
112109
mutableStateOf(
113110
HearingAidSettings(
114-
leftEQ = eq.value,
115-
rightEQ = eq.value,
111+
leftEQ = leftEQ.value,
112+
rightEQ = rightEQ.value,
116113
leftAmplification = amplificationSliderValue.floatValue + (0.5f - balanceSliderValue.floatValue) * amplificationSliderValue.floatValue * 2,
117114
rightAmplification = amplificationSliderValue.floatValue + (balanceSliderValue.floatValue - 0.5f) * amplificationSliderValue.floatValue * 2,
118115
leftTone = toneSliderValue.floatValue,
@@ -157,7 +154,8 @@ fun HearingAidAdjustmentsScreen(@Suppress("unused") navController: NavController
157154
toneSliderValue.floatValue = parsed.leftTone
158155
ambientNoiseReductionSliderValue.floatValue = parsed.leftAmbientNoiseReduction
159156
conversationBoostEnabled.value = parsed.leftConversationBoost
160-
eq.value = parsed.leftEQ.copyOf()
157+
leftEQ.value = parsed.leftEQ.copyOf()
158+
rightEQ.value = parsed.rightEQ.copyOf()
161159
ownVoiceAmplification.floatValue = parsed.ownVoiceAmplification
162160
Log.d(TAG, "Updated hearing aid settings from notification")
163161
} else {
@@ -192,8 +190,8 @@ fun HearingAidAdjustmentsScreen(@Suppress("unused") navController: NavController
192190
}
193191

194192
hearingAidSettings.value = HearingAidSettings(
195-
leftEQ = eq.value,
196-
rightEQ = eq.value,
193+
leftEQ = leftEQ.value,
194+
rightEQ = rightEQ.value,
197195
leftAmplification = amplificationSliderValue.floatValue + if (balanceSliderValue.floatValue < 0) -balanceSliderValue.floatValue else 0f,
198196
rightAmplification = amplificationSliderValue.floatValue + if (balanceSliderValue.floatValue > 0) balanceSliderValue.floatValue else 0f,
199197
leftTone = toneSliderValue.floatValue,
@@ -216,26 +214,6 @@ fun HearingAidAdjustmentsScreen(@Suppress("unused") navController: NavController
216214
attManager.enableNotifications(ATTHandles.HEARING_AID)
217215
attManager.registerListener(ATTHandles.HEARING_AID, hearingAidATTListener)
218216

219-
try {
220-
if (aacpManager != null) {
221-
Log.d(TAG, "Found AACPManager, reading cached EQ data")
222-
val aacpEQ = aacpManager.eqData
223-
if (aacpEQ.isNotEmpty()) {
224-
eq.value = aacpEQ.copyOf()
225-
phoneMediaEQ.value = aacpEQ.copyOf()
226-
phoneEQEnabled.value = aacpManager.eqOnPhone
227-
mediaEQEnabled.value = aacpManager.eqOnMedia
228-
Log.d(TAG, "Populated EQ from AACPManager: ${aacpEQ.toList()}")
229-
} else {
230-
Log.d(TAG, "AACPManager EQ data empty")
231-
}
232-
} else {
233-
Log.d(TAG, "No AACPManager available")
234-
}
235-
} catch (e: Exception) {
236-
Log.w(TAG, "Error reading EQ from AACPManager: ${e.message}")
237-
}
238-
239217
var parsedSettings: HearingAidSettings? = null
240218
for (attempt in 1..3) {
241219
initialReadAttempts.intValue = attempt
@@ -261,7 +239,8 @@ fun HearingAidAdjustmentsScreen(@Suppress("unused") navController: NavController
261239
toneSliderValue.floatValue = parsedSettings.leftTone
262240
ambientNoiseReductionSliderValue.floatValue = parsedSettings.leftAmbientNoiseReduction
263241
conversationBoostEnabled.value = parsedSettings.leftConversationBoost
264-
eq.value = parsedSettings.leftEQ.copyOf()
242+
leftEQ.value = parsedSettings.leftEQ.copyOf()
243+
rightEQ.value = parsedSettings.rightEQ.copyOf()
265244
ownVoiceAmplification.floatValue = parsedSettings.ownVoiceAmplification
266245
initialReadSucceeded.value = true
267246
} else {

0 commit comments

Comments
 (0)