Skip to content

feat(lib): swap ADC implementation#60

Merged
tadelv merged 4 commits into
mainfrom
feat/adc-lib
May 27, 2026
Merged

feat(lib): swap ADC implementation#60
tadelv merged 4 commits into
mainfrom
feat/adc-lib

Conversation

@tadelv
Copy link
Copy Markdown
Collaborator

@tadelv tadelv commented May 26, 2026

switch ADC implementation to the common open sourced one.

Experimental, while it might potentially improve things, the change is not tested enough yet.

@tadelv tadelv requested a review from Sofronio May 26, 2026 19:02
tadelv and others added 2 commits May 27, 2026 08:45
Pin decentespresso/ADS1232_ADC to the reviewed/tested commit (lib has no
semver tags; unpinned URL = non-reproducible builds). Document the new
external-lib layout and its footguns: polling-mode only (its FreeRTOS task
pins core 1, same as AsyncTCP), setSamplesInUse() buffer-wipe blip, and the
zero-filled USB debug bytes.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Picks up decentespresso/ADS1232_ADC 17703305 — conversion timing now
measures the true inter-sample interval (reports ~10 SPS) instead of the
bit-bang read duration (bogus ~11kHz). Verified on hardware.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@tadelv tadelv merged commit a647cc7 into main May 27, 2026
skialpine added a commit to skialpine/openscale that referenced this pull request May 27, 2026
Rebased onto current main (post decentespresso#58 WS-OOM gate, post decentespresso#60 ADC library
swap) and restructured from the original "embed telemetry in status"
shape to deliver telemetry out-of-band, so apps that don't care about
diagnostics (on-device UI, decentespresso app, third-party scale apps)
aren't paying ~21% extra bytes on every status broadcast tick.

The collection bits — SoC die-temperature sampler, weight-stall watchdog,
ADC recovery counter widened to volatile uint32_t, reset-reason capture
at boot, StopWatch-tear-fix timer snapshot — are unchanged from review-
round-2.

Wire-protocol delivery is reorganized into three frames:

  session_info  one-shot, server→client on WS_EVT_CONNECT. Carries the
                fields immutable for the connection (protocol_version,
                firmware_version, reset_reason). Clients no longer have
                to ask for these.

  debug events  broadcast on diagnostic-relevant change. Emitted by:
                  - sendWebsocketDebugStall(true)  on stall onset
                  - sendWebsocketDebugStall(false) on stall resume
                  - sendWebsocketDebugAdcRecovery() on ADC power-cycle
                  - sendWebsocketDebugTempPeak()    on new SoC max temp
                Subscribers see the event the moment it happens; non-
                subscribers ignore the unknown type. No periodic
                broadcast — temp_peak fires at most once per warm-up
                curve, stall_*/adc_recovery only on real events.

  debug reply   on-request snapshot per-client. Send {"command":"debug"}
                (also accepted: "diag") and the server replies with the
                full diagnostic set (current/peak temp, stall state +
                count + last, recovery count). Per-client, not a
                broadcast — no heap cost for other clients.

All event broadcasts go through the existing wsBroadcastHeapOk() gate
(PR decentespresso#58). Per-client sends don't need it (one allocation, not one-per-
client).

Net effect:

  - Status frame stays at its current 16 fields (≈310 B payload). Apps
    that don't care about diagnostics get back ~21% per status broadcast
    — meaningful under multi-client load where allocations stack.
  - Diagnostic consumers (soak tools, debug dashboards, this PR's own
    thermal_load_test.sh) get *immediate* notification of stall /
    recovery events instead of waiting up to 5 s for the next status.
  - session_info means clients no longer have to roundtrip a status
    request just to learn reset_reason after reconnect.

Also includes:

  - Updated ADS1232 debug callback for the new library's field set
    (rebased from old API; the old dataMin/Max/Avg/StdDev /
    tareInProgress/tareTimes are gone in the upstream lib). Callback
    stays dormant by default (registered but setDebugEnabled(false) is
    the default in the lib).
  - StopWatch read-tear fix: sendWebsocketStatus and StatusAll now read
    g_timerRunning/g_timerElapsed (snapshotted once per main-loop pass)
    instead of touching stopWatch directly from the AsyncTCP task.
  - CLAUDE.md: "Fixing bugs you find along the way" guidance from
    review round 2.
  - README.md: full documentation of session_info + debug frames.
  - tools/thermal_load_test.sh: 1-hour multi-protocol soak runner.

Build verified clean on esp32s3 (RAM 17.2%, Flash 45.5%).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant