Refactor brightness and colortemp_step calculations
- Simplified calculation of brightness_step and colortemp_step for better readability. - Corrected the calculation of reached final values for brightness and color temperature. - Introduced sleep_duration variable for improved flexibility in sleep intervals. - Adjusted the loop to start from 0 to correctly set the initial values. - Added a comment to clarify the purpose of the loop and its iteration. - Set the current_brightness and current_colortemp directly to the end values after the loop, ensuring they reach the intended final values. - Moved the sleep_duration calculation inside the loop for consistency. This refactoring enhances the script's clarity and ensures accurate calculation of brightness and color temperature steps during the gradual adjustment process. The changes also include improvements in sleep duration handling.
This commit is contained in:
parent
5ecd10a431
commit
05af18857a
21
wecker.sh
21
wecker.sh
@ -169,14 +169,17 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Calculate steps for brightness and color temperature per step
|
# Calculate steps for brightness and color temperature per step
|
||||||
brightness_step=$(bc <<< "($end_brightness - $start_brightness) / $steps")
|
brightness_step=$(( (end_brightness - start_brightness) / steps ))
|
||||||
echo "Brightness difference per step: $brightness_step"
|
echo "Brightness difference per step: $brightness_step"
|
||||||
echo "Reached final brightness: $((brightness_step * steps)) from $end_brightness"
|
echo "Reached final brightness: $((brightness_step * steps + start_brightness)) from $end_brightness"
|
||||||
colortemp_step=$(bc <<< "$start_colortemp / $steps")
|
|
||||||
|
colortemp_step=$(( start_colortemp / steps ))
|
||||||
echo "Color temperature difference per step: $colortemp_step"
|
echo "Color temperature difference per step: $colortemp_step"
|
||||||
echo "Reached final colortemp: $((start_colortemp - (colortemp_step * steps))) from $end_colortemp"
|
echo "Reached final colortemp: $((start_colortemp - colortemp_step * steps)) from $end_colortemp"
|
||||||
|
sleep_duration=$((duration_seconds / steps))
|
||||||
|
|
||||||
# Gradual adjustment of brightness and color temperature
|
# Gradual adjustment of brightness and color temperature
|
||||||
for ((i = 1; i <= $steps; i++)); do
|
for ((i = 0; i <= $steps; i++)); do
|
||||||
current_brightness=$(printf "%.0f" $(bc <<< "$start_brightness + ($brightness_step * $i)"))
|
current_brightness=$(printf "%.0f" $(bc <<< "$start_brightness + ($brightness_step * $i)"))
|
||||||
current_colortemp=$(printf "%.0f" $(bc <<< "$start_colortemp - ($colortemp_step * $i)"))
|
current_colortemp=$(printf "%.0f" $(bc <<< "$start_colortemp - ($colortemp_step * $i)"))
|
||||||
|
|
||||||
@ -200,10 +203,16 @@ for ((i = 1; i <= $steps; i++)); do
|
|||||||
sleep 12
|
sleep 12
|
||||||
echo "DEBUG: Wait 12 sec. between steps."
|
echo "DEBUG: Wait 12 sec. between steps."
|
||||||
else
|
else
|
||||||
sleep 27 # Changes every 30 (27) seconds
|
sleep $sleep_duration # Changes every 30 seconds
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Set to end values.
|
||||||
|
current_brightness="$end_brightness"
|
||||||
|
current_colortemp="$end_colortemp"
|
||||||
|
set_brightness "$end_brightness"
|
||||||
|
set_colortemp "$end_colortemp"
|
||||||
|
|
||||||
# Execute the check_ip function.
|
# Execute the check_ip function.
|
||||||
check_ip
|
check_ip
|
||||||
echo "$A72_ip"
|
echo "$A72_ip"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user