Skip to content

Commit a692700

Browse files
author
dcyoung
committed
Added reset command and simplified azimuth conversion
1 parent e961205 commit a692700

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

Sweep/Sweep.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,11 @@ bool Sweep::getReading(ScanPacket &reading)
6060
{
6161
// TODO: validate receipt
6262
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]));
6665
reading.distance = (_responseScanPacket[4] << 8) + (_responseScanPacket[3]);
6766
reading.signalStrength = _responseScanPacket[5];
68-
return (reading.distance <= 1) ? false : true;
67+
return true;
6968
}
7069
return false;
7170
}
@@ -173,6 +172,11 @@ bool Sweep::setSampleRate(const uint8_t sampleRateCode[2])
173172
return false;
174173
}
175174

175+
void Sweep::reset()
176+
{
177+
_writeCommand(_RESET_DEVICE);
178+
}
179+
176180
bool Sweep::_writeCommand(const uint8_t cmd[2])
177181
{
178182
const uint8_t command[3] = {cmd[0], cmd[1], _COMMAND_TERMINATION};

Sweep/Sweep.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ class Sweep
127127
*/
128128
bool setSampleRate(const uint8_t sampleRateCode[2]);
129129

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+
130138
private:
131139
// The stream object connected to the sweep device.
132140
Stream &_serial;
@@ -166,8 +174,13 @@ class Sweep
166174
bool _readResponseInfoSetting();
167175
void _flushInputBuffer();
168176

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+
171184
// converts a pair of ascii code (between '00':'10') into an integer
172185
inline const int32_t _ascii_bytes_to_integer(const uint8_t bytes[2])
173186
{

Sweep/keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ getMotorSpeed KEYWORD2
2121
setMotorSpeed KEYWORD2
2222
getSampleRate KEYWORD2
2323
setSampleRate KEYWORD2
24+
reset KEYWORD2
2425

2526
#######################################
2627
# Constants (LITERAL1)

0 commit comments

Comments
 (0)