hybridgroup.gobot/device.go

36 lines
857 B
Go
Raw Normal View History

2013-10-23 07:45:31 +08:00
package gobot
2013-10-24 13:00:03 +08:00
import (
"fmt"
2013-10-25 13:04:58 +08:00
"reflect"
2013-10-24 13:00:03 +08:00
)
2013-10-23 07:45:31 +08:00
type Device struct {
Name string
2013-10-27 07:41:43 +08:00
Interval string
2013-10-25 13:04:58 +08:00
Robot *Robot
Connection *Connection
Driver *Driver
2013-10-24 13:00:03 +08:00
Params map[string]string
2013-10-23 07:45:31 +08:00
}
2013-10-27 07:41:43 +08:00
func NewDevice(d interface{}, r *Robot) *Device {
2013-10-25 13:04:58 +08:00
dt := new(Device)
2013-10-27 07:41:43 +08:00
dt.Name = reflect.ValueOf(d).Elem().FieldByName("Name").String()
2013-10-25 13:04:58 +08:00
dt.Robot = r
dt.Driver = new(Driver)
2013-10-27 07:41:43 +08:00
dt.Driver.Pin = reflect.ValueOf(d).Elem().FieldByName("Pin").String()
dt.Driver.Interval = reflect.ValueOf(d).Elem().FieldByName("Interval").String()
dt.Driver.Name = reflect.ValueOf(d).Elem().FieldByName("Name").String()
2013-10-25 13:04:58 +08:00
dt.Connection = new(Connection)
2013-10-24 13:00:03 +08:00
return dt
2013-10-23 07:45:31 +08:00
}
2013-10-25 13:04:58 +08:00
func (dt *Device) Start() {
2013-10-27 07:41:43 +08:00
fmt.Println("Device " + dt.Name + " started")
2013-10-24 13:00:03 +08:00
dt.Driver.Start()
2013-10-23 07:45:31 +08:00
}
2013-10-25 13:04:58 +08:00
func (dt *Device) Command(method_name string, arguments []string) {
2013-10-24 13:00:03 +08:00
//dt.Driver.Command(method_name, arguments)
2013-10-23 07:45:31 +08:00
}