From 767df957ccb46c337963aeade926fcc20b825f0c Mon Sep 17 00:00:00 2001 From: bartschdo76253 Date: Sun, 25 Jul 2021 17:38:12 +0200 Subject: [PATCH] ldr schwelle [lx], parameter change when inactive --- data/index.html | 2 +- lib/httpserver/httpserver.cpp | 2 +- lib/treppe/treppe.cpp | 22 +++++++++++++--------- lib/treppe/treppe.h | 6 +++--- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/data/index.html b/data/index.html index caae964..7d87641 100644 --- a/data/index.html +++ b/data/index.html @@ -49,7 +49,7 @@
- LDR Schwelle [%]: 50 % + LDR Schwelle [lx]: 50 lx
diff --git a/lib/httpserver/httpserver.cpp b/lib/httpserver/httpserver.cpp index 925f061..8b6e3b3 100644 --- a/lib/httpserver/httpserver.cpp +++ b/lib/httpserver/httpserver.cpp @@ -76,7 +76,7 @@ void HTTPServer::start_apps() { logt("set_time_ldr = %d\n", arg(i).toInt()); } else if (argName(i).equals("range_ldr_shw")) { - treppe->set_ldr_schwelle(arg(i).toInt(), VORGABE_PROZENT); + treppe->set_ldr_schwelle(arg(i).toInt(), VORGABE_12BIT); logt("set_ldr_schwelle = %d %\n", arg(i).toInt()); } diff --git a/lib/treppe/treppe.cpp b/lib/treppe/treppe.cpp index 0328be8..1634c7e 100644 --- a/lib/treppe/treppe.cpp +++ b/lib/treppe/treppe.cpp @@ -177,7 +177,7 @@ float Treppe::read_ldr() { float ldr_ohm = 40.57*(3.3-voltage)/voltage; float ldr_value = 6526.6 / (ldr_ohm * ldr_ohm); #ifdef LDRDEBUG - Serial.printf("Ohm: %f lux: %f\n", ldr_ohm,ldr_value); + Serial.printf("Ohm: %f lux: %f Comp: %d\n", ldr_ohm,ldr_value, param.ldr_schwelle); #endif return ldr_value; } @@ -186,8 +186,7 @@ bool Treppe::check_ldr() { static uint8_t active = 0; #ifdef LDRDEBUG - Serial.printf("R(LDR) = %f kOhm %f lux\n", ldr_value, lux); - return true; + //return true; #endif // follow up: averaging over many samples? @@ -273,11 +272,16 @@ void Treppe::task() { fsm_pend.anim_beendet = dimmer_tick(&dimmer_ldr, DIM_LDR); } - if (param_changed) { - param_changed = false; - param = param_pend; - save_param_to_eeprom(); - } + } + + if (fsm_outputs.status == ST_RUHEZUSTAND || + fsm_outputs.status == ST_INAKTIV_LDR){ + if (param_changed) { + param_changed = false; + param = param_pend; + save_param_to_eeprom(); + Serial.printf("Parameter Change applied!\n"); + } } #ifdef DEBUG_TIMING @@ -378,7 +382,7 @@ void Treppe::set_ldr_schwelle(const uint16_t value, // ?! param_pend.ldr_schwelle = 10 * value / 100; } else if (vorgabe_typ == VORGABE_12BIT) { - // param_pend.ldr_schwelle = value; + param_pend.ldr_schwelle = value; } param_changed = true; diff --git a/lib/treppe/treppe.h b/lib/treppe/treppe.h index 70389cc..b19f8ef 100644 --- a/lib/treppe/treppe.h +++ b/lib/treppe/treppe.h @@ -5,8 +5,8 @@ #include "PCA9685.h" #include -// #define LDRDEBUG // comment in to override LDR measurement -#define LDR_HYS 5 // Hysteresis for switching off FSM [lux] +//#define LDRDEBUG // comment in to override LDR measurement +#define LDR_HYS 8 // Hysteresis for switching off FSM [lux] #define SENSOR_OBEN 16 #define SENSOR_UNTEN 12 @@ -28,7 +28,7 @@ private: uint16_t time_per_stair = 300; // dimmtime per stair [ms] uint16_t idle_pwm_max = 100; uint16_t active_pwm = 2000; - uint16_t ldr_schwelle = 2; // activation value for FSM [lx] + uint16_t ldr_schwelle = 30; // activation value for FSM [lx] }; stairway_param_t param; stairway_param_t param_pend; // zwischenspeicher änderungen