Skip to content

Commit

Permalink
Use new standard for Form Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasto committed Jun 9, 2018
1 parent ce5bf47 commit 2011abf
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 95 deletions.
87 changes: 43 additions & 44 deletions _P214_Atlas_EZO_pH.ino
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ boolean Plugin_214(byte function, struct EventStruct *event, String& string)
#define _P214_ATLASEZO_I2C_NB_OPTIONS 4
byte I2Cchoice = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
int optionValues[_P214_ATLASEZO_I2C_NB_OPTIONS] = { 0x63, 0x64, 0x65, 0x66 };
addFormSelectorI2C(string, F("plugin_214_i2c"), _P214_ATLASEZO_I2C_NB_OPTIONS, optionValues, I2Cchoice);
addFormSelectorI2C(F("plugin_214_i2c"), _P214_ATLASEZO_I2C_NB_OPTIONS, optionValues, I2Cchoice);

addFormSubHeader(string, F("General"));
addFormSubHeader(F("General"));

char sensordata[32];
bool status;
Expand All @@ -62,30 +62,30 @@ boolean Plugin_214(byte function, struct EventStruct *event, String& string)
if (status) {
String boardInfo(sensordata);

string += "<TR><TD>Board type : </TD><TD>";
addHtml(F("<TR><TD>Board type : </TD><TD>"));
int pos1 = boardInfo.indexOf(',');
int pos2 = boardInfo.lastIndexOf(',');
string += boardInfo.substring(pos1+1,pos2);
addHtml(boardInfo.substring(pos1+1,pos2));
if (boardInfo.substring(pos1+1,pos2) != "pH"){
string += "<span style='color:red'> WARNING : Board type should be 'pH', check your i2c Address ? </span>";
addHtml(F("<span style='color:red'> WARNING : Board type should be 'pH', check your i2c Address ? </span>"));
}
string += "</TD></TR><TR><TD>Board version :</TD><TD>";
string += boardInfo.substring(pos2+1);
string += "</TD></TR>";
addHtml(F("</TD></TR><TR><TD>Board version :</TD><TD>"));
addHtml(boardInfo.substring(pos2+1));
addHtml(F("</TD></TR>"));

string += F("<input type='hidden' name='plugin_214_sensorVersion' value='");
string += boardInfo.substring(pos2+1);
string += F("'>");
addHtml(F("<input type='hidden' name='plugin_214_sensorVersion' value='"));
addHtml(boardInfo.substring(pos2+1));
addHtml(F("'>"));

} else {
string += "<span style='color:red;'>Unable to send command to device</span>";
addHtml(F("<span style='color:red;'>Unable to send command to device</span>"));
success = false;
break;
}

addFormCheckBox(string, F("Status LED"), F("Plugin_214_status_led"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
addFormCheckBox(F("Status LED"),F("Plugin_214_status_led"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);

addFormSubHeader(string, F("Calibration"));
addFormSubHeader(F("Calibration"));

int nb_calibration_points = -1;
status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0], "Cal,?",sensordata);
Expand All @@ -99,38 +99,35 @@ boolean Plugin_214(byte function, struct EventStruct *event, String& string)
}
}

string += F("<TR><TD>Middle calibration</TD><TD>Enable ");
addCheckBox(string, F("Plugin_214_enable_cal_M' onClick='document.getElementById(\"Plugin_214_enable_cal_H\").checked = false;document.getElementById(\"Plugin_214_enable_cal_L\").checked = false;"), false);
string += F("&nbsp; &nbsp;Ref Ph:&nbsp;");
addNumericBox(string, F("Plugin_214_ref_cal_M' step='0.01"),Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1],1,14);
addRowLabel(F("<strong>Middle</strong>"));
addFormNumericBox(F("Ref Ph"),F("Plugin_214_ref_cal_M' step='0.01"),Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1],1,14);
if (nb_calibration_points > 0) {
string += F("&nbsp;<span style='color:green;'>OK</span>");
addHtml(F("&nbsp;<span style='color:green;'>OK</span>"));
} else {
string += F("&nbsp;<span style='color:red;'>Not yet calibrated</span>");
addHtml(F("&nbsp;<span style='color:red;'>Not yet calibrated</span>"));
}
string += F("</TD>");
addFormCheckBox(F("Enable"),F("Plugin_214_enable_cal_M"), false);
addHtml(F("\n<script type='text/javascript'>document.getElementById(\"Plugin_214_enable_cal_M\").onclick = function(){document.getElementById(\"Plugin_214_enable_cal_L\").checked = false;document.getElementById(\"Plugin_214_enable_cal_H\").checked = false;};</script>\n"));

