From 5ff2d5aee61f26ef4c6a3e36a0da6ede22fb6997 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 16 Mar 2017 14:38:35 -0400 Subject: [PATCH] mcu: Defer MCU_adc register_msg until ready to receive messages Register the callback handler only after it's required state is setup. Signed-off-by: Kevin O'Connor --- klippy/mcu.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/klippy/mcu.py b/klippy/mcu.py index b255a1f3..4d444f4c 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -326,9 +326,6 @@ class MCU_adc: self._query_cmd = None def build_config(self): self._mcu_freq = self._mcu.get_mcu_freq() - self._report_clock = int(self._report_time * self._mcu_freq) - self._mcu.register_msg(self._handle_analog_in_state, "analog_in_state" - , self._oid) self._query_cmd = self._mcu.lookup_command( "query_analog_in oid=%c clock=%u sample_ticks=%u sample_count=%c" " rest_ticks=%u min_value=%hu max_value=%hu") @@ -346,6 +343,9 @@ class MCU_adc: mcu_adc_max = self._mcu.serial.msgparser.get_constant_float("ADC_MAX") max_adc = self._sample_count * mcu_adc_max self._inv_max_adc = 1.0 / max_adc + self._report_clock = int(self._report_time * self._mcu_freq) + self._mcu.register_msg(self._handle_analog_in_state, "analog_in_state" + , self._oid) min_sample = int(self._min_sample * max_adc) max_sample = min(0xffff, int(math.ceil(self._max_sample * max_adc))) msg = self._query_cmd.encode(