-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added "fan mode" command to get/set the pwm mode of a specific fan
- Loading branch information
1 parent
c765e77
commit 890f2aa
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package fan | ||
|
||
import ( | ||
"fmt" | ||
"github.com/markusressel/fan2go/internal/fans" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
var modeCmd = &cobra.Command{ | ||
Use: "mode", | ||
Short: "Get/Set the current pwm mode setting of a fan", | ||
Long: ``, | ||
Args: cobra.RangeArgs(0, 1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
pterm.DisableOutput() | ||
|
||
fan, err := getFan(fanId) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(args) > 0 { | ||
firstArg := args[0] | ||
argAsInt, err := strconv.Atoi(firstArg) | ||
var pwmEnabled fans.ControlMode | ||
if err != nil { | ||
switch strings.ToLower(firstArg) { | ||
case "auto": | ||
pwmEnabled = fans.ControlModeAutomatic | ||
case "pwm": | ||
pwmEnabled = fans.ControlModePWM | ||
case "disabled": | ||
pwmEnabled = fans.ControlModeDisabled | ||
default: | ||
return fmt.Errorf("unknown mode: %s, must be a integer in (1..3) or one of: 'auto', 'pwm', 'disabled'", firstArg) | ||
} | ||
} else { | ||
pwmEnabled = fans.ControlMode(argAsInt) | ||
} | ||
err = fan.SetPwmEnabled(pwmEnabled) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
pwmEnabled, err := fan.GetPwmEnabled() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
switch fans.ControlMode(pwmEnabled) { | ||
case fans.ControlModeDisabled: | ||
fmt.Printf("No control, 100%% all the time (%d)", pwmEnabled) | ||
case fans.ControlModePWM: | ||
fmt.Printf("Manual PWM control, gives fan2go control (%d)", pwmEnabled) | ||
case fans.ControlModeAutomatic: | ||
fmt.Printf("Automatic control by integrated hardware (%d)", pwmEnabled) | ||
default: | ||
fmt.Printf("Unknown (%d)", pwmEnabled) | ||
} | ||
|
||
return err | ||
}, | ||
} | ||
|
||
func init() { | ||
Command.AddCommand(modeCmd) | ||
} |