Compare commits

Author SHA1 Message Date
schmidtsi76327 d059c3d72d working, but need to write test 2021-06-25 18:35:16 +02:00
schmidtsi76327 55ebd21975 test 2021-06-25 04:53:06 +02:00
schmidtsi76327 2b2a135bd5 reorganzie main 2021-06-24 19:46:24 +02:00
bartschdo76253 a400b0464d deleted Wire setClock 2021-06-24 19:34:26 +02:00
7 changed files with 192 additions and 56 deletions

No files matched your search

+3
View File
@@ -66,3 +66,6 @@ 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 !!!!!
+4
View File
@@ -1,6 +1,10 @@
#ifndef __OTA_H #ifndef __OTA_H
#define __OTA_H #define __OTA_H
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
void ota_setup() { void ota_setup() {
ArduinoOTA.setPort(8266); ArduinoOTA.setPort(8266);
ArduinoOTA.setHostname("ESP_Treppenlicht"); ArduinoOTA.setHostname("ESP_Treppenlicht");
+62 -7
View File
@@ -1,4 +1,4 @@
#include "pwm.h" #include "treppe.h"
uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){ uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){
/* /*
@@ -15,7 +15,7 @@ uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){
static uint8_t lastled = 255; static uint8_t lastled = 255;
static float current_pwm = 0; static float current_pwm = 0;
static float stepsize = 1.0; static float stepsize = 0.5;
if(led != lastled){ if(led != lastled){
pwmController.setChannelPWM(led, (uint16_t)startval); pwmController.setChannelPWM(led, (uint16_t)startval);
lastled = led; lastled = led;
@@ -44,6 +44,7 @@ void Treppe::ledsequence(){
static uint8_t finish = 1; static uint8_t finish = 1;
static uint16_t status = 0; static uint16_t status = 0;
uint16_t status_build = 0; uint16_t status_build = 0;
status_build |= direction << 8; status_build |= direction << 8;
status_build |= state; status_build |= state;
if(status_build != status){ // check if any parameter changed if(status_build != status){ // check if any parameter changed
@@ -91,10 +92,58 @@ void Treppe::ledsequence(){
} }
} }
void Treppe::elelel()
{
if(state) {
if(direction) { // aufwärts
if(tick >= ticks_treppe-1) { // ziel erreicht
Serial.println("[Treppe] oberster tick !");
state = 0;
return;
}
tick++; // eins hoch
}
else { // abwärts
if(tick <= 0) { // ziel erreicht
Serial.println("[Treppe] unterster tick !");
state = 0;
return;
}
tick--; // eins runter
}
stufe = tick / ticks_pro_stufe;
float new_pwm = differenz_pwm_pro_tick * (tick - ticks_pro_stufe*stufe);
if(direction)
new_pwm += differenz_pwm_pro_tick;
new_pwm += idle_brightness;
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
);
}
}
// if(stufe > stairs || stufe < 0 || tick < 0 || tick > ticks_treppe-1) {
// Serial.println("[Treppe] ERROR, Something went wrong !");
// state = 0;
// return;
// }
void Treppe::setup(){ void Treppe::setup(){
Serial.printf("differenz_pwm_pro_tick %f\n", differenz_pwm_pro_tick);
pwmController.resetDevices(); pwmController.resetDevices();
// Deactive PCA9685 due to LED Flickering // Deactivate PCA9685_PhaseBalancer due to LED Flickering
// https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15 // https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
// see also lib/PCA9685-Arduin/PCA9685.h:204 // see also lib/PCA9685-Arduin/PCA9685.h:204
pwmController.init(PCA9685_PhaseBalancer_None); pwmController.init(PCA9685_PhaseBalancer_None);
@@ -102,9 +151,15 @@ void Treppe::setup(){
Serial.println("Hello from Treppe"); Serial.println("Hello from Treppe");
Serial.print("Treppe: initial parameters: stairs="); Serial.print("Treppe: initial parameters: stairs=");
Serial.println(stairs); Serial.println(stairs);
for(uint8_t i=0; i<stairs; i++) {
pwmController.setChannelPWM(i, idle_brightness);
}
} }
void Treppe::task(){ void Treppe::task(){
ledsequence(); //ledsequence();
elelel();
} }
uint16_t Treppe::setIdle(uint16_t _idle_brightness){ uint16_t Treppe::setIdle(uint16_t _idle_brightness){
@@ -125,7 +180,7 @@ uint16_t Treppe::setTime(uint16_t _time_per_stair){
uint8_t Treppe::setDirection(uint8_t _direction){ uint8_t Treppe::setDirection(uint8_t _direction){
direction = _direction; direction = _direction;
Serial.println("Treppe: Direction changed!"); Serial.printf("Treppe: Direction: %d!\n",direction);
// to do: implement state command variable to determine dimm-state // to do: implement state command variable to determine dimm-state
return direction; return direction;
} }
@@ -134,7 +189,7 @@ uint8_t Treppe::setState(uint8_t _state){
if(state == _state) return 1; if(state == _state) return 1;
else{ else{
state = _state; state = _state;
Serial.println("Treppe: State changed!"); Serial.printf("Treppe: State: %d!\n",state);
} }
return 0; return 0;
} }
+28 -5
View File
@@ -3,32 +3,55 @@
#include "PCA9685.h" #include "PCA9685.h"
class Treppe { class Treppe {
private: private:
uint8_t stairs; uint8_t stairs;
uint16_t time_per_stair = 300; // dimmtime per stair [ms] uint16_t time_per_stair = 300; // dimmtime per stair [ms]
uint16_t idle_brightness = 200; uint16_t idle_brightness = 0;
uint16_t active_brightness = 2048; uint16_t active_brightness = 500;
uint8_t direction = 0; uint8_t direction = 0;
uint8_t state = 0; uint8_t state = 0;
uint8_t switch_state = 0; uint8_t switch_state = 0;
uint32_t tick = 0;
uint32_t stufe = 0;
uint32_t ticks_treppe = 0;
uint32_t ticks_pro_stufe = 0;
float differenz_pwm_pro_tick = 0.0;
// initialize with i2c-Address 0, use Wire Library // initialize with i2c-Address 0, use Wire Library
PCA9685 pwmController; PCA9685 pwmController;
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval); uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
void ledsequence(); void ledsequence();
public: public:
Treppe(uint8_t _stairs) : stairs(_stairs){} 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 task(); // call periodically void task(); // call periodically
void setup(); void setup();
void elelel();
// Parameter section // Parameter section
uint16_t setIdle(uint16_t _idle_brightness); uint16_t setIdle(uint16_t _idle_brightness);
uint16_t setActive(uint16_t _active_brightness); uint16_t setActive(uint16_t _active_brightness);
uint16_t setTime(uint16_t _time_per_stair); 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 // Runtime Parameter section
uint8_t setDirection(uint8_t _direction); uint8_t setDirection(uint8_t _direction);
uint8_t setState(uint8_t _state); uint8_t setState(uint8_t _state);
+17 -14
View File
@@ -9,11 +9,7 @@ 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 "ota.h"
#include "wifi_credentials.h" #include "wifi_credentials.h"
#include "httpserver.h" #include "httpserver.h"
@@ -22,13 +18,10 @@ 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;
@@ -115,12 +108,22 @@ void setup() {
stairs.setDirection(1); stairs.setDirection(1);
} }
#include <random>
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);
// uint32_t t = rand() % stairs.getTicks();
// uint32_t d = rand() % 2;
// stairs.setTick(t);
// stairs.setDirection(d);
stairs.setDirection(!stairs.getDirection());
stairs.setState(1); stairs.setState(1);
stairs.setDirection(0);
} }
TIMEIF_US(ArduinoOTA.handle(), 1000, "OTA");
TIMEIF_US(httpServer.handleClient(), 1000, "HTTP"); TIMEIF_US(ArduinoOTA.handle(), 10000, "OTA");
TIMEIF_US(httpServer.handleClient(), 10000, "HTTP");
} }
+30 -30
View File
@@ -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()
{ // {
} // }
+48
View File
@@ -0,0 +1,48 @@
#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()
{
}