got interrupts working
This commit is contained in:
@@ -19,53 +19,19 @@
|
||||
/* Buffer to hold incoming characters */
|
||||
uint8_t packetbuffer[READ_BUFSIZE+1];
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Casts the four bytes at the specified address to a float
|
||||
*/
|
||||
/**************************************************************************/
|
||||
float parsefloat(uint8_t *buffer) {
|
||||
float f = ((float *)buffer)[0];
|
||||
return f;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Prints a hexadecimal value in plain characters
|
||||
@param data Pointer to the byte data
|
||||
@param numBytes Data length in bytes
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void printHex(const uint8_t * data, const uint32_t numBytes)
|
||||
{
|
||||
void printHex(const uint8_t * data, const uint32_t numBytes) {
|
||||
uint32_t szPos;
|
||||
for (szPos=0; szPos < numBytes; szPos++)
|
||||
{
|
||||
for (szPos=0; szPos < numBytes; szPos++) {
|
||||
Serial.print(F("0x"));
|
||||
// Append leading 0 for small values
|
||||
if (data[szPos] <= 0xF)
|
||||
{
|
||||
Serial.print(F("0"));
|
||||
Serial.print(data[szPos] & 0xf, HEX);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(data[szPos] & 0xff, HEX);
|
||||
}
|
||||
Serial.print(data[szPos], HEX);
|
||||
// Add a trailing space if appropriate
|
||||
if ((numBytes > 1) && (szPos != numBytes - 1))
|
||||
{
|
||||
if ((numBytes > 1) && (szPos != numBytes - 1)) {
|
||||
Serial.print(F(" "));
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Waits for incoming data and parses it
|
||||
*/
|
||||
/**************************************************************************/
|
||||
uint8_t readPacket(Adafruit_BLE *ble, uint16_t timeout)
|
||||
{
|
||||
uint16_t origtimeout = timeout, replyidx = 0;
|
||||
@@ -93,9 +59,7 @@ uint8_t readPacket(Adafruit_BLE *ble, uint16_t timeout)
|
||||
if (timeout == 0) break;
|
||||
delay(1);
|
||||
}
|
||||
//Serial.println();
|
||||
|
||||
//return;
|
||||
packetbuffer[replyidx] = 0; // null term
|
||||
|
||||
if (!replyidx) // no data or timeout
|
||||
@@ -113,8 +77,7 @@ uint8_t readPacket(Adafruit_BLE *ble, uint16_t timeout)
|
||||
xsum = ~xsum;
|
||||
|
||||
// Throw an error message if the checksum's don't match
|
||||
if (xsum != checksum)
|
||||
{
|
||||
if (xsum != checksum){
|
||||
Serial.print("Checksum mismatch in packet : ");
|
||||
printHex(packetbuffer, replyidx+1);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user