Browse Source

small updates to treppe

tags/v1.0.0
Simon Schmidt 3 years ago
parent
commit
03d0cfedd1
2 changed files with 42 additions and 31 deletions
  1. 36
    25
      lib/treppe/treppe.cpp
  2. 6
    6
      lib/treppe/treppe.h

+ 36
- 25
lib/treppe/treppe.cpp View File

#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)
{ {

+ 6
- 6
lib/treppe/treppe.h View File

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_bright_internal = 0;
uint16_t active_brightness = 700;
uint16_t idle_pwm = 100;
uint16_t idle_pwm_internal = 0;
uint16_t active_pwm = 700;


uint16_t ldr_schwelle = 7; // activation value for FSM [lx] uint16_t ldr_schwelle = 7; // activation value for FSM [lx]




/* 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();


// 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…
Cancel
Save