1
1
var interval_status = - 1 ;
2
2
var probe_progress_status = 0 ;
3
+ var surface_progress_status = 0 ;
3
4
var grbl_error_msg = "" ;
4
5
var gotWCO = false ;
5
6
var WCOx = 0 ;
@@ -124,6 +125,24 @@ function onprobetouchplatethicknessChange() {
124
125
return true ;
125
126
}
126
127
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
+
127
146
function on_autocheck_status ( use_value ) {
128
147
if ( probe_progress_status != 0 ) {
129
148
document . getElementById ( 'autocheck_status' ) . checked = true ;
@@ -289,6 +308,9 @@ function process_grbl_status(response) {
289
308
if ( probe_progress_status != 0 ) {
290
309
probe_failed_notification ( ) ;
291
310
}
311
+ if ( surface_progress_status != 0 ) {
312
+ surface_failed_notification ( ) ;
313
+ }
292
314
//grbl_error_msg = "";
293
315
//check we are printing or not
294
316
if ( response . indexOf ( "|SD:" ) != - 1 ) {
@@ -303,6 +325,10 @@ function process_grbl_status(response) {
303
325
document . getElementById ( 'sd_reset_btn' ) . style . display = "none" ;
304
326
}
305
327
if ( tab2 . toLowerCase ( ) . startsWith ( "idle" ) ) {
328
+
329
+ if ( surface_progress_status == 100 ) {
330
+ finalize_surfacing ( ) ;
331
+ }
306
332
grbl_error_msg = "" ;
307
333
}
308
334
document . getElementById ( 'grbl_status_text' ) . innerHTML = translate_text_item ( grbl_error_msg ) ;
@@ -317,6 +343,16 @@ function finalize_probing() {
317
343
document . getElementById ( "probingtext" ) . style . display = "none" ;
318
344
document . getElementById ( 'sd_pause_btn' ) . style . display = "none" ;
319
345
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" ;
320
356
document . getElementById ( 'sd_reset_btn' ) . style . display = "none" ;
321
357
}
322
358
@@ -334,6 +370,9 @@ function process_grbl_SD(response) {
334
370
progress = progress . replace ( ">" , "" ) ;
335
371
}
336
372
document . getElementById ( 'grbl_SD_status' ) . innerHTML = sdname + " <progress id='print_prg' value=" + progress + " max='100'></progress>" + progress + "%" ;
373
+ if ( progress == 100 & surface_progress_status != 0 ) {
374
+ surface_progress_status = progress ;
375
+ }
337
376
} else { //no SD printing
338
377
//TODO
339
378
document . getElementById ( 'grbl_SD_status' ) . innerHTML = "" ;
@@ -375,6 +414,7 @@ function grbl_process_msg(response) {
375
414
376
415
function grbl_reset ( ) {
377
416
if ( probe_progress_status != 0 ) probe_failed_notification ( ) ;
417
+ if ( surface_progress_status != 0 ) surface_failed_notification ( ) ;
378
418
SendRealtimeCmd ( String . fromCharCode ( 0x18 ) ) ;
379
419
}
380
420
@@ -410,8 +450,15 @@ function probe_failed_notification() {
410
450
beep ( 70 , 261 ) ;
411
451
}
412
452
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
+
413
459
function StartProbeProcess ( ) {
414
460
var cmd = "G38.2 G91 Z-" ;
461
+
415
462
if ( ! onprobemaxtravelChange ( ) ||
416
463
! onprobefeedrateChange ( ) ||
417
464
! onprobetouchplatethicknessChange ( ) ) {
@@ -427,3 +474,78 @@ function StartProbeProcess() {
427
474
grbl_error_msg = "" ;
428
475
document . getElementById ( 'grbl_status_text' ) . innerHTML = grbl_error_msg ;
429
476
}
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