diff --git a/HTML/application.html b/HTML/application.html index d33d39d..5f00fbc 100644 --- a/HTML/application.html +++ b/HTML/application.html @@ -9,6 +9,26 @@ ~name~ + @@ -19,11 +39,11 @@
-
TIMER
- +
TIMERS
+
diff --git a/HTML/res/appstyles.css b/HTML/res/appstyles.css index 8a32b2d..9f182a9 100644 --- a/HTML/res/appstyles.css +++ b/HTML/res/appstyles.css @@ -176,6 +176,7 @@ float:right; } .tmlab{ float:left; +color: var(--accent-color); } .nowrap diff --git a/HTML/res/cron.js b/HTML/res/cron.js index 6fd1c72..60bd0f7 100644 --- a/HTML/res/cron.js +++ b/HTML/res/cron.js @@ -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"]; -actions_test = ["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": "* * * * * *" } -]; +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_dscr = ["action_1", "action_2", "action_3", "action_4"]; function PostData(data,page,conf,alrt,reld) { if(conf){if (!confirm(conf)) return;} @@ -49,9 +25,12 @@ payload += "}"; console.log(payload); PostData(payload, "application.html", false, false, true); } - -function extractSelectArr(select) -{ +function deltm(n) { + 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 options = select && select.options; var opt; @@ -94,8 +73,7 @@ function extractSelectArr(select) } return grouped; } -function handleSelect(tnum, type) -{ +function handleSelect(tnum, type){ var cinp = document.getElementById("cron" + tnum); var c = (cinp.value).split(" "); 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]; } -function deltm(n) { - if(confirm("Confirm delete timer "+n+"?") == true){ - timarr_test.splice(n - 1, 1); - drawtimers(timarr_test);} -} + function setcron(n) { var target = document.getElementById("cronext" + n); var content = ""; @@ -228,6 +202,7 @@ function drawtimers(tarr) { var target = document.getElementById("timer"); var content = ""; for (i = 1; i <= num; i++) { + if(tarr[i-1].del == 1) continue; content += ("
"); content += (""); content += ("
"); @@ -244,17 +219,17 @@ function drawtimers(tarr) { content += ("
"); content +=("
"); content += ("
"); content += ("
"); content +=("
"); content += ("
"); content += ("
"); @@ -272,11 +247,4 @@ function drawtimers(tarr) { } 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); -} \ No newline at end of file diff --git a/main/include/AppConfiguration.h b/main/include/AppConfiguration.h index f6965dc..2e66c95 100644 --- a/main/include/AppConfiguration.h +++ b/main/include/AppConfiguration.h @@ -51,6 +51,7 @@ typedef struct int obj; int act; char cron[TIMER_CRONSTRING_LENGTH]; + bool del; } cron_timer_t; typedef struct appconf diff --git a/main/src/AppConfiguration.c b/main/src/AppConfiguration.c index bee4119..48de8f3 100644 --- a/main/src/AppConfiguration.c +++ b/main/src/AppConfiguration.c @@ -116,11 +116,12 @@ void ResetAppConfig(APP_CONFIG *Conf) for (int i = 0; i < CRON_TIMERS_NUMBER; i++ ) { GetAppConf()->Timers[i].num = i+1; - GetAppConf()->Timers[i].enab = false; + GetAppConf()->Timers[i].enab = true; GetAppConf()->Timers[i].obj = 0; GetAppConf()->Timers[i].act = 0; strcpy(GetAppConf()->Timers[i].name, "Timer Name"); strcpy(GetAppConf()->Timers[i].cron, "* * * * * *"); + GetAppConf()->Timers[i].del = true; } } diff --git a/main/src/HTTPPostCustom.c b/main/src/HTTPPostCustom.c index 7ef3976..db13048 100644 --- a/main/src/HTTPPostCustom.c +++ b/main/src/HTTPPostCustom.c @@ -70,10 +70,34 @@ static HTTP_IO_RESULT HTTPPostApplication(httpd_req_t *req, char *PostData) T.obj = jRead_int(tmp, "{'obj'", NULL); T.act = jRead_int(tmp, "{'act'", 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)); 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; } diff --git a/main/src/HTTPPrintCustom.c b/main/src/HTTPPrintCustom.c index 8fab5ee..ad2aee7 100644 --- a/main/src/HTTPPrintCustom.c +++ b/main/src/HTTPPrintCustom.c @@ -39,6 +39,7 @@ static void HTTPPrint_crontmr(char *VarData, void *arg) jwObj_int("obj", (unsigned int) T.obj); jwObj_int("act", (unsigned int) T.act); jwObj_string("cron", T.cron); + jwObj_int("del", (T.del)?1:0); jwEnd(); jwClose(); snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", data);