1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-14 19:29:32 +08:00
hybridgroup.gobot/driver.go

52 lines
988 B
Go
Raw Normal View History

2014-04-30 08:10:44 -07:00
package gobot
2013-10-23 22:00:03 -07:00
2014-05-03 03:31:11 -07:00
import "time"
2013-10-23 22:00:03 -07:00
type Driver struct {
Adaptor AdaptorInterface
Interval time.Duration
Pin string
Name string
Commands map[string]func(map[string]interface{}) interface{}
Events map[string]*Event
2013-10-23 22:00:03 -07:00
}
type DriverInterface interface {
Start() bool
2014-03-31 14:25:20 -07:00
Halt() bool
adaptor() AdaptorInterface
2014-06-06 14:44:16 -07:00
setInterval(time.Duration)
2014-06-13 10:09:03 -07:00
interval() time.Duration
2014-06-06 14:44:16 -07:00
setName(string)
2014-06-13 10:09:03 -07:00
name() string
commands() map[string]func(map[string]interface{}) interface{}
2014-06-06 14:44:16 -07:00
}
func (d *Driver) adaptor() AdaptorInterface {
return d.Adaptor
}
2014-06-06 14:44:16 -07:00
func (d *Driver) setInterval(t time.Duration) {
d.Interval = t
}
2014-06-13 10:09:03 -07:00
func (d *Driver) interval() time.Duration {
2014-06-06 14:44:16 -07:00
return d.Interval
}
func (d *Driver) setName(s string) {
d.Name = s
}
2014-06-13 10:09:03 -07:00
func (d *Driver) name() string {
2014-06-06 14:44:16 -07:00
return d.Name
2013-10-23 22:00:03 -07:00
}
2014-06-11 17:41:04 -07:00
2014-06-13 10:09:03 -07:00
func (d *Driver) commands() map[string]func(map[string]interface{}) interface{} {
return d.Commands
2014-06-11 17:41:04 -07:00
}
2014-06-13 10:09:03 -07:00
func (d *Driver) AddCommand(name string, f func(map[string]interface{}) interface{}) {
d.Commands[name] = f
2014-06-11 17:41:04 -07:00
}