Forráskód Böngészése

Пкеределал конфигурацию.

Vladimir N. Shilov 9 éve
szülő
commit
fc51fdb284
5 módosított fájl, 104 hozzáadás és 113 törlés
  1. 11 0
      README.md
  2. 26 21
      app/configuration.cpp
  3. 28 13
      app/webserver.cpp
  4. 16 24
      include/configuration.h
  5. 23 55
      web/config.html

+ 11 - 0
README.md

@@ -105,3 +105,14 @@ FTP сервер уже влазит, вот только нужен ли он?
 
 UDP Server тоже влез. Если я всё правильно понял, то на строку "get_sensors"
 должен возвращать температуру и влажность. На любые другие данные -- echo.
+
+Переделал конфигурацию -- выбросил всё ненужное, добавил настройку уровней 
+освещённости (два) и ировней яркости индикатора (три). Пока не использую.
+План такой:
+	if (ADCVAL < LLow) {
+		MAX7219br = BLow
+	} else if (ADCVAL > LHigh) {
+		MAX7219br = BHigh
+ 	} else {
+		MAX7219br = BMid
+	}

+ 26 - 21
app/configuration.cpp

@@ -2,17 +2,17 @@
 
 #include <SmingCore/SmingCore.h>
 
-MeteoConfig ActiveConfig;
+ClockConfig ActiveConfig;
 
-MeteoConfig loadConfig()
+ClockConfig loadConfig()
 {
 	DynamicJsonBuffer jsonBuffer;
-	MeteoConfig cfg;
-	if (fileExist(METEO_CONFIG_FILE))
+	ClockConfig cfg;
+	if (fileExist(CLOCK_CONFIG_FILE))
 	{
-		int size = fileGetSize(METEO_CONFIG_FILE);
+		int size = fileGetSize(CLOCK_CONFIG_FILE);
 		char* jsonString = new char[size + 1];
-		fileGetContent(METEO_CONFIG_FILE, jsonString, size + 1);
+		fileGetContent(CLOCK_CONFIG_FILE, jsonString, size + 1);
 		JsonObject& root = jsonBuffer.parseObject(jsonString);
 
 		JsonObject& network = root["network"];
@@ -20,14 +20,16 @@ MeteoConfig loadConfig()
 		cfg.NetworkPassword = String((const char*)network["password"]);
 
 		JsonObject& correction = root["correction"];
-		cfg.AddT = correction["T"];
-		cfg.AddRH = correction["RH"];
 		cfg.AddTZ = correction["TZ"];
 
-		JsonObject& trigger = root["trigger"];
-		cfg.Trigger = (TriggerType)(int)trigger["type"];
-		cfg.RangeMin = trigger["min"];
-		cfg.RangeMax = trigger["max"];
+		JsonObject& light = root["light"];
+		cfg.LightTrhLow = light["low"];
+		cfg.LightTrhLow = light["high"];
+
+		JsonObject& bright = root["bright"];
+		cfg.BrightnessLow = bright["low"];
+		cfg.BrightnessMiddle = bright["mid"];
+		cfg.BrightnessHigh = bright["high"];
 
 		delete[] jsonString;
 	}
@@ -39,7 +41,7 @@ MeteoConfig loadConfig()
 	return cfg;
 }
 
-void saveConfig(MeteoConfig& cfg)
+void saveConfig(ClockConfig& cfg)
 {
 	ActiveConfig = cfg;
 
@@ -53,19 +55,22 @@ void saveConfig(MeteoConfig& cfg)
 
 	JsonObject& correction = jsonBuffer.createObject();
 	root["correction"] = correction;
-	correction["T"] = cfg.AddT;
-	correction["RH"] = cfg.AddRH;
 	correction["TZ"] = cfg.AddTZ;
 
-	JsonObject& trigger = jsonBuffer.createObject();
-	root["trigger"] = trigger;
-	trigger["type"] = (int)cfg.Trigger;
-	trigger["min"] = cfg.RangeMin;
-	trigger["max"] = cfg.RangeMax;
+	JsonObject& light = jsonBuffer.createObject();
+	root["light"] = light;
+	light["low"] = cfg.LightTrhLow;
+	light["high"] = cfg.LightTrhHigh;
+
+	JsonObject& bright = jsonBuffer.createObject();
+	root["bright"] = bright;
+	bright["low"] = cfg.BrightnessLow;
+	bright["mid"] = cfg.BrightnessMiddle;
+	bright["high"] = cfg.BrightnessHigh;
 
 	char buf[3048];
 	root.prettyPrintTo(buf, sizeof(buf));
-	fileSetContent(METEO_CONFIG_FILE, buf);
+	fileSetContent(CLOCK_CONFIG_FILE, buf);
 }
 
 

+ 28 - 13
app/webserver.cpp

