Add Halt function to DriverInterface
This commit is contained in:
parent
16c650ae82
commit
0418ca26ca
|
@ -13,6 +13,7 @@ type device struct {
|
||||||
|
|
||||||
type Device interface {
|
type Device interface {
|
||||||
Start() bool
|
Start() bool
|
||||||
|
Halt() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDevice(driver DriverInterface, r *Robot) *device {
|
func NewDevice(driver DriverInterface, r *Robot) *device {
|
||||||
|
@ -31,6 +32,11 @@ func (d *device) Start() bool {
|
||||||
return d.Driver.Start()
|
return d.Driver.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *device) Halt() bool {
|
||||||
|
log.Println("Device " + d.Name + " halted")
|
||||||
|
return d.Driver.Halt()
|
||||||
|
}
|
||||||
|
|
||||||
func (d *device) Commands() interface{} {
|
func (d *device) Commands() interface{} {
|
||||||
return FieldByNamePtr(d.Driver, "Commands").Interface()
|
return FieldByNamePtr(d.Driver, "Commands").Interface()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,4 +10,5 @@ type Driver struct {
|
||||||
|
|
||||||
type DriverInterface interface {
|
type DriverInterface interface {
|
||||||
Start() bool
|
Start() bool
|
||||||
|
Halt() bool
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ func (m *Master) Start() {
|
||||||
|
|
||||||
for _ = range c {
|
for _ = range c {
|
||||||
for r := range m.Robots {
|
for r := range m.Robots {
|
||||||
|
m.Robots[r].haltDevices()
|
||||||
m.Robots[r].finalizeConnections()
|
m.Robots[r].finalizeConnections()
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
6
robot.go
6
robot.go
|
@ -98,6 +98,12 @@ func (r *Robot) startDevices() bool {
|
||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Robot) haltDevices() {
|
||||||
|
for _, device := range r.devices {
|
||||||
|
device.Halt()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Robot) finalizeConnections() {
|
func (r *Robot) finalizeConnections() {
|
||||||
for _, connection := range r.connections {
|
for _, connection := range r.connections {
|
||||||
connection.Finalize()
|
connection.Finalize()
|
||||||
|
|
|
@ -5,6 +5,7 @@ type testDriver struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me *testDriver) Start() bool { return true }
|
func (me *testDriver) Start() bool { return true }
|
||||||
|
func (me *testDriver) Halt() bool { return true }
|
||||||
|
|
||||||
type testAdaptor struct {
|
type testAdaptor struct {
|
||||||
Adaptor
|
Adaptor
|
||||||
|
|
Loading…
Reference in New Issue