Skip to content

Commit

Permalink
Add commands to enable temperature compensation on atlas sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
oscgonfer committed Oct 28, 2024
1 parent a4cae9c commit 7c55fdc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
46 changes: 32 additions & 14 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 @@ -598,14 +604,34 @@ String AuxBoards::control(SensorType wichSensor, String command)
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();

if (command.startsWith("on")) thisAtlas->tComp(1);
else if (command.startsWith("off")) thisAtlas.tComp(0);
// 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.tComp() ? "on" : "off");
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 @@ -1514,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 @@ -1678,16 +1703,6 @@ bool Atlas::getBusyState()
return true;
}

bool Atlas::tComp(int8_t value)
{
// Value: 0 -> disable, 1 -> enable, any other -> get current setting

if (value == 1) sparkfun_scd30.setAutoSelfCalibration(true);
else if (value == 0) sparkfun_scd30.setAutoSelfCalibration(false);

return sparkfun_scd30.getAutoSelfCalibration();
}

void Atlas::goToSleep()
{

Expand Down Expand Up @@ -1722,6 +1737,9 @@ bool Atlas::sendCommand(char* command)
}
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
8 changes: 7 additions & 1 deletion 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 @@ -416,7 +423,6 @@ class Atlas
bool stop();
bool getReading();
bool getBusyState();
bool tComp(int8_t value=-1);

void goToSleep();
bool sendCommand(char* command);
Expand Down

0 comments on commit 7c55fdc

Please sign in to comment.