Skip to content

Commit

Permalink
Merge pull request #8 from adafruit/actionci
Browse files Browse the repository at this point in the history
Actionci
  • Loading branch information
ladyada authored Dec 28, 2019
2 parents 79ca700 + c2768f7 commit 8ca62f4
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 44 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/githubci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Arduino Library CI

on: [pull_request, push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
repository: adafruit/ci-arduino
path: ci

- name: pre-install
run: bash ci/actions_install.sh

- name: install other libraries
run: |
wget https://cdn-learn.adafruit.com/assets/assets/000/046/217/original/MMA8653.zip
unzip MMA8653.zip
mv MMA8653 /home/runner/Arduino/libraries
- name: test platforms
run: python3 ci/build_platform.py microbit

- name: clang
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .

- name: doxygen
env:
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
PRETTYNAME : "Adafruit micro:bit Library"
run: bash ci/doxy_gen_and_deploy.sh
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Adafruit MicroBit library
# Adafruit MicroBit library ![Build Status](https://github.com/adafruit/Adafruit_Microbit/workflows/Arduino%20Library%20CI/badge.svg)


Wrapper code and examples for using microbit with arduino IDE

Expand Down
76 changes: 34 additions & 42 deletions examples/ble_controller/packetParser.cpp
Original file line number Diff line number Diff line change
@@ -1,60 +1,52 @@
#include <string.h>
#include <Arduino.h>
#include <SPI.h>
#include <string.h>

#define PACKET_ACC_LEN (15)
#define PACKET_GYRO_LEN (15)
#define PACKET_MAG_LEN (15)
#define PACKET_QUAT_LEN (19)
#define PACKET_BUTTON_LEN (5)
#define PACKET_COLOR_LEN (6)
#define PACKET_LOCATION_LEN (15)
#define PACKET_ACC_LEN (15)
#define PACKET_GYRO_LEN (15)
#define PACKET_MAG_LEN (15)
#define PACKET_QUAT_LEN (19)
#define PACKET_BUTTON_LEN (5)
#define PACKET_COLOR_LEN (6)
#define PACKET_LOCATION_LEN (15)

// READ_BUFSIZE Size of the read buffer for incoming packets
#define READ_BUFSIZE (20)

#define READ_BUFSIZE (20)

/* Buffer to hold incoming characters */
uint8_t packetbuffer[READ_BUFSIZE+1];
uint8_t packetbuffer[READ_BUFSIZE + 1];

/**************************************************************************/
/*!
@brief Casts the four bytes at the specified address to a float
*/
/**************************************************************************/
float parsefloat(uint8_t *buffer)
{
float parsefloat(uint8_t *buffer) {
float f;
memcpy(&f, buffer, 4);
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)
{
if (data[szPos] <= 0xF) {
Serial.print(F("0"));
Serial.print(data[szPos] & 0xf, HEX);
}
else
{
} else {
Serial.print(data[szPos] & 0xff, HEX);
}
// Add a trailing space if appropriate
if ((numBytes > 1) && (szPos != numBytes - 1))
{
if ((numBytes > 1) && (szPos != numBytes - 1)) {
Serial.print(F(" "));
}
}
Expand All @@ -66,14 +58,14 @@ void printHex(const uint8_t * data, const uint32_t numBytes)
@brief Waits for incoming data and parses it
*/
/**************************************************************************/
uint8_t readPacket(Stream *ble, uint16_t timeout)
{
uint8_t readPacket(Stream *ble, uint16_t timeout) {
uint16_t origtimeout = timeout, replyidx = 0;

memset(packetbuffer, 0, READ_BUFSIZE);

while (timeout--) {
if (replyidx >= 20) break;
if (replyidx >= 20)
break;
if ((packetbuffer[1] == 'A') && (replyidx == PACKET_ACC_LEN))
break;
if ((packetbuffer[1] == 'G') && (replyidx == PACKET_GYRO_LEN))
Expand All @@ -90,43 +82,43 @@ uint8_t readPacket(Stream *ble, uint16_t timeout)
break;

while (ble->available()) {
char c = ble->read();
char c = ble->read();
if (c == '!') {
replyidx = 0;
}
packetbuffer[replyidx] = c;
replyidx++;
timeout = origtimeout;
}

if (timeout == 0) break;

if (timeout == 0)
break;
delay(1);
}

packetbuffer[replyidx] = 0; // null term
packetbuffer[replyidx] = 0; // null term

if (!replyidx) // no data or timeout
if (!replyidx) // no data or timeout
return 0;
if (packetbuffer[0] != '!') // doesn't start with '!' packet beginning
if (packetbuffer[0] != '!') // doesn't start with '!' packet beginning
return 0;

// check checksum!
uint8_t xsum = 0;
uint8_t checksum = packetbuffer[replyidx-1];
for (uint8_t i=0; i<replyidx-1; i++) {
uint8_t checksum = packetbuffer[replyidx - 1];

for (uint8_t i = 0; i < replyidx - 1; i++) {
xsum += packetbuffer[i];
}
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);
printHex(packetbuffer, replyidx + 1);
return 0;
}

// checksum passed!
return replyidx;
}
3 changes: 2 additions & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name=Adafruit microbit Library
version=1.1.0
version=1.2.0
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for using micro:bit nRF51
paragraph=Now you can use the micro:bit board with Arduino IDE - and this library will give you an interface to the LED matrix and BTLE for use with the Adafruit Bluefruit Connect app
category=Device Control
url=https://github.com/adafruit/Adafruit_Microbit
architectures=*
depends=Adafruit GFX Library, SparkFun MAG3110 Magnetometer Breakout Arduino Library, STM32duino LSM303AGR, BLEPeripheral

0 comments on commit 8ca62f4

Please sign in to comment.