-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPage_General.h
145 lines (115 loc) · 4.75 KB
/
Page_General.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//
#pragma once
// HTML PAGE
//
const char PAGE_AdminGeneralSettings[] PROGMEM = R"=====(
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<a href="admin.html" class="btn btn--s"><</a> <strong>General Settings</strong>
<hr>
<form action="" method="post">
<table border="0" cellspacing="0" cellpadding="3" >
<tr>
<td align="right">Name of Device</td>
<td><input type="text" id="devicename" name="devicename" value="" pattern="[a-zA-Z0-9\-]*"></td>
</tr>
<tr>
<td align="left" colspan="2"><hr></td>
</tr>
<tr>
<td align="left" colspan="2">Turn on at</td>
</tr>
<tr>
<td align="right"> Enabled:</td>
<td><input type="checkbox" id="tonenabled" name="tonenabled"></td>
</tr>
<tr>
<td align="right"> Time:</td>
<td><input type="text" id="tonhour" name="tonhour" size="2" value="00">:<input type="text" id="tonminute" name="tonminute" size="2" value="00"></td>
</tr>
<tr>
<td align="left" colspan="2">Turn off at:</td>
<tr>
<td align="right"> Enabled:</td>
<td><input type="checkbox" id="toffenabled" name="toffenabled"></td>
</tr>
<tr>
<td align="right"> Time:</td>
<td><input type="text" id="toffhour" name="toffhour" size="2" value="00">:<input type="text" id="toffminute" name="toffminute" size="2" value="00"></td>
</tr>
<tr><td colspan="2"><hr></span></td></tr>
<tr><td align="right">Firmware:</td><td><span id="x_firmware"></span></td></tr>
<tr><td colspan="2" align="center"><input type="submit" style="width:150px" class="btn btn--m btn--blue" value="Save"></td></tr>
<tr><td colspan="2" align="center"><input type="submit" name="reset" style="width:150px" class="btn btn--m btn--blue" value="FACTORY DEFAULTS"></td></tr>
</table>
</form>
<script>
window.onload = function ()
{
load("style.css","css", function()
{
load("microajax.js","js", function()
{
setValues("/admin/generalvalues");
});
});
}
function load(e,t,n){if("js"==t){var a=document.createElement("script");a.src=e,a.type="text/javascript",a.async=!1,a.onload=function(){n()},document.getElementsByTagName("head")[0].appendChild(a)}else if("css"==t){var a=document.createElement("link");a.href=e,a.rel="stylesheet",a.type="text/css",a.async=!1,a.onload=function(){n()},document.getElementsByTagName("head")[0].appendChild(a)}}
</script>
)=====";
//-------------------------------------------------------------------------------------
// Functions for this Page
void send_devicename_value_html()
{
String values ="";
values += "devicename|" + (String) config.DeviceName + "|div\n";
server.send ( 200, "text/plain", values);
Serial.println(__FUNCTION__);
}
//-------------------------------------------------------------------------------------
void send_general_html()
{
if (server.args() > 0 ) // Save Settings
{
config.AutoTurnOn = false;
config.AutoTurnOff = false;
String temp = "";
for ( uint8_t i = 0; i < server.args(); i++ ) {
if (server.argName(i) == "reset") {
DEBUGGING("\n RESET \n");
EraseConfig();
ESP.restart();
}
}
for ( uint8_t i = 0; i < server.args(); i++ ) {
if (server.argName(i) == "devicename") config.DeviceName = urldecode(server.arg(i));
if (server.argName(i) == "tonenabled") config.AutoTurnOn = true;
if (server.argName(i) == "toffenabled") config.AutoTurnOff = true;
if (server.argName(i) == "tonhour") config.TurnOnHour = server.arg(i).toInt();
if (server.argName(i) == "tonminute") config.TurnOnMinute = server.arg(i).toInt();
if (server.argName(i) == "toffhour") config.TurnOffHour = server.arg(i).toInt();
if (server.argName(i) == "toffminute") config.TurnOffMinute = server.arg(i).toInt();
}
config.Firmware = FIRMWARE;
WriteConfig();
firstStart = true;
}
server.send ( 200, "text/html", PAGE_AdminGeneralSettings );
// Serial.println(__FUNCTION__);
}
//-------------------------------------------------------------------------------------
// server.on ( "/admin/generalvalues", send_general_configuration_values_html);
void send_general_configuration_values_html()
{
String values ="";
values += "devicename|" + (String) config.DeviceName + "|input\n";
values += "tonhour|" + (String) config.TurnOnHour + "|input\n";
values += "tonminute|" + (String) config.TurnOnMinute + "|input\n";
values += "tonenabled|" + (String) (config.AutoTurnOn ? "checked" : "") + "|chk\n";
values += "toffhour|" + (String) config.TurnOffHour + "|input\n";
values += "toffminute|" + (String) config.TurnOffMinute + "|input\n";
values += "toffenabled|" + (String) (config.AutoTurnOff ? "checked" : "") + "|chk\n";
values += "x_firmware|" + (String) config.Firmware + "|div\n";
server.send ( 200, "text/plain", values);
// Serial.println(__FUNCTION__);
}