Skip to content

Commit 5b9f26c

Browse files
committed
Return ReportID being read from the sensor
1 parent 34e6c96 commit 5b9f26c

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/SparkFun_BNO080_Arduino_Library.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void BNO080::enableDebugging(Stream &debugPort)
171171

172172
//Updates the latest variables if possible
173173
//Returns false if new readings are not available
174-
bool BNO080::dataAvailable(void)
174+
uint16_t BNO080::dataAvailable(void)
175175
{
176176
//If we have an interrupt pin connection available, check if data is available.
177177
//If int pin is not set, then we'll rely on receivePacket() to timeout
@@ -187,21 +187,18 @@ bool BNO080::dataAvailable(void)
187187
//Check to see if this packet is a sensor reporting its data to us
188188
if (shtpHeader[2] == CHANNEL_REPORTS && shtpData[0] == SHTP_REPORT_BASE_TIMESTAMP)
189189
{
190-
parseInputReport(); //This will update the rawAccelX, etc variables depending on which feature report is found
191-
return (true);
190+
return parseInputReport(); //This will update the rawAccelX, etc variables depending on which feature report is found
192191
}
193192
else if (shtpHeader[2] == CHANNEL_CONTROL)
194193
{
195-
parseCommandReport(); //This will update responses to commands, calibrationStatus, etc.
196-
return (true);
194+
return parseCommandReport(); //This will update responses to commands, calibrationStatus, etc.
197195
}
198196
else if(shtpHeader[2] == CHANNEL_GYRO)
199197
{
200-
parseInputReport(); //This will update the rawAccelX, etc variables depending on which feature report is found
201-
return (true);
198+
return parseInputReport(); //This will update the rawAccelX, etc variables depending on which feature report is found
202199
}
203200
}
204-
return (false);
201+
return 0;
205202
}
206203

207204
//This function pulls the data from the command response report
@@ -222,7 +219,7 @@ bool BNO080::dataAvailable(void)
222219
//shtpData[5 + 6]: R6
223220
//shtpData[5 + 7]: R7
224221
//shtpData[5 + 8]: R8
225-
void BNO080::parseCommandReport(void)
222+
uint16_t BNO080::parseCommandReport(void)
226223
{
227224
if (shtpData[0] == SHTP_REPORT_COMMAND_RESPONSE)
228225
{
@@ -233,6 +230,7 @@ void BNO080::parseCommandReport(void)
233230
{
234231
calibrationStatus = shtpData[5 + 0]; //R0 - Status (0 = success, non-zero = fail)
235232
}
233+
return shtpData[0];
236234
}
237235
else
238236
{
@@ -241,6 +239,7 @@ void BNO080::parseCommandReport(void)
241239
}
242240

243241
//TODO additional feature reports may be strung together. Parse them all.
242+
return 0;
244243
}
245244

246245
//This function pulls the data from the input report
@@ -258,7 +257,7 @@ void BNO080::parseCommandReport(void)
258257
//shtpData[8:9]: k/accel z/gyro z/etc
259258
//shtpData[10:11]: real/gyro temp/etc
260259
//shtpData[12:13]: Accuracy estimate
261-
void BNO080::parseInputReport(void)
260+
uint16_t BNO080::parseInputReport(void)
262261
{
263262
//Calculate the number of data bytes in this packet
264263
int16_t dataLength = ((uint16_t)shtpHeader[1] << 8 | shtpHeader[0]);
@@ -279,7 +278,7 @@ void BNO080::parseInputReport(void)
279278
rawFastGyroY = (uint16_t)shtpData[11] << 8 | shtpData[10];
280279
rawFastGyroZ = (uint16_t)shtpData[13] << 8 | shtpData[12];
281280

282-
return;
281+
return SENSOR_REPORTID_GYRO_INTEGRATED_ROTATION_VECTOR;
283282
}
284283

285284
uint8_t status = shtpData[5 + 2] & 0x03; //Get status bits
@@ -398,9 +397,11 @@ void BNO080::parseInputReport(void)
398397
{
399398
//This sensor report ID is unhandled.
400399
//See reference manual to add additional feature reports as needed
400+
return 0;
401401
}
402402

403403
//TODO additional feature reports may be strung together. Parse them all.
404+
return shtpData[5];
404405
}
405406

406407
// Quaternion to Euler conversion

src/SparkFun_BNO080_Arduino_Library.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ class BNO080
164164
void enableRawMagnetometer(uint16_t timeBetweenReports);
165165
void enableGyroIntegratedRotationVector(uint16_t timeBetweenReports);
166166

167-
bool dataAvailable(void);
168-
void parseInputReport(void); //Parse sensor readings out of report
169-
void parseCommandReport(void); //Parse command responses out of report
167+
uint16_t dataAvailable(void);
168+
uint16_t parseInputReport(void); //Parse sensor readings out of report
169+
uint16_t parseCommandReport(void); //Parse command responses out of report
170170

171171
float getQuatI();
172172
float getQuatJ();

0 commit comments

Comments
 (0)