diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml new file mode 100644 index 0000000..03bfe06 --- /dev/null +++ b/.github/workflows/githubci.yml @@ -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 diff --git a/README.md b/README.md index 68995df..6810083 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples/ble_controller/packetParser.cpp b/examples/ble_controller/packetParser.cpp index 0ccf583..2130320 100644 --- a/examples/ble_controller/packetParser.cpp +++ b/examples/ble_controller/packetParser.cpp @@ -1,60 +1,52 @@ -#include #include #include +#include -#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(" ")); } } @@ -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)) @@ -90,7 +82,7 @@ uint8_t readPacket(Stream *ble, uint16_t timeout) break; while (ble->available()) { - char c = ble->read(); + char c = ble->read(); if (c == '!') { replyidx = 0; } @@ -98,35 +90,35 @@ uint8_t readPacket(Stream *ble, uint16_t timeout) 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 sentence=Arduino library for using micro:bit nRF51 @@ -7,3 +7,4 @@ paragraph=Now you can use the micro:bit board with Arduino IDE - and this librar category=Device Control url=https://github.com/adafruit/Adafruit_Microbit architectures=* +depends=Adafruit GFX Library, SparkFun MAG3110 Magnetometer Breakout Arduino Library, STM32duino LSM303AGR, BLEPeripheral \ No newline at end of file