From a41d07f70aa7bb43c9a807a1ede733c49765aa8f Mon Sep 17 00:00:00 2001
From: Thomas Flori <thflori@gmail.com>
Date: Sat, 3 Jun 2023 10:55:27 +0200
Subject: [PATCH] update hugga and log when fans go over 30% speed

---
 app/Command/Daemon.php       |  5 ++++-
 app/Model/Rule/CurveRule.php |  2 +-
 composer.json                |  2 +-
 composer.lock                | 27 ++++++++++++++-------------
 4 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/app/Command/Daemon.php b/app/Command/Daemon.php
index 06af7bc..00381a0 100644
--- a/app/Command/Daemon.php
+++ b/app/Command/Daemon.php
@@ -9,6 +9,7 @@ use Hugga\Console;
 class Daemon extends AbstractCommand
 {
     const PID_PATH = '/run/fan-ctrl.pid';
+    const UPDATE_INTERVAL = 500_000; // in micro seconds
 
     protected $name = 'daemon';
 
@@ -48,13 +49,15 @@ class Daemon extends AbstractCommand
 
         // prepare
         $rules = $fanConfig->getRules();
+        $this->console->setLogger($this->app->logger);
+        $this->info('Fan Control started');
 
         // main loop
         while (true) {
             foreach ($rules as $rule) {
                 $rule->apply($this->console);
             }
-            sleep(1);
+            usleep(self::UPDATE_INTERVAL);
         }
     }
 }
diff --git a/app/Model/Rule/CurveRule.php b/app/Model/Rule/CurveRule.php
index c20a987..ddf2ef7 100644
--- a/app/Model/Rule/CurveRule.php
+++ b/app/Model/Rule/CurveRule.php
@@ -84,7 +84,7 @@ class CurveRule extends Rule
                     $percentage,
                     $lastPercentage,
                     $lastPercentage
-                ), Console::WEIGHT_DEBUG);
+                ), $speed > 30 ? Console::WEIGHT_LOW : Console::WEIGHT_DEBUG);
                 $this->setSpeed($speed);
             }
             break;
diff --git a/composer.json b/composer.json
index 7ccc20c..9e58c35 100644
--- a/composer.json
+++ b/composer.json
@@ -3,7 +3,7 @@
     "bin": ["bin/fan-ctrl"],
     "require":           {
         "tflori/riki-framework": "dev-master",
-        "tflori/hugga":          "^1.1",
+        "tflori/hugga":          "^1.2",
         "ulrichsg/getopt-php":   "^4.0",
         "filp/whoops": "^2.14",
         "monolog/monolog": "^1.9",
diff --git a/composer.lock b/composer.lock
index ff722eb..b7b555f 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,20 +4,20 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "cddd1ddd64b18141de6444950d1076f4",
+    "content-hash": "dc0a733546b0eca25d08dbfda7ed570c",
     "packages": [
         {
             "name": "filp/whoops",
-            "version": "2.14.6",
+            "version": "2.15.2",
             "source": {
                 "type": "git",
                 "url": "https://github.com/filp/whoops.git",
-                "reference": "f7948baaa0330277c729714910336383286305da"
+                "reference": "aac9304c5ed61bf7b1b7a6064bf9806ab842ce73"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/filp/whoops/zipball/f7948baaa0330277c729714910336383286305da",
-                "reference": "f7948baaa0330277c729714910336383286305da",
+                "url": "https://api.github.com/repos/filp/whoops/zipball/aac9304c5ed61bf7b1b7a6064bf9806ab842ce73",
+                "reference": "aac9304c5ed61bf7b1b7a6064bf9806ab842ce73",
                 "shasum": ""
             },
             "require": {
@@ -67,7 +67,7 @@
             ],
             "support": {
                 "issues": "https://github.com/filp/whoops/issues",
-                "source": "https://github.com/filp/whoops/tree/2.14.6"
+                "source": "https://github.com/filp/whoops/tree/2.15.2"
             },
             "funding": [
                 {
@@ -75,7 +75,7 @@
                     "type": "github"
                 }
             ],
-            "time": "2022-11-02T16:23:29+00:00"
+            "time": "2023-04-12T12:00:00+00:00"
         },
         {
             "name": "monolog/monolog",
@@ -456,16 +456,16 @@
         },
         {
             "name": "tflori/hugga",
-            "version": "v1.1.0",
+            "version": "v1.2.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/tflori/hugga.git",
-                "reference": "204f03ccf04a5381a117dc6025364f74a70923d9"
+                "reference": "ece10d4e60d7208318bd14d7146d2fc3151ba7da"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/tflori/hugga/zipball/204f03ccf04a5381a117dc6025364f74a70923d9",
-                "reference": "204f03ccf04a5381a117dc6025364f74a70923d9",
+                "url": "https://api.github.com/repos/tflori/hugga/zipball/ece10d4e60d7208318bd14d7146d2fc3151ba7da",
+                "reference": "ece10d4e60d7208318bd14d7146d2fc3151ba7da",
                 "shasum": ""
             },
             "require": {
@@ -497,9 +497,9 @@
             "description": "library for console applications with input and output handling",
             "support": {
                 "issues": "https://github.com/tflori/hugga/issues",
-                "source": "https://github.com/tflori/hugga/tree/v1.1.0"
+                "source": "https://github.com/tflori/hugga/tree/v1.2.0"
             },
-            "time": "2022-03-18T16:46:56+00:00"
+            "time": "2023-06-01T20:11:36+00:00"
         },
         {
             "name": "tflori/riki-framework",
@@ -612,6 +612,7 @@
     "prefer-lowest": false,
     "platform": {
         "ext-pcntl": "*",
+        "ext-posix": "*",
         "php": ">=7.4"
     },
     "platform-dev": [],
-- 
GitLab