Skip to content

Commit

Permalink
Arduino ci (#12)
Browse files Browse the repository at this point in the history
* initial arduino-ci
* add unit tests (with some fails as no HW present)
  • Loading branch information
RobTillaart authored Dec 24, 2020
1 parent b116412 commit 5c30a2b
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 15 deletions.
7 changes: 7 additions & 0 deletions .arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
- due
- zero
13 changes: 13 additions & 0 deletions .github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 10 additions & 9 deletions GY521.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions GY521.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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**
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/GY521.git"
},
"version":"0.2.0",
"version":"0.2.1",
"frameworks": "arduino",
"platforms": "*"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=GY521
version=0.2.0
version=0.2.1
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for GY521 angle measurement
Expand Down
108 changes: 108 additions & 0 deletions test/unit_test_001.cpp
Original file line number Diff line number Diff line change
@@ -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 <ArduinoUnitTests.h>

#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()

// --------

0 comments on commit 5c30a2b

Please sign in to comment.