Compare commits
5
Commits
6ae3f5690f
...
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bd0844927 | ||
|
|
b309c0b207 | ||
|
|
767df957cc | ||
|
|
0d6f0b28e2 | ||
|
|
937f7f09e7 |
No files matched your search
+1
-1
@@ -49,7 +49,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="param_block">
|
<div class="param_block">
|
||||||
LDR Schwelle [%]: <output id="out_ldr_shw" class="val_range">50</output> %
|
LDR Schwelle [lx]: <output id="out_ldr_shw" class="val_range">50</output> lx
|
||||||
<div class="slider">
|
<div class="slider">
|
||||||
<input type="range" class="regler" id="range_ldr_shw" data-output="out_ldr_shw" min="0" max="100" value="50">
|
<input type="range" class="regler" id="range_ldr_shw" data-output="out_ldr_shw" min="0" max="100" value="50">
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+34
-2
@@ -34,7 +34,7 @@ function reloadTerminal() {
|
|||||||
const terminal = document.querySelector("#term");
|
const terminal = document.querySelector("#term");
|
||||||
const autoscroll = document.querySelector("#scroll");
|
const autoscroll = document.querySelector("#scroll");
|
||||||
|
|
||||||
fetch(`/terminal`, {
|
fetch('/terminal', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
@@ -52,15 +52,47 @@ function reloadTerminal() {
|
|||||||
.catch(error => console.log('Error:', error));
|
.catch(error => console.log('Error:', error));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function updateParameters() {
|
||||||
|
fetch('/parameters', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
},
|
||||||
|
body: ''
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(json_str => {
|
||||||
|
const active_pwm = Math.round(json_str.active_pwm / 4095 * 100);
|
||||||
|
document.querySelector('#range_act_pwm').value = active_pwm;
|
||||||
|
document.querySelector('#out_act_pwm').value = active_pwm;
|
||||||
|
|
||||||
|
const idle_pwm_max = Math.round(json_str.idle_pwm_max / json_str.active_pwm * 100);
|
||||||
|
document.querySelector('#range_idl_pwm').value = idle_pwm_max;
|
||||||
|
document.querySelector('#out_idl_pwm').value = idle_pwm_max;
|
||||||
|
|
||||||
|
document.querySelector('#range_tim_sta').value = json_str.time_per_stair;
|
||||||
|
document.querySelector('#out_tim_sta').value = json_str.time_per_stair;
|
||||||
|
|
||||||
|
document.querySelector('#range_tim_ldr').value = json_str.time_ldr;
|
||||||
|
document.querySelector('#out_tim_ldr').value = json_str.time_ldr;
|
||||||
|
|
||||||
|
document.querySelector('#range_ldr_shw').value = json_str.ldr_schwelle;
|
||||||
|
document.querySelector('#out_ldr_shw').value = json_str.ldr_schwelle;
|
||||||
|
|
||||||
|
})
|
||||||
|
.catch(error => console.log('Error:', error));
|
||||||
|
};
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
setInterval(reloadTerminal, 1000);
|
setInterval(reloadTerminal, 1000);
|
||||||
setInterval(reloadRangeValues, 1000);
|
setInterval(reloadRangeValues, 1000);
|
||||||
|
|
||||||
|
updateParameters();
|
||||||
|
|
||||||
// use data- attributes for action
|
// use data- attributes for action
|
||||||
document.querySelectorAll('.control').forEach((button) => {
|
document.querySelectorAll('.control').forEach((button) => {
|
||||||
button.onclick = () => {
|
button.onclick = () => {
|
||||||
fetch(`/action`, {
|
fetch('/action', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ void HTTPServer::start_apps() {
|
|||||||
logt("set_time_ldr = %d\n", arg(i).toInt());
|
logt("set_time_ldr = %d\n", arg(i).toInt());
|
||||||
}
|
}
|
||||||
else if (argName(i).equals("range_ldr_shw")) {
|
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());
|
logt("set_ldr_schwelle = %d %\n", arg(i).toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +94,14 @@ void HTTPServer::start_apps() {
|
|||||||
send(202, "text/plain", "");
|
send(202, "text/plain", "");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this->on("/parameters", HTTP_POST, [this]() {
|
||||||
|
logt("got /parameters\n");
|
||||||
|
char json_str[255];
|
||||||
|
treppe->param_to_json(json_str, 255);
|
||||||
|
logt("%s\n", json_str);
|
||||||
|
send(200, "application/json", json_str);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
|
|||||||
+24
-4
@@ -172,8 +172,14 @@ float Treppe::read_ldr() {
|
|||||||
E(LDR) = 6526.5 / (R(LDR)^2)
|
E(LDR) = 6526.5 / (R(LDR)^2)
|
||||||
ldr_value = E(LDR)
|
ldr_value = E(LDR)
|
||||||
*/
|
*/
|
||||||
float ldr_ohm = 37280.00 / analogRead(A0);
|
// float ldr_ohm = 37280.00 / analogRead(A0);
|
||||||
|
float voltage = analogRead(A0) * 0.0036;
|
||||||
|
float ldr_ohm = 40.57 * (3.3 - voltage) / voltage;
|
||||||
float ldr_value = 6526.6 / (ldr_ohm * ldr_ohm);
|
float ldr_value = 6526.6 / (ldr_ohm * ldr_ohm);
|
||||||
|
#ifdef LDRDEBUG
|
||||||
|
Serial.printf("Ohm: %f lux: %f Comp: %d\n", ldr_ohm, ldr_value,
|
||||||
|
param.ldr_schwelle);
|
||||||
|
#endif
|
||||||
return ldr_value;
|
return ldr_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,8 +187,7 @@ bool Treppe::check_ldr() {
|
|||||||
static uint8_t active = 0;
|
static uint8_t active = 0;
|
||||||
|
|
||||||
#ifdef LDRDEBUG
|
#ifdef LDRDEBUG
|
||||||
Serial.printf("R(LDR) = %f kOhm %f lux\n", ldr_value, lux);
|
// return true;
|
||||||
return true;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// follow up: averaging over many samples?
|
// follow up: averaging over many samples?
|
||||||
@@ -267,11 +272,15 @@ void Treppe::task() {
|
|||||||
if (!fsm_pend.anim_beendet) {
|
if (!fsm_pend.anim_beendet) {
|
||||||
fsm_pend.anim_beendet = dimmer_tick(&dimmer_ldr, DIM_LDR);
|
fsm_pend.anim_beendet = dimmer_tick(&dimmer_ldr, DIM_LDR);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fsm_outputs.status == ST_RUHEZUSTAND ||
|
||||||
|
fsm_outputs.status == ST_INAKTIV_LDR) {
|
||||||
if (param_changed) {
|
if (param_changed) {
|
||||||
param_changed = false;
|
param_changed = false;
|
||||||
param = param_pend;
|
param = param_pend;
|
||||||
save_param_to_eeprom();
|
save_param_to_eeprom();
|
||||||
|
Serial.printf("Parameter Change applied!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,9 +382,20 @@ void Treppe::set_ldr_schwelle(const uint16_t value,
|
|||||||
// ?!
|
// ?!
|
||||||
param_pend.ldr_schwelle = 10 * value / 100;
|
param_pend.ldr_schwelle = 10 * value / 100;
|
||||||
} else if (vorgabe_typ == VORGABE_12BIT) {
|
} else if (vorgabe_typ == VORGABE_12BIT) {
|
||||||
// param_pend.ldr_schwelle = value;
|
param_pend.ldr_schwelle = value;
|
||||||
}
|
}
|
||||||
param_changed = true;
|
param_changed = true;
|
||||||
|
|
||||||
Serial.printf("Treppe: ldr_schwelle=%d\n", param_pend.ldr_schwelle);
|
Serial.printf("Treppe: ldr_schwelle=%d\n", param_pend.ldr_schwelle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Treppe::param_to_json(char *json_str, size_t sz) {
|
||||||
|
snprintf(json_str, sz, "{\n\
|
||||||
|
\"time_ldr\": %d,\n\
|
||||||
|
\"time_per_stair\": %d,\n\
|
||||||
|
\"idle_pwm_max\": %d,\n\
|
||||||
|
\"active_pwm\": %d,\n\
|
||||||
|
\"ldr_schwelle\": %d\n}\n",
|
||||||
|
param.time_ldr, param.time_per_stair, param.idle_pwm_max,
|
||||||
|
param.active_pwm, param.ldr_schwelle);
|
||||||
|
}
|
||||||
+4
-2
@@ -6,7 +6,7 @@
|
|||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
|
|
||||||
//#define LDRDEBUG // comment in to override LDR measurement
|
//#define LDRDEBUG // comment in to override LDR measurement
|
||||||
#define LDR_HYS 1 // Hysteresis for switching off FSM [lux]
|
#define LDR_HYS 8 // Hysteresis for switching off FSM [lux]
|
||||||
|
|
||||||
#define SENSOR_OBEN 16
|
#define SENSOR_OBEN 16
|
||||||
#define SENSOR_UNTEN 12
|
#define SENSOR_UNTEN 12
|
||||||
@@ -28,7 +28,7 @@ private:
|
|||||||
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
|
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
|
||||||
uint16_t idle_pwm_max = 100;
|
uint16_t idle_pwm_max = 100;
|
||||||
uint16_t active_pwm = 2000;
|
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;
|
||||||
stairway_param_t param_pend; // zwischenspeicher änderungen
|
stairway_param_t param_pend; // zwischenspeicher änderungen
|
||||||
@@ -105,6 +105,8 @@ public:
|
|||||||
|
|
||||||
// Parameter section
|
// Parameter section
|
||||||
void save_param_to_eeprom();
|
void save_param_to_eeprom();
|
||||||
|
void param_to_json(char* json_str, size_t sz);
|
||||||
|
|
||||||
void set_idle_pwm_max(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
|
void set_idle_pwm_max(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
|
||||||
void set_active_pwm(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
|
void set_active_pwm(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user