I’m one of those still thinking about a laser cutter while finishing other projects, but I’ve been enjoying reading your MeerK40t (love the subtle use of the hex value of @
!) source. I agree it’s pretty easy to navigate!
I’ve written rather a lot of python, so I had some fun reading it. I never read Whisperer code so not making any comparisons, but I agree that it looks modular and hackable. Thank you!
I had a thought about get_code_string_from_code()
— isn’t an unknown code potentially fatal? Is there a reason you didn’t raise an exception there?
Also, my usual pattern for that would be declarative rather than procedural. Without raising an error, something like:
def get_code_string_from_code(code):
return {
STATUS_OK: "OK",
STATUS_BUSY: "Busy",
STATUS_PACKET_REJECTED: "Rejected",
STATUS_FINISH: "Finish",
STATUS_POWER: "Low Power",
STATUS_BAD_STATE: "Bad State",
}.get(code, "Unknown: " + str(code))
Typically the map would actually be outside the function rather than in it:
status_code_map = {
STATUS_OK: "OK",
STATUS_BUSY: "Busy",
STATUS_PACKET_REJECTED: "Rejected",
STATUS_FINISH: "Finish",
STATUS_POWER: "Low Power",
STATUS_BAD_STATE: "Bad State",
}
def get_code_string_from_code(code):
return status_code_map.get(code, "Unknown: " + str(code))
Or, raising an exception:
def get_code_string_from_code(code):
try:
return status_code_map[code]
except IndexError:
raise UnknownStatusCodeError(code)
where, of course, UnknownStatusCodeError
is an error class.
I’ve found that pattern of declarative maps easy to read and modify and used it many times so I thought I’d pass it along in case you like it. No obligation to agree that it’s better implied. 