@@ -170,7 +170,7 @@ $pi->output1()->reset();
170
170
171
171
### Monitoring IO Variables
172
172
173
- The ` DigitalMonitor ` will cause the callback to be called whenever the monitored value changes.
173
+ The monitor will cause the callback to be called whenever the monitored value changes.
174
174
175
175
``` php
176
176
use Flat3\RevPi\Monitors\DigitalMonitor;
@@ -183,6 +183,27 @@ $pi->input1()->monitor(new DigitalMonitor, function($newValue) {
183
183
});
184
184
```
185
185
186
+ #### Monitor::debounce
187
+
188
+ Wraps a callback to fire ** only after changes stop** for the given interval (in milliseconds).
189
+
190
+ ``` php
191
+ $pi->input1()->monitor(new DigitalMonitor, Monitor::debounce(function($value) {
192
+ // Handle change after quiet period
193
+ }, 200));
194
+ ```
195
+
196
+ #### Monitor::throttle
197
+
198
+ Wraps a callback to fire ** at most once per interval** (in milliseconds).
199
+
200
+ ``` php
201
+ $pi->input1()->monitor(new DigitalMonitor, Monitor::throttle(function($value) {
202
+ // Handle change no more than every 200ms
203
+ }, 200));
204
+ ```
205
+
206
+
186
207
### Process Image (Low-Level)
187
208
188
209
Get the raw process image interface for advanced access:
@@ -309,13 +330,13 @@ $port = app(\Flat3\RevPi\Interfaces\SerialPort::class); // Usually you want $pi-
309
330
310
331
### Monitoring with Custom Monitors
311
332
312
- If you want to create a custom monitor (beyond DigitalMonitor) :
333
+ If you want to create a custom monitor:
313
334
314
335
``` php
315
- use Flat3\RevPi\Interfaces \Monitor;
336
+ use Flat3\RevPi\Monitors \Monitor;
316
337
317
- class MyMonitor implements Monitor {
318
- public function evaluate(int|bool|null $next): bool {
338
+ class MyMonitor extends Monitor {
339
+ public function evaluate(int|bool $next): bool {
319
340
// Implement custom transition/action logic here
320
341
// e.g. if crossing a threshold
321
342
// Return true if the monitor has detected sufficient change
0 commit comments