Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ emoji
endif
endl
EVT
EZO
FONTFAMILY
FONTSTYLE
FONTWEIGHT
Expand All @@ -46,6 +47,7 @@ ifdef
ine
ino
iostream
isdigit
isnan
itoa
jgfoster
Expand Down
8 changes: 8 additions & 0 deletions examples/TankController/TankController.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions scripts/install_libraries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions src/Devices/PHProbe.cpp
Original file line number Diff line number Diff line change
@@ -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 <CR>
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();
}
}
19 changes: 19 additions & 0 deletions src/Devices/PHProbe.h
Original file line number Diff line number Diff line change
@@ -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();
};
15 changes: 15 additions & 0 deletions src/TankControllerLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
*/
Expand Down
2 changes: 2 additions & 0 deletions src/TankControllerLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
32 changes: 32 additions & 0 deletions test/PHProbeTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <Arduino.h>
#include <ArduinoUnitTests.h>

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