1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00
hybridgroup.gobot/device.go

38 lines
697 B
Go
Raw Normal View History

2013-10-22 16:45:31 -07:00
package gobot
2013-10-23 22:00:03 -07:00
import (
2013-11-13 20:44:54 -08:00
"fmt"
2013-10-23 22:00:03 -07:00
)
2013-10-22 16:45:31 -07:00
type device struct {
2013-11-13 20:44:54 -08:00
Name string
Interval string `json:"-"`
2013-11-23 10:36:08 -08:00
Robot *Robot `json:"-"`
Driver DriverInterface
2013-10-22 16:45:31 -07:00
}
type Device interface {
Start() bool
}
func NewDevice(driver DriverInterface, r *Robot) *device {
d := new(device)
d.Name = FieldByNamePtr(driver, "Name").String()
2013-11-13 20:44:54 -08:00
d.Robot = r
if FieldByNamePtr(driver, "Interval").String() == "" {
FieldByNamePtr(driver, "Interval").SetString("0.1s")
2013-12-15 14:26:16 -08:00
}
2013-11-13 20:44:54 -08:00
d.Driver = driver
return d
2013-10-22 16:45:31 -07:00
}
func (d *device) Start() bool {
2013-11-13 20:44:54 -08:00
fmt.Println("Device " + d.Name + " started")
d.Driver.Start()
return true
2013-10-22 16:45:31 -07:00
}
2013-10-28 18:50:09 -07:00
func (d *device) Commands() interface{} {
return FieldByNamePtr(d.Driver, "Commands").Interface()
2013-10-22 16:45:31 -07:00
}