2014-04-30 23:10:44 +08:00
|
|
|
package gobot
|
2013-10-24 13:00:03 +08:00
|
|
|
|
2014-05-03 18:31:11 +08:00
|
|
|
import "time"
|
|
|
|
|
2013-10-24 13:00:03 +08:00
|
|
|
type Driver struct {
|
2014-06-12 08:41:04 +08:00
|
|
|
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:"-"`
|
2013-10-24 13:00:03 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 07:25:07 +08:00
|
|
|
type DriverInterface interface {
|
|
|
|
Start() bool
|
2014-04-01 05:25:20 +08:00
|
|
|
Halt() bool
|
2014-06-07 05:44:16 +08:00
|
|
|
setInterval(time.Duration)
|
|
|
|
getInterval() time.Duration
|
|
|
|
setName(string)
|
|
|
|
getName() string
|
2014-06-12 08:41:04 +08:00
|
|
|
getCommands() map[string]func(map[string]interface{}) interface{}
|
2014-06-07 05:44:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Driver) setInterval(t time.Duration) {
|
|
|
|
d.Interval = t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Driver) getInterval() time.Duration {
|
|
|
|
return d.Interval
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Driver) setName(s string) {
|
|
|
|
d.Name = s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Driver) getName() string {
|
|
|
|
return d.Name
|
2013-10-24 13:00:03 +08:00
|
|
|
}
|
2014-06-12 08:41:04 +08:00
|
|
|
|
|
|
|
func (d *Driver) AddCommand(name string, f func(map[string]interface{}) interface{}) {
|
|
|
|
d.Commands[name] = f
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Driver) getCommands() map[string]func(map[string]interface{}) interface{} {
|
|
|
|
return d.Commands
|
|
|
|
}
|