Skip to content

Commit aa7d55a

Browse files
committed
leds: respect brightness setting and master toggle in achievement flash
Flash peaked at raw 1f brightness and left it there: the restore frame matched the writer's stale dedup cache and got skipped, so LEDs stuck at full white after an unlock. Flash now scales to the configured brightness, requires the master toggle, invalidates the writer cache before restoring, and suppresses ambient frames while flashing. stop() cancels an in-flight flash. Achievement Flash setting hides with the master toggle off.
1 parent 0f0e202 commit aa7d55a

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

app/src/main/kotlin/com/nendo/argosy/hardware/AmbientLedManager.kt

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ class AmbientLedManager @Inject constructor(
145145
fun stop() {
146146
Log.i(TAG, "Stopping ambient LED manager")
147147
stopAudioCapture()
148+
flashJob?.cancel()
149+
flashActive = false
148150
ledController.setEnabled(false)
149151
}
150152

@@ -301,36 +303,38 @@ class AmbientLedManager @Inject constructor(
301303
}
302304

303305
private var flashJob: Job? = null
306+
@Volatile private var flashActive = false
304307

305308
fun flashAchievement(isHardcore: Boolean) {
306-
if (!ledController.isAvailable || !achievementFlashEnabled) return
309+
if (!ledController.isAvailable || !isEnabled || !achievementFlashEnabled) return
307310

308311
flashJob?.cancel()
309312
flashJob = scope.launch {
310-
val flashColor = if (isHardcore) {
311-
Color(0xFFFFE566) // Bright gold/yellow for hardcore
312-
} else {
313-
Color(0xFFFFAA44) // Bright orange for casual
314-
}
313+
flashActive = true
314+
val flashColor = if (isHardcore) HARDCORE_FLASH_COLOR else CASUAL_FLASH_COLOR
315+
val peak = brightnessScalar
316+
val dim = 0.2f * brightnessScalar
315317

316318
repeat(3) {
317319
ledController.setColor(flashColor)
318-
ledController.setBrightness(1f)
320+
ledController.setBrightness(peak)
319321
delay(150)
320-
ledController.setBrightness(0.2f)
322+
ledController.setBrightness(dim)
321323
delay(100)
322324
}
323325

324-
ledController.setBrightness(1f)
325-
delay(50)
326-
326+
flashActive = false
327+
writerCacheStale = true
327328
if (isEnabled) {
328329
updateLeds()
330+
} else {
331+
ledController.setEnabled(false)
329332
}
330333
}
331334
}
332335

333336
private fun updateLeds() {
337+
if (flashActive) return
334338
val currentState = _state.value
335339
val (leftColor, rightColor) = when (currentState.context) {
336340
AmbientLedContext.ARGOSY_UI, AmbientLedContext.GAME_HOVER -> {
@@ -357,12 +361,20 @@ class AmbientLedManager @Inject constructor(
357361
ledFrames.trySend(LedFrame(leftColor, rightColor, brightness))
358362
}
359363

364+
@Volatile private var writerCacheStale = false
365+
360366
private fun startLedWriter() {
361367
scope.launch(Dispatchers.IO) {
362368
var lastLeft: Color? = null
363369
var lastRight: Color? = null
364370
var lastBrightness = -1f
365371
for (frame in ledFrames) {
372+
if (writerCacheStale) {
373+
writerCacheStale = false
374+
lastLeft = null
375+
lastRight = null
376+
lastBrightness = -1f
377+
}
366378
val colorChanged = lastLeft == null || lastRight == null ||
367379
colorDelta(lastLeft, frame.left) > COLOR_EPSILON ||
368380
colorDelta(lastRight, frame.right) > COLOR_EPSILON
@@ -513,5 +525,7 @@ class AmbientLedManager @Inject constructor(
513525
private const val MIN_WRITE_INTERVAL_MS = 33L
514526
private const val COLOR_EPSILON = 0.012f
515527
private const val BRIGHTNESS_EPSILON = 0.01f
528+
private val HARDCORE_FLASH_COLOR = Color(0xFFFFE566)
529+
private val CASUAL_FLASH_COLOR = Color(0xFFFFAA44)
516530
}
517531
}

app/src/main/kotlin/com/nendo/argosy/ui/screens/settings/sections/AmbientLedSection.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ internal sealed class AmbientLedItem(
4242
visibleWhen = { it.ambientLedEnabled })
4343
data object CustomColorHue : AmbientLedItem("customColorHue", "general",
4444
visibleWhen = { it.ambientLedEnabled && it.ambientLedCustomColor })
45-
data object AchievementFlash : AmbientLedItem("achievementFlash", "general")
45+
data object AchievementFlash : AmbientLedItem("achievementFlash", "general",
46+
visibleWhen = { it.ambientLedEnabled })
4647

4748
// Cover Art
4849
data object CoverArtColors : AmbientLedItem("coverArtColors", "coverArt",

0 commit comments

Comments
 (0)