-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpio.go
51 lines (42 loc) · 976 Bytes
/
gpio.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
// +build !arm
// gpio.go
package main
import (
"encoding/json"
"errors"
"github.com/golang/glog"
// "time"
"fmt"
)
type GPIOParam struct {
Pin int // Pin number (BCM numbering)
Do string // read | write
Value string // high | low | toggle
Duration int // in ms
Repeat int
Interval int // in ms
Op string
}
func init() {
RegisterInternalFunc(ActorFunc, "GPIO", CallGPIO)
RegisterInternalFunc(SensorFunc, "GPIO", CallGPIO)
}
func CallGPIO(param1 string, param2 string) (result string, err error) {
var gpioParam GPIOParam
if len(param1) <= 0 {
result = "Missing GPIO parameters"
err = errors.New(result)
glog.Errorf("GPIO error : %s ", err)
return
}
err = json.Unmarshal([]byte(param1), &gpioParam)
if err != nil {
result = fmt.Sprintf("Fail to unmarshal gpioParam '%+v' : %s", gpioParam, err)
glog.Errorf(result)
return
}
if glog.V(1) {
glog.Infof("CallGPIO : %v ", gpioParam)
}
return "Done", nil
}