@@ -2,6 +2,10 @@ import { Path, PathType } from './path';
22import { GCodeCommand } from './gcode-parser' ;
33import { Job } from './job' ;
44
5+
6+ // eslint-disable-next-line no-unused-vars
7+ type Method = ( ...args : unknown [ ] ) => unknown ;
8+
59/**
610 * Interprets and executes G-code commands, updating the job state accordingly
711 *
@@ -14,6 +18,11 @@ export class Interpreter {
1418 // eslint-disable-next-line no-unused-vars
1519 [ key : string ] : ( ...args : unknown [ ] ) => unknown ;
1620
21+ private retractions = 0 ;
22+ private wipes = 0 ;
23+ private feedrateChanges = 0 ;
24+ private points = 0 ;
25+
1726 /**
1827 * Executes an array of G-code commands, updating the provided job
1928 * @param commands - Array of GCodeCommand objects to execute
@@ -24,14 +33,22 @@ export class Interpreter {
2433 job . resumeLastPath ( ) ;
2534 commands . forEach ( ( command ) => {
2635 if ( command . gcode !== undefined ) {
27- if ( this [ command . gcode ] === undefined ) {
36+
37+ if ( typeof this [ command . gcode ] !== 'function' ) {
2838 return ;
2939 }
30- this [ command . gcode ] ( command , job ) ;
40+ const method = this [ command . gcode ] as Method ;
41+ method . bind ( this ) ( command , job ) ;
3142 }
3243 } ) ;
3344 job . finishPath ( ) ;
3445
46+ console . debug ( 'Done processing gcode' , measure . duration . toFixed ( 0 ) + 'ms' ) ;
47+ console . debug ( this . retractions , 'retractions' ) ;
48+ console . debug ( this . wipes , 'wipes' ) ;
49+ console . debug ( this . feedrateChanges , 'feedrateChanges' ) ;
50+ console . debug ( this . points , 'points' ) ;
51+
3552 return job ;
3653 }
3754
@@ -49,9 +66,24 @@ export class Interpreter {
4966
5067 // discard zero length moves
5168 if ( x === undefined && y === undefined && z === undefined ) {
69+ // console.warn('Discarding zero length move');
70+ if ( e > 0 ) {
71+ this . retractions ++ ;
72+ }
73+
74+ else if ( e < 0 ) {
75+ this . wipes ++ ;
76+ }
77+
78+ if ( f !== undefined ) {
79+ this . feedrateChanges ++ ;
80+ }
81+
5282 return ;
5383 }
5484
85+ this . points ++ ;
86+
5587 const { state } = job ;
5688 let currentPath = job . inprogressPath ;
5789 const pathType = e > 0 ? PathType . Extrusion : PathType . Travel ;
0 commit comments