From ff595bff2261e67ed59199a0f27838565e7cd694 Mon Sep 17 00:00:00 2001 From: caherbel Date: Mon, 2 Nov 2020 10:02:06 -0700 Subject: [PATCH 01/15] Arduino TempProbe changes WIP --- .arduino-ci.yml | 6 ++ src/Devices/TempProbe_TC.h | 111 +++++++++++++++++++++++++++++++++++++ test/TempProbe_TC_Test.cpp | 53 ++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 src/Devices/TempProbe_TC.h create mode 100644 test/TempProbe_TC_Test.cpp diff --git a/.arduino-ci.yml b/.arduino-ci.yml index 9db6f922..b03b018d 100644 --- a/.arduino-ci.yml +++ b/.arduino-ci.yml @@ -9,6 +9,7 @@ platforms: defines: - __AVR_ATmega2560__ - ARDUINO_CI + - __AVR__ warnings: flags: @@ -17,9 +18,14 @@ unittest: - mega2560 libraries: - "LiquidCrystal" + - "Adafruit BusIO" + - "Adafruit_MAX31865" + compile: platforms: - mega2560 libraries: - "LiquidCrystal" + - "Adafruit BusIO" + - "Adafruit_MAX31865" diff --git a/src/Devices/TempProbe_TC.h b/src/Devices/TempProbe_TC.h new file mode 100644 index 00000000..7a085262 --- /dev/null +++ b/src/Devices/TempProbe_TC.h @@ -0,0 +1,111 @@ +#include "Arduino.h" +#include "ArduinoUnitTests.h" + +#ifdef ARDUINO_CI +#include "Adafruit_MAX31865_CI.h" +#else +#include "Adafruit_MAX31865.h" +#endif + +// Adafruit MAX31865 +// The Adafruit MAX31865 is an external device that connects to a thermocouple (temperature +// sensor), and has pins that can be used to read a resistance, temperature, or fault. The +// associated library has a simple API as described below. +// +// Device I/O: +// This device has 5 pins: Vin (3V or 5V powersupply, the same as the +// microcontroler), GND (Ground), CLK (Clock), SDO (MOSI: Master Out Slave In), +// SDI (MISO: Master In Slave Out), and CS (Slave Select). +// +// Connection with the thermocouple: +// The Adafruit MAX31865 can connect to three different types of thermocouples, +// two wire, three wire, or four wire. You'll need to look at the sensor's +// documentation to find the wiring requirments. The board has four pins used +// for connection with the thermocouple, they are labeled on the board: RTD+ +// (Resistance Positive), RTD- (Resistance Negative), F+ (Fault Plus), and F- +// (Fault Negative). +// +// Using Adafruit MAX31865 +// There are 5 functions needed to use Adafruit MAX31865: the constructor, +// begin(), readRTD() (Read Resistance), temperature(), readFault(), and +// clearFault(). +// +// Here is a description of those functions: +// +// Constructor: +// To use the constructor you will have to set which pins you want to use, the +// functions are labled below. Adafruit_MAX31865 thermo = Adafruit_MAX31865(CS +// (Slave Select), DI (MOSI), DO (MISO), CLK (Clock)); +// +// Begin: +// Call this after calling the constructor and before anything else. Returns +// true if successful. Default is a 2 wire thermocouple but you can specify 2,3, +// and 4 wire by passing in MAX31865_2WIRE, MAX31865_3WIRE, and MAX31865_4WIRE. +// bool successful = thermo.begin(max31865_numwires_t x = MAX31865_2WIRE); +// +// Read Resistance: +// Returns the resitance of the device. +// uint16_t rtd = thermo.readRTD(); +// +// Get Temperature: +// To get the temperature you will need to know the Nominal Resistance, and the +// Resistor Reference of your temperature sensor. This must be set according to +// your thermocouple. Read your thermocouple +// manual to find these values. +// float temp = thermo.temperature(float RTDnominal, float refResistor) +// +// Read Fault: +// Returns a fault number in hex. You can compare with returned fault with the +// defualt fault values given below uint8_t fault = thermo.readFault(); +// +// Faults: +// MAX31865_FAULT_HIGHTHRESH (RTD High Threshold) +// MAX31865_FAULT_LOWTHRESH (RTD Low Threshold) +// MAX31865_FAULT_REFINLOW (REFIN- > 0.85 x Bias) +// MAX31865_FAULT_REFINHIGH (REFIN- < 0.85 x Bias - FORCE- open) +// MAX31865_FAULT_RTDINLOW (RTDIN- < 0.85 x Bias - FORCE- open) +// MAX31865_FAULT_OVUV (Under/Over Voltage) +// +// Clear Fault: +// Once Fault is read clear fault so that it returns to its default state of 0 +// wich is no fault. thermo.clearFault(); +// +// How to use the Device: +// To use the device you must call the constructor, call begin, and then you can +// either call readRTD(), or temperature(). Once you have read either, or both +// you can check for a fault, use the data accordingly, and then clear the fault +// before reading again. +// +// How to use this TempProbe_TC class: +// Call the constructor TempProbe_TC tempProbe = TempProbe_TC(); +// Since this class is build for Tank Controller class, it will automatically +// set the device to a three wire thermocouple, set the pins that the tank +// controller has delegated for it, and it has values for RTDnominal, and the +// refResistore. This class is pretty straightforward and you can the functions +// and how to call them below. + +class TempProbe_TC { +private: + Adafruit_MAX31865 thermo = Adafruit_MAX31865(45, 43, 41, 39); + + // RTDnominal, and refResistor for pt100 + const int RTDnominal = 100; + const int refResistor = 430; + +public: + TempProbe_TC() { + thermo.begin(MAX31865_3WIRE); // Start pt100 temperature probe with 3 wire configuration + } + + uint16_t getResistance() { return thermo.readRTD(); } + float getTemperature() { return thermo.temperature(RTDnominal, refResistor); } + uint8_t readFault() { return thermo.readFault(); } + void clearFault() { thermo.clearFault(); } + +#ifdef ARDUINO_CI + + void setRTD(uint16_t newResistance) { thermo.setRTD(newResistance); } + void setFault(uint8_t newFault) { thermo.setFault(newFault); } + +#endif +}; diff --git a/test/TempProbe_TC_Test.cpp b/test/TempProbe_TC_Test.cpp new file mode 100644 index 00000000..32604810 --- /dev/null +++ b/test/TempProbe_TC_Test.cpp @@ -0,0 +1,53 @@ +// #include "Arduino.h" +// #include "ArduinoUnitTests.h" + +// #ifdef ARDUINO_CI +// #include "Adafruit_MAX31865_CI.h" +// #else +// #include "Adafruit_MAX31865.h" +// #endif + + +// unittest(readRTD_TC_TempProbe) { +// std::cout << std::endl; +// uint16_t expectedRTD = 0; +// TempProbe_TC tempProbe; +// uint16_t testRTD = tempProbe.getResistance(); +// assert(testRTD == expectedRTD); +// std::cout << std::endl; +// } + +// unittest(getTemp_TC_TempProbe) { +// std::cout << std::endl; +// float expectedTemp = -242.02; +// TempProbe_TC tempProbe; +// float testTemp = tempProbe.getTemperature(); +// assert(testTemp == expectedTemp); +// std::cout << std::endl; +// } + +// unittest(readFault_TC_TempProbe) { +// std::cout << std::endl; +// TempProbe_TC tempProbe; +// uint8_t testFault = tempProbe.readFault(); +// assertEqual(0, testFault); +// uint8_t expectedFault = 1; +// tempProbe.setFault(expectedFault); +// testFault = tempProbe.readFault(); +// assert(testFault == expectedFault); +// std::cout << std::endl; +// } + +// unittest(clearFault_TC_TempProbe) { +// std::cout << std::endl; +// uint8_t setFault = 1; +// uint8_t expectedFault = 0; +// TempProbe_TC tempProbe; +// tempProbe.setFault(setFault); +// tempProbe.clearFault(); +// uint8_t testFault = tempProbe.readFault(); +// assert(testFault == expectedFault); +// std::cout << std::endl; +// } + +// unittest_main() \ No newline at end of file From dac1309dffd9f04452d73ba6257b069967a11d60 Mon Sep 17 00:00:00 2001 From: caherbel Date: Mon, 2 Nov 2020 10:10:31 -0700 Subject: [PATCH 02/15] WIP changes --- test/TempProbe_TC_Test.cpp | 92 +++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/test/TempProbe_TC_Test.cpp b/test/TempProbe_TC_Test.cpp index 32604810..b05c7c4f 100644 --- a/test/TempProbe_TC_Test.cpp +++ b/test/TempProbe_TC_Test.cpp @@ -1,53 +1,53 @@ -// #include "Arduino.h" -// #include "ArduinoUnitTests.h" +#include "Arduino.h" +#include "ArduinoUnitTests.h" -// #ifdef ARDUINO_CI -// #include "Adafruit_MAX31865_CI.h" -// #else -// #include "Adafruit_MAX31865.h" -// #endif +#ifdef ARDUINO_CI +#include "Adafruit_MAX31865_CI.h" +#else +#include "Adafruit_MAX31865.h" +#endif -// unittest(readRTD_TC_TempProbe) { -// std::cout << std::endl; -// uint16_t expectedRTD = 0; -// TempProbe_TC tempProbe; -// uint16_t testRTD = tempProbe.getResistance(); -// assert(testRTD == expectedRTD); -// std::cout << std::endl; -// } +unittest(readRTD_TC_TempProbe) { + std::cout << std::endl; + uint16_t expectedRTD = 0; + TempProbe_TC tempProbe; + uint16_t testRTD = tempProbe.getResistance(); + assert(testRTD == expectedRTD); + std::cout << std::endl; +} -// unittest(getTemp_TC_TempProbe) { -// std::cout << std::endl; -// float expectedTemp = -242.02; -// TempProbe_TC tempProbe; -// float testTemp = tempProbe.getTemperature(); -// assert(testTemp == expectedTemp); -// std::cout << std::endl; -// } +unittest(getTemp_TC_TempProbe) { + std::cout << std::endl; + float expectedTemp = -242.02; + TempProbe_TC tempProbe; + float testTemp = tempProbe.getTemperature(); + assert(testTemp == expectedTemp); + std::cout << std::endl; +} -// unittest(readFault_TC_TempProbe) { -// std::cout << std::endl; -// TempProbe_TC tempProbe; -// uint8_t testFault = tempProbe.readFault(); -// assertEqual(0, testFault); -// uint8_t expectedFault = 1; -// tempProbe.setFault(expectedFault); -// testFault = tempProbe.readFault(); -// assert(testFault == expectedFault); -// std::cout << std::endl; -// } +unittest(readFault_TC_TempProbe) { + std::cout << std::endl; + TempProbe_TC tempProbe; + uint8_t testFault = tempProbe.readFault(); + assertEqual(0, testFault); + uint8_t expectedFault = 1; + tempProbe.setFault(expectedFault); + testFault = tempProbe.readFault(); + assert(testFault == expectedFault); + std::cout << std::endl; +} -// unittest(clearFault_TC_TempProbe) { -// std::cout << std::endl; -// uint8_t setFault = 1; -// uint8_t expectedFault = 0; -// TempProbe_TC tempProbe; -// tempProbe.setFault(setFault); -// tempProbe.clearFault(); -// uint8_t testFault = tempProbe.readFault(); -// assert(testFault == expectedFault); -// std::cout << std::endl; -// } +unittest(clearFault_TC_TempProbe) { + std::cout << std::endl; + uint8_t setFault = 1; + uint8_t expectedFault = 0; + TempProbe_TC tempProbe; + tempProbe.setFault(setFault); + tempProbe.clearFault(); + uint8_t testFault = tempProbe.readFault(); + assert(testFault == expectedFault); + std::cout << std::endl; +} -// unittest_main() \ No newline at end of file +unittest_main() \ No newline at end of file From 7bc2e07869e06543d4a9465e2691cdd66c7da246 Mon Sep 17 00:00:00 2001 From: caherbel Date: Wed, 4 Nov 2020 15:13:12 -0700 Subject: [PATCH 03/15] Formatting Changes --- src/Devices/TempProbe_TC.h | 28 ++++++++++++++++++++-------- test/TempProbe_TC_Test.cpp | 1 - 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Devices/TempProbe_TC.h b/src/Devices/TempProbe_TC.h index 7a085262..887584ae 100644 --- a/src/Devices/TempProbe_TC.h +++ b/src/Devices/TempProbe_TC.h @@ -9,7 +9,7 @@ // Adafruit MAX31865 // The Adafruit MAX31865 is an external device that connects to a thermocouple (temperature -// sensor), and has pins that can be used to read a resistance, temperature, or fault. The +// sensor), and has pins that can be used to read a resistance, temperature, or fault. The // associated library has a simple API as described below. // // Device I/O: @@ -94,18 +94,30 @@ class TempProbe_TC { public: TempProbe_TC() { - thermo.begin(MAX31865_3WIRE); // Start pt100 temperature probe with 3 wire configuration + thermo.begin(MAX31865_3WIRE); // Start pt100 temperature probe with 3 wire configuration } - uint16_t getResistance() { return thermo.readRTD(); } - float getTemperature() { return thermo.temperature(RTDnominal, refResistor); } - uint8_t readFault() { return thermo.readFault(); } - void clearFault() { thermo.clearFault(); } + uint16_t getResistance() { + return thermo.readRTD(); + } + float getTemperature() { + return thermo.temperature(RTDnominal, refResistor); + } + uint8_t readFault() { + return thermo.readFault(); + } + void clearFault() { + thermo.clearFault(); + } #ifdef ARDUINO_CI - void setRTD(uint16_t newResistance) { thermo.setRTD(newResistance); } - void setFault(uint8_t newFault) { thermo.setFault(newFault); } + void setRTD(uint16_t newResistance) { + thermo.setRTD(newResistance); + } + void setFault(uint8_t newFault) { + thermo.setFault(newFault); + } #endif }; diff --git a/test/TempProbe_TC_Test.cpp b/test/TempProbe_TC_Test.cpp index b05c7c4f..0ff4fba7 100644 --- a/test/TempProbe_TC_Test.cpp +++ b/test/TempProbe_TC_Test.cpp @@ -7,7 +7,6 @@ #include "Adafruit_MAX31865.h" #endif - unittest(readRTD_TC_TempProbe) { std::cout << std::endl; uint16_t expectedRTD = 0; From a1692f0def07e5e1ac999b5951ede2c21474ad16 Mon Sep 17 00:00:00 2001 From: caherbel Date: Wed, 4 Nov 2020 15:23:34 -0700 Subject: [PATCH 04/15] Formatting Changes --- test/TempProbe_TC_Test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/TempProbe_TC_Test.cpp b/test/TempProbe_TC_Test.cpp index 0ff4fba7..34d58e34 100644 --- a/test/TempProbe_TC_Test.cpp +++ b/test/TempProbe_TC_Test.cpp @@ -49,4 +49,4 @@ unittest(clearFault_TC_TempProbe) { std::cout << std::endl; } -unittest_main() \ No newline at end of file +unittest_main() From b61619608d1fffbf615e8cf92d4072842ea63ef2 Mon Sep 17 00:00:00 2001 From: caherbel Date: Fri, 13 Nov 2020 16:50:01 -0700 Subject: [PATCH 05/15] TempProbe Wrapper is working --- .arduino-ci.yml | 4 ++-- Gemfile | 2 +- test/TempProbe_TC_Test.cpp | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.arduino-ci.yml b/.arduino-ci.yml index ed76f77d..bcbfe889 100644 --- a/.arduino-ci.yml +++ b/.arduino-ci.yml @@ -19,7 +19,7 @@ unittest: libraries: - "LiquidCrystal" - "RTClib" - - "Adafruit BusIO" + - "Adafruit_BusIO" - "Adafruit_MAX31865" compile: @@ -28,6 +28,6 @@ compile: libraries: - "LiquidCrystal" - "RTClib" - - "Adafruit BusIO" + - "Adafruit_BusIO" - "Adafruit_MAX31865" diff --git a/Gemfile b/Gemfile index 10f86cea..7cd9ec68 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,2 @@ source 'https://rubygems.org' -gem 'arduino_ci', git: 'https://github.com/jgfoster/arduino_ci.git', branch: 'cptr450', :ref => "4632f74b2bc9d18e843a3c6638e3217ea1550fdb" +gem 'arduino_ci', git: 'https://github.com/arduino-ci/arduino_ci.git', branch: 'master' diff --git a/test/TempProbe_TC_Test.cpp b/test/TempProbe_TC_Test.cpp index 34d58e34..c924bb7d 100644 --- a/test/TempProbe_TC_Test.cpp +++ b/test/TempProbe_TC_Test.cpp @@ -1,5 +1,6 @@ #include "Arduino.h" #include "ArduinoUnitTests.h" +#include "TempProbe_TC.h" #ifdef ARDUINO_CI #include "Adafruit_MAX31865_CI.h" From e2bfef48839bcd8bd814f6983d46bcb868f54d1a Mon Sep 17 00:00:00 2001 From: caherbel Date: Fri, 13 Nov 2020 16:52:31 -0700 Subject: [PATCH 06/15] Formatting Changes --- test/TempProbe_TC_Test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/TempProbe_TC_Test.cpp b/test/TempProbe_TC_Test.cpp index c924bb7d..64582370 100644 --- a/test/TempProbe_TC_Test.cpp +++ b/test/TempProbe_TC_Test.cpp @@ -1,6 +1,7 @@ +#include "TempProbe_TC.h" + #include "Arduino.h" #include "ArduinoUnitTests.h" -#include "TempProbe_TC.h" #ifdef ARDUINO_CI #include "Adafruit_MAX31865_CI.h" From 0d03973bb4d5ff5771d47f90f9d2b2450a37f25a Mon Sep 17 00:00:00 2001 From: James Foster Date: Sun, 22 Nov 2020 10:46:38 -0800 Subject: [PATCH 07/15] Save WIP. --- Gemfile | 2 +- scripts/install_libraries.sh | 21 +++++++++++++-------- scripts/test.sh | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index 7cd9ec68..fb422d12 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,2 @@ source 'https://rubygems.org' -gem 'arduino_ci', git: 'https://github.com/arduino-ci/arduino_ci.git', branch: 'master' +gem 'arduino_ci' diff --git a/scripts/install_libraries.sh b/scripts/install_libraries.sh index f8ccb941..31fb7861 100755 --- a/scripts/install_libraries.sh +++ b/scripts/install_libraries.sh @@ -2,19 +2,24 @@ # set up directories bundle exec ensure_arduino_installation.rb +cd $(bundle exec arduino_library_location.rb) # get custom version of LiquidCrystal -git clone https://github.com/Arduino-CI/LiquidCrystal.git -mv LiquidCrystal $(bundle exec arduino_library_location.rb) +if [ ! -d LiquidCrystal ]; then + git clone https://github.com/Arduino-CI/LiquidCrystal.git +fi # get custom version of RTClib -git clone https://github.com/Arduino-CI/RTClib.git -mv RTClib $(bundle exec arduino_library_location.rb) +if [ ! -d RTClib ]; then + git clone https://github.com/Arduino-CI/RTClib.git +fi # get custom version of Adafruit_BusIO -git clone https://github.com/Arduino-CI/Adafruit_BusIO.git -mv Adafruit_BusIO $(bundle exec arduino_library_location.rb) +if [ ! -d Adafruit_BusIO ]; then + git clone https://github.com/Arduino-CI/Adafruit_BusIO.git +fi # get custom version of Adafruit_MAX31865 -git clone https://github.com/Arduino-CI/Adafruit_MAX31865.git -mv Adafruit_MAX31865 $(bundle exec arduino_library_location.rb) +if [ ! -d Adafruit_MAX31865 ]; then + git clone https://github.com/Arduino-CI/Adafruit_MAX31865.git +fi diff --git a/scripts/test.sh b/scripts/test.sh index ef17bd83..20de4941 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,4 +1,4 @@ #! /bin/sh bundle config --local path vendor/bundle bundle install -bundle exec arduino_ci_remote.rb --skip-examples-compilation +bundle exec arduino_ci_remote.rb --skip-examples-compilation From 0427549cf5e0368741cb9d9aff8a49e414d0d70a Mon Sep 17 00:00:00 2001 From: James Foster Date: Sun, 22 Nov 2020 12:29:15 -0800 Subject: [PATCH 08/15] Use `MOCK_PINS_COUNT` instead of `ARDUINO_CI` to recognize testing. --- scripts/install_libraries.sh | 4 ++++ src/Devices/TempProbe_TC.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/install_libraries.sh b/scripts/install_libraries.sh index 9315c6d3..661f4e54 100755 --- a/scripts/install_libraries.sh +++ b/scripts/install_libraries.sh @@ -8,6 +8,10 @@ export SHALLOW='--depth 1 --branch master --single-branch ' # use this if you started with SHALLOW and now want the full repository with history # git fetch --unshallow +# ensure we have `arduino_ci` +bundle config --local path vendor/bundle +bundle install + # set up directories bundle exec ensure_arduino_installation.rb cd $(bundle exec arduino_library_location.rb) diff --git a/src/Devices/TempProbe_TC.h b/src/Devices/TempProbe_TC.h index 887584ae..3b847819 100644 --- a/src/Devices/TempProbe_TC.h +++ b/src/Devices/TempProbe_TC.h @@ -110,7 +110,7 @@ class TempProbe_TC { thermo.clearFault(); } -#ifdef ARDUINO_CI +#ifdef MOCK_PINS_COUNT void setRTD(uint16_t newResistance) { thermo.setRTD(newResistance); From a442f4b65da22f47049865ad5b89c07b14f89b7a Mon Sep 17 00:00:00 2001 From: caherbel Date: Mon, 23 Nov 2020 15:53:34 -0700 Subject: [PATCH 09/15] Comninued Work --- .arduino-ci.yml | 6 ++---- src/Devices/TempProbe_TC.h | 10 +++++++--- test/TempProbe_TC_Test.cpp | 6 +++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.arduino-ci.yml b/.arduino-ci.yml index c1d14937..3e4fecbd 100644 --- a/.arduino-ci.yml +++ b/.arduino-ci.yml @@ -4,19 +4,17 @@ unittest: - mega2560 libraries: - "Adafruit BusIO" - - "Adafruit_MAX31865" + - "Adafruit MAX31865" - "Ethernet" - "LiquidCrystal" - "RTClib" - - "Adafruit_BusIO" - - "Adafruit_MAX31865" compile: platforms: - mega2560 libraries: - "Adafruit BusIO" - - "Adafruit_MAX31865" + - "Adafruit MAX31865" - "Ethernet" - "LiquidCrystal" - "RTClib" diff --git a/src/Devices/TempProbe_TC.h b/src/Devices/TempProbe_TC.h index 3b847819..097b7a12 100644 --- a/src/Devices/TempProbe_TC.h +++ b/src/Devices/TempProbe_TC.h @@ -1,7 +1,7 @@ #include "Arduino.h" #include "ArduinoUnitTests.h" -#ifdef ARDUINO_CI +#ifdef MOCK_PINS_COUNT #include "Adafruit_MAX31865_CI.h" #else #include "Adafruit_MAX31865.h" @@ -110,14 +110,18 @@ class TempProbe_TC { thermo.clearFault(); } -#ifdef MOCK_PINS_COUNT + void setRTD(uint16_t newResistance) { + #ifdef MOCK_PINS_COUNT thermo.setRTD(newResistance); + #endif } void setFault(uint8_t newFault) { + #ifdef MOCK_PINS_COUNT thermo.setFault(newFault); + #endif } -#endif + }; diff --git a/test/TempProbe_TC_Test.cpp b/test/TempProbe_TC_Test.cpp index 64582370..0f602d05 100644 --- a/test/TempProbe_TC_Test.cpp +++ b/test/TempProbe_TC_Test.cpp @@ -3,7 +3,7 @@ #include "Arduino.h" #include "ArduinoUnitTests.h" -#ifdef ARDUINO_CI +#ifdef MOCK_PINS_COUNT #include "Adafruit_MAX31865_CI.h" #else #include "Adafruit_MAX31865.h" @@ -33,7 +33,9 @@ unittest(readFault_TC_TempProbe) { uint8_t testFault = tempProbe.readFault(); assertEqual(0, testFault); uint8_t expectedFault = 1; + #ifdef MOCK_PINS_COUNT tempProbe.setFault(expectedFault); + #endif testFault = tempProbe.readFault(); assert(testFault == expectedFault); std::cout << std::endl; @@ -44,7 +46,9 @@ unittest(clearFault_TC_TempProbe) { uint8_t setFault = 1; uint8_t expectedFault = 0; TempProbe_TC tempProbe; + #ifdef MOCK_PINS_COUNT tempProbe.setFault(setFault); + #endif tempProbe.clearFault(); uint8_t testFault = tempProbe.readFault(); assert(testFault == expectedFault); From aac5d5f484cc7b698528c6dacccb0f7e78504208 Mon Sep 17 00:00:00 2001 From: caherbel Date: Tue, 24 Nov 2020 15:53:13 -0700 Subject: [PATCH 10/15] Temp Probe Working on my end --- .arduino-ci.yml | 4 +- src/Devices/TempProbe_TC.cpp | 26 +++++++++++++ src/Devices/TempProbe_TC.h | 71 ++++++++++++++---------------------- test/TempProbe_TC_Test.cpp | 66 +++++++++------------------------ 4 files changed, 73 insertions(+), 94 deletions(-) create mode 100644 src/Devices/TempProbe_TC.cpp diff --git a/.arduino-ci.yml b/.arduino-ci.yml index 3e4fecbd..319d7302 100644 --- a/.arduino-ci.yml +++ b/.arduino-ci.yml @@ -4,7 +4,7 @@ unittest: - mega2560 libraries: - "Adafruit BusIO" - - "Adafruit MAX31865" + - "Adafruit_MAX31865" - "Ethernet" - "LiquidCrystal" - "RTClib" @@ -14,7 +14,7 @@ compile: - mega2560 libraries: - "Adafruit BusIO" - - "Adafruit MAX31865" + - "Adafruit_MAX31865" - "Ethernet" - "LiquidCrystal" - "RTClib" diff --git a/src/Devices/TempProbe_TC.cpp b/src/Devices/TempProbe_TC.cpp new file mode 100644 index 00000000..b3faf330 --- /dev/null +++ b/src/Devices/TempProbe_TC.cpp @@ -0,0 +1,26 @@ +#include "Devices/TempProbe_TC.h" + +// class instance variables +/** + * static variable for singleton + */ +TempProbe_TC* TempProbe_TC::_instance = nullptr; + +// class methods +/** + * static member function to return singleton + */ +TempProbe_TC* TempProbe_TC::instance() { + if (!_instance) { + _instance = new TempProbe_TC(); + } + return _instance; +} + +// instance methods +/** + * constructor (private so clients use the singleton) + */ +TempProbe_TC::TempProbe_TC() { + thermo.begin(MAX31865_3WIRE); // Start pt100 temperature probe with 3 wire configuration +} diff --git a/src/Devices/TempProbe_TC.h b/src/Devices/TempProbe_TC.h index 097b7a12..4637694b 100644 --- a/src/Devices/TempProbe_TC.h +++ b/src/Devices/TempProbe_TC.h @@ -1,12 +1,3 @@ -#include "Arduino.h" -#include "ArduinoUnitTests.h" - -#ifdef MOCK_PINS_COUNT -#include "Adafruit_MAX31865_CI.h" -#else -#include "Adafruit_MAX31865.h" -#endif - // Adafruit MAX31865 // The Adafruit MAX31865 is an external device that connects to a thermocouple (temperature // sensor), and has pins that can be used to read a resistance, temperature, or fault. The @@ -84,44 +75,36 @@ // refResistore. This class is pretty straightforward and you can the functions // and how to call them below. -class TempProbe_TC { -private: - Adafruit_MAX31865 thermo = Adafruit_MAX31865(45, 43, 41, 39); - - // RTDnominal, and refResistor for pt100 - const int RTDnominal = 100; - const int refResistor = 430; - -public: - TempProbe_TC() { - thermo.begin(MAX31865_3WIRE); // Start pt100 temperature probe with 3 wire configuration - } +#pragma once +#include "Arduino.h" - uint16_t getResistance() { - return thermo.readRTD(); - } - float getTemperature() { - return thermo.temperature(RTDnominal, refResistor); - } - uint8_t readFault() { - return thermo.readFault(); - } - void clearFault() { - thermo.clearFault(); - } +#ifdef MOCK_PINS_COUNT +#include +#else +#include +#endif +class TempProbe_TC { +public: + static TempProbe_TC* instance(); - void setRTD(uint16_t newResistance) { - #ifdef MOCK_PINS_COUNT - thermo.setRTD(newResistance); - #endif - } - void setFault(uint8_t newFault) { - #ifdef MOCK_PINS_COUNT - thermo.setFault(newFault); - #endif - } + uint16_t getResistance() { return thermo.readRTD(); } + float getTemperature() { return thermo.temperature(RTDnominal, refResistor); } + uint8_t readFault() { return thermo.readFault(); } + void clearFault() { thermo.clearFault(); } +private: + // class variable + static TempProbe_TC* _instance; + const int RTDnominal = 100; + const int refResistor = 430; + Adafruit_MAX31865 thermo = Adafruit_MAX31865(45, 43, 41, 39); -}; + //Methods + TempProbe_TC(); + + + + +}; \ No newline at end of file diff --git a/test/TempProbe_TC_Test.cpp b/test/TempProbe_TC_Test.cpp index 0f602d05..c4cecf95 100644 --- a/test/TempProbe_TC_Test.cpp +++ b/test/TempProbe_TC_Test.cpp @@ -1,58 +1,28 @@ -#include "TempProbe_TC.h" - #include "Arduino.h" #include "ArduinoUnitTests.h" +#include -#ifdef MOCK_PINS_COUNT -#include "Adafruit_MAX31865_CI.h" -#else -#include "Adafruit_MAX31865.h" -#endif -unittest(readRTD_TC_TempProbe) { - std::cout << std::endl; - uint16_t expectedRTD = 0; - TempProbe_TC tempProbe; - uint16_t testRTD = tempProbe.getResistance(); - assert(testRTD == expectedRTD); - std::cout << std::endl; -} +unittest(TempProbe_Test) { + //Instace + TempProbe_TC* tempProbe = TempProbe_TC::instance(); -unittest(getTemp_TC_TempProbe) { - std::cout << std::endl; - float expectedTemp = -242.02; - TempProbe_TC tempProbe; - float testTemp = tempProbe.getTemperature(); - assert(testTemp == expectedTemp); - std::cout << std::endl; -} + //Test getResistance() + uint16_t testRTD = tempProbe->getResistance(); + assertEqual(32767, testRTD); -unittest(readFault_TC_TempProbe) { - std::cout << std::endl; - TempProbe_TC tempProbe; - uint8_t testFault = tempProbe.readFault(); - assertEqual(0, testFault); - uint8_t expectedFault = 1; - #ifdef MOCK_PINS_COUNT - tempProbe.setFault(expectedFault); - #endif - testFault = tempProbe.readFault(); - assert(testFault == expectedFault); - std::cout << std::endl; -} + //Test getTemperature() + float testTemp = tempProbe->getTemperature(); + assertEqual (988, (int) testTemp); + + //Test readFault() + uint8_t testFault = tempProbe->readFault(); + assertEqual(255, testFault); -unittest(clearFault_TC_TempProbe) { - std::cout << std::endl; - uint8_t setFault = 1; - uint8_t expectedFault = 0; - TempProbe_TC tempProbe; - #ifdef MOCK_PINS_COUNT - tempProbe.setFault(setFault); - #endif - tempProbe.clearFault(); - uint8_t testFault = tempProbe.readFault(); - assert(testFault == expectedFault); - std::cout << std::endl; + //Test clearFault() + tempProbe->clearFault(); + testFault = tempProbe->readFault(); + assertEqual(255, testFault); } unittest_main() From 18399caeab03eabb1cd203f41df84eab68ffc940 Mon Sep 17 00:00:00 2001 From: caherbel Date: Tue, 24 Nov 2020 15:57:56 -0700 Subject: [PATCH 11/15] Formatting --- src/Devices/TempProbe_TC.h | 27 +++++++++++++++------------ test/TempProbe_TC_Test.cpp | 16 ++++++++-------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/Devices/TempProbe_TC.h b/src/Devices/TempProbe_TC.h index 4637694b..0d153f29 100644 --- a/src/Devices/TempProbe_TC.h +++ b/src/Devices/TempProbe_TC.h @@ -85,26 +85,29 @@ #endif class TempProbe_TC { - public: static TempProbe_TC* instance(); - uint16_t getResistance() { return thermo.readRTD(); } - float getTemperature() { return thermo.temperature(RTDnominal, refResistor); } - uint8_t readFault() { return thermo.readFault(); } - void clearFault() { thermo.clearFault(); } + uint16_t getResistance() { + return thermo.readRTD(); + } + float getTemperature() { + return thermo.temperature(RTDnominal, refResistor); + } + uint8_t readFault() { + return thermo.readFault(); + } + void clearFault() { + thermo.clearFault(); + } private: - // class variable + // Class variables static TempProbe_TC* _instance; const int RTDnominal = 100; const int refResistor = 430; Adafruit_MAX31865 thermo = Adafruit_MAX31865(45, 43, 41, 39); - //Methods + // Methods TempProbe_TC(); - - - - -}; \ No newline at end of file +}; diff --git a/test/TempProbe_TC_Test.cpp b/test/TempProbe_TC_Test.cpp index c4cecf95..f0c328e1 100644 --- a/test/TempProbe_TC_Test.cpp +++ b/test/TempProbe_TC_Test.cpp @@ -1,25 +1,25 @@ -#include "Arduino.h" -#include "ArduinoUnitTests.h" #include +#include "Arduino.h" +#include "ArduinoUnitTests.h" unittest(TempProbe_Test) { - //Instace + // Instance TempProbe_TC* tempProbe = TempProbe_TC::instance(); - //Test getResistance() + // Test getResistance() uint16_t testRTD = tempProbe->getResistance(); assertEqual(32767, testRTD); - //Test getTemperature() + // Test getTemperature() float testTemp = tempProbe->getTemperature(); - assertEqual (988, (int) testTemp); + assertEqual (988, (int)testTemp); - //Test readFault() + // Test readFault() uint8_t testFault = tempProbe->readFault(); assertEqual(255, testFault); - //Test clearFault() + // Test clearFault() tempProbe->clearFault(); testFault = tempProbe->readFault(); assertEqual(255, testFault); From fe8fb04d689d5a6048dda4b88b72ed1e2b5df4fa Mon Sep 17 00:00:00 2001 From: caherbel Date: Tue, 24 Nov 2020 16:01:34 -0700 Subject: [PATCH 12/15] More Formatting --- src/Devices/TempProbe_TC.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Devices/TempProbe_TC.h b/src/Devices/TempProbe_TC.h index 0d153f29..0faa9ba8 100644 --- a/src/Devices/TempProbe_TC.h +++ b/src/Devices/TempProbe_TC.h @@ -91,12 +91,15 @@ class TempProbe_TC { uint16_t getResistance() { return thermo.readRTD(); } + float getTemperature() { return thermo.temperature(RTDnominal, refResistor); } + uint8_t readFault() { return thermo.readFault(); } + void clearFault() { thermo.clearFault(); } From bf6799deb7e710d697fa7a09b6177cb1205b74ca Mon Sep 17 00:00:00 2001 From: caherbel Date: Tue, 24 Nov 2020 16:03:27 -0700 Subject: [PATCH 13/15] Minor Change --- src/Devices/TempProbe_TC.h | 18 +++++++++--------- test/TempProbe_TC_Test.cpp | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Devices/TempProbe_TC.h b/src/Devices/TempProbe_TC.h index 0faa9ba8..cfc00a38 100644 --- a/src/Devices/TempProbe_TC.h +++ b/src/Devices/TempProbe_TC.h @@ -88,20 +88,20 @@ class TempProbe_TC { public: static TempProbe_TC* instance(); - uint16_t getResistance() { - return thermo.readRTD(); + uint16_t getResistance() { + return thermo.readRTD(); } - float getTemperature() { - return thermo.temperature(RTDnominal, refResistor); + float getTemperature() { + return thermo.temperature(RTDnominal, refResistor); } - uint8_t readFault() { - return thermo.readFault(); + uint8_t readFault() { + return thermo.readFault(); } - - void clearFault() { - thermo.clearFault(); + + void clearFault() { + thermo.clearFault(); } private: diff --git a/test/TempProbe_TC_Test.cpp b/test/TempProbe_TC_Test.cpp index f0c328e1..c7c58dfc 100644 --- a/test/TempProbe_TC_Test.cpp +++ b/test/TempProbe_TC_Test.cpp @@ -13,7 +13,7 @@ unittest(TempProbe_Test) { // Test getTemperature() float testTemp = tempProbe->getTemperature(); - assertEqual (988, (int)testTemp); + assertEqual(988, (int)testTemp); // Test readFault() uint8_t testFault = tempProbe->readFault(); From d2508b9bae2406e257c01fc35bb258051a6c6f71 Mon Sep 17 00:00:00 2001 From: caherbel Date: Tue, 24 Nov 2020 16:10:01 -0700 Subject: [PATCH 14/15] Value Changes --- test/TempProbe_TC_Test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/TempProbe_TC_Test.cpp b/test/TempProbe_TC_Test.cpp index c7c58dfc..43a72dd2 100644 --- a/test/TempProbe_TC_Test.cpp +++ b/test/TempProbe_TC_Test.cpp @@ -9,20 +9,20 @@ unittest(TempProbe_Test) { // Test getResistance() uint16_t testRTD = tempProbe->getResistance(); - assertEqual(32767, testRTD); + assertEqual(0, testRTD); // Test getTemperature() float testTemp = tempProbe->getTemperature(); - assertEqual(988, (int)testTemp); + assertEqual(-242, (int)testTemp); // Test readFault() uint8_t testFault = tempProbe->readFault(); - assertEqual(255, testFault); + assertEqual(0, testFault); // Test clearFault() tempProbe->clearFault(); testFault = tempProbe->readFault(); - assertEqual(255, testFault); + assertEqual(0, testFault); } unittest_main() From e8721402cc2d1e15bb930168b3cbe6808e7ad16f Mon Sep 17 00:00:00 2001 From: James Foster Date: Fri, 27 Nov 2020 10:36:22 -0800 Subject: [PATCH 15/15] Update TempProbe_TC.h Change to multi-line comment. --- src/Devices/TempProbe_TC.h | 154 +++++++++++++++++++------------------ 1 file changed, 78 insertions(+), 76 deletions(-) diff --git a/src/Devices/TempProbe_TC.h b/src/Devices/TempProbe_TC.h index cfc00a38..b38028e0 100644 --- a/src/Devices/TempProbe_TC.h +++ b/src/Devices/TempProbe_TC.h @@ -1,79 +1,81 @@ -// Adafruit MAX31865 -// The Adafruit MAX31865 is an external device that connects to a thermocouple (temperature -// sensor), and has pins that can be used to read a resistance, temperature, or fault. The -// associated library has a simple API as described below. -// -// Device I/O: -// This device has 5 pins: Vin (3V or 5V powersupply, the same as the -// microcontroler), GND (Ground), CLK (Clock), SDO (MOSI: Master Out Slave In), -// SDI (MISO: Master In Slave Out), and CS (Slave Select). -// -// Connection with the thermocouple: -// The Adafruit MAX31865 can connect to three different types of thermocouples, -// two wire, three wire, or four wire. You'll need to look at the sensor's -// documentation to find the wiring requirments. The board has four pins used -// for connection with the thermocouple, they are labeled on the board: RTD+ -// (Resistance Positive), RTD- (Resistance Negative), F+ (Fault Plus), and F- -// (Fault Negative). -// -// Using Adafruit MAX31865 -// There are 5 functions needed to use Adafruit MAX31865: the constructor, -// begin(), readRTD() (Read Resistance), temperature(), readFault(), and -// clearFault(). -// -// Here is a description of those functions: -// -// Constructor: -// To use the constructor you will have to set which pins you want to use, the -// functions are labled below. Adafruit_MAX31865 thermo = Adafruit_MAX31865(CS -// (Slave Select), DI (MOSI), DO (MISO), CLK (Clock)); -// -// Begin: -// Call this after calling the constructor and before anything else. Returns -// true if successful. Default is a 2 wire thermocouple but you can specify 2,3, -// and 4 wire by passing in MAX31865_2WIRE, MAX31865_3WIRE, and MAX31865_4WIRE. -// bool successful = thermo.begin(max31865_numwires_t x = MAX31865_2WIRE); -// -// Read Resistance: -// Returns the resitance of the device. -// uint16_t rtd = thermo.readRTD(); -// -// Get Temperature: -// To get the temperature you will need to know the Nominal Resistance, and the -// Resistor Reference of your temperature sensor. This must be set according to -// your thermocouple. Read your thermocouple -// manual to find these values. -// float temp = thermo.temperature(float RTDnominal, float refResistor) -// -// Read Fault: -// Returns a fault number in hex. You can compare with returned fault with the -// defualt fault values given below uint8_t fault = thermo.readFault(); -// -// Faults: -// MAX31865_FAULT_HIGHTHRESH (RTD High Threshold) -// MAX31865_FAULT_LOWTHRESH (RTD Low Threshold) -// MAX31865_FAULT_REFINLOW (REFIN- > 0.85 x Bias) -// MAX31865_FAULT_REFINHIGH (REFIN- < 0.85 x Bias - FORCE- open) -// MAX31865_FAULT_RTDINLOW (RTDIN- < 0.85 x Bias - FORCE- open) -// MAX31865_FAULT_OVUV (Under/Over Voltage) -// -// Clear Fault: -// Once Fault is read clear fault so that it returns to its default state of 0 -// wich is no fault. thermo.clearFault(); -// -// How to use the Device: -// To use the device you must call the constructor, call begin, and then you can -// either call readRTD(), or temperature(). Once you have read either, or both -// you can check for a fault, use the data accordingly, and then clear the fault -// before reading again. -// -// How to use this TempProbe_TC class: -// Call the constructor TempProbe_TC tempProbe = TempProbe_TC(); -// Since this class is build for Tank Controller class, it will automatically -// set the device to a three wire thermocouple, set the pins that the tank -// controller has delegated for it, and it has values for RTDnominal, and the -// refResistore. This class is pretty straightforward and you can the functions -// and how to call them below. +/** + * Adafruit MAX31865 + * The Adafruit MAX31865 is an external device that connects to a thermocouple (temperature + * sensor), and has pins that can be used to read a resistance, temperature, or fault. The + * associated library has a simple API as described below. + * + * Device I/O: + * This device has 5 pins: Vin (3V or 5V powersupply, the same as the + * microcontroler), GND (Ground), CLK (Clock), SDO (MOSI: Master Out Slave In), + * SDI (MISO: Master In Slave Out), and CS (Slave Select). + * + * Connection with the thermocouple: + * The Adafruit MAX31865 can connect to three different types of thermocouples, + * two wire, three wire, or four wire. You'll need to look at the sensor's + * documentation to find the wiring requirments. The board has four pins used + * for connection with the thermocouple, they are labeled on the board: RTD+ + * (Resistance Positive), RTD- (Resistance Negative), F+ (Fault Plus), and F- + * (Fault Negative). + * + * Using Adafruit MAX31865 + * There are 5 functions needed to use Adafruit MAX31865: the constructor, + * begin(), readRTD() (Read Resistance), temperature(), readFault(), and + * clearFault(). + * + * Here is a description of those functions: + * + * Constructor: + * To use the constructor you will have to set which pins you want to use, the + * functions are labled below. Adafruit_MAX31865 thermo = Adafruit_MAX31865(CS + * (Slave Select), DI (MOSI), DO (MISO), CLK (Clock)); + * + * Begin: + * Call this after calling the constructor and before anything else. Returns + * true if successful. Default is a 2 wire thermocouple but you can specify 2,3, + * and 4 wire by passing in MAX31865_2WIRE, MAX31865_3WIRE, and MAX31865_4WIRE. + * bool successful = thermo.begin(max31865_numwires_t x = MAX31865_2WIRE); + * + * Read Resistance: + * Returns the resitance of the device. + * uint16_t rtd = thermo.readRTD(); + * + * Get Temperature: + * To get the temperature you will need to know the Nominal Resistance, and the + * Resistor Reference of your temperature sensor. This must be set according to + * your thermocouple. Read your thermocouple + * manual to find these values. + * float temp = thermo.temperature(float RTDnominal, float refResistor) + * + * Read Fault: + * Returns a fault number in hex. You can compare with returned fault with the + * defualt fault values given below uint8_t fault = thermo.readFault(); + * + * Faults: + * MAX31865_FAULT_HIGHTHRESH (RTD High Threshold) + * MAX31865_FAULT_LOWTHRESH (RTD Low Threshold) + * MAX31865_FAULT_REFINLOW (REFIN- > 0.85 x Bias) + * MAX31865_FAULT_REFINHIGH (REFIN- < 0.85 x Bias - FORCE- open) + * MAX31865_FAULT_RTDINLOW (RTDIN- < 0.85 x Bias - FORCE- open) + * MAX31865_FAULT_OVUV (Under/Over Voltage) + * + * Clear Fault: + * Once Fault is read clear fault so that it returns to its default state of 0 + * wich is no fault. thermo.clearFault(); + * + * How to use the Device: + * To use the device you must call the constructor, call begin, and then you can + * either call readRTD(), or temperature(). Once you have read either, or both + * you can check for a fault, use the data accordingly, and then clear the fault + * before reading again. + * + * How to use this TempProbe_TC class: + * Call the constructor TempProbe_TC tempProbe = TempProbe_TC(); + * Since this class is build for Tank Controller class, it will automatically + * set the device to a three wire thermocouple, set the pins that the tank + * controller has delegated for it, and it has values for RTDnominal, and the + * refResistore. This class is pretty straightforward and you can the functions + * and how to call them below. + */ #pragma once #include "Arduino.h"