added save in mach
This commit is contained in:
@@ -79,7 +79,7 @@ class Config(object):
|
|||||||
def get(self, name, default = None):
|
def get(self, name, default = None):
|
||||||
return self.values.get(name, default)
|
return self.values.get(name, default)
|
||||||
|
|
||||||
# def set_values(self, name, default = None):
|
# def set(self, name, default = None):
|
||||||
# self.log.info(f'name:{name} default:{default}')
|
# self.log.info(f'name:{name} default:{default}')
|
||||||
# self.log.info(f'config: {repr(self)}')
|
# self.log.info(f'config: {repr(self)}')
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,8 @@
|
|||||||
import bbctrl
|
import bbctrl
|
||||||
from bbctrl.Comm import Comm
|
from bbctrl.Comm import Comm
|
||||||
import bbctrl.Cmd as Cmd
|
import bbctrl.Cmd as Cmd
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
# Axis homing procedure:
|
# Axis homing procedure:
|
||||||
#
|
#
|
||||||
@@ -354,11 +355,26 @@ class Mach(Comm):
|
|||||||
def optional_pause(self, enable = True):
|
def optional_pause(self, enable = True):
|
||||||
self.ctrl.state.set('optional_pause', enable)
|
self.ctrl.state.set('optional_pause', enable)
|
||||||
|
|
||||||
|
def save_config(self, axis, target):
|
||||||
|
config = self.ctrl.config
|
||||||
|
path = self.ctrl.get_path('config.json')
|
||||||
|
|
||||||
|
try:
|
||||||
|
if os.path.exists(path):
|
||||||
|
with open(path, 'r') as f: config_data = json.load(f)
|
||||||
|
else: config_data = {'version': self.version}
|
||||||
|
|
||||||
|
axes = config_data.setdefault('axes',{})
|
||||||
|
axes[axis]['abs'] = target
|
||||||
|
config.save(config_data)
|
||||||
|
self.mlog.info(f'done with config: {config_data}')
|
||||||
|
except Exception: self.log.exception('Internal error: Failed to upgrade config')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def set_position(self, axis, position):
|
def set_position(self, axis, position):
|
||||||
axis = axis.lower()
|
axis = axis.lower()
|
||||||
state = self.ctrl.state
|
state = self.ctrl.state
|
||||||
config = self.ctrl.config
|
|
||||||
|
|
||||||
if state.is_axis_homed(axis):
|
if state.is_axis_homed(axis):
|
||||||
# If homed, change the offset rather than the absolute position
|
# If homed, change the offset rather than the absolute position
|
||||||
@@ -374,9 +390,7 @@ class Mach(Comm):
|
|||||||
self.mlog.info('target ' + str(target))
|
self.mlog.info('target ' + str(target))
|
||||||
self.mlog.info('state.get ' + str(state.get('offset_' + axis)))
|
self.mlog.info('state.get ' + str(state.get('offset_' + axis)))
|
||||||
state.set(axis + 'p', target)
|
state.set(axis + 'p', target)
|
||||||
axes = config.values.setdefault('axes',{})
|
self.save_config(axis, target)
|
||||||
axes[axis]['abs'] = target
|
|
||||||
# config.set_values('axes',axes)
|
|
||||||
super().queue_command(Cmd.set_axis(axis, target))
|
super().queue_command(Cmd.set_axis(axis, target))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user