diff --git a/test/client/index.html b/test/client/index.html index 9146e0c..cf66650 100644 --- a/test/client/index.html +++ b/test/client/index.html @@ -4,7 +4,7 @@ - +

Klippy Web API Test

@@ -56,6 +56,7 @@ Progress: +

diff --git a/test/client/js/main.js b/test/client/js/main.js index 0108018..cfe2583 100644 --- a/test/client/js/main.js +++ b/test/client/js/main.js @@ -247,6 +247,36 @@ function handle_klippy_state(state) { break; } } + +function process_mesh(result) { + let bed_mesh = result.status.bed_mesh; + let matrix = bed_mesh.probed_matrix; + if (!(matrix instanceof Array) || matrix.length < 3 || + !(matrix[0] instanceof Array) || matrix[0].length < 3) { + // make sure that the matrix is valid + console.log("Invalid Mesh Received"); + return; + } + let coordinates = []; + let x_distance = (bed_mesh.mesh_max[0] - bed_mesh.mesh_min[0]) / + (matrix[0].length - 1); + let y_distance = (bed_mesh.mesh_max[1] - bed_mesh.mesh_min[1]) / + (matrix.length - 1); + let x_idx = 0; + let y_idx = 0; + for (const x_axis of matrix) { + x_idx = 0; + let y_coord = bed_mesh.mesh_min[1] + (y_idx * y_distance); + for (const z_coord of x_axis) { + let x_coord = bed_mesh.mesh_min[0] + (x_idx * x_distance); + x_idx++; + coordinates.push([x_coord, y_coord, z_coord]); + } + y_idx++; + } + console.log("Processed Mesh Coordinates:"); + console.log(coordinates); +} //***********End UI Update Functions****************/ //***********Websocket-Klipper API Functions (JSON-RPC)************/ @@ -381,6 +411,17 @@ function get_object_list() { }); } +function get_mesh() { + json_rpc.call_method_with_kwargs( + api.object_status.method, {objects: {bed_mesh: null}}) + .then((result) => { + process_mesh(result); + }) + .catch((error) => { + update_error(api.object_status.method, error); + }); +} + function add_subscription(printer_objects) { json_rpc.call_method_with_kwargs( api.object_subscription.method, printer_objects) @@ -1562,6 +1603,20 @@ window.onload = () => { } }); + $('#btntestmesh').click(() => { + if (api_type == 'http') { + let settings = {url: origin + api.object_status.url + "?bed_mesh"}; + if (apikey != null) + settings.headers = {"X-Api-Key": apikey}; + $.get(settings, (resp, status) => { + process_mesh(resp.result) + return false; + }); + } else { + get_mesh(); + } + }); + $('#btnsendbatch').click(() => { let default_gcs = "M118 This works,RESPOND TYPE=invalid,M118 Execs Despite an Error"; let result = window.prompt("Enter a set of comma separated gcodes:", default_gcs);