Commit 74d7f0f
fix: review feedback — volatile cross-task globals, atomic mask replace
Code review on PR decentespresso#54 caught two real bugs in the deferred-action fix:
1. The pending-mask let opposing actions accumulate. If a client sent
"display off" then "display on" before the main loop drained, both
bits were set and processWsPendingCmds ran them in source order —
final hardware ended up off while b_u8g2Sleep reported on. Add a
wsReplacePending(set, clear) helper that atomically supersedes
the opposing bit, and use it for the three mutually-exclusive
pairs (display, low_power, sleep).
2. The new WS state globals (weightWebsocketNotifyInterval,
b_websocketEventsEnabled, b_websocketLowPower/LedEnabled,
i_websocketLedR/G/B, t_lastWebsocketStatusUpdate) and the pre-
existing b_softSleep / b_u8g2Sleep / b_powerOff that are now
written from the AsyncTCP task are missing `volatile`. On dual-
core ESP32-S3 the compiler may cache stale values in a register
on the loop core across the WS gate check. Mark them volatile.
Also fold in smaller doc/format cleanups from the same review:
* Cast stopWatch.elapsed() (uint32_t) to (unsigned long) for the
%lu format spec in sendWebsocketStatus / sendWebsocketStatusAll.
Works today on ESP32 (both 32-bit) but technically a type
mismatch.
* Correct the wsQueuePending doc-comment (StopWatch is safe to
mutate inline; only u8g2 and power-rail GPIOs need deferring).
* Correct the processWsPendingCmds comment to note that
b_powerOff is set here on purpose.
* README: document the JSON rate forms accepted by the parser
that weren't listed (rate_hz, hz, interval_ms).
Re-verified:
* 60/60 WS feature regression PASS
* 120s freeze stress: max weight gap 0.60s (was 4.18s pre-fix),
0 HTTP failures, 0 slow, 590 commands sent
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 1051681 commit 74d7f0f
3 files changed
Lines changed: 48 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
71 | 74 | | |
72 | 75 | | |
73 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
| |||
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
68 | | - | |
| 71 | + | |
| 72 | + | |
69 | 73 | | |
70 | 74 | | |
71 | 75 | | |
| |||
91 | 95 | | |
92 | 96 | | |
93 | 97 | | |
94 | | - | |
| 98 | + | |
| 99 | + | |
95 | 100 | | |
96 | 101 | | |
97 | 102 | | |
| |||
106 | 111 | | |
107 | 112 | | |
108 | 113 | | |
109 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
110 | 117 | | |
111 | 118 | | |
112 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
485 | 485 | | |
486 | 486 | | |
487 | 487 | | |
488 | | - | |
| 488 | + | |
| 489 | + | |
489 | 490 | | |
490 | 491 | | |
491 | 492 | | |
492 | 493 | | |
493 | 494 | | |
494 | 495 | | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
495 | 506 | | |
496 | 507 | | |
497 | 508 | | |
498 | 509 | | |
499 | 510 | | |
500 | 511 | | |
501 | 512 | | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
506 | 519 | | |
507 | 520 | | |
508 | 521 | | |
| |||
571 | 584 | | |
572 | 585 | | |
573 | 586 | | |
574 | | - | |
| 587 | + | |
575 | 588 | | |
576 | 589 | | |
577 | 590 | | |
| |||
595 | 608 | | |
596 | 609 | | |
597 | 610 | | |
598 | | - | |
| 611 | + | |
599 | 612 | | |
600 | 613 | | |
601 | 614 | | |
| |||
738 | 751 | | |
739 | 752 | | |
740 | 753 | | |
741 | | - | |
| 754 | + | |
742 | 755 | | |
743 | 756 | | |
744 | 757 | | |
745 | 758 | | |
746 | 759 | | |
747 | 760 | | |
748 | | - | |
| 761 | + | |
749 | 762 | | |
750 | 763 | | |
751 | 764 | | |
| |||
757 | 770 | | |
758 | 771 | | |
759 | 772 | | |
760 | | - | |
| 773 | + | |
761 | 774 | | |
762 | 775 | | |
763 | 776 | | |
764 | 777 | | |
765 | 778 | | |
766 | 779 | | |
767 | | - | |
| 780 | + | |
768 | 781 | | |
769 | 782 | | |
770 | 783 | | |
| |||
778 | 791 | | |
779 | 792 | | |
780 | 793 | | |
781 | | - | |
| 794 | + | |
782 | 795 | | |
783 | 796 | | |
784 | 797 | | |
785 | 798 | | |
786 | 799 | | |
787 | 800 | | |
788 | 801 | | |
789 | | - | |
| 802 | + | |
790 | 803 | | |
791 | 804 | | |
792 | 805 | | |
| |||
0 commit comments