diff --git a/device.go b/device.go index 4e1b1581..c15cd26f 100644 --- a/device.go +++ b/device.go @@ -10,26 +10,24 @@ type Device struct { Interval string Robot *Robot Connection *Connection - Driver *Driver + Driver interface{} Params map[string]string } -func NewDevice(d interface{}, r *Robot) *Device { - dt := new(Device) - dt.Name = reflect.ValueOf(d).Elem().FieldByName("Name").String() - dt.Robot = r - dt.Driver = new(Driver) - 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() - dt.Connection = new(Connection) - return dt +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 + d.Connection = new(Connection) + return d } -func (dt *Device) Start() { - fmt.Println("Device " + dt.Name + " started") - dt.Driver.Start() +func (d *Device) Start() { + fmt.Println("Device " + d.Name + " started") + reflect.ValueOf(d.Driver).MethodByName("StartDriver").Call([]reflect.Value{}) } -func (dt *Device) Command(method_name string, arguments []string) { + +func (d *Device) Command(method_name string, arguments []string) { //dt.Driver.Command(method_name, arguments) } diff --git a/robot.go b/robot.go index 68b3c7b3..d76fe743 100644 --- a/robot.go +++ b/robot.go @@ -44,7 +44,7 @@ func (r *Robot) initDevices() { fmt.Println("Initializing devices...") for i := range r.Devices { fmt.Println("Initializing device " + reflect.ValueOf(r.Devices[i]).Elem().FieldByName("Name").String() + "...") - r.devices[i] = NewDevice(r.Connections[i], r) + r.devices[i] = NewDevice(r.Devices[i], r) } }