1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-24 13:48:49 +08:00

Add Piner and Porter

This commit is contained in:
Adrian Zankich 2014-11-21 19:35:01 -08:00
parent 59aee80c91
commit 4cb20e1088
4 changed files with 17 additions and 8 deletions

View File

@ -4,6 +4,8 @@ type Adaptor interface {
Finalize() []error
Connect() []error
Name() string
Port() string
String() string
}
type Porter interface {
Port() string
}

View File

@ -42,10 +42,13 @@ func (c *connections) Start() (errs []error) {
log.Println("Starting connections...")
for _, connection := range *c {
info := "Starting connection " + connection.Name()
if connection.Port() != "" {
info = info + " on port " + connection.Port()
if porter, ok := connection.(Porter); ok {
info = info + " on port " + porter.Port()
}
log.Println(info + "...")
if errs = connection.Connect(); len(errs) > 0 {
for i, err := range errs {
errs[i] = errors.New(fmt.Sprintf("Connection %q: %v", connection.Name(), err))

View File

@ -52,9 +52,11 @@ func (d *devices) Start() (errs []error) {
log.Println("Starting devices...")
for _, device := range *d {
info := "Starting device " + device.Name()
if device.Pin() != "" {
info = info + " on pin " + device.Pin()
if piner, ok := device.(Piner); ok {
info = info + " on pin " + piner.Pin()
}
log.Println(info + "...")
if errs = device.Start(); len(errs) > 0 {
for i, err := range errs {

View File

@ -4,7 +4,9 @@ type Driver interface {
Start() []error
Halt() []error
Name() string
Pin() string
String() string
Connection() Connection
}
type Piner interface {
Pin() string
}