forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.go
45 lines (36 loc) · 1.08 KB
/
driver.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
package gobot
import "time"
type Driver struct {
Interval time.Duration `json:"interval"`
Pin string `json:"pin"`
Name string `json:"name"`
Commands map[string]func(map[string]interface{}) interface{} `json:"commands"`
Events map[string]*Event `json:"-"`
}
type DriverInterface interface {
Start() bool
Halt() bool
setInterval(time.Duration)
interval() time.Duration
setName(string)
name() string
commands() map[string]func(map[string]interface{}) interface{}
}
func (d *Driver) setInterval(t time.Duration) {
d.Interval = t
}
func (d *Driver) interval() time.Duration {
return d.Interval
}
func (d *Driver) setName(s string) {
d.Name = s
}
func (d *Driver) name() string {
return d.Name
}
func (d *Driver) commands() map[string]func(map[string]interface{}) interface{} {
return d.Commands
}
func (d *Driver) AddCommand(name string, f func(map[string]interface{}) interface{}) {
d.Commands[name] = f
}