mirror of https://github.com/Desuuuu/klipper.git
serialhdl: Rename register_callback() to register_response()
Rename the method and use that name in the mcu class as well. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
daadb36cb4
commit
647f1ee2e0
|
@ -44,7 +44,7 @@ class ClockSync:
|
|||
params = self.get_clock_cmd.send_with_response(response='clock')
|
||||
self._handle_clock(params)
|
||||
self.reactor.pause(0.100)
|
||||
serial.register_callback(self._handle_clock, 'clock')
|
||||
serial.register_response(self._handle_clock, 'clock')
|
||||
self.reactor.update_timer(self.get_clock_timer, self.reactor.NOW)
|
||||
def connect_file(self, serial, pace=False):
|
||||
self.serial = serial
|
||||
|
|
|
@ -61,7 +61,7 @@ class KeyboardReader:
|
|||
["%s=%s" % (k, v) for k, v in msgparser.config.items()])))
|
||||
self.clocksync.connect(self.ser)
|
||||
self.ser.handle_default = self.handle_default
|
||||
self.ser.register_callback(self.handle_output, '#output')
|
||||
self.ser.register_response(self.handle_output, '#output')
|
||||
self.mcu_freq = msgparser.get_constant_float('CLOCK_FREQ')
|
||||
mcu_type = msgparser.get_constant('MCU')
|
||||
self.pins = pins.PinResolver(mcu_type, {}, validate_aliases=False)
|
||||
|
@ -130,7 +130,7 @@ class KeyboardReader:
|
|||
except ValueError as e:
|
||||
self.output("Error: %s" % (str(e),))
|
||||
return
|
||||
self.ser.register_callback(self.handle_suppress, name, oid)
|
||||
self.ser.register_response(self.handle_suppress, name, oid)
|
||||
def command_STATS(self, parts):
|
||||
curtime = self.reactor.monotonic()
|
||||
self.output(' '.join([self.ser.stats(curtime),
|
||||
|
|
|
@ -51,8 +51,8 @@ class MCU_buttons:
|
|||
"buttons_query oid=%d clock=%d"
|
||||
" rest_ticks=%d retransmit_count=%d" % (
|
||||
self.oid, clock, rest_ticks, RETRANSMIT_COUNT), is_init=True)
|
||||
self.mcu.register_msg(
|
||||
self.handle_buttons_state, "buttons_state", self.oid)
|
||||
self.mcu.register_response(self.handle_buttons_state,
|
||||
"buttons_state", self.oid)
|
||||
def handle_buttons_state(self, params):
|
||||
# Expand the message ack_count from 8-bit
|
||||
ack_count = self.ack_count
|
||||
|
|
|
@ -28,7 +28,8 @@ class SensorBase:
|
|||
self.mcu = mcu = self.spi.get_mcu()
|
||||
# Reader chip configuration
|
||||
self.oid = oid = mcu.create_oid()
|
||||
mcu.register_msg(self._handle_spi_response, "thermocouple_result", oid)
|
||||
mcu.register_response(self._handle_spi_response,
|
||||
"thermocouple_result", oid)
|
||||
mcu.register_config_callback(self._build_config)
|
||||
def setup_minmax(self, min_temp, max_temp):
|
||||
adc_range = [self.calc_adc(min_temp), self.calc_adc(max_temp)]
|
||||
|
|
|
@ -177,8 +177,8 @@ class MCU_endstop:
|
|||
" rest_ticks=%u pin_value=%c", cq=cmd_queue)
|
||||
self._query_cmd = self._mcu.lookup_command(
|
||||
"end_stop_query_state oid=%c", cq=cmd_queue)
|
||||
self._mcu.register_msg(self._handle_end_stop_state, "end_stop_state"
|
||||
, self._oid)
|
||||
self._mcu.register_response(self._handle_end_stop_state,
|
||||
"end_stop_state", self._oid)
|
||||
def home_prepare(self):
|
||||
pass
|
||||
def home_start(self, print_time, sample_time, sample_count, rest_time,
|
||||
|
@ -414,8 +414,8 @@ class MCU_adc:
|
|||
self._oid, clock, sample_ticks, self._sample_count,
|
||||
self._report_clock, min_sample, max_sample,
|
||||
self._range_check_count), is_init=True)
|
||||
self._mcu.register_msg(self._handle_analog_in_state, "analog_in_state"
|
||||
, self._oid)
|
||||
self._mcu.register_response(self._handle_analog_in_state,
|
||||
"analog_in_state", self._oid)
|
||||
def _handle_analog_in_state(self, params):
|
||||
last_value = params['value'] * self._inv_max_adc
|
||||
next_clock = self._mcu.clock32_to_clock64(params['next_clock'])
|
||||
|
@ -640,9 +640,9 @@ class MCU:
|
|||
or self._config_reset_cmd is not None)
|
||||
and msgparser.get_constant('SERIAL_BAUD', None) is None):
|
||||
self._restart_method = 'command'
|
||||
self.register_msg(self._handle_shutdown, 'shutdown')
|
||||
self.register_msg(self._handle_shutdown, 'is_shutdown')
|
||||
self.register_msg(self._handle_mcu_stats, 'stats')
|
||||
self.register_response(self._handle_shutdown, 'shutdown')
|
||||
self.register_response(self._handle_shutdown, 'is_shutdown')
|
||||
self.register_response(self._handle_mcu_stats, 'stats')
|
||||
self._check_config()
|
||||
move_msg = "Configured MCU '%s' (%d moves)" % (name, self._move_count)
|
||||
logging.info(move_msg)
|
||||
|
@ -680,8 +680,8 @@ class MCU:
|
|||
return self._printer
|
||||
def get_name(self):
|
||||
return self._name
|
||||
def register_msg(self, cb, msg, oid=None):
|
||||
self._serial.register_callback(cb, msg, oid)
|
||||
def register_response(self, cb, msg, oid=None):
|
||||
self._serial.register_response(cb, msg, oid)
|
||||
def alloc_command_queue(self):
|
||||
return self._serial.alloc_command_queue()
|
||||
def lookup_command(self, msgformat, cq=None):
|
||||
|
|
|
@ -82,7 +82,7 @@ class SerialReader:
|
|||
msgparser = msgproto.MessageParser()
|
||||
msgparser.process_identify(identify_data)
|
||||
self.msgparser = msgparser
|
||||
self.register_callback(self.handle_unknown, '#unknown')
|
||||
self.register_response(self.handle_unknown, '#unknown')
|
||||
# Setup baud adjust
|
||||
mcu_baud = msgparser.get_constant_float('SERIAL_BAUD', None)
|
||||
if mcu_baud is not None:
|
||||
|
@ -117,10 +117,10 @@ class SerialReader:
|
|||
self.serialqueue, self.stats_buf, len(self.stats_buf))
|
||||
return self.ffi_main.string(self.stats_buf)
|
||||
# Serial response callbacks
|
||||
def register_callback(self, callback, name, oid=None):
|
||||
def register_response(self, callback, name, oid=None):
|
||||
with self.lock:
|
||||
self.handlers[name, oid] = callback
|
||||
def unregister_callback(self, name, oid=None):
|
||||
def unregister_response(self, name, oid=None):
|
||||
with self.lock:
|
||||
del self.handlers[name, oid]
|
||||
# Command sending
|
||||
|
@ -200,11 +200,11 @@ class SerialRetryCommand:
|
|||
reactor = self.serial.reactor
|
||||
self.mutex = reactor.mutex(is_locked=True)
|
||||
self.min_query_time = self.serial.reactor.monotonic()
|
||||
self.serial.register_callback(self.handle_callback, self.name, self.oid)
|
||||
self.serial.register_response(self.handle_callback, self.name, self.oid)
|
||||
retry_time = self.send_event(self.min_query_time)
|
||||
self.send_timer = reactor.register_timer(self.send_event, retry_time)
|
||||
def unregister(self):
|
||||
self.serial.unregister_callback(self.name, self.oid)
|
||||
self.serial.unregister_response(self.name, self.oid)
|
||||
self.serial.reactor.unregister_timer(self.send_timer)
|
||||
def send_event(self, eventtime):
|
||||
if self.response is not None:
|
||||
|
@ -240,15 +240,15 @@ class SerialBootStrap:
|
|||
self.identify_cmd = self.serial.lookup_command(
|
||||
"identify offset=%u count=%c")
|
||||
self.is_done = False
|
||||
self.serial.register_callback(self.handle_identify, 'identify_response')
|
||||
self.serial.register_callback(self.handle_unknown, '#unknown')
|
||||
self.serial.register_response(self.handle_identify, 'identify_response')
|
||||
self.serial.register_response(self.handle_unknown, '#unknown')
|
||||
self.send_timer = self.serial.reactor.register_timer(
|
||||
self.send_event, self.serial.reactor.NOW)
|
||||
def get_identify_data(self, timeout):
|
||||
eventtime = self.serial.reactor.monotonic()
|
||||
while not self.is_done and eventtime <= timeout:
|
||||
eventtime = self.serial.reactor.pause(eventtime + 0.05)
|
||||
self.serial.unregister_callback('identify_response')
|
||||
self.serial.unregister_response('identify_response')
|
||||
self.serial.reactor.unregister_timer(self.send_timer)
|
||||
if not self.is_done:
|
||||
return None
|
||||
|
|
Loading…
Reference in New Issue