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 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 }