Skip to content

Commit 2e64e3d

Browse files
committed
Updates
1 parent 3a7e6f1 commit 2e64e3d

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

src/Interfaces/Monitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
interface Monitor
88
{
9-
public function evaluate(mixed $previous, mixed $next): bool;
9+
public function evaluate(int|bool|null $next): bool;
1010
}

src/Modules/Module.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,11 @@ public function cancel(): void
6363
public function monitor(string $variable, Monitor $monitor, callable $callback): void
6464
{
6565
Event::listen(PollingEvent::class, function () use ($callback, $variable, $monitor) {
66-
static $previous = null;
67-
6866
$next = $this->getProcessImage()->readVariable($variable);
6967

70-
if ($previous !== null && $previous !== $next) {
71-
if ($monitor->evaluate($previous, $next)) {
72-
$callback($next);
73-
}
68+
if ($monitor->evaluate($next)) {
69+
$callback($next);
7470
}
75-
76-
$previous = $next;
7771
});
7872
}
7973
}

src/Monitors/DigitalMonitor.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@
88

99
class DigitalMonitor implements Monitor
1010
{
11-
public function evaluate(mixed $previous, mixed $next): bool
11+
protected int|bool|null $previous = null;
12+
13+
public function evaluate(int|bool|null $next): bool
1214
{
13-
return $previous !== $next;
15+
$previous = $this->previous;
16+
$this->previous = $next;
17+
18+
if ($previous === null || $previous === $next) {
19+
return false;
20+
}
21+
22+
return true;
1423
}
1524
}

0 commit comments

Comments
 (0)