string += F("<TR><TD>Low calibration</TD><TD>Enable ");
addCheckBox(string, F("Plugin_214_enable_cal_L' onClick='document.getElementById(\"Plugin_214_enable_cal_M\").checked = false;document.getElementById(\"Plugin_214_enable_cal_H\").checked = false;"), false);
string += F("&nbsp; &nbsp;Ref Ph:&nbsp;");
addNumericBox(string, F("Plugin_214_ref_cal_L' step='0.01"), Settings.TaskDevicePluginConfigFloat[event->TaskIndex][2],1,14);
addRowLabel(F("<strong>Low</strong>"));
addFormNumericBox(F("Ref Ph"),F("Plugin_214_ref_cal_L' step='0.01"), Settings.TaskDevicePluginConfigFloat[event->TaskIndex][2],1,14);
if (nb_calibration_points > 1) {
string += F("&nbsp;<span style='color:green;'>OK</span>");
addHtml(F("&nbsp;<span style='color:green;'>OK</span>"));
} else {
string += F("&nbsp;<span style='color:red;'>Not yet calibrated</span>");
addHtml(F("&nbsp;<span style='color:red;'>Not yet calibrated</span>"));
}
string += F("</TD>");
addFormCheckBox(F("Enable"),F("Plugin_214_enable_cal_L"), false);
addHtml(F("\n<script type='text/javascript'>document.getElementById(\"Plugin_214_enable_cal_L\").onclick = function(){document.getElementById(\"Plugin_214_enable_cal_M\").checked = false;document.getElementById(\"Plugin_214_enable_cal_H\").checked = false;};</script>\n"));

string += F("<TR><TD>High calibration</TD><TD>Enable ");
addCheckBox(string, F("Plugin_214_enable_cal_H' onClick='document.getElementById(\"Plugin_214_enable_cal_M\").checked = false;document.getElementById(\"Plugin_214_enable_cal_L\").checked = false;"), false);
string += F("&nbsp; &nbsp;Ref Ph:&nbsp;");
addNumericBox(string, F("Plugin_214_ref_cal_H' step='0.01"), Settings.TaskDevicePluginConfigFloat[event->TaskIndex][3],1,14);
addHtml(F("<TR><TD><strong>High</strong></TD>"));
addFormNumericBox(F("Ref Ph"),F("Plugin_214_ref_cal_H' step='0.01"), Settings.TaskDevicePluginConfigFloat[event->TaskIndex][3],1,14);
if (nb_calibration_points > 2) {
string += F("&nbsp;<span style='color:green;'>OK</span>");
addHtml(F("&nbsp;<span style='color:green;'>OK</span>"));
} else {
string += F("&nbsp;<span style='color:orange;'>Not yet calibrated</span>");
addHtml(F("&nbsp;<span style='color:orange;'>Not yet calibrated</span>"));
}
string += F("</TD>");
addFormCheckBox(F("Enable"),F("Plugin_214_enable_cal_H"), false);
addHtml(F("\n<script type='text/javascript'>document.getElementById(\"Plugin_214_enable_cal_H\").onclick = function(){document.getElementById(\"Plugin_214_enable_cal_L\").checked = false;document.getElementById(\"Plugin_214_enable_cal_M\").checked = false;};</script>\n"));

