mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-16 03:07:56 -06:00
mcu: Raise config_error (not protocol error) on pin enumeration errors
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
31fcd491fd
commit
ecbfa76242
2 changed files with 36 additions and 19 deletions
|
@ -86,12 +86,14 @@ class PT_progmem_buffer(PT_string):
|
|||
class PT_buffer(PT_string):
|
||||
pass
|
||||
|
||||
MessageTypes = {
|
||||
'%u': PT_uint32(), '%i': PT_int32(),
|
||||
'%hu': PT_uint16(), '%hi': PT_int16(),
|
||||
'%c': PT_byte(),
|
||||
'%s': PT_string(), '%.*s': PT_progmem_buffer(), '%*s': PT_buffer(),
|
||||
}
|
||||
class enumeration_error(error):
|
||||
def __init__(self, enum_name, value):
|
||||
self.enum_name = enum_name
|
||||
self.value = value
|
||||
error.__init__(self, "Unknown value '%s' in enumeration '%s'"
|
||||
% (value, enum_name))
|
||||
def get_enum_params(self):
|
||||
return self.enum_name, self.value
|
||||
|
||||
class Enumeration:
|
||||
is_int = False
|
||||
|
@ -105,8 +107,7 @@ class Enumeration:
|
|||
def encode(self, out, v):
|
||||
tv = self.enums.get(v)
|
||||
if tv is None:
|
||||
raise error("Unknown value '%s' in enumeration '%s'"
|
||||
% (v, self.enum_name))
|
||||
raise enumeration_error(self.enum_name, v)
|
||||
self.pt.encode(out, tv)
|
||||
def parse(self, s, pos):
|
||||
v, pos = self.pt.parse(s, pos)
|
||||
|
@ -115,6 +116,13 @@ class Enumeration:
|
|||
tv = "?%d" % (v,)
|
||||
return tv, pos
|
||||
|
||||
MessageTypes = {
|
||||
'%u': PT_uint32(), '%i': PT_int32(),
|
||||
'%hu': PT_uint16(), '%hi': PT_int16(),
|
||||
'%c': PT_byte(),
|
||||
'%s': PT_string(), '%.*s': PT_progmem_buffer(), '%*s': PT_buffer(),
|
||||
}
|
||||
|
||||
# Lookup the message types for a format string
|
||||
def lookup_params(msgformat, enumerations={}):
|
||||
out = []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue