Skip to content
Merged
Show file tree
Hide file tree
Changes from 25 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
1 change: 1 addition & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ highpoint
HIGHTHRESH
homepage
HSCROLL
HSet
http
ifdef
ine
Expand Down
2 changes: 1 addition & 1 deletion scripts/testAndBuild.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
bundle config set --local path 'vendor/bundle'
bundle install
bundle exec arduino_ci.rb --min-free-space=5990 | tee output.txt
bundle exec arduino_ci.rb --min-free-space=5960 | tee output.txt
result="${PIPESTATUS[0]}"
tail -n 4 output.txt | head -n 2 > size.txt
exit "$result"
4 changes: 2 additions & 2 deletions size.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Sketch uses 75918 bytes (29%) of program storage space. Maximum is 253952 bytes.
Global variables use 2194 bytes (26%) of dynamic memory, leaving 5998 bytes for local variables. Maximum is 8192 bytes.
Sketch uses 77948 bytes (30%) of program storage space. Maximum is 253952 bytes.
Global variables use 2224 bytes (27%) of dynamic memory, leaving 5968 bytes for local variables. Maximum is 8192 bytes.
28 changes: 26 additions & 2 deletions src/Devices/EEPROM_TC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,24 @@ float EEPROM_TC::getPHSeriesPointer() {
float EEPROM_TC::getPHSeriesSize() {
return eepromReadFloat(PH_SERIES_SIZE_ADDRESS);
}
uint32_t EEPROM_TC::getRampTimeStart() {
uint32_t EEPROM_TC::getPhRampTimeStart() {
return eepromReadInt(RAMP_TIME_START_PH_ADDRESS);
}
uint32_t EEPROM_TC::getRampTimeEnd() {
uint32_t EEPROM_TC::getPhRampTimeEnd() {
return eepromReadInt(RAMP_TIME_END_PH_ADDRESS);
}
float EEPROM_TC::getRampStartingPH() {
return eepromReadFloat(RAMP_STARTING_PH_ADDRESS);
}
uint32_t EEPROM_TC::getPhSineStartTime() {
return eepromReadInt(PH_SINE_START_TIME_ADDRESS);
}
uint32_t EEPROM_TC::getPhSinePeriod() {
return eepromReadInt(PH_SINE_AMPLITUDE_ADDRESS);
}
float EEPROM_TC::getPhSineAmplitude() {
return eepromReadFloat(PH_SINE_PERIOD_ADDRESS);
}
uint32_t EEPROM_TC::getRampTimeStartTemp() {
return eepromReadInt(RAMP_TIME_START_TEMP_ADDRESS);
}
Expand All @@ -126,6 +135,9 @@ uint32_t EEPROM_TC::getRampTimeEndTemp() {
float EEPROM_TC::getRampStartingTemp() {
return eepromReadFloat(RAMP_STARTING_TEMP_ADDRESS);
}
uint16_t EEPROM_TC::getPHSetType() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Ph" or "PH"? Lets be consistent and make it always "Ph" in the function names.

return static_cast<uint16_t>(eepromReadFloat(PH_SET_TYPE_ADDRESS));
}
uint16_t EEPROM_TC::getTankID() {
return static_cast<uint16_t>(eepromReadFloat(TANK_ID_ADDRESS));
}
Expand Down Expand Up @@ -204,6 +216,15 @@ void EEPROM_TC::setPhRampTimeEnd(uint32_t value) {
void EEPROM_TC::setRampStartingPH(float value) {
eepromWriteFloat(RAMP_STARTING_PH_ADDRESS, value);
}
void EEPROM_TC::setPhSineStartTime(uint32_t value) {
eepromWriteInt(PH_SINE_START_TIME_ADDRESS, value);
}
void EEPROM_TC::setPhSinePeriod(uint32_t value) {
eepromWriteInt(PH_SINE_AMPLITUDE_ADDRESS, value);
}
void EEPROM_TC::setPhSineAmplitude(float value) {
eepromWriteFloat(PH_SINE_PERIOD_ADDRESS, value);
}
void EEPROM_TC::setRampTimeStartTemp(uint32_t value) {
eepromWriteInt(RAMP_TIME_START_TEMP_ADDRESS, value);
}
Expand All @@ -213,6 +234,9 @@ void EEPROM_TC::setRampTimeEndTemp(uint32_t value) {
void EEPROM_TC::setRampStartingTemp(float value) {
eepromWriteFloat(RAMP_STARTING_TEMP_ADDRESS, value);
}
void EEPROM_TC::setPHSetType(uint16_t value) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Ph" or "PH"? Lets be consistent and make it always "Ph" in the function names.

eepromWriteFloat(PH_SET_TYPE_ADDRESS, (float)value);
}
void EEPROM_TC::setTankID(uint16_t value) {
eepromWriteFloat(TANK_ID_ADDRESS, (float)value);
}
Expand Down
24 changes: 18 additions & 6 deletions src/Devices/EEPROM_TC.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,20 @@ class EEPROM_TC {
void getMac(uint8_t* bytes); // used for DHCP request for IP address
float getMaxDataAge(); // not used
float getPH(); // target pH
uint32_t getRampTimeStart();
uint32_t getRampTimeEnd();
uint32_t getPhRampTimeStart();
uint32_t getPhRampTimeEnd();
float getRampStartingPH();
uint32_t getPhSineStartTime();
uint32_t getPhSinePeriod();
float getPhSineAmplitude();
uint32_t getRampTimeStartTemp();
uint32_t getRampTimeEndTemp();
float getRampStartingTemp();
float getPHDelay(); // not used
float getPHInterval(); // not used
float getPHSeriesPointer(); // not used
float getPHSeriesSize(); // not used
float getPHDelay(); // not used
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Ph" or "PH"? Lets be consistent and make it always "Ph" in the function names. Update for the whole file.

float getPHInterval(); // not used
float getPHSeriesPointer(); // not used
float getPHSeriesSize(); // not used
uint16_t getPHSetType();
uint16_t getTankID(); // unique tank identifier for reporting
float getTemp(); // target temperature
float getTempDelay(); // not used
Expand All @@ -59,13 +63,17 @@ class EEPROM_TC {
void setPhRampTimeStart(uint32_t value);
void setPhRampTimeEnd(uint32_t value);
void setRampStartingPH(float value);
void setPhSineStartTime(uint32_t value);
void setPhSinePeriod(uint32_t value);
void setPhSineAmplitude(float value);
void setRampTimeStartTemp(uint32_t value);
void setRampTimeEndTemp(uint32_t value);
void setRampStartingTemp(float value);
void setPHDelay(float value);
void setPHInterval(float value);
void setPHSeriesPointer(float value);
void setPHSeriesSize(float value);
void setPHSetType(uint16_t value);
void setTankID(uint16_t value);
void setTemp(float value);
void setTempDelay(float value);
Expand Down Expand Up @@ -104,9 +112,13 @@ class EEPROM_TC {
const uint16_t RAMP_STARTING_PH_ADDRESS = 112;
const uint16_t RAMP_TIME_START_PH_ADDRESS = 116;
const uint16_t RAMP_TIME_END_PH_ADDRESS = 120;
const uint16_t PH_SINE_AMPLITUDE_ADDRESS = 112;
const uint16_t PH_SINE_START_TIME_ADDRESS = 116;
const uint16_t PH_SINE_PERIOD_ADDRESS = 120;
const uint16_t RAMP_STARTING_TEMP_ADDRESS = 124;
const uint16_t RAMP_TIME_START_TEMP_ADDRESS = 128;
const uint16_t RAMP_TIME_END_TEMP_ADDRESS = 132;
const uint16_t PH_SET_TYPE_ADDRESS = 136;

// class variables
static EEPROM_TC* _instance;
Expand Down
89 changes: 73 additions & 16 deletions src/Devices/PHControl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "PHControl.h"

#include <math.h>

#include "Devices/DateTime_TC.h"
#include "Devices/EEPROM_TC.h"
#include "Devices/PHProbe.h"
Expand Down Expand Up @@ -42,15 +44,31 @@ PHControl::PHControl() {
targetPh = DEFAULT_PH;
EEPROM_TC::instance()->setPH(targetPh);
}
rampTimeEnd = EEPROM_TC::instance()->getRampTimeEnd();
if (rampTimeEnd == 0xFFFFFFFF || rampTimeEnd == 0) {
rampTimeEnd = 0;
EEPROM_TC::instance()->setPhRampTimeEnd(rampTimeEnd);
rampTimeStart = 0;
EEPROM_TC::instance()->setPhRampTimeStart(rampTimeStart);
} else {
rampTimeStart = EEPROM_TC::instance()->getRampTimeStart();
rampStartingPh = EEPROM_TC::instance()->getRampStartingPH();
pHSetType = EEPROM_TC::instance()->getPHSetType();
if (pHSetType == 0xFFFFFFFF) {
pHSetType = FLAT_TYPE;
EEPROM_TC::instance()->setPHSetType(pHSetType);
}
switch (pHSetType) {
case RAMP_TYPE:
rampTimeEnd = EEPROM_TC::instance()->getPhRampTimeEnd();
if (rampTimeEnd == 0xFFFFFFFF || rampTimeEnd == 0) {
rampTimeEnd = 0;
EEPROM_TC::instance()->setPhRampTimeEnd(rampTimeEnd);
rampTimeStart = 0;
EEPROM_TC::instance()->setPhRampTimeStart(rampTimeStart);
} else {
rampTimeStart = EEPROM_TC::instance()->getPhRampTimeStart();
rampStartingPh = EEPROM_TC::instance()->getRampStartingPH();
}
break;
case SINE_TYPE:
period = EEPROM_TC::instance()->getPhSinePeriod();
amplitude = EEPROM_TC::instance()->getPhSineAmplitude();
sineStartTime = EEPROM_TC::instance()->getPhSineStartTime();
break;
default:
break;
}
char buffer[40];
strncpy_P(buffer, (PGM_P)F("PHControl with target pH = "), sizeof(buffer));
Expand Down Expand Up @@ -83,16 +101,31 @@ void PHControl::setRampDuration(float newPhRampDuration) {
rampTimeStart = DateTime_TC::now().secondstime();
rampTimeEnd = rampTimeStart + (newPhRampDuration * 3600);
rampStartingPh = PHProbe::instance()->getPh();
pHSetType = phSetTypeTypes::RAMP_TYPE;
EEPROM_TC::instance()->setPHSetType(pHSetType);
EEPROM_TC::instance()->setPhRampTimeStart(rampTimeStart);
EEPROM_TC::instance()->setPhRampTimeEnd(rampTimeEnd);
EEPROM_TC::instance()->setRampStartingPH(rampStartingPh);
} else {
rampTimeEnd = 0;
pHSetType = phSetTypeTypes::FLAT_TYPE;
EEPROM_TC::instance()->setPHSetType(pHSetType);
EEPROM_TC::instance()->setPhRampTimeEnd(rampTimeEnd);
serial("set ramp time to 0");
}
}

void PHControl::setSine(float sineAmplitude, float sinePeriodInHours) {
period = (sinePeriodInHours * 3600);
amplitude = sineAmplitude;
pHSetType = phSetTypeTypes::SINE_TYPE;
sineStartTime = DateTime_TC::now().secondstime();
EEPROM_TC::instance()->setPHSetType(pHSetType);
EEPROM_TC::instance()->setPhSinePeriod(period);
EEPROM_TC::instance()->setPhSineAmplitude(amplitude);
EEPROM_TC::instance()->setPhSineStartTime(sineStartTime);
}

void PHControl::enablePID(bool flag) {
usePID = flag;
// save to EEPROM?
Expand All @@ -106,13 +139,37 @@ bool PHControl::isOn() {
void PHControl::updateControl(float pH) {
int msToBeOn;
int nowModWindow = millis() % WINDOW_SIZE;
float currentTime = DateTime_TC::now().secondstime();
// if ramp is being used
if (currentTime < rampTimeEnd) {
currentPHTarget =
rampStartingPh + ((currentTime - rampTimeStart) * (targetPh - rampStartingPh) / (rampTimeEnd - rampTimeStart));
} else {
currentPHTarget = targetPh;
uint32_t currentTime = DateTime_TC::now().secondstime();
switch (pHSetType) {
case FLAT_TYPE: {
currentPHTarget = targetPh;
break;
}
case RAMP_TYPE: {
if (currentTime < rampTimeEnd) {
currentPHTarget = rampStartingPh +
((currentTime - rampTimeStart) * (targetPh - rampStartingPh) / (rampTimeEnd - rampTimeStart));
} else {
currentPHTarget = targetPh;
}
break;
}
case SINE_TYPE: {
uint32_t sineEndTime = sineStartTime + period;
if (currentTime >= sineEndTime) {
sineStartTime = DateTime_TC::now().secondstime();
sineEndTime = sineStartTime + period;
EEPROM_TC::instance()->setPhSineStartTime(sineStartTime);
}
float timeLeftTillPeriodEnd = sineEndTime - currentTime;
float percentNOTThroughPeriod = timeLeftTillPeriodEnd / period;
float percentThroughPeriod = 1 - percentNOTThroughPeriod;
float x = percentThroughPeriod * (2 * PI); // the x position for our sine wave
currentPHTarget = amplitude * sin(x) + targetPh; // y position in our sine wave
break;
}
default:
break;
}
COUT("PHControl::updateControl(" << pH << ") at " << millis());
if (usePID) {
Expand Down
23 changes: 21 additions & 2 deletions src/Devices/PHControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ class PHControl {
float rampStartingPh;
uint32_t rampTimeStart;
uint32_t rampTimeEnd;
float amplitude;
uint32_t period;
uint32_t sineStartTime;
const uint16_t WINDOW_SIZE = 10000; // 10 second Proportional output window (for PID)
bool usePID = true;
int pHSetType = FLAT_TYPE;
PHControl();

public:
enum phSetTypeTypes {
FLAT_TYPE,
RAMP_TYPE,
SINE_TYPE,
};
static PHControl* instance();
static void clearInstance();
float getTargetPh() {
Expand All @@ -29,18 +38,28 @@ class PHControl {
float getCurrentPHTarget() {
return currentPHTarget;
}
uint32_t getRampTimeStart() {
int getPHSetType() {
return pHSetType;
}
float getAmplitude() {
return amplitude;
}
uint32_t getPhRampTimeStart() {
return rampTimeStart;
}
uint32_t getRampTimeEnd() {
uint32_t getPhRampTimeEnd() {
return rampTimeEnd;
}
uint32_t getPeriod() {
return period;
}
bool getUsePID() {
return usePID;
}
bool isOn();
void setTargetPh(float newPh);
void setRampDuration(float newPhRampDuration);
void setSine(float sineAmplitude, float sinePeriodInHours);
void enablePID(bool flag);
void updateControl(float pH);
};
4 changes: 2 additions & 2 deletions src/Devices/TemperatureControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class TemperatureControl {
float getCurrentTemperatureTarget() {
return currentTemperatureTarget;
}
uint32_t getRampTimeStart() {
uint32_t getPhRampTimeStart() {
return rampTimeStart;
}
uint32_t getRampTimeEnd() {
uint32_t getPhRampTimeEnd() {
return rampTimeEnd;
}
virtual bool isHeater();
Expand Down
5 changes: 5 additions & 0 deletions src/UIState/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "SetKI.h"
#include "SetKP.h"
#include "SetPHSetPoint.h"
#include "SetPHWithSine.h"
#include "SetTankID.h"
#include "SetTempSetPoint.h"
#include "SetTime.h"
Expand Down Expand Up @@ -53,6 +54,7 @@ MainMenu::MainMenu(TankController *tc) : UIState(tc) {
setMenus[SET_TEMP_CALIBRATION] = F("Temp calibration");
setMenus[SET_TEMPERATURE] = F("Set temperature");
setMenus[SET_TIME] = F("Set date/time");
setMenus[SET_PH_WITH_SINE] = F("Set pH w sine");
}

/**
Expand Down Expand Up @@ -205,6 +207,9 @@ void MainMenu::selectSet() {
case SET_TEMPERATURE:
this->setNextState(static_cast<UIState *>(new SetTempSetPoint(tc)));
break;
case SET_PH_WITH_SINE:
this->setNextState(static_cast<UIState *>(new SetPHWithSine(tc)));
break;
case SET_TIME:
this->setNextState(static_cast<UIState *>(new SetTime(tc)));
break;
Expand Down
5 changes: 3 additions & 2 deletions src/UIState/MainMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class TankController; // forward reference
class MainMenu : public UIState {
public:
enum ViewCommands {
enum ViewCommands { // this order affects tests
VIEW_TIME,
VIEW_PID,
VIEW_PH_SLOPE,
Expand All @@ -24,7 +24,7 @@ class MainMenu : public UIState {
VIEW_FREE_MEMORY,
VIEW_COMMAND_COUNT // always last
};
enum SetCommands {
enum SetCommands { // this order affects tests
SET_PH,
SET_TEMPERATURE,
SET_CALIBRATION,
Expand All @@ -38,6 +38,7 @@ class MainMenu : public UIState {
SET_GOOGLE_MINS,
SET_TIME,
SET_TANK_ID,
SET_PH_WITH_SINE,
SET_COMMAND_COUNT // always last
};
MainMenu(TankController* tc);
Expand Down
4 changes: 2 additions & 2 deletions src/UIState/SetPHSetPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ float SetPHSetPoint::getCurrentValue() {
if (subState == 0) {
return PHControl::instance()->getTargetPh();
} else {
uint32_t rampTimeStart = PHControl::instance()->getRampTimeStart();
uint32_t rampTimeEnd = PHControl::instance()->getRampTimeEnd();
uint32_t rampTimeStart = PHControl::instance()->getPhRampTimeStart();
uint32_t rampTimeEnd = PHControl::instance()->getPhRampTimeEnd();
return (rampTimeEnd - rampTimeStart) / 3600;
}
}
Expand Down
Loading