Compare commits
50
Commits
5e36ef55df
..
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bd0844927 | ||
|
|
b309c0b207 | ||
|
|
767df957cc | ||
|
|
0d6f0b28e2 | ||
|
|
937f7f09e7 | ||
|
|
6ae3f5690f | ||
|
|
7c770a7802 | ||
|
|
6807d0f0af | ||
|
|
770c2436fd | ||
|
|
3145949020 | ||
|
|
ca938ef3dd | ||
|
|
f8fac7acfb | ||
|
|
9ed1b24316 | ||
|
|
125b39a418 | ||
|
|
e47cae30a8 | ||
|
|
b2ff66d44c | ||
|
|
c23b9f2bc6 | ||
|
|
31c268487c | ||
|
|
ad21d73fbb | ||
|
|
42a927e383 | ||
|
|
13db3da082 | ||
|
|
9518c06fd9 | ||
|
|
2820869e14 | ||
|
|
6e810fad59 | ||
|
|
79a9eecaad | ||
|
|
1189b7c3a4 | ||
|
|
7643961ed2 | ||
|
|
6cc52dc460 | ||
|
|
d3ed19e639 | ||
|
|
d55da4e6d7 | ||
|
|
f677f18681 | ||
|
|
f027478e2e | ||
|
|
5986beb10c | ||
|
|
f57e875a17 | ||
|
|
d16f3823b8 | ||
|
|
a5ac7d358b | ||
|
|
0cd46a3c9f | ||
|
|
3a93b8a002 | ||
|
|
0e5085c008 | ||
|
|
7177472ea6 | ||
|
|
03d0cfedd1 | ||
|
|
66d220cdb0 | ||
|
|
2754bd5247 | ||
|
|
f62a18fe66 | ||
|
|
2139ff5943 | ||
|
|
6a04a4d1c9 | ||
|
|
630250da78 | ||
|
|
35ba3e7573 | ||
|
|
53efb0c309 | ||
|
|
c1e24d633b |
No files matched your search
Binary file not shown.
|
Before Width: | Height: | Size: 209 KiB |
+41
-45
@@ -1,67 +1,63 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>ESP8266 Treppenlicht</title>
|
<title>ESP8266 Treppenlicht</title>
|
||||||
<!-- main style sheet -->
|
|
||||||
<link href="/favicon.png" rel="icon" type="image/png" sizes="10x10">
|
<link href="/favicon.png" rel="icon" type="image/png" sizes="10x10">
|
||||||
<link href="/style.css" rel="stylesheet" type="text/css">
|
<link href="/style.css" rel="stylesheet" type="text/css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="kopfzeile" style="text-align: center;">
|
<div class="topbar">Treppenlicht</div>
|
||||||
<b>Treppenlicht</b>
|
|
||||||
|
<div class="param_block">
|
||||||
|
<input type="button" class="control" data-action="s_oben" value="sensor_oben">
|
||||||
|
<input type="button" class="control" data-action="s_unten" value="sensor_unten">
|
||||||
|
<input type="button" class="control" data-action="on_off" value="on_off">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="ueberschrift">
|
<div class="param_block">
|
||||||
Helligkeit
|
Active Brightness: <output id="out_act_pwm" class="val_range">50</output> %
|
||||||
<!--<label id="label_pwm">
|
<div class="slider">
|
||||||
</label>-->
|
<input type="range" class="regler" id="range_act_pwm" data-output="out_act_pwm" min="0" max="100" value="50">
|
||||||
<div class="slider">
|
</div>
|
||||||
<input type="range" class="regler" id="helligkeit" name="rangeInput" min="0" max="100" value="50"
|
|
||||||
oninput="amount1.value=helligkeit.value">
|
|
||||||
<br>
|
|
||||||
<output name="amount1" id="amount1" for="helligkeit">50</output>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="ueberschrift">
|
|
||||||
Helligkeit bei Dunkelheit
|
|
||||||
<!--<label id="label_pwm_dark">
|
|
||||||
</label>-->
|
|
||||||
<div class="slider">
|
|
||||||
<input type="range" class="regler" id="helligkeit_dunkel" name="rangeInput" min="0" max="100" value="50"
|
|
||||||
oninput="amount2.value=helligkeit_dunkel.value">
|
|
||||||
<br>
|
|
||||||
<output name="amount2" id="amount2" for="helligkeit_dunkel">50</output>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="ueberschrift">
|
<div class="param_block">
|
||||||
Laufgeschwindigkeit
|
Idle Brightness Maximum: <output id="out_idl_pwm" class="val_range">50</output> %
|
||||||
<!--<label id="label_geschwindigkeit">
|
<label id="note">[100% == Active Brightness]</label>
|
||||||
</label>-->
|
<div class="slider">
|
||||||
<div class="slider">
|
<input type="range" class="regler" id="range_idl_pwm" data-output="out_idl_pwm" min="0" max="100" value="50">
|
||||||
<input type="range" class="regler" id="geschwindigkeit" name="rangeInput" min="0" max="100" value="50"
|
</div>
|
||||||
oninput="amount3.value=geschwindigkeit.value">
|
<label id="note">idle brightness gets controlled via LDR measurments</label>
|
||||||
<br>
|
|
||||||
<output name="amount3" id="amount3" for="geschwindigkeit">50</output>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="ueberschrift">
|
<div class="param_block">
|
||||||
Licht-An-Zeit
|
Time per stair [ms]: <output id="out_tim_sta" class="val_range">300</output> ms
|
||||||
<!-- <label id="label_time">
|
|
||||||
</label>-->
|
<div class="slider">
|
||||||
<div class="slider">
|
<input type="range" class="regler" id="range_tim_sta" data-output="out_tim_sta" min="0" max="5000" value="300">
|
||||||
<input type="range" class="regler" id="time" name="rangeInput" min="0" max="100" value="50"
|
</div>
|
||||||
oninput="amount4.value=time.value">
|
|
||||||
<br>
|
|
||||||
<output name="amount4" id="amount4" for="time">50</output>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="param_block">
|
||||||
|
Time LDR [ms]: <output id="out_tim_ldr" class="val_range">500</output> ms
|
||||||
|
<div class="slider">
|
||||||
|
<input type="range" class="regler" id="range_tim_ldr" data-output="out_tim_ldr" min="0" max="5000" value="500">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<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">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="terminal">
|
<div class="terminal">
|
||||||
<input type="button" id="clear_term" value="clear" onclick="clearTerminal();">
|
<input type="button" id="clear_term" value="clear">
|
||||||
<input type="checkbox" id="scroll" name="scroll" value="scroll" checked>
|
<input type="checkbox" id="scroll" name="scroll" value="scroll" checked>
|
||||||
<label for="scroll"> autoscroll </label>
|
<label for="scroll"> autoscroll </label>
|
||||||
<textarea id="term">waiting for log messages ... </textarea>
|
<textarea id="term">waiting for log messages ... </textarea>
|
||||||
|
|||||||
+110
-30
@@ -1,40 +1,120 @@
|
|||||||
// var slider = document.getElementById("helligkeit");
|
let rangeValues = {};
|
||||||
// var output = document.getElementById("l_pwm");
|
let xhrUpd = new XMLHttpRequest();
|
||||||
// output.innerHTML = slider.value; // Display the default slider value
|
|
||||||
|
|
||||||
// // Update the current slider value (each time you drag the slider handle)
|
xhrUpd.onreadystatechange = function () {
|
||||||
// slider.oninput = function() {
|
if (xhrUpd.readyState == 4) {
|
||||||
// output.innerHTML = this.value;
|
if (xhrUpd.status == 200) {
|
||||||
// }
|
console.log("xhrUpd: ", xhrUpd.responseText);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let xhr = new XMLHttpRequest();
|
|
||||||
|
|
||||||
xhr.onreadystatechange = function(){
|
|
||||||
if(xhr.readyState == 4) {
|
|
||||||
if (xhr.status == 200){
|
|
||||||
console.log(xhr.responseText);
|
|
||||||
terminal = document.getElementById("term");
|
|
||||||
autoscroll = document.getElementById("scroll");
|
|
||||||
terminal.innerHTML += xhr.responseText;
|
|
||||||
if(autoscroll.checked)
|
|
||||||
terminal.scrollTop = terminal.scrollHeight;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log("status:", xhr.status);
|
console.log("xhrUpd: status=", xhrUpd.status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function reloadTerminal() {
|
function reloadRangeValues() {
|
||||||
xhr.open("POST", "/app=terminal", true);
|
let url = "/update";
|
||||||
xhr.send();
|
// if there are scheduled updates, send them
|
||||||
setTimeout(reloadTerminal, 1000);
|
if (Object.keys(rangeValues).length > 0) {
|
||||||
|
let params = [];
|
||||||
|
for (let p in rangeValues)
|
||||||
|
params.push(encodeURIComponent(p) + "=" + encodeURIComponent(rangeValues[p]));
|
||||||
|
params = params.join("&");
|
||||||
|
|
||||||
|
xhrUpd.open("POST", url, true);
|
||||||
|
xhrUpd.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||||
|
xhrUpd.send(params);
|
||||||
|
|
||||||
|
rangeValues = {};
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
reloadTerminal();
|
function reloadTerminal() {
|
||||||
|
const terminal = document.querySelector("#term");
|
||||||
|
const autoscroll = document.querySelector("#scroll");
|
||||||
|
|
||||||
|
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));
|
||||||
|
};
|
||||||
|
|
||||||
|
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', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
},
|
||||||
|
body: `control=${button.dataset.action}`
|
||||||
|
})
|
||||||
|
.then(response => console.log(response))
|
||||||
|
.catch(error => console.log('Error:', error));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll('.regler').forEach((regler) => {
|
||||||
|
regler.oninput = () => {
|
||||||
|
document.querySelector(`#${regler.dataset.output}`).innerHTML = regler.value;
|
||||||
|
rangeValues[regler.id] = regler.value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelector('#clear_term').onclick = () => {
|
||||||
|
document.querySelector("#term").innerHTML = '';
|
||||||
|
};
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
function clearTerminal() {
|
|
||||||
document.getElementById("term").innerHTML = '';
|
|
||||||
}
|
|
||||||
+44
-32
@@ -1,45 +1,50 @@
|
|||||||
html {
|
html {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
font-family: sans-serif, Arial, Helvetica;
|
font-family: sans-serif, Arial, Helvetica;
|
||||||
background-color: #d4d4d4;
|
background-color: #ffffff;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
/* background-image: url('Background.png'); */
|
|
||||||
background-repeat: repeat;
|
|
||||||
background-size: 150% 150%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
margin: 0 auto;
|
|
||||||
border: none;
|
|
||||||
border-radius: 3;
|
border-radius: 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
.topbar {
|
.topbar {
|
||||||
padding: 1em;
|
padding: 10px;
|
||||||
background-color: #1f1f1f;
|
background-color: #585858;
|
||||||
color: white;
|
color: white;
|
||||||
|
font-size: xx-large;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.param_block{
|
||||||
|
padding: 1em;
|
||||||
|
color: #000000;
|
||||||
|
border: 1px solid darkred;
|
||||||
font-size: x-large;
|
font-size: x-large;
|
||||||
text-align: center;
|
width: 80%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ueberschrift{
|
.val_range {
|
||||||
color: #ffffff;
|
font-weight: bold;
|
||||||
font-size: 50px;
|
|
||||||
width: 100%;
|
|
||||||
text-align: center;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.regler{
|
.regler {
|
||||||
|
/* -webkit-appearance: none; */
|
||||||
-webkit-appearance: none;
|
height: 50px;
|
||||||
height: 30px;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
outline: black;
|
outline: black;
|
||||||
background-color: rgb(176, 188, 228);
|
background-color: rgb(176, 188, 228);
|
||||||
}
|
}
|
||||||
.regler::-webkit-slider-thumb{
|
|
||||||
|
#note {
|
||||||
|
font-size: medium;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* .regler::-webkit-slider-thumb{
|
||||||
-webkit-appearance: none;
|
-webkit-appearance: none;
|
||||||
appearance: none;
|
appearance: none;
|
||||||
width: 5%;
|
width: 5%;
|
||||||
@@ -47,29 +52,21 @@ body {
|
|||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
background-color: rgb(107, 122, 192);
|
background-color: rgb(107, 122, 192);
|
||||||
cursor:pointer;
|
cursor:pointer;
|
||||||
}
|
} */
|
||||||
input[type=range]::-webkit-slider-thumb{
|
/* input[type=range]::-webkit-slider-thumb{
|
||||||
-webkit-appearance: none;
|
-webkit-appearance: none;
|
||||||
border:none;
|
border:none;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
width: 4%;
|
width: 4%;
|
||||||
border-radius: 30px;
|
border-radius: 30px;
|
||||||
}
|
} */
|
||||||
.slider {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.kopfzeile{
|
.slider {
|
||||||
color: #1f1f1f;
|
margin: 1%;
|
||||||
font-size: 50px;
|
|
||||||
width: 100%;
|
|
||||||
background-color: #8d8a8a;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------*/
|
/*-------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/*Switch:
|
/*Switch:
|
||||||
.switch {
|
.switch {
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -120,3 +117,18 @@ input:checked + .slider:before {
|
|||||||
#clear_term {
|
#clear_term {
|
||||||
margin: 2px;
|
margin: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[type="number"] {
|
||||||
|
width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:invalid+span:after {
|
||||||
|
content: '✖';
|
||||||
|
padding-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:valid+span:after {
|
||||||
|
content: '✓';
|
||||||
|
padding-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -97,3 +97,45 @@ new easier script needed to just convert to .gz
|
|||||||
maybe measure timings on ESP
|
maybe measure timings on ESP
|
||||||
|
|
||||||
__=> use serveStatic because way simpler !__
|
__=> use serveStatic because way simpler !__
|
||||||
|
__=> serverStatic("/") works wonders__
|
||||||
|
|
||||||
|
|
||||||
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARHRRHRGH
|
||||||
|
Two implementations of FSM are not that good,
|
||||||
|
linker puts them together ?!?
|
||||||
|
:):):):):):):)
|
||||||
|
=> maybe investigate for doc
|
||||||
|
|
||||||
|
### TODO Treppe
|
||||||
|
- dynamic lighting with ldr
|
||||||
|
- http control over active pwm ... => set_active_pwm()
|
||||||
|
-> is implemntiert, kann mit % oder abs eingestellt werden
|
||||||
|
- testing if dimming crashes when two animations
|
||||||
|
-> ldr does not interrupt animation, animation get's finished and stairs fade out -> FSM works without collisions
|
||||||
|
- interrupt to pending from sensors
|
||||||
|
-> rising edge trigger implemented, via pending input
|
||||||
|
- settings struct
|
||||||
|
-> implemented with EEPROM
|
||||||
|
-> adapted to only change on ruhezustand
|
||||||
|
- script for gdb on windows
|
||||||
|
-> [implemented](start_xtensa_gdb_stub.cmd)
|
||||||
|
- welcome animation ?
|
||||||
|
-> wird hochgedimmt beim einschalten von 0
|
||||||
|
- on/off switch http
|
||||||
|
- use logging to serial http monitor with httpserver.logt()
|
||||||
|
-> is used for some status updates
|
||||||
|
|
||||||
|
- behavior when someone enters stairway from opposite direction while animation is running?
|
||||||
|
-> currently ignored, second persons walks in darkness
|
||||||
|
-> animation from both sides?
|
||||||
|
-> problem: person 1 leaving stairway might pass the sensor right after person 2 -> person 1 leaving not detected
|
||||||
|
|
||||||
|
- behavior when someone enters stairway from opposite direction after animation finished but person 1 is still on stairway?
|
||||||
|
-> currently stairs fade off from direction 1
|
||||||
|
-> additional wait-state between "warten hoch/runter" and "abdimmen hoch/runter" after sensor detected person?
|
||||||
|
|
||||||
|
|
||||||
|
- active brightness can be lower than idle in the moment
|
||||||
|
- change idle to precentage of active !!
|
||||||
|
|
||||||
|
- Webpage needs to load settings from eeprom !!
|
||||||
+4
-1
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#ifndef __OTA_H
|
||||||
|
#define __OTA_H
|
||||||
|
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
@@ -46,3 +47,5 @@ void ota_setup() {
|
|||||||
ArduinoOTA.begin();
|
ArduinoOTA.begin();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // __OTA_H
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
FSInfo fsinfo;
|
FSInfo fsinfo;
|
||||||
|
|
||||||
bool mount_fs() {
|
auto mount_fs() -> bool {
|
||||||
if(!LittleFS.begin()) {
|
if(!LittleFS.begin()) {
|
||||||
Serial.println("[ERROR] LittleFS.info(), reset ...");
|
Serial.println("[ERROR] LittleFS.info(), reset ...");
|
||||||
return false;
|
return false;
|
||||||
@@ -25,7 +25,7 @@ bool mount_fs() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool format_fs() {
|
auto format_fs() -> bool {
|
||||||
printf("Formatting FS ! \n\r");
|
printf("Formatting FS ! \n\r");
|
||||||
return LittleFS.format();
|
return LittleFS.format();
|
||||||
}
|
}
|
||||||
@@ -122,7 +122,3 @@ void deleteFile(const char * path) {
|
|||||||
Serial.println("Delete failed");
|
Serial.println("Delete failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
|
|
||||||
// some usefull wrappers for Filesystem
|
// some usefull wrappers for Filesystem
|
||||||
|
|
||||||
bool mount_fs();
|
bool mount_fs();
|
||||||
bool format_fs();
|
bool format_fs();
|
||||||
|
|
||||||
|
|||||||
+112
-58
@@ -1,68 +1,122 @@
|
|||||||
#include "httpserver.h"
|
#include "httpserver.h"
|
||||||
|
|
||||||
|
auto HTTPServer::start() -> bool {
|
||||||
|
if (!mount_fs()) {
|
||||||
|
logf("cant mount filesystem, EXIT !\n\r");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool HTTPServer::start() {
|
logf("LittleFS mounted !\n\r");
|
||||||
if(!mount_fs()) {
|
logf("root:\n\r");
|
||||||
logf("cant mount filesystem, EXIT !\n\r");
|
this->listRoot();
|
||||||
return false;
|
logf("\n\r");
|
||||||
|
|
||||||
|
// default handler
|
||||||
|
this->onNotFound([this]() {
|
||||||
|
String message = "File Not Found\n\n";
|
||||||
|
message += "URI: ";
|
||||||
|
message += uri();
|
||||||
|
message += "\nMethod: ";
|
||||||
|
message += (method() == HTTP_GET) ? "GET" : "POST";
|
||||||
|
message += "\nArguments: ";
|
||||||
|
message += args();
|
||||||
|
message += "\n";
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < args(); i++) {
|
||||||
|
message += " " + argName(i) + ": " + arg(i) + "\n";
|
||||||
}
|
}
|
||||||
logf("LittleFS mounted !\n\r");
|
send(404, "text/plain", message);
|
||||||
logf("root:\n\r");
|
});
|
||||||
this->listRoot();
|
|
||||||
logf("\n\r");
|
|
||||||
|
|
||||||
// default handler
|
// add static root file handler for http
|
||||||
this->onNotFound([this]() {
|
this->serveStatic("/", LittleFS, "/");
|
||||||
String message = "File Not Found\n\n";
|
this->begin();
|
||||||
message += "URI: ";
|
logf("Server active on Port 80 !\n\r");
|
||||||
message += uri();
|
return true;
|
||||||
message += "\nMethod: ";
|
|
||||||
message += (method() == HTTP_GET) ? "GET" : "POST";
|
|
||||||
message += "\nArguments: ";
|
|
||||||
message += args();
|
|
||||||
message += "\n";
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < args(); i++) {
|
|
||||||
message += " " + argName(i) + ": " + arg(i) + "\n";
|
|
||||||
}
|
|
||||||
send(404, "text/plain", message);
|
|
||||||
});
|
|
||||||
|
|
||||||
// add static root file handler for http
|
|
||||||
this->serveStatic("/", LittleFS, "/");
|
|
||||||
this->begin();
|
|
||||||
Serial.printf("Server active on Port 80 !\n\r");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HTTPServer::logf(const char *format, ...) {
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
char temp[64];
|
|
||||||
size_t len = vsnprintf(temp, sizeof(temp), format, args);
|
|
||||||
Serial.print(log_prefix);
|
|
||||||
Serial.write(temp, len);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HTTPServer::logt(const char *format, ...) {
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
// append logging string to local buffer
|
|
||||||
if(tbuf_head < TBUF_LEN) {
|
|
||||||
size_t len = vsnprintf(tbuf+tbuf_head, TBUF_LEN-tbuf_head, format, args);
|
|
||||||
tbuf_head += len;
|
|
||||||
}
|
|
||||||
va_end(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPServer::start_apps() {
|
void HTTPServer::start_apps() {
|
||||||
// application handler
|
this->on("/action", HTTP_POST, [this]() {
|
||||||
this->on("/app=terminal", HTTP_POST, [this]() {
|
if (args()) {
|
||||||
if(tbuf_head) {
|
logf("%s=%s\n", argName(0).c_str(), arg(0).c_str());
|
||||||
send(200, "text/plain", tbuf);
|
|
||||||
tbuf_head = 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
if (argName(0).equals("control")) {
|
||||||
|
if (arg(0).equals("s_oben")) {
|
||||||
|
treppe->overwrite_sensors(true, false);
|
||||||
|
logt("control => s_oben !\n");
|
||||||
|
}
|
||||||
|
else if (arg(0).equals("s_unten")) {
|
||||||
|
treppe->overwrite_sensors(false, true);
|
||||||
|
logt("control => s_unten !\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
send(200, "text/plain", "accepted");
|
||||||
|
});
|
||||||
|
|
||||||
|
this->on("/update", HTTP_POST, [this]() {
|
||||||
|
if (args()) {
|
||||||
|
for (int i = 0; i < args() - 1; i++) {
|
||||||
|
logf("%s=%s\n", argName(i).c_str(), arg(i).c_str());
|
||||||
|
|
||||||
|
if (argName(i).equals("range_act_pwm")) {
|
||||||
|
treppe->set_active_pwm(arg(i).toInt(), VORGABE_PROZENT);
|
||||||
|
logt("set_active_pwm = %d %\n", arg(i).toInt());
|
||||||
|
}
|
||||||
|
else if (argName(i).equals("range_idl_pwm")) {
|
||||||
|
treppe->set_idle_pwm_max(arg(i).toInt(), VORGABE_PROZENT);
|
||||||
|
logt("set_idle_pwm_max = %d %\n", arg(i).toInt());
|
||||||
|
}
|
||||||
|
else if (argName(i).equals("range_tim_sta")) {
|
||||||
|
treppe->set_time_per_stair(arg(i).toInt());
|
||||||
|
logt("set_time_per_stair = %d\n", arg(i).toInt());
|
||||||
|
}
|
||||||
|
else if (argName(i).equals("range_tim_ldr")) {
|
||||||
|
treppe->set_time_ldr(arg(i).toInt());
|
||||||
|
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_12BIT);
|
||||||
|
logt("set_ldr_schwelle = %d %\n", arg(i).toInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
send(200, "text/plain", "accepted");
|
||||||
|
});
|
||||||
|
|
||||||
|
this->on("/terminal", HTTP_POST, [this]() {
|
||||||
|
// logf("got /terminal\n");
|
||||||
|
if (tbuf_head) {
|
||||||
|
send(200, "text/plain", tbuf);
|
||||||
|
tbuf_head = 0;
|
||||||
|
} else {
|
||||||
|
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>
|
||||||
|
void HTTPServer::logf(const char *format, Args... args) const {
|
||||||
|
Serial.print(log_prefix);
|
||||||
|
Serial.printf(format, args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HTTPServer::logt(const char *format, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
// append logging string to local buffer
|
||||||
|
if (tbuf_head < TBUF_LEN) {
|
||||||
|
tbuf_head +=
|
||||||
|
vsnprintf(tbuf + tbuf_head, TBUF_LEN - tbuf_head, format, args);
|
||||||
|
}
|
||||||
|
va_end(args);
|
||||||
}
|
}
|
||||||
+20
-22
@@ -1,42 +1,40 @@
|
|||||||
|
#ifndef __HTTPSERVER_H
|
||||||
|
#define __HTTPSERVER_H
|
||||||
// Wrapper for ESP8266WebServer with Filesystem as HTTP source
|
// Wrapper for ESP8266WebServer with Filesystem as HTTP source
|
||||||
|
|
||||||
#pragma once
|
#include "filesys.h"
|
||||||
|
#include "treppe.h"
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "filesys.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)
|
||||||
|
|
||||||
#define TBUF_LEN 256
|
#define TBUF_LEN 256
|
||||||
|
|
||||||
|
|
||||||
class HTTPServer : public ESP8266WebServer {
|
class HTTPServer : public ESP8266WebServer {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char* rootDir = "/";
|
const char *rootDir = "/";
|
||||||
const char* log_prefix = "[HTTPServer] ";
|
const char *log_prefix = "[HTTPServer] ";
|
||||||
|
|
||||||
size_t tbuf_head = 0;
|
size_t tbuf_head = 0;
|
||||||
char tbuf[TBUF_LEN];
|
char tbuf[TBUF_LEN];
|
||||||
|
|
||||||
void listRoot() {
|
void listRoot() { ls(rootDir); }
|
||||||
ls(rootDir);
|
Treppe *treppe;
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HTTPServer(const int _port, const char* _rootDir) :
|
HTTPServer(const int _port, const char *_rootDir, Treppe *_treppe)
|
||||||
ESP8266WebServer(_port), rootDir(_rootDir)
|
: ESP8266WebServer(_port), rootDir(_rootDir), treppe(_treppe) {}
|
||||||
{ }
|
~HTTPServer() { Serial.printf("[HTTPServer] shut down ...\n\r"); }
|
||||||
~HTTPServer()
|
|
||||||
{
|
|
||||||
Serial.printf("[HTTPServer] shut down ...\n\r");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool start();
|
bool start();
|
||||||
void start_apps();
|
void start_apps();
|
||||||
|
|
||||||
void logf(const char *format, ...);
|
template <class... Args>
|
||||||
void logt(const char *format, ...);
|
void logf(const char *format, Args... args) const;
|
||||||
|
void logt(const char *format, ...);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif // __HTTPSERVER_H
|
||||||
@@ -7,27 +7,28 @@
|
|||||||
//
|
//
|
||||||
// Code generated for Simulink model 'FSMTreppe'.
|
// Code generated for Simulink model 'FSMTreppe'.
|
||||||
//
|
//
|
||||||
// Model version : 1.29
|
// Model version : 1.51
|
||||||
// Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
|
// Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
|
||||||
// C/C++ source code generated on : Sat Jul 3 17:39:25 2021
|
// C/C++ source code generated on : Wed Jul 7 18:54:01 2021
|
||||||
//
|
//
|
||||||
// Target selection: ert.tlc
|
// Target selection: ert.tlc
|
||||||
// Embedded hardware selection: ARM Compatible->ARM Cortex-M
|
// Embedded hardware selection: ARM Compatible->ARM Cortex-M
|
||||||
// Code generation objectives: Unspecified
|
// Code generation objectives: Unspecified
|
||||||
// Validation result: Not run
|
// Validation result: Not run
|
||||||
//
|
//
|
||||||
#include "FSMTreppe2.h"
|
#include "FSMTreppe3.h"
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
// Named constants for Chart: '<Root>/FSMTreppe'
|
// Named constants for Chart: '<Root>/FSMTreppe'
|
||||||
const uint8_t FSMTreppe_IN_abdimmen_hoch = 1U;
|
const uint32_t FSMTreppe_IN_abdimmen_hoch = 1U;
|
||||||
const uint8_t FSMTreppe_IN_abdimmen_runter = 2U;
|
const uint32_t FSMTreppe_IN_abdimmen_ldr = 2U;
|
||||||
const uint8_t FSMTreppe_IN_aufdimmen_hoch = 3U;
|
const uint32_t FSMTreppe_IN_abdimmen_runter = 3U;
|
||||||
const uint8_t FSMTreppe_IN_aufdimmen_runter = 4U;
|
const uint32_t FSMTreppe_IN_aufdimmen_hoch = 4U;
|
||||||
const uint8_t FSMTreppe_IN_inaktiv = 5U;
|
const uint32_t FSMTreppe_IN_aufdimmen_ldr = 5U;
|
||||||
const uint8_t FSMTreppe_IN_ruhezustand = 6U;
|
const uint32_t FSMTreppe_IN_aufdimmen_runter = 6U;
|
||||||
const uint8_t FSMTreppe_IN_warten_hoch = 7U;
|
const uint32_t FSMTreppe_IN_inaktiv = 7U;
|
||||||
const uint8_t FSMTreppe_IN_warten_runter = 8U;
|
const uint32_t FSMTreppe_IN_ruhezustand = 8U;
|
||||||
|
const uint32_t FSMTreppe_IN_warten_hoch = 9U;
|
||||||
|
const uint32_t FSMTreppe_IN_warten_runter = 10U;
|
||||||
|
|
||||||
// Model step function
|
// Model step function
|
||||||
void FSMTreppeModelClass::step()
|
void FSMTreppeModelClass::step()
|
||||||
@@ -56,13 +57,28 @@ void FSMTreppeModelClass::step()
|
|||||||
FSMTreppe_Y.dimmrichtung = 0U;
|
FSMTreppe_Y.dimmrichtung = 0U;
|
||||||
|
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 4U;
|
FSMTreppe_Y.status = 6U;
|
||||||
if (FSMTreppe_U.anim_beendet || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
if ((FSMTreppe_U.anim_beendet == 1U) || (FSMTreppe_DW.temporalCounter_i1 >=
|
||||||
{
|
500U)) {
|
||||||
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_ruhezustand;
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_ruhezustand;
|
||||||
|
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 1U;
|
FSMTreppe_Y.status = 3U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSMTreppe_IN_abdimmen_ldr:
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 2U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 0U;
|
||||||
|
if ((FSMTreppe_U.anim_beendet == 1U) || (FSMTreppe_DW.temporalCounter_i1 >=
|
||||||
|
500U)) {
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_inaktiv;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 0U;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -71,13 +87,13 @@ void FSMTreppeModelClass::step()
|
|||||||
FSMTreppe_Y.dimmrichtung = 0U;
|
FSMTreppe_Y.dimmrichtung = 0U;
|
||||||
|
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 7U;
|
FSMTreppe_Y.status = 9U;
|
||||||
if (FSMTreppe_U.anim_beendet || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
if ((FSMTreppe_U.anim_beendet == 1U) || (FSMTreppe_DW.temporalCounter_i1 >=
|
||||||
{
|
500U)) {
|
||||||
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_ruhezustand;
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_ruhezustand;
|
||||||
|
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 1U;
|
FSMTreppe_Y.status = 3U;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -89,12 +105,27 @@ void FSMTreppeModelClass::step()
|
|||||||
FSMTreppe_Y.dimmrichtung = 1U;
|
FSMTreppe_Y.dimmrichtung = 1U;
|
||||||
|
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 2U;
|
FSMTreppe_Y.status = 4U;
|
||||||
if (FSMTreppe_U.anim_beendet || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
if ((FSMTreppe_U.anim_beendet == 1U) || (FSMTreppe_DW.temporalCounter_i1 >=
|
||||||
{
|
500U)) {
|
||||||
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_warten_hoch;
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_warten_hoch;
|
||||||
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 5U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSMTreppe_IN_aufdimmen_ldr:
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 1U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 1U;
|
||||||
|
if ((FSMTreppe_U.anim_beendet == 1U) || (FSMTreppe_DW.temporalCounter_i1 >=
|
||||||
|
500U)) {
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_ruhezustand;
|
||||||
|
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 3U;
|
FSMTreppe_Y.status = 3U;
|
||||||
}
|
}
|
||||||
@@ -108,32 +139,36 @@ void FSMTreppeModelClass::step()
|
|||||||
FSMTreppe_Y.dimmrichtung = 1U;
|
FSMTreppe_Y.dimmrichtung = 1U;
|
||||||
|
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 5U;
|
FSMTreppe_Y.status = 7U;
|
||||||
if (FSMTreppe_U.anim_beendet || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
if ((FSMTreppe_U.anim_beendet == 1U) || (FSMTreppe_DW.temporalCounter_i1 >=
|
||||||
{
|
500U)) {
|
||||||
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_warten_runter;
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_warten_runter;
|
||||||
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 6U;
|
FSMTreppe_Y.status = 8U;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FSMTreppe_IN_inaktiv:
|
case FSMTreppe_IN_inaktiv:
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 0U;
|
FSMTreppe_Y.status = 0U;
|
||||||
if (FSMTreppe_U.ldr_schwelle == 1.0) {
|
if (FSMTreppe_U.ldr_schwelle == 1U) {
|
||||||
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_ruhezustand;
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_aufdimmen_ldr;
|
||||||
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 1U;
|
FSMTreppe_Y.status = 1U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 1U;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FSMTreppe_IN_ruhezustand:
|
case FSMTreppe_IN_ruhezustand:
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 1U;
|
FSMTreppe_Y.status = 3U;
|
||||||
if (FSMTreppe_U.sensor_unten) {
|
if (FSMTreppe_U.sensor_unten == 1U) {
|
||||||
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_aufdimmen_hoch;
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_aufdimmen_hoch;
|
||||||
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
@@ -144,8 +179,8 @@ void FSMTreppeModelClass::step()
|
|||||||
FSMTreppe_Y.dimmrichtung = 1U;
|
FSMTreppe_Y.dimmrichtung = 1U;
|
||||||
|
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 2U;
|
FSMTreppe_Y.status = 4U;
|
||||||
} else if (FSMTreppe_U.sensor_oben) {
|
} else if (FSMTreppe_U.sensor_oben == 1U) {
|
||||||
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_aufdimmen_runter;
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_aufdimmen_runter;
|
||||||
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
@@ -156,20 +191,24 @@ void FSMTreppeModelClass::step()
|
|||||||
FSMTreppe_Y.dimmrichtung = 1U;
|
FSMTreppe_Y.dimmrichtung = 1U;
|
||||||
|
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 5U;
|
FSMTreppe_Y.status = 7U;
|
||||||
} else if (FSMTreppe_U.ldr_schwelle == 0.0) {
|
} else if (FSMTreppe_U.ldr_schwelle == 0U) {
|
||||||
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_inaktiv;
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_abdimmen_ldr;
|
||||||
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 0U;
|
FSMTreppe_Y.status = 2U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 0U;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FSMTreppe_IN_warten_hoch:
|
case FSMTreppe_IN_warten_hoch:
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 3U;
|
FSMTreppe_Y.status = 5U;
|
||||||
if (FSMTreppe_U.sensor_oben || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
if ((FSMTreppe_U.sensor_oben == 1U) || (FSMTreppe_DW.temporalCounter_i1 >=
|
||||||
{
|
500U)) {
|
||||||
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_abdimmen_hoch;
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_abdimmen_hoch;
|
||||||
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
@@ -177,16 +216,16 @@ void FSMTreppeModelClass::step()
|
|||||||
FSMTreppe_Y.dimmrichtung = 0U;
|
FSMTreppe_Y.dimmrichtung = 0U;
|
||||||
|
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 4U;
|
FSMTreppe_Y.status = 6U;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
// case IN_warten_runter:
|
// case IN_warten_runter:
|
||||||
FSMTreppe_Y.status = 6U;
|
FSMTreppe_Y.status = 8U;
|
||||||
if (FSMTreppe_U.sensor_unten || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
if ((FSMTreppe_U.sensor_unten == 1U) || (FSMTreppe_DW.temporalCounter_i1 >=
|
||||||
{
|
500U)) {
|
||||||
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_abdimmen_runter;
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_abdimmen_runter;
|
||||||
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
@@ -194,7 +233,7 @@ void FSMTreppeModelClass::step()
|
|||||||
FSMTreppe_Y.dimmrichtung = 0U;
|
FSMTreppe_Y.dimmrichtung = 0U;
|
||||||
|
|
||||||
// Outport: '<Root>/status'
|
// Outport: '<Root>/status'
|
||||||
FSMTreppe_Y.status = 7U;
|
FSMTreppe_Y.status = 9U;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
//
|
//
|
||||||
// Code generated for Simulink model 'FSMTreppe'.
|
// Code generated for Simulink model 'FSMTreppe'.
|
||||||
//
|
//
|
||||||
// Model version : 1.28
|
// Model version : 1.51
|
||||||
// Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
|
// Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
|
||||||
// C/C++ source code generated on : Sat Jul 3 13:50:17 2021
|
// C/C++ source code generated on : Wed Jul 7 18:54:01 2021
|
||||||
//
|
//
|
||||||
// Target selection: ert.tlc
|
// Target selection: ert.tlc
|
||||||
// Embedded hardware selection: ARM Compatible->ARM Cortex-M
|
// Embedded hardware selection: ARM Compatible->ARM Cortex-M
|
||||||
@@ -27,24 +27,24 @@ class FSMTreppeModelClass {
|
|||||||
public:
|
public:
|
||||||
// Block states (default storage) for system '<Root>'
|
// Block states (default storage) for system '<Root>'
|
||||||
struct DW_FSMTreppe_T {
|
struct DW_FSMTreppe_T {
|
||||||
uint16_t temporalCounter_i1; // '<Root>/FSMTreppe'
|
uint16_t temporalCounter_i1=0; // '<Root>/FSMTreppe'
|
||||||
uint8_t is_active_c3_FSMTreppe; // '<Root>/FSMTreppe'
|
uint8_t is_active_c3_FSMTreppe=0; // '<Root>/FSMTreppe'
|
||||||
uint8_t is_c3_FSMTreppe; // '<Root>/FSMTreppe'
|
uint8_t is_c3_FSMTreppe=0; // '<Root>/FSMTreppe'
|
||||||
};
|
};
|
||||||
|
|
||||||
// External inputs (root inport signals with default storage)
|
// External inputs (root inport signals with default storage)
|
||||||
struct ExtU_FSMTreppe_T {
|
struct ExtU_FSMTreppe_T {
|
||||||
bool sensor_unten; // '<Root>/sensor_unten'
|
uint32_t sensor_unten=0; // '<Root>/sensor_unten'
|
||||||
bool sensor_oben; // '<Root>/sensor_oben'
|
uint32_t sensor_oben=0; // '<Root>/sensor_oben'
|
||||||
bool anim_beendet; // '<Root>/anim_beendet'
|
uint32_t anim_beendet=0; // '<Root>/anim_beendet'
|
||||||
double ldr_schwelle; // '<Root>/ldr_schwelle'
|
uint32_t ldr_schwelle=0; // '<Root>/ldr_schwelle'
|
||||||
};
|
};
|
||||||
|
|
||||||
// External outputs (root outports fed by signals with default storage)
|
// External outputs (root outports fed by signals with default storage)
|
||||||
struct ExtY_FSMTreppe_T {
|
struct ExtY_FSMTreppe_T {
|
||||||
uint8_t laufrichtung; // '<Root>/laufrichtung'
|
uint32_t laufrichtung=0; // '<Root>/laufrichtung'
|
||||||
uint8_t status; // '<Root>/status'
|
uint32_t status=0; // '<Root>/status'
|
||||||
uint8_t dimmrichtung; // '<Root>/dimmrichtung'
|
uint32_t dimmrichtung=0; // '<Root>/dimmrichtung'
|
||||||
};
|
};
|
||||||
|
|
||||||
// model initialize function
|
// model initialize function
|
||||||
@@ -67,13 +67,16 @@ class FSMTreppeModelClass {
|
|||||||
// Root inports set method
|
// Root inports set method
|
||||||
void setExternalInputs(const ExtU_FSMTreppe_T* pExtU_FSMTreppe_T)
|
void setExternalInputs(const ExtU_FSMTreppe_T* pExtU_FSMTreppe_T)
|
||||||
{
|
{
|
||||||
FSMTreppe_U = *pExtU_FSMTreppe_T;
|
FSMTreppe_U.anim_beendet = pExtU_FSMTreppe_T->anim_beendet;
|
||||||
|
FSMTreppe_U.ldr_schwelle = pExtU_FSMTreppe_T->ldr_schwelle;
|
||||||
|
FSMTreppe_U.sensor_oben = pExtU_FSMTreppe_T->sensor_oben;
|
||||||
|
FSMTreppe_U.sensor_unten = pExtU_FSMTreppe_T->sensor_unten;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Root-level structure-based outputs get method
|
// Root-level structure-based outputs get method
|
||||||
|
|
||||||
// Root outports get method
|
// Root outports get method
|
||||||
const FSMTreppeModelClass::ExtY_FSMTreppe_T & getExternalOutputs() const
|
const FSMTreppeModelClass::ExtY_FSMTreppe_T getExternalOutputs() const
|
||||||
{
|
{
|
||||||
return FSMTreppe_Y;
|
return FSMTreppe_Y;
|
||||||
}
|
}
|
||||||
Binary file not shown.
+295
-165
@@ -1,147 +1,146 @@
|
|||||||
#include "treppe.h"
|
#include "treppe.h"
|
||||||
|
// #define DEBUG_TIMING
|
||||||
|
|
||||||
/*
|
/*
|
||||||
dimm_stufe
|
- dimmer_tick: increment pwm jeden tick, bis anim beendet
|
||||||
- dimmt stufe (0 - 15, PCA9685 outputs) mit linearen ticks
|
- return: fsm_pend.anim_beendet
|
||||||
von idle bis active brightness
|
|
||||||
- return false solange gedimmt wird
|
|
||||||
- return true bei nächster stufe
|
|
||||||
*/
|
*/
|
||||||
bool Treppe::dimm_stufe(uint8_t stufe)
|
bool Treppe::dimmer_tick(dimmer_t *dimmer, bool dim_type) {
|
||||||
{
|
dimmer->pwm += dimmer->delta_pwm;
|
||||||
if (fsm_outputs.dimmrichtung == DR_AUFDIMMEN)
|
Serial.printf("%.0f", dimmer->pwm);
|
||||||
current_pwm += differenz_pwm_pro_tick;
|
|
||||||
else
|
|
||||||
current_pwm -= differenz_pwm_pro_tick;
|
|
||||||
pwmController.setChannelPWM(stufe, static_cast<uint16_t>(current_pwm));
|
|
||||||
|
|
||||||
current_tick++;
|
if (dim_type == DIM_STUFEN) {
|
||||||
if (current_tick >= ticks_pro_stufe)
|
pwmController.setChannelPWM(dimmer->stufe,
|
||||||
return false;
|
static_cast<uint16_t>(dimmer->pwm));
|
||||||
return true;
|
} else { // DIM_LDR
|
||||||
}
|
pwmController.setAllChannelsPWM(static_cast<uint16_t>(dimmer->pwm));
|
||||||
|
|
||||||
/*
|
|
||||||
animation tick
|
|
||||||
- nach dem dimmen einer stufe wird die stufe weitergezählt
|
|
||||||
- abbruch am ende => anim_beendet = true;
|
|
||||||
*/
|
|
||||||
void Treppe::anim_tick()
|
|
||||||
{
|
|
||||||
if (!dimm_stufe(stufe))
|
|
||||||
{
|
|
||||||
Serial.printf("anim_tick(): stufe: %d, start: %d, ziel: %d, current %f\n",
|
|
||||||
stufe, start_pwm, ziel_pwm, current_pwm);
|
|
||||||
|
|
||||||
if (fsm_outputs.laufrichtung == LR_HOCH)
|
|
||||||
{
|
|
||||||
if (stufe >= stufen - 1)
|
|
||||||
{
|
|
||||||
anim_beendet = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
stufe++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (stufe <= 0)
|
|
||||||
{
|
|
||||||
anim_beendet = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
stufe--;
|
|
||||||
}
|
|
||||||
current_tick = 0;
|
|
||||||
current_pwm = start_pwm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dimmer->tick++;
|
||||||
|
if (dimmer->tick < dimmer->ticks) {
|
||||||
|
Serial.print("-");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Serial.println("");
|
||||||
|
|
||||||
|
if (dim_type == DIM_LDR) {
|
||||||
|
Serial.printf("DIM_LDR: start: %d, ziel: %d\n", dimmer->start_pwm,
|
||||||
|
dimmer->ziel_pwm);
|
||||||
|
return true;
|
||||||
|
} else { // DIM_STUFEN
|
||||||
|
Serial.printf("DIM_STUFEN: stufe: %d, start: %d, ziel: %d\n",
|
||||||
|
dimmer->stufe, dimmer->start_pwm, dimmer->ziel_pwm);
|
||||||
|
|
||||||
|
if (fsm_outputs.laufrichtung == LR_HOCH) {
|
||||||
|
if (dimmer->stufe >= stufen - 1)
|
||||||
|
return true;
|
||||||
|
dimmer->stufe++;
|
||||||
|
} else { // LR_RUNTER
|
||||||
|
if (dimmer->stufe <= 0)
|
||||||
|
return true;
|
||||||
|
dimmer->stufe--;
|
||||||
|
}
|
||||||
|
dimmer->tick = 0;
|
||||||
|
dimmer->pwm = dimmer->start_pwm;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// startbedingunen für animation
|
// startbedingunen für animation
|
||||||
void Treppe::start_animation()
|
void Treppe::start_animation(dimmer_t *dimmer, bool dim_type, uint16_t on_pwm,
|
||||||
{
|
uint16_t off_pwm) {
|
||||||
anim_beendet = false;
|
fsm_pend.anim_beendet = false;
|
||||||
|
|
||||||
if (fsm_outputs.laufrichtung == LR_HOCH)
|
if (dim_type == DIM_STUFEN) {
|
||||||
stufe = 0;
|
if (fsm_outputs.laufrichtung == LR_HOCH)
|
||||||
else
|
dimmer->stufe = 0;
|
||||||
stufe = stufen - 1;
|
else
|
||||||
|
dimmer->stufe = stufen - 1;
|
||||||
|
|
||||||
if (fsm_outputs.dimmrichtung == DR_AUFDIMMEN)
|
dimmer->ticks = param.time_per_stair / INT_TIME; // [ms]
|
||||||
{
|
} else { // DIM_LDR
|
||||||
start_pwm = idle_brightness;
|
dimmer->ticks = param.time_ldr / INT_TIME; // [ms]
|
||||||
ziel_pwm = active_brightness;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
start_pwm = active_brightness;
|
|
||||||
ziel_pwm = idle_brightness;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
current_tick = 0;
|
if (fsm_outputs.dimmrichtung == DR_AUFDIMMEN) {
|
||||||
current_pwm = start_pwm;
|
dimmer->start_pwm = off_pwm;
|
||||||
|
dimmer->ziel_pwm = on_pwm;
|
||||||
|
dimmer->delta_pwm = (float)(on_pwm - off_pwm) / (float)dimmer->ticks;
|
||||||
|
} else {
|
||||||
|
dimmer->start_pwm = on_pwm;
|
||||||
|
dimmer->ziel_pwm = off_pwm;
|
||||||
|
dimmer->delta_pwm = (float)(off_pwm - on_pwm) / (float)dimmer->ticks;
|
||||||
|
}
|
||||||
|
|
||||||
|
dimmer->tick = 0;
|
||||||
|
dimmer->pwm = dimmer->start_pwm;
|
||||||
|
|
||||||
|
Serial.printf("stufe %d, ticks %d, delta %f, start %d, ziel %d\n",
|
||||||
|
dimmer->stufe, dimmer->ticks, dimmer->delta_pwm,
|
||||||
|
dimmer->start_pwm, dimmer->ziel_pwm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Treppe::print_state_on_change()
|
void Treppe::print_state_on_change() {
|
||||||
{
|
|
||||||
static FSMTreppeModelClass::ExtU_FSMTreppe_T last_in;
|
static FSMTreppeModelClass::ExtU_FSMTreppe_T last_in;
|
||||||
static FSMTreppeModelClass::ExtY_FSMTreppe_T last_out;
|
static FSMTreppeModelClass::ExtY_FSMTreppe_T last_out;
|
||||||
if (
|
if (fsm_inputs.anim_beendet != last_in.anim_beendet ||
|
||||||
fsm_inputs.anim_beendet != last_in.anim_beendet ||
|
|
||||||
fsm_inputs.sensor_oben != last_in.sensor_oben ||
|
fsm_inputs.sensor_oben != last_in.sensor_oben ||
|
||||||
fsm_inputs.sensor_unten != last_in.sensor_unten ||
|
fsm_inputs.sensor_unten != last_in.sensor_unten ||
|
||||||
|
fsm_inputs.ldr_schwelle != last_in.ldr_schwelle ||
|
||||||
fsm_outputs.dimmrichtung != last_out.dimmrichtung ||
|
fsm_outputs.dimmrichtung != last_out.dimmrichtung ||
|
||||||
fsm_outputs.laufrichtung != last_out.laufrichtung ||
|
fsm_outputs.laufrichtung != last_out.laufrichtung ||
|
||||||
fsm_outputs.status != last_out.status)
|
fsm_outputs.status != last_out.status) {
|
||||||
{
|
|
||||||
last_in.anim_beendet = fsm_inputs.anim_beendet;
|
last_in.anim_beendet = fsm_inputs.anim_beendet;
|
||||||
last_in.sensor_oben = fsm_inputs.sensor_oben;
|
last_in.sensor_oben = fsm_inputs.sensor_oben;
|
||||||
last_in.sensor_unten = fsm_inputs.sensor_unten;
|
last_in.sensor_unten = fsm_inputs.sensor_unten;
|
||||||
|
last_in.ldr_schwelle = fsm_inputs.ldr_schwelle;
|
||||||
last_out.dimmrichtung = fsm_outputs.dimmrichtung;
|
last_out.dimmrichtung = fsm_outputs.dimmrichtung;
|
||||||
last_out.laufrichtung = fsm_outputs.laufrichtung;
|
last_out.laufrichtung = fsm_outputs.laufrichtung;
|
||||||
last_out.status = fsm_outputs.status;
|
last_out.status = fsm_outputs.status;
|
||||||
|
|
||||||
Serial.printf("FSM IN: s_u: %d, s_o: %d, beendet: %d =>",
|
Serial.printf("FSM IN: s_u: %d, s_o: %d, a_b: %d, l_s: %d => ",
|
||||||
fsm_inputs.sensor_oben, fsm_inputs.sensor_unten, fsm_inputs.anim_beendet);
|
fsm_inputs.sensor_oben, fsm_inputs.sensor_unten,
|
||||||
Serial.print(" step => ");
|
fsm_inputs.anim_beendet, fsm_inputs.ldr_schwelle);
|
||||||
Serial.printf("OUT: LR: %d DR: %d ST: %d\n",
|
Serial.printf("OUT: LR: %d DR: %d ST: %d\n", fsm_outputs.laufrichtung,
|
||||||
fsm_outputs.laufrichtung, fsm_outputs.dimmrichtung, fsm_outputs.status);
|
fsm_outputs.dimmrichtung, fsm_outputs.status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Treppe::read_sensor(int sensor)
|
void Treppe::overwrite_sensors(bool s_oben, bool s_unten) {
|
||||||
{
|
fsm_pend.web_ctrl_s_oben = s_oben;
|
||||||
|
fsm_pend.web_ctrl_s_unten = s_unten;
|
||||||
/*
|
|
||||||
reads sensors with edge detection
|
|
||||||
|
|
||||||
returns true if motion was detected
|
|
||||||
returns false if no motion was detected
|
|
||||||
returns false if motion was detected, but state did not change back to not detected
|
|
||||||
*/
|
|
||||||
uint8_t pegel = digitalRead(sensor);
|
|
||||||
static uint8_t pegel_alt[2] = {0, 0};
|
|
||||||
|
|
||||||
uint8_t index = 0;
|
|
||||||
if (sensor == SENSOR_OBEN)
|
|
||||||
index = 0;
|
|
||||||
else
|
|
||||||
index = 1;
|
|
||||||
|
|
||||||
if (pegel == 1 && pegel_alt[index] == 0)
|
|
||||||
{
|
|
||||||
pegel_alt[index] = pegel;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pegel_alt[index] = pegel;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
//return static_cast<bool>(pegel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float Treppe::read_ldr()
|
void Treppe::read_sensors() {
|
||||||
{
|
const bool s_oben = digitalRead(SENSOR_OBEN);
|
||||||
|
const bool s_unten = digitalRead(SENSOR_UNTEN);
|
||||||
|
|
||||||
|
fsm_pend.sensor_oben = false;
|
||||||
|
fsm_pend.sensor_unten = false;
|
||||||
|
|
||||||
|
// rising trigger => 1 cycle true !
|
||||||
|
if (s_oben && !fsm_pend.last_s_oben) {
|
||||||
|
fsm_pend.sensor_oben = true;
|
||||||
|
}
|
||||||
|
if (s_unten && !fsm_pend.last_s_unten) {
|
||||||
|
fsm_pend.sensor_unten = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
fsm_pend.last_s_oben = s_oben;
|
||||||
|
fsm_pend.last_s_unten = s_unten;
|
||||||
|
|
||||||
|
// check for manipulation over webserver
|
||||||
|
if (fsm_pend.web_ctrl_s_oben) {
|
||||||
|
fsm_pend.sensor_oben = true;
|
||||||
|
fsm_pend.web_ctrl_s_oben = false;
|
||||||
|
}
|
||||||
|
if (fsm_pend.web_ctrl_s_unten) {
|
||||||
|
fsm_pend.sensor_unten = true;
|
||||||
|
fsm_pend.web_ctrl_s_unten = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float Treppe::read_ldr() {
|
||||||
/*
|
/*
|
||||||
Reads Illuminance in Lux
|
Reads Illuminance in Lux
|
||||||
|
|
||||||
@@ -169,75 +168,146 @@ float Treppe::read_ldr()
|
|||||||
= 37280.00/analogRead(A0)
|
= 37280.00/analogRead(A0)
|
||||||
ldr_ohm = R(LDR)
|
ldr_ohm = R(LDR)
|
||||||
|
|
||||||
E(LDR) = 79.735 * R(LDR)^-0.498 (see Excel Regression)
|
E(LDR) = 6526.5 * R(LDR)^-2 (see Excel Regression)
|
||||||
|
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 ldr_value = 79.735 * pow(ldr_ohm, -0.498);
|
float voltage = analogRead(A0) * 0.0036;
|
||||||
|
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 Comp: %d\n", ldr_ohm, ldr_value,
|
||||||
|
param.ldr_schwelle);
|
||||||
|
#endif
|
||||||
return ldr_value;
|
return ldr_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Treppe::check_ldr()
|
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?
|
||||||
float ldr = read_ldr();
|
float ldr = read_ldr();
|
||||||
if (ldr < ldr_schwelle)
|
|
||||||
active = 1;
|
|
||||||
if (ldr > ldr_schwelle + LDR_HYS)
|
|
||||||
active = 0;
|
|
||||||
|
|
||||||
|
if (ldr < param.ldr_schwelle) {
|
||||||
|
active = 1;
|
||||||
|
}
|
||||||
|
if (ldr > param.ldr_schwelle + LDR_HYS) {
|
||||||
|
active = 0;
|
||||||
|
}
|
||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Treppe::task()
|
void Treppe::task() {
|
||||||
{
|
#ifdef DEBUG_TIMING
|
||||||
|
uint32_t m = micros();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// TODO wenn LDR geändert => idle_pwm_soll anpassen
|
||||||
|
// fsm_pend.ldr_changed = true;
|
||||||
fsm_inputs.ldr_schwelle = check_ldr();
|
fsm_inputs.ldr_schwelle = check_ldr();
|
||||||
|
|
||||||
fsm_inputs.sensor_oben = read_sensor(SENSOR_OBEN);
|
#ifdef DEBUG_TIMING
|
||||||
fsm_inputs.sensor_unten = read_sensor(SENSOR_UNTEN);
|
Serial.print("1:");
|
||||||
fsm_inputs.anim_beendet = static_cast<bool>(anim_beendet);
|
Serial.println(micros() - m);
|
||||||
|
m = micros();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
read_sensors();
|
||||||
|
fsm_inputs.sensor_oben = fsm_pend.sensor_oben;
|
||||||
|
fsm_inputs.sensor_unten = fsm_pend.sensor_unten;
|
||||||
|
|
||||||
|
fsm_inputs.anim_beendet = fsm_pend.anim_beendet;
|
||||||
|
|
||||||
|
#ifdef DEBUG_TIMING
|
||||||
|
Serial.print("2:");
|
||||||
|
Serial.println(micros() - m);
|
||||||
|
m = micros();
|
||||||
|
#endif
|
||||||
|
|
||||||
FSMTreppe_Obj.setExternalInputs(&fsm_inputs);
|
FSMTreppe_Obj.setExternalInputs(&fsm_inputs);
|
||||||
FSMTreppe_Obj.step();
|
FSMTreppe_Obj.step();
|
||||||
fsm_outputs = FSMTreppe_Obj.getExternalOutputs();
|
fsm_outputs = FSMTreppe_Obj.getExternalOutputs();
|
||||||
|
|
||||||
|
#ifdef DEBUG_TIMING
|
||||||
|
Serial.print("3:");
|
||||||
|
Serial.println(micros() - m);
|
||||||
|
m = micros();
|
||||||
|
#endif
|
||||||
|
|
||||||
print_state_on_change();
|
print_state_on_change();
|
||||||
|
|
||||||
if (fsm_outputs.status > ST_RUHEZUSTAND)
|
#ifdef DEBUG_TIMING
|
||||||
{
|
Serial.print("4:");
|
||||||
if (anim_beendet == true &&
|
Serial.println(micros() - m);
|
||||||
(fsm_outputs.status == ST_AUFDIMMEN_HOCH || fsm_outputs.status == ST_ABDIMMEN_HOCH ||
|
m = micros();
|
||||||
fsm_outputs.status == ST_AUFDIMMEN_RUNTER || fsm_outputs.status == ST_ABDIMMEN_RUNTER))
|
#endif
|
||||||
{
|
|
||||||
start_animation();
|
if (fsm_outputs.status == ST_AUFDIMMEN_HOCH ||
|
||||||
|
fsm_outputs.status == ST_ABDIMMEN_HOCH ||
|
||||||
|
fsm_outputs.status == ST_AUFDIMMEN_RUNTER ||
|
||||||
|
fsm_outputs.status == ST_ABDIMMEN_RUNTER) {
|
||||||
|
if (fsm_pend.anim_beendet)
|
||||||
|
start_animation(&dimmer_stufen, DIM_STUFEN, param.active_pwm,
|
||||||
|
idle_pwm_ist);
|
||||||
|
else
|
||||||
|
fsm_pend.anim_beendet = dimmer_tick(&dimmer_stufen, DIM_STUFEN);
|
||||||
|
} else if (fsm_outputs.status == ST_AUFDIMMEN_LDR ||
|
||||||
|
fsm_outputs.status == ST_ABDIMMEN_LDR) {
|
||||||
|
if (fsm_pend.anim_beendet)
|
||||||
|
start_animation(&dimmer_ldr, DIM_LDR, idle_pwm_ist, 0);
|
||||||
|
else
|
||||||
|
fsm_pend.anim_beendet = dimmer_tick(&dimmer_ldr, DIM_LDR);
|
||||||
|
} else if (fsm_outputs.status == ST_RUHEZUSTAND) {
|
||||||
|
if (fsm_pend.ldr_changed) {
|
||||||
|
fsm_pend.ldr_changed = false;
|
||||||
|
fsm_outputs.dimmrichtung = DR_AUFDIMMEN;
|
||||||
|
start_animation(&dimmer_ldr, DIM_LDR, idle_pwm_soll, idle_pwm_ist);
|
||||||
|
idle_pwm_ist = idle_pwm_soll;
|
||||||
|
}
|
||||||
|
if (!fsm_pend.anim_beendet) {
|
||||||
|
fsm_pend.anim_beendet = dimmer_tick(&dimmer_ldr, DIM_LDR);
|
||||||
}
|
}
|
||||||
if (!anim_beendet)
|
|
||||||
anim_tick();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
Serial.print("5:");
|
||||||
|
Serial.println(micros() - m);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Treppe::berechne_dimmer()
|
void Treppe::setup() {
|
||||||
{
|
|
||||||
ticks_pro_stufe = time_per_stair / INT_TIME; // [ms]
|
|
||||||
differenz_pwm_pro_tick = (float)(active_brightness - idle_brightness) / (float)ticks_pro_stufe;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Treppe::setup()
|
|
||||||
{
|
|
||||||
pwmController.resetDevices();
|
pwmController.resetDevices();
|
||||||
// Deactive PCA9685 Phase Balancer due to LED Flickering
|
// Deactive PCA9685 Phase Balancer due to LED Flickering
|
||||||
// https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
// https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
||||||
// see also lib/PCA9685-Arduin/PCA9685.h:204
|
// see also lib/PCA9685-Arduin/PCA9685.h:204
|
||||||
pwmController.init(PCA9685_PhaseBalancer_None);
|
pwmController.init(PCA9685_PhaseBalancer_None);
|
||||||
//pwmController.init(PCA9685_PhaseBalancer_Linear);
|
// pwmController.init(PCA9685_PhaseBalancer_Linear);
|
||||||
pwmController.setPWMFrequency(100);
|
pwmController.setPWMFrequency(100);
|
||||||
pwmController.setAllChannelsPWM(idle_brightness);
|
// pwmController.setAllChannelsPWM(idle_pwm);
|
||||||
|
|
||||||
|
// WARNING: before getting Parameters of Flash, make sure plausible parameters
|
||||||
|
// are written in flash!
|
||||||
|
EEPROM.get(EEP_START_ADDR, param); // get Parameters of flash
|
||||||
|
|
||||||
|
pinMode(13, OUTPUT);
|
||||||
|
pinMode(0, OUTPUT);
|
||||||
|
digitalWrite(13, HIGH);
|
||||||
|
digitalWrite(0, HIGH);
|
||||||
|
|
||||||
pinMode(A0, INPUT);
|
pinMode(A0, INPUT);
|
||||||
pinMode(SENSOR_OBEN, INPUT);
|
pinMode(SENSOR_OBEN, INPUT);
|
||||||
@@ -245,27 +315,87 @@ void Treppe::setup()
|
|||||||
pinMode(OE, OUTPUT);
|
pinMode(OE, OUTPUT);
|
||||||
digitalWrite(OE, 0);
|
digitalWrite(OE, 0);
|
||||||
|
|
||||||
Serial.printf("differenz_pwm_pro_tick %f\n", differenz_pwm_pro_tick);
|
Serial.printf("Treppe: stufen=%d\n", stufen);
|
||||||
Serial.printf("Treppe: initial parameters: stufen=%d\n", stufen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ###################################################################################################################
|
void Treppe::save_param_to_eeprom() {
|
||||||
// GEBUFFERT => Erst im Ruhezustand übernehmen !!!!
|
EEPROM.put(EEP_START_ADDR,
|
||||||
void Treppe::set_idle_pwm(uint16_t _idle_brightness)
|
param); // copy Parameters so "EEPROM"-section in RAM
|
||||||
{
|
EEPROM.commit(); // write "EEPROM"-section to flash
|
||||||
idle_brightness = _idle_brightness;
|
|
||||||
berechne_dimmer();
|
|
||||||
Serial.printf("Treppe: idle_brightness=%d\n", idle_brightness);
|
|
||||||
}
|
}
|
||||||
void Treppe::set_active_pwm(uint16_t _active_brightness)
|
|
||||||
{
|
void Treppe::set_idle_pwm_max(const uint16_t value,
|
||||||
active_brightness = _active_brightness;
|
const vorgabe_typ_t vorgabe_typ) {
|
||||||
berechne_dimmer();
|
if (vorgabe_typ == VORGABE_PROZENT) {
|
||||||
Serial.printf("Treppe: active_brightness=%d\n", active_brightness);
|
param_pend.idle_pwm_max = param_pend.active_pwm * value / 100;
|
||||||
|
} else if (vorgabe_typ == VORGABE_12BIT) {
|
||||||
|
param_pend.idle_pwm_max = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param_pend.idle_pwm_max > param_pend.active_pwm) {
|
||||||
|
param_pend.idle_pwm_max = param_pend.active_pwm;
|
||||||
|
}
|
||||||
|
param_changed = true;
|
||||||
|
|
||||||
|
Serial.printf("Treppe: param_pend.idle_pwm_max=%d\n",
|
||||||
|
param_pend.idle_pwm_max);
|
||||||
}
|
}
|
||||||
void Treppe::set_time_per_stair(uint16_t _time_per_stair)
|
|
||||||
{
|
void Treppe::set_active_pwm(const uint16_t value,
|
||||||
time_per_stair = _time_per_stair;
|
const vorgabe_typ_t vorgabe_typ) {
|
||||||
berechne_dimmer();
|
|
||||||
Serial.printf("Treppe: time_per_stair=%d\n", time_per_stair);
|
if (vorgabe_typ == VORGABE_PROZENT) {
|
||||||
|
param_pend.active_pwm = 4095 * value / 100;
|
||||||
|
} else if (vorgabe_typ == VORGABE_12BIT) {
|
||||||
|
param_pend.active_pwm = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param_pend.active_pwm > 4095) {
|
||||||
|
param_pend.idle_pwm_max = 4095;
|
||||||
|
}
|
||||||
|
param_changed = true;
|
||||||
|
|
||||||
|
Serial.printf("Treppe: param_pend.active_pwm=%d\n", param_pend.active_pwm);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Treppe::set_time_ldr(const uint16_t value) {
|
||||||
|
param_pend.time_ldr = value;
|
||||||
|
if (param_pend.time_ldr > TIME_MS_MAX)
|
||||||
|
param_pend.time_ldr = TIME_MS_MAX;
|
||||||
|
param_changed = true;
|
||||||
|
|
||||||
|
Serial.printf("Treppe: time_ldr=%d\n", param_pend.time_ldr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Treppe::set_time_per_stair(const uint16_t value) {
|
||||||
|
param_pend.time_per_stair = value;
|
||||||
|
if (param_pend.time_per_stair > TIME_MS_MAX)
|
||||||
|
param_pend.time_per_stair = TIME_MS_MAX;
|
||||||
|
param_changed = true;
|
||||||
|
|
||||||
|
Serial.printf("Treppe: time_per_stair=%d\n", param_pend.time_per_stair);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Treppe::set_ldr_schwelle(const uint16_t value,
|
||||||
|
const vorgabe_typ_t vorgabe_typ) {
|
||||||
|
if (vorgabe_typ == VORGABE_PROZENT) {
|
||||||
|
// ?!
|
||||||
|
param_pend.ldr_schwelle = 10 * value / 100;
|
||||||
|
} else if (vorgabe_typ == VORGABE_12BIT) {
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
+98
-64
@@ -1,86 +1,120 @@
|
|||||||
#pragma once
|
#ifndef __TREPPE_H
|
||||||
|
#define __TREPPE_H
|
||||||
|
|
||||||
#include "FSMTreppe2/FSMTreppe2.h"
|
#include "FSMTreppe3/FSMTreppe3.h"
|
||||||
#include "PCA9685.h"
|
#include "PCA9685.h"
|
||||||
|
#include <EEPROM.h>
|
||||||
|
|
||||||
// #define LDRDEBUG // comment in to override LDR measurement
|
//#define LDRDEBUG // comment in to override LDR measurement
|
||||||
|
#define LDR_HYS 8 // Hysteresis for switching off FSM [lux]
|
||||||
|
|
||||||
#define LDR_HYS 5.0 // Hysteresis for switching off FSM [lux]
|
#define SENSOR_OBEN 16
|
||||||
|
|
||||||
#define SENSOR_OBEN 2
|
|
||||||
#define SENSOR_UNTEN 12
|
#define SENSOR_UNTEN 12
|
||||||
#define OE 14
|
#define OE 14
|
||||||
|
|
||||||
#define INT_TIME 20 // interrupt intervall [ms]
|
#define INT_TIME 20 // interrupt intervall [ms]
|
||||||
|
#define TIME_MS_MAX 5000 // maximum time for animation [ms]
|
||||||
|
|
||||||
|
enum vorgabe_typ_t { VORGABE_PROZENT = 0, VORGABE_12BIT = 1 };
|
||||||
|
|
||||||
|
#define EEP_START_ADDR 100 // define Start Address for "EEPROM" storage -> depends on size of "wifi_data"!
|
||||||
|
|
||||||
class Treppe {
|
class Treppe {
|
||||||
private:
|
private:
|
||||||
const uint8_t stufen;
|
const uint8_t stufen;
|
||||||
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
|
|
||||||
uint16_t idle_brightness = 100;
|
|
||||||
uint16_t active_brightness = 700;
|
|
||||||
|
|
||||||
uint16_t ldr_schwelle = 7; // activation value for FSM [lx]
|
struct stairway_param_t {
|
||||||
|
uint16_t time_ldr = 500;
|
||||||
|
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 = 30; // activation value for FSM [lx]
|
||||||
|
};
|
||||||
|
stairway_param_t param;
|
||||||
|
stairway_param_t param_pend; // zwischenspeicher änderungen
|
||||||
|
bool param_changed = false;
|
||||||
|
|
||||||
uint16_t start_pwm = 0;
|
uint16_t idle_pwm_ist = param.idle_pwm_max;
|
||||||
uint16_t ziel_pwm = 0;
|
uint16_t idle_pwm_soll = 0;
|
||||||
|
|
||||||
|
struct fsm_pending_inputs_t {
|
||||||
bool anim_beendet = true;
|
bool anim_beendet = true;
|
||||||
|
bool sensor_unten = false;
|
||||||
|
bool last_s_unten = false;
|
||||||
|
bool web_ctrl_s_unten = false;
|
||||||
|
bool sensor_oben = false;
|
||||||
|
bool last_s_oben = false;
|
||||||
|
bool web_ctrl_s_oben = false;
|
||||||
|
bool ldr_changed = false;
|
||||||
|
};
|
||||||
|
fsm_pending_inputs_t fsm_pend;
|
||||||
|
|
||||||
|
struct dimmer_t {
|
||||||
uint8_t stufe = 0;
|
uint8_t stufe = 0;
|
||||||
uint16_t current_tick = 0;
|
uint16_t ticks = 0;
|
||||||
float current_pwm = 0.0;
|
uint16_t tick = 0;
|
||||||
uint16_t ticks_pro_stufe = 0;
|
|
||||||
float differenz_pwm_pro_tick = 0.0;
|
|
||||||
|
|
||||||
// initialize with i2c-Address 0, use Wire Library
|
float delta_pwm = 0.0;
|
||||||
PCA9685 pwmController;
|
float pwm = 0.0;
|
||||||
FSMTreppeModelClass FSMTreppe_Obj;
|
uint16_t start_pwm = 0;
|
||||||
FSMTreppeModelClass::ExtU_FSMTreppe_T fsm_inputs;
|
uint16_t ziel_pwm = 0;
|
||||||
FSMTreppeModelClass::ExtY_FSMTreppe_T fsm_outputs;
|
};
|
||||||
enum fsm_status_t {
|
enum dimmer_type_t { DIM_STUFEN = 0, DIM_LDR = 1 };
|
||||||
ST_INAKTIV_LDR =0,
|
dimmer_t dimmer_stufen;
|
||||||
ST_RUHEZUSTAND =1,
|
dimmer_t dimmer_ldr;
|
||||||
ST_AUFDIMMEN_HOCH =2,
|
|
||||||
ST_WARTEN_HOCH =3,
|
|
||||||
ST_ABDIMMEN_HOCH =4,
|
|
||||||
ST_AUFDIMMEN_RUNTER =5,
|
|
||||||
ST_WARTEN_RUNTER =6,
|
|
||||||
ST_ABDIMMEN_RUNTER =7
|
|
||||||
};
|
|
||||||
enum fsm_laufrichtung_t {
|
|
||||||
LR_RUNTER=0,
|
|
||||||
LR_HOCH=1
|
|
||||||
};
|
|
||||||
enum fsm_dimmrichtung_t {
|
|
||||||
DR_ABDIMMEN=0,
|
|
||||||
DR_AUFDIMMEN=1
|
|
||||||
};
|
|
||||||
|
|
||||||
/* DIMM */
|
// initialize with i2c-Address 0, use Wire Library
|
||||||
bool dimm_stufe(uint8_t stufe);
|
PCA9685 pwmController;
|
||||||
void anim_tick();
|
FSMTreppeModelClass FSMTreppe_Obj;
|
||||||
void start_animation();
|
FSMTreppeModelClass::ExtU_FSMTreppe_T fsm_inputs;
|
||||||
void berechne_dimmer();
|
FSMTreppeModelClass::ExtY_FSMTreppe_T fsm_outputs;
|
||||||
void print_state_on_change();
|
enum fsm_status_t {
|
||||||
|
ST_INAKTIV_LDR = 0,
|
||||||
|
ST_AUFDIMMEN_LDR = 1,
|
||||||
|
ST_ABDIMMEN_LDR = 2,
|
||||||
|
ST_RUHEZUSTAND = 3,
|
||||||
|
ST_AUFDIMMEN_HOCH = 4,
|
||||||
|
ST_WARTEN_HOCH = 5,
|
||||||
|
ST_ABDIMMEN_HOCH = 6,
|
||||||
|
ST_AUFDIMMEN_RUNTER = 7,
|
||||||
|
ST_WARTEN_RUNTER = 8,
|
||||||
|
ST_ABDIMMEN_RUNTER = 9
|
||||||
|
};
|
||||||
|
enum fsm_laufrichtung_t { LR_RUNTER = 0, LR_HOCH = 1 };
|
||||||
|
enum fsm_dimmrichtung_t { DR_ABDIMMEN = 0, DR_AUFDIMMEN = 1 };
|
||||||
|
|
||||||
|
void read_sensors();
|
||||||
|
void print_state_on_change();
|
||||||
|
|
||||||
|
/* DIMM */
|
||||||
|
bool dimmer_tick(dimmer_t *dimmer, bool dim_type);
|
||||||
|
void start_animation(dimmer_t *dimmer, bool dim_type, uint16_t on_pwm,
|
||||||
|
uint16_t off_pwm);
|
||||||
|
|
||||||
|
/* LDR */
|
||||||
|
bool read_sensor(int sensor);
|
||||||
|
float read_ldr();
|
||||||
|
bool check_ldr();
|
||||||
|
|
||||||
/* LDR */
|
|
||||||
bool read_sensor(int sensor);
|
|
||||||
float read_ldr();
|
|
||||||
bool check_ldr();
|
|
||||||
public:
|
public:
|
||||||
Treppe(uint8_t _stufen) : stufen(_stufen){
|
Treppe(uint8_t _stufen) : stufen(_stufen) { FSMTreppe_Obj.initialize(); }
|
||||||
FSMTreppe_Obj.initialize();
|
~Treppe() { FSMTreppe_Obj.terminate(); }
|
||||||
berechne_dimmer();
|
|
||||||
}
|
|
||||||
~Treppe() {
|
|
||||||
FSMTreppe_Obj.terminate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup();
|
void setup();
|
||||||
void task(); // call periodically
|
void task(); // call periodically
|
||||||
|
|
||||||
// Parameter section
|
// Parameter section
|
||||||
void set_idle_pwm(uint16_t _idle_brightness);
|
void save_param_to_eeprom();
|
||||||
void set_active_pwm(uint16_t _active_brightness);
|
void param_to_json(char* json_str, size_t sz);
|
||||||
void set_time_per_stair(uint16_t _time_per_stair);
|
|
||||||
|
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_time_ldr(const uint16_t value);
|
||||||
|
void set_time_per_stair(const uint16_t value);
|
||||||
|
void set_ldr_schwelle(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
|
||||||
|
|
||||||
|
void overwrite_sensors(bool s_oben, bool s_unten);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif // __TREPPE_H
|
||||||
Binary file not shown.
@@ -0,0 +1,17 @@
|
|||||||
|
set remote hardware-breakpoint-limit 1
|
||||||
|
set remote hardware-watchpoint-limit 1
|
||||||
|
set remote interrupt-on-connect on
|
||||||
|
set remote kill-packet off
|
||||||
|
set remote symbol-lookup-packet off
|
||||||
|
set remote verbose-resume-packet off
|
||||||
|
mem 0x20000000 0x3fefffff ro cache
|
||||||
|
mem 0x3ff00000 0x3fffffff rw
|
||||||
|
mem 0x40000000 0x400fffff ro cache
|
||||||
|
mem 0x40100000 0x4013ffff rw cache
|
||||||
|
mem 0x40140000 0x5fffffff ro cache
|
||||||
|
mem 0x60000000 0x60001fff rw
|
||||||
|
set serial baud 460800
|
||||||
|
|
||||||
|
file .pio/build/debug/firmware.elf
|
||||||
|
target remote \\.\COM23
|
||||||
|
thb loop
|
||||||
+48
-33
@@ -6,16 +6,17 @@
|
|||||||
|
|
||||||
#include "PCA9685.h"
|
#include "PCA9685.h"
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "user_interface.h"
|
#include "user_interface.h"
|
||||||
}
|
}
|
||||||
// OTA & WEB
|
// OTA & WEB
|
||||||
#include "wifi_credentials.h"
|
|
||||||
#include "ota.h"
|
|
||||||
#include "httpserver.h"
|
#include "httpserver.h"
|
||||||
|
#include "ota.h"
|
||||||
|
#include "wifi_credentials.h"
|
||||||
|
#include <EEPROM.h>
|
||||||
|
|
||||||
// BOARD
|
// BOARD
|
||||||
#define ESP12_LED 2
|
#define ESP12_LED 2
|
||||||
#define NODEMCU_LED 16
|
// #define NODEMCU_LED 16
|
||||||
|
|
||||||
// PWM
|
// PWM
|
||||||
#include "treppe.h"
|
#include "treppe.h"
|
||||||
@@ -24,28 +25,39 @@ uint8_t timer_flag = 0;
|
|||||||
Treppe stairs(16);
|
Treppe stairs(16);
|
||||||
|
|
||||||
// WIFI
|
// WIFI
|
||||||
const char* ssid = STASSID;
|
const char *ssid = STASSID;
|
||||||
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) \
|
||||||
#define TIMEIF_US(_f, _l, _str) _t=micros(); _f; _t=micros()-_t; if(_t > _l) { SP_US(_str, _t); }
|
Serial.print(_str); \
|
||||||
|
Serial.print(" took: "); \
|
||||||
|
Serial.print(_a); \
|
||||||
|
Serial.println("us")
|
||||||
|
#define TIMEIF_US(_f, _l, _str) \
|
||||||
|
_t = micros(); \
|
||||||
|
_f; \
|
||||||
|
_t = micros() - _t; \
|
||||||
|
if (_t > (_l)) { \
|
||||||
|
SP_US(_str, _t); \
|
||||||
|
}
|
||||||
|
|
||||||
|
struct { // Struct for wifi-data, 40 Bytes each SSID and PW
|
||||||
|
char SSID[40] = "";
|
||||||
|
char PW[40] = "";
|
||||||
|
} wifi_data;
|
||||||
|
|
||||||
void timerCallback(void *pArg)
|
void timerCallback(void *pArg) {
|
||||||
{
|
*(static_cast<int *>(pArg)) += 1;
|
||||||
*((int *) pArg) += 1;
|
|
||||||
stairs.task();
|
stairs.task();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===============================================
|
// ===============================================
|
||||||
uint8_t inter = 0;
|
uint8_t inter = 0;
|
||||||
ICACHE_RAM_ATTR void int_test(){
|
ICACHE_RAM_ATTR void int_test() { inter = 1; }
|
||||||
inter = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
#ifdef WITH_DEBUGGING_ON
|
#ifdef WITH_DEBUGGING_ON
|
||||||
@@ -54,14 +66,24 @@ void setup() {
|
|||||||
#else
|
#else
|
||||||
Serial.begin(76800);
|
Serial.begin(76800);
|
||||||
#endif
|
#endif
|
||||||
|
Serial.println("Booting ....");
|
||||||
Serial.println(F("Booting ...."));
|
|
||||||
|
|
||||||
//pinMode(NODEMCU_LED, OUTPUT);
|
|
||||||
pinMode(ESP12_LED, OUTPUT);
|
pinMode(ESP12_LED, OUTPUT);
|
||||||
|
|
||||||
Wire.begin(); // Wire must be started first
|
EEPROM.begin(512); // init virtual "EEPROM" with size 512 Bytes
|
||||||
Wire.setClock(1000000); // Supported baud rates are 100kHz, 400kHz, and 1000kHz
|
|
||||||
|
// strncpy(wifi_data.SSID, "donotconnect", 40);
|
||||||
|
// strncpy(wifi_data.PW, "unsafe lol", 40);
|
||||||
|
|
||||||
|
EEPROM.get(0, wifi_data);
|
||||||
|
// EEPROM.commit();
|
||||||
|
|
||||||
|
Wire.begin(); // Wire must be started first
|
||||||
|
Wire.setClock(
|
||||||
|
1000000); // Supported baud rates are 100kHz, 400kHz, and 1000kHz
|
||||||
|
stairs.setup();
|
||||||
|
Serial.println("PCA9685 connected !");
|
||||||
|
// attachInterrupt(digitalPinToInterrupt(2), int_test, RISING);
|
||||||
|
// attachInterrupt(digitalPinToInterrupt(12), int_test, RISING);
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
@@ -82,27 +104,20 @@ void setup() {
|
|||||||
|
|
||||||
httpServer.start();
|
httpServer.start();
|
||||||
httpServer.start_apps();
|
httpServer.start_apps();
|
||||||
|
|
||||||
Serial.println("HTTP server started !");
|
Serial.println("HTTP server started !");
|
||||||
|
|
||||||
stairs.setup();
|
|
||||||
Serial.println("PCA9685 connected !");
|
|
||||||
//attachInterrupt(digitalPinToInterrupt(2), int_test, RISING);
|
|
||||||
//attachInterrupt(digitalPinToInterrupt(12), int_test, RISING);
|
|
||||||
|
|
||||||
os_timer_setfn(&timer1, timerCallback, &timer_flag);
|
os_timer_setfn(&timer1, timerCallback, &timer_flag);
|
||||||
os_timer_arm(&timer1, 20, true);
|
os_timer_arm(&timer1, 20, true);
|
||||||
|
|
||||||
|
Serial.println("SSID: " + String(wifi_data.SSID) +
|
||||||
|
" PW: " + String(wifi_data.PW));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t c = 0;
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if(inter){
|
if (inter != 0u) {
|
||||||
Serial.printf("interrupt\n");
|
Serial.printf("interrupt\n");
|
||||||
inter = 0;
|
inter = 0;
|
||||||
}
|
}
|
||||||
if(c++%1000000 == 0)
|
|
||||||
httpServer.logt("[%d] starting :)\n", c);
|
|
||||||
|
|
||||||
TIMEIF_US(ArduinoOTA.handle(), 10000, "OTA");
|
TIMEIF_US(ArduinoOTA.handle(), 10000, "OTA");
|
||||||
TIMEIF_US(httpServer.handleClient(), 10000, "HTTP");
|
TIMEIF_US(httpServer.handleClient(), 10000, "HTTP");
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
SET GDB_PATH=C:\Users\simon\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.0-newlib4.0.0-gnu23-48f7b08\bin\xtensa-lx106-elf-gdb.exe
|
||||||
|
|
||||||
|
echo "Starting gdb"
|
||||||
|
echo %GDB_PATH%
|
||||||
|
%GDB_PATH% -x ".\scripts\gdboptions_win"
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
GDB_PATH=~/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.0-newlib4.0.0-gnu23-48f7b08/bin/xtensa-lx106-elf-gdb
|
GDB_PATH=~/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.0-newlib4.0.0-gnu23-48f7b08/bin/xtensa-lx106-elf-gdb
|
||||||
|
|
||||||
cd ..
|
|
||||||
echo "Starting gdb"
|
echo "Starting gdb"
|
||||||
$GDB_PATH -x scripts/gdboptions
|
$GDB_PATH -x scripts/gdboptions
|
||||||
Reference in new issue
Block a user