Explorar el Código

Add bringht control API. Show Luminance in WEB.

Vladimir N. Shilov hace 2 años
padre
commit
6aeebb3537
Se han modificado 5 ficheros con 49 adiciones y 28 borrados
  1. 7 6
      app/led_spi.cpp
  2. 1 1
      app/tm1650.cpp
  3. 37 17
      app/webserver.cpp
  4. 2 2
      web/api.html
  5. 2 2
      web/index.html

+ 7 - 6
app/led_spi.cpp

@@ -1,4 +1,5 @@
 #include "led_spi.h"
+#include "configuration.h"
 #include <HardwarePWM.h>
 
 /* Private defines */
@@ -65,7 +66,7 @@ static led_symb_t led_bufer[LED_NUM] = {sym_Blank, sym_Blank, sym_Blank, sym_Bla
 static Timer ledTimer;
 static uint8_t hw_pwm_pins[1] = {PIN_OUTE};
 static HardwarePWM OE_pwm(hw_pwm_pins, 1);
-static uint32 MaxDuty;
+static uint32 MaxDuty, DutyStep;
 
 /* Private functions */
 void LED_writeData (led_pos_t pos, led_symb_t data) {
@@ -107,12 +108,12 @@ void LED_ShowLed(void) {
 void LED_Init (void) {
   Serial.println("BIG LED SPI init!");
 
-  /* in future, replace by pwm */
 /*  pinMode(PIN_OUTE, OUTPUT);
   PinRes(PIN_OUTE); // output enable
 */
   MaxDuty = OE_pwm.getMaxDuty();
-  LED_SetBright(14);
+  DutyStep = MaxDuty / LedBrightMax;
+  LED_SetBright(LedBrightMiddl);
 
   /* prepare soft spi */
   pinMode(PIN_DOUT, OUTPUT);
@@ -184,9 +185,9 @@ void LED_SemicolonOFF(void) {
  * @param bright Percent value 0..100
  */
 void LED_SetBright(uint8_t bright) {
-  if (bright > 100) { bright = 100;}
-  bright = 100 - bright;
+  if (bright > LedBrightMax) { bright = LedBrightMax;}
+  bright = LedBrightMax - bright;
 
-  uint32 new_duty = MaxDuty * bright / 100;
+  uint32 new_duty = DutyStep * bright; //MaxDuty * bright / LedBrightMax;
   OE_pwm.setDutyChan(0, bright);
 }

+ 1 - 1
app/tm1650.cpp

@@ -35,7 +35,7 @@ void TM1650_Init(void) {
     return;
   }
   isPresent = true;
-  TM1650_Bright(1);
+  TM1650_Bright(LedBrightMiddl);
 }
 
 /**

+ 37 - 17
app/webserver.cpp

@@ -5,6 +5,7 @@ bool serverStarted = false;
 HttpServer server;
 
 extern float SensorT, SensorH, SensorHI, SensorCR;
+extern uint32_t SensorLux;
 extern String StrCF;
 extern time_t NTPLastUpdate;
 
@@ -18,7 +19,7 @@ void onIndex(HttpRequest& request, HttpResponse& response)
   vars["HI"] = String(SensorHI, 0);
   vars["CR"] = String(SensorCR, 0);
   vars["CF"] = StrCF; // это первое место, где оно используется
-  vars["ADC"] = String(system_adc_read ());
+  vars["LUX"] = String(SensorLux, 0);
   vars["VDD"] = String(system_get_vdd33 ());
   vars["LASTNTP"] = String (SystemClock.now () - NTPLastUpdate);
 
@@ -93,12 +94,12 @@ void onConfiguration(HttpRequest& request, HttpResponse& response)
 	TemplateFileStream* tmpl = new TemplateFileStream("config.html");
 	auto& vars = tmpl->variables();
 	vars["SSID"] = cfg.NetworkSSID;
-  vars["TZ"] = String(cfg.AddTZ, 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);
+	vars["TZ"] = String(cfg.AddTZ, 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.sendNamedStream(tmpl);
 }
 
@@ -138,16 +139,35 @@ void onApiSensors(HttpRequest& request, HttpResponse& response)
 	json["status"] = (bool)true;
 	JsonObject sensors = json.createNestedObject("sensors");
 
-  sensors["temperature"] = String(SensorT, 2);
-  sensors["humidity"] = String(SensorH, 2);
-  sensors["heatindex"] = String(SensorHI, 2);
-  sensors["comfortp"] = String(SensorCR, 2);
-  sensors["comforts"] = StrCF.c_str (); //??? второе место
-  sensors["adcvalue"] = String(system_adc_read ());
-  sensors["vddvalue"] = String(system_get_vdd33 ());
-  time_t now = SystemClock.now();
-  sensors["datetime"] = String(now);
-  sensors["lastntp"] = String(now - NTPLastUpdate);
+	sensors["temperature"] = String(SensorT, 2);
+	sensors["humidity"] = String(SensorH, 2);
+	sensors["heatindex"] = String(SensorHI, 2);
+	sensors["comfortp"] = String(SensorCR, 2);
+	sensors["comforts"] = StrCF.c_str (); //??? второе место
+	sensors["luxvalue"] = String(SensorLux, 0);
+	sensors["vddvalue"] = String(system_get_vdd33 ());
+	time_t now = SystemClock.now();
+	sensors["datetime"] = String(now);
+	sensors["lastntp"] = String(now - NTPLastUpdate);
+
+	response.sendDataStream(stream, MIME_JSON);
+}
+
+#include "led_spi.h"
+#include "tm1650.h"
+void onApiControl (HttpRequest &request, HttpResponse &response)
+{
+	int val = request.getQueryParameter ("bright", "-1").toInt ();
+	if (val < LedBrightMin) { val = LedBrightMin; }
+	if (val > LedBrightMax) { val = LedBrightMax; }
+
+	LED_SetBright(val);
+	TM1650_Bright(val);
+
+	JsonObjectStream* stream = new JsonObjectStream();
+	JsonObject json = stream->getRoot();
+
+	json["status"] = val;
 
 	response.sendDataStream(stream, MIME_JSON);
 }

+ 2 - 2
web/api.html

@@ -51,10 +51,10 @@
 						<h3 class="panel-title">Control LED brightnes</h3>
 					</div>
 					<div class="panel-body">
-						<h4>http://{IP}/api/control?bright=15</h4>
+						<h4>http://{IP}/api/control?bright=7</h4>
 						<p>Set LED bright to highest value.</p>
 						
-						<h4>http://{IP}/api/control?bright=1</h4>
+						<h4>http://{IP}/api/control?bright=0</h4>
 						<p>Set LED bright to lowest value.</p>
 					</div>
 				</div>

+ 2 - 2
web/index.html

@@ -83,10 +83,10 @@
 			<div class="col-xs-10 col-md-5">
 				<div class="panel panel-default">
 				<div class="panel-heading">
-					<h3 class="panel-title">ADC Value</h3>
+					<h3 class="panel-title">Luminance</h3>
 				</div>
 				<div class="panel-body">
-					<h1 class="text-center main">{ADC}</h1>
+					<h1 class="text-center main">{LUX} lux</h1>
 				</div>
 				</div>
 			</div>