8
8
9
9
"gobot.io/x/gobot/v2"
10
10
"gobot.io/x/gobot/v2/drivers/ble"
11
- "gobot.io/x/gobot/v2/drivers/common/sphero "
11
+ "gobot.io/x/gobot/v2/drivers/common/spherocommon "
12
12
)
13
13
14
14
// MotorModes is used to configure the motor
@@ -63,14 +63,14 @@ type Point2D struct {
63
63
type OllieDriver struct {
64
64
* ble.Driver
65
65
gobot.Eventer
66
- defaultCollisionConfig sphero .CollisionConfig
66
+ defaultCollisionConfig spherocommon .CollisionConfig
67
67
seq uint8
68
68
collisionResponse []uint8
69
69
packetChannel chan * packet
70
70
asyncBuffer []byte
71
71
asyncMessage []byte
72
72
locatorCallback func (p Point2D )
73
- powerstateCallback func (p sphero .PowerStatePacket )
73
+ powerstateCallback func (p spherocommon .PowerStatePacket )
74
74
}
75
75
76
76
// NewOllieDriver creates a driver for a Sphero Ollie
@@ -80,7 +80,7 @@ func NewOllieDriver(a gobot.BLEConnector, opts ...ble.OptionApplier) *OllieDrive
80
80
81
81
func newOllieBaseDriver (
82
82
a gobot.BLEConnector , name string ,
83
- dcc sphero .CollisionConfig , opts ... ble.OptionApplier ,
83
+ dcc spherocommon .CollisionConfig , opts ... ble.OptionApplier ,
84
84
) * OllieDriver {
85
85
d := & OllieDriver {
86
86
defaultCollisionConfig : dcc ,
@@ -89,8 +89,8 @@ func newOllieBaseDriver(
89
89
}
90
90
d .Driver = ble .NewDriver (a , name , d .initialize , d .shutdown , opts ... )
91
91
92
- d .AddEvent (sphero .ErrorEvent )
93
- d .AddEvent (sphero .CollisionEvent )
92
+ d .AddEvent (spherocommon .ErrorEvent )
93
+ d .AddEvent (spherocommon .CollisionEvent )
94
94
95
95
return d
96
96
}
@@ -118,7 +118,7 @@ func (d *OllieDriver) Wake() error {
118
118
}
119
119
120
120
// ConfigureCollisionDetection configures the sensitivity of the detection.
121
- func (d * OllieDriver ) ConfigureCollisionDetection (cc sphero .CollisionConfig ) {
121
+ func (d * OllieDriver ) ConfigureCollisionDetection (cc spherocommon .CollisionConfig ) {
122
122
d .sendCraftPacket ([]uint8 {cc .Method , cc .Xt , cc .Yt , cc .Xs , cc .Ys , cc .Dead }, 0x02 , 0x12 )
123
123
}
124
124
@@ -130,7 +130,7 @@ func (d *OllieDriver) GetLocatorData(f func(p Point2D)) {
130
130
}
131
131
132
132
// GetPowerState calls the passed function with the Power State information from the sphero
133
- func (d * OllieDriver ) GetPowerState (f func (p sphero .PowerStatePacket )) {
133
+ func (d * OllieDriver ) GetPowerState (f func (p spherocommon .PowerStatePacket )) {
134
134
// CID 0x20 is the code for the power state
135
135
d .sendCraftPacket ([]uint8 {}, 0x00 , 0x20 )
136
136
d .powerstateCallback = f
@@ -194,7 +194,7 @@ func (d *OllieDriver) Sleep() {
194
194
}
195
195
196
196
// SetDataStreamingConfig passes the config to the sphero to stream sensor data
197
- func (d * OllieDriver ) SetDataStreamingConfig (dsc sphero .DataStreamingConfig ) error {
197
+ func (d * OllieDriver ) SetDataStreamingConfig (dsc spherocommon .DataStreamingConfig ) error {
198
198
buf := new (bytes.Buffer )
199
199
if err := binary .Write (buf , binary .BigEndian , dsc ); err != nil {
200
200
return err
@@ -225,7 +225,7 @@ func (d *OllieDriver) initialize() error {
225
225
packet := <- d .packetChannel
226
226
err := d .writeCommand (packet )
227
227
if err != nil {
228
- d .Publish (d .Event (sphero .ErrorEvent ), err )
228
+ d .Publish (d .Event (spherocommon .ErrorEvent ), err )
229
229
}
230
230
}
231
231
}()
@@ -331,13 +331,13 @@ func (d *OllieDriver) handleDataStreaming(data []byte) {
331
331
332
332
// data packet is the same as for the normal sphero, since the same communication api is used
333
333
// only difference in communication is that the "newer" spheros use BLE for communications
334
- var dataPacket sphero .DataStreamingPacket
334
+ var dataPacket spherocommon .DataStreamingPacket
335
335
buffer := bytes .NewBuffer (data [5 :]) // skip header
336
336
if err := binary .Read (buffer , binary .BigEndian , & dataPacket ); err != nil {
337
337
panic (err )
338
338
}
339
339
340
- d .Publish (sphero .SensorDataEvent , dataPacket )
340
+ d .Publish (spherocommon .SensorDataEvent , dataPacket )
341
341
}
342
342
343
343
func (d * OllieDriver ) handleLocatorDetected (data []uint8 ) {
@@ -368,7 +368,7 @@ func (d *OllieDriver) handleLocatorDetected(data []uint8) {
368
368
}
369
369
370
370
func (d * OllieDriver ) handlePowerStateDetected (data []uint8 ) {
371
- var dataPacket sphero .PowerStatePacket
371
+ var dataPacket spherocommon .PowerStatePacket
372
372
buffer := bytes .NewBuffer (data [5 :]) // skip header
373
373
if err := binary .Read (buffer , binary .BigEndian , & dataPacket ); err != nil {
374
374
panic (err )
@@ -404,18 +404,18 @@ func (d *OllieDriver) handleCollisionDetected(data []uint8) {
404
404
// confirm checksum
405
405
size := len (d .collisionResponse )
406
406
chk := d .collisionResponse [size - 1 ] // last byte is checksum
407
- if chk != sphero .CalculateChecksum (d .collisionResponse [2 :size - 1 ]) {
407
+ if chk != spherocommon .CalculateChecksum (d .collisionResponse [2 :size - 1 ]) {
408
408
return
409
409
}
410
410
411
- var collision sphero .CollisionPacket
411
+ var collision spherocommon .CollisionPacket
412
412
buffer := bytes .NewBuffer (d .collisionResponse [5 :]) // skip header
413
413
if err := binary .Read (buffer , binary .BigEndian , & collision ); err != nil {
414
414
panic (err )
415
415
}
416
416
d .collisionResponse = nil // clear the current response
417
417
418
- d .Publish (sphero .CollisionEvent , collision )
418
+ d .Publish (spherocommon .CollisionEvent , collision )
419
419
}
420
420
421
421
func (d * OllieDriver ) sendCraftPacket (body []uint8 , did byte , cid byte ) {
@@ -430,15 +430,15 @@ func (d *OllieDriver) craftPacket(body []uint8, did byte, cid byte) *packet {
430
430
packet := & packet {
431
431
body : body ,
432
432
header : hdr ,
433
- checksum : sphero .CalculateChecksum (buf [2 :]),
433
+ checksum : spherocommon .CalculateChecksum (buf [2 :]),
434
434
}
435
435
436
436
return packet
437
437
}
438
438
439
439
// ollieDefaultCollisionConfig returns a CollisionConfig with sensible collision defaults
440
- func ollieDefaultCollisionConfig () sphero .CollisionConfig {
441
- return sphero .CollisionConfig {
440
+ func ollieDefaultCollisionConfig () spherocommon .CollisionConfig {
441
+ return spherocommon .CollisionConfig {
442
442
Method : 0x01 ,
443
443
Xt : 0x20 ,
444
444
Yt : 0x20 ,
0 commit comments