if (nb_calibration_points > 1){
char sensordata[32];
Expand All @@ -141,24 +138,26 @@ boolean Plugin_214(byte function, struct EventStruct *event, String& string)
if (status){
String slopeAnswer("Answer to 'Slope' command : ");
slopeAnswer += sensordata;
addFormNote(string, slopeAnswer);
addFormNote(slopeAnswer);
}
}

addFormSubHeader(string, F("Temperature compensation"));
addFormSubHeader(F("Temperature compensation"));
char deviceTemperatureTemplate[40];
LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate));
addFormTextBox(string, F("Temperature "), F("Plugin_214_temperature_template"), deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate));
addFormNote(string, F("You can use a formulae (and idealy refer to a temp sensor). "));
addFormTextBox(F("Temperature "), F("Plugin_214_temperature_template"), deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate));
addFormNote(F("You can use a formulae (and idealy refer to a temp sensor). "));
float value;
string += "<div class='note'>";
char strValue[5];
addHtml(F("<div class='note'>"));
if (Calculate(deviceTemperatureTemplate,&value) == CALCULATE_OK ){
string += "Actual value : ";
string += value;
addHtml(F("Actual value : "));
dtostrf(value,5,2,strValue);
addHtml(strValue);
} else {
string += "(It seems I can't parse your formulae)";
addHtml(F("(It seems I can't parse your formulae)"));
}
string += "</div>";
addHtml(F("</div>"));

success = true;
break;
Expand Down
105 changes: 54 additions & 51 deletions _P215_Atlas_EZO_EC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ boolean Plugin_215(byte function, struct EventStruct *event, String& string)
#define ATLASEZO_EC_I2C_NB_OPTIONS 3
byte I2Cchoice = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
int optionValues[ATLASEZO_EC_I2C_NB_OPTIONS] = { 0x64, 0x65, 0x66 };
addFormSelectorI2C(string, F("Plugin_215_i2c"), ATLASEZO_EC_I2C_NB_OPTIONS, optionValues, I2Cchoice);
addFormSelectorI2C(F("Plugin_215_i2c"), ATLASEZO_EC_I2C_NB_OPTIONS, optionValues, I2Cchoice);

addFormSubHeader(string, F("General"));
addFormSubHeader(F("General"));

char sensordata[32];
bool status;
Expand All @@ -62,89 +62,92 @@ boolean Plugin_215(byte function, struct EventStruct *event, String& string)
if (status) {
String boardInfo(sensordata);

string += "<TR><TD>Board type : </TD><TD>";
addHtml(F("<TR><TD>Board type : </TD><TD>"));
int pos1 = boardInfo.indexOf(',');
int pos2 = boardInfo.lastIndexOf(',');
string += boardInfo.substring(pos1+1,pos2);
addHtml(boardInfo.substring(pos1+1,pos2));
if (boardInfo.substring(pos1+1,pos2) != "EC"){
string += "<span style='color:red'> WARNING : Board type should be 'EC', check your i2c Address ? </span>";
addHtml(F("<span style='color:red'> WARNING : Board type should be 'EC', check your i2c Address ? </span>"));
}
string += "</TD></TR><TR><TD>Board version :</TD><TD>";
string += boardInfo.substring(pos2+1);
string += "</TD></TR>\n";
addHtml(F("</TD></TR><TR><TD>Board version :</TD><TD>"));
addHtml(boardInfo.substring(pos2+1));
addHtml(F("</TD></TR>\n"));

string += F("<input type='hidden' name='Plugin_215_sensorVersion' value='");
string += boardInfo.substring(pos2+1);
string += F("'>");
addHtml(F("<input type='hidden' name='Plugin_215_sensorVersion' value='"));
addHtml(boardInfo.substring(pos2+1));
addHtml(F("'>"));

status = _P215_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"K,?",sensordata);
boardInfo = sensordata;
string += "<TR><TD>Sensor type : </TD><TD>K=";
addHtml(F("<TR><TD>Sensor type : </TD><TD>K="));
pos2 = boardInfo.lastIndexOf(',');
string += boardInfo.substring(pos2+1);
string += "</TD></TR>\n";
addHtml(boardInfo.substring(pos2+1));
addHtml(F("</TD></TR>\n"));

} else {
string += "<span style='color:red;'>Unable to send command to device</span>";
addHtml(F("<span style='color:red;'>Unable to send command to device</span>"));
success = false;
break;
}

