-
Notifications
You must be signed in to change notification settings - Fork 1
/
commands.go
111 lines (93 loc) · 2.5 KB
/
commands.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"fmt"
"os"
"strconv"
"strings"
"github.com/olekukonko/tablewriter"
)
func printUsage() {
fmt.Println("Usage: fancontrol [options] <command> [arguments...]")
fmt.Println("More help: fancontrol help")
}
func printHelp() {
fmt.Println("Usage: fancontrol [options] <command> [arguments...]")
//fmt.Println("Options:")
fmt.Println(`Commands:
help
Dispalys this help
ls, list
Shows a list with information about cards installed
pls, plainlist
Same as above but with ugly format. Thought for being used by other programs.
set <card> <"auto"|0-100>
Setting the fan speed
`)
}
func plainPrintListCards(command []string) {
if len(command) == 1 {
list := listCardsS()
for _, f := range list {
fmt.Printf("%s\t%s\t%s\t%s\n", f.card, f.name, f.temp, f.fan)
}
fmt.Println(len(list))
} else {
newCard(command[1])
}
}
func prettyPrintListCards(command []string) {
list := listCardsS()
data := make([][]string, 0)
for _, f := range list {
data = append(data, []string{f.card, f.name, f.temp, f.fan, strconv.FormatInt(int64(f.fanm), 10)})
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Card", "Name", "Temp (°C)", "Fan Speed (%)", "Fan mode"})
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
table.SetCenterSeparator("|")
table.AppendBulk(data) // Add Bulk Data
table.Render()
}
func printGetTemperature(command []string) {
if len(command) == 1 {
fmt.Println("Printing all card temps")
list := listCards()
for _, c := range list {
fmt.Printf(c+"\t%.1f°C\n", getTemperature(c))
}
} else if len(command) == 2 {
fmt.Printf("%.1f°C\n", getTemperature(command[1]))
}
}
func printGetFanSpeed(command []string) {
if len(command) == 1 {
fmt.Println("Printing all fan speeds")
list := listCards()
for _, c := range list {
fmt.Println(c + "\t" + getFanSpeedAsString(c) + "%")
}
} else if len(command) == 2 {
fmt.Println(getFanSpeedAsString(command[1]) + "%")
}
}
func setFan(command []string) {
if len(command) != 3 {
fmt.Println("Wrong number of arguments")
return
}
card := command[1]
speed := command[2]
if strings.EqualFold(speed, "auto") {
fmt.Println("Setting speed of " + card + " to: auto")
setFanMode(card, 2)
} else {
speedInt, _ := strconv.ParseInt(speed, 10, 32)
if speedInt >= 0 && speedInt <= 100 {
fmt.Println("Setting speed of " + card + " to: " + speed)
setFanMode(card, 1)
setFanSpeed(card, int(speedInt))
} else {
fmt.Println("Wrong speed argument")
}
}
}