From c8045ca28bc228cfb01894b1d863674f7d9c1e86 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Wed, 30 Dec 2020 20:55:08 +0100 Subject: [PATCH] Arduino ci (#13) * add arduino-ci * add unit test --- .arduino-ci.yml | 7 ++ .github/workflows/arduino_test_runner.yml | 13 +++ MAX31855.cpp | 74 ++++++++------- MAX31855.h | 5 +- README.md | 5 + library.json | 2 +- library.properties | 2 +- test/unit_test_001.cpp | 111 ++++++++++++++++++++++ 8 files changed, 179 insertions(+), 40 deletions(-) create mode 100644 .arduino-ci.yml create mode 100644 .github/workflows/arduino_test_runner.yml create mode 100644 test/unit_test_001.cpp 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/MAX31855.cpp b/MAX31855.cpp index 146249c..d24b99c 100644 --- a/MAX31855.cpp +++ b/MAX31855.cpp @@ -1,28 +1,28 @@ // // FILE: MAX31855.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.2.3 +// VERSION: 0.2.4 // PURPOSE: Arduino library for MAX31855 chip for K type thermocouple // DATE: 2014-01-01 // URL: https://github.com/RobTillaart/MAX31855_RT // -// HISTORY: -// -// 0.2.3 2020-08-30 fix #8 support hardware SPI + example -// 0.2.2 2020-08-30 fix#9 + fix failing examples + minor refactor -// 0.2.1 2020-08-26 read rawData and STATUS_NO_COMMUNICATION recognition (thanks to FabioBrondo) -// 0.2.0 2020-06-20 #pragma once; major refactor; removed pre 1.0 support; fix offset -// 0.1.10 2019-07-31 add 3 inline functions to test errors + demo sketch -// 0.1.9 2017-07-27 reverted double -> float (issue33) -// 0.1.08 2015-12-06 replaced all temperature calls with one TCfactor + update demos. -// 0.1.07 2015-12-06 updated TC factors from the MAX31855 datasheet -// 0.1.06 2015-12-05 added support for other types of TC's (experimental) -// 0.1.05 2015-07-12 refactor robust constructor -// 0.1.04 2015-03-09 replaced float -> double (ARM support) -// 0.1.03 2014-01-24 fixed negative temperature -// 0.1.02 2014-01-03 added offset -// 0.1.01 2014-01-02 refactored speed/performance -// 0.1.00 2014-01-02 initial version. +// HISTORY: +// 0.2.4 2020-12-30 arduinoCI, unit test +// 0.2.3 2020-08-30 fix #8 support hardware SPI + example +// 0.2.2 2020-08-30 fix#9 + fix failing examples + minor refactor +// 0.2.1 2020-08-26 read rawData and STATUS_NO_COMMUNICATION recognition (thanks to FabioBrondo) +// 0.2.0 2020-06-20 #pragma once; major refactor; removed pre 1.0 support; fix offset +// 0.1.10 2019-07-31 add 3 inline functions to test errors + demo sketch +// 0.1.9 2017-07-27 reverted double -> float (issue33) +// 0.1.08 2015-12-06 replaced all temperature calls with one TCfactor + update demos. +// 0.1.07 2015-12-06 updated TC factors from the MAX31855 datasheet +// 0.1.06 2015-12-05 added support for other types of TC's (experimental) +// 0.1.05 2015-07-12 refactor robust constructor +// 0.1.04 2015-03-09 replaced float -> double (ARM support) +// 0.1.03 2014-01-24 fixed negative temperature +// 0.1.02 2014-01-03 added offset +// 0.1.01 2014-01-02 refactored speed/performance +// 0.1.00 2014-01-02 initial version. // @@ -31,28 +31,30 @@ MAX31855::MAX31855(const uint8_t cs) { - _cs = cs; - _hwSPI = true; - - _offset = 0; - _SC = K_TC; - _status = STATUS_NOREAD; - _temperature = -999; - _internal = -999; + _cs = cs; + _hwSPI = true; + + _offset = 0; + _SC = K_TC; + _status = STATUS_NOREAD; + _temperature = MAX31855_NO_TEMPERATURE; + _internal = MAX31855_NO_TEMPERATURE; + _rawData = 0; } MAX31855::MAX31855(const uint8_t sclk, const uint8_t cs, const uint8_t miso) { - _sclk = sclk; - _cs = cs; - _miso = miso; - _hwSPI = false; - - _offset = 0; - _SC = K_TC; - _status = STATUS_NOREAD; - _temperature = -999; - _internal = -999; + _sclk = sclk; + _cs = cs; + _miso = miso; + _hwSPI = false; + + _offset = 0; + _SC = K_TC; + _status = STATUS_NOREAD; + _temperature = MAX31855_NO_TEMPERATURE; + _internal = MAX31855_NO_TEMPERATURE; + _rawData = 0; } void MAX31855::begin() diff --git a/MAX31855.h b/MAX31855.h index 5c16f2b..5d149de 100644 --- a/MAX31855.h +++ b/MAX31855.h @@ -2,7 +2,7 @@ // // FILE: MAX31855.h // AUTHOR: Rob Tillaart -// VERSION: 0.2.3 +// VERSION: 0.2.4 // PURPOSE: Arduino library for MAX31855 chip for K type thermocouple // DATE: 2014-01-01 // URL: https://github.com/RobTillaart/MAX31855_RT @@ -22,8 +22,9 @@ #include "Arduino.h" #include "SPI.h" -#define MAX31855_VERSION "0.2.3" +#define MAX31855_VERSION "0.2.4" +#define MAX31855_NO_TEMPERATURE -999 // STATE constants returnd by read() #define STATUS_OK 0x00 diff --git a/README.md b/README.md index a488293..44365fd 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ + +[![Arduino CI](https://github.com/RobTillaart/MAX31855_RT/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/MAX31855_RT/blob/master/LICENSE) +[![GitHub release](https://img.shields.io/github/release/RobTillaart/MAX31855_RT.svg?maxAge=3600)](https://github.com/RobTillaart/MAX31855_RT/releases) + # MAX31855_RT Arduino library for MAX31855 chip for K type thermocouple diff --git a/library.json b/library.json index d0d7201..5469b67 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/MAX31855_RT" }, - "version":"0.2.3", + "version":"0.2.4", "frameworks": "arduino", "platforms": "*" } diff --git a/library.properties b/library.properties index 465c2a1..6fa679f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=MAX31855_RT -version=0.2.3 +version=0.2.4 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for MAX31855 chip for K type thermocouple. diff --git a/test/unit_test_001.cpp b/test/unit_test_001.cpp new file mode 100644 index 0000000..fe802ff --- /dev/null +++ b/test/unit_test_001.cpp @@ -0,0 +1,111 @@ +// +// FILE: unit_test_001.cpp +// AUTHOR: Rob Tillaart +// DATE: 2020-12-03 +// PURPOSE: unit tests for the MAX31855_RT Thermocouple library +// https://github.com/RobTillaart/MAX31855_RT +// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md +// + +// supported assertions +// ---------------------------- +// assertEqual(expected, actual); // a == b +// assertNotEqual(unwanted, actual); // a != b +// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b)) +// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b)) +// assertLess(upperBound, actual); // a < b +// assertMore(lowerBound, actual); // a > b +// assertLessOrEqual(upperBound, actual); // a <= b +// assertMoreOrEqual(lowerBound, actual); // a >= b +// assertTrue(actual); +// assertFalse(actual); +// assertNull(actual); + +// // special cases for floats +// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon +// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon +// assertInfinity(actual); // isinf(a) +// assertNotInfinity(actual); // !isinf(a) +// assertNAN(arg); // isnan(a) +// assertNotNAN(arg); // !isnan(a) + +#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 "MAX31855.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_all) +{ + fprintf(stderr, "VERSION: %s\n", MAX31855_VERSION); + + const int doPin = 7; + const int csPin = 6; + const int clPin = 5; + + MAX31855 tc(clPin, csPin, doPin); + tc.begin(); + + fprintf(stderr, "Status...\n"); + assertEqual(STATUS_NOREAD, (int)tc.getStatus()); + assertEqual(0, tc.lastRead()); + assertEqual(0, tc.getRawData()); + assertFalse(tc.openCircuit()); + assertFalse(tc.shortToGND()); + assertFalse(tc.shortToVCC()); + assertFalse(tc.genericError()); + assertFalse(tc.noCommunication()); + assertTrue(tc.noRead()); + + fprintf(stderr, "Temperature...\n"); + assertEqualFloat(MAX31855_NO_TEMPERATURE, tc.getInternal(), 0.001); + assertEqualFloat(MAX31855_NO_TEMPERATURE, tc.getTemperature(), 0.001); + + fprintf(stderr, "Offset...\n"); + for (int of = 0; of < 10; of++) + { + tc.setOffset(of * 0.1); + fprintf(stderr, "%f\t", of * 0.1); + assertEqualFloat(of * 0.1, tc.getOffset(), 0.001); + } + + fprintf(stderr, "SeebeckCoefficient...\n"); + for (float sbc = 9; sbc < 100; sbc += 12.345) // non existant still good for test. + { + tc.setSeebeckCoefficient(sbc); + fprintf(stderr, "%f\t", sbc); + assertEqualFloat(sbc, tc.getSeebeckCoefficient(), 0.001); + } + +} + +unittest_main() + +// --------