-
Notifications
You must be signed in to change notification settings - Fork 35
PHProbe part1 #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
PHProbe part1 #67
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6bef036
Initial implementation of PHProbe
eucalvo 23ed44f
update format
eucalvo 8821367
format update
eucalvo 17b3068
update format
eucalvo 3a6e462
update spelling
eucalvo f42d176
changed serialEvent1 to happen in PHProbe
63049dc
merge
75f772b
update format
1b441ac
fixed errors and updated test
ed7ae6d
clang format vsix
eucalvo aff18b3
Merge branch '2021' of https://github.com/eucalvo/TankController into…
eucalvo aaad57e
delete clang vsix file
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #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::probeData(String string) { | ||
| Serial_TC *serial = Serial_TC::instance(); | ||
| if (string.size() > 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(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 probeData(String string); | ||
|
|
||
| private: | ||
| // Class variable | ||
| static PHProbe* _instance; | ||
| // instance variable | ||
| double value = 0; | ||
| // Methods | ||
| PHProbe(); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #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(probeData) { | ||
| GodmodeState *state = GODMODE(); | ||
| state->reset(); | ||
| assertEqual("", state->serialPort[0].dataOut); | ||
| PHProbe *pPHProbe = PHProbe::instance(); | ||
| assertEqual(0, pPHProbe->getPH()); | ||
| pPHProbe->probeData("7.250"); | ||
| assertEqual(7.25, pPHProbe->getPH()); | ||
| assertEqual("pH = 7.250\r\n", state->serialPort[0].dataOut); | ||
| } | ||
|
|
||
| unittest(serialEvent1) { | ||
| GODMODE()->serialPort[1].dataIn = "7.75\r"; // the queue of data waiting to be read | ||
| TankControllerLib::instance()->serialEvent1(); | ||
| assertEqual(7.75, PHProbe::instance()->getPH()); | ||
| } | ||
|
|
||
| unittest_main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's modify this to move the read into the PHProbe class.