Skip to content

Commit

Permalink
bed_mesh: Report actual mesh profiles as status
Browse files Browse the repository at this point in the history
Report the actual profiles available via BED_MESH_PROFILE
via the status for use by clients.

Signed-off-by: Kurt Haenen <kurt.haenen@gmail.com>
  • Loading branch information
Misterke authored and KevinOConnor committed Feb 16, 2022
1 parent 131cca2 commit 8b0c6fc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/Status_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The following information is available in the
[bed_mesh](Config_Reference.md#bed_mesh) object:
- `profile_name`, `mesh_min`, `mesh_max`, `probed_matrix`,
`mesh_matrix`: Information on the currently active bed_mesh.
- `profiles`: The set of currently defined profiles as setup
using BED_MESH_PROFILE.

## configfile

Expand Down
14 changes: 11 additions & 3 deletions klippy/extras/bed_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ def get_status(self, eventtime=None):
"mesh_min": (0., 0.),
"mesh_max": (0., 0.),
"probed_matrix": [[]],
"mesh_matrix": [[]]
"mesh_matrix": [[]],
"profiles": self.pmgr.get_profiles()
}
if self.z_mesh is not None:
params = self.z_mesh.get_mesh_params()
Expand Down Expand Up @@ -1134,6 +1135,8 @@ def initialize(self):
self._check_incompatible_profiles()
if "default" in self.profiles:
self.load_profile("default")
def get_profiles(self):
return self.profiles
def get_current_profile(self):
return self.current_profile
def _check_incompatible_profiles(self):
Expand Down Expand Up @@ -1170,9 +1173,12 @@ def save_profile(self, prof_name):
for key, value in mesh_params.items():
configfile.set(cfg_name, key, value)
# save copy in local storage
self.profiles[prof_name] = profile = {}
# ensure any self.profiles returned as status remains immutable
profiles = dict(self.profiles)
profiles[prof_name] = profile = {}
profile['points'] = probed_matrix
profile['mesh_params'] = collections.OrderedDict(mesh_params)
self.profiles = profiles
self.current_profile = prof_name
self.gcode.respond_info(
"Bed Mesh state has been saved to profile [%s]\n"
Expand All @@ -1197,7 +1203,9 @@ def remove_profile(self, prof_name):
if prof_name in self.profiles:
configfile = self.printer.lookup_object('configfile')
configfile.remove_section('bed_mesh ' + prof_name)
del self.profiles[prof_name]
profiles = dict(self.profiles)
del profiles[prof_name]
self.profiles = profiles
self.gcode.respond_info(
"Profile [%s] removed from storage for this session.\n"
"The SAVE_CONFIG command will update the printer\n"
Expand Down

0 comments on commit 8b0c6fc

Please sign in to comment.