Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

execute G-Code after render finish #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions component/timelapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self, confighelper: ConfigHelper) -> None:
'mode': "layermacro",
'camera': 0,
'snapshoturl': "http://localhost:8080/?action=snapshot",
'gcode_verbose': True,
'gcode_verbose': False,
'parkhead': False,
'parkpos': "back_left",
'park_custom_pos_x': 0.0,
Expand Down Expand Up @@ -429,6 +429,7 @@ async def handle_status_update(self, status: str) -> None:
ioloop = IOLoop.current()
ioloop.spawn_callback(self.render)


def cleanup(self) -> None:
logging.debug("cleanup frame directory")
filelist = glob.glob(self.temp_dir + "frame*.jpg")
Expand Down Expand Up @@ -488,12 +489,11 @@ def call_render(self, byrendermacro=False) -> None:
self.byrendermacro = byrendermacro
ioloop = IOLoop.current()
ioloop.spawn_callback(self.render)

async def render(self, webrequest=None):
filelist = sorted(glob.glob(self.temp_dir + "frame*.jpg"))
self.framecount = len(filelist)
result = {'action': 'render'}

if not filelist:
msg = "no frames to render, skip"
status = "skipped"
Expand Down Expand Up @@ -609,6 +609,15 @@ async def render(self, webrequest=None):
self.out_dir + outfile + ".mp4")
except OSError as err:
logging.info(f"moving output file failed: {err}")

gcommand = "_done_shutdown"
logging.debug(f"run gcommand: {gcommand}")
try:
await self.klippy_apis.run_gcode(gcommand)
except self.server.error:
msg = f"Error executing GCode {gcommand}"
logging.exception(msg)


# copy image preview
if self.config['previewImage']:
Expand Down
32 changes: 27 additions & 5 deletions klipper_macro/timelapse.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license
#
# Macro version 1.1
# Macro version 1.2
#

##### DO NOT CHANGE ANY MACRO!!! #####
Expand All @@ -15,6 +15,9 @@
# GET_TIMELAPSE_SETUP: Print the Timelapse setup to console #
# #
##########################################################################
[gcode_macro get_timelapse_status]
gcode:
GET_TIMELAPSE_SETUP

[gcode_macro GET_TIMELAPSE_SETUP]
description: Print the Timelapse setup
Expand All @@ -41,9 +44,10 @@ gcode:
###############################################################################################

[gcode_macro _SET_TIMELAPSE_SETUP]
description: Set user parameters for timelaps
description: Set user parameters for timelapse
gcode:
##### get dictonaries #####
UPDATE_DELAYED_GCODE ID=_done_shutdown_timed DURATION=0
{% set enable = printer['gcode_macro TIMELAPSE_TAKE_FRAME'].enable %}
{% set verbose = printer['gcode_macro TIMELAPSE_TAKE_FRAME'].verbose %}
{% set park = printer['gcode_macro TIMELAPSE_TAKE_FRAME'].park %}
Expand Down Expand Up @@ -239,12 +243,12 @@ gcode:
{% endif %}
{% else %}
{% if verbose|lower == 'true' %}
{action_respond_info("Timelapse: take frame ignored")}
{action_respond_info("Timelapse: disabled, take frame ignored")}
{% endif %}
{% endif %}

[gcode_macro _TIMELAPSE_NEW_FRAME]
description: action call for timelaps shoot. must be a seperate macro
description: action call for timelapse shoot. must be a seperate macro
gcode:
{% set hyperlapse = false %}
{% if params.HYPERLAPSE is defined %}
Expand Down Expand Up @@ -297,7 +301,7 @@ gcode:
{action_respond_info("Hyperlapse: frames stopped")}
UPDATE_DELAYED_GCODE ID=_HYPERLAPSE_LOOP DURATION=0
{% else %}
{action_respond_info("Hyperlapse: No falid input parameter
{action_respond_info("Hyperlapse: No valid input parameter
Use:
- HYPERLAPSE ACTION=START [CYCLE=time]
- HYPERLAPSE ACTION=STOP")}
Expand Down Expand Up @@ -342,3 +346,21 @@ gcode:
RESUME_BASE
{% endif %}

[gcode_macro _done_shutdown]
gcode:
UPDATE_DELAYED_GCODE ID=_done_shutdown_timer DURATION=0
Copy link
Author

@pappicio pappicio Oct 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UPDATE_DELAYED_GCODE ID=_done_shutdown_timer DURATION=0
my own code to delete delayed gcode on printeing finish on printer.cfg

UPDATE_DELAYED_GCODE ID=_done_shutdown_timed DURATION=1

[delayed_gcode _done_shutdown_timed]
initial_duration: 0
gcode:
{% if printer.extruder.temperature > 50 %}
UPDATE_DELAYED_GCODE ID=_done_shutdown_timed DURATION=1
#m117 ciclo...
#m118 ciclo...
{% else %}
m117 spengo.....
m118 spengo.....
spegni_tutto
Copy link
Author

@pappicio pappicio Oct 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spegni_tutto
my own gcode to power off a tasmota switch to shutdown printer and raspberry

{% endif %}