addFormCheckBox(string, F("Status LED"), F("Plugin_215_status_led"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);
addFormSubHeader(string, F("Calibration"));
string += F("<TR><TD>Dry calibration</TD><TD>Enable ");
addCheckBox(string, F("Plugin_215_enable_cal_dry' onClick='document.getElementById(\"Plugin_215_enable_cal_single\").checked = false;document.getElementById(\"Plugin_215_enable_cal_L\").checked = false;;document.getElementById(\"Plugin_215_enable_cal_H\").checked = false;"), false);
string += "</TD></TR><TR>\n";
addFormNote(string, F("Dry calibration must always be done first!"));
string += "</TR>";

string += F("<TR><TD>Single point calibration</TD><TD>Enable ");
addCheckBox(string, F("Plugin_215_enable_cal_single' onClick='document.getElementById(\"Plugin_215_enable_cal_dry\").checked = false;document.getElementById(\"Plugin_215_enable_cal_L\").checked = false;;document.getElementById(\"Plugin_215_enable_cal_H\").checked = false;"), false);
string += F("&nbsp; &nbsp;Ref EC:&nbsp;");
addNumericBox(string, F("Plugin_215_ref_cal_single"), Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
string += "&micro;S</TD></TR>\n";

string += F("<TR><TD>Low calibration</TD><TD>Enable ");
addCheckBox(string, F("Plugin_215_enable_cal_L' onClick='document.getElementById(\"Plugin_215_enable_cal_dry\").checked = false;document.getElementById(\"Plugin_215_enable_cal_single\").checked = false;;document.getElementById(\"Plugin_215_enable_cal_H\").checked = false;"), false);
string += F("&nbsp; &nbsp;Ref EC:&nbsp;");
addNumericBox(string, F("Plugin_215_ref_cal_L"), Settings.TaskDevicePluginConfig[event->TaskIndex][3]);
string += "&micro;S</TD></TR>\n";

string += F("<TR><TD>High calibration</TD><TD>Enable ");
addCheckBox(string, F("Plugin_215_enable_cal_H' onClick='document.getElementById(\"Plugin_215_enable_cal_dry\").checked = false;document.getElementById(\"Plugin_215_enable_cal_single\").checked = false;;document.getElementById(\"Plugin_215_enable_cal_L\").checked = false;"), false);
string += F("&nbsp; &nbsp;Ref EC:&nbsp;");
addNumericBox(string, F("Plugin_215_ref_cal_H"), Settings.TaskDevicePluginConfig[event->TaskIndex][4]);
string += "&micro;S</TD></TR>\n";
addFormCheckBox(F("Status LED"), F("Plugin_215_status_led"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]);

addFormSubHeader(F("Calibration"));

addRowLabel(F("<strong>Dry calibration</strong>"));
addFormCheckBox(F("Enable"),F("Plugin_215_enable_cal_dry"), false);
addHtml(F("\n<script type='text/javascript'>document.getElementById(\"Plugin_215_enable_cal_dry\").onclick=function() {document.getElementById(\"Plugin_215_enable_cal_single\").checked = false;document.getElementById(\"Plugin_215_enable_cal_L\").checked = false;;document.getElementById(\"Plugin_215_enable_cal_H\").checked = false;};</script>"));
addFormNote(F("Dry calibration must always be done first!"));

addRowLabel(F("<strong>Single point calibration</strong> "));
addFormCheckBox(F("Enable"),F("Plugin_215_enable_cal_single"), false);
addHtml(F("\n<script type='text/javascript'>document.getElementById(\"Plugin_215_enable_cal_single\").onclick=function() {document.getElementById(\"Plugin_215_enable_cal_dry\").checked = false;document.getElementById(\"Plugin_215_enable_cal_L\").checked = false;;document.getElementById(\"Plugin_215_enable_cal_H\").checked = false;};</script>"));
addFormNumericBox(F("Ref EC"),F("Plugin_215_ref_cal_single"), Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
addUnit("&micro;S");

addRowLabel(F("<strong>Low calibration</strong>"));
addFormCheckBox(F("enable"),F("Plugin_215_enable_cal_L' onClick='document.getElementById(\"Plugin_215_enable_cal_dry\").checked = false;document.getElementById(\"Plugin_215_enable_cal_single\").checked = false;;document.getElementById(\"Plugin_215_enable_cal_H\").checked = false;"), false);
addHtml(F("\n<script type='text/javascript'>document.getElementById(\"Plugin_215_enable_cal_L\").onclick=function() {document.getElementById(\"Plugin_215_enable_cal_dry\").checked = false;document.getElementById(\"Plugin_215_enable_cal_single\").checked = false;;document.getElementById(\"Plugin_215_enable_cal_H\").checked = false;};</script>"));
addFormNumericBox(F("Ref EC"),F("Plugin_215_ref_cal_L"), Settings.TaskDevicePluginConfig[event->TaskIndex][3]);
addUnit("&micro;S");

addRowLabel(F("<strong>High calibration</strong>"));
addFormCheckBox(F("Enable"),F("Plugin_215_enable_cal_H"), false);
addHtml(F("\n<script type='text/javascript'>document.getElementById(\"Plugin_215_enable_cal_H\").onclick=function() {document.getElementById(\"Plugin_215_enable_cal_dry\").checked = false;document.getElementById(\"Plugin_215_enable_cal_single\").checked = false;;document.getElementById(\"Plugin_215_enable_cal_L\").checked = false;};</script>"));
addFormNumericBox(F("Ref EC"),F("Plugin_215_ref_cal_H"), Settings.TaskDevicePluginConfig[event->TaskIndex][4]);
addUnit("&micro;S");

status = _P215_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0], "Cal,?",sensordata);
if (status){
switch (sensordata[5]) {
case '0' :
addFormNote(string,F("<span style='color:red'>Calibration needed</span>"));
addFormNote(F("<span style='color:red'>Calibration needed</span>"));
break;
case '1' :
addFormNote(string,F("<span style='color:green'>Single point calibration ok</span>"));
addFormNote(F("<span style='color:green'>Single point calibration ok</span>"));
break;
case '2' :
addFormNote(string,F("<span style='color:green'>Two points calibration ok</span>"));
addFormNote(F("<span style='color:green'>Two points calibration ok</span>"));
break;
}
}

addFormSubHeader(string, F("Temperature compensation"));
addFormSubHeader(F("Temperature compensation"));
char deviceTemperatureTemplate[40];
LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate));
addFormTextBox(string, F("Temperature "), F("Plugin_215_temperature_template"), deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate));
addFormNote(string, F("You can use a formulae (and idealy refer to a temp sensor). "));
addFormTextBox(F("Temperature "), F("Plugin_215_temperature_template"), deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate));
addFormNote(F("You can use a formulae (and idealy refer to a temp sensor). "));
float value;
string += "<div class='note'>";
char strValue[5];
addHtml(F("<div class='note'>"));
if (Calculate(deviceTemperatureTemplate,&value) == CALCULATE_OK ){
string += "Actual value : ";
string += value;
addHtml(F("Actual value : "));
dtostrf(value,5,2,strValue);
addHtml(strValue);
} else {
string += "(It seems I can't parse your formulae)";
addHtml(F("(It seems I can't parse your formulae)"));
}
string += "</div>";
addHtml(F("</div>"));

success = true;
break;
Expand Down

0 comments on commit 2011abf

Please sign in to comment.