2013-10-23 07:45:31 +08:00
|
|
|
package gobot
|
|
|
|
|
2013-10-24 13:00:03 +08:00
|
|
|
import (
|
2013-12-31 14:04:23 +08:00
|
|
|
"log"
|
2013-10-24 13:00:03 +08:00
|
|
|
)
|
2013-10-23 07:45:31 +08:00
|
|
|
|
2013-12-19 07:25:07 +08:00
|
|
|
type device struct {
|
2013-11-14 12:44:54 +08:00
|
|
|
Name string
|
2013-12-19 07:25:07 +08:00
|
|
|
Interval string `json:"-"`
|
2013-11-24 02:36:08 +08:00
|
|
|
Robot *Robot `json:"-"`
|
2013-12-19 07:25:07 +08:00
|
|
|
Driver DriverInterface
|
2013-10-23 07:45:31 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 07:25:07 +08:00
|
|
|
type Device interface {
|
|
|
|
Start() bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDevice(driver DriverInterface, r *Robot) *device {
|
|
|
|
d := new(device)
|
|
|
|
d.Name = FieldByNamePtr(driver, "Name").String()
|
2013-11-14 12:44:54 +08:00
|
|
|
d.Robot = r
|
2013-12-19 07:25:07 +08:00
|
|
|
if FieldByNamePtr(driver, "Interval").String() == "" {
|
|
|
|
FieldByNamePtr(driver, "Interval").SetString("0.1s")
|
2013-12-16 06:26:16 +08:00
|
|
|
}
|
2013-11-14 12:44:54 +08:00
|
|
|
d.Driver = driver
|
|
|
|
return d
|
2013-10-23 07:45:31 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 07:25:07 +08:00
|
|
|
func (d *device) Start() bool {
|
2013-12-31 14:04:23 +08:00
|
|
|
log.Println("Device " + d.Name + " started")
|
2013-12-31 08:51:21 +08:00
|
|
|
return d.Driver.Start()
|
2013-10-23 07:45:31 +08:00
|
|
|
}
|
2013-10-29 09:50:09 +08:00
|
|
|
|
2013-12-19 07:25:07 +08:00
|
|
|
func (d *device) Commands() interface{} {
|
|
|
|
return FieldByNamePtr(d.Driver, "Commands").Interface()
|
2013-10-23 07:45:31 +08:00
|
|
|
}
|