mcu: Add support for commands to send only on a host restart

Add a new "on_restart" parameter to mcu.add_config_cmd() and only send
those commands on a host restart that does not involve a
micro-controller restart.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-07-19 12:26:31 -04:00
parent 4a35d7e8bd
commit d204cc1fb7
2 changed files with 14 additions and 9 deletions

View File

@ -40,7 +40,7 @@ class MCU_endstop:
self._oid, self._pin, self._pullup, len(self._steppers))) self._oid, self._pin, self._pullup, len(self._steppers)))
self._mcu.add_config_cmd( self._mcu.add_config_cmd(
"endstop_home oid=%d clock=0 sample_ticks=0 sample_count=0" "endstop_home oid=%d clock=0 sample_ticks=0 sample_count=0"
" rest_ticks=0 pin_value=0" % (self._oid,), is_init=True) " rest_ticks=0 pin_value=0" % (self._oid,), on_restart=True)
for i, s in enumerate(self._steppers): for i, s in enumerate(self._steppers):
self._mcu.add_config_cmd( self._mcu.add_config_cmd(
"endstop_set_stepper oid=%d pos=%d stepper_oid=%d" % ( "endstop_set_stepper oid=%d pos=%d stepper_oid=%d" % (
@ -412,8 +412,9 @@ class MCU:
self._printer.lookup_object('pins').register_chip(self._name, self) self._printer.lookup_object('pins').register_chip(self._name, self)
self._oid_count = 0 self._oid_count = 0
self._config_callbacks = [] self._config_callbacks = []
self._init_cmds = []
self._config_cmds = [] self._config_cmds = []
self._restart_cmds = []
self._init_cmds = []
self._pin_map = config.get('pin_map', None) self._pin_map = config.get('pin_map', None)
self._mcu_freq = 0. self._mcu_freq = 0.
# Move command queuing # Move command queuing
@ -495,10 +496,9 @@ class MCU:
pin_resolver = ppins.get_pin_resolver(self._name) pin_resolver = ppins.get_pin_resolver(self._name)
if self._pin_map is not None: if self._pin_map is not None:
pin_resolver.add_pin_mapping(mcu_type, self._pin_map) pin_resolver.add_pin_mapping(mcu_type, self._pin_map)
for i, cmd in enumerate(self._config_cmds): for cmdlist in (self._config_cmds, self._restart_cmds, self._init_cmds):
self._config_cmds[i] = pin_resolver.update_command(cmd) for i, cmd in enumerate(cmdlist):
for i, cmd in enumerate(self._init_cmds): cmdlist[i] = pin_resolver.update_command(cmd)
self._init_cmds[i] = pin_resolver.update_command(cmd)
# Calculate config CRC # Calculate config CRC
config_crc = zlib.crc32('\n'.join(self._config_cmds)) & 0xffffffff config_crc = zlib.crc32('\n'.join(self._config_cmds)) & 0xffffffff
self.add_config_cmd("finalize_config crc=%d" % (config_crc,)) self.add_config_cmd("finalize_config crc=%d" % (config_crc,))
@ -512,6 +512,9 @@ class MCU:
self._name) self._name)
for c in self._config_cmds: for c in self._config_cmds:
self._serial.send(c) self._serial.send(c)
else:
for c in self._restart_cmds:
self._serial.send(c)
# Transmit init messages # Transmit init messages
for c in self._init_cmds: for c in self._init_cmds:
self._serial.send(c) self._serial.send(c)
@ -612,9 +615,11 @@ class MCU:
return self._oid_count - 1 return self._oid_count - 1
def register_config_callback(self, cb): def register_config_callback(self, cb):
self._config_callbacks.append(cb) self._config_callbacks.append(cb)
def add_config_cmd(self, cmd, is_init=False): def add_config_cmd(self, cmd, is_init=False, on_restart=False):
if is_init: if is_init:
self._init_cmds.append(cmd) self._init_cmds.append(cmd)
elif on_restart:
self._restart_cmds.append(cmd)
else: else:
self._config_cmds.append(cmd) self._config_cmds.append(cmd)
def get_query_slot(self, oid): def get_query_slot(self, oid):

View File

@ -76,8 +76,8 @@ class MCU_stepper:
self._oid, self._step_pin, self._dir_pin, self._oid, self._step_pin, self._dir_pin,
self._mcu.seconds_to_clock(min_stop_interval), self._mcu.seconds_to_clock(min_stop_interval),
self._invert_step)) self._invert_step))
self._mcu.add_config_cmd( self._mcu.add_config_cmd("reset_step_clock oid=%d clock=0"
"reset_step_clock oid=%d clock=0" % (self._oid,), is_init=True) % (self._oid,), on_restart=True)
step_cmd_id = self._mcu.lookup_command_id( step_cmd_id = self._mcu.lookup_command_id(
"queue_step oid=%c interval=%u count=%hu add=%hi") "queue_step oid=%c interval=%u count=%hu add=%hi")
dir_cmd_id = self._mcu.lookup_command_id( dir_cmd_id = self._mcu.lookup_command_id(