File tree Expand file tree Collapse file tree 3 files changed +24
-6
lines changed Expand file tree Collapse file tree 3 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -60,12 +60,11 @@ bool Sweep::getReading(ScanPacket &reading)
60
60
{
61
61
// TODO: validate receipt
62
62
reading.bIsSync = _responseScanPacket[0 ] % 2 == 1 ;
63
- // convert the angle into a float according sweep protocol (in degrees),
64
- // then store that value in a 16 bit unsigned int by converting it to millidegrees
65
- reading.angle = _u16_to_f32 ((_responseScanPacket[2 ] << 8 ) + (_responseScanPacket[1 ]));
63
+ // convert the angle into a float in degrees
64
+ reading.angle = angle_raw_to_deg ((_responseScanPacket[2 ] << 8 ) + (_responseScanPacket[1 ]));
66
65
reading.distance = (_responseScanPacket[4 ] << 8 ) + (_responseScanPacket[3 ]);
67
66
reading.signalStrength = _responseScanPacket[5 ];
68
- return (reading. distance <= 1 ) ? false : true ;
67
+ return true ;
69
68
}
70
69
return false ;
71
70
}
@@ -173,6 +172,11 @@ bool Sweep::setSampleRate(const uint8_t sampleRateCode[2])
173
172
return false ;
174
173
}
175
174
175
+ void Sweep::reset ()
176
+ {
177
+ _writeCommand (_RESET_DEVICE);
178
+ }
179
+
176
180
bool Sweep::_writeCommand (const uint8_t cmd[2 ])
177
181
{
178
182
const uint8_t command[3 ] = {cmd[0 ], cmd[1 ], _COMMAND_TERMINATION};
Original file line number Diff line number Diff line change @@ -127,6 +127,14 @@ class Sweep
127
127
*/
128
128
bool setSampleRate (const uint8_t sampleRateCode[2 ]);
129
129
130
+ /* *
131
+ * Resets the device.
132
+ * Warning: attempting to communicate with the device while
133
+ * it is resetting will cause issues. Device is ready
134
+ * when the LED turns blue.
135
+ */
136
+ void reset ();
137
+
130
138
private:
131
139
// The stream object connected to the sweep device.
132
140
Stream &_serial;
@@ -166,8 +174,13 @@ class Sweep
166
174
bool _readResponseInfoSetting ();
167
175
void _flushInputBuffer ();
168
176
169
- // converts a uint16_t representing a float into an f32
170
- inline float _u16_to_f32 (uint16_t v) { return ((float )(v >> 4u )) + (v & 15u ) / 16 .0f ; }
177
+ // Some protocol conversion utilities
178
+ inline int angle_raw_to_deg (uint16_t v)
179
+ {
180
+ // angle is transmitted as fixed point integer with scaling factor of 16
181
+ return static_cast <int >(v / 16 .0f );
182
+ }
183
+
171
184
// converts a pair of ascii code (between '00':'10') into an integer
172
185
inline const int32_t _ascii_bytes_to_integer (const uint8_t bytes[2 ])
173
186
{
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ getMotorSpeed KEYWORD2
21
21
setMotorSpeed KEYWORD2
22
22
getSampleRate KEYWORD2
23
23
setSampleRate KEYWORD2
24
+ reset KEYWORD2
24
25
25
26
#######################################
26
27
# Constants (LITERAL1)
You can’t perform that action at this time.
0 commit comments