|
|
|
|
|
|
|
|
#include "treppe.h" |
|
|
#include "treppe.h" |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
dimm_stufe |
|
|
|
|
|
- dimmt stufe (0 - 15, PCA9685 outputs) mit linearen ticks |
|
|
- dimmt stufe (0 - 15, PCA9685 outputs) mit linearen ticks |
|
|
von idle bis active brightness |
|
|
|
|
|
|
|
|
von idle bis active pwm |
|
|
- return false solange gedimmt wird |
|
|
- return false solange gedimmt wird |
|
|
- return true bei nächster stufe |
|
|
- return true bei nächster stufe |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
- dimmt treppe (all PCA9685 outputs) mit linearen ticks |
|
|
|
|
|
von idle bis active brightness |
|
|
|
|
|
- return false solange gedimmt wird |
|
|
|
|
|
- return true bei ende |
|
|
|
|
|
*/ |
|
|
|
|
|
bool Treppe::dimm_treppe() |
|
|
|
|
|
{ |
|
|
|
|
|
// needs to be in state machine |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
animation tick |
|
|
|
|
|
- nach dem dimmen einer stufe wird die stufe weitergezählt |
|
|
- nach dem dimmen einer stufe wird die stufe weitergezählt |
|
|
- abbruch am ende => anim_beendet = true; |
|
|
- abbruch am ende => anim_beendet = true; |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fsm_outputs.dimmrichtung == DR_AUFDIMMEN) |
|
|
if (fsm_outputs.dimmrichtung == DR_AUFDIMMEN) |
|
|
{ |
|
|
{ |
|
|
start_pwm = idle_bright_internal; |
|
|
|
|
|
ziel_pwm = active_brightness; |
|
|
|
|
|
|
|
|
start_pwm = idle_pwm_internal; |
|
|
|
|
|
ziel_pwm = active_pwm; |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
start_pwm = active_brightness; |
|
|
|
|
|
ziel_pwm = idle_bright_internal; |
|
|
|
|
|
|
|
|
start_pwm = active_pwm; |
|
|
|
|
|
ziel_pwm = idle_pwm_internal; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
current_tick = 0; |
|
|
current_tick = 0; |
|
|
|
|
|
|
|
|
fsm_outputs.status == ST_ABDIMMEN_HOCH || |
|
|
fsm_outputs.status == ST_ABDIMMEN_HOCH || |
|
|
fsm_outputs.status == ST_AUFDIMMEN_RUNTER || |
|
|
fsm_outputs.status == ST_AUFDIMMEN_RUNTER || |
|
|
fsm_outputs.status == ST_ABDIMMEN_RUNTER) |
|
|
fsm_outputs.status == ST_ABDIMMEN_RUNTER) |
|
|
) |
|
|
|
|
|
|
|
|
) |
|
|
{ |
|
|
{ |
|
|
start_animation(); |
|
|
start_animation(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Treppe::berechne_dimmer() |
|
|
void Treppe::berechne_dimmer() |
|
|
{ |
|
|
{ |
|
|
ticks_pro_stufe = time_per_stair / INT_TIME; // [ms] |
|
|
ticks_pro_stufe = time_per_stair / INT_TIME; // [ms] |
|
|
differenz_pwm_pro_tick = (float)(active_brightness - idle_bright_internal) / (float)ticks_pro_stufe; |
|
|
|
|
|
|
|
|
differenz_pwm_pro_tick = (float)(active_pwm - idle_pwm_internal) |
|
|
|
|
|
/ (float)ticks_pro_stufe; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Treppe::setup() |
|
|
void Treppe::setup() |
|
|
|
|
|
|
|
|
pwmController.init(PCA9685_PhaseBalancer_None); |
|
|
pwmController.init(PCA9685_PhaseBalancer_None); |
|
|
//pwmController.init(PCA9685_PhaseBalancer_Linear); |
|
|
//pwmController.init(PCA9685_PhaseBalancer_Linear); |
|
|
pwmController.setPWMFrequency(100); |
|
|
pwmController.setPWMFrequency(100); |
|
|
//pwmController.setAllChannelsPWM(idle_brightness); |
|
|
|
|
|
|
|
|
//pwmController.setAllChannelsPWM(idle_pwm); |
|
|
|
|
|
|
|
|
pinMode(A0, INPUT); |
|
|
pinMode(A0, INPUT); |
|
|
pinMode(SENSOR_OBEN, INPUT); |
|
|
pinMode(SENSOR_OBEN, INPUT); |
|
|
|
|
|
|
|
|
Serial.printf("Treppe: initial parameters: stufen=%d\n", stufen); |
|
|
Serial.printf("Treppe: initial parameters: stufen=%d\n", stufen); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Treppe::set_idle_prozent(int prozent) { |
|
|
void Treppe::set_idle_prozent(int prozent) { |
|
|
uint16_t new_pwm = 0xFFF * prozent / 100; |
|
|
uint16_t new_pwm = 0xFFF * prozent / 100; |
|
|
set_idle_pwm(new_pwm); |
|
|
set_idle_pwm(new_pwm); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Treppe::set_idle_pwm(uint16_t _idle_brightness) |
|
|
|
|
|
|
|
|
void Treppe::set_idle_pwm(uint16_t new_idle_pwm) |
|
|
{ |
|
|
{ |
|
|
if(_idle_brightness > active_brightness) { |
|
|
|
|
|
idle_bright_internal = active_brightness; |
|
|
|
|
|
|
|
|
if(new_idle_pwm > active_pwm) { |
|
|
|
|
|
idle_pwm = active_pwm; |
|
|
} else { |
|
|
} else { |
|
|
idle_bright_internal = _idle_brightness; |
|
|
|
|
|
|
|
|
idle_pwm = new_idle_pwm; |
|
|
} |
|
|
} |
|
|
Serial.printf("Treppe: idle_bright_internal=%d\n", idle_bright_internal); |
|
|
|
|
|
berechne_dimmer(); |
|
|
|
|
|
|
|
|
|
|
|
pwmController.setAllChannelsPWM(idle_bright_internal); |
|
|
|
|
|
|
|
|
Serial.printf("Treppe: idle_pwm=%d\n", idle_pwm); |
|
|
|
|
|
berechne_dimmer(); |
|
|
|
|
|
activate_idle_pwm(true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Treppe::activate_idle_pwm(bool active) |
|
|
void Treppe::activate_idle_pwm(bool active) |
|
|
{ |
|
|
{ |
|
|
static uint8_t former_active = 0; |
|
|
static uint8_t former_active = 0; |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
if (active != former_active) |
|
|
if (active != former_active) |
|
|
{ |
|
|
{ |
|
|
idle_bright_internal = idle_brightness * active; |
|
|
|
|
|
|
|
|
idle_pwm_internal = idle_pwm * active; |
|
|
// Dimming Function for all LEDS ? |
|
|
// Dimming Function for all LEDS ? |
|
|
pwmController.setAllChannelsPWM(idle_bright_internal); |
|
|
|
|
|
|
|
|
pwmController.setAllChannelsPWM(idle_pwm_internal); |
|
|
former_active = active; |
|
|
former_active = active; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Treppe::set_active_pwm(uint16_t _active_brightness) |
|
|
|
|
|
|
|
|
void Treppe::set_active_pwm(uint16_t _active_pwm) |
|
|
{ |
|
|
{ |
|
|
active_brightness = _active_brightness; |
|
|
|
|
|
|
|
|
active_pwm = _active_pwm; |
|
|
berechne_dimmer(); |
|
|
berechne_dimmer(); |
|
|
Serial.printf("Treppe: active_brightness=%d\n", active_brightness); |
|
|
|
|
|
|
|
|
Serial.printf("Treppe: active_pwm=%d\n", active_pwm); |
|
|
} |
|
|
} |
|
|
void Treppe::set_time_per_stair(uint16_t _time_per_stair) |
|
|
void Treppe::set_time_per_stair(uint16_t _time_per_stair) |
|
|
{ |
|
|
{ |