Skip to content

Commit ddfa557

Browse files
authored
Merge pull request #55 from ya-mouse/SP-reportID
Return ReportID being read from the sensor
2 parents 34e6c96 + feb3021 commit ddfa557

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/SparkFun_BNO080_Arduino_Library.cpp

+17-11
Original file line numberDiff line numberDiff line change
@@ -172,36 +172,38 @@ void BNO080::enableDebugging(Stream &debugPort)
172172
//Updates the latest variables if possible
173173
//Returns false if new readings are not available
174174
bool BNO080::dataAvailable(void)
175+
{
176+
return (getReadings() != 0);
177+
}
178+
179+
uint16_t BNO080::getReadings(void)
175180
{
176181
//If we have an interrupt pin connection available, check if data is available.
177182
//If int pin is not set, then we'll rely on receivePacket() to timeout
178183
//See issue 13: https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/issues/13
179184
if (_int != 255)
180185
{
181186
if (digitalRead(_int) == HIGH)
182-
return (false);
187+
return 0;
183188
}
184189

185190
if (receivePacket() == true)
186191
{
187192
//Check to see if this packet is a sensor reporting its data to us
188193
if (shtpHeader[2] == CHANNEL_REPORTS && shtpData[0] == SHTP_REPORT_BASE_TIMESTAMP)
189194
{
190-
parseInputReport(); //This will update the rawAccelX, etc variables depending on which feature report is found
191-
return (true);
195+
return parseInputReport(); //This will update the rawAccelX, etc variables depending on which feature report is found
192196
}
193197
else if (shtpHeader[2] == CHANNEL_CONTROL)
194198
{
195-
parseCommandReport(); //This will update responses to commands, calibrationStatus, etc.
196-
return (true);
199+
return parseCommandReport(); //This will update responses to commands, calibrationStatus, etc.
197200
}
198201
else if(shtpHeader[2] == CHANNEL_GYRO)
199202
{
200-
parseInputReport(); //This will update the rawAccelX, etc variables depending on which feature report is found
201-
return (true);
203+
return parseInputReport(); //This will update the rawAccelX, etc variables depending on which feature report is found
202204
}
203205
}
204-
return (false);
206+
return 0;
205207
}
206208

207209
//This function pulls the data from the command response report
@@ -222,7 +224,7 @@ bool BNO080::dataAvailable(void)
222224
//shtpData[5 + 6]: R6
223225
//shtpData[5 + 7]: R7
224226
//shtpData[5 + 8]: R8
225-
void BNO080::parseCommandReport(void)
227+
uint16_t BNO080::parseCommandReport(void)
226228
{
227229
if (shtpData[0] == SHTP_REPORT_COMMAND_RESPONSE)
228230
{
@@ -233,6 +235,7 @@ void BNO080::parseCommandReport(void)
233235
{
234236
calibrationStatus = shtpData[5 + 0]; //R0 - Status (0 = success, non-zero = fail)
235237
}
238+
return shtpData[0];
236239
}
237240
else
238241
{
@@ -241,6 +244,7 @@ void BNO080::parseCommandReport(void)
241244
}
242245

243246
//TODO additional feature reports may be strung together. Parse them all.
247+
return 0;
244248
}
245249

246250
//This function pulls the data from the input report
@@ -258,7 +262,7 @@ void BNO080::parseCommandReport(void)
258262
//shtpData[8:9]: k/accel z/gyro z/etc
259263
//shtpData[10:11]: real/gyro temp/etc
260264
//shtpData[12:13]: Accuracy estimate
261-
void BNO080::parseInputReport(void)
265+
uint16_t BNO080::parseInputReport(void)
262266
{
263267
//Calculate the number of data bytes in this packet
264268
int16_t dataLength = ((uint16_t)shtpHeader[1] << 8 | shtpHeader[0]);
@@ -279,7 +283,7 @@ void BNO080::parseInputReport(void)
279283
rawFastGyroY = (uint16_t)shtpData[11] << 8 | shtpData[10];
280284
rawFastGyroZ = (uint16_t)shtpData[13] << 8 | shtpData[12];
281285

282-
return;
286+
return SENSOR_REPORTID_GYRO_INTEGRATED_ROTATION_VECTOR;
283287
}
284288

285289
uint8_t status = shtpData[5 + 2] & 0x03; //Get status bits
@@ -398,9 +402,11 @@ void BNO080::parseInputReport(void)
398402
{
399403
//This sensor report ID is unhandled.
400404
//See reference manual to add additional feature reports as needed
405+
return 0;
401406
}
402407

403408
//TODO additional feature reports may be strung together. Parse them all.
409+
return shtpData[5];
404410
}
405411

406412
// Quaternion to Euler conversion

src/SparkFun_BNO080_Arduino_Library.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ class BNO080
165165
void enableGyroIntegratedRotationVector(uint16_t timeBetweenReports);
166166

167167
bool dataAvailable(void);
168-
void parseInputReport(void); //Parse sensor readings out of report
169-
void parseCommandReport(void); //Parse command responses out of report
168+
uint16_t getReadings(void);
169+
uint16_t parseInputReport(void); //Parse sensor readings out of report
170+
uint16_t parseCommandReport(void); //Parse command responses out of report
170171

171172
float getQuatI();
172173
float getQuatJ();

0 commit comments

Comments
 (0)