Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 5 additions & 6 deletions src/Devices/PHProbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,16 @@ void PHProbe::clearCalibration() {
}

void PHProbe::sendSlopeRequest() {
Serial1.print(F("Slope,?\r")); // Sending request for Calibration Slope
Serial1.print("SLOPE,?\r"); // Sending request for Calibration Slope
slopeResponse = " Slope requested!";
}

String PHProbe::getSlope() {
// for example "?Slope,99.7,100.3, -0.89"
// for example "?SLOPE,99.7,100.3, -0.89"
if (slopeResponse.length() < 10) {
return String("");
}
String slope = slopeResponse.substring(7);
// output to log
serial("Calibration Slope: %s", slope.c_str());
return slope;
}

Expand All @@ -64,8 +62,9 @@ void PHProbe::serialEvent1() {
// convert the string to a floating point number so it can be evaluated by the Arduino
value = string.toFloat();
} else if (string[0] == '?') { // answer to a previous query
if (string.length() > 7 && string.substring(0, 7) == "?Slope,") {
// for example "?Slope,99.7,100.3, -0.89\r"
serial("PHProbe serialEvent1: \"%s\"", string.c_str());
if (string.length() > 7 && string.substring(0, 7) == "?SLOPE,") {
// for example "?SLOPE,16.1,100.0"
slopeResponse = string;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Devices/PHProbe.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

/**
* wrapper class for EZO pH Circuit | Atlas Scientific
*
* https://www.atlas-scientific.com/files/pH_EZO_Datasheet.pdf
*
* Issuing the "Cal,mid,n\r" command will
* clear the other calibration points.
*
* While the data sheet uses "Slope" the actual string is "SLOPE"
*/

// getValue() function is for testing purposes
Expand Down
12 changes: 5 additions & 7 deletions test/PHProbeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ unittest(serialEvent1) {
pTC->serialEvent1(); // fake interrupt
assertEqual(0, pPHProbe->getPh());
assertEqual("", pPHProbe->getSlopeResponse());
GODMODE()->serialPort[1].dataIn = "7.75\r?Slope,99.7,100.3,-0.89\r"; // the queue of data waiting to be read
GODMODE()->serialPort[1].dataIn = "7.75\r?SLOPE,99.7,100.3,-0.89\r"; // the queue of data waiting to be read
pTC->serialEvent1(); // fake interrupt
assertEqual("?Slope,99.7,100.3,-0.89", pPHProbe->getSlopeResponse());
assertEqual("?SLOPE,99.7,100.3,-0.89", pPHProbe->getSlopeResponse());
assertEqual(7.75, pPHProbe->getPh());
}

Expand Down Expand Up @@ -78,7 +78,7 @@ unittest(sendSlopeRequest) {
state->reset();
state->serialPort[0].dataOut = "";
PHProbe::instance()->sendSlopeRequest();
assertEqual("Slope,?\r", GODMODE()->serialPort[1].dataOut);
assertEqual("SLOPE,?\r", GODMODE()->serialPort[1].dataOut);
}

// this test assumes that earlier tests have run and that there is a slope available
Expand All @@ -88,19 +88,17 @@ unittest(getSlope) {
TankControllerLib *pTC = TankControllerLib::instance();
state->serialPort[0].dataOut = "";
PHProbe *pPHProbe = PHProbe::instance();
GODMODE()->serialPort[1].dataIn = "?Slope,99.7,100.3,-0.89\r"; // the queue of data waiting to be read
GODMODE()->serialPort[1].dataIn = "?SLOPE,99.7,100.3,-0.89\r"; // the queue of data waiting to be read
pTC->serialEvent1(); // fake interrupt
String slope = pPHProbe->getSlope();
assertEqual("99.7,100.3,-0.89", slope);
COUT(state->serialPort[0].dataOut.length());
GODMODE()->serialPort[1].dataIn = "?Slope,98.7,101.3,-0.89\r"; // the answer to getSlop() waiting to be read
GODMODE()->serialPort[1].dataIn = "?SLOPE,98.7,101.3,-0.89\r"; // the answer to getSlop() waiting to be read
pTC->serialEvent1(); // fake interrupt
COUT(state->serialPort[0].dataOut.length());
state->serialPort[0].dataOut = "";
slope = pPHProbe->getSlope();
assertEqual("98.7,101.3,-0.89", slope);
COUT(state->serialPort[0].dataOut.length());
assertEqual("Calibration Slope: 98.7,101.3,-0.89\r\n", state->serialPort[0].dataOut);
}

unittest(getPh) {
Expand Down
4 changes: 2 additions & 2 deletions test/SeePHSlopeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ unittest(testOutput) {
// Set up
TankControllerLib* tc = TankControllerLib::instance();
LiquidCrystal_TC* display = LiquidCrystal_TC::instance();
GODMODE()->serialPort[1].dataIn = "?Slope,99.7,100.3,-0.89\r"; // the queue of data waiting to be read
GODMODE()->serialPort[1].dataIn = "?SLOPE,99.7,100.3,-0.89\r"; // the queue of data waiting to be read
tc->serialEvent1(); // fake interrupt

assertEqual("MainMenu", tc->stateName());
Expand All @@ -23,7 +23,7 @@ unittest(testOutput) {
assertEqual("requesting slope", display->getLines().at(1));
tc->loop();
assertEqual("Slope requested!", display->getLines().at(1));
GODMODE()->serialPort[1].dataIn = "?Slope,99.7,100.3,-0.89\r"; // the queue of data waiting to be read
GODMODE()->serialPort[1].dataIn = "?SLOPE,99.7,100.3,-0.89\r"; // the queue of data waiting to be read
tc->serialEvent1(); // fake interrupt
tc->loop();
assertEqual("99.7,100.3,-0.89", display->getLines().at(1));
Expand Down