Skip to content

Commit d910624

Browse files
authored
Merge pull request #48 from sparkfun/Testing_Issue_#42
Added some debug improvements to help when testing issue #42
2 parents d978711 + 58b2197 commit d910624

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ receivePacket KEYWORD2
2828
getData KEYWORD2
2929
sendPacket KEYWORD2
3030
printPacket KEYWORD2
31+
printHeader KEYWORD2
3132

3233
enableRotationVector KEYWORD2
3334
enableGameRotationVector KEYWORD2

src/SparkFun_BNO080_Arduino_Library.cpp

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ boolean BNO080::begin(uint8_t deviceAddress, TwoWire &wirePort, uint8_t intPin)
5656
{
5757
if (shtpData[0] == SHTP_REPORT_PRODUCT_ID_RESPONSE)
5858
{
59+
if (_printDebug == true)
60+
{
61+
_debugPort->print(F("SW Version Major: 0x"));
62+
_debugPort->print(shtpData[2], HEX);
63+
_debugPort->print(F(" SW Version Minor: 0x"));
64+
_debugPort->print(shtpData[3], HEX);
65+
uint32_t SW_Part_Number = ((uint32_t)shtpData[7] << 24) | ((uint32_t)shtpData[6] << 16) | ((uint32_t)shtpData[5] << 8) | ((uint32_t)shtpData[4]);
66+
_debugPort->print(F(" SW Part Number: 0x"));
67+
_debugPort->print(SW_Part_Number, HEX);
68+
uint32_t SW_Build_Number = ((uint32_t)shtpData[11] << 24) | ((uint32_t)shtpData[10] << 16) | ((uint32_t)shtpData[9] << 8) | ((uint32_t)shtpData[8]);
69+
_debugPort->print(F(" SW Build Number: 0x"));
70+
_debugPort->print(SW_Build_Number, HEX);
71+
uint16_t SW_Version_Patch = ((uint16_t)shtpData[13] << 8) | ((uint16_t)shtpData[12]);
72+
_debugPort->print(F(" SW Version Patch: 0x"));
73+
_debugPort->println(SW_Version_Patch, HEX);
74+
}
5975
return (true);
6076
}
6177
}
@@ -123,6 +139,22 @@ boolean BNO080::beginSPI(uint8_t user_CSPin, uint8_t user_WAKPin, uint8_t user_I
123139
if (receivePacket() == true)
124140
{
125141
if (shtpData[0] == SHTP_REPORT_PRODUCT_ID_RESPONSE)
142+
if (_printDebug == true)
143+
{
144+
_debugPort->print(F("SW Version Major: 0x"));
145+
_debugPort->print(shtpData[2], HEX);
146+
_debugPort->print(F(" SW Version Minor: 0x"));
147+
_debugPort->print(shtpData[3], HEX);
148+
uint32_t SW_Part_Number = ((uint32_t)shtpData[7] << 24) | ((uint32_t)shtpData[6] << 16) | ((uint32_t)shtpData[5] << 8) | ((uint32_t)shtpData[4]);
149+
_debugPort->print(F(" SW Part Number: 0x"));
150+
_debugPort->print(SW_Part_Number, HEX);
151+
uint32_t SW_Build_Number = ((uint32_t)shtpData[11] << 24) | ((uint32_t)shtpData[10] << 16) | ((uint32_t)shtpData[9] << 8) | ((uint32_t)shtpData[8]);
152+
_debugPort->print(F(" SW Build Number: 0x"));
153+
_debugPort->print(SW_Build_Number, HEX);
154+
uint16_t SW_Version_Patch = ((uint16_t)shtpData[13] << 8) | ((uint16_t)shtpData[12]);
155+
_debugPort->print(F(" SW Version Patch: 0x"));
156+
_debugPort->println(SW_Version_Patch, HEX);
157+
}
126158
return (true);
127159
}
128160

@@ -346,13 +378,19 @@ void BNO080::parseInputReport(void)
346378
}
347379
else if (shtpData[5] == SHTP_REPORT_COMMAND_RESPONSE)
348380
{
349-
Serial.println("!");
381+
if (_printDebug == true)
382+
{
383+
_debugPort->println(F("!"));
384+
}
350385
//The BNO080 responds with this report to command requests. It's up to use to remember which command we issued.
351386
uint8_t command = shtpData[5 + 2]; //This is the Command byte of the response
352387

353388
if (command == COMMAND_ME_CALIBRATE)
354389
{
355-
Serial.println("ME Cal report found!");
390+
if (_printDebug == true)
391+
{
392+
_debugPort->println(F("ME Cal report found!"));
393+
}
356394
calibrationStatus = shtpData[5 + 5]; //R0 - Status (0 = success, non-zero = fail)
357395
}
358396
}
@@ -1231,6 +1269,7 @@ boolean BNO080::receivePacket(void)
12311269
if (dataLength == 0)
12321270
{
12331271
//Packet is empty
1272+
printHeader();
12341273
return (false); //All done
12351274
}
12361275
dataLength -= 4; //Remove the header bytes from the data count
@@ -1246,7 +1285,7 @@ boolean BNO080::receivePacket(void)
12461285
digitalWrite(_cs, HIGH); //Release BNO080
12471286

12481287
_spiPort->endTransaction();
1249-
//printPacket();
1288+
printPacket();
12501289
}
12511290
else //Do I2C
12521291
{
@@ -1443,3 +1482,21 @@ void BNO080::printPacket(void)
14431482
_debugPort->println();
14441483
}
14451484
}
1485+
1486+
//Pretty prints the contents of the current shtp header (only)
1487+
void BNO080::printHeader(void)
1488+
{
1489+
if (_printDebug == true)
1490+
{
1491+
//Print the four byte header
1492+
_debugPort->print(F("Header:"));
1493+
for (uint8_t x = 0; x < 4; x++)
1494+
{
1495+
_debugPort->print(F(" "));
1496+
if (shtpHeader[x] < 0x10)
1497+
_debugPort->print(F("0"));
1498+
_debugPort->print(shtpHeader[x], HEX);
1499+
}
1500+
_debugPort->println();
1501+
}
1502+
}

src/SparkFun_BNO080_Arduino_Library.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class BNO080
146146
boolean getData(uint16_t bytesRemaining); //Given a number of bytes, send the requests in I2C_BUFFER_LENGTH chunks
147147
boolean sendPacket(uint8_t channelNumber, uint8_t dataLength);
148148
void printPacket(void); //Prints the current shtp header and data packets
149+
void printHeader(void); //Prints the current shtp header (only)
149150

150151
void enableRotationVector(uint16_t timeBetweenReports);
151152
void enableGameRotationVector(uint16_t timeBetweenReports);

0 commit comments

Comments
 (0)