Add Halt function to DriverInterface

This commit is contained in:
Adrian Zankich 2014-03-31 14:25:20 -07:00
parent 16c650ae82
commit 0418ca26ca
5 changed files with 15 additions and 0 deletions

View File

@ -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()
} }

View File

@ -10,4 +10,5 @@ type Driver struct {
type DriverInterface interface { type DriverInterface interface {
Start() bool Start() bool
Halt() bool
} }

View File

@ -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

View File

@ -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()

View File

@ -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