<div class="param_block"> | <div class="param_block"> | ||||
Active Brightness: <output id="out_act_pwm" class="val_range">50</output> % | Active Brightness: <output id="out_act_pwm" class="val_range">50</output> % | ||||
<div class="slider"> | <div class="slider"> | ||||
<input type="range" class="regler" id="range_act_pwm" min="0" max="100" value="50" | |||||
oninput="amount1.value=helligkeit.value"> | |||||
<input type="range" class="regler" id="range_act_pwm" min="0" max="100" value="50"> | |||||
</div> | </div> | ||||
</div> | </div> | ||||
<div class="param_block"> | <div class="param_block"> | ||||
Idle Brightness: <output id="out_idl_pwm" class="val_range">50</output> % | Idle Brightness: <output id="out_idl_pwm" class="val_range">50</output> % | ||||
<div class="slider"> | <div class="slider"> | ||||
<input type="range" class="regler" id="range_idl_pwm" min="0" max="100" value="50" | |||||
oninput="amount2.value=helligkeit_dunkel.value"> | |||||
<input type="range" class="regler" id="range_idl_pwm" min="0" max="100" value="50"> | |||||
</div> | </div> | ||||
</div> | </div> | ||||
Time per stair: <output id="out_tim_sta" class="val_range">50</output> % | Time per stair: <output id="out_tim_sta" class="val_range">50</output> % | ||||
<div class="slider"> | <div class="slider"> | ||||
<input type="range" class="regler" id="range_tim_sta" min="0" max="100" value="50" | |||||
oninput="amount3.value=geschwindigkeit.value"> | |||||
<input type="range" class="regler" id="range_tim_sta" min="0" max="100" value="50"> | |||||
</div> | </div> | ||||
</div> | </div> | ||||
<div class="param_block"> | <div class="param_block"> | ||||
On Time: <output id="out_tim_on" class="val_range">50</output> % | On Time: <output id="out_tim_on" class="val_range">50</output> % | ||||
<div class="slider"> | <div class="slider"> | ||||
<input type="range" class="regler" id="range_tim_on" min="0" max="100" value="50" | |||||
oninput="amount4.value=time.value"> | |||||
<input type="range" class="regler" id="range_tim_on" min="0" max="100" value="50"> | |||||
</div> | </div> | ||||
</div> | </div> |
let params = []; | let params = []; | ||||
for(let p in rangeValues) | for(let p in rangeValues) | ||||
params.push(encodeURIComponent(p) + "=" + encodeURIComponent(rangeValues[p])); | params.push(encodeURIComponent(p) + "=" + encodeURIComponent(rangeValues[p])); | ||||
params.join("&"); | |||||
params = params.join("&"); | |||||
xhrUpd.open("POST", url, true); | xhrUpd.open("POST", url, true); | ||||
xhrUpd.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | xhrUpd.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | ||||
xhrUpd.send(params); | xhrUpd.send(params); | ||||
rangeValues = {}; | rangeValues = {}; | ||||
} | } | ||||
setTimeout(reloadRangeValues, 500); | |||||
setTimeout(reloadRangeValues, 1000); | |||||
}; | }; | ||||
reloadRangeValues(); | reloadRangeValues(); | ||||
// application handler | // application handler | ||||
this->on("/update", HTTP_POST, [this]() { | this->on("/update", HTTP_POST, [this]() { | ||||
// Serial.printf("got /update with args()=%d\n", args()); | |||||
for(int i=0; i<args(); i++) { | |||||
Serial.printf("%s=%s\n", argName(i).c_str(), arg(i).c_str()); | |||||
if(args()) { | |||||
for(int i=0; i<args()-1; i++) { | |||||
Serial.printf("%s=%s\n", argName(i).c_str(), arg(i).c_str()); | |||||
if(argName(i).equals("range_idl_pwm")) { | |||||
treppe->set_idle_prozent(arg(i).toInt()); | |||||
} | |||||
} | |||||
} | } | ||||
send(200, "text/plain", "accepted"); | send(200, "text/plain", "accepted"); | ||||
}); | }); |
#include <ESP8266WebServer.h> | #include <ESP8266WebServer.h> | ||||
#include <stdarg.h> | #include <stdarg.h> | ||||
#include "filesys.h" | #include "filesys.h" | ||||
#include "treppe.h" | |||||
// debug log <ESP8266WebServer.h> | // debug log <ESP8266WebServer.h> | ||||
// #define DEBUGV(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0) | // #define DEBUGV(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0) | ||||
void listRoot() { | void listRoot() { | ||||
ls(rootDir); | ls(rootDir); | ||||
} | } | ||||
Treppe* treppe; | |||||
public: | public: | ||||
HTTPServer(const int _port, const char* _rootDir) : | |||||
ESP8266WebServer(_port), rootDir(_rootDir) | |||||
HTTPServer(const int _port, const char* _rootDir, Treppe* _treppe) : | |||||
ESP8266WebServer(_port), rootDir(_rootDir), treppe(_treppe) | |||||
{ } | { } | ||||
~HTTPServer() | ~HTTPServer() | ||||
{ | { |
if (fsm_outputs.status > ST_RUHEZUSTAND) | if (fsm_outputs.status > ST_RUHEZUSTAND) | ||||
{ | { | ||||
if (anim_beendet == true && | if (anim_beendet == true && | ||||
(fsm_outputs.status == ST_AUFDIMMEN_HOCH || fsm_outputs.status == ST_ABDIMMEN_HOCH || | |||||
fsm_outputs.status == ST_AUFDIMMEN_RUNTER || fsm_outputs.status == ST_ABDIMMEN_RUNTER)) | |||||
(fsm_outputs.status == ST_AUFDIMMEN_HOCH || | |||||
fsm_outputs.status == ST_ABDIMMEN_HOCH || | |||||
fsm_outputs.status == ST_AUFDIMMEN_RUNTER || | |||||
fsm_outputs.status == ST_ABDIMMEN_RUNTER) | |||||
) | |||||
{ | { | ||||
start_animation(); | start_animation(); | ||||
} | } | ||||
void Treppe::berechne_dimmer() | void Treppe::berechne_dimmer() | ||||
{ | { | ||||
ticks_pro_stufe = time_per_stair / INT_TIME; // [ms] | ticks_pro_stufe = time_per_stair / INT_TIME; // [ms] | ||||
differenz_pwm_pro_tick = (float)(active_brightness - idle_brightness) / (float)ticks_pro_stufe; | |||||
differenz_pwm_pro_tick = (float)(active_brightness - idle_bright_internal) / (float)ticks_pro_stufe; | |||||
} | } | ||||
void Treppe::setup() | void Treppe::setup() | ||||
Serial.printf("Treppe: initial parameters: stufen=%d\n", stufen); | Serial.printf("Treppe: initial parameters: stufen=%d\n", stufen); | ||||
} | } | ||||
// ################################################################################################################### | |||||
// GEBUFFERT => Erst im Ruhezustand übernehmen !!!! | |||||
void Treppe::set_idle_prozent(int prozent) { | |||||
uint16_t new_pwm = 0xFFF * prozent / 100; | |||||
set_idle_pwm(new_pwm); | |||||
} | |||||
void Treppe::set_idle_pwm(uint16_t _idle_brightness) | void Treppe::set_idle_pwm(uint16_t _idle_brightness) | ||||
{ | { | ||||
idle_brightness = _idle_brightness; | |||||
if(_idle_brightness > active_brightness) { | |||||
idle_bright_internal = active_brightness; | |||||
} else { | |||||
idle_bright_internal = _idle_brightness; | |||||
} | |||||
Serial.printf("Treppe: idle_bright_internal=%d\n", idle_bright_internal); | |||||
berechne_dimmer(); | berechne_dimmer(); | ||||
Serial.printf("Treppe: idle_brightness=%d\n", idle_brightness); | |||||
pwmController.setAllChannelsPWM(idle_bright_internal); | |||||
} | } | ||||
void Treppe::activate_idle_pwm(bool active) | void Treppe::activate_idle_pwm(bool active) | ||||
{ | { | ||||
static uint8_t former_active = 0; | static uint8_t former_active = 0; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void Treppe::set_active_pwm(uint16_t _active_brightness) | void Treppe::set_active_pwm(uint16_t _active_brightness) | ||||
{ | { | ||||
active_brightness = _active_brightness; | active_brightness = _active_brightness; |
void task(); // call periodically | void task(); // call periodically | ||||
// Parameter section | // Parameter section | ||||
void set_idle_prozent(int prozent); | |||||
void set_idle_pwm(uint16_t _idle_brightness); | void set_idle_pwm(uint16_t _idle_brightness); | ||||
void activate_idle_pwm(bool active); | void activate_idle_pwm(bool active); | ||||
void set_active_pwm(uint16_t _active_brightness); | void set_active_pwm(uint16_t _active_brightness); |
const char* password = STAPSK; | const char* password = STAPSK; | ||||
// port 80, root directory of server '/' | // port 80, root directory of server '/' | ||||
HTTPServer httpServer(80, "/"); | |||||
HTTPServer httpServer(80, "/", &stairs); | |||||
uint32_t _t=0; | uint32_t _t=0; | ||||
#define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("us") | #define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("us") |