-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget.go
49 lines (44 loc) · 1.3 KB
/
get.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
// This file is part of macfanctl.
//
// Copyright (C) 2013 Roberto Teixeira <robteix@robteix.com>
//
// macfanctl is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// macfanctl is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with macfanctl. If not, see <http://www.gnu.org/licenses/>.
//
package main
import (
"fmt"
"log"
"os"
)
var cmdGet = &Command{
Run: runGet,
UsageLine: "get",
Help: "get current fan speed",
}
const sysDir = "/sys/devices/platform/applesmc.768"
func runGet(cmd *Command, args []string) {
fanInput := fmt.Sprintf("%s/fan1_input", sysDir)
file, err := os.Open(fanInput) // For read access.
if err != nil {
log.Fatal(err)
}
defer file.Close()
var speed int
_, err = fmt.Fscanf(file, "%d\n", &speed)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not read from %s: %s\n", fanInput, err)
os.Exit(1)
}
fmt.Printf("%d\n", speed)
}