small updates to treppe
This commit is contained in:
parent
66d220cdb0
commit
03d0cfedd1
@ -1,9 +1,8 @@
|
|||||||
#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
|
||||||
*/
|
*/
|
||||||
@ -22,8 +21,21 @@ bool Treppe::dimm_stufe(uint8_t 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;
|
||||||
*/
|
*/
|
||||||
@ -69,13 +81,13 @@ void Treppe::start_animation()
|
|||||||
|
|
||||||
if (fsm_outputs.dimmrichtung == DR_AUFDIMMEN)
|
if (fsm_outputs.dimmrichtung == DR_AUFDIMMEN)
|
||||||
{
|
{
|
||||||
start_pwm = idle_bright_internal;
|
start_pwm = idle_pwm_internal;
|
||||||
ziel_pwm = active_brightness;
|
ziel_pwm = active_pwm;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
start_pwm = active_brightness;
|
start_pwm = active_pwm;
|
||||||
ziel_pwm = idle_bright_internal;
|
ziel_pwm = idle_pwm_internal;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_tick = 0;
|
current_tick = 0;
|
||||||
@ -217,7 +229,7 @@ void Treppe::task()
|
|||||||
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();
|
||||||
}
|
}
|
||||||
@ -229,7 +241,9 @@ void Treppe::task()
|
|||||||
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()
|
||||||
@ -241,7 +255,7 @@ 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);
|
||||||
@ -253,27 +267,24 @@ void Treppe::setup()
|
|||||||
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) {
|
if(new_idle_pwm > active_pwm) {
|
||||||
idle_bright_internal = active_brightness;
|
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);
|
|
||||||
|
Serial.printf("Treppe: idle_pwm=%d\n", idle_pwm);
|
||||||
berechne_dimmer();
|
berechne_dimmer();
|
||||||
|
activate_idle_pwm(true);
|
||||||
pwmController.setAllChannelsPWM(idle_bright_internal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
@ -282,19 +293,19 @@ void Treppe::activate_idle_pwm(bool active)
|
|||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
@ -17,10 +17,9 @@ class Treppe {
|
|||||||
private:
|
private:
|
||||||
const uint8_t stufen;
|
const uint8_t stufen;
|
||||||
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
|
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
|
||||||
uint16_t idle_brightness = 100;
|
uint16_t idle_pwm = 100;
|
||||||
uint16_t idle_bright_internal = 0;
|
uint16_t idle_pwm_internal = 0;
|
||||||
|
uint16_t active_pwm = 700;
|
||||||
uint16_t active_brightness = 700;
|
|
||||||
|
|
||||||
uint16_t ldr_schwelle = 7; // activation value for FSM [lx]
|
uint16_t ldr_schwelle = 7; // activation value for FSM [lx]
|
||||||
|
|
||||||
@ -60,6 +59,7 @@ private:
|
|||||||
|
|
||||||
/* DIMM */
|
/* DIMM */
|
||||||
bool dimm_stufe(uint8_t stufe);
|
bool dimm_stufe(uint8_t stufe);
|
||||||
|
bool dimm_treppe();
|
||||||
void anim_tick();
|
void anim_tick();
|
||||||
void start_animation();
|
void start_animation();
|
||||||
void berechne_dimmer();
|
void berechne_dimmer();
|
||||||
@ -83,8 +83,8 @@ public:
|
|||||||
|
|
||||||
// Parameter section
|
// Parameter section
|
||||||
void set_idle_prozent(int prozent);
|
void set_idle_prozent(int prozent);
|
||||||
void set_idle_pwm(uint16_t _idle_brightness);
|
void set_idle_pwm(uint16_t _idle_pwm);
|
||||||
void activate_idle_pwm(bool active);
|
void activate_idle_pwm(bool active);
|
||||||
void set_active_pwm(uint16_t _active_brightness);
|
void set_active_pwm(uint16_t _active_pwm);
|
||||||
void set_time_per_stair(uint16_t _time_per_stair);
|
void set_time_per_stair(uint16_t _time_per_stair);
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user