@@ -10,6 +10,7 @@ const DIRECTION_MAPPINGS = {
1010 'right' : 'X'
1111} ;
1212
13+ let config ;
1314let deviceAddress ;
1415let connected ;
1516let websocket ;
@@ -35,10 +36,11 @@ module.exports.setupWifi = async (credentials) => {
3536 return { result : 'fail' } ;
3637} ;
3738
38- module . exports . connect = async ( address , callback ) => {
39+ module . exports . connect = async ( address , callback , config_ ) => {
3940 if ( connected ) this . disconnect ( ) ;
4041 deviceAddress = address ;
4142 wsCallback = callback ;
43+ config = config_ ;
4244
4345 try {
4446 let res = await axios . get ( `http://${ deviceAddress } :8080/ping` ) ;
@@ -93,6 +95,11 @@ module.exports.connect = async (address, callback) => {
9395 case 'ok:IDLE' :
9496 paused = false ;
9597 framing = false ;
98+ laserDotActive = false ;
99+ break ;
100+ case 'ok:WORKING_OFFLINE' :
101+ framing = false ;
102+ laserDotActive = false ;
96103 break ;
97104 case 'ok:WORKING_FRAMING' :
98105 framing = true ;
@@ -257,30 +264,35 @@ module.exports.moveLaser = async (direction, distance, speed) => {
257264 }
258265
259266 try {
267+ let laserDotPower = config . laserSpotIntensity ;
268+ if ( laserDotPower > 10 ) laserDotPower = 10 ;
269+
260270 let gcode ;
261271 if ( direction == 'home' ) {
262272 gcode =
263273`M17 S1
264274M207 S0
265- M106 S1
266- M205 X424 Y400
267275M28
268276M18
269277` ;
270278 } else {
271279 gcode =
272280`M17 S1
273281M207 S0
274- M106 S1
275- M205 X424 Y400
276282M101
277283G92 X0 Y0
278284G90
279- G1 ${ DIRECTION_MAPPINGS [ direction ] + distance } F${ speed * 60 } S0
285+ G1 ${ DIRECTION_MAPPINGS [ direction ] + distance } F${ speed * 60 } S ${ laserDotActive ? laserDotPower * 10 : 0 }
280286M18
281287` ;
282288 }
283289
290+ if ( laserDotActive ) {
291+ let power = config . laserSpotIntensity ;
292+ if ( power > 10 ) power = 10 ;
293+ gcode += `M9 S${ power * 10 } N1000000000000\n` ;
294+ }
295+
284296 await this . executeGcode ( gcode ) ;
285297 } catch ( err ) {
286298 console . error ( 'Moving laser failed failed:' , err ) ;
@@ -333,6 +345,21 @@ module.exports.getCurrentState = async () => {
333345 return state ;
334346} ;
335347
348+ module . exports . dotModeActive = async ( ) => {
349+ if ( ! connected ) {
350+ console . error ( 'Requesting current dot mode state failed: Not connected' ) ;
351+ return ;
352+ }
353+
354+ try {
355+ let res = await axios . get ( `http://${ deviceAddress } :8080/system?action=dotMode` ) ;
356+ return res . data . dotMode == 1 ;
357+ } catch ( err ) {
358+ console . error ( 'Requesting current state failed:' , err ) ;
359+ }
360+ return false ;
361+ }
362+
336363module . exports . getProgress = async ( ) => {
337364 if ( ! connected ) {
338365 console . error ( 'Requesting current progress failed: Not connected' ) ;
0 commit comments