|
|
@@ -12,12 +12,15 @@ bool Treppe::dimm_stufe(uint8_t stufe) |
|
|
|
current_pwm += differenz_pwm_pro_tick; |
|
|
|
else |
|
|
|
current_pwm -= differenz_pwm_pro_tick; |
|
|
|
Serial.printf("dimm_stufe %d %f\n", stufe, current_pwm); |
|
|
|
Serial.printf("%3.0f", current_pwm); |
|
|
|
pwmController.setChannelPWM(stufe, static_cast<uint16_t>(current_pwm)); |
|
|
|
|
|
|
|
current_tick++; |
|
|
|
if (current_tick >= ticks_pro_stufe) |
|
|
|
if (current_tick >= ticks_pro_stufe) { |
|
|
|
Serial.println(""); |
|
|
|
return false; |
|
|
|
} |
|
|
|
Serial.print(" - "); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
@@ -43,9 +46,8 @@ void Treppe::anim_tick() |
|
|
|
{ |
|
|
|
if (!dimm_stufe(stufe)) |
|
|
|
{ |
|
|
|
Serial.printf("anim_tick(): stufe: %d, start: %d, ziel: %d, current %f\n", |
|
|
|
stufe, start_pwm, ziel_pwm, current_pwm); |
|
|
|
|
|
|
|
// Serial.printf("anim_tick(): stufe: %d, start: %d, ziel: %d, current %f\n", |
|
|
|
// stufe, start_pwm, ziel_pwm, current_pwm); |
|
|
|
if (fsm_outputs.laufrichtung == LR_HOCH) |
|
|
|
{ |
|
|
|
if (stufe >= stufen - 1) |
|
|
@@ -102,6 +104,7 @@ void Treppe::print_state_on_change() |
|
|
|
fsm_inputs.anim_beendet != last_in.anim_beendet || |
|
|
|
fsm_inputs.sensor_oben != last_in.sensor_oben || |
|
|
|
fsm_inputs.sensor_unten != last_in.sensor_unten || |
|
|
|
fsm_inputs.ldr_schwelle != last_in.ldr_schwelle || |
|
|
|
fsm_outputs.dimmrichtung != last_out.dimmrichtung || |
|
|
|
fsm_outputs.laufrichtung != last_out.laufrichtung || |
|
|
|
fsm_outputs.status != last_out.status) |
|
|
@@ -109,13 +112,14 @@ void Treppe::print_state_on_change() |
|
|
|
last_in.anim_beendet = fsm_inputs.anim_beendet; |
|
|
|
last_in.sensor_oben = fsm_inputs.sensor_oben; |
|
|
|
last_in.sensor_unten = fsm_inputs.sensor_unten; |
|
|
|
last_in.ldr_schwelle = fsm_inputs.ldr_schwelle; |
|
|
|
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 =>", |
|
|
|
fsm_inputs.sensor_oben, fsm_inputs.sensor_unten, fsm_inputs.anim_beendet); |
|
|
|
Serial.print(" step => "); |
|
|
|
Serial.printf("FSM IN: s_u: %d, s_o: %d, a_b: %d, l_s: %d => ", |
|
|
|
fsm_inputs.sensor_oben, fsm_inputs.sensor_unten, |
|
|
|
fsm_inputs.anim_beendet, fsm_inputs.ldr_schwelle); |
|
|
|
Serial.printf("OUT: LR: %d DR: %d ST: %d\n", |
|
|
|
fsm_outputs.laufrichtung, fsm_outputs.dimmrichtung, fsm_outputs.status); |
|
|
|
} |
|
|
@@ -210,31 +214,35 @@ bool Treppe::check_ldr() |
|
|
|
return active; |
|
|
|
} |
|
|
|
|
|
|
|
int i = 0; |
|
|
|
|
|
|
|
void Treppe::task() |
|
|
|
{ |
|
|
|
fsm_inputs.ldr_schwelle = check_ldr(); |
|
|
|
i = !i; |
|
|
|
fsm_inputs.ldr_schwelle = i; |
|
|
|
|
|
|
|
fsm_inputs.sensor_oben = 0UL; |
|
|
|
fsm_inputs.sensor_unten = 0UL; |
|
|
|
fsm_inputs.anim_beendet = 1UL; |
|
|
|
|
|
|
|
fsm_inputs.sensor_oben = read_sensor(SENSOR_OBEN); |
|
|
|
fsm_inputs.sensor_unten = read_sensor(SENSOR_UNTEN); |
|
|
|
fsm_inputs.anim_beendet = static_cast<bool>(anim_beendet); |
|
|
|
// fsm_inputs.ldr_schwelle = check_ldr(); |
|
|
|
// fsm_inputs.sensor_oben = read_sensor(SENSOR_OBEN); |
|
|
|
// fsm_inputs.sensor_unten = read_sensor(SENSOR_UNTEN); |
|
|
|
// fsm_inputs.anim_beendet = static_cast<bool>(anim_beendet); |
|
|
|
|
|
|
|
FSMTreppe_Obj.setExternalInputs(&fsm_inputs); |
|
|
|
FSMTreppe_Obj.step(); |
|
|
|
fsm_outputs = FSMTreppe_Obj.getExternalOutputs(); |
|
|
|
print_state_on_change(); |
|
|
|
|
|
|
|
if (fsm_outputs.status > ST_RUHEZUSTAND) |
|
|
|
if( fsm_outputs.status == ST_AUFDIMMEN_HOCH || |
|
|
|
fsm_outputs.status == ST_ABDIMMEN_HOCH || |
|
|
|
fsm_outputs.status == ST_AUFDIMMEN_RUNTER || |
|
|
|
fsm_outputs.status == ST_ABDIMMEN_RUNTER ) |
|
|
|
{ |
|
|
|
if (anim_beendet == true && |
|
|
|
(fsm_outputs.status == ST_AUFDIMMEN_HOCH || |
|
|
|
fsm_outputs.status == ST_ABDIMMEN_HOCH || |
|
|
|
fsm_outputs.status == ST_AUFDIMMEN_RUNTER || |
|
|
|
fsm_outputs.status == ST_ABDIMMEN_RUNTER) |
|
|
|
) |
|
|
|
{ |
|
|
|
if(anim_beendet) |
|
|
|
start_animation(); |
|
|
|
} |
|
|
|
if (!anim_beendet) |
|
|
|
else |
|
|
|
anim_tick(); |
|
|
|
} |
|
|
|
} |
|
|
@@ -244,7 +252,6 @@ void Treppe::berechne_dimmer() |
|
|
|
ticks_pro_stufe = time_per_stair / INT_TIME; // [ms] |
|
|
|
differenz_pwm_pro_tick = (float)(active_pwm - idle_pwm_internal) |
|
|
|
/ (float)ticks_pro_stufe; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void Treppe::setup() |