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:
parent
59aee80c91
commit
4cb20e1088
@ -4,6 +4,8 @@ type Adaptor interface {
|
||||
Finalize() []error
|
||||
Connect() []error
|
||||
Name() string
|
||||
Port() string
|
||||
String() string
|
||||
}
|
||||
|
||||
type Porter interface {
|
||||
Port() string
|
||||
}
|
||||
|
@ -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))
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user