Merge pull request #11456 from stefanbode/patch-10

Add shutter support for more than 8 relays
This commit is contained in:
Theo Arends 2021-03-24 16:16:44 +01:00 committed by GitHub
commit 0be8bdee09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 6 deletions

View File

@ -242,7 +242,7 @@ void ShutterInit(void)
for (uint32_t i = 0; i < MAX_SHUTTERS; i++) {
// set startrelay to 1 on first init, but only to shutter 1. 90% usecase
Settings.shutter_startrelay[i] = (Settings.shutter_startrelay[i] == 0 && i == 0? 1 : Settings.shutter_startrelay[i]);
if (Settings.shutter_startrelay[i] && (Settings.shutter_startrelay[i] < 9)) {
if (Settings.shutter_startrelay[i] && (Settings.shutter_startrelay[i] <= MAX_RELAYS )) {
TasmotaGlobal.shutters_present++;
// Add the two relays to the mask to knaw they belong to shutters
@ -389,9 +389,21 @@ void ShutterCalculateAccelerator(uint8_t i)
// decellaration way from current velocity
current_stop_way = min_runtime_ms * STEPS_PER_SECOND * (current_pwm_velocity + velocity_change_per_step_max) * Shutter[i].direction / 2 / ShutterGlobal.open_velocity_max - (Shutter[i].accelerator<0?Shutter[i].direction*1000*current_pwm_velocity/ShutterGlobal.open_velocity_max:0);
next_possible_stop_position = current_real_position + current_stop_way ;
// ensure that the accelerotor kicks in at least one step BEFORE it is to late and a hard stop required.
if (next_possible_stop_position * Shutter[i].direction > Shutter[i].target_position * Shutter[i].direction ) {
// ensure that the accelerotor kicks in at the first overrun of the target position
if ( Shutter[i].accelerator < 0 || next_possible_stop_position * Shutter[i].direction > Shutter[i].target_position * Shutter[i].direction ) {
// if startet to early because of 0.05sec maximum accuracy and final position is to far away (200) accelerate a bit less
if (next_possible_stop_position * Shutter[i].direction+200 < Shutter[i].target_position * Shutter[i].direction) {
Shutter[i].accelerator = -velocity_change_per_step_max*9/10;
} else {
// in any case increase accelleration if overrun is detected during decelleration
if (next_possible_stop_position * Shutter[i].direction > Shutter[i].target_position * Shutter[i].direction && Shutter[i].accelerator < 0) {
Shutter[i].accelerator = -velocity_change_per_step_max*11/10;
} else {
// as long as the calculated end position is ok stay with proposed decelleration
Shutter[i].accelerator = -velocity_change_per_step_max;
}
}
// detect during the acceleration phase the point final speed is reached
} else if ( Shutter[i].accelerator > 0 && current_pwm_velocity == velocity_max) {
Shutter[i].accelerator = 0;
}