@@ -46,14 +46,14 @@ controller.on('serialport:open', function(options) {
4646 Cookies . set ( 'cnc.port' , port ) ;
4747 Cookies . set ( 'cnc.baudrate' , baudrate ) ;
4848
49- if ( controllerType == 'Grbl' ) {
49+ if ( controllerType === 'Grbl' ) {
5050 // Read the settings so we can determine the units for position reports
5151 // This will trigger a Grbl:settings callback to set grblReportingUnits
5252
5353 // This has a problem: The first status report arrives before the
5454 // settings report, so interpreting the numbers from the first status
5555 // report is ambiguous. Subsequent status reports are interpreted correctly.
56- // We work around that by deferring status reports until the settings report.
56+ // We work around that by deferring status reports until the settings report.
5757 controller . writeln ( '$$' ) ;
5858 }
5959
@@ -175,10 +175,10 @@ controller.on('serialport:write', function(data) {
175175
176176 // Track manual changes to the Grbl position reporting units setting
177177 // We are looking for either $13=0 or $13=1
178- if ( cnc . controllerType == 'Grbl' ) {
178+ if ( cnc . controllerType === 'Grbl' ) {
179179 cmd = data . split ( '=' ) ;
180- if ( cmd . length == 2 && cmd [ 0 ] == "$13" ) {
181- grblReportingUnits = cmd [ 1 ] ;
180+ if ( cmd . length === 2 && cmd [ 0 ] = == "$13" ) {
181+ grblReportingUnits = Number ( cmd [ 1 ] ) || 0 ;
182182 }
183183 }
184184} ) ;
@@ -209,17 +209,17 @@ function renderGrblState(data) {
209209 mlabel = 'MPos (in):' ;
210210 wlabel = 'WPos (in):' ;
211211 digits = 4 ;
212- factor = grblReportingUnits == 0 ? 1 / 25.4 : 1.0 ;
212+ factor = grblReportingUnits === 0 ? 1 / 25.4 : 1.0 ;
213213 break ;
214214 case 'G21' :
215215 mlabel = 'MPos (mm):' ;
216216 wlabel = 'WPos (mm):' ;
217217 digits = 3 ;
218- factor = grblReportingUnits == 0 ? 1.0 : 25.4 ;
218+ factor = grblReportingUnits === 0 ? 1.0 : 25.4 ;
219219 break ;
220220 }
221221
222- console . log ( grblReportingUnits , factor ) ;
222+ // console.log(grblReportingUnits, factor);
223223
224224 mpos . x = ( mpos . x * factor ) . toFixed ( digits ) ;
225225 mpos . y = ( mpos . y * factor ) . toFixed ( digits ) ;
@@ -244,27 +244,24 @@ function renderGrblState(data) {
244244controller . on ( 'Grbl:state' , function ( data ) {
245245 // If we do not yet know the reporting units from the $13 setting, we copy
246246 // the data for later processing when we do know.
247- if ( typeof grblReportingUnits == 'undefined' ) {
248- console . log ( "DEFER" ) ;
249- savedGrblState = JSON . parse ( JSON . stringify ( data ) ) ;
247+ if ( typeof grblReportingUnits === 'undefined' ) {
248+ savedGrblState = JSON . parse ( JSON . stringify ( data ) ) ;
250249 } else {
251- console . log ( "STATE" ) ;
252- renderGrblState ( data ) ;
250+ renderGrblState ( data ) ;
253251 }
254252} ) ;
255253
256254controller . on ( 'Grbl:settings' , function ( data ) {
257255 var settings = data . settings || { } ;
258- console . log ( "SETTINGS" ) ;
259- if ( settings [ '$13' ] != undefined ) {
260- grblReportingUnits = settings [ '$13' ] ;
261-
262- if ( typeof savedGrblState != 'undefined' ) {
263- renderGrblState ( savedGrblState ) ;
264- // Don't re-render the state if we get later settings reports,
265- // as the savedGrblState is probably stale.
266- savedGrblState = undefined ;
267- }
256+ if ( settings [ '$13' ] !== undefined ) {
257+ grblReportingUnits = Number ( settings [ '$13' ] ) || 0 ;
258+
259+ if ( typeof savedGrblState !== 'undefined' ) {
260+ renderGrblState ( savedGrblState ) ;
261+ // Don't re-render the state if we get later settings reports,
262+ // as the savedGrblState is probably stale.
263+ savedGrblState = undefined ;
264+ }
268265 }
269266} ) ;
270267
0 commit comments