Skip to content

Commit 066f394

Browse files
committed
Revert "fw/services/light: prime ALS across wake interaction windows"
This reverts commit dcb88c8. Signed-off-by: Joshua Jun <lets@throw.rocks>
1 parent b728afe commit 066f394

1 file changed

Lines changed: 1 addition & 69 deletions

File tree

src/fw/services/light/service.c

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -114,49 +114,8 @@ static uint32_t s_als_cached_level;
114114
static RtcTicks s_als_cached_ticks; // 0 = invalid
115115
#define ALS_CACHE_TTL_TICKS (RTC_TICKS_HZ) // 1 second
116116

117-
//! Event-gated continuous ALS:
118-
//!
119-
//! Wake-related entry points call prv_als_prime_for_interaction(), which (if
120-
//! not already primed) takes a single ambient_light_prime() refcount and
121-
//! starts a release timer for ALS_PRIME_HOLDOFF_MS. Each subsequent wake-y
122-
//! call rearms the timer. When it eventually fires, we drop the prime so the
123-
//! sensor goes back to idle.
124-
//!
125-
//! While primed, the W1160 runs in continuous mode: ALS reads collapse to a
126-
//! plain register read once one IT has elapsed, and the cache hits more often
127-
//! because reads are cheap enough that callers don't gate on them. The
128-
//! holdoff is sized to cover typical multi-wake patterns ("raise wrist, lower,
129-
//! raise again a few seconds later") so we keep sampling across them rather
130-
//! than re-paying the first-IT wait per wake.
131-
static TimerID s_als_prime_release_timer_id;
132-
static bool s_als_primed;
133-
#define ALS_PRIME_HOLDOFF_MS (5000)
134-
135117
static void prv_change_state(BacklightState new_state);
136118

137-
//! Timer callback: holdoff expired, drop the prime so the W1160 stops
138-
//! integrating in the background. Runs on the new_timer task.
139-
static void prv_als_prime_release_callback(void *data) {
140-
mutex_lock(s_mutex);
141-
if (s_als_primed) {
142-
s_als_primed = false;
143-
ambient_light_release();
144-
}
145-
mutex_unlock(s_mutex);
146-
}
147-
148-
//! Open or extend an "interaction window" during which the W1160 is held in
149-
//! continuous-sampling mode. Call from any wake-event-y entry point before
150-
//! consulting ALS. Caller must hold s_mutex.
151-
static void prv_als_prime_for_interaction(void) {
152-
if (!s_als_primed) {
153-
s_als_primed = true;
154-
ambient_light_prime();
155-
}
156-
new_timer_start(s_als_prime_release_timer_id, ALS_PRIME_HOLDOFF_MS,
157-
prv_als_prime_release_callback, NULL, 0 /* flags */);
158-
}
159-
160119
static uint32_t prv_get_als_level(void) {
161120
RtcTicks now = rtc_get_ticks();
162121
const bool cache_valid =
@@ -260,15 +219,6 @@ static void prv_change_brightness(uint8_t new_brightness) {
260219
// Scale the 0-100% to the maximum value allowed in hardware
261220
uint8_t scaled_brightness = (new_brightness * (uint16_t)BOARD_CONFIG.backlight_on_percent) / 100U;
262221

263-
// Bleed-through gate around backlight 0↔on edges: while the LED is
264-
// illuminating the cover glass, the W1160 photodiode would latch
265-
// contaminated readings even though our cache pins to the pre-on value.
266-
// Suspending stops integration entirely, so the chip preserves the last
267-
// clean DATA_ALS until we resume. No-op while not primed (driver
268-
// composes suspend with the prime refcount).
269-
const bool turning_on = (s_current_brightness == 0U) && (new_brightness > 0U);
270-
const bool turning_off = (s_current_brightness > 0U) && (new_brightness == 0U);
271-
272222
if (new_brightness == 0U) {
273223
PBL_ANALYTICS_TIMER_STOP(backlight_on_time_ms);
274224
} else {
@@ -277,13 +227,7 @@ static void prv_change_brightness(uint8_t new_brightness) {
277227

278228
prv_update_intensity_analytics(scaled_brightness);
279229

280-
if (turning_on) {
281-
ambient_light_suspend();
282-
}
283230
backlight_set_brightness(scaled_brightness);
284-
if (turning_off) {
285-
ambient_light_resume();
286-
}
287231
s_current_brightness = new_brightness;
288232

289233
#ifdef CONFIG_BACKLIGHT_HAS_COLOR
@@ -386,6 +330,7 @@ static bool prv_light_allowed(void) {
386330
void light_init(void) {
387331
s_light_state = LIGHT_STATE_OFF;
388332
s_current_brightness = 0;
333+
s_timer_id = new_timer_create();
389334
s_num_buttons_down = 0;
390335
s_user_controlled_state = false;
391336
s_fade_start_intensity = 0;
@@ -400,13 +345,6 @@ void light_init(void) {
400345

401346
s_als_cached_level = 0;
402347
s_als_cached_ticks = 0;
403-
404-
// Create the ALS release timer before the fade timer so existing tests that
405-
// pluck the most-recently-created idle timer (test_light.c:149) still pick
406-
// up s_timer_id.
407-
s_als_prime_release_timer_id = new_timer_create();
408-
s_als_primed = false;
409-
s_timer_id = new_timer_create();
410348
}
411349

412350
void light_button_pressed(void) {
@@ -418,8 +356,6 @@ void light_button_pressed(void) {
418356
s_num_buttons_down = 0;
419357
}
420358

421-
prv_als_prime_for_interaction();
422-
423359
// set the state to be on; releasing buttons will start the timer counting down
424360
if (prv_light_allowed()) {
425361
prv_change_state(LIGHT_STATE_ON);
@@ -456,8 +392,6 @@ void light_enable_interaction(void) {
456392
return;
457393
}
458394

459-
prv_als_prime_for_interaction();
460-
461395
if (prv_light_allowed()) {
462396
prv_change_state(LIGHT_STATE_ON_TIMED);
463397
} else {
@@ -495,7 +429,6 @@ void light_enable_respect_settings(bool enable) {
495429
s_user_controlled_state = enable;
496430

497431
if (enable) {
498-
prv_als_prime_for_interaction();
499432
if (prv_light_allowed()) {
500433
prv_change_state(LIGHT_STATE_ON);
501434
}
@@ -579,7 +512,6 @@ static void prv_light_reset_to_timed_mode(void) {
579512

580513
if (s_user_controlled_state) {
581514
s_user_controlled_state = false;
582-
prv_als_prime_for_interaction();
583515
if (prv_light_allowed()) {
584516
prv_change_state(LIGHT_STATE_ON_TIMED);
585517
}

0 commit comments

Comments
 (0)