Wake the screen on wear faster after charging

This commit is contained in:
James Babcock committed 2026-09-28 12:04:15 -07:00
1 parent 2052e268b0
commit deaa93fead
5 files changed
+71 -9

No files matched your search

@@ -1364,10 +1364,15 @@ class GlassesSessionCore(
else
null
var emitWearState = false
var putOnWhileCharging = false
var event: G2Event? = null
monitor.withLock {
lastIncomingAtMs = now()
if (decodedWearState >= 0 && decodedWearState != wearState) {
// An observed OFF_HEAD -> ON_HEAD means charging is over, up
// to CHARGING_BATTERY_POLL_MS before a battery poll would say
// so. Like TS's put-on wake, a first snapshot doesn't count.
putOnWhileCharging = chargingMode && wearState == 0 && decodedWearState == 1
wearState = decodedWearState
emitWearState = true
}
@@ -1540,6 +1545,11 @@ class GlassesSessionCore(
logLine(if (decodedWearState > 0) "wear state ON_HEAD" else "wear state OFF_HEAD")
emitWearState(decodedWearState > 0)
}
if (putOnWhileCharging) {
// After the emit, so TS sees the put-on while still in its
// charging phase and wakes once the rebuilt session is ready.
monitor.withLock { endChargingModeLocked("glasses put on while charging") }
}
if (compassEvent != null) {
emitCompassEvent(compassEvent)
}
@@ -1649,6 +1659,12 @@ class GlassesSessionCore(
// Connect sequence (worker thread)
internal fun connectLoopOnce() {
monitor.withLock {
// TS treats a wear snapshot as per-transport and forgets it on a
// reconnect; forget ours too, or the new session's first report
// (the CFW query reply) is deduped away and TS never relearns it.
wearState = -1
}
setStateDisplay("connecting", "Connecting to the glasses...")
try {
connectArm(rightAddress, true)
@@ -1003,12 +1003,24 @@ internal fun GlassesSessionCore.updateChargingModeLocked(charging: Boolean, batt
logLine("glasses are charging; pausing display communication")
setStateDisplay("charging", GlassesSessionCore.chargingStatusText(battery))
} else {
chargingMode = false
logLine("glasses removed from charger; reconnecting")
handleTransportFailure("charging ended")
endChargingModeLocked("glasses removed from charger")
}
}
/**
* Leave charging mode, whether a battery poll or putting the glasses on
* (they can't be worn in the case) said charging is over. The rebuild goes
* through the normal reconnect loop.
*/
internal fun GlassesSessionCore.endChargingModeLocked(why: String) {
if (!chargingMode) {
return
}
chargingMode = false
logLine("$why; reconnecting")
handleTransportFailure("charging ended")
}
/**
* Record, into the frame that is waiting, why it did not go out on this
* pass of the send loop. Without this the export shows a bare multi-second