added Halt() to a collection of devices
This commit is contained in:
parent
9c639af41c
commit
8b978c4284
17
device.go
17
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 {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
10
robot.go
10
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 {
|
||||
|
|
Loading…
Reference in New Issue