dashboard gauge settings wip
This commit is contained in:
parent
a153501e13
commit
84ffd44a5e
4 changed files with 233 additions and 2 deletions
include
|
@ -339,6 +339,7 @@ struct Config_Grow_Dashboard {
|
|||
bool chartConfigured[Max_Dashboard_Chart];
|
||||
byte chartSensor[Max_Dashboard_Chart];
|
||||
byte chartRead[Max_Dashboard_Chart];
|
||||
char chartColor[Max_Dashboard_Chart][7];
|
||||
bool dataConfigured[Max_Sensors];
|
||||
byte dataSensor[Max_Sensors];
|
||||
byte dataRead[Max_Sensors];
|
||||
|
|
|
@ -450,6 +450,8 @@ bool LoadConfig() {
|
|||
config.grow.dashboard.chartSensor[i] = objDashboard["chartSensor"][i];
|
||||
if(objDashboard.containsKey("chartRead"))
|
||||
config.grow.dashboard.chartRead[i] = objDashboard["chartRead"][i];
|
||||
if(objDashboard.containsKey("chartColor"))
|
||||
strlcpy(config.grow.dashboard.chartColor[i], objDashboard["chartColor"][i], sizeof(config.grow.dashboard.chartColor[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -664,6 +666,7 @@ bool SaveConfig(bool writeToSerial = false) {
|
|||
objDashboard["chartConfigured"][i] = config.grow.dashboard.chartConfigured[i];
|
||||
objDashboard["chartSensor"][i] = config.grow.dashboard.chartSensor[i];
|
||||
objDashboard["chartRead"][i] = config.grow.dashboard.chartRead[i];
|
||||
objDashboard["chartColor"][i] = config.grow.dashboard.chartColor[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
/* dirty tmpParam hack again */
|
||||
byte tmpParam_editGaugeId = 255;
|
||||
|
||||
byte tmpParam_editChartId = 255;
|
||||
|
||||
/* subnav processor */
|
||||
const byte WEB_GROW_SUBNAV_GENERAL = 1;
|
||||
|
@ -1010,7 +1010,51 @@ String Proc_WebPage_grow_dashboard(const String& var) {
|
|||
}
|
||||
return html;
|
||||
} else if(var == "TR_TD_CHART") {
|
||||
String html;
|
||||
String html;
|
||||
for(byte i = 0; i < Max_Dashboard_Chart; i++) {
|
||||
if(config.grow.dashboard.chartConfigured[i] == true) {
|
||||
html += F("<tr><td>");
|
||||
html += i;
|
||||
html += F("</td><td>");
|
||||
html += config.system.sensor.name[config.grow.dashboard.chartSensor[i]];
|
||||
html += F("</td><td>");
|
||||
//html += FPSTR(Sensor_Read_descr[SensorIndex[config.system.sensor.type[config.grow.dashboard.gaugeSensor[i]]].read[config.grow.dashboard.gaugeRead[i]]]);
|
||||
/* when RAW convert is set, use this for description. Otherwise use RAW*/
|
||||
if((SensorIndex[config.system.sensor.type[config.grow.dashboard.chartSensor[i]]].read[config.grow.dashboard.chartRead[i]] == SENSOR_READ_TYPE_RAW) && (config.system.sensor.rawConvert[config.grow.dashboard.chartSensor[i]][config.grow.dashboard.chartRead[i]] > 0)) {
|
||||
html += FPSTR(Sensor_Convert_Raw_descr[config.system.sensor.rawConvert[config.grow.dashboard.chartSensor[i]][config.grow.dashboard.chartRead[i]]]);
|
||||
} else {
|
||||
html += FPSTR(Sensor_Read_descr[SensorIndex[config.system.sensor.type[config.grow.dashboard.chartSensor[i]]].read[config.grow.dashboard.chartRead[i]]]);
|
||||
}
|
||||
html += F("</td><td>");
|
||||
// edit button
|
||||
html += F("<form class='linkForm' action='/grow/dashboard/chartAdd' method='get'>");
|
||||
html += F("<input type='hidden' name='edit' value='");
|
||||
html += i;
|
||||
html += F("'>");
|
||||
html += F("<input type='submit' value='✏️' title='Edit'></form> ");
|
||||
// delete button
|
||||
html += F("<form class='linkForm' action='/grow/dashboard/' method='post'>");
|
||||
html += F("<input type='hidden' name='delete_chart' value='");
|
||||
html += i;
|
||||
html += F("'>");
|
||||
html += F("<input type='submit' value='❌' onclick=\"return confirmDelete('");
|
||||
html += F("chart for ");
|
||||
html += config.system.sensor.name[config.grow.dashboard.chartSensor[i]];
|
||||
html += F(" ");
|
||||
|
||||
|
||||
//html += FPSTR(Sensor_Read_descr[SensorIndex[config.system.sensor.type[config.grow.dashboard.gaugeSensor[i]]].read[config.grow.dashboard.gaugeRead[i]]]);
|
||||
/* when RAW convert is set, use this for description. Otherwise use RAW*/
|
||||
if((SensorIndex[config.system.sensor.type[config.grow.dashboard.chartSensor[i]]].read[config.grow.dashboard.chartRead[i]] == SENSOR_READ_TYPE_RAW) && (config.system.sensor.rawConvert[config.grow.dashboard.chartSensor[i]][config.grow.dashboard.chartRead[i]] > 0)) {
|
||||
html += FPSTR(Sensor_Convert_Raw_descr[config.system.sensor.rawConvert[config.grow.dashboard.chartSensor[i]][config.grow.dashboard.chartRead[i]]]);
|
||||
} else {
|
||||
html += FPSTR(Sensor_Read_descr[SensorIndex[config.system.sensor.type[config.grow.dashboard.chartSensor[i]]].read[config.grow.dashboard.chartRead[i]]]);
|
||||
}
|
||||
|
||||
html += F("')\" title='Delete'></form>");
|
||||
html += F("</td></tr>");
|
||||
}
|
||||
}
|
||||
return html;
|
||||
} else if(var == "TR_TD_DATA") {
|
||||
String html;
|
||||
|
@ -1053,6 +1097,21 @@ void WebPage_grow_dashboard(AsyncWebServerRequest *request) {
|
|||
config.grow.dashboard.gaugeConfigured[gaugeId] = false;
|
||||
config.grow.dashboard.gaugeSensor[gaugeId] = 0;
|
||||
config.grow.dashboard.gaugeRead[gaugeId] = 0;
|
||||
config.grow.dashboard.gaugeMin[gaugeId] = 0;
|
||||
config.grow.dashboard.gaugeMax[gaugeId] = 0;
|
||||
|
||||
SaveConfig();
|
||||
Log.notice(F("%s config saved" CR), LogLoc);
|
||||
} else if(request->hasParam("delete_chart", true)) {
|
||||
byte chartId;
|
||||
|
||||
const AsyncWebParameter* param = request->getParam("delete_chart", true);
|
||||
chartId = param->value().toInt();
|
||||
|
||||
// we ensure that every field is empty
|
||||
config.grow.dashboard.chartConfigured[chartId] = false;
|
||||
config.grow.dashboard.chartSensor[chartId] = 0;
|
||||
config.grow.dashboard.chartRead[chartId] = 0;
|
||||
|
||||
SaveConfig();
|
||||
Log.notice(F("%s config saved" CR), LogLoc);
|
||||
|
@ -1210,3 +1269,129 @@ void WebPage_grow_dashboard_gaugeAdd(AsyncWebServerRequest *request) {
|
|||
//request->send_P(200, TEXT_HTML, Page_grow_dashboard_gaugeAdd_HTML, Proc_WebPage_grow_dashboard_gaugeAdd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* grow dashboards chartAdd page
|
||||
*/
|
||||
String Proc_WebPage_grow_dashboard_chartAdd(const String& var) {
|
||||
const static char LogLoc[] PROGMEM = "[Webserver:grow:dashboard:chartAdd(Proc)]";
|
||||
|
||||
if(TestHeaderFooter(var)) {
|
||||
return AddHeaderFooter(var, 1);
|
||||
} else if(Test_WebPage_grow_SUBNAV(var)) {
|
||||
return Proc_WebPage_grow_SUBNAV(var, WEB_GROW_SUBNAV_DASHBOARD);
|
||||
} else if(var == "ACTION") {
|
||||
return FPSTR(Common_HTML_ACTION_ADD);
|
||||
} else if(var == "GAUGE_ID") {
|
||||
return String(Give_Free_Dashboard_ChartId());
|
||||
} else if(var == "SELECT_SENSOR_READ") {
|
||||
String html;
|
||||
html += Html_SelectOpt_Sensor_Read();
|
||||
return html;
|
||||
} else {
|
||||
return String();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String Proc_WebPage_grow_dashboard_chartAddEdit(const String& var) {
|
||||
const static char LogLoc[] PROGMEM = "[Webserver:grow:dashboard:chartAdd(Proc)]";
|
||||
|
||||
if(TestHeaderFooter(var)) {
|
||||
return AddHeaderFooter(var, 1);
|
||||
} else if(Test_WebPage_grow_SUBNAV(var)) {
|
||||
return Proc_WebPage_grow_SUBNAV(var, WEB_GROW_SUBNAV_DASHBOARD);
|
||||
} else if(var == "ACTION") {
|
||||
return FPSTR(Common_HTML_ACTION_ADD);
|
||||
} else if(var == "GAUGE_ID") {
|
||||
return String(tmpParam_editChartId);
|
||||
} else if(var == "SELECT_SENSOR_READ") {
|
||||
String html;
|
||||
html += Html_SelectOpt_Sensor_Read(config.grow.dashboard.chartSensor[tmpParam_editChartId], config.grow.dashboard.chartRead[tmpParam_editChartId]);
|
||||
return html;
|
||||
} else if(var == "SENSOR_ID") {
|
||||
return String(config.grow.dashboard.chartSensor[tmpParam_editChartId]);
|
||||
} else if(var == "READ_ID") {
|
||||
return String(config.grow.dashboard.chartRead[tmpParam_editChartId]);
|
||||
} else if(var == "COLOR") {
|
||||
return String(config.grow.dashboard.chartColor[tmpParam_editChartId]);
|
||||
} else {
|
||||
return String();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String Proc_WebPage_grow_dashboard_chartAdd_POST(const String& var) {
|
||||
/* This is the processor for POST
|
||||
* Its exactly the same, just looking for SAVE_MSG string.
|
||||
* If nothing matches, it calles the main Proc_WebPage_grow()
|
||||
* processor function, so all the other stuff like header and so
|
||||
* on get replaced
|
||||
*/
|
||||
if(var == "SAVE_MSG") {
|
||||
return String(Common_HTML_SAVE_MSG);
|
||||
} else {
|
||||
return Proc_WebPage_grow_dashboard(var);
|
||||
}
|
||||
}
|
||||
|
||||
/* WebPage function */
|
||||
void WebPage_grow_dashboard_chartAdd(AsyncWebServerRequest *request) {
|
||||
const static char LogLoc[] PROGMEM = "[Webserver:grow:dashboard:chartAdd]";
|
||||
|
||||
|
||||
/* Which kind of Request */
|
||||
if(request->method() == HTTP_POST) {
|
||||
byte chartId;
|
||||
|
||||
if(request->hasParam("chartId", true)) {
|
||||
const AsyncWebParameter* param = request->getParam("chartId", true);
|
||||
chartId = param->value().toInt();
|
||||
/* set chartId to configured = true */
|
||||
config.grow.dashboard.chartConfigured[chartId] = true;
|
||||
}
|
||||
|
||||
if(request->hasParam("chartSensor", true)) {
|
||||
const AsyncWebParameter* param = request->getParam("chartSensor", true);
|
||||
config.grow.dashboard.chartSensor[chartId] = param->value().toInt();
|
||||
}
|
||||
|
||||
if(request->hasParam("chartRead", true)) {
|
||||
const AsyncWebParameter* param = request->getParam("chartRead", true);
|
||||
config.grow.dashboard.chartRead[chartId] = param->value().toInt();
|
||||
}
|
||||
|
||||
if(request->hasParam("chartColor", true)) {
|
||||
const AsyncWebParameter* param = request->getParam("chartColor", true);
|
||||
strlcpy(config.grow.dashboard.chartColor[chartId], param->value().c_str(), sizeof(config.grow.dashboard.chartColor[chartId]));
|
||||
}
|
||||
|
||||
|
||||
SaveConfig();
|
||||
request->redirect("/grow/dashboard/?success");
|
||||
//request->send_P(200, TEXT_HTML, Page_grow_dashboard_chartAdd_HTML, Proc_WebPage_grow_dashboard_chartAdd_POST);
|
||||
|
||||
} else {
|
||||
/* GET REQUEST */
|
||||
/* when in edit mode */
|
||||
if(request->hasParam("edit")) {
|
||||
const AsyncWebParameter* param = request->getParam("edit");
|
||||
tmpParam_editChartId = param->value().toInt();
|
||||
request->send_P(200, TEXT_HTML, Page_grow_dashboard_chartAdd_HTML, Proc_WebPage_grow_dashboard_chartAddEdit);
|
||||
/* if we want to add new sensor, check if a sensor id is available. if not send error */
|
||||
} else if(Give_Free_SensorId() > Max_Sensors) {
|
||||
request->send_P(200, TEXT_HTML, Page_grow_dashboard_chartAdd_HTML_NO_ID_AVAILABLE, Proc_WebPage_grow_dashboard_chartAdd);
|
||||
/* Otherwise let the user create new sensor */
|
||||
} else {
|
||||
request->send_P(200, TEXT_HTML, Page_grow_dashboard_chartAdd_HTML, Proc_WebPage_grow_dashboard_chartAdd);
|
||||
}
|
||||
|
||||
//request->send_P(200, TEXT_HTML, Page_grow_dashboard_chartAdd_HTML, Proc_WebPage_grow_dashboard_chartAdd);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,3 +173,45 @@ const char Page_grow_dashboard_gaugeAdd_HTML_NO_ID_AVAILABLE[] PROGMEM = R"(%HEA
|
|||
<h3>You cannot create more gauges, limit reached.</h3>
|
||||
|
||||
%FOOTER% )";
|
||||
|
||||
|
||||
|
||||
|
||||
/* /grow/dashboard/chartAdd page */
|
||||
const char Page_grow_dashboard_chartAdd_HTML[] PROGMEM = R"(%HEADER%
|
||||
%SUBNAV%
|
||||
%SAVE_MSG%
|
||||
|
||||
<h3>%ACTION% Chart ID %GAUGE_ID%</h3>
|
||||
<p>Select which Sensor Reading to use for the chart<br></p>
|
||||
|
||||
<form method='post' action='/grow/dashboard/chartAdd'>
|
||||
<input type='hidden' name='chartId' value='%GAUGE_ID%' />
|
||||
|
||||
<div>
|
||||
<u>Sensor Reading</u>:<br>
|
||||
<input type='hidden' name='chartSensor' value='%SENSOR_ID%' id='chartSensor' />
|
||||
<input type='hidden' name='chartRead' value='%READ_ID%' id='chartRead' />
|
||||
|
||||
<select name='controlBy' id='selSensor' onChange="GrowSelectControlSensorRead('selSensor', 'chartSensor', 'chartRead');" required>
|
||||
<option value='' selected hidden >---</option>
|
||||
%SELECT_SENSOR_READ%
|
||||
</select><br>
|
||||
|
||||
<u>Color</u>:<br>
|
||||
<input type='color' id='chartColor' name='chartColor' value='%COLOR%' required>
|
||||
|
||||
</div>
|
||||
<br>
|
||||
<input type='submit' value='💾 Save settings'>
|
||||
|
||||
%FOOTER% )";
|
||||
|
||||
|
||||
const char Page_grow_dashboard_chartAdd_HTML_NO_ID_AVAILABLE[] PROGMEM = R"(%HEADER%
|
||||
%SUBNAV%
|
||||
%SAVE_MSG%
|
||||
|
||||
<h3>You cannot create more charts, limit reached.</h3>
|
||||
|
||||
%FOOTER% )";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue