Skip to content

Commit

Permalink
Merge pull request #263 from markusressel/feature/support-rpm-in-file…
Browse files Browse the repository at this point in the history
…-fan-config

Feature/support rpm in file fan config
  • Loading branch information
markusressel authored Oct 3, 2023
2 parents 5504fb8 + f1edba5 commit be35da4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion internal/configuration/fans.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 22 additions & 4 deletions internal/fans/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit be35da4

Please sign in to comment.