forgot smtn in print, spaces to 4

This commit is contained in:
Simon Schmidt 2021-07-03 17:51:14 +02:00
parent b2ddc978b6
commit 8351a6430c

View File

@ -1,6 +1,7 @@
#include "treppe.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)
{
/* /*
softstart task softstart task
@ -16,30 +17,36 @@ 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 = 1.0;
if(led != lastled){ if (led != lastled)
{
pwmController.setChannelPWM(led, (uint16_t)startval); pwmController.setChannelPWM(led, (uint16_t)startval);
lastled = led; lastled = led;
current_pwm = startval; current_pwm = startval;
stepsize = INT_TIME*abs(stopval - startval)/(float)time_per_stair; // only valid at 1ms function call interval stepsize = INT_TIME * abs(stopval - startval) / (float)time_per_stair; // only valid at 1ms function call interval
return 1; return 1;
} }
if(startval > stopval){ if (startval > stopval)
{
current_pwm -= stepsize; current_pwm -= stepsize;
} }
else { else
{
current_pwm += stepsize; current_pwm += stepsize;
} }
// Serial.println((uint16_t)current_pwm); // Serial.println((uint16_t)current_pwm);
pwmController.setChannelPWM(led, (uint16_t)current_pwm); pwmController.setChannelPWM(led, (uint16_t)current_pwm);
if(current_pwm > stopval - stepsize && current_pwm < stopval + stepsize){ if (current_pwm > stopval - stepsize && current_pwm < stopval + stepsize)
if(stopval == 0) pwmController.setChannelPWM(led, 0); {
if (stopval == 0)
pwmController.setChannelPWM(led, 0);
return 0; return 0;
} }
return 1; return 1;
} }
void Treppe::ledsequence(){ void Treppe::ledsequence()
{
static int8_t led = 0; static int8_t led = 0;
static uint16_t brightness = 0; static uint16_t brightness = 0;
static uint16_t lastbrightness = 0; static uint16_t lastbrightness = 0;
@ -47,15 +54,20 @@ void Treppe::ledsequence(){
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
finish = 0; // set state unfinished -> start action finish = 0; // set state unfinished -> start action
if(direction) led = 0; // reset led counter depending of direction if (direction)
else led = stairs-1; led = 0; // reset led counter depending of direction
if(state){ else
led = stairs - 1;
if (state)
{
brightness = active_brightness; // set brightness value depending of on/off brightness = active_brightness; // set brightness value depending of on/off
lastbrightness = idle_brightness; lastbrightness = idle_brightness;
} }
else{ else
{
brightness = idle_brightness; brightness = idle_brightness;
lastbrightness = active_brightness; lastbrightness = active_brightness;
} }
@ -63,19 +75,23 @@ void Treppe::ledsequence(){
Serial.printf("----Status Changed! onoff: %d, dir: %d\n", state, direction); Serial.printf("----Status Changed! onoff: %d, dir: %d\n", state, direction);
} }
if(!finish){ // finish == 0 -> action pending if (!finish)
if(!softstart_led(led,lastbrightness, brightness)){ { // finish == 0 -> action pending
if (!softstart_led(led, lastbrightness, brightness))
{
Serial.printf("one LED finished: led: %d, last: %d, curr %d\n", Serial.printf("one LED finished: led: %d, last: %d, curr %d\n",
led, lastbrightness, brightness); led, lastbrightness, brightness);
if(direction){ if (direction)
{
led++; led++;
if(led >= stairs) if (led >= stairs)
finish = 1; finish = 1;
} }
else{ else
{
led--; led--;
if(led < 0) if (led < 0)
finish = 1; finish = 1;
} }
} }
@ -84,22 +100,28 @@ void Treppe::ledsequence(){
void Treppe::rampe() void Treppe::rampe()
{ {
if(state) { if (state)
{
finish = 0; finish = 0;
state = 0;// set parameter memory state = 0; // set parameter memory
} }
if(!finish) { if (!finish)
if(direction) { // aufwärts {
if(tick >= ticks_treppe-1) { // ziel erreicht if (direction)
{ // aufwärts
if (tick >= ticks_treppe - 1)
{ // ziel erreicht
Serial.println("[Treppe] oberster tick !"); Serial.println("[Treppe] oberster tick !");
finish = 1; finish = 1;
return; return;
} }
tick++; // eins hoch tick++; // eins hoch
} }
else { // abwärts else
if(tick <= 0) { // ziel erreicht { // abwärts
if (tick <= 0)
{ // ziel erreicht
Serial.println("[Treppe] unterster tick !"); Serial.println("[Treppe] unterster tick !");
finish = 1; finish = 1;
return; return;
@ -110,28 +132,32 @@ void Treppe::rampe()
stufe = tick / ticks_pro_stufe; stufe = tick / ticks_pro_stufe;
float new_pwm = 0.0; float new_pwm = 0.0;
if(an_aus) { if (an_aus)
new_pwm = differenz_pwm_pro_tick * (tick - ticks_pro_stufe*stufe); {
new_pwm = differenz_pwm_pro_tick * (tick - ticks_pro_stufe * stufe);
new_pwm += idle_brightness; new_pwm += idle_brightness;
if(direction) new_pwm += differenz_pwm_pro_tick; if (direction)
new_pwm += differenz_pwm_pro_tick;
} }
else { else
new_pwm = active_brightness - differenz_pwm_pro_tick * (tick - ticks_pro_stufe*stufe); {
new_pwm = active_brightness - differenz_pwm_pro_tick * (tick - ticks_pro_stufe * stufe);
new_pwm += idle_brightness; new_pwm += idle_brightness;
if(direction) new_pwm -= differenz_pwm_pro_tick; if (direction)
new_pwm -= differenz_pwm_pro_tick;
} }
pwmController.setChannelPWM(stufe, (uint16_t) new_pwm); pwmController.setChannelPWM(stufe, (uint16_t)new_pwm);
Serial.printf("tick %04u, led %02d:%02u, pwm %4.1f\n", Serial.printf("tick %04u, led %02d:%02u, pwm %4.1f\n",
tick, tick,
stufe, stufe,
(tick - ticks_pro_stufe*stufe), (tick - ticks_pro_stufe * stufe),
new_pwm new_pwm);
);
} }
} }
void Treppe::setup(){ void Treppe::setup()
{
pwmController.resetDevices(); pwmController.resetDevices();
// Deactive PCA9685 Phase Balancer due to LED Flickering // Deactive PCA9685 Phase Balancer due to LED Flickering
@ -154,20 +180,24 @@ void Treppe::setup(){
Serial.println(stairs); Serial.println(stairs);
} }
void Treppe::print_state_on_change() { void Treppe::print_state_on_change()
{
static FSMTreppeModelClass::ExtU_FSMTreppe_T last_in; static FSMTreppeModelClass::ExtU_FSMTreppe_T last_in;
static FSMTreppeModelClass::ExtY_FSMTreppe_T last_out; static FSMTreppeModelClass::ExtY_FSMTreppe_T last_out;
if( if (
fsm_inputs.anim_beendet != last_in.anim_beendet || fsm_inputs.anim_beendet != last_in.anim_beendet ||
fsm_inputs.sensor_oben != last_in.sensor_oben || fsm_inputs.sensor_oben != last_in.sensor_oben ||
fsm_inputs.sensor_unten != last_in.sensor_unten || fsm_inputs.sensor_unten != last_in.sensor_unten ||
fsm_outputs.dimmrichtung != last_out.dimmrichtung || fsm_outputs.dimmrichtung != last_out.dimmrichtung ||
fsm_outputs.laufrichtung != last_out.laufrichtung || fsm_outputs.laufrichtung != last_out.laufrichtung ||
fsm_outputs.status != last_out.status fsm_outputs.status != last_out.status)
) { {
last_in.anim_beendet = fsm_inputs.anim_beendet; last_in.anim_beendet = fsm_inputs.anim_beendet;
last_in.sensor_oben = fsm_inputs.sensor_oben; last_in.sensor_oben = fsm_inputs.sensor_oben;
last_in.sensor_unten = fsm_inputs.sensor_unten; last_in.sensor_unten = fsm_inputs.sensor_unten;
last_out.dimmrichtung = fsm_outputs.dimmrichtung;
last_out.laufrichtung = fsm_outputs.laufrichtung;
last_out.status = fsm_outputs.status;
Serial.printf("FSM IN: s_u: %d, s_o: %d, beendet: %d =>", Serial.printf("FSM IN: s_u: %d, s_o: %d, beendet: %d =>",
fsm_inputs.sensor_oben, fsm_inputs.sensor_unten, fsm_inputs.anim_beendet); fsm_inputs.sensor_oben, fsm_inputs.sensor_unten, fsm_inputs.anim_beendet);
@ -177,10 +207,12 @@ void Treppe::print_state_on_change() {
} }
} }
void Treppe::task(){ void Treppe::task()
{
//Serial.printf("LDR: %f\n", ((float)analogRead(A0))/1023.*3.68); //Serial.printf("LDR: %f\n", ((float)analogRead(A0))/1023.*3.68);
if(finish){ if (finish)
{
direction = switch_direction; direction = switch_direction;
state = switch_state; state = switch_state;
} }
@ -206,37 +238,47 @@ void Treppe::task(){
ledsequence(); ledsequence();
} }
uint16_t Treppe::setIdle(uint16_t _idle_brightness)
uint16_t Treppe::setIdle(uint16_t _idle_brightness){ {
idle_brightness = _idle_brightness; idle_brightness = _idle_brightness;
Serial.println("Treppe: idle brightness changed!"); Serial.println("Treppe: idle brightness changed!");
return idle_brightness; return idle_brightness;
} }
uint16_t Treppe::setActive(uint16_t _active_brightness){ uint16_t Treppe::setActive(uint16_t _active_brightness)
{
active_brightness = _active_brightness; active_brightness = _active_brightness;
Serial.println("Treppe: active brightness changed!"); Serial.println("Treppe: active brightness changed!");
return active_brightness; return active_brightness;
} }
uint16_t Treppe::setTime(uint16_t _time_per_stair){ uint16_t Treppe::setTime(uint16_t _time_per_stair)
{
time_per_stair = _time_per_stair; time_per_stair = _time_per_stair;
Serial.println("Treppe: time changed!"); Serial.println("Treppe: time changed!");
return time_per_stair; return time_per_stair;
} }
void Treppe::setDirection(uint8_t _direction){ void Treppe::setDirection(uint8_t _direction)
{
switch_direction = _direction; switch_direction = _direction;
Serial.printf("Treppe: switch_direction=%d!\n", switch_direction); Serial.printf("Treppe: switch_direction=%d!\n", switch_direction);
if(finish) Serial.println("apply direction request immediately"); if (finish)
else Serial.println("currently active, dir change afterwards"); Serial.println("apply direction request immediately");
else
Serial.println("currently active, dir change afterwards");
// to do: implement state command variable to determine dimm-state // to do: implement state command variable to determine dimm-state
} }
void Treppe::setState(uint8_t _state){ void Treppe::setState(uint8_t _state)
if(state == _state) return; {
else { if (state == _state)
return;
else
{
switch_state = _state; switch_state = _state;
Serial.printf("Treppe: switch_state=%d!\n", switch_state); Serial.printf("Treppe: switch_state=%d!\n", switch_state);
if(finish) Serial.println("apply state request immediately"); if (finish)
else Serial.println("currently active, state changes after activity"); Serial.println("apply state request immediately");
else
Serial.println("currently active, state changes after activity");
} }
} }