mcu: Setup for steppersync_free to be automatically called

Use ffi_main.gc() to automatically free the C steppersync object.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-09-16 23:41:27 -04:00
parent 2447025fa6
commit 9814daa999
1 changed files with 14 additions and 14 deletions

View File

@ -430,8 +430,8 @@ class MCU:
self._mcu_freq = 0.
# Move command queuing
ffi_main, self._ffi_lib = chelper.get_ffi()
self._max_stepper_error = config.getfloat(
'max_stepper_error', 0.000025, minval=0.)
self._max_stepper_error = config.getfloat('max_stepper_error', 0.000025,
minval=0.)
self._stepqueues = []
self._steppersync = None
# Stats
@ -566,17 +566,19 @@ class MCU:
else:
start_reason = self._printer.get_start_args().get("start_reason")
if start_reason == 'firmware_restart':
raise error("Failed automated reset of MCU '%s'" % (
self._name,))
raise error("Failed automated reset of MCU '%s'"
% (self._name,))
# Already configured - send init commands
self._send_config(config_params['crc'])
# Setup steppersync with the move_count returned by get_config
move_count = config_params['move_count']
self._steppersync = self._ffi_lib.steppersync_alloc(
self._serial.serialqueue, self._stepqueues, len(self._stepqueues),
move_count)
self._ffi_lib.steppersync_set_time(
self._steppersync, 0., self._mcu_freq)
ffi_main, ffi_lib = chelper.get_ffi()
self._steppersync = ffi_main.gc(
ffi_lib.steppersync_alloc(self._serial.serialqueue,
self._stepqueues, len(self._stepqueues),
move_count),
ffi_lib.steppersync_free)
ffi_lib.steppersync_set_time(self._steppersync, 0., self._mcu_freq)
# Log config information
move_msg = "Configured MCU '%s' (%d moves)" % (self._name, move_count)
logging.info(move_msg)
@ -682,9 +684,7 @@ class MCU:
# Restarts
def _disconnect(self):
self._serial.disconnect()
if self._steppersync is not None:
self._ffi_lib.steppersync_free(self._steppersync)
self._steppersync = None
self._steppersync = None
def _shutdown(self, force=False):
if (self._emergency_stop_cmd is None
or (self._is_shutdown and not force)):
@ -745,8 +745,8 @@ class MCU:
return
ret = self._ffi_lib.steppersync_flush(self._steppersync, clock)
if ret:
raise error("Internal error in MCU '%s' stepcompress" % (
self._name,))
raise error("Internal error in MCU '%s' stepcompress"
% (self._name,))
def check_active(self, print_time, eventtime):
if self._steppersync is None:
return