mirror of
				https://github.com/Klipper3d/klipper.git
				synced 2025-10-31 10:25:57 +01:00 
			
		
		
		
	msgproto: Support default values in get_constant() calls
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
		| @@ -324,12 +324,16 @@ class MessageParser: | |||||||
|         except Exception as e: |         except Exception as e: | ||||||
|             logging.exception("process_identify error") |             logging.exception("process_identify error") | ||||||
|             raise error("Error during identify: %s" % (str(e),)) |             raise error("Error during identify: %s" % (str(e),)) | ||||||
|     def get_constant(self, name): |     class sentinel: pass | ||||||
|         try: |     def get_constant(self, name, default=sentinel): | ||||||
|             return self.config[name] |         if name not in self.config: | ||||||
|         except KeyError: |             if default is not self.sentinel: | ||||||
|  |                 return default | ||||||
|             raise error("Firmware constant '%s' not found" % (name,)) |             raise error("Firmware constant '%s' not found" % (name,)) | ||||||
|     def get_constant_float(self, name): |         return self.config[name] | ||||||
|  |     def get_constant_float(self, name, default=sentinel): | ||||||
|  |         if name not in self.config and default is not self.sentinel: | ||||||
|  |             return default | ||||||
|         try: |         try: | ||||||
|             return float(self.config[name]) |             return float(self.config[name]) | ||||||
|         except ValueError: |         except ValueError: | ||||||
|   | |||||||
| @@ -90,8 +90,8 @@ class SerialReader: | |||||||
|         logging.info("MCU config: %s", " ".join( |         logging.info("MCU config: %s", " ".join( | ||||||
|             ["%s=%s" % (k, v) for k, v in msgparser.config.items()])) |             ["%s=%s" % (k, v) for k, v in msgparser.config.items()])) | ||||||
|         # Setup baud adjust |         # Setup baud adjust | ||||||
|         mcu_baud = float(msgparser.config.get('SERIAL_BAUD', 0.)) |         mcu_baud = msgparser.get_constant_float('SERIAL_BAUD', None) | ||||||
|         if mcu_baud: |         if mcu_baud is not None: | ||||||
|             baud_adjust = self.BITS_PER_BYTE / mcu_baud |             baud_adjust = self.BITS_PER_BYTE / mcu_baud | ||||||
|             self.ffi_lib.serialqueue_set_baud_adjust( |             self.ffi_lib.serialqueue_set_baud_adjust( | ||||||
|                 self.serialqueue, baud_adjust) |                 self.serialqueue, baud_adjust) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user