timers management implemented
This commit is contained in:
parent
4daab54c6f
commit
fd9528d387
|
|
@ -9,6 +9,26 @@
|
||||||
<script src="res/res.js"></script>
|
<script src="res/res.js"></script>
|
||||||
<script src="res/cron.js"></script>
|
<script src="res/cron.js"></script>
|
||||||
<title>~name~</title>
|
<title>~name~</title>
|
||||||
|
<script type="text/javascript">
|
||||||
|
timarr = [
|
||||||
|
~crontmr(0)~,
|
||||||
|
~crontmr(1)~,
|
||||||
|
~crontmr(2)~,
|
||||||
|
~crontmr(3)~,
|
||||||
|
~crontmr(4)~,
|
||||||
|
~crontmr(5)~,
|
||||||
|
~crontmr(6)~,
|
||||||
|
~crontmr(7)~,
|
||||||
|
~crontmr(8)~,
|
||||||
|
~crontmr(9)~,
|
||||||
|
~crontmr(10)~,
|
||||||
|
~crontmr(11)~,
|
||||||
|
~crontmr(12)~,
|
||||||
|
~crontmr(13)~,
|
||||||
|
~crontmr(14)~,
|
||||||
|
~crontmr(15)~
|
||||||
|
];
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script>PageSurround();</script>
|
<script>PageSurround();</script>
|
||||||
|
|
@ -19,11 +39,11 @@
|
||||||
<div class="mlp">
|
<div class="mlp">
|
||||||
<div class="mlpc">
|
<div class="mlpc">
|
||||||
<form name="tmr" method="post">
|
<form name="tmr" method="post">
|
||||||
<div class="mlhdr">TIMER</div>
|
<div class="mlhdr">TIMERS</div>
|
||||||
<button type="button" class ='btn' id='bt2' onclick="addtm()">Add new timer</button>
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div id="timer"></div>
|
<div id="timer"></div>
|
||||||
</div>
|
</div>
|
||||||
|
<button type="button" class ='btn' id='bt2' onclick="addtm()">Add timer</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,7 @@ float:right;
|
||||||
}
|
}
|
||||||
.tmlab{
|
.tmlab{
|
||||||
float:left;
|
float:left;
|
||||||
|
color: var(--accent-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.nowrap
|
.nowrap
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,5 @@
|
||||||
objects_test = ["object_1", "object_2", "object_3", "object_4", "object_5", "object_6", "object_7", "object_8", "object_9", "object_10", "object_11", "object_12", "object_13", "object_14", "object_15", "object_16"];
|
objects_dscr = ["object_1", "object_2", "object_3", "object_4", "object_5", "object_6", "object_7", "object_8", "object_9", "object_10", "object_11", "object_12", "object_13", "object_14", "object_15", "object_16"];
|
||||||
actions_test = ["action_1", "action_2", "action_3", "action_4"];
|
actions_dscr = ["action_1", "action_2", "action_3", "action_4"];
|
||||||
timarr = [
|
|
||||||
~crontmr(0)~,
|
|
||||||
~crontmr(1)~,
|
|
||||||
~crontmr(2)~,
|
|
||||||
~crontmr(3)~,
|
|
||||||
~crontmr(4)~,
|
|
||||||
~crontmr(5)~,
|
|
||||||
~crontmr(6)~,
|
|
||||||
~crontmr(7)~,
|
|
||||||
~crontmr(8)~,
|
|
||||||
~crontmr(9)~,
|
|
||||||
~crontmr(10)~,
|
|
||||||
~crontmr(11)~,
|
|
||||||
~crontmr(12)~,
|
|
||||||
~crontmr(13)~,
|
|
||||||
~crontmr(14)~,
|
|
||||||
~crontmr(15)~
|
|
||||||
];
|
|
||||||
|
|
||||||
timarr_test = [
|
|
||||||
{ "num": 1, "enab":1, "name":"Timer1 name", "obj": 2, "act": 0, "cron": "*/2 * * * * *" },
|
|
||||||
{ "num": 2, "enab":0, "name":"Timer2 name", "obj": 12, "act": 1, "cron": "6 0 12 * * *" },
|
|
||||||
{ "num": 3, "enab":1, "name":"Timer3 name", "obj": 8, "act": 0, "cron": "* * * * * *" }
|
|
||||||
];
|
|
||||||
|
|
||||||
function PostData(data,page,conf,alrt,reld) {
|
function PostData(data,page,conf,alrt,reld) {
|
||||||
if(conf){if (!confirm(conf)) return;}
|
if(conf){if (!confirm(conf)) return;}
|
||||||
|
|
@ -49,9 +25,12 @@ payload += "}";
|
||||||
console.log(payload);
|
console.log(payload);
|
||||||
PostData(payload, "application.html", false, false, true);
|
PostData(payload, "application.html", false, false, true);
|
||||||
}
|
}
|
||||||
|
function deltm(n) {
|
||||||
function extractSelectArr(select)
|
if(confirm("Confirm delete timer "+n+"?") == true){
|
||||||
{
|
PostData("deltimer="+n, "application.html", false, false, true);}}
|
||||||
|
function addtm() {
|
||||||
|
PostData("addtimer=any", "application.html", false, false, true);}
|
||||||
|
function extractSelectArr(select){
|
||||||
var result = [];
|
var result = [];
|
||||||
var options = select && select.options;
|
var options = select && select.options;
|
||||||
var opt;
|
var opt;
|
||||||
|
|
@ -94,8 +73,7 @@ function extractSelectArr(select)
|
||||||
}
|
}
|
||||||
return grouped;
|
return grouped;
|
||||||
}
|
}
|
||||||
function handleSelect(tnum, type)
|
function handleSelect(tnum, type){
|
||||||
{
|
|
||||||
var cinp = document.getElementById("cron" + tnum);
|
var cinp = document.getElementById("cron" + tnum);
|
||||||
var c = (cinp.value).split(" ");
|
var c = (cinp.value).split(" ");
|
||||||
if(c.length != 6)
|
if(c.length != 6)
|
||||||
|
|
@ -132,11 +110,7 @@ function handleSelect(tnum, type)
|
||||||
}
|
}
|
||||||
cinp.value = c[0] + " " + c[1] + " " + c[2] + " " + c[3] + " " + c[4] + " " + c[5];
|
cinp.value = c[0] + " " + c[1] + " " + c[2] + " " + c[3] + " " + c[4] + " " + c[5];
|
||||||
}
|
}
|
||||||
function deltm(n) {
|
|
||||||
if(confirm("Confirm delete timer "+n+"?") == true){
|
|
||||||
timarr_test.splice(n - 1, 1);
|
|
||||||
drawtimers(timarr_test);}
|
|
||||||
}
|
|
||||||
function setcron(n) {
|
function setcron(n) {
|
||||||
var target = document.getElementById("cronext" + n);
|
var target = document.getElementById("cronext" + n);
|
||||||
var content = "";
|
var content = "";
|
||||||
|
|
@ -228,6 +202,7 @@ function drawtimers(tarr) {
|
||||||
var target = document.getElementById("timer");
|
var target = document.getElementById("timer");
|
||||||
var content = "";
|
var content = "";
|
||||||
for (i = 1; i <= num; i++) {
|
for (i = 1; i <= num; i++) {
|
||||||
|
if(tarr[i-1].del == 1) continue;
|
||||||
content += ("<div class=\"timer\">");
|
content += ("<div class=\"timer\">");
|
||||||
content += ("<label class=\"tmlab\">Timer " + i + "</label>");
|
content += ("<label class=\"tmlab\">Timer " + i + "</label>");
|
||||||
content += ("<div class=\"timerrec\">");
|
content += ("<div class=\"timerrec\">");
|
||||||
|
|
@ -244,17 +219,17 @@ function drawtimers(tarr) {
|
||||||
content += ("<div class=\"nowrap\">");
|
content += ("<div class=\"nowrap\">");
|
||||||
content +=("<div><label for=\"object"+i+"\">Object:</label>");
|
content +=("<div><label for=\"object"+i+"\">Object:</label>");
|
||||||
content += ("<select class=\"\" id=\"object"+i+"\">");
|
content += ("<select class=\"\" id=\"object"+i+"\">");
|
||||||
for (k = 0; k < objects_test.length; k++) {
|
for (k = 0; k < objects_dscr.length; k++) {
|
||||||
var selected = (tarr[i - 1].obj == k) ? "selected" : "";
|
var selected = (tarr[i - 1].obj == k) ? "selected" : "";
|
||||||
content += ("<option value=\"" + (k) + "\" " + selected + ">" + objects_test[k] + "</option>");}
|
content += ("<option value=\"" + (k) + "\" " + selected + ">" + objects_dscr[k] + "</option>");}
|
||||||
content += ("</select></div></div>");
|
content += ("</select></div></div>");
|
||||||
|
|
||||||
content += ("<div class=\"nowrap\">");
|
content += ("<div class=\"nowrap\">");
|
||||||
content +=("<div><label for=\"action"+i+"\">Action:</label>");
|
content +=("<div><label for=\"action"+i+"\">Action:</label>");
|
||||||
content += ("<select class=\"\" id=\"action"+i+"\">");
|
content += ("<select class=\"\" id=\"action"+i+"\">");
|
||||||
for (k = 0; k < actions_test.length; k++) {
|
for (k = 0; k < actions_dscr.length; k++) {
|
||||||
var selected = (tarr[i - 1].act == k) ? "selected" : "";
|
var selected = (tarr[i - 1].act == k) ? "selected" : "";
|
||||||
content += ("<option value=\"" + (k) + "\" " + selected + ">" + actions_test[k] + "</option>");}
|
content += ("<option value=\"" + (k) + "\" " + selected + ">" + actions_dscr[k] + "</option>");}
|
||||||
content += ("</select></div></div>");
|
content += ("</select></div></div>");
|
||||||
|
|
||||||
content += ("<div class=\"nowrap\">");
|
content += ("<div class=\"nowrap\">");
|
||||||
|
|
@ -272,11 +247,4 @@ function drawtimers(tarr) {
|
||||||
}
|
}
|
||||||
target.innerHTML = content;
|
target.innerHTML = content;
|
||||||
}
|
}
|
||||||
function applytm() {
|
|
||||||
|
|
||||||
}
|
|
||||||
function addtm() {
|
|
||||||
var num = timarr_test.length + 1;
|
|
||||||
timarr_test.push({ 'num': num, 'enab':1, 'name':'Timer'+num+' name', 'obj': 0, 'act': 0, 'cron': '* * * * * *' });
|
|
||||||
drawtimers(timarr_test);
|
|
||||||
}
|
|
||||||
|
|
@ -51,6 +51,7 @@ typedef struct
|
||||||
int obj;
|
int obj;
|
||||||
int act;
|
int act;
|
||||||
char cron[TIMER_CRONSTRING_LENGTH];
|
char cron[TIMER_CRONSTRING_LENGTH];
|
||||||
|
bool del;
|
||||||
} cron_timer_t;
|
} cron_timer_t;
|
||||||
|
|
||||||
typedef struct appconf
|
typedef struct appconf
|
||||||
|
|
|
||||||
|
|
@ -116,11 +116,12 @@ void ResetAppConfig(APP_CONFIG *Conf)
|
||||||
for (int i = 0; i < CRON_TIMERS_NUMBER; i++ )
|
for (int i = 0; i < CRON_TIMERS_NUMBER; i++ )
|
||||||
{
|
{
|
||||||
GetAppConf()->Timers[i].num = i+1;
|
GetAppConf()->Timers[i].num = i+1;
|
||||||
GetAppConf()->Timers[i].enab = false;
|
GetAppConf()->Timers[i].enab = true;
|
||||||
GetAppConf()->Timers[i].obj = 0;
|
GetAppConf()->Timers[i].obj = 0;
|
||||||
GetAppConf()->Timers[i].act = 0;
|
GetAppConf()->Timers[i].act = 0;
|
||||||
strcpy(GetAppConf()->Timers[i].name, "Timer Name");
|
strcpy(GetAppConf()->Timers[i].name, "Timer Name");
|
||||||
strcpy(GetAppConf()->Timers[i].cron, "* * * * * *");
|
strcpy(GetAppConf()->Timers[i].cron, "* * * * * *");
|
||||||
|
GetAppConf()->Timers[i].del = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,10 +70,34 @@ static HTTP_IO_RESULT HTTPPostApplication(httpd_req_t *req, char *PostData)
|
||||||
T.obj = jRead_int(tmp, "{'obj'", NULL);
|
T.obj = jRead_int(tmp, "{'obj'", NULL);
|
||||||
T.act = jRead_int(tmp, "{'act'", NULL);
|
T.act = jRead_int(tmp, "{'act'", NULL);
|
||||||
jRead_string(tmp, "{'cron'", T.cron, sizeof(T.cron), NULL);
|
jRead_string(tmp, "{'cron'", T.cron, sizeof(T.cron), NULL);
|
||||||
|
T.del = jRead_int(tmp, "{'del'", NULL);
|
||||||
memcpy(&GetAppConf()->Timers[T.num-1], &T, sizeof(cron_timer_t));
|
memcpy(&GetAppConf()->Timers[T.num-1], &T, sizeof(cron_timer_t));
|
||||||
WriteNVSAppConfig(GetAppConf());
|
WriteNVSAppConfig(GetAppConf());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (httpd_query_key_value(PostData, "deltimer", tmp, sizeof(tmp)) == ESP_OK)
|
||||||
|
{
|
||||||
|
int num = (atoi(tmp) - 1);
|
||||||
|
if(num >= 0 && num <16)
|
||||||
|
{
|
||||||
|
GetAppConf()->Timers[num].del = true;
|
||||||
|
}
|
||||||
|
return HTTP_IO_DONE;
|
||||||
|
}
|
||||||
|
if (httpd_query_key_value(PostData, "addtimer", tmp, sizeof(tmp)) == ESP_OK)
|
||||||
|
{
|
||||||
|
for(int i = 0; i< CRON_TIMERS_NUMBER; i++)
|
||||||
|
{
|
||||||
|
if(GetAppConf()->Timers[i].del == 1)
|
||||||
|
{
|
||||||
|
GetAppConf()->Timers[i].del = 0;
|
||||||
|
|
||||||
|
return HTTP_IO_DONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return HTTP_IO_DONE;
|
return HTTP_IO_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ static void HTTPPrint_crontmr(char *VarData, void *arg)
|
||||||
jwObj_int("obj", (unsigned int) T.obj);
|
jwObj_int("obj", (unsigned int) T.obj);
|
||||||
jwObj_int("act", (unsigned int) T.act);
|
jwObj_int("act", (unsigned int) T.act);
|
||||||
jwObj_string("cron", T.cron);
|
jwObj_string("cron", T.cron);
|
||||||
|
jwObj_int("del", (T.del)?1:0);
|
||||||
jwEnd();
|
jwEnd();
|
||||||
jwClose();
|
jwClose();
|
||||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", data);
|
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", data);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user