Refactor firmata to use new adaptor interface
This commit is contained in:
parent
4cb20e1088
commit
d38b95f41f
|
@ -11,10 +11,11 @@ import (
|
||||||
"github.com/tarm/goserial"
|
"github.com/tarm/goserial"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ gobot.AdaptorInterface = (*FirmataAdaptor)(nil)
|
var _ gobot.Adaptor = (*FirmataAdaptor)(nil)
|
||||||
|
|
||||||
type FirmataAdaptor struct {
|
type FirmataAdaptor struct {
|
||||||
gobot.Adaptor
|
name string
|
||||||
|
port string
|
||||||
board *board
|
board *board
|
||||||
i2cAddress byte
|
i2cAddress byte
|
||||||
connect func(*FirmataAdaptor) (err error)
|
connect func(*FirmataAdaptor) (err error)
|
||||||
|
@ -43,11 +44,8 @@ func NewFirmataAdaptor(name string, args ...interface{}) *FirmataAdaptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &FirmataAdaptor{
|
return &FirmataAdaptor{
|
||||||
Adaptor: *gobot.NewAdaptor(
|
name: name,
|
||||||
name,
|
port: port,
|
||||||
"FirmataAdaptor",
|
|
||||||
port,
|
|
||||||
),
|
|
||||||
connect: func(f *FirmataAdaptor) (err error) {
|
connect: func(f *FirmataAdaptor) (err error) {
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
conn, err = serial.OpenPort(&serial.Config{Name: f.Port(), Baud: 57600})
|
conn, err = serial.OpenPort(&serial.Config{Name: f.Port(), Baud: 57600})
|
||||||
|
@ -67,7 +65,6 @@ func (f *FirmataAdaptor) Connect() (errs []error) {
|
||||||
return []error{err}
|
return []error{err}
|
||||||
}
|
}
|
||||||
f.board.connect()
|
f.board.connect()
|
||||||
f.SetConnected(true)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +85,9 @@ func (f *FirmataAdaptor) Finalize() (errs []error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *FirmataAdaptor) Port() string { return f.port }
|
||||||
|
func (f *FirmataAdaptor) Name() string { return f.name }
|
||||||
|
|
||||||
// InitServo (not yet implemented)
|
// InitServo (not yet implemented)
|
||||||
func (f *FirmataAdaptor) InitServo() (err error) {
|
func (f *FirmataAdaptor) InitServo() (err error) {
|
||||||
return errors.New("InitServo is not yet implemented")
|
return errors.New("InitServo is not yet implemented")
|
||||||
|
|
Loading…
Reference in New Issue