Skip to content

Commit

Permalink
Arduino ci (#13)
Browse files Browse the repository at this point in the history
* add arduino-ci
* add unit test
  • Loading branch information
RobTillaart authored Dec 30, 2020
1 parent 88f1b40 commit c8045ca
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 40 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/[email protected]
74 changes: 38 additions & 36 deletions MAX31855.cpp
Original file line number Diff line number Diff line change
@@ -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.
//


Expand All @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions MAX31855.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
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/MAX31855_RT"
},
"version":"0.2.3",
"version":"0.2.4",
"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=MAX31855_RT
version=0.2.3
version=0.2.4
author=Rob Tillaart <[email protected]>
maintainer=Rob Tillaart <[email protected]>
sentence=Arduino library for MAX31855 chip for K type thermocouple.
Expand Down
111 changes: 111 additions & 0 deletions test/unit_test_001.cpp
Original file line number Diff line number Diff line change
@@ -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 <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 "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()

// --------

0 comments on commit c8045ca

Please sign in to comment.