-
Notifications
You must be signed in to change notification settings - Fork 3
/
outlet.go
40 lines (35 loc) · 953 Bytes
/
outlet.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
package uvr
import (
"fmt"
"github.com/brutella/canopen"
"strings"
)
type Outlet struct {
Description canopen.ObjectIndex
StartDelay canopen.ObjectIndex
RunOnTime canopen.ObjectIndex
Mode canopen.ObjectIndex
State canopen.ObjectIndex
SpeedStage canopen.ObjectIndex
}
func NewOutlet(subIndex uint8) Outlet {
return Outlet{
Description: canopen.NewObjectIndex(0x20a5, subIndex),
StartDelay: canopen.NewObjectIndex(0x20a3, subIndex),
RunOnTime: canopen.NewObjectIndex(0x20a4, subIndex),
Mode: canopen.NewObjectIndex(0x20a1, subIndex),
State: canopen.NewObjectIndex(0x20aa, subIndex),
SpeedStage: canopen.NewObjectIndex(0x20ab, subIndex),
}
}
func StringToBool(str string) (bool, error) {
switch strings.TrimSpace(str) {
case OutletStateOn:
return true, nil
case OutletStateOff:
return false, nil
default:
break
}
return false, fmt.Errorf("Unknown string value %v (%X)", str, str)
}