Skip to content

Commit d4fcb39

Browse files
authored
Merge pull request #193 from cotepat/surfacewiz
Surface wizard
2 parents 29c1ebb + ca431b2 commit d4fcb39

File tree

7 files changed

+578
-27
lines changed

7 files changed

+578
-27
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
node_modules
22
dist
33
src
4+
.DS_Store
5+
docs/.DS_Store
6+
www/.DS_Store

www/js/files.js

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,24 @@ function process_files_Createdir(answer) {
182182
}
183183

184184
function files_create_dir(name) {
185+
files_create_dir(name, files_currentPath)
186+
}
187+
188+
function files_create_dir2(name, path) {
185189
if (direct_sd && !((target_firmware == "smoothieware") && files_currentPath.startsWith(secondary_sd))) {
186-
var cmdpath = files_currentPath;
187-
if (target_firmware == "smoothieware") cmdpath = files_currentPath.substring(primary_sd.length);
190+
var cmdpath = path;
191+
if (target_firmware == "smoothieware") cmdpath = path.substring(primary_sd.length);
188192
var url = "/upload?path=" + encodeURIComponent(cmdpath) + "&action=createdir&filename=" + encodeURIComponent(name);
189193
document.getElementById('files_nav_loader').style.display = "block";
190194
SendGetHttp(url, files_directSD_list_success, files_directSD_list_failed);
191195
} else {
192196
var command = "";
193197
if (target_firmware == "smoothieware") {
194-
command = "mkdir " + files_currentPath + name;
198+
command = "mkdir " + path + name;
195199
} else {
196-
command = "M32 " + files_currentPath + name;
200+
command = "M32 " + path + name;
197201
}
198-
SendPrinterCommand(command, true, files_proccess_and_update);
202+
SendPrinterCommand(command, true, files_process_and_update);
199203
}
200204
}
201205

@@ -234,11 +238,11 @@ function files_delete_file(index) {
234238
if ((current_source == tft_usb)|| (current_source == tft_sd))command +=current_source;
235239
command += files_currentPath + files_file_list[index].name;
236240
}
237-
SendPrinterCommand(command, true, files_proccess_and_update);
241+
SendPrinterCommand(command, true, files_process_and_update);
238242
}
239243
}
240244

