|
|
|
|
|
|
|
|
current_pwm += differenz_pwm_pro_tick; |
|
|
current_pwm += differenz_pwm_pro_tick; |
|
|
else |
|
|
else |
|
|
current_pwm -= differenz_pwm_pro_tick; |
|
|
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)); |
|
|
pwmController.setChannelPWM(stufe, static_cast<uint16_t>(current_pwm)); |
|
|
|
|
|
|
|
|
current_tick++; |
|
|
current_tick++; |
|
|
if (current_tick >= ticks_pro_stufe) |
|
|
|
|
|
|
|
|
if (current_tick >= ticks_pro_stufe) { |
|
|
|
|
|
Serial.println(""); |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
Serial.print(" - "); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
if (!dimm_stufe(stufe)) |
|
|
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 (fsm_outputs.laufrichtung == LR_HOCH) |
|
|
{ |
|
|
{ |
|
|
if (stufe >= stufen - 1) |
|
|
if (stufe >= stufen - 1) |
|
|
|
|
|
|
|
|
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_inputs.ldr_schwelle != last_in.ldr_schwelle || |
|
|
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_in.ldr_schwelle = fsm_inputs.ldr_schwelle; |
|
|
last_out.dimmrichtung = fsm_outputs.dimmrichtung; |
|
|
last_out.dimmrichtung = fsm_outputs.dimmrichtung; |
|
|
last_out.laufrichtung = fsm_outputs.laufrichtung; |
|
|
last_out.laufrichtung = fsm_outputs.laufrichtung; |
|
|
last_out.status = fsm_outputs.status; |
|
|
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", |
|
|
Serial.printf("OUT: LR: %d DR: %d ST: %d\n", |
|
|
fsm_outputs.laufrichtung, fsm_outputs.dimmrichtung, fsm_outputs.status); |
|
|
fsm_outputs.laufrichtung, fsm_outputs.dimmrichtung, fsm_outputs.status); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return active; |
|
|
return active; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int i = 0; |
|
|
|
|
|
|
|
|
void Treppe::task() |
|
|
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.setExternalInputs(&fsm_inputs); |
|
|
FSMTreppe_Obj.step(); |
|
|
FSMTreppe_Obj.step(); |
|
|
fsm_outputs = FSMTreppe_Obj.getExternalOutputs(); |
|
|
fsm_outputs = FSMTreppe_Obj.getExternalOutputs(); |
|
|
print_state_on_change(); |
|
|
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(); |
|
|
start_animation(); |
|
|
} |
|
|
|
|
|
if (!anim_beendet) |
|
|
|
|
|
|
|
|
else |
|
|
anim_tick(); |
|
|
anim_tick(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ticks_pro_stufe = time_per_stair / INT_TIME; // [ms] |
|
|
ticks_pro_stufe = time_per_stair / INT_TIME; // [ms] |
|
|
differenz_pwm_pro_tick = (float)(active_pwm - idle_pwm_internal) |
|
|
differenz_pwm_pro_tick = (float)(active_pwm - idle_pwm_internal) |
|
|
/ (float)ticks_pro_stufe; |
|
|
/ (float)ticks_pro_stufe; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Treppe::setup() |
|
|
void Treppe::setup() |