added Halt() to a collection of devices

This commit is contained in:
Matt Aimonetti 2014-04-26 21:52:10 -07:00
parent 82b8fd5224
commit 852a7699c1
3 changed files with 16 additions and 13 deletions

View File

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

View File

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

View File

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