Skip to content

Commit 11a4fa1

Browse files
eucalvocalvel
andauthored
PHProbe part1 (#67)
* Initial implementation of PHProbe * changed serialEvent1 to happen in PHProbe Co-authored-by: calvel <[email protected]>
1 parent 960e56e commit 11a4fa1

File tree

8 files changed

+130
-0
lines changed

8 files changed

+130
-0
lines changed

.github/actions/spelling/expect.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ emoji
2929
endif
3030
endl
3131
EVT
32+
EZO
3233
FONTFAMILY
3334
FONTSTYLE
3435
FONTWEIGHT
@@ -46,6 +47,7 @@ ifdef
4647
ine
4748
ino
4849
iostream
50+
isdigit
4951
isnan
5052
itoa
5153
jgfoster

examples/TankController/TankController.ino

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88

99
TankControllerLib *tank;
1010

11+
void serialEvent() { // if the hardware serial port_0 receives a char
12+
tank->serialEvent();
13+
}
14+
15+
void serialEvent1() { // if the hardware serial port_1 receives a char
16+
tank->serialEvent1();
17+
}
18+
1119
void setup() {
1220
tank = TankControllerLib::instance();
1321
tank->setup();

scripts/install_libraries.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,54 +22,63 @@ fi
2222
# add missing libraries
2323
export GITHUB="https://github.com/Arduino-CI"
2424
if [ -d "./Adafruit_BusIO" ]; then
25+
echo update Adafruit_BusIO
2526
(cd Adafruit_BusIO; git pull)
2627
else
2728
git clone $SHALLOW_MASTER $GITHUB/Adafruit_BusIO.git
2829
fi
2930

3031
if [ -d "./Adafruit_MAX31865" ]; then
32+
echo update Adafruit_MAX31865
3133
(cd Adafruit_MAX31865; git pull)
3234
else
3335
git clone $SHALLOW_MAIN $GITHUB/Adafruit_MAX31865.git
3436
fi
3537

3638
if [ -d "./Ethernet" ]; then
39+
echo update Ethernet
3740
(cd Ethernet; git pull)
3841
else
3942
git clone $SHALLOW_MASTER $GITHUB/Ethernet.git
4043
fi
4144

4245
if [ -d "./LiquidCrystal" ]; then
46+
echo update LiquidCrystal
4347
(cd LiquidCrystal; git pull)
4448
else
4549
git clone $SHALLOW_MASTER $GITHUB/LiquidCrystal.git
4650
fi
4751

4852
if [ -d "./RTClib" ]; then
53+
echo update RTClib
4954
(cd RTClib; git pull)
5055
else
5156
git clone $SHALLOW_MASTER $GITHUB/RTClib.git
5257
fi
5358

5459
if [ -d "./Keypad" ]; then
60+
echo update Keypad
5561
(cd Keypad; git pull)
5662
else
5763
git clone $SHALLOW_MASTER $GITHUB/Keypad.git
5864
fi
5965

6066
if [ -d "./Arduino-PID-Library" ]; then
67+
echo update Arduino-PID-Library
6168
(cd Arduino-PID-Library; git pull)
6269
else
6370
git clone $SHALLOW_MASTER $GITHUB/Arduino-PID-Library.git
6471
fi
6572

6673
if [ -d "./Arduino-PID-AutoTune-Library" ]; then
74+
echo update Arduino-PID-AutoTune-Library
6775
(cd Arduino-PID-AutoTune-Library; git pull)
6876
else
6977
git clone $SHALLOW_MASTER $GITHUB/Arduino-PID-AutoTune-Library.git
7078
fi
7179

7280
if [ -d "./SD" ]; then
81+
echo update SD
7382
(cd SD; git pull)
7483
else
7584
git clone $SHALLOW_MAIN $GITHUB/SD.git

src/Devices/PHProbe.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "Devices/PHProbe.h"
2+
3+
#include "Devices/Serial_TC.h"
4+
5+
// class instance variables
6+
/**
7+
* static variable for singleton
8+
*/
9+
PHProbe *PHProbe::_instance = nullptr;
10+
11+
// class methods
12+
/**
13+
* static member function to return singleton
14+
*/
15+
PHProbe *PHProbe::instance() {
16+
if (!_instance) {
17+
_instance = new PHProbe();
18+
}
19+
return _instance;
20+
}
21+
22+
// instance methods
23+
/**
24+
* constructor (private so clients use the singleton)
25+
*/
26+
PHProbe::PHProbe() {
27+
Serial1.print(F("*OK,0\r")); // Turn off the returning of OK after command to EZO pH
28+
Serial1.print(F("C,1\r")); // Reset pH stamp to continuous measurement: once per second
29+
}
30+
31+
/**
32+
* data arriving from probe
33+
*/
34+
void PHProbe::serialEvent1() {
35+
String string = Serial1.readStringUntil(13); // read the string until we see a <CR>
36+
Serial_TC *serial = Serial_TC::instance();
37+
if (string.length() > 0 && isdigit(string[0])) { // if the first character in the string is a digit
38+
value = string.toFloat(); // convert the string to a floating point number so it can be evaluated by the Arduino
39+
serial->print(F("pH = "), false);
40+
serial->print(value, 3);
41+
serial->println();
42+
}
43+
}

src/Devices/PHProbe.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
#include "Arduino.h"
3+
4+
class PHProbe {
5+
public:
6+
static PHProbe* instance();
7+
double getPH() {
8+
return value;
9+
}
10+
void serialEvent1();
11+
12+
private:
13+
// Class variable
14+
static PHProbe* _instance;
15+
// instance variable
16+
double value = 0;
17+
// Methods
18+
PHProbe();
19+
};

src/TankControllerLib.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "Devices/Keypad_TC.h"
44
#include "Devices/LiquidCrystal_TC.h"
5+
#include "Devices/PHProbe.h"
56
#include "Devices/SD_TC.h"
67
#include "Devices/Serial_TC.h"
78
#include "TC_util.h"
@@ -85,6 +86,20 @@ void TankControllerLib::loop() {
8586
handleUI();
8687
}
8788

89+
/**
90+
* This public instance function is called when there is data on the serial port(0).
91+
*/
92+
void TankControllerLib::serialEvent() {
93+
}
94+
95+
/**
96+
* This public instance function is called when there is data on the serial port(1).
97+
* This the Atlas EZO pH circuit probe.
98+
*/
99+
void TankControllerLib::serialEvent1() {
100+
PHProbe::instance()->serialEvent1();
101+
}
102+
88103
/**
89104
* Set the next state
90105
*/

src/TankControllerLib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class TankControllerLib {
1515

1616
// instance methods
1717
void loop();
18+
void serialEvent();
19+
void serialEvent1();
1820
void setNextState(UIState* newState, bool update = false);
1921
void setup();
2022
const char* stateName();

test/PHProbeTest.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <Arduino.h>
2+
#include <ArduinoUnitTests.h>
3+
4+
#include "Devices/PHProbe.h"
5+
#include "TankControllerLib.h"
6+
7+
unittest(singleton) {
8+
PHProbe *singleton1 = PHProbe::instance();
9+
PHProbe *singleton2 = PHProbe::instance();
10+
assertEqual(singleton1, singleton2);
11+
}
12+
13+
unittest(constructor) {
14+
assertEqual("*OK,0\rC,1\r", GODMODE()->serialPort[1].dataOut);
15+
}
16+
17+
// tests getPH() as well
18+
unittest(serialEvent1) {
19+
GodmodeState *state = GODMODE();
20+
state->reset();
21+
PHProbe *pPHProbe = PHProbe::instance();
22+
assertEqual(0, pPHProbe->getPH());
23+
GODMODE()->serialPort[1].dataIn = "7.75\r"; // the queue of data waiting to be read
24+
TankControllerLib *pTC = TankControllerLib::instance();
25+
state->serialPort[0].dataOut = "";
26+
assertEqual("", state->serialPort[0].dataOut);
27+
pTC->serialEvent1();
28+
assertEqual("pH = 7.750\r\n", state->serialPort[0].dataOut);
29+
assertEqual(7.75, PHProbe::instance()->getPH());
30+
}
31+
32+
unittest_main()

0 commit comments

Comments
 (0)