Skip to content
This repository was archived by the owner on Jul 31, 2026. It is now read-only.

Commit 6ea4100

Browse files
perf(filter): faster weight response — level 1 software tuning (10Hz HX711)
Reduces display lag from ~3-4s to ~0.8-1s without hardware changes: - EMA_ALPHA_FINE 0.04 → 0.18 (TC: 2.5s → 0.56s at 10Hz) - EMA_ALPHA_FAST 0.10 → 0.35 (snappy spool placement detection) - MEDIAN_WINDOW 15 → 5 (buffer: 1.5s → 0.5s) - STABLE_WINDOW 2000 → 1200ms (0.8s saved per weighing) - STABLE_EPSILON 0.6 → 0.8g (slightly relaxed for faster settle) - WS_UPDATE 250 → 100ms (10Hz display refresh) Level 2 (80Hz RATE pin): same constants, just delay(10)→delay(2). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a81b7f4 commit 6ea4100

1 file changed

Lines changed: 29 additions & 28 deletions

File tree

‎src/main.cpp‎

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212
// §3 FORWARD DECLARATIONS 147– 226
1313
// §4 WEIGHT ROUNDING 227– 246
1414
// §5 GLOBAL OBJECTS 247– 260
15-
// §6 CONFIGURATION VARIABLES 261– 447
16-
// §7 OLED DISPLAY 448– 565
17-
// §8 CLOUD PARSING 566– 580
18-
// §9 WIFI SETUP 581– 853
19-
// §10 LITTLEFS 854– 898
20-
// §11 FIREBASE AUTHENTICATION 899– 1092
21-
// §12 FIRESTORE SCALE HEARTBEAT & SYNC 1093– 2057
22-
// §13 WEBSOCKET 2058– 2084
23-
// §14 5 — CLOUD WORKER TASK (non-blocking Firestore on core 0) 2085– 2119
24-
// §15 5 — UNIFIED WS FRAME BUILDER 2120– 2158
25-
// §16 WEIGHT FILTER HELPERS 2159– 2173
26-
// §17 POST-SEND STATE RESET (shared by all send paths) 2174– 2192
27-
// §18 SHARED WEIGHT PUSH HANDLER (used by /api/weight and /api/push-weight) 2193– 2265
28-
// §19 WEB SERVER 2266– 2965
29-
// §20 CLOUD COMMUNICATION 2966– 3148
30-
// §21 WEIGH WORKFLOW (IDLE → SCANNING → STABLE_WAIT → SENDING) 3149– 3364
31-
// §22 mDNS 3365– 3402
32-
// §23 SCALE 3403– 3494
33-
// §24 RFID 3495– 3824
34-
// §25 OTA — Over-the-air firmware + filesystem update 3825– 4193
35-
// §26 SETUP & LOOP 4194– 4566
15+
// §6 CONFIGURATION VARIABLES 261– 448
16+
// §7 OLED DISPLAY 449– 566
17+
// §8 CLOUD PARSING 567– 581
18+
// §9 WIFI SETUP 582– 854
19+
// §10 LITTLEFS 855– 899
20+
// §11 FIREBASE AUTHENTICATION 900– 1093
21+
// §12 FIRESTORE SCALE HEARTBEAT & SYNC 1094– 2058
22+
// §13 WEBSOCKET 2059– 2085
23+
// §14 5 — CLOUD WORKER TASK (non-blocking Firestore on core 0) 2086– 2120
24+
// §15 5 — UNIFIED WS FRAME BUILDER 2121– 2159
25+
// §16 WEIGHT FILTER HELPERS 2160– 2174
26+
// §17 POST-SEND STATE RESET (shared by all send paths) 2175– 2193
27+
// §18 SHARED WEIGHT PUSH HANDLER (used by /api/weight and /api/push-weight) 2194– 2266
28+
// §19 WEB SERVER 2267– 2966
29+
// §20 CLOUD COMMUNICATION 2967– 3149
30+
// §21 WEIGH WORKFLOW (IDLE → SCANNING → STABLE_WAIT → SENDING) 3150– 3365
31+
// §22 mDNS 3366– 3403
32+
// §23 SCALE 3404– 3495
33+
// §24 RFID 3496– 3825
34+
// §25 OTA — Over-the-air firmware + filesystem update 3826– 4194
35+
// §26 SETUP & LOOP 4195– 4567
3636
//
3737
// To regenerate this block: ./scripts/update_toc.sh
3838
// ─── TOC END ───────────────────────────────────────────────
@@ -78,7 +78,7 @@
7878
#define SERVO_PIN 26
7979
#define LED_PIN 2
8080

81-
#define WS_UPDATE_INTERVAL_MS 250
81+
#define WS_UPDATE_INTERVAL_MS 100 // was 250ms — 10 Hz display, kitchen-scale feel
8282

8383
// Set to 1 to enable verbose RFID page dumps on Serial
8484
#define DEBUG_RFID_DUMP 0
@@ -355,16 +355,17 @@ bool idleAutoTareArmed = true; // Rearm only after leaving near-ze
355355
uint32_t lowWeightSinceMs = 0; // Anti-stuck timer when near empty
356356

357357
// Auto-push configuration
358-
const float STABLE_EPSILON_G = 0.6f;
359-
const uint32_t STABLE_WINDOW_MS = 2000;
358+
const float STABLE_EPSILON_G = 0.8f; // was 0.6 — slightly relaxed for faster settle
359+
const uint32_t STABLE_WINDOW_MS = 1200; // was 2000ms — 0.8s saved on every weighing
360360
const float MIN_WEIGHT_TO_SEND_G = 5.0f;
361361
const float RESEND_DELTA_G = 3.0f;
362362
const uint32_t RESEND_COOLDOWN_MS = 15000;
363363

364-
// Weight filter configuration
365-
const float EMA_ALPHA_FINE = 0.04f;
366-
const float EMA_ALPHA_FAST = 0.10f;
367-
const int MEDIAN_WINDOW_LARGE = 15;
364+
// Weight filter configuration — tuned for 10 Hz HX711, kitchen-scale feel
365+
// Level 2 (80 Hz RATE pin): keep same alphas, just change delay(10)→delay(2)
366+
const float EMA_ALPHA_FINE = 0.18f; // was 0.04 — TC: 2.5s→0.56s at 10Hz
367+
const float EMA_ALPHA_FAST = 0.35f; // was 0.10 — snappy on spool placement
368+
const int MEDIAN_WINDOW_LARGE = 5; // was 15 — buffer: 1.5s→0.5s at 10Hz
368369
const float HYSTERESIS_THRESHOLD = 0.5f;
369370
const float DEAD_ZONE_G = 1.0f;
370371
const uint32_t STABLE_DISPLAY_MS = 1500;

0 commit comments

Comments
 (0)