Skip to content

Commit

Permalink
add guppy config helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ballaswag committed Jan 17, 2024
1 parent 6d71018 commit a20edd7
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions k1/k1_mods/guppy_config_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class GuppyConfigHelper:
def __init__(self, config):
self.printer = config.get_printer()

# Register commands
gcode = config.get_printer().lookup_object('gcode')
gcode.register_command("GUPPY_SAVE_CONFIG", self.cmd_guppy_save_config)
gcode.register_command("GUPPY_DELETE_CONFIG", self.cmd_guppy_delete_config)

def cmd_guppy_save_config(self, gcmd):
self.section = gcmd.get('SECTION', None)
self.pairs = gcmd.get('KEY_VALUE', None)

if self.section and self.pairs:
configfile = self.printer.lookup_object('configfile')
kv = self.pairs.split(',')
d = dict(s.split(':') for s in kv)

configfile.remove_section(self.section)

for k, v in d.items():
configfile.set(self.section, k, v)

def cmd_guppy_delete_config(self, gcmd):
self.section = gcmd.get('SECTION', None)

if self.section:
configfile = self.printer.lookup_object('configfile')
configfile.remove_section(self.section)

def load_config(config):
return GuppyConfigHelper(config)

0 comments on commit a20edd7

Please sign in to comment.