@@ -35,7 +35,7 @@ void onIndex(HttpRequest &request, HttpResponse &response)
  */
 void onConfiguration(HttpRequest &request, HttpResponse &response)
 {
-	MeteoConfig cfg = loadConfig();
+	ClockConfig cfg = loadConfig();
 	if (request.getRequestMethod() == RequestMethod::POST)
 	{
 		// Update config
@@ -44,17 +44,32 @@ void onConfiguration(HttpRequest &request, HttpResponse &response)
 			cfg.NetworkSSID = request.getPostParameter("SSID");
 			cfg.NetworkPassword = request.getPostParameter("Password");
 		}
+
 		if (request.getPostParameter("TZ").length() > 0) // Correction
 		{
-			cfg.AddT = request.getPostParameter("T").toFloat();
-			cfg.AddRH = request.getPostParameter("RH").toFloat();
 			cfg.AddTZ = request.getPostParameter("TZ").toFloat();
 		}
-		if (request.getPostParameter("Trigger").length() > 0) // Trigger
+
+		if (request.getPostParameter("BLow").length() > 0) // Low brightness level.
+		{
+			cfg.BrightnessLow = request.getPostParameter("BLow").toInt();
+		}
+		if (request.getPostParameter("BMid").length() > 0) // Middle brightness level.
+		{
+			cfg.BrightnessMiddle = request.getPostParameter("BMid").toInt();
+		}
+		if (request.getPostParameter("BHigh").length() > 0) // High brightness level.
+		{
+			cfg.BrightnessHigh = request.getPostParameter("BHigh").toInt();
+		}
+
+		if (request.getPostParameter("LLow").length() > 0) // Low light level trh.
+		{
+			cfg.LightTrhLow = request.getPostParameter("LLow").toInt();
+		}
+		if (request.getPostParameter("LHigh").length() > 0) // High light level trh.
 		{
-			cfg.Trigger = (TriggerType)request.getPostParameter("Trigger").toInt();
-			cfg.RangeMin = request.getPostParameter("RMin").toFloat();
-			cfg.RangeMax = request.getPostParameter("RMax").toFloat();
+			cfg.LightTrhHigh = request.getPostParameter("LHigh").toInt();
 		}
 		saveConfig(cfg);
 		SystemClock.setTimeZone(cfg.AddTZ);
@@ -64,17 +79,17 @@ void onConfiguration(HttpRequest &request, HttpResponse &response)
 	TemplateFileStream *tmpl = new TemplateFileStream("config.html");
 	auto &vars = tmpl->variables();
 	vars["SSID"] = cfg.NetworkSSID;
-	vars["T"] = String(cfg.AddT, 2);
-	vars["RH"] = String(cfg.AddRH, 2);
 	vars["TZ"] = String(cfg.AddTZ, 2);
-	vars["Trigger"] = String((int)cfg.Trigger);
-	vars["RMin"] = String(cfg.RangeMin, 2);
-	vars["RMax"] = String(cfg.RangeMax, 2);
+	vars["LLow"] = String(cfg.LightTrhLow);
+	vars["LHigh"] = String(cfg.LightTrhHigh);
+	vars["BLow"] = String(cfg.BrightnessLow);
+	vars["BMid"] = String(cfg.BrightnessMiddle);
+	vars["BHigh"] = String(cfg.BrightnessHigh);
 	response.sendTemplate(tmpl);
 }
 
 /*
- * õç.
+ * ðîóòåð
  */
 void onFile(HttpRequest &request, HttpResponse &response)
 {

+ 16 - 24
include/configuration.h

@@ -27,42 +27,34 @@
 #define PIN_SS		12
 
 
-#define METEO_CONFIG_FILE ".meteo.conf" // leading point for security reasons :)
+#define CLOCK_CONFIG_FILE ".clock.conf" // leading point for security reasons :)
 
-enum TriggerType
+struct ClockConfig
 {
-	eTT_None = 0,
-	eTT_Temperature,
-	eTT_Humidity
-};
-
-struct MeteoConfig
-{
-	MeteoConfig()
+	ClockConfig()
 	{
-		AddT = 0;
-		AddRH = 0;
 		AddTZ = 2;
-		Trigger = eTT_Humidity;
-		RangeMin = 30;
-		RangeMax = 50;
+		LightTrhLow = 341;
+		LightTrhHigh = 683;
+		BrightnessLow = 1;
+		BrightnessMiddle = 7;
+		BrightnessHigh = 15;
 	}
 
 	String NetworkSSID;
 	String NetworkPassword;
 
-	float AddT; // Temperature adjustment
-	float AddRH; // Humidity adjustment
 	float AddTZ; // TimeZone - local time offset
-
-	TriggerType Trigger; // Sensor trigger type
-	float RangeMin;
-	float RangeMax;
+	uint16_t LightTrhLow; // Low Light level
+	uint16_t LightTrhHigh; // High Light level
+	int8_t BrightnessLow; // Low LED brightness level
+	int8_t BrightnessMiddle; // Middle LED brightness level
+	int8_t BrightnessHigh; // High LED brightness level
 };
 
-MeteoConfig loadConfig();
-void saveConfig(MeteoConfig& cfg);
+ClockConfig loadConfig();
+void saveConfig(ClockConfig& cfg);
 
-extern MeteoConfig ActiveConfig;
+extern ClockConfig ActiveConfig;
 
 #endif /* INCLUDE_CONFIGURATION_H_ */

+ 23 - 55
web/config.html

@@ -32,7 +32,7 @@
 						<li role="presentation"><a href="/api">API</a></li>
           </ul>
         </nav>
-        <h3 class="text-muted">MeteoControl</h3>
+        <h3 class="text-muted">ClockControl</h3>
       </div>
 	  
 	  <div class="row">
@@ -61,24 +61,38 @@
 			  </div>
 			</div>
 			
-			<!-- Sensor adjustment config -->
+			<!-- Clock config -->
 			<div>
 			  <div class="panel panel-default">
 				<div class="panel-heading">
-				  <h3 class="panel-title">Adjustments and sensor corrections</h3>
+				  <h3 class="panel-title">Clock settings</h3>
 				</div>
 				<div class="panel-body">
 				  <form method="POST">
 					  <div class="form-group">
-						<label for="exampleInputEmail1">Temperature adjustment, &#x00B1; &deg;C</label>
-						<input type="text" name="T" class="form-control" value="{T}">
+						<label>Low light level threshold, 0 &mdash; 1023</label>
+						<input type="text" name="LLow" class="form-control" value="{LLow}">
 					  </div>
 					  <div class="form-group">
-						<label for="exampleInputPassword1">Humidity adjustment, &#x00B1; %</label>
-						<input type="text" name="RH" class="form-control" value="{RH}">
+						<label>High light level threshold, 0 &mdash; 1023</label>
+						<input type="text" name="LHihg" class="form-control" value="{LHihg}">
+					  </div>
+
+					  <div class="form-group">
+						<label>Brightness Low level, 0 &mdash; 15</label>
+						<input type="text" name="BLow" class="form-control" value="{BLow}">
 					  </div>
 					  <div class="form-group">
-						<label for="exampleInputPassword1">Local time, &#x00B1; hours from GMT</label>
+						<label>Brightness Middle level, 0 &mdash; 15</label>
+						<input type="text" name="BMid" class="form-control" value="{BMid}">
+					  </div>
+					  <div class="form-group">
+						<label>Brightness High level, 0 &mdash; 14</label>
+						<input type="text" name="BHigh" class="form-control" value="{BHigh}">
+					  </div>
+
+					  <div class="form-group">
+						<label>Local time, &#x00B1; hours from GMT</label>
 						<input type="text" name="TZ" class="form-control" value="{TZ}">
 					  </div>
 					  <button type="submit" class="btn btn-success">Save correction</button>
@@ -87,53 +101,7 @@
 				</div>
 			  </div>
 			</div>
-			
-			<!-- Trigger config -->
-			<div>
-			  <div class="panel panel-default">
-				<div class="panel-heading">
-				  <h3 class="panel-title">Sensor automatic trigger</h3>
-				</div>
-				<div class="panel-body">
-				  <form method="POST">
-						<div class="form-group">
-							<div class="radio">
-								<label><input type="radio" name="Trigger" value="0">Disabled</label>
-							</div>
-							<div class="radio">
-								<label><input type="radio" name="Trigger" value="1">By Temperature</label>
-							</div>
-							<div class="radio">
-								<label><input type="radio" name="Trigger" value="2">By Humidity</label>
-							</div>
-							<script>$( document ).ready( ($("input:radio[name=Trigger]"))[ {Trigger} ].click() )</script>
-						</div>
-						
-						<fieldset>
-							<legend>Value range</legend>
-							<div class='row'>
-								<div class='col-sm-4'>
-										<div class='form-group'>
-												<label>Minimum</label>
-												<input type="text" name="RMin" class="form-control" value="{RMin}">
-										</div>
-								</div>
-								<div class='col-sm-4'>
-										<div class='form-group'>
-												<label>Maximum</label>
-												<input type="text" name="RMax" class="form-control" value="{RMax}">
-										</div>
-								</div>
-							</div>
-							<span id="helpBlock" class="help-block">* The trigger will fire when the value is less than the minimum or greater than the maximum</span>
-						</fieldset>
-					  <button type="submit" class="btn btn-success">Save trigger</button>
-					  <button type="cancel" class="btn btn-link">Cancel</button>
-					</form>
-				</div>
-			  </div>
-			</div>
-			
+
 		</div>
       </div>