241-
function files_proccess_and_update(answer) {
245+
function files_process_and_update(answer) {
242246
document.getElementById('files_navigation_buttons').style.display = "block";
243247
if (answer.startsWith("{") && answer.endsWith("}")) {
244248
try {
@@ -807,25 +811,28 @@ function process_check_sd_presence(answer) {
807811
}
808812

809813
function files_start_upload() {
814+
var files = document.getElementById("files_input_file").files;
815+
files_start_upload(files, files_currentPath)
816+
}
817+
818+
function files_start_upload2(files, path) {
810819
if (http_communication_locked) {
811820
alertdlg(translate_text_item("Busy..."), translate_text_item("Communications are currently locked, please wait and retry."));
812821
console.log("communication locked");
813822
return;
814823
}
815824
var url = "/upload";
816-
var path = files_currentPath;
817-
if (direct_sd && (target_firmware == "smoothieware") && (files_currentPath.startsWith(primary_sd))) {
818-
path = files_currentPath.substring(primary_sd.length);
825+
if (direct_sd && (target_firmware == "smoothieware") && (path.startsWith(primary_sd))) {
826+
path = path.substring(primary_sd.length);
819827
}
820-
if (!direct_sd || (target_firmware == "smoothieware" && files_currentPath.startsWith(secondary_sd))) {
828+
if (!direct_sd || (target_firmware == "smoothieware" && path.startsWith(secondary_sd))) {
821829
url = "/upload_serial";
822830
if (target_firmware == "smoothieware") {
823-
if (files_currentPath.startsWith(secondary_sd)) path = files_currentPath.substring(secondary_sd.length);
824-
else path = files_currentPath.substring(primary_sd.length);
831+
if (path.startsWith(secondary_sd)) path = path.substring(secondary_sd.length);
832+
else path = path.substring(primary_sd.length);
825833
}
826834
}
827-
//console.log("upload from " + path );
828-
var files = document.getElementById("files_input_file").files;
835+
console.log("upload from " + path );
829836

830837
if (files.value == "" || typeof files[0].name === 'undefined') {
831838
console.log("nothing to upload");
@@ -840,22 +847,21 @@ function files_start_upload() {
840847
//append file size first to check updload is complete
841848
formData.append(arg, file.size);
842849
formData.append('myfile[]', file, path + file.name);
843-
//console.log( path +file.name);
850+
console.log(path +file.name);
844851
}
845852
files_error_status = "Upload " + file.name;
846853
document.getElementById('files_currentUpload_msg').innerHTML = file.name;
847854
document.getElementById('files_uploading_msg').style.display = "block";
848855
document.getElementById('files_navigation_buttons').style.display = "none";
849-
if (direct_sd && !(target_firmware == "smoothieware" && files_currentPath.startsWith(secondary_sd))) {
856+
if (direct_sd && !(target_firmware == "smoothieware" && path.startsWith(secondary_sd))) {
850857
SendFileHttp(url, formData, FilesUploadProgressDisplay, files_directSD_list_success, files_directSD_list_failed);
851-
//console.log("send file");
852858
} else {
853-
SendFileHttp(url, formData, FilesUploadProgressDisplay, files_proccess_and_update, files_serial_M20_list_failed);
859+
SendFileHttp(url, formData, FilesUploadProgressDisplay, files_process_and_update, files_serial_M20_list_failed);
854860
}
855861
document.getElementById("files_input_file").value = "";
862+
files_refreshFiles(path)
856863
}
857864

858-
859865
function FilesUploadProgressDisplay(oEvent) {
860866
if (oEvent.lengthComputable) {
861867
var percentComplete = (oEvent.loaded / oEvent.total) * 100;

www/js/grbl.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var interval_status = -1;
22
var probe_progress_status = 0;
3+
var surface_progress_status = 0;
34
var grbl_error_msg = "";
45
var gotWCO = false;
56
var WCOx = 0;
@@ -124,6 +125,24 @@ function onprobetouchplatethicknessChange() {
124125
return true;
125126
}
126127

128+
function onsurfacewidthChange() {
129+
var travel = parseFloat(document.getElementById('surfacewidth').value);
130+
if (travel > 9999 || travel <= 0 || isNaN(travel) || (travel === null)) {
131+
alertdlg(translate_text_item("Out of range"), translate_text_item("Value of surface width must be between 1 mm and 9999 mm !"));
132+
return false;
133+
}
134+
return true;
135+
}
136+
137+
function onsurfacelengthChange() {
138+
var travel = parseFloat(document.getElementById('surfacelength').value);
139+
if (travel > 9999 || travel <= 0 || isNaN(travel) || (travel === null)) {
140+
alertdlg(translate_text_item("Out of range"), translate_text_item("Value of surface length must be between 1 mm and 9999 mm !"));
141+
return false;
142+
}
143+
return true;
144+
}
145+
127146
function on_autocheck_status(use_value) {
128147
if (probe_progress_status != 0) {
129148
document.getElementById('autocheck_status').checked = true;
@@ -289,6 +308,9 @@ function process_grbl_status(response) {
289308
if (probe_progress_status != 0) {
290309
probe_failed_notification();
291310
}
311+
if (surface_progress_status != 0) {
312+
surface_failed_notification();
313+
}
292314
//grbl_error_msg = "";
293315
//check we are printing or not
294316
if (response.indexOf("|SD:") != -1) {
@@ -303,6 +325,10 @@ function process_grbl_status(response) {
303325
document.getElementById('sd_reset_btn').style.display = "none";
304326
}
305327
if (tab2.toLowerCase().startsWith("idle")) {
328+
329+
if(surface_progress_status == 100) {
330+
finalize_surfacing();
331+
}
306332
grbl_error_msg = "";
307333
}
308334
document.getElementById('grbl_status_text').innerHTML = translate_text_item(grbl_error_msg);
@@ -317,6 +343,16 @@ function finalize_probing() {
317343
document.getElementById("probingtext").style.display = "none";
318344
document.getElementById('sd_pause_btn').style.display = "none";
319345
document.getElementById('sd_resume_btn').style.display = "none";
346+
document.getElementById('sd_reset_btn').style.display = "none";
347+
}
348+
349+
function finalize_surfacing() {
350+
surface_progress_status = 0;
351+
grbl_error_msg = "";
352+
document.getElementById("surfacebtn").style.display = "table-row";
353+
document.getElementById("surfacingtext").style.display = "none";
354+
document.getElementById('sd_pause_btn').style.display = "none";
355+
document.getElementById('sd_resume_btn').style.display = "none";
320356
document.getElementById('sd_reset_btn').style.display = "none";
321357
}
322358

@@ -334,6 +370,9 @@ function process_grbl_SD(response) {
334370
progress = progress.replace(">", "");
335371
}
336372
document.getElementById('grbl_SD_status').innerHTML = sdname + "&nbsp;<progress id='print_prg' value=" + progress + " max='100'></progress>" + progress + "%";
373+
if(progress == 100 & surface_progress_status != 0) {
374+
surface_progress_status = progress;
375+
}
337376
} else { //no SD printing
338377
//TODO
339378
document.getElementById('grbl_SD_status').innerHTML = "";
@@ -375,6 +414,7 @@ function grbl_process_msg(response) {
375414

376415
function grbl_reset() {
377416
if (probe_progress_status != 0) probe_failed_notification();
417+
if (surface_progress_status != 0) surface_failed_notification();
378418
SendRealtimeCmd(String.fromCharCode(0x18));
379419
}
380420

@@ -410,8 +450,15 @@ function probe_failed_notification() {
410450
beep(70, 261);
411451
}
412452

453+
function surface_failed_notification() {
454+
finalize_surfacing();
455+
alertdlg(translate_text_item("Error"), translate_text_item("Surfacing failed !"));
456+
beep(70, 261);
457+
}
458+
413459
function StartProbeProcess() {
414460
var cmd = "G38.2 G91 Z-";
461+
415462
if (!onprobemaxtravelChange() ||
416463
!onprobefeedrateChange() ||
417464
!onprobetouchplatethicknessChange()) {
@@ -427,3 +474,78 @@ function StartProbeProcess() {
427474
grbl_error_msg = "";
428475
document.getElementById('grbl_status_text').innerHTML = grbl_error_msg;
429476
}
477+
478+
function StartSurfaceProcess() {
479+
var path = "/";
480+
var dirname = "SurfaceWizard";
481+
482+
var bitdiam = document.getElementById('surfacebitdiam').value;;
483+
var stepover = document.getElementById('surfacestepover').value;;
484+
var feedrate = document.getElementById('surfacefeedrate').value;;
485+
var surfacewidth = document.getElementById('surfacewidth').value;
486+
var surfacelength = document.getElementById('surfacelength').value;
487+
var Zdepth = document.getElementById('surfacezdepth').value;;
488+
var spindle = document.getElementById('surfacespindle').value;;
489+
490+
ncProg = CreateSurfaceProgram(bitdiam, stepover, feedrate, surfacewidth, surfacelength, Zdepth, spindle);
491+
492+
filename = "Surface" + "_X" + surfacewidth + "_Y" + surfacelength + "_Z-" + Zdepth + ".nc";
493+
494+
var blob = new Blob([ncProg], {type: "txt"});
495+
496+
files = [];
497+
files.push(new File([blob], filename));
498+
499+
files_start_upload2(files, "/" + dirname + "/")
500+
501+
surface_progress_status = 1;
502+
on_autocheck_status(true);
503+
files_print_filename(path + dirname + "/" + filename);
504+
document.getElementById("surfacebtn").style.display = "none";
505+
document.getElementById("surfacingtext").style.display = "table-row";
506+
//grbl_error_msg = "";
507+
//document.getElementById('grbl_status_text').innerHTML = grbl_error_msg;
508+
//finalize_surfacing()
509+
}
510+
511+
function CreateSurfaceProgram(bitdiam, stepover, feedrate, surfacewidth, surfacelength, Zdepth, spindle) {
512+
var crlf = "\n";
513+
514+
effectiveCuttingWidth = Math.round(1000 * (bitdiam * (1 - stepover/100))) / 1000;
515+
nPasses = Math.floor(surfacelength / effectiveCuttingWidth);
516+
lastPassWidth = surfacelength % effectiveCuttingWidth;
517+
518+
ncProg = "G21" + crlf; // Unit = mm
519+
ncProg += "G90" + crlf; // Absolute Positioning
520+
ncProg += "G53 G0 Z-5" + crlf; // Move spindle to safe height
521+
ncProg += "G54" + crlf; // Work Coordinates
522+
ncProg += "M3 S" + spindle + crlf; // Set spindle speed
523+
ncProg += "G4 P1.8" + crlf; // Spindle delay
524+
ncProg += "G1 F" + feedrate + crlf; // Set feedrate
525+
ncProg += "G0 X0 Y0" + crlf; // Move to XY origin at Z-safe height
526+
ncProg += "G1 Z-" + Zdepth + crlf; // Move to Z origin (while starting to cut)
527+
528+
var Xend = 0;
529+
for (var i = 0; i <= nPasses; i++) {
530+
Xend == 0 ? Xend = surfacewidth : Xend = 0; // alternate X (passes are in X direction)
531+
cmd = "G1 X" + Xend + " Y" + i * effectiveCuttingWidth + " Z-" + Zdepth;
532+
ncProg += cmd + crlf;
533+
if (i < nPasses) {
534+
cmd = "G1 Y" + (i+1) * effectiveCuttingWidth; // increment Y at each pass
535+
ncProg += cmd + crlf;
536+
}
537+
}
538+
539+
if(lastPassWidth > 0) {
540+
Xend == 0 ? Xend = surfacewidth : Xend = 0; // alternate X
541+
cmd = "G1 Y" + surfacelength;
542+
ncProg += cmd + crlf;
543+
cmd = "G1 X" + Xend + " Y" + surfacelength + " Z-" + Zdepth;
544+
ncProg += cmd + crlf;
545+
}
546+
547+
ncProg += "G53 G0 Z-5" + crlf; // Move spindle to safe height
548+
ncProg += "M5 S0" + crlf; // Spindle off
549+
550+
return ncProg;
551+
}

0 commit comments

Comments
 (0)