Skip to content

feat: optional Wake-on-Weight mode via RTC timer polling - #180

Open
Sofronio wants to merge 4 commits into
decentespresso:mainfrom
Sofronio:feat-wake-on-weight
Open

feat: optional Wake-on-Weight mode via RTC timer polling#180
Sofronio wants to merge 4 commits into
decentespresso:mainfrom
Sofronio:feat-wake-on-weight

Conversation

@Sofronio

@Sofronio Sofronio commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Implements the optional Wake-on-Weight mode from #173: after deep sleep, an
RTC timer wakes the scale for a brief load-cell check and either goes back
to sleep (nothing placed) or continues into a full normal boot (weight
placed).

Design (as validated on hardware)

  • User setting: Power menu row WakeOnWeight o/2/3/4 (o = off; 2/3/4 =
    detection interval in seconds), NVS key wow_interval, defaults to off.
  • Tick: every interval the chip wakes from deep sleep (RTC timer,
    coexists with the existing EXT1 button/charging wake), downclocks to the
    20 MHz minimum, raises the main switched rail (PWR_CTRL), reads one
    raw ADS1232 conversion at 10 SPS, and compares |raw − baseline| against a
    50 g-equivalent threshold stored in RTC_DATA_ATTR at sleep entry.
  • Measured bring-up facts (V8.1, two units): the first DRDY after rail
    power arrives ~415 ms, so a tick costs ~850 ms end to end (≈300 ms boot +
    100 ms settle + ~415 ms read). 0.5/1 s intervals are physically wasteful;
    the menu therefore offers 2/3/4 s.
  • Safety: never arms on low battery, inert until calibrated (signed
    calibration factors handled via fabsf), charging allowed, ticks never
    touch NVS or read the battery, and on weight detection the boot frequency
    is restored before continuing the normal setup() flow (boot tare zeroes
    whatever was placed).
  • New file include/wake_on_weight.h holds the micro-wake, baseline capture
    and timer arming; power.h's esp32_sleep() gained two hooks. First use
    of RTC_DATA_ATTR in the repo.
  • Contract test tools/test_wake_on_weight_contract.py pins the source
    structure; docs in docs/wake-on-weight.md (incl. estimated power budget
    pending ammeter measurement).

Testing

  • Builds: esp32s3, esp32s3-grinder, esp32s3-energy-menu all green.
  • Contract suite + regressions (menu/storage/energy/soft-sleep/charging
    contracts) all green.
  • Hardware bench on two V8.1 units: sleep → tick → empty-scale drift stays
    well under threshold; placing a weight wakes the scale into a normal full
    boot; button wake coexists with ticks; no crashes.

Sofronio and others added 4 commits September 6, 2026 11:37
After deep sleep, an RTC timer wakes the scale on a user-selectable
interval (0.5/1/2 s or off, Power menu 'Wake:' row, NVS wow_interval);
the micro-wakeup powers the load-cell rail, reads one raw ADS1232
conversion at 10 SPS, and either re-enters deep sleep (|raw - baseline|
under a 50 g-equivalent threshold stored in RTC_DATA_ATTR at sleep
entry) or falls through to a full normal boot. Disabled on low battery,
inert until calibrated; charging allowed; button/charging EXT1 wake
unchanged.

Co-Authored-By: Claude <[email protected]>
Changes validated on V8.1 hardware (two units):
- rail settle 100 ms and a 900 ms read window: the first ADS1232
  DRDY after rail power arrives ~415 ms at 10 SPS; the original
  250 ms window never caught a sample
- run the micro-wake at the 20 MHz minimum and restore the boot
  frequency (240 MHz) before continuing into a full boot on weight
  detection (getCpuFrequencyMhz already returns MHz)
- threshold uses fabsf of the calibration factor (signed factors
  otherwise collapsed to the 500-count floor)
- arm the RTC timer only after baseline capture, and gate the timer
  disable on having enabled it this boot (avoids ESP-IDF
  'Incorrect wakeup source' noise on ordinary sleeps)
- menu setting back to a cycling row: Off / 2s / 3s / 4s; interval
  is snapshotted into RTC memory at sleep entry

Co-Authored-By: Claude <[email protected]>
Row cycles o/2/3/4 (off / interval seconds); the press confirmation
message keeps the unit (Off/2s/3s/4s).

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants