Correctly start drivers
This commit is contained in:
parent
9ef568ec65
commit
dbc602d5bd
28
device.go
28
device.go
|
@ -10,26 +10,24 @@ type Device struct {
|
||||||
Interval string
|
Interval string
|
||||||
Robot *Robot
|
Robot *Robot
|
||||||
Connection *Connection
|
Connection *Connection
|
||||||
Driver *Driver
|
Driver interface{}
|
||||||
Params map[string]string
|
Params map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDevice(d interface{}, r *Robot) *Device {
|
func NewDevice(driver interface{}, r *Robot) *Device {
|
||||||
dt := new(Device)
|
d := new(Device)
|
||||||
dt.Name = reflect.ValueOf(d).Elem().FieldByName("Name").String()
|
d.Name = reflect.ValueOf(driver).Elem().FieldByName("Name").String()
|
||||||
dt.Robot = r
|
d.Robot = r
|
||||||
dt.Driver = new(Driver)
|
d.Driver = driver
|
||||||
dt.Driver.Pin = reflect.ValueOf(d).Elem().FieldByName("Pin").String()
|
d.Connection = new(Connection)
|
||||||
dt.Driver.Interval = reflect.ValueOf(d).Elem().FieldByName("Interval").String()
|
return d
|
||||||
dt.Driver.Name = reflect.ValueOf(d).Elem().FieldByName("Name").String()
|
|
||||||
dt.Connection = new(Connection)
|
|
||||||
return dt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dt *Device) Start() {
|
func (d *Device) Start() {
|
||||||
fmt.Println("Device " + dt.Name + " started")
|
fmt.Println("Device " + d.Name + " started")
|
||||||
dt.Driver.Start()
|
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)
|
//dt.Driver.Command(method_name, arguments)
|
||||||
}
|
}
|
||||||
|
|
2
robot.go
2
robot.go
|
@ -44,7 +44,7 @@ func (r *Robot) initDevices() {
|
||||||
fmt.Println("Initializing devices...")
|
fmt.Println("Initializing devices...")
|
||||||
for i := range r.Devices {
|
for i := range r.Devices {
|
||||||
fmt.Println("Initializing device " + reflect.ValueOf(r.Devices[i]).Elem().FieldByName("Name").String() + "...")
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue