Compare commits
38
Commits
v0.2.0
...
9d1105cb80
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d1105cb80 | ||
|
|
4130b64370 | ||
|
|
bff8cdbeb7 | ||
|
|
d8343ea91f | ||
|
|
78f09b3a3b | ||
|
|
bd0e364d22 | ||
|
|
32266b5f37 | ||
|
|
b62f4f9f95 | ||
|
|
a8af7543ba | ||
|
|
85f8da3476 | ||
|
|
f323bd4cf9 | ||
|
|
708bb2cda4 | ||
|
|
a4196bb579 | ||
|
|
908c4298be | ||
|
|
6e885673b8 | ||
|
|
93cc958800 | ||
|
|
9d30423ca3 | ||
|
|
b3b11d0818 | ||
|
|
51bdd6210e | ||
|
|
d51bb4c95c | ||
|
|
2659e366ec | ||
|
|
4951ca46c1 | ||
|
|
97a6076864 | ||
|
|
ff6b82867c | ||
|
|
a3dc7a5fba | ||
|
|
c13b0adc82 | ||
|
|
da20f74db8 | ||
|
|
d5b9827543 | ||
|
|
3c6889854e | ||
|
|
8d8ffe4173 | ||
|
|
006404fccf | ||
|
|
d17091651f | ||
|
|
4b608c42ca | ||
|
|
278f746b33 | ||
|
|
642ee7d0a6 | ||
|
|
6596346d3d | ||
|
|
b696703d45 | ||
|
|
baecaf02da |
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
.pio
|
.pio
|
||||||
.vscode
|
.vscode
|
||||||
|
compress
|
||||||
platformio.ini
|
platformio.ini
|
||||||
include/wifi_credentials.h
|
include/wifi_credentials.h
|
||||||
include/*.gz.h
|
include/*.gz.h
|
||||||
Vendored
+38
-1
@@ -10,6 +10,43 @@
|
|||||||
"vector": "cpp",
|
"vector": "cpp",
|
||||||
"string_view": "cpp",
|
"string_view": "cpp",
|
||||||
"memory": "cpp",
|
"memory": "cpp",
|
||||||
"ranges": "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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+5
-2
@@ -28,8 +28,11 @@ def convert_to_gzip(src, out, f):
|
|||||||
f_out.write(top.encode(encoding='utf-8'))
|
f_out.write(top.encode(encoding='utf-8'))
|
||||||
|
|
||||||
|
|
||||||
src='include/http/'
|
src='data/'
|
||||||
out='include/'
|
out='compress/'
|
||||||
|
|
||||||
|
if not 'compress' in os.listdir():
|
||||||
|
os.mkdir('compress')
|
||||||
|
|
||||||
for f in os.listdir(src):
|
for f in os.listdir(src):
|
||||||
convert_to_gzip(src, out, f)
|
convert_to_gzip(src, out, f)
|
||||||
File renamed without changes.
@@ -0,0 +1,56 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>ESP8266 Treppenlicht</title>
|
||||||
|
<!-- main style sheet -->
|
||||||
|
<link href="/favicon.png" rel="icon" type="image/png" sizes="10x10">
|
||||||
|
<link href="/style.css" rel="stylesheet" type="text/css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="kopfzeile" style="text-align: center;">
|
||||||
|
<b>Treppenlicht</b>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="ueberschrift">
|
||||||
|
<center>Helligkeit</center>
|
||||||
|
<div class="slider">
|
||||||
|
<label id="label_pwm">
|
||||||
|
</label>
|
||||||
|
<input type="range" class="testregler" min="0" max="100">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="ueberschrift">
|
||||||
|
<center>Helligkeit bei Dunkelheit</center>
|
||||||
|
<div class="slider">
|
||||||
|
<label id="label_geschwindigkeit">
|
||||||
|
</label>
|
||||||
|
<input type="range" class="testregler" min="0" max="100">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="ueberschrift">
|
||||||
|
<center>Laufgeschwindigkeit</center>
|
||||||
|
<div class="slider">
|
||||||
|
<label id="label_geschwindigkeit">
|
||||||
|
</label>
|
||||||
|
<input type="range" class="testregler" min="0" max="100">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="ueberschrift">
|
||||||
|
<center>Licht-An-Zeit</center>
|
||||||
|
<div class="slider">
|
||||||
|
<label id="label_geschwindigkeit">
|
||||||
|
</label>
|
||||||
|
<input type="range" class="testregler" min="0" max="100">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script src="/input.js"></script>
|
||||||
|
|
||||||
|
</html>
|
||||||
File renamed without changes.
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -1,7 +1,7 @@
|
|||||||
html {
|
html {
|
||||||
font-size: 10px;
|
font-size: 16px;
|
||||||
font-family: sans-serif, Arial, Helvetica;
|
font-family: sans-serif, Arial, Helvetica;
|
||||||
background-color: #b3b3b3;
|
background-color: #d4d4d4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.topbar {
|
.topbar {
|
||||||
@@ -17,6 +17,45 @@ html {
|
|||||||
padding: 1em;
|
padding: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ueberschrift{
|
||||||
|
color: #ffffff;
|
||||||
|
font-size: 50px;
|
||||||
|
width: 40%;
|
||||||
|
background-color: #5f5f5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.testregler{
|
||||||
|
-webkit-appearance: none;
|
||||||
|
height: 30px;
|
||||||
|
width: 98%;
|
||||||
|
border-radius: 20px;
|
||||||
|
outline: black;
|
||||||
|
background-color: rgb(176, 188, 228);
|
||||||
|
}
|
||||||
|
.testregler::-webkit-slider-thumb{
|
||||||
|
-webkit-appearance: none;
|
||||||
|
appearance: none;
|
||||||
|
width: 5%;
|
||||||
|
height: 20px;
|
||||||
|
border-radius: 10px;
|
||||||
|
background-color: rgb(107, 122, 192);
|
||||||
|
cursor:pointer;
|
||||||
|
}
|
||||||
|
input[type=range]::-webkit-slider-thumb{
|
||||||
|
-webkit-appearance: none;
|
||||||
|
border:none;
|
||||||
|
height: 30px;
|
||||||
|
width: 4%;
|
||||||
|
border-radius: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.kopfzeile{
|
||||||
|
color: #1f1f1f;
|
||||||
|
font-size: 50px;
|
||||||
|
width: 100%;
|
||||||
|
background-color: #8d8a8a;
|
||||||
|
|
||||||
|
}
|
||||||
p, li {
|
p, li {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
line-height: 2;
|
line-height: 2;
|
||||||
@@ -26,7 +65,7 @@ p, li {
|
|||||||
|
|
||||||
body {
|
body {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
border: 1px solid black;
|
border: none;
|
||||||
border-radius: 3;
|
border-radius: 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,18 +88,10 @@ body {
|
|||||||
|
|
||||||
/* The slider */
|
/* The slider */
|
||||||
.slider {
|
.slider {
|
||||||
position: absolute;
|
width: 100%;
|
||||||
cursor: pointer;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
background-color: #ccc;
|
|
||||||
-webkit-transition: .4s;
|
|
||||||
transition: .4s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.slider:before {
|
/*.slider:before {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
content: "";
|
content: "";
|
||||||
height: 26px;
|
height: 26px;
|
||||||
@@ -70,7 +101,7 @@ body {
|
|||||||
background-color: white;
|
background-color: white;
|
||||||
-webkit-transition: .4s;
|
-webkit-transition: .4s;
|
||||||
transition: .4s;
|
transition: .4s;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
input:checked + .slider {
|
input:checked + .slider {
|
||||||
background-color: #04AA6D;
|
background-color: #04AA6D;
|
||||||
@@ -94,8 +125,6 @@ input:checked + .slider:before {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* The slider itself */
|
/* The slider itself */
|
||||||
.rangeslider {
|
.rangeslider {
|
||||||
-webkit-appearance: none; /* Override default CSS styles */
|
-webkit-appearance: none; /* Override default CSS styles */
|
||||||
@@ -22,4 +22,42 @@ GDB-Version aus Arduino Toolchain hat Support
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ ./start_xtensa_gdb_stub.sh
|
$ ./start_xtensa_gdb_stub.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### __Achtung !__
|
||||||
|
Don`t forget __\r__
|
||||||
|
|
||||||
|
ESP-OTA wird von ufw oder Defender geblockt.
|
||||||
|
- Windows -> Python needs to be granted with rights
|
||||||
|
- Linux -> open udp port in ufw ->
|
||||||
|
|
||||||
|
```sh
|
||||||
|
platform.ini
|
||||||
|
upload_flags =
|
||||||
|
--host-port <PORT>
|
||||||
|
...
|
||||||
|
$ sudo ufw allow tcp/<PORT>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
```c++
|
||||||
|
server.streamFile(f, mime::getContentType(SRH::_path), requestMethod);
|
||||||
|
|
||||||
|
=====>
|
||||||
|
|
||||||
|
const String& p = SRH::_path;
|
||||||
|
if(p.endsWith(".gzip")) {
|
||||||
|
server.sendHeader("Content-Encoding", "gzip");
|
||||||
|
server.streamFile(f, mime::getContentType(p.substring(0, p.length()-5)), requestMethod);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
server.streamFile(f, mime::getContentType(SRH::_path), requestMethod);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Webserver on v0.3.0 now working with LittleFS
|
||||||
|
TODO:
|
||||||
|
- check dir for files automatic
|
||||||
|
- move handleNotFound to httpserver.h
|
||||||
|
- maybe compress files ?
|
||||||
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef __FILESYS_H
|
||||||
|
#define __FILESYS_H
|
||||||
|
|
||||||
|
#include <LittleFS.h>
|
||||||
|
|
||||||
|
bool mount_fs();
|
||||||
|
bool format_fs();
|
||||||
|
|
||||||
|
void ls(const char * dirname);
|
||||||
|
void readFile(const char * path);
|
||||||
|
void writeFile(const char * path, const char * message);
|
||||||
|
void appendFile(const char * path, const char * message);
|
||||||
|
void renameFile(const char * path1, const char * path2);
|
||||||
|
void deleteFile(const char * path);
|
||||||
|
|
||||||
|
#endif // __FILESYS_H
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 54 KiB |
@@ -1,40 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>ESP8266 Treppenlicht</title>
|
|
||||||
<!-- main style sheet -->
|
|
||||||
<link href="/favicon.png" rel="icon" type="image/png" sizes="16x16">
|
|
||||||
<link href="/style.css" rel="stylesheet" type="text/css">
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="topbar">
|
|
||||||
ESP8266 Treppenlicht Controller
|
|
||||||
</div>
|
|
||||||
<div class="control">
|
|
||||||
<div class="brightness">
|
|
||||||
</div>
|
|
||||||
<div class="onoff">
|
|
||||||
toggle all
|
|
||||||
<label id="l_onoff"></label>
|
|
||||||
<label class="switch">
|
|
||||||
<input type="checkbox">
|
|
||||||
<span class="slider round"></span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="pwm">
|
|
||||||
<label id="label_pwm"></label>
|
|
||||||
<input type="range" min="1" max="100" value="50" class="rangeslider" id="range1">
|
|
||||||
</div>
|
|
||||||
<div class="timer">
|
|
||||||
<label id="label_timer"></label>
|
|
||||||
<input type="range" min="1" max="100" value="50" class="rangeslider" id="timer_range">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
<script src="/input.js"></script>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
+34
-23
@@ -1,37 +1,48 @@
|
|||||||
#ifndef __HTTPSERVER_H
|
#ifndef __HTTPSERVER_H
|
||||||
#define __HTTPSERVER_H
|
#define __HTTPSERVER_H
|
||||||
|
|
||||||
|
#include "filesys.h"
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
|
|
||||||
class HTTPServer {
|
|
||||||
|
class HTTPServer : public ESP8266WebServer {
|
||||||
private:
|
private:
|
||||||
int port;
|
const char* rootDir;
|
||||||
ESP8266WebServer* server;
|
|
||||||
|
bool addRootFileHandler();
|
||||||
|
bool formatFS() {
|
||||||
|
return format_fs();
|
||||||
|
}
|
||||||
|
void listRoot() {
|
||||||
|
ls(rootDir);
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HTTPServer(int port) {
|
HTTPServer(const int _port, const char* _rootDir) :
|
||||||
server = new ESP8266WebServer;
|
ESP8266WebServer(_port), rootDir(_rootDir)
|
||||||
|
{ }
|
||||||
// server->on("/", handleRootGz);
|
~HTTPServer()
|
||||||
// server->on("/style.css", handleCssGz);
|
{
|
||||||
// server->on("/favicon.png", handleFaviconGz);
|
Serial.printf("[HTTPServer] shut down ...\n\r");
|
||||||
// server->onNotFound(handleNotFound);
|
|
||||||
|
|
||||||
server->begin(port);
|
|
||||||
}
|
|
||||||
~HTTPServer() {
|
|
||||||
server->stop();
|
|
||||||
delete server;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize() {
|
bool start() {
|
||||||
server->begin(port);
|
if(!mount_fs())
|
||||||
}
|
return false;
|
||||||
|
Serial.printf("[HTTPServer] LittleFS mounted !\n\r");
|
||||||
void handleClient() {
|
|
||||||
server->handleClient();
|
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
|
#endif // __HTTPSERVER_H
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
#ifndef __OTA_H
|
||||||
|
#define __OTA_H
|
||||||
|
|
||||||
|
void ota_setup() {
|
||||||
|
ArduinoOTA.setPort(8266);
|
||||||
|
ArduinoOTA.setHostname("ESP_Treppenlicht");
|
||||||
|
ArduinoOTA.setPassword("admin");
|
||||||
|
// Password can be set with it's md5 value as well
|
||||||
|
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
|
||||||
|
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
|
||||||
|
|
||||||
|
ArduinoOTA.onStart([]() {
|
||||||
|
String type;
|
||||||
|
if (ArduinoOTA.getCommand() == U_FLASH) {
|
||||||
|
type = "sketch";
|
||||||
|
} else { // U_FS
|
||||||
|
type = "filesystem";
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: if updating FS this would be the place to unmount FS using FS.end()
|
||||||
|
Serial.println("Start updating " + type);
|
||||||
|
});
|
||||||
|
ArduinoOTA.onEnd([]() {
|
||||||
|
Serial.println("\nEnd");
|
||||||
|
});
|
||||||
|
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||||
|
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
|
||||||
|
});
|
||||||
|
ArduinoOTA.onError([](ota_error_t error) {
|
||||||
|
Serial.printf("Error[%u]: ", error);
|
||||||
|
if (error == OTA_AUTH_ERROR) {
|
||||||
|
Serial.println("Auth Failed");
|
||||||
|
} else if (error == OTA_BEGIN_ERROR) {
|
||||||
|
Serial.println("Begin Failed");
|
||||||
|
} else if (error == OTA_CONNECT_ERROR) {
|
||||||
|
Serial.println("Connect Failed");
|
||||||
|
} else if (error == OTA_RECEIVE_ERROR) {
|
||||||
|
Serial.println("Receive Failed");
|
||||||
|
} else if (error == OTA_END_ERROR) {
|
||||||
|
Serial.println("End Failed");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ArduinoOTA.begin();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // __OTA_H
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#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;};
|
||||||
|
};
|
||||||
+130
@@ -0,0 +1,130 @@
|
|||||||
|
#include "filesys.h"
|
||||||
|
|
||||||
|
// listDir("/");
|
||||||
|
// deleteFile("/hello.txt");
|
||||||
|
// writeFile("/hello.txt", "Hello ");
|
||||||
|
// appendFile("/hello.txt", "World!\n\r");
|
||||||
|
// readFile("/hello.txt");
|
||||||
|
// listDir("/");
|
||||||
|
|
||||||
|
FSInfo fsinfo;
|
||||||
|
|
||||||
|
bool mount_fs() {
|
||||||
|
if(!LittleFS.begin()) {
|
||||||
|
Serial.println("[ERROR] LittleFS.info(), reset ...");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!LittleFS.info(fsinfo)) {
|
||||||
|
Serial.println("[ERROR] LittleFS.info(), reset ...");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Filesystem opened:\n\r");
|
||||||
|
printf("\ttotalBytes:\t%d\n\r", fsinfo.totalBytes);
|
||||||
|
printf("\tusedBytes:\t%d\n\r", fsinfo.usedBytes);
|
||||||
|
printf("\tblockSize:\t%d\n\r", fsinfo.blockSize);
|
||||||
|
printf("\tpageSize:\t%d\n\r", fsinfo.pageSize);
|
||||||
|
printf("\tmaxOpenFiles:\t%d\n\r", fsinfo.maxOpenFiles);
|
||||||
|
printf("\tmaxPathLength:\t%d\n\r", fsinfo.maxPathLength);
|
||||||
|
printf("\n\r");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool format_fs() {
|
||||||
|
printf("Formatting FS ! \n\r");
|
||||||
|
return LittleFS.format();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ls(const char * dirname) {
|
||||||
|
Serial.printf("ls -l %s\n\r", dirname);
|
||||||
|
Dir root = LittleFS.openDir(dirname);
|
||||||
|
|
||||||
|
while (root.next()) {
|
||||||
|
File file = root.openFile("r");
|
||||||
|
|
||||||
|
time_t lw = file.getLastWrite();
|
||||||
|
struct tm * tmstruct = localtime(&lw);
|
||||||
|
Serial.printf("%8d %02d %02d %02d:%02d %s\n\r",
|
||||||
|
file.size(),
|
||||||
|
tmstruct->tm_mon + 1,
|
||||||
|
tmstruct->tm_mday,
|
||||||
|
tmstruct->tm_hour,
|
||||||
|
tmstruct->tm_min,
|
||||||
|
root.fileName().c_str());
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void readFile(const char * path) {
|
||||||
|
Serial.printf("Reading file: %s\n\r", path);
|
||||||
|
|
||||||
|
File file = LittleFS.open(path, "r");
|
||||||
|
if (!file) {
|
||||||
|
Serial.println("Failed to open file for reading");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print("Read from file: ");
|
||||||
|
while (file.available()) {
|
||||||
|
Serial.write(file.read());
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeFile(const char * path, const char * message) {
|
||||||
|
Serial.printf("Writing file: %s\n\r", path);
|
||||||
|
|
||||||
|
File file = LittleFS.open(path, "w");
|
||||||
|
if (!file) {
|
||||||
|
Serial.println("Failed to open file for writing");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (file.print(message)) {
|
||||||
|
Serial.println("File written");
|
||||||
|
} else {
|
||||||
|
Serial.println("Write failed");
|
||||||
|
}
|
||||||
|
delay(2000); // Make sure the CREATE and LASTWRITE times are different
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void appendFile(const char * path, const char * message) {
|
||||||
|
Serial.printf("Appending to file: %s\n\r", path);
|
||||||
|
|
||||||
|
File file = LittleFS.open(path, "a");
|
||||||
|
if (!file) {
|
||||||
|
Serial.println("Failed to open file for appending");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(file.print(message)) {
|
||||||
|
Serial.println("Message appended");
|
||||||
|
} else {
|
||||||
|
Serial.println("Append failed");
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void renameFile(const char * path1, const char * path2) {
|
||||||
|
Serial.printf("Renaming file %s to %s\n\r", path1, path2);
|
||||||
|
if (LittleFS.rename(path1, path2)) {
|
||||||
|
Serial.println("File renamed");
|
||||||
|
} else {
|
||||||
|
Serial.println("Rename failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteFile(const char * path) {
|
||||||
|
Serial.printf("Deleting file: %s\n\r", path);
|
||||||
|
if (LittleFS.remove(path)) {
|
||||||
|
Serial.println("File deleted");
|
||||||
|
} else {
|
||||||
|
Serial.println("Delete failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
+58
-257
@@ -1,185 +1,71 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
// debugging support via GDBStub over UART
|
|
||||||
#ifdef WITH_DEBUGGING_ON
|
#ifdef WITH_DEBUGGING_ON
|
||||||
#include <GDBStub.h>
|
#include <GDBStub.h> // debugging support via GDBStub over UART
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "PCA9685.h"
|
#include "PCA9685.h"
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "user_interface.h"
|
#include "user_interface.h"
|
||||||
}
|
}
|
||||||
|
// OTA & WEB
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <WiFiUdp.h>
|
||||||
|
#include <ArduinoOTA.h>
|
||||||
|
#include "ota.h"
|
||||||
|
|
||||||
|
#include "wifi_credentials.h"
|
||||||
|
#include "httpserver.h"
|
||||||
|
|
||||||
|
// BOARD
|
||||||
#define ESP12_LED 2
|
#define ESP12_LED 2
|
||||||
#define NODEMCU_LED 16
|
#define NODEMCU_LED 16
|
||||||
|
|
||||||
|
// PWM
|
||||||
|
|
||||||
os_timer_t Timer1; // Verwaltungsstruktur des Timers
|
#include "pwm.h"
|
||||||
|
os_timer_t timer1;
|
||||||
|
uint8_t timer_flag = 0;
|
||||||
|
|
||||||
int c;
|
Treppe stairs(13);
|
||||||
bool toggle = false;
|
|
||||||
uint32_t m=0;
|
|
||||||
|
|
||||||
uint32_t dimmtimer = 0;
|
|
||||||
uint8_t direction = 1;
|
|
||||||
uint8_t onoff = 1;
|
|
||||||
|
|
||||||
|
|
||||||
void ledsequence(uint8_t direction, uint8_t onoff, uint8_t factor);
|
// WIFI
|
||||||
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval, uint8_t factor);
|
const char* ssid = STASSID;
|
||||||
|
const char* password = STAPSK;
|
||||||
|
|
||||||
|
|
||||||
void timerCallback(void *pArg)
|
void timerCallback(void *pArg)
|
||||||
{
|
{
|
||||||
*((int *) pArg) += 1;
|
*((int *) pArg) += 1;
|
||||||
|
stairs.task();
|
||||||
ledsequence(direction, onoff, 4);
|
|
||||||
// Serial.print("[");
|
|
||||||
// Serial.print(micros()-m);
|
|
||||||
// Serial.print("] timerCallback\n");
|
|
||||||
// m = micros();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// OTA & WEB
|
// HTTP
|
||||||
#include "wifi_credentials.h"
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <WiFiUdp.h>
|
|
||||||
#include <ArduinoOTA.h>
|
|
||||||
|
|
||||||
#include <ESP8266WebServer.h>
|
|
||||||
#include <WiFiClient.h>
|
|
||||||
|
|
||||||
#include "index.html.gz.h"
|
|
||||||
#include "style.css.gz.h"
|
|
||||||
#include "favicon.png.gz.h"
|
|
||||||
// images are possible
|
|
||||||
// maybe check out FS <- SPIFFS
|
|
||||||
|
|
||||||
const char* ssid = STASSID;
|
|
||||||
const char* password = STAPSK;
|
|
||||||
|
|
||||||
void setup_webserver();
|
|
||||||
void setup_ota();
|
|
||||||
void setup_pwm_pca9685();
|
|
||||||
void handleRootGz();
|
|
||||||
void handleCssGz();
|
|
||||||
void handleNotFound();
|
void handleNotFound();
|
||||||
|
HTTPServer httpServer(80, "/");
|
||||||
|
|
||||||
const int led = 13;
|
uint32_t _t=0;
|
||||||
ESP8266WebServer server(80);
|
#define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("us")
|
||||||
PCA9685 pwmController;
|
#define TIMEIF_US(_f, _l, _str) _t=micros(); _f; _t=micros()-_t; if(_t > _l) { SP_US(_str, _t); }
|
||||||
|
// ===============================================
|
||||||
|
|
||||||
void handleRootGz() {
|
|
||||||
const char* dataType = "text/html";
|
|
||||||
server.sendHeader(F("Content-Encoding"), F("gzip"));
|
|
||||||
server.send(200, dataType, (const char*)index_html_gz, index_html_gz_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void handleCssGz() {
|
|
||||||
const char* dataType = "text/css";
|
|
||||||
server.sendHeader(F("Content-Encoding"), F("gzip"));
|
|
||||||
server.send(200, dataType, (const char*)style_css_gz, style_css_gz_len);
|
|
||||||
}
|
|
||||||
void handleFaviconGz() {
|
|
||||||
const char* dataType = "image/png";
|
|
||||||
server.sendHeader(F("Content-Encoding"), F("gzip"));
|
|
||||||
server.send(200, dataType, (const char*)favicon_png_gz, favicon_png_gz_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void handleNotFound() {
|
void handleNotFound() {
|
||||||
digitalWrite(led, 1);
|
|
||||||
String message = "File Not Found\n\n";
|
String message = "File Not Found\n\n";
|
||||||
message += "URI: ";
|
message += "URI: ";
|
||||||
message += server.uri();
|
message += httpServer.uri();
|
||||||
message += "\nMethod: ";
|
message += "\nMethod: ";
|
||||||
message += (server.method() == HTTP_GET) ? "GET" : "POST";
|
message += (httpServer.method() == HTTP_GET) ? "GET" : "POST";
|
||||||
message += "\nArguments: ";
|
message += "\nArguments: ";
|
||||||
message += server.args();
|
message += httpServer.args();
|
||||||
message += "\n";
|
message += "\n";
|
||||||
|
|
||||||
for (uint8_t i = 0; i < server.args(); i++) {
|
for (uint8_t i = 0; i < httpServer.args(); i++) {
|
||||||
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
|
message += " " + httpServer.argName(i) + ": " + httpServer.arg(i) + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
server.send(404, "text/plain", message);
|
httpServer.send(404, "text/plain", message);
|
||||||
digitalWrite(led, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void setup_webserver() {
|
|
||||||
pinMode(led, OUTPUT);
|
|
||||||
digitalWrite(led, 0);
|
|
||||||
Serial.println("");
|
|
||||||
|
|
||||||
// Wait for connection
|
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
|
||||||
delay(500);
|
|
||||||
Serial.print(".");
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.println("");
|
|
||||||
Serial.print("Connected to ");
|
|
||||||
Serial.println(ssid);
|
|
||||||
Serial.print("IP address: ");
|
|
||||||
Serial.println(WiFi.localIP());
|
|
||||||
|
|
||||||
server.on("/", handleRootGz);
|
|
||||||
server.on("/style.css", handleCssGz);
|
|
||||||
server.on("/favicon.png", handleFaviconGz);
|
|
||||||
server.onNotFound(handleNotFound);
|
|
||||||
|
|
||||||
server.begin();
|
|
||||||
Serial.println("HTTP server started");
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup_ota() {
|
|
||||||
ArduinoOTA.setPort(8266);
|
|
||||||
ArduinoOTA.setHostname("ESP_Treppenlicht");
|
|
||||||
ArduinoOTA.setPassword("admin");
|
|
||||||
// Password can be set with it's md5 value as well
|
|
||||||
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
|
|
||||||
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
|
|
||||||
|
|
||||||
ArduinoOTA.onStart([]() {
|
|
||||||
String type;
|
|
||||||
if (ArduinoOTA.getCommand() == U_FLASH) {
|
|
||||||
type = "sketch";
|
|
||||||
} else { // U_FS
|
|
||||||
type = "filesystem";
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: if updating FS this would be the place to unmount FS using FS.end()
|
|
||||||
Serial.println("Start updating " + type);
|
|
||||||
});
|
|
||||||
ArduinoOTA.onEnd([]() {
|
|
||||||
Serial.println("\nEnd");
|
|
||||||
});
|
|
||||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
|
||||||
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
|
|
||||||
});
|
|
||||||
ArduinoOTA.onError([](ota_error_t error) {
|
|
||||||
Serial.printf("Error[%u]: ", error);
|
|
||||||
if (error == OTA_AUTH_ERROR) {
|
|
||||||
Serial.println("Auth Failed");
|
|
||||||
} else if (error == OTA_BEGIN_ERROR) {
|
|
||||||
Serial.println("Begin Failed");
|
|
||||||
} else if (error == OTA_CONNECT_ERROR) {
|
|
||||||
Serial.println("Connect Failed");
|
|
||||||
} else if (error == OTA_RECEIVE_ERROR) {
|
|
||||||
Serial.println("Receive Failed");
|
|
||||||
} else if (error == OTA_END_ERROR) {
|
|
||||||
Serial.println("End Failed");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ArduinoOTA.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup_pwm_pca9685() {
|
|
||||||
pwmController.resetDevices(); // Software resets all PCA9685 devices on Wire line
|
|
||||||
|
|
||||||
pwmController.init(B000000); // Address pins A5-A0 set to B000000
|
|
||||||
pwmController.setPWMFrequency(200); // Default is 200Hz, supports 24Hz to 1526Hz
|
|
||||||
|
|
||||||
Serial.println(pwmController.getChannelPWM(0)); // Should output 2048, which is 128 << 4
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@@ -196,7 +82,7 @@ void setup() {
|
|||||||
pinMode(ESP12_LED, OUTPUT);
|
pinMode(ESP12_LED, OUTPUT);
|
||||||
|
|
||||||
Wire.begin(); // Wire must be started first
|
Wire.begin(); // Wire must be started first
|
||||||
Wire.setClock(400000); // Supported baud rates are 100kHz, 400kHz, and 1000kHz
|
Wire.setClock(1000000); // Supported baud rates are 100kHz, 400kHz, and 1000kHz
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
@@ -207,119 +93,34 @@ void setup() {
|
|||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
os_timer_setfn(&Timer1, timerCallback, &c);
|
Serial.println("");
|
||||||
os_timer_arm(&Timer1, 1, true);
|
Serial.print("Connected to ");
|
||||||
|
Serial.println(ssid);
|
||||||
|
|
||||||
Serial.println("Ready");
|
|
||||||
Serial.print("IP address: ");
|
Serial.print("IP address: ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
setup_ota();
|
ota_setup();
|
||||||
setup_webserver();
|
|
||||||
setup_pwm_pca9685();
|
httpServer.start();
|
||||||
|
httpServer.onNotFound(handleNotFound);
|
||||||
|
Serial.println("HTTP server started !");
|
||||||
|
|
||||||
|
stairs.setup();
|
||||||
|
Serial.println("PCA9685 connected !");
|
||||||
|
|
||||||
|
os_timer_setfn(&timer1, timerCallback, &timer_flag);
|
||||||
|
os_timer_arm(&timer1, 20, true);
|
||||||
|
|
||||||
|
stairs.setState(1);
|
||||||
|
stairs.setDirection(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t t;
|
|
||||||
#define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("µs")
|
|
||||||
#define TIMEIF_US(_str,_f, _l) t=micros(); _f; t=micros()-t; if(t > _l) { SP_US(_str, t); }
|
|
||||||
|
|
||||||
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval, uint8_t factor){
|
|
||||||
static uint8_t lastled = 255;
|
|
||||||
static uint8_t current_pwm = 0;
|
|
||||||
|
|
||||||
if(led != lastled){
|
|
||||||
pwmController.setChannelPWM(led, startval);
|
|
||||||
lastled = led;
|
|
||||||
current_pwm = startval;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(current_pwm == stopval){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(startval > stopval){
|
|
||||||
current_pwm -= 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
current_pwm += 1;
|
|
||||||
}
|
|
||||||
pwmController.setChannelPWM(led, current_pwm*factor);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define LEDCOUNT 16
|
|
||||||
|
|
||||||
void ledsequence(uint8_t direction, uint8_t onoff, uint8_t factor){
|
|
||||||
static int8_t led = 0;
|
|
||||||
static uint8_t brightness = 0;
|
|
||||||
static uint8_t lastbrightness = 0;
|
|
||||||
static uint8_t finish = 1;
|
|
||||||
static uint32_t status = 0;
|
|
||||||
uint32_t status_build = 0;
|
|
||||||
status_build |= direction << 16;
|
|
||||||
status_build |= onoff << 8;
|
|
||||||
status_build |= factor;
|
|
||||||
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 = LEDCOUNT-1;
|
|
||||||
if(onoff){
|
|
||||||
brightness = 127; // set brightness value depending of on/off
|
|
||||||
lastbrightness = 0;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
brightness = 0;
|
|
||||||
lastbrightness = 127;
|
|
||||||
}
|
|
||||||
status = status_build; // set parameter memory
|
|
||||||
Serial.print("----Status Changed! onoff: ");
|
|
||||||
Serial.print(onoff);
|
|
||||||
Serial.print(" dir: ");
|
|
||||||
Serial.println(direction);
|
|
||||||
|
|
||||||
}
|
|
||||||
if(!finish){ // finish == 0 -> action pending
|
|
||||||
if(!softstart_led(led,lastbrightness, brightness, factor)){
|
|
||||||
Serial.print("one LED finished, new set led: ");
|
|
||||||
Serial.print(led);
|
|
||||||
Serial.print(" last: ");
|
|
||||||
Serial.print(lastbrightness);
|
|
||||||
Serial.print(" curr: ");
|
|
||||||
Serial.println(brightness);
|
|
||||||
if(direction){
|
|
||||||
led++;
|
|
||||||
if(led >= LEDCOUNT) {
|
|
||||||
finish = 1;
|
|
||||||
//lastbrightness = brightness;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
led--;
|
|
||||||
if(led < 0){
|
|
||||||
//lastbrightness = brightness;
|
|
||||||
finish = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
if(millis() > 25000 && stairs.getState() == 1 && stairs.getDirection() == 1) stairs.setState(0);
|
||||||
|
if(millis() > 45000 && stairs.getDirection() == 1){
|
||||||
|
stairs.setState(1);
|
||||||
if(millis() - dimmtimer > 2){
|
stairs.setDirection(0);
|
||||||
//ledsequence(direction, onoff, 4);
|
|
||||||
dimmtimer = millis();
|
|
||||||
}
|
}
|
||||||
if(millis() > 25000 && onoff == 1 && direction == 1) onoff = 0;
|
TIMEIF_US(ArduinoOTA.handle(), 1000, "OTA");
|
||||||
if(millis() > 35000 && direction == 1){
|
TIMEIF_US(httpServer.handleClient(), 1000, "HTTP");
|
||||||
onoff = 1;
|
|
||||||
direction = 0;
|
|
||||||
}
|
|
||||||
TIMEIF_US("OTA", ArduinoOTA.handle(), 1000);
|
|
||||||
TIMEIF_US("HTTP", server.handleClient(), 1000);
|
|
||||||
}
|
}
|
||||||
+136
@@ -0,0 +1,136 @@
|
|||||||
|
#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(B000000);
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -12,23 +12,29 @@
|
|||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = nodemcuv2
|
board = nodemcuv2
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
|
||||||
|
; for http files
|
||||||
|
board_build.filesystem = littlefs
|
||||||
|
board_build.ldscript = eagle.flash.4m1m.ld
|
||||||
|
extra_scripts = pre:create_gz_files.py
|
||||||
|
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
extra_scripts = pre:extra_script.py
|
|
||||||
|
|
||||||
[env:serial]
|
[env:serial]
|
||||||
upload_protocol = esptool
|
upload_protocol = esptool
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
|
|
||||||
[env:ota]
|
[env:ota]
|
||||||
; stuff for OTA
|
; OTA => https://docs.platformio.org/en/latest/platforms/espressif8266.html#over-the-air-ota-update
|
||||||
; 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 !!>
|
||||||
upload_flags =
|
upload_flags =
|
||||||
--port=8266
|
--port=8266
|
||||||
|
--host_port=<!! PORT !!>
|
||||||
--auth=admin
|
--auth=admin
|
||||||
|
|
||||||
[env:debug]
|
[env:debug]
|
||||||
|
; 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
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
CD .\include\http
|
CD .\data
|
||||||
py.exe -m http.server
|
py.exe -m http.server
|
||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
cd include/http
|
cd data
|
||||||
python3 -m http.server
|
python3 -m http.server
|
||||||
Reference in new issue
Block a user