diff --git a/device.go b/device.go index 5b5d47e1..9b197369 100644 --- a/device.go +++ b/device.go @@ -5,6 +5,12 @@ import ( "reflect" ) +type Device interface { + Init() bool + Start() bool + Halt() bool +} + type device struct { Name string `json:"name"` Type string `json:"driver"` @@ -13,10 +19,13 @@ type device struct { Driver DriverInterface `json:"-"` } -type Device interface { - Init() bool - Start() bool - Halt() bool +type devices []*device + +// Halt() stop all the devices. +func (d devices) Halt() { + for _, device := range d { + device.Halt() + } } func NewDevice(driver DriverInterface, r *Robot) *device { diff --git a/master.go b/master.go index 2daa5ec3..f6a8289f 100644 --- a/master.go +++ b/master.go @@ -42,7 +42,7 @@ func (m *Master) Start() { // waiting on something coming on the channel _ = <-c for _, r := range m.Robots { - r.haltDevices() + r.GetDevices().Halt() r.finalizeConnections() } diff --git a/robot.go b/robot.go index 07d94651..fff6997e 100644 --- a/robot.go +++ b/robot.go @@ -113,20 +113,14 @@ func (r *Robot) startDevices() bool { return success } -func (r *Robot) haltDevices() { - for _, device := range r.devices { - device.Halt() - } -} - func (r *Robot) finalizeConnections() { for _, connection := range r.connections { connection.Finalize() } } -func (r *Robot) GetDevices() []*device { - return r.devices +func (r *Robot) GetDevices() devices { + return devices(r.devices) } func (r *Robot) GetDevice(name string) *device {