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 <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-03-16 14:38:35 -04:00
parent 1f474742eb
commit 5ff2d5aee6
1 changed files with 3 additions and 3 deletions

View File

@ -326,9 +326,6 @@ class MCU_adc:
self._query_cmd = None self._query_cmd = None
def build_config(self): def build_config(self):
self._mcu_freq = self._mcu.get_mcu_freq() 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( self._query_cmd = self._mcu.lookup_command(
"query_analog_in oid=%c clock=%u sample_ticks=%u sample_count=%c" "query_analog_in oid=%c clock=%u sample_ticks=%u sample_count=%c"
" rest_ticks=%u min_value=%hu max_value=%hu") " 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") mcu_adc_max = self._mcu.serial.msgparser.get_constant_float("ADC_MAX")
max_adc = self._sample_count * mcu_adc_max max_adc = self._sample_count * mcu_adc_max
self._inv_max_adc = 1.0 / max_adc 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) min_sample = int(self._min_sample * max_adc)
max_sample = min(0xffff, int(math.ceil(self._max_sample * max_adc))) max_sample = min(0xffff, int(math.ceil(self._max_sample * max_adc)))
msg = self._query_cmd.encode( msg = self._query_cmd.encode(