Skip to content

Commit

Permalink
Confirmed working with Octoprint, test code commented out
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Sep 24, 2018
1 parent 834e90f commit 3b13826
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions octoprint_PrusaMeshMap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import json



class PrusameshmapPlugin(octoprint.plugin.SettingsPlugin,
octoprint.plugin.AssetPlugin,
octoprint.plugin.TemplatePlugin,
Expand Down Expand Up @@ -84,16 +85,17 @@ def get_update_information(self):
)

##~~ GCode Received hook


def mesh_level_check(self, comm, line, *args, **kwargs):
if re.match(r"^( -?\d+.\d+)+$", line):
self.mesh_level_responses.append(line)
self._logger.info("FOUND: " + line)
self.mesh_level_generate() #meme
return line
elif line.startswith("mesh_map_output"):
elif line.startswith(""mesh_map_output"):
klipper_json_line = line
self._logger.info("Klipper meme aquired. Ready the matplotlibs: " + line)
self._logger.info("Klipper line found. Ready the matplotlibs: " + line)
self.generate_graph_klipper_mode(klipper_json_line)
return line
else:
Expand All @@ -102,7 +104,11 @@ def mesh_level_check(self, comm, line, *args, **kwargs):
# Klipper mode heatmap generation. Above brig's stuff because it's better :D

def generate_graph_klipper_mode(self,klipper_json_line):
#Remove the first 16 charicters of the line and import to a dictionary

self._logger.info("Processing in Klipper mode...")
#Remove the first 16 charicters of the line and import to a dictionary
#use this line for testing
#klipper_json_line = 'mesh_map_output {"max_point": [212.0, 204.0], "z_positions": [[-0.12499999999999833, -0.10999999999999777, -0.09750000000000203, -0.1399999999999989, -0.2200000000000043], [0.014999999999995128, 0.02749999999999797, 0.012499999999997402, -0.016249999999997766, -0.0500000000000026], [0.02749999999999797, 0.03250000000000053, 0.02875000000000394, 0.046250000000002234, 0.034999999999998255], [0.04000000000000081, 0.07750000000000223, 0.07999999999999996, 0.0787500000000011, 0.08124999999999882], [-0.01000000000000345, 0.05249999999999655, 0.11750000000000138, 0.11750000000000138, 0.10250000000000081]], "xy_offset": [24.0, 5.0], "min_point": [2.0, 0.0]}'
klipper_json_line = klipper_json_line[16:]
jsonDict = json.loads(klipper_json_line)
xyOffset = jsonDict["xy_offset"]
Expand Down Expand Up @@ -142,7 +148,10 @@ def generate_graph_klipper_mode(self,klipper_json_line):
x, y = np.meshgrid(x,y)

#Plot all of the things, including the mk52 back
img = mpimg.imread(r'C:\Users\matth\Documents\GitHub\OctoPrint-PrusaMeshMap\octoprint_PrusaMeshMap\static\img\mk52_steel_sheet.png')


img = mpimg.imread(self.get_asset_folder() + '/img/mk52_steel_sheet.png')
#img = mpimg.imread(r'C:\Users\matth\Documents\GitHub\OctoPrint-PrusaMeshMap\octoprint_PrusaMeshMap\static\img\mk52_steel_sheet.png')
plt.imshow(img, extent=[sheet_left_x, sheet_right_x, sheet_front_y, sheet_back_y], interpolation="lanczos", cmap=plt.cm.get_cmap('viridis'))

#plot the interpolated mesh, bar, and probed points
Expand All @@ -156,7 +165,9 @@ def generate_graph_klipper_mode(self,klipper_json_line):
plt.ylabel("Y Axis (mm)")

# Save our graph as an image in the current directory.
fig.savefig(self.get_asset_folder() + '/img/heatmap.png', bbox_inches="tight")
plt.savefig(self.get_asset_folder() + '/img/heatmap.png', bbox_inches="tight")
#plt.savefig('/home/pi/heatmap.png', bbox_inches="tight")

self._logger.info("Heatmap updated")


Expand Down

0 comments on commit 3b13826

Please sign in to comment.