test_client: Add button to retreive mesh

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-10-26 20:16:26 -04:00
parent 374d984ced
commit 4919548ef5
2 changed files with 57 additions and 1 deletions

View File

@ -4,7 +4,7 @@
<link rel="stylesheet" href="dist/themes/default/style.min.css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="dist/jstree.min.js"></script>
<script src="/js/main.js?v=0.1.19" type="module"></script>
<script src="/js/main.js?v=0.1.2" type="module"></script>
</head>
<body>
<h3>Klippy Web API Test</h3>
@ -56,6 +56,7 @@ Progress: <progress id="progressbar" value="0" max="100"></progress>
<button id="btngetfiles" style="width: 9em">Get File List</button>
<button id="btngethelp" style="width: 9em">Get Gcode Help</button>
<button id="btngetobjs" style="width: 9em">Get Object List</button>
<button id="btntestmesh" style="width: 9em">Get Bed Mesh</button>
<button id="btnsendbatch" class="reqws" style="width: 9em">Test GC Batch</button>
<button id="btnsendmacro" class="reqws" style="width: 9em">Test GC Macro</button>
<br/><br/>

View File

@ -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);