Skip to content
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

Feat/atlas tcomp command #72

Merged
merged 6 commits into from
Nov 8, 2024
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
Binary file not shown.
Binary file not shown.
54 changes: 50 additions & 4 deletions sam/src/SckAux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ bool AuxBoards::start(SckBase *base, SensorType wichSensor)
moistureChirp.calibrated = true;
}
#endif

#ifdef WITH_ATLAS
atlasPH.enableTComp = data.config.pHEnableTComp;
atlasEC.enableTComp = data.config.ECEnableTComp;
atlasDO.enableTComp = data.config.DOEnableTComp;
#endif
}

switch (wichSensor) {
Expand Down Expand Up @@ -597,6 +603,35 @@ String AuxBoards::control(SensorType wichSensor, String command)
if (responseCode == 1) return thisAtlas->atlasResponse;
else return String(responseCode);

} else if (command.startsWith("tcomp")) {
// Enable or disable temperature compensation on sensors
if (wichSensor == SENSOR_ATLAS_TEMPERATURE || wichSensor == SENSOR_ATLAS_ORP) {
return String("Sensor does not support temperature compensation. Ignoring");
}

command.replace("tcomp", "");
command.trim();

// Value: 0 -> disable, 1 -> enable, any other -> get current setting
if (command.startsWith("on")){
thisAtlas->enableTComp = true;
} else if (command.startsWith("off")) {
thisAtlas->enableTComp = false;
}

if (wichSensor == SENSOR_ATLAS_EC || wichSensor == SENSOR_ATLAS_EC_SG || wichSensor == SENSOR_ATLAS_EC_TDS || wichSensor == SENSOR_ATLAS_EC_SAL) {
data.config.ECEnableTComp = thisAtlas->enableTComp;
} else if (wichSensor == SENSOR_ATLAS_DO || wichSensor == SENSOR_ATLAS_DO_SAT) {
data.config.DOEnableTComp = thisAtlas->enableTComp;
} else if (wichSensor == SENSOR_ATLAS_PH) {
data.config.pHEnableTComp = thisAtlas->enableTComp;
}

eepromAuxData.write(data);

return String F("Atlas temperature compensation: ") + String(thisAtlas->enableTComp ? "on" : "off");
} else {
return F("Wrong command!!\r\nOptions:\r\ntcomp [on/off] # Enables temperature compensation\r\ncom [atlas commands]");
}
break;

Expand Down Expand Up @@ -1505,7 +1540,6 @@ bool Atlas::start()

if (!I2Cdetect(&auxWire, deviceAddress)) return false;


// Protocol lock
if (!sendCommand((char*)"Plock,1")) return false;
delay(shortWait);
Expand Down Expand Up @@ -1577,7 +1611,13 @@ bool Atlas::getBusyState()
if (millis() - lastUpdate < 2) return true;
switch (state) {

case REST: {
case SLEEP: {

if (millis() - lastCommandSent >= shortWait) {
if (sendCommand((char*)"r")) state = REST;
}

} case REST: {

// ORP doesn't need temp compensation so we jump directly to ask reading
if (ORP) {
Expand All @@ -1596,7 +1636,7 @@ bool Atlas::getBusyState()

} case TEMP_COMP_SENT: {

if (millis() - lastCommandSent >= shortWait) {
if (millis() - lastCommandSent >= longWait) {
if (sendCommand((char*)"r")) state = ASKED_READING;
}
break;
Expand Down Expand Up @@ -1662,13 +1702,16 @@ bool Atlas::getBusyState()
lastUpdate = millis();
return true;
}

void Atlas::goToSleep()
{

auxWire.beginTransmission(deviceAddress);
auxWire.write("Sleep");
auxWire.endTransmission();
state = SLEEP;
}

bool Atlas::sendCommand(char* command)
{

Expand All @@ -1688,12 +1731,15 @@ bool Atlas::sendCommand(char* command)
return true;
}

delay(300);
delay(shortWait);
}
return false;
}
bool Atlas::tempCompensation()
{
// If we don't enable Temperature compensation, we directly return
if (!enableTComp) return true;

if (!ORP) {
// Temperature compensation for PH, EC, and DO
float temperature = -1000;
Expand Down
9 changes: 9 additions & 0 deletions sam/src/SckAux.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,16 @@ struct Calibration {
int32_t wetPoint;
};

struct Config {
bool pHEnableTComp = true;
bool DOEnableTComp = true;
bool ECEnableTComp = true;
};

struct EepromAuxData {
bool valid = false;
Calibration calibration;
Config config;
};

bool I2Cdetect(byte address);
Expand Down Expand Up @@ -354,12 +361,14 @@ class Atlas
bool DO = false;
bool TEMP = false;
bool ORP = false;
bool enableTComp = true;
float newReading[4];
String atlasResponse;
uint32_t lastCommandSent = 0;
uint32_t lastUpdate = 0;
enum State {
REST,
SLEEP,
TEMP_COMP_SENT,
ASKED_READING,
};
Expand Down
Loading