Update sphero package
This commit is contained in:
parent
da835935a8
commit
3f3444f7e7
|
@ -14,12 +14,13 @@ type SpheroAdaptor struct {
|
|||
|
||||
func NewSpheroAdaptor(name string, port string) *SpheroAdaptor {
|
||||
return &SpheroAdaptor{
|
||||
Adaptor: gobot.Adaptor{
|
||||
Name: name,
|
||||
Port: port,
|
||||
},
|
||||
Adaptor: *gobot.NewAdaptor(
|
||||
name,
|
||||
"SpheroAdaptor",
|
||||
port,
|
||||
),
|
||||
connect: func(a *SpheroAdaptor) {
|
||||
c := &serial.Config{Name: a.Port, Baud: 115200}
|
||||
c := &serial.Config{Name: a.Port(), Baud: 115200}
|
||||
s, err := serial.OpenPort(c)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -31,12 +32,12 @@ func NewSpheroAdaptor(name string, port string) *SpheroAdaptor {
|
|||
|
||||
func (a *SpheroAdaptor) Connect() bool {
|
||||
a.connect(a)
|
||||
a.Connected = true
|
||||
a.SetConnected(true)
|
||||
return true
|
||||
}
|
||||
|
||||
func (a *SpheroAdaptor) Reconnect() bool {
|
||||
if a.Connected == true {
|
||||
if a.Connected() == true {
|
||||
a.Disconnect()
|
||||
}
|
||||
return a.Connect()
|
||||
|
@ -44,7 +45,7 @@ func (a *SpheroAdaptor) Reconnect() bool {
|
|||
|
||||
func (a *SpheroAdaptor) Disconnect() bool {
|
||||
a.sp.Close()
|
||||
a.Connected = false
|
||||
a.SetConnected(false)
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -23,18 +23,16 @@ type SpheroDriver struct {
|
|||
|
||||
func NewSpheroDriver(a *SpheroAdaptor, name string) *SpheroDriver {
|
||||
s := &SpheroDriver{
|
||||
Driver: gobot.Driver{
|
||||
Name: name,
|
||||
Events: map[string]*gobot.Event{
|
||||
"Collision": gobot.NewEvent(),
|
||||
},
|
||||
Commands: make(map[string]func(map[string]interface{}) interface{}),
|
||||
Adaptor: a,
|
||||
},
|
||||
Driver: *gobot.NewDriver(
|
||||
name,
|
||||
"SpheroDriver",
|
||||
a,
|
||||
),
|
||||
packetChannel: make(chan *packet, 1024),
|
||||
responseChannel: make(chan []uint8, 1024),
|
||||
}
|
||||
|
||||
s.AddEvent("collision")
|
||||
s.Driver.AddCommand("SetRGB", func(params map[string]interface{}) interface{} {
|
||||
r := uint8(params["r"].(float64))
|
||||
g := uint8(params["g"].(float64))
|
||||
|
@ -80,7 +78,7 @@ func NewSpheroDriver(a *SpheroAdaptor, name string) *SpheroDriver {
|
|||
}
|
||||
|
||||
func (s *SpheroDriver) adaptor() *SpheroAdaptor {
|
||||
return s.Driver.Adaptor.(*SpheroAdaptor)
|
||||
return s.Driver.Adaptor().(*SpheroAdaptor)
|
||||
}
|
||||
|
||||
func (s *SpheroDriver) Init() bool {
|
||||
|
@ -182,7 +180,7 @@ func (s *SpheroDriver) configureCollisionDetection() {
|
|||
}
|
||||
|
||||
func (s *SpheroDriver) handleCollisionDetected(data []uint8) {
|
||||
gobot.Publish(s.Events["Collision"], data)
|
||||
gobot.Publish(s.Event("collision"), data)
|
||||
}
|
||||
|
||||
func (s *SpheroDriver) getSyncResponse(packet *packet) []byte {
|
||||
|
|
Loading…
Reference in New Issue