From 3e4534bd6bf5501ef3ab7954730d0bd6932a1210 Mon Sep 17 00:00:00 2001
From: Thomas Flori <thflori@gmail.com>
Date: Sat, 3 Jun 2023 13:43:08 +0200
Subject: [PATCH] log the status every 5 seconds

---
 app/Command/Daemon.php       | 8 +++++++-
 app/Model/Rule.php           | 2 +-
 app/Model/Rule/CurveRule.php | 6 +++---
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/app/Command/Daemon.php b/app/Command/Daemon.php
index 00381a0..941973d 100644
--- a/app/Command/Daemon.php
+++ b/app/Command/Daemon.php
@@ -51,11 +51,17 @@ class Daemon extends AbstractCommand
         $rules = $fanConfig->getRules();
         $this->console->setLogger($this->app->logger);
         $this->info('Fan Control started');
+        $last = 0;
 
         // main loop
         while (true) {
+            $showStatus = false;
+            if (microtime(true) > $last+5) {
+                $last = microtime(true);
+                $showStatus = true;
+            }
             foreach ($rules as $rule) {
-                $rule->apply($this->console);
+                $rule->apply($this->console, $showStatus);
             }
             usleep(self::UPDATE_INTERVAL);
         }
diff --git a/app/Model/Rule.php b/app/Model/Rule.php
index 41bcaff..6a017d1 100644
--- a/app/Model/Rule.php
+++ b/app/Model/Rule.php
@@ -13,7 +13,7 @@ abstract class Rule extends Model
     /** @var Sensor */
     public $sensor;
 
-    abstract public function apply(Console $console);
+    abstract public function apply(Console $console, bool $showStatus = false);
 
     abstract public function describe(): string;
 }
diff --git a/app/Model/Rule/CurveRule.php b/app/Model/Rule/CurveRule.php
index ddf2ef7..4c54a1e 100644
--- a/app/Model/Rule/CurveRule.php
+++ b/app/Model/Rule/CurveRule.php
@@ -44,7 +44,7 @@ class CurveRule extends Rule
         }
     }
 
-    public function apply(Console $console)
+    public function apply(Console $console, bool $showStatus = false)
     {
         $temp = $this->sensor->getTemperature();
         $lastPercentage = null;
@@ -67,7 +67,7 @@ class CurveRule extends Rule
                     $this->sensor->name,
                     $temp,
                     $percentage,
-                ), Console::WEIGHT_DEBUG);
+                ), $showStatus ? Console::WEIGHT_LOW : Console::WEIGHT_DEBUG);
                 $this->setSpeed($percentage);
             } else {
                 $factor = ($temp - $lastLimit) / ($limit - $lastLimit);
@@ -84,7 +84,7 @@ class CurveRule extends Rule
                     $percentage,
                     $lastPercentage,
                     $lastPercentage
-                ), $speed > 30 ? Console::WEIGHT_LOW : Console::WEIGHT_DEBUG);
+                ), $showStatus ? Console::WEIGHT_LOW : Console::WEIGHT_DEBUG);
                 $this->setSpeed($speed);
             }
             break;
-- 
GitLab