Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22f141e2cd | ||
|
|
f5d6e376c6 | ||
|
|
eeac10c66f | ||
|
|
e9d16a80d4 | ||
|
|
dcae074b55 | ||
|
|
472eba7977 | ||
|
|
6a398d9ba0 | ||
|
|
f28aa2df8b | ||
|
|
754da9f931 | ||
|
|
df2a8fa1e3 | ||
|
|
dc159a35d0 | ||
|
|
2378ca80b9 | ||
|
|
79ff1f0d33 | ||
|
|
6a36971406 | ||
|
|
714fcb4b18 | ||
|
|
712acf3541 | ||
|
|
df89c9716c | ||
|
|
66e8ddb2d9 | ||
|
|
5b197288bc | ||
|
|
a9f098097c | ||
|
|
a0f6a5aec3 | ||
|
|
633b99f818 | ||
|
|
5d32392844 | ||
|
|
50e714e5f8 | ||
|
|
e0bc75826f | ||
|
|
3d13e761f4 | ||
|
|
3c824bfc92 | ||
|
|
9ea541a1b4 | ||
|
|
b89604edc3 | ||
|
|
4e6445fea8 | ||
|
|
10b57ca516 | ||
|
|
e8329f2587 | ||
|
|
014aa028d7 | ||
|
|
b47f778fc1 | ||
|
|
c7eaffda00 | ||
|
|
69e1e869a5 | ||
|
|
1a284080e8 | ||
|
|
3490e7ba44 | ||
|
|
d059c3d72d | ||
|
|
33499beb32 | ||
|
|
38c81ae182 | ||
|
|
a8ceb258b8 | ||
|
|
7e5a6fac9f | ||
|
|
b7ba521c59 | ||
|
|
55ebd21975 | ||
|
|
2b2a135bd5 | ||
|
|
a400b0464d | ||
|
|
2d9be85b09 | ||
|
|
33b9f0150e | ||
|
|
48d0dc50f7 | ||
|
|
cdb34a3cbf |
@@ -1,6 +1,9 @@
|
|||||||
.pio
|
.pio
|
||||||
.vscode
|
.vscode
|
||||||
|
.vscode/*
|
||||||
|
.vscode/**
|
||||||
compress
|
compress
|
||||||
|
data_gz
|
||||||
platformio.ini
|
platformio.ini
|
||||||
include/wifi_credentials.h
|
include/wifi_credentials.h
|
||||||
include/*.gz.h
|
include/*.gz.h
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "lib/PCA9685-Arduino"]
|
||||||
|
path = lib/PCA9685-Arduino
|
||||||
|
url = https://github.com/NachtRaveVL/PCA9685-Arduino
|
||||||
Vendored
-7
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
|
||||||
// for the documentation about the extensions.json format
|
|
||||||
"recommendations": [
|
|
||||||
"platformio.platformio-ide"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Vendored
-52
@@ -1,52 +0,0 @@
|
|||||||
{
|
|
||||||
"files.associations": {
|
|
||||||
"random": "cpp",
|
|
||||||
"array": "cpp",
|
|
||||||
"*.tcc": "cpp",
|
|
||||||
"deque": "cpp",
|
|
||||||
"list": "cpp",
|
|
||||||
"string": "cpp",
|
|
||||||
"unordered_map": "cpp",
|
|
||||||
"vector": "cpp",
|
|
||||||
"string_view": "cpp",
|
|
||||||
"memory": "cpp",
|
|
||||||
"ranges": "cpp",
|
|
||||||
"initializer_list": "cpp",
|
|
||||||
"utility": "cpp",
|
|
||||||
"atomic": "cpp",
|
|
||||||
"bit": "cpp",
|
|
||||||
"cctype": "cpp",
|
|
||||||
"clocale": "cpp",
|
|
||||||
"cmath": "cpp",
|
|
||||||
"compare": "cpp",
|
|
||||||
"concepts": "cpp",
|
|
||||||
"cstdarg": "cpp",
|
|
||||||
"cstddef": "cpp",
|
|
||||||
"cstdint": "cpp",
|
|
||||||
"cstdio": "cpp",
|
|
||||||
"cstdlib": "cpp",
|
|
||||||
"cstring": "cpp",
|
|
||||||
"cwchar": "cpp",
|
|
||||||
"cwctype": "cpp",
|
|
||||||
"map": "cpp",
|
|
||||||
"set": "cpp",
|
|
||||||
"exception": "cpp",
|
|
||||||
"algorithm": "cpp",
|
|
||||||
"functional": "cpp",
|
|
||||||
"iterator": "cpp",
|
|
||||||
"memory_resource": "cpp",
|
|
||||||
"numeric": "cpp",
|
|
||||||
"optional": "cpp",
|
|
||||||
"system_error": "cpp",
|
|
||||||
"tuple": "cpp",
|
|
||||||
"type_traits": "cpp",
|
|
||||||
"iosfwd": "cpp",
|
|
||||||
"limits": "cpp",
|
|
||||||
"new": "cpp",
|
|
||||||
"ostream": "cpp",
|
|
||||||
"stdexcept": "cpp",
|
|
||||||
"streambuf": "cpp",
|
|
||||||
"cinttypes": "cpp",
|
|
||||||
"typeinfo": "cpp"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os, gzip
|
||||||
|
# https://www.mischianti.org/2020/10/26/web-server-with-esp8266-and-esp32-byte-array-gzipped-pages-and-spiffs-2/
|
||||||
|
|
||||||
|
def convert_to_gzip(src, out, f):
|
||||||
|
input_file = f'{src}{f}'
|
||||||
|
output_file = f'{out}{f}.gz.h'
|
||||||
|
output_charp = f'{f.replace(".", "_")}_gz'
|
||||||
|
|
||||||
|
top = ''
|
||||||
|
with open(input_file, 'rb') as f_in:
|
||||||
|
gz = gzip.compress(f_in.read())
|
||||||
|
gzlen = len(gz)
|
||||||
|
|
||||||
|
top += f'// filename: {f}.gz.h\n'
|
||||||
|
top += f'#define {output_charp}_len {gzlen}\n'
|
||||||
|
top += f'const char {output_charp}[] = '
|
||||||
|
top += '{'
|
||||||
|
|
||||||
|
with open(output_file, 'wb') as f_out:
|
||||||
|
for i, b in enumerate(gz):
|
||||||
|
if not i%10:
|
||||||
|
top += '\n '
|
||||||
|
top += f'0x{b:02X}, '
|
||||||
|
top = top[:-2]
|
||||||
|
top += '};'
|
||||||
|
f_out.write(top.encode(encoding='utf-8'))
|
||||||
|
|
||||||
|
|
||||||
|
src='data/'
|
||||||
|
out='compress/'
|
||||||
|
|
||||||
|
if not 'compress' in os.listdir():
|
||||||
|
os.mkdir('compress')
|
||||||
|
|
||||||
|
for f in os.listdir(src):
|
||||||
|
convert_to_gzip(src, out, f)
|
||||||
+9
-32
@@ -1,38 +1,15 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import os, gzip
|
import os, gzip
|
||||||
# https://www.mischianti.org/2020/10/26/web-server-with-esp8266-and-esp32-byte-array-gzipped-pages-and-spiffs-2/
|
# https://stackoverflow.com/questions/8156707/gzip-a-file-in-python
|
||||||
|
|
||||||
def convert_to_gzip(src, out, f):
|
src_dir='data'
|
||||||
input_file = f'{src}{f}'
|
out_dir='data_gz'
|
||||||
output_file = f'{out}{f}.gz.h'
|
|
||||||
output_charp = f'{f.replace(".", "_")}_gz'
|
|
||||||
|
|
||||||
top = ''
|
if not 'data_gz' in os.listdir():
|
||||||
with open(input_file, 'rb') as f_in:
|
os.mkdir('data_gz')
|
||||||
gz = gzip.compress(f_in.read())
|
|
||||||
gzlen = len(gz)
|
|
||||||
|
|
||||||
top += f'// filename: {f}.gz.h\n'
|
for f in os.listdir(src_dir):
|
||||||
top += f'#define {output_charp}_len {gzlen}\n'
|
with open(f'{src_dir}/{f}', 'rb') as f_in:
|
||||||
top += f'const char {output_charp}[] = '
|
with gzip.open(f'{out_dir}/{f}.gz', 'wb') as f_out:
|
||||||
top += '{'
|
f_out.writelines(f_in)
|
||||||
|
|
||||||
with open(output_file, 'wb') as f_out:
|
|
||||||
for i, b in enumerate(gz):
|
|
||||||
if not i%10:
|
|
||||||
top += '\n '
|
|
||||||
top += f'0x{b:02X}, '
|
|
||||||
top = top[:-2]
|
|
||||||
top += '};'
|
|
||||||
f_out.write(top.encode(encoding='utf-8'))
|
|
||||||
|
|
||||||
|
|
||||||
src='data/'
|
|
||||||
out='compress/'
|
|
||||||
|
|
||||||
if not 'compress' in os.listdir():
|
|
||||||
os.mkdir('compress')
|
|
||||||
|
|
||||||
for f in os.listdir(src):
|
|
||||||
convert_to_gzip(src, out, f)
|
|
||||||
@@ -60,6 +60,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="terminal">
|
||||||
|
<input type="button" id="clear_term" value="clear" onclick="clearTerminal();">
|
||||||
|
<input type="checkbox" id="scroll" name="scroll" value="scroll" checked>
|
||||||
|
<label for="scroll"> autoscroll </label>
|
||||||
|
<textarea id="term">waiting for log messages ... </textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
<script src="/input.js"></script>
|
<script src="/input.js"></script>
|
||||||
|
|||||||
+38
-6
@@ -1,8 +1,40 @@
|
|||||||
var slider = document.getElementById("range1");
|
// var slider = document.getElementById("helligkeit");
|
||||||
var output = document.getElementById("l_pwm");
|
// var output = document.getElementById("l_pwm");
|
||||||
output.innerHTML = slider.value; // Display the default slider value
|
// output.innerHTML = slider.value; // Display the default slider value
|
||||||
|
|
||||||
// Update the current slider value (each time you drag the slider handle)
|
// // Update the current slider value (each time you drag the slider handle)
|
||||||
slider.oninput = function() {
|
// slider.oninput = function() {
|
||||||
output.innerHTML = this.value;
|
// output.innerHTML = this.value;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 {
|
||||||
|
console.log("status:", xhr.status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function reloadTerminal() {
|
||||||
|
xhr.open("POST", "/app=terminal", true);
|
||||||
|
xhr.send();
|
||||||
|
setTimeout(reloadTerminal, 1000);
|
||||||
|
};
|
||||||
|
|
||||||
|
reloadTerminal();
|
||||||
|
|
||||||
|
function clearTerminal() {
|
||||||
|
document.getElementById("term").innerHTML = '';
|
||||||
}
|
}
|
||||||
+19
-3
@@ -3,7 +3,7 @@ html {
|
|||||||
font-family: sans-serif, Arial, Helvetica;
|
font-family: sans-serif, Arial, Helvetica;
|
||||||
background-color: #d4d4d4;
|
background-color: #d4d4d4;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background-image: url('Background.png');
|
/* background-image: url('Background.png'); */
|
||||||
background-repeat: repeat;
|
background-repeat: repeat;
|
||||||
background-size: 150% 150%;
|
background-size: 150% 150%;
|
||||||
}
|
}
|
||||||
@@ -67,8 +67,6 @@ input[type=range]::-webkit-slider-thumb{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------*/
|
/*-------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
@@ -103,4 +101,22 @@ input:checked + .slider:before {
|
|||||||
-ms-transform: translateX(26px);
|
-ms-transform: translateX(26px);
|
||||||
transform: translateX(26px);
|
transform: translateX(26px);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
.terminal {
|
||||||
|
margin:5%;
|
||||||
|
padding: 1%;
|
||||||
|
width: 80%;
|
||||||
|
border: 1px solid black;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#term {
|
||||||
|
font-size: large;
|
||||||
|
width: 100%;
|
||||||
|
height: 20em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#clear_term {
|
||||||
|
margin: 2px;
|
||||||
|
}
|
||||||
@@ -54,6 +54,12 @@ else
|
|||||||
server.streamFile(f, mime::getContentType(SRH::_path), requestMethod);
|
server.streamFile(f, mime::getContentType(SRH::_path), requestMethod);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
LED_sequence_v1:
|
||||||
|
TODO:
|
||||||
|
- disable led stripes after defined time (webserver paramter?)
|
||||||
|
- define what to do if people enter stairs from different directions
|
||||||
|
- CAUTION: Sensor-Deadtime at LEAST 8 seconds
|
||||||
|
- --> switch off with person leaving stairs might not be possible
|
||||||
|
|
||||||
Webserver on v0.3.0 now working with LittleFS
|
Webserver on v0.3.0 now working with LittleFS
|
||||||
TODO:
|
TODO:
|
||||||
@@ -62,7 +68,19 @@ TODO:
|
|||||||
- maybe compress files ?
|
- maybe compress files ?
|
||||||
|
|
||||||
|
|
||||||
LED Flickering issue
|
### LED Flickering issue
|
||||||
https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
||||||
|
PlatformIO Library veraltet !!
|
||||||
|
|
||||||
PlatformIO Library veraltet
|
|
||||||
|
### TIMER in OTA unterbrechen !!!!!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### further improvments
|
||||||
|
with streamFile gzip encoded Files can be sent
|
||||||
|
this reduces space on fs !
|
||||||
|
new easier script needed to just convert to .gz
|
||||||
|
maybe measure timings on ESP
|
||||||
|
|
||||||
|
__=> use serveStatic because way simpler !__
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
#ifndef __HTTPSERVER_H
|
|
||||||
#define __HTTPSERVER_H
|
|
||||||
|
|
||||||
#include "filesys.h"
|
|
||||||
#include <ESP8266WebServer.h>
|
|
||||||
|
|
||||||
|
|
||||||
class HTTPServer : public ESP8266WebServer {
|
|
||||||
private:
|
|
||||||
const char* rootDir;
|
|
||||||
|
|
||||||
bool addRootFileHandler();
|
|
||||||
bool formatFS() {
|
|
||||||
return format_fs();
|
|
||||||
}
|
|
||||||
void listRoot() {
|
|
||||||
ls(rootDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
HTTPServer(const int _port, const char* _rootDir) :
|
|
||||||
ESP8266WebServer(_port), rootDir(_rootDir)
|
|
||||||
{ }
|
|
||||||
~HTTPServer()
|
|
||||||
{
|
|
||||||
Serial.printf("[HTTPServer] shut down ...\n\r");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool start() {
|
|
||||||
if(!mount_fs())
|
|
||||||
return false;
|
|
||||||
Serial.printf("[HTTPServer] LittleFS mounted !\n\r");
|
|
||||||
|
|
||||||
Serial.printf("[HTTPServer] root:\n\r");
|
|
||||||
this->listRoot();
|
|
||||||
Serial.printf("\n\r");
|
|
||||||
|
|
||||||
if( this->addRootFileHandler() ){
|
|
||||||
this->begin();
|
|
||||||
Serial.printf("[HTTPServer] Server active on Port 80 !\n\r");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Serial.printf("[HTTPServer] Not starting Server, something went wrong !\n\r");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // __HTTPSERVER_H
|
|
||||||
+5
-5
@@ -1,5 +1,8 @@
|
|||||||
#ifndef __OTA_H
|
#pragma once
|
||||||
#define __OTA_H
|
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <WiFiUdp.h>
|
||||||
|
#include <ArduinoOTA.h>
|
||||||
|
|
||||||
void ota_setup() {
|
void ota_setup() {
|
||||||
ArduinoOTA.setPort(8266);
|
ArduinoOTA.setPort(8266);
|
||||||
@@ -43,6 +46,3 @@ void ota_setup() {
|
|||||||
ArduinoOTA.begin();
|
ArduinoOTA.begin();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // __OTA_H
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "PCA9685.h"
|
|
||||||
|
|
||||||
class Treppe {
|
|
||||||
private:
|
|
||||||
uint8_t stairs;
|
|
||||||
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
|
|
||||||
uint16_t idle_brightness = 200;
|
|
||||||
uint16_t active_brightness = 2048;
|
|
||||||
|
|
||||||
uint8_t direction = 0;
|
|
||||||
uint8_t state = 0;
|
|
||||||
uint8_t switch_state = 0;
|
|
||||||
|
|
||||||
|
|
||||||
PCA9685 pwmController;
|
|
||||||
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
|
|
||||||
void ledsequence();
|
|
||||||
|
|
||||||
public:
|
|
||||||
Treppe(uint8_t _stairs) : stairs(_stairs){}
|
|
||||||
void task(); // call periodically
|
|
||||||
|
|
||||||
void setup();
|
|
||||||
|
|
||||||
// Parameter section
|
|
||||||
uint16_t setIdle(uint16_t _idle_brightness);
|
|
||||||
uint16_t setActive(uint16_t _active_brightness);
|
|
||||||
uint16_t setTime(uint16_t _time_per_stair);
|
|
||||||
|
|
||||||
// Runtime Parameter section
|
|
||||||
uint8_t setDirection(uint8_t _direction);
|
|
||||||
uint8_t setState(uint8_t _state);
|
|
||||||
|
|
||||||
uint8_t getState() { return state;};
|
|
||||||
uint8_t getDirection() {return direction;};
|
|
||||||
};
|
|
||||||
Submodule
+1
Submodule lib/PCA9685-Arduino added at a70be39257
-46
@@ -1,46 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project specific (private) libraries.
|
|
||||||
PlatformIO will compile them to static libraries and link into executable file.
|
|
||||||
|
|
||||||
The source code of each library should be placed in a an own separate directory
|
|
||||||
("lib/your_library_name/[here are source files]").
|
|
||||||
|
|
||||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
|
||||||
|
|
||||||
|--lib
|
|
||||||
| |
|
|
||||||
| |--Bar
|
|
||||||
| | |--docs
|
|
||||||
| | |--examples
|
|
||||||
| | |--src
|
|
||||||
| | |- Bar.c
|
|
||||||
| | |- Bar.h
|
|
||||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
|
||||||
| |
|
|
||||||
| |--Foo
|
|
||||||
| | |- Foo.c
|
|
||||||
| | |- Foo.h
|
|
||||||
| |
|
|
||||||
| |- README --> THIS FILE
|
|
||||||
|
|
|
||||||
|- platformio.ini
|
|
||||||
|--src
|
|
||||||
|- main.c
|
|
||||||
|
|
||||||
and a contents of `src/main.c`:
|
|
||||||
```
|
|
||||||
#include <Foo.h>
|
|
||||||
#include <Bar.h>
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
PlatformIO Library Dependency Finder will find automatically dependent
|
|
||||||
libraries scanning project source files.
|
|
||||||
|
|
||||||
More information about PlatformIO Library Dependency Finder
|
|
||||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
|
||||||
@@ -1,12 +1,5 @@
|
|||||||
#include "filesys.h"
|
#include "filesys.h"
|
||||||
|
|
||||||
// listDir("/");
|
|
||||||
// deleteFile("/hello.txt");
|
|
||||||
// writeFile("/hello.txt", "Hello ");
|
|
||||||
// appendFile("/hello.txt", "World!\n\r");
|
|
||||||
// readFile("/hello.txt");
|
|
||||||
// listDir("/");
|
|
||||||
|
|
||||||
FSInfo fsinfo;
|
FSInfo fsinfo;
|
||||||
|
|
||||||
bool mount_fs() {
|
bool mount_fs() {
|
||||||
@@ -58,7 +51,12 @@ void ls(const char * dirname) {
|
|||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void readFile(const char * path) {
|
File open(const char * path) {
|
||||||
|
return LittleFS.open(path, "r");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void printFile(const char * path) {
|
||||||
Serial.printf("Reading file: %s\n\r", path);
|
Serial.printf("Reading file: %s\n\r", path);
|
||||||
|
|
||||||
File file = LittleFS.open(path, "r");
|
File file = LittleFS.open(path, "r");
|
||||||
@@ -1,16 +1,17 @@
|
|||||||
#ifndef __FILESYS_H
|
#pragma once
|
||||||
#define __FILESYS_H
|
|
||||||
|
|
||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
|
|
||||||
|
// some usefull wrappers for Filesystem
|
||||||
|
|
||||||
bool mount_fs();
|
bool mount_fs();
|
||||||
bool format_fs();
|
bool format_fs();
|
||||||
|
|
||||||
|
File open(const char * path);
|
||||||
|
|
||||||
void ls(const char * dirname);
|
void ls(const char * dirname);
|
||||||
void readFile(const char * path);
|
void printFile(const char * path);
|
||||||
void writeFile(const char * path, const char * message);
|
void writeFile(const char * path, const char * message);
|
||||||
void appendFile(const char * path, const char * message);
|
void appendFile(const char * path, const char * message);
|
||||||
void renameFile(const char * path1, const char * path2);
|
void renameFile(const char * path1, const char * path2);
|
||||||
void deleteFile(const char * path);
|
void deleteFile(const char * path);
|
||||||
|
|
||||||
#endif // __FILESYS_H
|
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
#include "httpserver.h"
|
||||||
|
|
||||||
|
|
||||||
|
bool HTTPServer::start() {
|
||||||
|
if(!mount_fs()) {
|
||||||
|
logf("cant mount filesystem, EXIT !\n\r");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
logf("LittleFS mounted !\n\r");
|
||||||
|
logf("root:\n\r");
|
||||||
|
this->listRoot();
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
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() {
|
||||||
|
// application handler
|
||||||
|
this->on("/app=terminal", HTTP_POST, [this]() {
|
||||||
|
if(tbuf_head) {
|
||||||
|
send(200, "text/plain", tbuf);
|
||||||
|
tbuf_head = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// Wrapper for ESP8266WebServer with Filesystem as HTTP source
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <ESP8266WebServer.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include "filesys.h"
|
||||||
|
|
||||||
|
// debug log <ESP8266WebServer.h>
|
||||||
|
// #define DEBUGV(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0)
|
||||||
|
|
||||||
|
#define TBUF_LEN 256
|
||||||
|
|
||||||
|
|
||||||
|
class HTTPServer : public ESP8266WebServer {
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char* rootDir = "/";
|
||||||
|
const char* log_prefix = "[HTTPServer] ";
|
||||||
|
|
||||||
|
size_t tbuf_head = 0;
|
||||||
|
char tbuf[TBUF_LEN];
|
||||||
|
|
||||||
|
void listRoot() {
|
||||||
|
ls(rootDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
HTTPServer(const int _port, const char* _rootDir) :
|
||||||
|
ESP8266WebServer(_port), rootDir(_rootDir)
|
||||||
|
{ }
|
||||||
|
~HTTPServer()
|
||||||
|
{
|
||||||
|
Serial.printf("[HTTPServer] shut down ...\n\r");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool start();
|
||||||
|
void start_apps();
|
||||||
|
|
||||||
|
void logf(const char *format, ...);
|
||||||
|
void logt(const char *format, ...);
|
||||||
|
};
|
||||||
@@ -0,0 +1,237 @@
|
|||||||
|
//
|
||||||
|
// Academic License - for use in teaching, academic research, and meeting
|
||||||
|
// course requirements at degree granting institutions only. Not for
|
||||||
|
// government, commercial, or other organizational use.
|
||||||
|
//
|
||||||
|
// File: FSMTreppe.cpp
|
||||||
|
//
|
||||||
|
// Code generated for Simulink model 'FSMTreppe'.
|
||||||
|
//
|
||||||
|
// Model version : 1.29
|
||||||
|
// Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
|
||||||
|
// C/C++ source code generated on : Sat Jul 3 17:39:25 2021
|
||||||
|
//
|
||||||
|
// Target selection: ert.tlc
|
||||||
|
// Embedded hardware selection: ARM Compatible->ARM Cortex-M
|
||||||
|
// Code generation objectives: Unspecified
|
||||||
|
// Validation result: Not run
|
||||||
|
//
|
||||||
|
#include "FSMTreppe2.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// Named constants for Chart: '<Root>/FSMTreppe'
|
||||||
|
const uint8_t FSMTreppe_IN_abdimmen_hoch = 1U;
|
||||||
|
const uint8_t FSMTreppe_IN_abdimmen_runter = 2U;
|
||||||
|
const uint8_t FSMTreppe_IN_aufdimmen_hoch = 3U;
|
||||||
|
const uint8_t FSMTreppe_IN_aufdimmen_runter = 4U;
|
||||||
|
const uint8_t FSMTreppe_IN_inaktiv = 5U;
|
||||||
|
const uint8_t FSMTreppe_IN_ruhezustand = 6U;
|
||||||
|
const uint8_t FSMTreppe_IN_warten_hoch = 7U;
|
||||||
|
const uint8_t FSMTreppe_IN_warten_runter = 8U;
|
||||||
|
|
||||||
|
// Model step function
|
||||||
|
void FSMTreppeModelClass::step()
|
||||||
|
{
|
||||||
|
// Chart: '<Root>/FSMTreppe' incorporates:
|
||||||
|
// Inport: '<Root>/anim_beendet'
|
||||||
|
// Inport: '<Root>/ldr_schwelle'
|
||||||
|
// Inport: '<Root>/sensor_oben'
|
||||||
|
// Inport: '<Root>/sensor_unten'
|
||||||
|
|
||||||
|
if (FSMTreppe_DW.temporalCounter_i1 < 511U) {
|
||||||
|
FSMTreppe_DW.temporalCounter_i1 = static_cast<uint16_t>
|
||||||
|
(FSMTreppe_DW.temporalCounter_i1 + 1U);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FSMTreppe_DW.is_active_c3_FSMTreppe == 0U) {
|
||||||
|
FSMTreppe_DW.is_active_c3_FSMTreppe = 1U;
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_inaktiv;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 0U;
|
||||||
|
} else {
|
||||||
|
switch (FSMTreppe_DW.is_c3_FSMTreppe) {
|
||||||
|
case FSMTreppe_IN_abdimmen_hoch:
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 4U;
|
||||||
|
if (FSMTreppe_U.anim_beendet || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
||||||
|
{
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_ruhezustand;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 1U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSMTreppe_IN_abdimmen_runter:
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 7U;
|
||||||
|
if (FSMTreppe_U.anim_beendet || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
||||||
|
{
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_ruhezustand;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 1U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSMTreppe_IN_aufdimmen_hoch:
|
||||||
|
// Outport: '<Root>/laufrichtung'
|
||||||
|
FSMTreppe_Y.laufrichtung = 1U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 1U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 2U;
|
||||||
|
if (FSMTreppe_U.anim_beendet || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
||||||
|
{
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_warten_hoch;
|
||||||
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 3U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSMTreppe_IN_aufdimmen_runter:
|
||||||
|
// Outport: '<Root>/laufrichtung'
|
||||||
|
FSMTreppe_Y.laufrichtung = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 1U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 5U;
|
||||||
|
if (FSMTreppe_U.anim_beendet || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
||||||
|
{
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_warten_runter;
|
||||||
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 6U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSMTreppe_IN_inaktiv:
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 0U;
|
||||||
|
if (FSMTreppe_U.ldr_schwelle == 1.0) {
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_ruhezustand;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 1U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSMTreppe_IN_ruhezustand:
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 1U;
|
||||||
|
if (FSMTreppe_U.sensor_unten) {
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_aufdimmen_hoch;
|
||||||
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/laufrichtung'
|
||||||
|
FSMTreppe_Y.laufrichtung = 1U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 1U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 2U;
|
||||||
|
} else if (FSMTreppe_U.sensor_oben) {
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_aufdimmen_runter;
|
||||||
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/laufrichtung'
|
||||||
|
FSMTreppe_Y.laufrichtung = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 1U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 5U;
|
||||||
|
} else if (FSMTreppe_U.ldr_schwelle == 0.0) {
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_inaktiv;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 0U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSMTreppe_IN_warten_hoch:
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 3U;
|
||||||
|
if (FSMTreppe_U.sensor_oben || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
||||||
|
{
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_abdimmen_hoch;
|
||||||
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 4U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
// case IN_warten_runter:
|
||||||
|
FSMTreppe_Y.status = 6U;
|
||||||
|
if (FSMTreppe_U.sensor_unten || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
||||||
|
{
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_abdimmen_runter;
|
||||||
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 7U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// End of Chart: '<Root>/FSMTreppe'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Model initialize function
|
||||||
|
void FSMTreppeModelClass::initialize()
|
||||||
|
{
|
||||||
|
// (no initialization code required)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Model terminate function
|
||||||
|
void FSMTreppeModelClass::terminate()
|
||||||
|
{
|
||||||
|
// (no terminate code required)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
FSMTreppeModelClass::FSMTreppeModelClass() :
|
||||||
|
FSMTreppe_DW(),
|
||||||
|
FSMTreppe_U(),
|
||||||
|
FSMTreppe_Y()
|
||||||
|
{
|
||||||
|
// Currently there is no constructor body generated.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
FSMTreppeModelClass::~FSMTreppeModelClass()
|
||||||
|
{
|
||||||
|
// Currently there is no destructor body generated.
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// File trailer for generated code.
|
||||||
|
//
|
||||||
|
// [EOF]
|
||||||
|
//
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
//
|
||||||
|
// Academic License - for use in teaching, academic research, and meeting
|
||||||
|
// course requirements at degree granting institutions only. Not for
|
||||||
|
// government, commercial, or other organizational use.
|
||||||
|
//
|
||||||
|
// File: FSMTreppe.h
|
||||||
|
//
|
||||||
|
// Code generated for Simulink model 'FSMTreppe'.
|
||||||
|
//
|
||||||
|
// Model version : 1.28
|
||||||
|
// Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
|
||||||
|
// C/C++ source code generated on : Sat Jul 3 13:50:17 2021
|
||||||
|
//
|
||||||
|
// Target selection: ert.tlc
|
||||||
|
// Embedded hardware selection: ARM Compatible->ARM Cortex-M
|
||||||
|
// Code generation objectives: Unspecified
|
||||||
|
// Validation result: Not run
|
||||||
|
//
|
||||||
|
#ifndef RTW_HEADER_FSMTreppe_h_
|
||||||
|
#define RTW_HEADER_FSMTreppe_h_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// Class declaration for model FSMTreppe
|
||||||
|
class FSMTreppeModelClass {
|
||||||
|
// public data and function members
|
||||||
|
public:
|
||||||
|
// Block states (default storage) for system '<Root>'
|
||||||
|
struct DW_FSMTreppe_T {
|
||||||
|
uint16_t temporalCounter_i1; // '<Root>/FSMTreppe'
|
||||||
|
uint8_t is_active_c3_FSMTreppe; // '<Root>/FSMTreppe'
|
||||||
|
uint8_t is_c3_FSMTreppe; // '<Root>/FSMTreppe'
|
||||||
|
};
|
||||||
|
|
||||||
|
// External inputs (root inport signals with default storage)
|
||||||
|
struct ExtU_FSMTreppe_T {
|
||||||
|
bool sensor_unten; // '<Root>/sensor_unten'
|
||||||
|
bool sensor_oben; // '<Root>/sensor_oben'
|
||||||
|
bool anim_beendet; // '<Root>/anim_beendet'
|
||||||
|
double ldr_schwelle; // '<Root>/ldr_schwelle'
|
||||||
|
};
|
||||||
|
|
||||||
|
// External outputs (root outports fed by signals with default storage)
|
||||||
|
struct ExtY_FSMTreppe_T {
|
||||||
|
uint8_t laufrichtung; // '<Root>/laufrichtung'
|
||||||
|
uint8_t status; // '<Root>/status'
|
||||||
|
uint8_t dimmrichtung; // '<Root>/dimmrichtung'
|
||||||
|
};
|
||||||
|
|
||||||
|
// model initialize function
|
||||||
|
void initialize();
|
||||||
|
|
||||||
|
// model step function
|
||||||
|
void step();
|
||||||
|
|
||||||
|
// model terminate function
|
||||||
|
void terminate();
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
FSMTreppeModelClass();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~FSMTreppeModelClass();
|
||||||
|
|
||||||
|
// Root-level structure-based inputs set method
|
||||||
|
|
||||||
|
// Root inports set method
|
||||||
|
void setExternalInputs(const ExtU_FSMTreppe_T* pExtU_FSMTreppe_T)
|
||||||
|
{
|
||||||
|
FSMTreppe_U = *pExtU_FSMTreppe_T;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Root-level structure-based outputs get method
|
||||||
|
|
||||||
|
// Root outports get method
|
||||||
|
const FSMTreppeModelClass::ExtY_FSMTreppe_T & getExternalOutputs() const
|
||||||
|
{
|
||||||
|
return FSMTreppe_Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// private data and function members
|
||||||
|
private:
|
||||||
|
// Block states
|
||||||
|
DW_FSMTreppe_T FSMTreppe_DW;
|
||||||
|
|
||||||
|
// External inputs
|
||||||
|
ExtU_FSMTreppe_T FSMTreppe_U;
|
||||||
|
|
||||||
|
// External outputs
|
||||||
|
ExtY_FSMTreppe_T FSMTreppe_Y;
|
||||||
|
};
|
||||||
|
|
||||||
|
//-
|
||||||
|
// The generated code includes comments that allow you to trace directly
|
||||||
|
// back to the appropriate location in the model. The basic format
|
||||||
|
// is <system>/block_name, where system is the system number (uniquely
|
||||||
|
// assigned by Simulink) and block_name is the name of the block.
|
||||||
|
//
|
||||||
|
// Note that this particular code originates from a subsystem build,
|
||||||
|
// and has its own system numbers different from the parent model.
|
||||||
|
// Refer to the system hierarchy for this subsystem below, and use the
|
||||||
|
// MATLAB hilite_system command to trace the generated code back
|
||||||
|
// to the parent model. For example,
|
||||||
|
//
|
||||||
|
// hilite_system('FSM_Treppenlicht/FSMTreppe') - opens subsystem FSM_Treppenlicht/FSMTreppe
|
||||||
|
// hilite_system('FSM_Treppenlicht/FSMTreppe/Kp') - opens and selects block Kp
|
||||||
|
//
|
||||||
|
// Here is the system hierarchy for this model
|
||||||
|
//
|
||||||
|
// '<Root>' : 'FSM_Treppenlicht'
|
||||||
|
// '<S1>' : 'FSM_Treppenlicht/FSMTreppe'
|
||||||
|
|
||||||
|
#endif // RTW_HEADER_FSMTreppe_h_
|
||||||
|
|
||||||
|
//
|
||||||
|
// File trailer for generated code.
|
||||||
|
//
|
||||||
|
// [EOF]
|
||||||
|
//
|
||||||
@@ -0,0 +1,242 @@
|
|||||||
|
#include "treppe.h"
|
||||||
|
|
||||||
|
uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){
|
||||||
|
/*
|
||||||
|
softstart task
|
||||||
|
|
||||||
|
- get's called at regular intervals (1ms at the moment)
|
||||||
|
- dimms single led (0 - 15, PCA9685 outputs) with linear intervals vom startval to stopval
|
||||||
|
- calculates pwm steps depending on startval, stopval and timeinterval
|
||||||
|
- -> results in constanst speed
|
||||||
|
- returns 1 if led dimming is running
|
||||||
|
- returns 0 if led dimming is finished
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
static uint8_t lastled = 255;
|
||||||
|
static float current_pwm = 0;
|
||||||
|
static float stepsize = 1.0;
|
||||||
|
if(led != lastled){
|
||||||
|
pwmController.setChannelPWM(led, (uint16_t)startval);
|
||||||
|
lastled = led;
|
||||||
|
current_pwm = startval;
|
||||||
|
stepsize = INT_TIME*abs(stopval - startval)/(float)time_per_stair; // only valid at 1ms function call interval
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(startval > stopval){
|
||||||
|
current_pwm -= stepsize;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
current_pwm += stepsize;
|
||||||
|
}
|
||||||
|
// Serial.println((uint16_t)current_pwm);
|
||||||
|
pwmController.setChannelPWM(led, (uint16_t)current_pwm);
|
||||||
|
if(current_pwm > stopval - stepsize && current_pwm < stopval + stepsize){
|
||||||
|
if(stopval == 0) pwmController.setChannelPWM(led, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Treppe::ledsequence(){
|
||||||
|
static int8_t led = 0;
|
||||||
|
static uint16_t brightness = 0;
|
||||||
|
static uint16_t lastbrightness = 0;
|
||||||
|
static uint16_t status = 0;
|
||||||
|
uint16_t status_build = 0;
|
||||||
|
status_build |= direction << 8;
|
||||||
|
status_build |= state;
|
||||||
|
if(status_build != status){ // check if any parameter changed
|
||||||
|
finish = 0; // set state unfinished -> start action
|
||||||
|
if(direction) led = 0; // reset led counter depending of direction
|
||||||
|
else led = stairs-1;
|
||||||
|
if(state){
|
||||||
|
brightness = active_brightness; // set brightness value depending of on/off
|
||||||
|
lastbrightness = idle_brightness;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
brightness = idle_brightness;
|
||||||
|
lastbrightness = active_brightness;
|
||||||
|
}
|
||||||
|
status = status_build; // set parameter memory
|
||||||
|
|
||||||
|
Serial.printf("----Status Changed! onoff: %d, dir: %d\n", state, direction);
|
||||||
|
}
|
||||||
|
if(!finish){ // finish == 0 -> action pending
|
||||||
|
if(!softstart_led(led,lastbrightness, brightness)){
|
||||||
|
Serial.printf("one LED finished: led: %d, last: %d, curr %d\n",
|
||||||
|
led, lastbrightness, brightness);
|
||||||
|
|
||||||
|
if(direction){
|
||||||
|
led++;
|
||||||
|
if(led >= stairs)
|
||||||
|
finish = 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
led--;
|
||||||
|
if(led < 0)
|
||||||
|
finish = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Treppe::rampe()
|
||||||
|
{
|
||||||
|
if(state) {
|
||||||
|
finish = 0;
|
||||||
|
state = 0;// set parameter memory
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!finish) {
|
||||||
|
if(direction) { // aufwärts
|
||||||
|
if(tick >= ticks_treppe-1) { // ziel erreicht
|
||||||
|
Serial.println("[Treppe] oberster tick !");
|
||||||
|
finish = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tick++; // eins hoch
|
||||||
|
}
|
||||||
|
else { // abwärts
|
||||||
|
if(tick <= 0) { // ziel erreicht
|
||||||
|
Serial.println("[Treppe] unterster tick !");
|
||||||
|
finish = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tick--; // eins runter
|
||||||
|
}
|
||||||
|
|
||||||
|
stufe = tick / ticks_pro_stufe;
|
||||||
|
|
||||||
|
float new_pwm = 0.0;
|
||||||
|
if(an_aus) {
|
||||||
|
new_pwm = differenz_pwm_pro_tick * (tick - ticks_pro_stufe*stufe);
|
||||||
|
new_pwm += idle_brightness;
|
||||||
|
if(direction) new_pwm += differenz_pwm_pro_tick;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new_pwm = active_brightness - differenz_pwm_pro_tick * (tick - ticks_pro_stufe*stufe);
|
||||||
|
new_pwm += idle_brightness;
|
||||||
|
if(direction) new_pwm -= differenz_pwm_pro_tick;
|
||||||
|
}
|
||||||
|
|
||||||
|
pwmController.setChannelPWM(stufe, (uint16_t) new_pwm);
|
||||||
|
Serial.printf("tick %04u, led %02d:%02u, pwm %4.1f\n",
|
||||||
|
tick,
|
||||||
|
stufe,
|
||||||
|
(tick - ticks_pro_stufe*stufe),
|
||||||
|
new_pwm
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Treppe::setup(){
|
||||||
|
|
||||||
|
pwmController.resetDevices();
|
||||||
|
// Deactive PCA9685 Phase Balancer due to LED Flickering
|
||||||
|
// https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
||||||
|
// see also lib/PCA9685-Arduin/PCA9685.h:204
|
||||||
|
pwmController.init(PCA9685_PhaseBalancer_None);
|
||||||
|
//pwmController.init(PCA9685_PhaseBalancer_Linear);
|
||||||
|
pwmController.setPWMFrequency(100);
|
||||||
|
pwmController.setAllChannelsPWM(idle_brightness);
|
||||||
|
|
||||||
|
pinMode(A0, INPUT);
|
||||||
|
pinMode(SENSOR_OBEN, INPUT);
|
||||||
|
pinMode(SENSOR_UNTEN, INPUT);
|
||||||
|
pinMode(OE, OUTPUT);
|
||||||
|
digitalWrite(OE, 0);
|
||||||
|
|
||||||
|
Serial.printf("differenz_pwm_pro_tick %f\n", differenz_pwm_pro_tick);
|
||||||
|
Serial.println("Hello from Treppe");
|
||||||
|
Serial.print("Treppe: initial parameters: stairs=");
|
||||||
|
Serial.println(stairs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Treppe::print_state_on_change() {
|
||||||
|
static FSMTreppeModelClass::ExtU_FSMTreppe_T last_in;
|
||||||
|
static FSMTreppeModelClass::ExtY_FSMTreppe_T last_out;
|
||||||
|
if(
|
||||||
|
fsm_inputs.anim_beendet != last_in.anim_beendet ||
|
||||||
|
fsm_inputs.sensor_oben != last_in.sensor_oben ||
|
||||||
|
fsm_inputs.sensor_unten != last_in.sensor_unten ||
|
||||||
|
fsm_outputs.dimmrichtung != last_out.dimmrichtung ||
|
||||||
|
fsm_outputs.laufrichtung != last_out.laufrichtung ||
|
||||||
|
fsm_outputs.status != last_out.status
|
||||||
|
) {
|
||||||
|
last_in.anim_beendet = fsm_inputs.anim_beendet;
|
||||||
|
last_in.sensor_oben = fsm_inputs.sensor_oben;
|
||||||
|
last_in.sensor_unten = fsm_inputs.sensor_unten;
|
||||||
|
|
||||||
|
Serial.printf("FSM IN: s_u: %d, s_o: %d, beendet: %d =>",
|
||||||
|
fsm_inputs.sensor_oben, fsm_inputs.sensor_unten, fsm_inputs.anim_beendet);
|
||||||
|
Serial.print(" step => ");
|
||||||
|
Serial.printf("OUT: LR: %d DR: %d ST: %d\n",
|
||||||
|
fsm_outputs.laufrichtung, fsm_outputs.dimmrichtung, fsm_outputs.status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Treppe::task(){
|
||||||
|
//Serial.printf("LDR: %f\n", ((float)analogRead(A0))/1023.*3.68);
|
||||||
|
|
||||||
|
if(finish){
|
||||||
|
direction = switch_direction;
|
||||||
|
state = switch_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
fsm_inputs.ldr_schwelle = true;
|
||||||
|
fsm_inputs.sensor_oben = read_sensor(SENSOR_OBEN);
|
||||||
|
fsm_inputs.sensor_unten = read_sensor(SENSOR_UNTEN);
|
||||||
|
fsm_inputs.anim_beendet = static_cast<bool>(finish);
|
||||||
|
|
||||||
|
FSMTreppe_Obj.setExternalInputs(&fsm_inputs);
|
||||||
|
FSMTreppe_Obj.step();
|
||||||
|
fsm_outputs = FSMTreppe_Obj.getExternalOutputs();
|
||||||
|
print_state_on_change();
|
||||||
|
|
||||||
|
direction = fsm_outputs.laufrichtung;
|
||||||
|
state = fsm_outputs.dimmrichtung;
|
||||||
|
|
||||||
|
// setTick(ticks_treppe);
|
||||||
|
// setAnAus(1);
|
||||||
|
// setDirection(0);
|
||||||
|
// setState(0);
|
||||||
|
|
||||||
|
ledsequence();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t Treppe::setIdle(uint16_t _idle_brightness){
|
||||||
|
idle_brightness = _idle_brightness;
|
||||||
|
Serial.println("Treppe: idle brightness changed!");
|
||||||
|
return idle_brightness;
|
||||||
|
}
|
||||||
|
uint16_t Treppe::setActive(uint16_t _active_brightness){
|
||||||
|
active_brightness = _active_brightness;
|
||||||
|
Serial.println("Treppe: active brightness changed!");
|
||||||
|
return active_brightness;
|
||||||
|
}
|
||||||
|
uint16_t Treppe::setTime(uint16_t _time_per_stair){
|
||||||
|
time_per_stair = _time_per_stair;
|
||||||
|
Serial.println("Treppe: time changed!");
|
||||||
|
return time_per_stair;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Treppe::setDirection(uint8_t _direction){
|
||||||
|
switch_direction = _direction;
|
||||||
|
Serial.printf("Treppe: switch_direction=%d!\n", switch_direction);
|
||||||
|
if(finish) Serial.println("apply direction request immediately");
|
||||||
|
else Serial.println("currently active, dir change afterwards");
|
||||||
|
// to do: implement state command variable to determine dimm-state
|
||||||
|
}
|
||||||
|
|
||||||
|
void Treppe::setState(uint8_t _state){
|
||||||
|
if(state == _state) return;
|
||||||
|
else {
|
||||||
|
switch_state = _state;
|
||||||
|
Serial.printf("Treppe: switch_state=%d!\n", switch_state);
|
||||||
|
if(finish) Serial.println("apply state request immediately");
|
||||||
|
else Serial.println("currently active, state changes after activity");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "FSMTreppe/FSMTreppe2.h"
|
||||||
|
#include "PCA9685.h"
|
||||||
|
|
||||||
|
#define SENSOR_OBEN 2
|
||||||
|
#define SENSOR_UNTEN 12
|
||||||
|
#define OE 14
|
||||||
|
|
||||||
|
#define INT_TIME 20 // interrupt intervall [ms]
|
||||||
|
|
||||||
|
class Treppe {
|
||||||
|
private:
|
||||||
|
|
||||||
|
uint8_t stairs;
|
||||||
|
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
|
||||||
|
uint16_t idle_brightness = 100;
|
||||||
|
uint16_t active_brightness = 300;
|
||||||
|
|
||||||
|
uint8_t direction = 0;
|
||||||
|
uint8_t switch_direction = 0;
|
||||||
|
uint8_t state = 0;
|
||||||
|
uint8_t switch_state = 0;
|
||||||
|
bool finish = 1;
|
||||||
|
|
||||||
|
// alternative
|
||||||
|
uint32_t tick = 0;
|
||||||
|
uint32_t stufe = 0;
|
||||||
|
uint8_t an_aus = 0;
|
||||||
|
|
||||||
|
uint32_t ticks_treppe = 0;
|
||||||
|
uint32_t ticks_pro_stufe = 0;
|
||||||
|
float differenz_pwm_pro_tick = 0.0;
|
||||||
|
// alternative
|
||||||
|
|
||||||
|
// initialize with i2c-Address 0, use Wire Library
|
||||||
|
PCA9685 pwmController;
|
||||||
|
FSMTreppeModelClass FSMTreppe_Obj;
|
||||||
|
FSMTreppeModelClass::ExtU_FSMTreppe_T fsm_inputs;
|
||||||
|
FSMTreppeModelClass::ExtY_FSMTreppe_T fsm_outputs;
|
||||||
|
void print_state_on_change();
|
||||||
|
|
||||||
|
const uint8_t FSMTreppe_IN_animation_down = 1U;
|
||||||
|
const uint8_t FSMTreppe_IN_animation_up = 2U;
|
||||||
|
const uint8_t FSMTreppe_IN_idle = 3U;
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
|
||||||
|
void ledsequence();
|
||||||
|
void rampe();
|
||||||
|
bool read_sensor(int sensor) {
|
||||||
|
int pegel = digitalRead(sensor);
|
||||||
|
return static_cast<bool>(pegel);
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
Treppe(uint8_t _stairs) : stairs(_stairs){
|
||||||
|
FSMTreppe_Obj.initialize();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ticks_pro_stufe = time_per_stair / 20; // [ms]
|
||||||
|
ticks_treppe = ticks_pro_stufe * stairs;
|
||||||
|
|
||||||
|
differenz_pwm_pro_tick = (float) (active_brightness - idle_brightness)
|
||||||
|
/ (float) ticks_pro_stufe;
|
||||||
|
}
|
||||||
|
~Treppe() {
|
||||||
|
FSMTreppe_Obj.terminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup();
|
||||||
|
void task(); // call periodically
|
||||||
|
|
||||||
|
// Parameter section
|
||||||
|
uint16_t setIdle(uint16_t _idle_brightness);
|
||||||
|
uint16_t setActive(uint16_t _active_brightness);
|
||||||
|
uint16_t setTime(uint16_t _time_per_stair);
|
||||||
|
|
||||||
|
void setTick(uint32_t _tick) {
|
||||||
|
tick = _tick;
|
||||||
|
Serial.printf("Treppe: Tick: %u!\n", tick);
|
||||||
|
}
|
||||||
|
uint32_t getTicks() {
|
||||||
|
return ticks_treppe;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Runtime Parameter section
|
||||||
|
void setDirection(uint8_t _direction);
|
||||||
|
void setState(uint8_t _state);
|
||||||
|
void setAnAus(uint8_t _an_aus) {
|
||||||
|
an_aus = _an_aus;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t getState() { return state;};
|
||||||
|
uint8_t getFinished() { return finish;};
|
||||||
|
uint8_t getDirection() {return direction;};
|
||||||
|
};
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#include "httpserver.h"
|
|
||||||
|
|
||||||
|
|
||||||
bool HTTPServer::addRootFileHandler() {
|
|
||||||
|
|
||||||
// //experimental, see doku.md
|
|
||||||
// server.serveStatic("/compressed", LittleFS, "/compressed.html.gzip");
|
|
||||||
|
|
||||||
this->serveStatic("", LittleFS, "/index.html");
|
|
||||||
this->serveStatic("/", LittleFS, "/index.html");
|
|
||||||
this->serveStatic("/#", LittleFS, "/index.html");
|
|
||||||
this->serveStatic("/style.css", LittleFS, "/style.css");
|
|
||||||
this->serveStatic("/input.js", LittleFS, "/input.js");
|
|
||||||
this->serveStatic("/favicon.png", LittleFS, "/favicon.png");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
+43
-46
@@ -9,12 +9,8 @@ extern "C" {
|
|||||||
#include "user_interface.h"
|
#include "user_interface.h"
|
||||||
}
|
}
|
||||||
// OTA & WEB
|
// OTA & WEB
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <WiFiUdp.h>
|
|
||||||
#include <ArduinoOTA.h>
|
|
||||||
#include "ota.h"
|
|
||||||
|
|
||||||
#include "wifi_credentials.h"
|
#include "wifi_credentials.h"
|
||||||
|
#include "ota.h"
|
||||||
#include "httpserver.h"
|
#include "httpserver.h"
|
||||||
|
|
||||||
// BOARD
|
// BOARD
|
||||||
@@ -22,18 +18,22 @@ extern "C" {
|
|||||||
#define NODEMCU_LED 16
|
#define NODEMCU_LED 16
|
||||||
|
|
||||||
// PWM
|
// PWM
|
||||||
|
#include "treppe.h"
|
||||||
#include "pwm.h"
|
|
||||||
os_timer_t timer1;
|
os_timer_t timer1;
|
||||||
uint8_t timer_flag = 0;
|
uint8_t timer_flag = 0;
|
||||||
|
Treppe stairs(16);
|
||||||
Treppe stairs(13);
|
|
||||||
|
|
||||||
|
|
||||||
// WIFI
|
// WIFI
|
||||||
const char* ssid = STASSID;
|
const char* ssid = STASSID;
|
||||||
const char* password = STAPSK;
|
const char* password = STAPSK;
|
||||||
|
|
||||||
|
// port 80, root directory of server '/'
|
||||||
|
HTTPServer httpServer(80, "/");
|
||||||
|
|
||||||
|
uint32_t _t=0;
|
||||||
|
#define SP_US(_str,_a) 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); }
|
||||||
|
|
||||||
|
|
||||||
void timerCallback(void *pArg)
|
void timerCallback(void *pArg)
|
||||||
{
|
{
|
||||||
@@ -41,31 +41,10 @@ void timerCallback(void *pArg)
|
|||||||
stairs.task();
|
stairs.task();
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTTP
|
|
||||||
void handleNotFound();
|
|
||||||
HTTPServer httpServer(80, "/");
|
|
||||||
|
|
||||||
uint32_t _t=0;
|
|
||||||
#define SP_US(_str,_a) 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); }
|
|
||||||
// ===============================================
|
// ===============================================
|
||||||
|
uint8_t inter = 0;
|
||||||
|
ICACHE_RAM_ATTR void int_test(){
|
||||||
void handleNotFound() {
|
inter = 1;
|
||||||
String message = "File Not Found\n\n";
|
|
||||||
message += "URI: ";
|
|
||||||
message += httpServer.uri();
|
|
||||||
message += "\nMethod: ";
|
|
||||||
message += (httpServer.method() == HTTP_GET) ? "GET" : "POST";
|
|
||||||
message += "\nArguments: ";
|
|
||||||
message += httpServer.args();
|
|
||||||
message += "\n";
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < httpServer.args(); i++) {
|
|
||||||
message += " " + httpServer.argName(i) + ": " + httpServer.arg(i) + "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
httpServer.send(404, "text/plain", message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@@ -73,12 +52,12 @@ void setup() {
|
|||||||
Serial.begin(460800);
|
Serial.begin(460800);
|
||||||
gdbstub_init();
|
gdbstub_init();
|
||||||
#else
|
#else
|
||||||
Serial.begin(115200);
|
Serial.begin(76800);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Serial.println(F("Booting ...."));
|
Serial.println(F("Booting ...."));
|
||||||
|
|
||||||
pinMode(NODEMCU_LED, OUTPUT);
|
//pinMode(NODEMCU_LED, OUTPUT);
|
||||||
pinMode(ESP12_LED, OUTPUT);
|
pinMode(ESP12_LED, OUTPUT);
|
||||||
|
|
||||||
Wire.begin(); // Wire must be started first
|
Wire.begin(); // Wire must be started first
|
||||||
@@ -102,25 +81,43 @@ void setup() {
|
|||||||
ota_setup();
|
ota_setup();
|
||||||
|
|
||||||
httpServer.start();
|
httpServer.start();
|
||||||
httpServer.onNotFound(handleNotFound);
|
httpServer.start_apps();
|
||||||
|
|
||||||
Serial.println("HTTP server started !");
|
Serial.println("HTTP server started !");
|
||||||
|
|
||||||
stairs.setup();
|
stairs.setup();
|
||||||
Serial.println("PCA9685 connected !");
|
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);
|
||||||
|
|
||||||
stairs.setState(1);
|
|
||||||
stairs.setDirection(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <random>
|
||||||
|
|
||||||
|
uint32_t c = 0;
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if(millis() > 25000 && stairs.getState() == 1 && stairs.getDirection() == 1) stairs.setState(0);
|
// if(stairs.getState() == 0) {
|
||||||
if(millis() > 45000 && stairs.getDirection() == 1){
|
// delay(1000);
|
||||||
stairs.setState(1);
|
|
||||||
stairs.setDirection(0);
|
// // uint32_t t = rand() % stairs.getTicks();
|
||||||
|
// // uint32_t d = rand() % 2;
|
||||||
|
|
||||||
|
// // stairs.setTick(t);
|
||||||
|
// // stairs.setDirection(d);
|
||||||
|
|
||||||
|
// stairs.setDirection(!stairs.getDirection());
|
||||||
|
// stairs.setState(1);
|
||||||
|
// }
|
||||||
|
if(inter){
|
||||||
|
Serial.printf("interrupt\n");
|
||||||
|
inter = 0;
|
||||||
}
|
}
|
||||||
TIMEIF_US(ArduinoOTA.handle(), 1000, "OTA");
|
if(c++%1000000 == 0)
|
||||||
TIMEIF_US(httpServer.handleClient(), 1000, "HTTP");
|
httpServer.logt("[%d] starting :)\n", c);
|
||||||
|
|
||||||
|
TIMEIF_US(ArduinoOTA.handle(), 10000, "OTA");
|
||||||
|
TIMEIF_US(httpServer.handleClient(), 10000, "HTTP");
|
||||||
}
|
}
|
||||||
-136
@@ -1,136 +0,0 @@
|
|||||||
#include "pwm.h"
|
|
||||||
|
|
||||||
uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){
|
|
||||||
/*
|
|
||||||
softstart task
|
|
||||||
|
|
||||||
- get's called at regular intervals (1ms at the moment)
|
|
||||||
- dimms single led (0 - 15, PCA9685 outputs) with linear intervals vom startval to stopval
|
|
||||||
- calculates pwm steps depending on startval, stopval and timeinterval
|
|
||||||
- -> results in constanst speed
|
|
||||||
- returns 1 if led dimming is running
|
|
||||||
- returns 0 if led dimming is finished
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
static uint8_t lastled = 255;
|
|
||||||
static float current_pwm = 0;
|
|
||||||
static float stepsize = 1.0;
|
|
||||||
if(led != lastled){
|
|
||||||
pwmController.setChannelPWM(led, (uint16_t)startval);
|
|
||||||
lastled = led;
|
|
||||||
current_pwm = startval;
|
|
||||||
stepsize = 20*abs(stopval - startval)/(float)time_per_stair; // only valid at 1ms function call interval
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(current_pwm > stopval - stepsize && current_pwm < stopval + stepsize) return 0;
|
|
||||||
// todo: duty cycle zero!
|
|
||||||
if(startval > stopval){
|
|
||||||
current_pwm -= stepsize;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
current_pwm += stepsize;
|
|
||||||
}
|
|
||||||
Serial.println((uint16_t)current_pwm);
|
|
||||||
pwmController.setChannelPWM(led, (uint16_t)current_pwm);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Treppe::ledsequence(){
|
|
||||||
static int8_t led = 0;
|
|
||||||
static uint16_t brightness = 0;
|
|
||||||
static uint16_t lastbrightness = 0;
|
|
||||||
static uint8_t finish = 1;
|
|
||||||
static uint16_t status = 0;
|
|
||||||
uint16_t status_build = 0;
|
|
||||||
status_build |= direction << 8;
|
|
||||||
status_build |= state;
|
|
||||||
if(status_build != status){ // check if any parameter changed
|
|
||||||
finish = 0; // set state unfinished -> start action
|
|
||||||
if(direction) led = 0; // reset led counter depending of direction
|
|
||||||
else led = stairs-1;
|
|
||||||
if(state){
|
|
||||||
brightness = active_brightness; // set brightness value depending of on/off
|
|
||||||
lastbrightness = idle_brightness;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
brightness = idle_brightness;
|
|
||||||
lastbrightness = active_brightness;
|
|
||||||
}
|
|
||||||
status = status_build; // set parameter memory
|
|
||||||
Serial.print("----Status Changed! onoff: ");
|
|
||||||
Serial.print(state);
|
|
||||||
Serial.print(" dir: ");
|
|
||||||
Serial.println(direction);
|
|
||||||
|
|
||||||
}
|
|
||||||
if(!finish){ // finish == 0 -> action pending
|
|
||||||
if(!softstart_led(led,lastbrightness, brightness)){
|
|
||||||
Serial.print("one LED finished: ");
|
|
||||||
Serial.print(led);
|
|
||||||
Serial.print(" last: ");
|
|
||||||
Serial.print(lastbrightness);
|
|
||||||
Serial.print(" curr: ");
|
|
||||||
Serial.println(brightness);
|
|
||||||
if(direction){
|
|
||||||
led++;
|
|
||||||
if(led >= stairs) {
|
|
||||||
finish = 1;
|
|
||||||
//lastbrightness = brightness;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
led--;
|
|
||||||
if(led < 0){
|
|
||||||
//lastbrightness = brightness;
|
|
||||||
finish = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Treppe::setup(){
|
|
||||||
pwmController.resetDevices();
|
|
||||||
pwmController.init();
|
|
||||||
pwmController.setPWMFrequency(200);
|
|
||||||
Serial.println("Hello from Treppe");
|
|
||||||
Serial.print("Treppe: initial parameters: stairs=");
|
|
||||||
Serial.println(stairs);
|
|
||||||
}
|
|
||||||
void Treppe::task(){
|
|
||||||
ledsequence();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t Treppe::setIdle(uint16_t _idle_brightness){
|
|
||||||
idle_brightness = _idle_brightness;
|
|
||||||
Serial.println("Treppe: idle brightness changed!");
|
|
||||||
return idle_brightness;
|
|
||||||
}
|
|
||||||
uint16_t Treppe::setActive(uint16_t _active_brightness){
|
|
||||||
active_brightness = _active_brightness;
|
|
||||||
Serial.println("Treppe: active brightness changed!");
|
|
||||||
return active_brightness;
|
|
||||||
}
|
|
||||||
uint16_t Treppe::setTime(uint16_t _time_per_stair){
|
|
||||||
time_per_stair = _time_per_stair;
|
|
||||||
Serial.println("Treppe: time changed!");
|
|
||||||
return time_per_stair;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t Treppe::setDirection(uint8_t _direction){
|
|
||||||
direction = _direction;
|
|
||||||
Serial.println("Treppe: Direction changed!");
|
|
||||||
// to do: implement state command variable to determine dimm-state
|
|
||||||
return direction;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t Treppe::setState(uint8_t _state){
|
|
||||||
if(state == _state) return 1;
|
|
||||||
else{
|
|
||||||
state = _state;
|
|
||||||
Serial.println("Treppe: State changed!");
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
+42
-3
@@ -8,23 +8,29 @@
|
|||||||
; Please visit documentation for the other options and examples
|
; Please visit documentation for the other options and examples
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[env]
|
[platformio]
|
||||||
|
description = ESP8266 Treppenlicht Steuerung
|
||||||
|
default_envs = ota
|
||||||
|
; test_dir = test
|
||||||
|
data_dir = data_gz
|
||||||
|
|
||||||
|
[env:hardware]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = nodemcuv2
|
board = nodemcuv2
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
|
||||||
; for http files
|
|
||||||
board_build.filesystem = littlefs
|
board_build.filesystem = littlefs
|
||||||
board_build.ldscript = eagle.flash.4m1m.ld
|
board_build.ldscript = eagle.flash.4m1m.ld
|
||||||
extra_scripts = pre:create_gz_files.py
|
extra_scripts = pre:create_gz_files.py
|
||||||
|
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
|
||||||
[env:serial]
|
[env:serial]
|
||||||
|
extends = env:hardware
|
||||||
upload_protocol = esptool
|
upload_protocol = esptool
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
|
|
||||||
[env:ota]
|
[env:ota]
|
||||||
|
extends = env:hardware
|
||||||
; OTA => https://docs.platformio.org/en/latest/platforms/espressif8266.html#over-the-air-ota-update
|
; OTA => https://docs.platformio.org/en/latest/platforms/espressif8266.html#over-the-air-ota-update
|
||||||
upload_protocol = espota
|
upload_protocol = espota
|
||||||
upload_port = <!! IP ADDRESS !!>
|
upload_port = <!! IP ADDRESS !!>
|
||||||
@@ -33,13 +39,46 @@ upload_flags =
|
|||||||
--host_port=<!! PORT !!>
|
--host_port=<!! PORT !!>
|
||||||
--auth=admin
|
--auth=admin
|
||||||
|
|
||||||
|
|
||||||
[env:debug]
|
[env:debug]
|
||||||
|
extends = env:hardware
|
||||||
; look at doku.md
|
; look at doku.md
|
||||||
build_flags = -DWITH_DEBUGGING_ON -Os -g3 -ggdb3
|
build_flags = -DWITH_DEBUGGING_ON -Os -g3 -ggdb3
|
||||||
upload_protocol = esptool
|
upload_protocol = esptool
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
|
|
||||||
|
|
||||||
|
# This file is used compile and run tests located in the `unit` directory.
|
||||||
|
# For more info, see:
|
||||||
|
# https://docs.platformio.org/en/latest/plus/unit-testing.html
|
||||||
|
# https://github.com/ThrowTheSwitch/Unity
|
||||||
|
# https://github.com/ThrowTheSwitch/Unity/blob/master/docs/UnityAssertionsReference.md
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# To prepare coverage data for lcov, add ${coverage.build_flags} to env:test build flags
|
||||||
|
# To actually generate coverage report:
|
||||||
|
# $ `pio test` / run the test `program` manually
|
||||||
|
# $ lcov --include (readlink -f ../espurna)'/*' --capture --directory .pio/build/test/ --output-file test.info
|
||||||
|
# $ genhtml --ignore-errors source test.info --output-directory out
|
||||||
|
|
||||||
|
[coverage]
|
||||||
|
build_flags = -lgcov -fprofile-arcs -ftest-coverage
|
||||||
|
|
||||||
|
[env:test]
|
||||||
|
extends = env:hardware
|
||||||
|
|
||||||
|
|
||||||
|
[env:native]
|
||||||
|
platform = native
|
||||||
|
test_build_project_src = true
|
||||||
|
build_flags =
|
||||||
|
-DMANUFACTURER="PLATFORMIO"
|
||||||
|
-DDEVICE="TEST"
|
||||||
|
-std=gnu++11
|
||||||
|
-g
|
||||||
|
-Os
|
||||||
|
-I lib/treppe
|
||||||
|
-I lib/PCA9685-Arduino
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+30
-30
@@ -1,40 +1,40 @@
|
|||||||
#include <Arduino.h>
|
// #include <Arduino.h>
|
||||||
#include <unity.h>
|
// #include <unity.h>
|
||||||
|
|
||||||
String STR_TO_TEST;
|
// String STR_TO_TEST;
|
||||||
|
|
||||||
void setUp(void) {
|
// // void setUp(void) {
|
||||||
// set stuff up here
|
// // // set stuff up here
|
||||||
STR_TO_TEST = "Hello, world!";
|
// // STR_TO_TEST = "Hello, world!";
|
||||||
}
|
// // }
|
||||||
|
|
||||||
void tearDown(void) {
|
// // void tearDown(void) {
|
||||||
// clean stuff up here
|
// // // clean stuff up here
|
||||||
STR_TO_TEST = "";
|
// // STR_TO_TEST = "";
|
||||||
}
|
// // }
|
||||||
|
|
||||||
void test_led_builtin_pin_number(void) {
|
// void test_led_builtin_pin_number(void) {
|
||||||
TEST_ASSERT_EQUAL(2, LED_BUILTIN);
|
// TEST_ASSERT_EQUAL(2, LED_BUILTIN);
|
||||||
}
|
// }
|
||||||
|
|
||||||
void test_string_concat(void) {
|
// void test_string_concat(void) {
|
||||||
String hello = "Hello, ";
|
// String hello = "Hello, ";
|
||||||
String world = "world!";
|
// String world = "world!";
|
||||||
TEST_ASSERT_EQUAL_STRING(STR_TO_TEST.c_str(), (hello + world).c_str());
|
// TEST_ASSERT_EQUAL_STRING(STR_TO_TEST.c_str(), (hello + world).c_str());
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
void setup()
|
// void setup()
|
||||||
{
|
// {
|
||||||
delay(2000); // service delay
|
// delay(2000); // service delay
|
||||||
UNITY_BEGIN();
|
// UNITY_BEGIN();
|
||||||
|
|
||||||
RUN_TEST(test_led_builtin_pin_number);
|
// RUN_TEST(test_led_builtin_pin_number);
|
||||||
RUN_TEST(test_string_concat);
|
// RUN_TEST(test_string_concat);
|
||||||
|
|
||||||
UNITY_END(); // stop unit testing
|
// UNITY_END(); // stop unit testing
|
||||||
}
|
// }
|
||||||
|
|
||||||
void loop()
|
// void loop()
|
||||||
{
|
// {
|
||||||
}
|
// }
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
// #include <Arduino.h>
|
||||||
|
#include "treppe.h"
|
||||||
|
#include <unity.h>
|
||||||
|
|
||||||
|
Treppe stairs(10);
|
||||||
|
|
||||||
|
void setUp(void) {
|
||||||
|
// run before each test
|
||||||
|
// set stuff up here
|
||||||
|
stairs.setup();
|
||||||
|
Serial.println("Treppe initialized !");
|
||||||
|
Serial.println("PCA9685 connected !");
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown(void) {
|
||||||
|
// clean stuff up here
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_set_state(void) {
|
||||||
|
stairs.setState(1);
|
||||||
|
TEST_ASSERT_EQUAL(1, stairs.getState());
|
||||||
|
stairs.setState(0);
|
||||||
|
TEST_ASSERT_EQUAL(0, stairs.getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_set_direction(void) {
|
||||||
|
stairs.setDirection(1);
|
||||||
|
TEST_ASSERT_EQUAL(1, stairs.getDirection());
|
||||||
|
stairs.setDirection(0);
|
||||||
|
TEST_ASSERT_EQUAL(0, stairs.getDirection());
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
delay(2000); // service delay
|
||||||
|
UNITY_BEGIN();
|
||||||
|
|
||||||
|
RUN_TEST(test_set_state);
|
||||||
|
RUN_TEST(test_set_direction);
|
||||||
|
|
||||||
|
UNITY_END(); // stop unit testing
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user