From f42e63f2d3c06f71a0d629ac6bdb2d1dd2975972 Mon Sep 17 00:00:00 2001 From: Markus Ressel Date: Tue, 3 Oct 2023 13:56:39 +0200 Subject: [PATCH 1/2] add support for RPM reading in file sensor --- internal/configuration/fans.go | 3 ++- internal/fans/file.go | 26 ++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/internal/configuration/fans.go b/internal/configuration/fans.go index fd218c5..6c6e4ca 100644 --- a/internal/configuration/fans.go +++ b/internal/configuration/fans.go @@ -29,7 +29,8 @@ type HwMonFanConfig struct { } type FileFanConfig struct { - Path string `json:"path"` + Path string `json:"path"` + RpmPath string `json:"rpmPath"` } type CmdFanConfig struct { diff --git a/internal/fans/file.go b/internal/fans/file.go index 0e401c9..e66c183 100644 --- a/internal/fans/file.go +++ b/internal/fans/file.go @@ -43,8 +43,25 @@ func (fan *FileFan) SetMaxPwm(pwm int, force bool) { // not supported } -func (fan *FileFan) GetRpm() (int, error) { - return 0, nil +func (fan *FileFan) GetRpm() (result int, err error) { + filePath := fan.Config.File.RpmPath + // resolve home dir path + if strings.HasPrefix(filePath, "~") { + currentUser, err := user.Current() + if err != nil { + return result, err + } + + filePath = filepath.Join(currentUser.HomeDir, filePath[1:]) + } + + integer, err := util.ReadIntFromFile(filePath) + if err != nil { + return 0, err + } + result = integer + fan.Pwm = result + return result, err } func (fan *FileFan) GetRpmAvg() float64 { @@ -132,8 +149,9 @@ func (fan *FileFan) Supports(feature FeatureFlag) bool { case FeatureControlMode: return false case FeatureRpmSensor: - // TODO: maybe we could support this in the future - return false + if len(fan.Config.File.RpmPath) > 0 { + return true + } } return false } From f1edba59d1f8d461221ee8ffcdffbf130b1a7543 Mon Sep 17 00:00:00 2001 From: Markus Ressel Date: Tue, 3 Oct 2023 13:58:29 +0200 Subject: [PATCH 2/2] updated README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 6f8c602..7dfc1cc 100644 --- a/README.md +++ b/README.md @@ -173,12 +173,17 @@ fans: fans: - id: file_fan file: + # Path to a file to set the PWM target for this fan path: /tmp/file_fan + # Path to a file to read the current RPM value of this fan + rpmPath: /tmp/file_fan_rpm ``` ```shell > cat /tmp/file_fan 255 +> cat /tmp/file_fan_rpm +3421 ``` #### CMD