Files
klipper-voron/printer_data/config/CUSTOM/c_evening_daylight.cfg
T

62 lines
2.2 KiB
INI

[gcode_shell_command GET_TIME]
command: sh /home/pi/printer_data/config/SCRIPTS/get_time.sh
timeout: 0.05
verbose: False
[gcode_macro process_time_output]
gcode:
{% set output = printer["gcode_shell_command GET_TIME"].output %}
RESPOND MSG="{output}" # just prints raw output
[gcode_macro SHOW_LIGHT_TIME]
gcode:
{% set hour = printer["gcode_macro EVENING_DAYLIGHT"].hour %}
{% set minute = printer["gcode_macro EVENING_DAYLIGHT"].minute %}
{% set msg = "🕒 Stored time: " ~ hour|string ~ ":" ~ ("%02d"|format(minute)) %}
RESPOND MSG="{msg}"
[gcode_macro FETCH_TIME]
gcode:
RUN_SHELL_COMMAND CMD=GET_TIME
UPDATE_DELAYED_GCODE ID=process_time_output DURATION=0.25
[gcode_macro CHECK_AND_FADE_LIGHT]
gcode:
FETCH_TIME
G4 P0300 # wait 1.5s to ensure time vars are ready
EVENING_DAYLIGHT
[gcode_macro EVENING_DAYLIGHT]
variable_hour: 0
variable_minute: 0
variable_last_brightness: -1.0
gcode:
{% set total_minutes = hour * 60 + minute %}
{% set fade_out_start = 7 * 60 %}
{% set fade_out_end = 8 * 60 %}
{% set fade_in_start = 16 * 60 + 30 %}
{% set fade_in_end = 18 * 60 %}
{% if total_minutes < fade_out_start %}
{% set target = 1.0 %}
{% elif total_minutes < fade_out_end %}
{% set progress = 1.0 - ((total_minutes - fade_out_start) / (fade_out_end - fade_out_start)) %}
{% set target = progress %}
{% elif total_minutes < fade_in_start %}
{% set target = 0.0 %}
{% elif total_minutes < fade_in_end %}
{% set progress = (total_minutes - fade_in_start) / (fade_in_end - fade_in_start) %}
{% set target = progress %}
{% else %}
{% set target = 1.0 %}
{% endif %}
{% set rounded_target = (target * 100)|int / 100.0 %}
{% if rounded_target != last_brightness %}
SET_PIN PIN=daylight VALUE={rounded_target}
SET_GCODE_VARIABLE MACRO=EVENING_DAYLIGHT VARIABLE=last_brightness VALUE={rounded_target}
{% set time_display = hour|string ~ ":" ~ ("%02d"|format(minute)) %}
{% set fade_msg = "💡 Brightness: " ~ (rounded_target * 100)|int|string ~ "% at " ~ time_display %}
RESPOND MSG="{fade_msg}"
{% endif %}