Compare commits
9
Commits
v0.4.0
...
e8329f2587
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8329f2587 | ||
|
|
014aa028d7 | ||
|
|
b47f778fc1 | ||
|
|
c7eaffda00 | ||
|
|
69e1e869a5 | ||
|
|
1a284080e8 | ||
|
|
3490e7ba44 | ||
|
|
d059c3d72d | ||
|
|
55ebd21975 |
No files matched your search
Vendored
+2
-1
@@ -48,5 +48,6 @@
|
||||
"streambuf": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"typeinfo": "cpp"
|
||||
}
|
||||
},
|
||||
"python.pythonPath": "C:\\Users\\simon\\AppData\\Local\\Programs\\Python\\Python37\\python.exe"
|
||||
}
|
||||
Binary file not shown.
@@ -72,3 +72,6 @@ LED Flickering issue
|
||||
https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
||||
|
||||
PlatformIO Library veraltet
|
||||
|
||||
|
||||
###TIMER in OTA unterbrechen !!!!!
|
||||
+2
-6
@@ -1,5 +1,4 @@
|
||||
#ifndef __OTA_H
|
||||
#define __OTA_H
|
||||
#pragma once
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
@@ -46,7 +45,4 @@ void ota_setup() {
|
||||
});
|
||||
ArduinoOTA.begin();
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // __OTA_H
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "PCA9685.h"
|
||||
|
||||
#define SENSOR1 15
|
||||
#define SENSOR2 12
|
||||
|
||||
#define INT_TIME 20 // interrupt intervall [ms]
|
||||
class Treppe {
|
||||
private:
|
||||
uint8_t stairs;
|
||||
uint16_t time_per_stair = 200; // dimmtime per stair [ms]
|
||||
uint16_t idle_brightness = 0;
|
||||
uint16_t active_brightness = 1048;
|
||||
|
||||
uint8_t direction = 0;
|
||||
uint8_t switch_direction = 0;
|
||||
uint8_t state = 0;
|
||||
uint8_t switch_state = 0;
|
||||
uint8_t finish = 1;
|
||||
|
||||
// initialize with i2c-Address 0, use Wire Library
|
||||
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;};
|
||||
};
|
||||
@@ -4,7 +4,7 @@
|
||||
// deleteFile("/hello.txt");
|
||||
// writeFile("/hello.txt", "Hello ");
|
||||
// appendFile("/hello.txt", "World!\n\r");
|
||||
// readFile("/hello.txt");
|
||||
// printFile("/hello.txt");
|
||||
// listDir("/");
|
||||
|
||||
FSInfo fsinfo;
|
||||
@@ -58,7 +58,12 @@ void ls(const char * dirname) {
|
||||
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);
|
||||
|
||||
File file = LittleFS.open(path, "r");
|
||||
@@ -1,16 +1,15 @@
|
||||
#ifndef __FILESYS_H
|
||||
#define __FILESYS_H
|
||||
#pragma once
|
||||
|
||||
#include <LittleFS.h>
|
||||
|
||||
bool mount_fs();
|
||||
bool format_fs();
|
||||
|
||||
File open(const char * path);
|
||||
|
||||
void ls(const char * dirname);
|
||||
void readFile(const char * path);
|
||||
void printFile(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
|
||||
@@ -14,4 +14,4 @@ bool HTTPServer::addRootFileHandler() {
|
||||
this->serveStatic("/favicon.png", LittleFS, "/favicon.png");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
#ifndef __HTTPSERVER_H
|
||||
#define __HTTPSERVER_H
|
||||
#pragma once
|
||||
|
||||
#include "filesys.h"
|
||||
#include <ESP8266WebServer.h>
|
||||
|
||||
|
||||
class HTTPServer : public ESP8266WebServer {
|
||||
private:
|
||||
const char* rootDir;
|
||||
@@ -35,6 +33,20 @@ public:
|
||||
this->listRoot();
|
||||
Serial.printf("\n\r");
|
||||
|
||||
// https://stackoverflow.com/questions/7627098/what-is-a-lambda-expression-in-c11
|
||||
on("/compress.html", [this]() {
|
||||
File f = open("/compress.html.gz");
|
||||
if (!f) {
|
||||
Serial.println("Failed to open file for reading");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Streaming /compress.html.gz to client");
|
||||
const String cont = "text/html";
|
||||
streamFile(f, cont);
|
||||
}
|
||||
});
|
||||
|
||||
if( this->addRootFileHandler() ){
|
||||
this->begin();
|
||||
Serial.printf("[HTTPServer] Server active on Port 80 !\n\r");
|
||||
@@ -44,5 +56,3 @@ public:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __HTTPSERVER_H
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "pwm.h"
|
||||
#include "treppe.h"
|
||||
|
||||
uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){
|
||||
/*
|
||||
@@ -30,7 +30,7 @@ uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){
|
||||
else {
|
||||
current_pwm += stepsize;
|
||||
}
|
||||
Serial.println((uint16_t)current_pwm);
|
||||
// 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);
|
||||
@@ -60,39 +60,80 @@ void Treppe::ledsequence(){
|
||||
lastbrightness = active_brightness;
|
||||
}
|
||||
status = status_build; // set parameter memory
|
||||
Serial.print("----Status Changed! onoff: ");
|
||||
Serial.print(state);
|
||||
Serial.print(" dir: ");
|
||||
Serial.println(direction);
|
||||
|
||||
Serial.printf("----Status Changed! onoff: %d, dir: %d\n", state, 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) {
|
||||
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;
|
||||
//lastbrightness = brightness;
|
||||
}
|
||||
}
|
||||
else{
|
||||
led--;
|
||||
if(led < 0){
|
||||
//lastbrightness = brightness;
|
||||
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(){
|
||||
Serial.printf("differenz_pwm_pro_tick %f\n", differenz_pwm_pro_tick);
|
||||
|
||||
pwmController.resetDevices();
|
||||
|
||||
// Deactive PCA9685 Phase Balancer due to LED Flickering
|
||||
@@ -108,6 +149,7 @@ void Treppe::setup(){
|
||||
Serial.print("Treppe: initial parameters: stairs=");
|
||||
Serial.println(stairs);
|
||||
}
|
||||
|
||||
void Treppe::task(){
|
||||
|
||||
if(finish){
|
||||
@@ -120,32 +162,41 @@ void Treppe::task(){
|
||||
current_sensor_state[1] = digitalRead(SENSOR2);
|
||||
|
||||
if(current_sensor_state[0] && !last_sensor_state[0] && state == 0){
|
||||
setTick(0);
|
||||
setAnAus(1);
|
||||
setDirection(1);
|
||||
setState(1);
|
||||
}
|
||||
|
||||
if(current_sensor_state[1] && !last_sensor_state[1] && state == 0){
|
||||
setTick(0);
|
||||
setAnAus(0);
|
||||
setDirection(0);
|
||||
setState(1);
|
||||
}
|
||||
|
||||
// first switch - off approach, use timer later
|
||||
if(!current_sensor_state[0] && last_sensor_state[0] && state == 1){
|
||||
setTick(ticks_treppe);
|
||||
setAnAus(1);
|
||||
setDirection(1);
|
||||
setState(0);
|
||||
}
|
||||
|
||||
if(!current_sensor_state[1] && last_sensor_state[1] && state == 1){
|
||||
setTick(ticks_treppe);
|
||||
setAnAus(1);
|
||||
setDirection(0);
|
||||
setState(0);
|
||||
}
|
||||
|
||||
last_sensor_state[0] = current_sensor_state[0];
|
||||
last_sensor_state[1] = current_sensor_state[1];
|
||||
ledsequence();
|
||||
|
||||
ledsequence();
|
||||
}
|
||||
|
||||
|
||||
uint16_t Treppe::setIdle(uint16_t _idle_brightness){
|
||||
idle_brightness = _idle_brightness;
|
||||
Serial.println("Treppe: idle brightness changed!");
|
||||
@@ -162,22 +213,20 @@ uint16_t Treppe::setTime(uint16_t _time_per_stair){
|
||||
return time_per_stair;
|
||||
}
|
||||
|
||||
uint8_t Treppe::setDirection(uint8_t _direction){
|
||||
void Treppe::setDirection(uint8_t _direction){
|
||||
switch_direction = _direction;
|
||||
Serial.println("Treppe: Direction changed!");
|
||||
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
|
||||
return switch_direction;
|
||||
}
|
||||
|
||||
uint8_t Treppe::setState(uint8_t _state){
|
||||
if(state == _state) return 1;
|
||||
else{
|
||||
switch_state = _state;
|
||||
Serial.println("Treppe: State Request changed!");
|
||||
if(finish) Serial.println("apply state request immediately");
|
||||
else Serial.println("currently active, state changes after activity");
|
||||
}
|
||||
return 0;
|
||||
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,75 @@
|
||||
#pragma once
|
||||
|
||||
#include "PCA9685.h"
|
||||
|
||||
#define SENSOR1 15
|
||||
#define SENSOR2 12
|
||||
|
||||
#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 = 0;
|
||||
uint16_t active_brightness = 500;
|
||||
|
||||
uint8_t direction = 0;
|
||||
uint8_t switch_direction = 0;
|
||||
uint8_t state = 0;
|
||||
uint8_t switch_state = 0;
|
||||
uint8_t 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;
|
||||
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
|
||||
void ledsequence();
|
||||
void rampe();
|
||||
|
||||
public:
|
||||
Treppe(uint8_t _stairs) : stairs(_stairs){
|
||||
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;
|
||||
}
|
||||
|
||||
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;};
|
||||
};
|
||||
+20
-5
@@ -9,8 +9,8 @@ extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
// OTA & WEB
|
||||
#include "ota.h"
|
||||
#include "wifi_credentials.h"
|
||||
#include "ota.h"
|
||||
#include "httpserver.h"
|
||||
|
||||
// BOARD
|
||||
@@ -18,10 +18,10 @@ extern "C" {
|
||||
#define NODEMCU_LED 16
|
||||
|
||||
// PWM
|
||||
#include "pwm.h"
|
||||
#include "treppe.h"
|
||||
os_timer_t timer1;
|
||||
uint8_t timer_flag = 0;
|
||||
Treppe stairs(13);
|
||||
Treppe stairs(16);
|
||||
|
||||
// WIFI
|
||||
const char* ssid = STASSID;
|
||||
@@ -105,7 +105,22 @@ void setup() {
|
||||
os_timer_arm(&timer1, 20, true);
|
||||
}
|
||||
|
||||
#include <random>
|
||||
|
||||
void loop() {
|
||||
TIMEIF_US(ArduinoOTA.handle(), 1000, "OTA");
|
||||
TIMEIF_US(httpServer.handleClient(), 1000, "HTTP");
|
||||
// if(stairs.getState() == 0) {
|
||||
// delay(1000);
|
||||
|
||||
// // uint32_t t = rand() % stairs.getTicks();
|
||||
// // uint32_t d = rand() % 2;
|
||||
|
||||
// // stairs.setTick(t);
|
||||
// // stairs.setDirection(d);
|
||||
|
||||
// stairs.setDirection(!stairs.getDirection());
|
||||
// stairs.setState(1);
|
||||
// }
|
||||
|
||||
TIMEIF_US(ArduinoOTA.handle(), 10000, "OTA");
|
||||
TIMEIF_US(httpServer.handleClient(), 10000, "HTTP");
|
||||
}
|
||||
+30
-30
@@ -1,40 +1,40 @@
|
||||
#include <Arduino.h>
|
||||
#include <unity.h>
|
||||
// #include <Arduino.h>
|
||||
// #include <unity.h>
|
||||
|
||||
String STR_TO_TEST;
|
||||
// String STR_TO_TEST;
|
||||
|
||||
void setUp(void) {
|
||||
// set stuff up here
|
||||
STR_TO_TEST = "Hello, world!";
|
||||
}
|
||||
// // void setUp(void) {
|
||||
// // // set stuff up here
|
||||
// // STR_TO_TEST = "Hello, world!";
|
||||
// // }
|
||||
|
||||
void tearDown(void) {
|
||||
// clean stuff up here
|
||||
STR_TO_TEST = "";
|
||||
}
|
||||
// // void tearDown(void) {
|
||||
// // // clean stuff up here
|
||||
// // STR_TO_TEST = "";
|
||||
// // }
|
||||
|
||||
void test_led_builtin_pin_number(void) {
|
||||
TEST_ASSERT_EQUAL(2, LED_BUILTIN);
|
||||
}
|
||||
// void test_led_builtin_pin_number(void) {
|
||||
// TEST_ASSERT_EQUAL(2, LED_BUILTIN);
|
||||
// }
|
||||
|
||||
void test_string_concat(void) {
|
||||
String hello = "Hello, ";
|
||||
String world = "world!";
|
||||
TEST_ASSERT_EQUAL_STRING(STR_TO_TEST.c_str(), (hello + world).c_str());
|
||||
}
|
||||
// void test_string_concat(void) {
|
||||
// String hello = "Hello, ";
|
||||
// String world = "world!";
|
||||
// TEST_ASSERT_EQUAL_STRING(STR_TO_TEST.c_str(), (hello + world).c_str());
|
||||
// }
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(2000); // service delay
|
||||
UNITY_BEGIN();
|
||||
// void setup()
|
||||
// {
|
||||
// delay(2000); // service delay
|
||||
// UNITY_BEGIN();
|
||||
|
||||
RUN_TEST(test_led_builtin_pin_number);
|
||||
RUN_TEST(test_string_concat);
|
||||
// RUN_TEST(test_led_builtin_pin_number);
|
||||
// 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