-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinfo.go
More file actions
58 lines (51 loc) · 954 Bytes
/
info.go
File metadata and controls
58 lines (51 loc) · 954 Bytes
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
package gopio
import (
"fmt"
"io/ioutil"
"os"
)
/*
Functions in this file: Value, Direction
*/
// get the current value
func (p *Pin) Value() (VALUE, error) {
file := fmt.Sprintf("%s/gpio%d/value", basedir, p.Num)
f, err := os.Open(file)
if err != nil {
return "", err
}
defer f.Close()
b, err := ioutil.ReadAll(f)
if err != nil {
return "", err
}
v := string(b)
if v == "0\n" {
return LOW, nil
} else if v == "1\n" {
return HIGH, nil
} else {
return "", fmt.Errorf("UNDEFINED VALUE")
}
}
// get the current direction
func (p *Pin) Direction() (DIR, error) {
file := fmt.Sprintf("%s/gpio%d/direction", basedir, p.Num)
f, err := os.Open(file)
if err != nil {
return "", err
}
defer f.Close()
b, err := ioutil.ReadAll(f)
if err != nil {
return "", err
}
d := string(b)
if d == "out\n" {
return OUT, nil
} else if d == "in\n" {
return IN, nil
} else {
return "", fmt.Errorf("UNDEFINED DIRECTION")
}
}