Skip to content

Commit

Permalink
Add Piner and Porter
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Nov 22, 2014
1 parent 59aee80 commit 4cb20e1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 3 additions & 1 deletion adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ type Adaptor interface {
Finalize() []error
Connect() []error
Name() string
}

type Porter interface {
Port() string
String() string
}
7 changes: 5 additions & 2 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 4 additions & 2 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ type Driver interface {
Start() []error
Halt() []error
Name() string
Pin() string
String() string
Connection() Connection
}

type Piner interface {
Pin() string
}

0 comments on commit 4cb20e1

Please sign in to comment.