diff --git a/.arduino-ci.yml b/.arduino-ci.yml new file mode 100644 index 0000000..ff5659b --- /dev/null +++ b/.arduino-ci.yml @@ -0,0 +1,7 @@ +compile: + # Choosing to run compilation tests on 2 different Arduino platforms + platforms: + - uno + - leonardo + - due + - zero diff --git a/.github/workflows/arduino_test_runner.yml b/.github/workflows/arduino_test_runner.yml new file mode 100644 index 0000000..476456b --- /dev/null +++ b/.github/workflows/arduino_test_runner.yml @@ -0,0 +1,13 @@ +--- +name: Arduino CI + +on: [push, pull_request] + +jobs: + arduino_ci: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: Arduino-CI/action@master + # Arduino-CI/action@v0.1.1 diff --git a/GY521.cpp b/GY521.cpp index caddb89..cb153b0 100644 --- a/GY521.cpp +++ b/GY521.cpp @@ -1,18 +1,19 @@ // // FILE: GY521.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.2.0 +// VERSION: 0.2.1 // PURPOSE: Arduino library for I2C GY521 accelerometer-gyroscope sensor // URL: https://github.com/RobTillaart/GY521 // -// HISTORY: -// 0.1.0 2017-11-20 initial version -// 0.1.1 2020-07-09 refactor + initial release -// 0.1.2 2020-08-06 fix setAccelSensitivity + add getters -// 0.1.3 2020-08-07 fix ESP support + pitch roll yaw demo -// 0.1.4 2020-09-29 fix #5 missing ; -// 0.1.5 2020-09-29 fix #6 fix math for Teensy -// 0.2.0 2020-11-03 improve error handling +// HISTORY: +// 0.1.0 2017-11-20 initial version +// 0.1.1 2020-07-09 refactor + initial release +// 0.1.2 2020-08-06 fix setAccelSensitivity + add getters +// 0.1.3 2020-08-07 fix ESP support + pitch roll yaw demo +// 0.1.4 2020-09-29 fix #5 missing ; +// 0.1.5 2020-09-29 fix #6 fix math for Teensy +// 0.2.0 2020-11-03 improve error handling +// 0.2.1 2020-12-24 arduino-ci + unit tests #include "GY521.h" diff --git a/GY521.h b/GY521.h index 1984ef9..4d28d08 100644 --- a/GY521.h +++ b/GY521.h @@ -2,7 +2,7 @@ // // FILE: GY521.h // AUTHOR: Rob Tillaart -// VERSION: 0.2.0 +// VERSION: 0.2.1 // PURPOSE: Arduino library for I2C GY521 accelerometer-gyroscope sensor // URL: https://github.com/RobTillaart/GY521 // @@ -13,7 +13,7 @@ #include "Arduino.h" #include "Wire.h" -#define GY521_LIB_VERSION (F("0.2.0")) +#define GY521_LIB_VERSION (F("0.2.1")) #ifndef GY521_THROTTLE_TIME #define GY521_THROTTLE_TIME 10 // milliseconds diff --git a/README.md b/README.md index d46391b..372835a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ + +[![Arduino CI](https://github.com/RobTillaart/GY521/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) +[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/GY521/blob/master/LICENSE) +[![GitHub release](https://img.shields.io/github/release/RobTillaart/GY521.svg?maxAge=3600)](https://github.com/RobTillaart/GY521/releases) + # GY521 Arduino library for I2C GY521 accelerometer-gyroscope sensor a.k.a. MCU-6050 @@ -21,7 +26,6 @@ It has three examples 1. wait until the middle 6 of the longer lines stabilize (should all be 0) 1. copy the 6 numbers above the axe aye aze as these are the numbers needed. - ## Future **Should** @@ -33,7 +37,6 @@ It has three examples - calibrate function in the lib ? (think not as lib might grow?) - calibrate sketch could print code snippet to include... - ## documents - check details - MPU-6000-Register-Map1.pdf diff --git a/library.json b/library.json index 2b34b11..65f7020 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/GY521.git" }, - "version":"0.2.0", + "version":"0.2.1", "frameworks": "arduino", "platforms": "*" } diff --git a/library.properties b/library.properties index 520e117..a268629 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=GY521 -version=0.2.0 +version=0.2.1 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for GY521 angle measurement diff --git a/test/unit_test_001.cpp b/test/unit_test_001.cpp new file mode 100644 index 0000000..db824ad --- /dev/null +++ b/test/unit_test_001.cpp @@ -0,0 +1,108 @@ +// +// FILE: unit_test_001.cpp +// AUTHOR: Rob Tillaart +// DATE: 2020-12-24 +// PURPOSE: unit tests for the GY521 +// https://github.com/RobTillaart/GY521 +// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md +// + +// supported assertions +// https://github.com/Arduino-CI/arduino_ci/blob/master/cpp/unittest/Assertion.h#L33-L42 +// ---------------------------- +// assertEqual(expected, actual) +// assertNotEqual(expected, actual) +// assertLess(expected, actual) +// assertMore(expected, actual) +// assertLessOrEqual(expected, actual) +// assertMoreOrEqual(expected, actual) +// assertTrue(actual) +// assertFalse(actual) +// assertNull(actual) +// assertNotNull(actual) + +#include + +#define assertEqualFloat(arg1, arg2, arg3) assertOp("assertEqualFloat", "expected", fabs(arg1 - arg2), compareLessOrEqual, "<=", "actual", arg3) +#define assertEqualINF(arg) assertOp("assertEqualINF", "expected", INFINITY, compareEqual, "==", "actual", arg) +#define assertEqualNAN(arg) assertOp("assertEqualNAN", "expected", true, compareEqual, "==", "actual", isnan(arg)) + + +#include "Arduino.h" +#include "GY521.h" + + + +unittest_setup() +{ +} + +unittest_teardown() +{ +} + +/* +unittest(test_new_operator) +{ + assertEqualINF(exp(800)); + assertEqualINF(0.0/0.0); + assertEqualINF(42); + + assertEqualNAN(INFINITY - INFINITY); + assertEqualNAN(0.0/0.0); + assertEqualNAN(42); +} +*/ + +unittest(test_constructor) +{ + GY521 sensor(0x69); + fprintf(stderr, "VERSION: %s\n", GY521_LIB_VERSION); + sensor.begin(); + assertEqual(GY521_OK, sensor.getError()); + + assertTrue(sensor.isConnected()); +} + + +unittest(test_get_set) +{ + GY521 sensor(0x69); + fprintf(stderr, "VERSION: %s\n", GY521_LIB_VERSION); + sensor.begin(); + assertEqual(GY521_OK, sensor.getError()); + + sensor.setThrottle(true); + assertTrue(sensor.getThrottle()); + sensor.setThrottle(false); + assertFalse(sensor.getThrottle()); + + fprintf(stderr, "setThrottleTime()\n"); + for (uint16_t ti = 1; ti != 0; ti <<= 1) + { + sensor.setThrottleTime(ti); + fprintf(stderr, "%d\t", sensor.getThrottleTime()); + assertEqual(ti, sensor.getThrottleTime()); + } + + fprintf(stderr, "setAccelSensitivity() - fails \n"); + for (int as = 0; as < 4; as++) + { + sensor.setAccelSensitivity(as); + // fprintf(stderr, "%d\n", sensor.getAccelSensitivity()); + assertEqual(255, sensor.getAccelSensitivity()); + } + + fprintf(stderr, "setGyroSensitivity() - fails \n"); + for (int gs = 0; gs < 4; gs++) + { + sensor.setGyroSensitivity(gs); + // fprintf(stderr, "%d\n", sensor.getAccelSensitivity()); + assertEqual(255, sensor.getAccelSensitivity()); + } + +} + +unittest_main() + +// --------