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

35 lines
665 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 (
"fmt"
2013-10-24 22:04:58 -07:00
"reflect"
2013-10-23 22:00:03 -07:00
)
2013-10-22 16:45:31 -07:00
type Device struct {
Name string
2013-10-26 16:41:43 -07:00
Interval string
2013-10-24 22:04:58 -07:00
Robot *Robot
2013-10-28 18:50:09 -07:00
Driver interface{}
2013-10-23 22:00:03 -07:00
Params map[string]string
2013-10-22 16:45:31 -07:00
}
2013-10-28 18:50:09 -07:00
func NewDevice(driver interface{}, r *Robot) *Device {
d := new(Device)
d.Name = reflect.ValueOf(driver).Elem().FieldByName("Name").String()
d.Robot = r
d.Driver = driver
return d
2013-10-22 16:45:31 -07:00
}
2013-10-28 18:50:09 -07:00
func (d *Device) Start() {
fmt.Println("Device " + d.Name + " started")
2013-11-12 23:41:22 -08:00
r := reflect.ValueOf(d.Driver).MethodByName("StartDriver")
if r.IsValid() {
r.Call([]reflect.Value{})
}
2013-10-22 16:45:31 -07:00
}
2013-10-28 18:50:09 -07:00
func (d *Device) Command(method_name string, arguments []string) {
2013-10-23 22:00:03 -07:00
//dt.Driver.Command(method_name, arguments)
2013-10-22 16:45:31 -07:00
}