|
7 | 7 | use Flat3\RevPi\Constants;
|
8 | 8 | use Flat3\RevPi\Events\PollingEvent;
|
9 | 9 | use Flat3\RevPi\Interfaces\Module as ModuleInterface;
|
| 10 | +use Flat3\RevPi\Interfaces\Monitor; |
10 | 11 | use Flat3\RevPi\Interfaces\ProcessImage;
|
11 | 12 | use Flat3\RevPi\Interfaces\SerialPort;
|
12 |
| -use Flat3\RevPi\Monitors\Monitor; |
13 | 13 | use Illuminate\Support\Facades\Event;
|
14 | 14 | use Revolt\EventLoop;
|
15 | 15 |
|
16 | 16 | abstract class Module implements ModuleInterface
|
17 | 17 | {
|
18 | 18 | protected ?string $pollingCallbackId = null;
|
19 | 19 |
|
20 |
| - protected float $frequency = Constants::f1Hz; |
| 20 | + protected float $frequency = Constants::f25Hz; |
21 | 21 |
|
22 | 22 | protected ?ProcessImage $processImage = null;
|
23 | 23 |
|
@@ -60,15 +60,17 @@ public function cancel(): void
|
60 | 60 | $this->pollingCallbackId = null;
|
61 | 61 | }
|
62 | 62 |
|
63 |
| - public function monitor(Monitor $monitor): void |
| 63 | + public function monitor(string $variable, Monitor $monitor, callable $callback): void |
64 | 64 | {
|
65 |
| - Event::listen(PollingEvent::class, function () use ($monitor) { |
| 65 | + Event::listen(PollingEvent::class, function () use ($callback, $variable, $monitor) { |
66 | 66 | static $previous = null;
|
67 | 67 |
|
68 |
| - $next = $this->getProcessImage()->readVariable($monitor->name); |
| 68 | + $next = $this->getProcessImage()->readVariable($variable); |
69 | 69 |
|
70 | 70 | if ($previous !== null && $previous !== $next) {
|
71 |
| - EventLoop::defer(fn () => $monitor->evaluate($previous, $next)); |
| 71 | + if ($monitor->evaluate($previous, $next)) { |
| 72 | + $callback($next); |
| 73 | + } |
72 | 74 | }
|
73 | 75 |
|
74 | 76 | $previous = $next;
|
|
0 commit comments