Compare commits
4
Commits
767df957cc
...
v1.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1686b9ea2a | ||
|
|
8c45c65d00 | ||
|
|
6bd0844927 | ||
|
|
b309c0b207 |
No files matched your search
+1
-1
@@ -51,7 +51,7 @@
|
||||
<div class="param_block">
|
||||
LDR Schwelle [lx]: <output id="out_ldr_shw" class="val_range">50</output> lx
|
||||
<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="1000" value="50">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
+43
-11
@@ -34,33 +34,65 @@ function reloadTerminal() {
|
||||
const terminal = document.querySelector("#term");
|
||||
const autoscroll = document.querySelector("#scroll");
|
||||
|
||||
fetch(`/terminal`, {
|
||||
fetch('/terminal', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: ''
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
if(data.length > 0) {
|
||||
terminal.innerHTML += data;
|
||||
if (autoscroll.checked)
|
||||
terminal.scrollTop = terminal.scrollHeight;
|
||||
}
|
||||
})
|
||||
.catch(error => console.log('Error:', error));
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
if(data.length > 0) {
|
||||
terminal.innerHTML += data;
|
||||
if (autoscroll.checked)
|
||||
terminal.scrollTop = terminal.scrollHeight;
|
||||
}
|
||||
})
|
||||
.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', () => {
|
||||
setInterval(reloadTerminal, 1000);
|
||||
setInterval(reloadRangeValues, 1000);
|
||||
|
||||
updateParameters();
|
||||
|
||||
// use data- attributes for action
|
||||
document.querySelectorAll('.control').forEach((button) => {
|
||||
button.onclick = () => {
|
||||
fetch(`/action`, {
|
||||
fetch('/action', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
|
||||
@@ -94,6 +94,14 @@ void HTTPServer::start_apps() {
|
||||
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>
|
||||
|
||||
+33
-22
@@ -58,7 +58,7 @@ void Treppe::start_animation(dimmer_t *dimmer, bool dim_type, uint16_t on_pwm,
|
||||
dimmer->stufe = stufen - 1;
|
||||
|
||||
dimmer->ticks = param.time_per_stair / INT_TIME; // [ms]
|
||||
} else { // DIM_LDR
|
||||
} else { // DIM_LDR
|
||||
dimmer->ticks = param.time_ldr / INT_TIME; // [ms]
|
||||
}
|
||||
|
||||
@@ -172,23 +172,24 @@ float Treppe::read_ldr() {
|
||||
E(LDR) = 6526.5 / (R(LDR)^2)
|
||||
ldr_value = E(LDR)
|
||||
*/
|
||||
//float ldr_ohm = 37280.00 / analogRead(A0);
|
||||
float voltage = analogRead(A0)*0.0036;
|
||||
float ldr_ohm = 40.57*(3.3-voltage)/voltage;
|
||||
// float ldr_ohm = 37280.00 / analogRead(A0);
|
||||
float vol_adc = analogRead(A0) * 0.0036;
|
||||
if(vol_adc > 3.29)
|
||||
vol_adc = 3.29;
|
||||
|
||||
float ldr_ohm = 40.67 * (3.3 - vol_adc) / vol_adc;
|
||||
|
||||
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
|
||||
#ifdef LDRDEBUG
|
||||
Serial.printf("vol_adc: %f Ohm: %f lux: %f Comp: %d\n", vol_adc, ldr_ohm, ldr_value,
|
||||
param.ldr_schwelle);
|
||||
#endif
|
||||
return ldr_value;
|
||||
}
|
||||
|
||||
bool Treppe::check_ldr() {
|
||||
static uint8_t active = 0;
|
||||
|
||||
#ifdef LDRDEBUG
|
||||
//return true;
|
||||
#endif
|
||||
|
||||
// follow up: averaging over many samples?
|
||||
float ldr = read_ldr();
|
||||
|
||||
@@ -271,17 +272,16 @@ void Treppe::task() {
|
||||
if (!fsm_pend.anim_beendet) {
|
||||
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) {
|
||||
param_changed = false;
|
||||
param = param_pend;
|
||||
save_param_to_eeprom();
|
||||
Serial.printf("Parameter Change applied!\n");
|
||||
}
|
||||
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
|
||||
@@ -321,7 +321,7 @@ void Treppe::setup() {
|
||||
void Treppe::save_param_to_eeprom() {
|
||||
EEPROM.put(EEP_START_ADDR,
|
||||
param); // copy Parameters so "EEPROM"-section in RAM
|
||||
EEPROM.commit(); // write "EEPROM"-section to flash
|
||||
EEPROM.commit(); // write "EEPROM"-section to flash
|
||||
}
|
||||
|
||||
void Treppe::set_idle_pwm_max(const uint16_t value,
|
||||
@@ -382,9 +382,20 @@ 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;
|
||||
|
||||
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
@@ -5,8 +5,8 @@
|
||||
#include "PCA9685.h"
|
||||
#include <EEPROM.h>
|
||||
|
||||
//#define LDRDEBUG // comment in to override LDR measurement
|
||||
#define LDR_HYS 8 // Hysteresis for switching off FSM [lux]
|
||||
#define LDRDEBUG // comment in to override LDR measurement
|
||||
#define LDR_HYS 100 // Hysteresis for switching off FSM [lux]
|
||||
|
||||
#define SENSOR_OBEN 16
|
||||
#define SENSOR_UNTEN 12
|
||||
@@ -105,6 +105,8 @@ public:
|
||||
|
||||
// Parameter section
|
||||
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_active_pwm(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
|
||||
|
||||
|
||||
+14
-11
@@ -19,25 +19,20 @@ platform = espressif8266
|
||||
; board = nodemcuv2
|
||||
board = huzzah
|
||||
framework = arduino
|
||||
|
||||
; for pio check
|
||||
; check_tool = cppcheck
|
||||
check_tool = clangtidy
|
||||
check_flags =
|
||||
; clangtidy: --fix-errors
|
||||
clangtidy: lib/httpserver/* lib/treppe/* lib/PCA9685-Arduino/*
|
||||
check_skip_packages = yes
|
||||
|
||||
; build_unflags = -Os
|
||||
; build_flags = -O2
|
||||
|
||||
board_build.filesystem = littlefs
|
||||
board_build.ldscript = eagle.flash.4m1m.ld
|
||||
extra_scripts = pre:create_gz_files.py
|
||||
monitor_speed = 76800
|
||||
|
||||
[env:serial]
|
||||
extends = env:hardware
|
||||
upload_protocol = esptool
|
||||
upload_speed = 921600
|
||||
upload_port = COM23
|
||||
monitor_port = COM23
|
||||
monitor_speed = 76800
|
||||
|
||||
[env:ota]
|
||||
extends = env:hardware
|
||||
@@ -45,7 +40,7 @@ extends = env:hardware
|
||||
upload_protocol = espota
|
||||
upload_port = <!! IP ADDRESS !!>
|
||||
upload_flags =
|
||||
--port=8266
|
||||
--port=8266
|
||||
--host_port=<!! PORT !!>
|
||||
--auth=admin
|
||||
|
||||
@@ -56,7 +51,15 @@ extends = env:hardware
|
||||
build_flags = -DWITH_DEBUGGING_ON -Os -g3 -ggdb3
|
||||
upload_protocol = esptool
|
||||
upload_speed = 921600
|
||||
upload_port = COM23
|
||||
|
||||
; for pio check
|
||||
; check_tool = cppcheck
|
||||
check_tool = clangtidy
|
||||
check_flags =
|
||||
clangtidy: --fix-errors lib/httpserver/*
|
||||
; clangtidy: lib/httpserver/* lib/treppe/* lib/treppe/FSMTreppe3/* lib/PCA9685-Arduino/*
|
||||
check_skip_packages = yes
|
||||
|
||||
# This file is used compile and run tests located in the `unit` directory.
|
||||
# For more info, see:
|
||||
|
||||
Reference in new issue
Block a user