diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index 429f53ae0..080d8c9f2 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -29,6 +29,7 @@ emoji endif endl EVT +EZO FONTFAMILY FONTSTYLE FONTWEIGHT @@ -46,6 +47,7 @@ ifdef ine ino iostream +isdigit isnan itoa jgfoster diff --git a/examples/TankController/TankController.ino b/examples/TankController/TankController.ino index e2c44a32b..205a7f3fa 100644 --- a/examples/TankController/TankController.ino +++ b/examples/TankController/TankController.ino @@ -8,6 +8,14 @@ TankControllerLib *tank; +void serialEvent() { // if the hardware serial port_0 receives a char + tank->serialEvent(); +} + +void serialEvent1() { // if the hardware serial port_1 receives a char + tank->serialEvent1(); +} + void setup() { tank = TankControllerLib::instance(); tank->setup(); diff --git a/scripts/install_libraries.sh b/scripts/install_libraries.sh index 999655fc3..67cb0237c 100755 --- a/scripts/install_libraries.sh +++ b/scripts/install_libraries.sh @@ -22,54 +22,63 @@ fi # add missing libraries export GITHUB="https://github.com/Arduino-CI" if [ -d "./Adafruit_BusIO" ]; then + echo update Adafruit_BusIO (cd Adafruit_BusIO; git pull) else git clone $SHALLOW_MASTER $GITHUB/Adafruit_BusIO.git fi if [ -d "./Adafruit_MAX31865" ]; then + echo update Adafruit_MAX31865 (cd Adafruit_MAX31865; git pull) else git clone $SHALLOW_MAIN $GITHUB/Adafruit_MAX31865.git fi if [ -d "./Ethernet" ]; then + echo update Ethernet (cd Ethernet; git pull) else git clone $SHALLOW_MASTER $GITHUB/Ethernet.git fi if [ -d "./LiquidCrystal" ]; then + echo update LiquidCrystal (cd LiquidCrystal; git pull) else git clone $SHALLOW_MASTER $GITHUB/LiquidCrystal.git fi if [ -d "./RTClib" ]; then + echo update RTClib (cd RTClib; git pull) else git clone $SHALLOW_MASTER $GITHUB/RTClib.git fi if [ -d "./Keypad" ]; then + echo update Keypad (cd Keypad; git pull) else git clone $SHALLOW_MASTER $GITHUB/Keypad.git fi if [ -d "./Arduino-PID-Library" ]; then + echo update Arduino-PID-Library (cd Arduino-PID-Library; git pull) else git clone $SHALLOW_MASTER $GITHUB/Arduino-PID-Library.git fi if [ -d "./Arduino-PID-AutoTune-Library" ]; then + echo update Arduino-PID-AutoTune-Library (cd Arduino-PID-AutoTune-Library; git pull) else git clone $SHALLOW_MASTER $GITHUB/Arduino-PID-AutoTune-Library.git fi if [ -d "./SD" ]; then + echo update SD (cd SD; git pull) else git clone $SHALLOW_MAIN $GITHUB/SD.git diff --git a/src/Devices/PHProbe.cpp b/src/Devices/PHProbe.cpp new file mode 100644 index 000000000..c1fdc0021 --- /dev/null +++ b/src/Devices/PHProbe.cpp @@ -0,0 +1,43 @@ +#include "Devices/PHProbe.h" + +#include "Devices/Serial_TC.h" + +// class instance variables +/** + * static variable for singleton + */ +PHProbe *PHProbe::_instance = nullptr; + +// class methods +/** + * static member function to return singleton + */ +PHProbe *PHProbe::instance() { + if (!_instance) { + _instance = new PHProbe(); + } + return _instance; +} + +// instance methods +/** + * constructor (private so clients use the singleton) + */ +PHProbe::PHProbe() { + Serial1.print(F("*OK,0\r")); // Turn off the returning of OK after command to EZO pH + Serial1.print(F("C,1\r")); // Reset pH stamp to continuous measurement: once per second +} + +/** + * data arriving from probe + */ +void PHProbe::serialEvent1() { + String string = Serial1.readStringUntil(13); // read the string until we see a + Serial_TC *serial = Serial_TC::instance(); + if (string.length() > 0 && isdigit(string[0])) { // if the first character in the string is a digit + value = string.toFloat(); // convert the string to a floating point number so it can be evaluated by the Arduino + serial->print(F("pH = "), false); + serial->print(value, 3); + serial->println(); + } +} diff --git a/src/Devices/PHProbe.h b/src/Devices/PHProbe.h new file mode 100644 index 000000000..5a54fd03e --- /dev/null +++ b/src/Devices/PHProbe.h @@ -0,0 +1,19 @@ +#pragma once +#include "Arduino.h" + +class PHProbe { +public: + static PHProbe* instance(); + double getPH() { + return value; + } + void serialEvent1(); + +private: + // Class variable + static PHProbe* _instance; + // instance variable + double value = 0; + // Methods + PHProbe(); +}; diff --git a/src/TankControllerLib.cpp b/src/TankControllerLib.cpp index 39219b4ec..6751aef2f 100644 --- a/src/TankControllerLib.cpp +++ b/src/TankControllerLib.cpp @@ -2,6 +2,7 @@ #include "Devices/Keypad_TC.h" #include "Devices/LiquidCrystal_TC.h" +#include "Devices/PHProbe.h" #include "Devices/SD_TC.h" #include "Devices/Serial_TC.h" #include "TC_util.h" @@ -85,6 +86,20 @@ void TankControllerLib::loop() { handleUI(); } +/** + * This public instance function is called when there is data on the serial port(0). + */ +void TankControllerLib::serialEvent() { +} + +/** + * This public instance function is called when there is data on the serial port(1). + * This the Atlas EZO pH circuit probe. + */ +void TankControllerLib::serialEvent1() { + PHProbe::instance()->serialEvent1(); +} + /** * Set the next state */ diff --git a/src/TankControllerLib.h b/src/TankControllerLib.h index 3699c8ccd..acd053f25 100644 --- a/src/TankControllerLib.h +++ b/src/TankControllerLib.h @@ -15,6 +15,8 @@ class TankControllerLib { // instance methods void loop(); + void serialEvent(); + void serialEvent1(); void setNextState(UIState* newState, bool update = false); void setup(); const char* stateName(); diff --git a/test/PHProbeTest.cpp b/test/PHProbeTest.cpp new file mode 100644 index 000000000..d3aff4110 --- /dev/null +++ b/test/PHProbeTest.cpp @@ -0,0 +1,32 @@ +#include +#include + +#include "Devices/PHProbe.h" +#include "TankControllerLib.h" + +unittest(singleton) { + PHProbe *singleton1 = PHProbe::instance(); + PHProbe *singleton2 = PHProbe::instance(); + assertEqual(singleton1, singleton2); +} + +unittest(constructor) { + assertEqual("*OK,0\rC,1\r", GODMODE()->serialPort[1].dataOut); +} + +// tests getPH() as well +unittest(serialEvent1) { + GodmodeState *state = GODMODE(); + state->reset(); + PHProbe *pPHProbe = PHProbe::instance(); + assertEqual(0, pPHProbe->getPH()); + GODMODE()->serialPort[1].dataIn = "7.75\r"; // the queue of data waiting to be read + TankControllerLib *pTC = TankControllerLib::instance(); + state->serialPort[0].dataOut = ""; + assertEqual("", state->serialPort[0].dataOut); + pTC->serialEvent1(); + assertEqual("pH = 7.750\r\n", state->serialPort[0].dataOut); + assertEqual(7.75, PHProbe::instance()->getPH()); +} + +unittest_main()