File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ var cncserver = require("cncserver");
2
2
var serialport = require ( "./node_modules/cncserver/node_modules/serialport/serialport.js" ) ;
3
3
var SerialPort = serialport . SerialPort ;
4
4
5
- var port = process . argv [ 2 ] ? process . argv [ 2 ] : "/dev/ttyACM0" ;
5
+ var port = process . argv [ 2 ] ;
6
6
7
7
// Actually try to init the connection and handle the various callbacks
8
8
cncserver . start ( {
@@ -15,7 +15,9 @@ cncserver.start({
15
15
connect : function ( ) {
16
16
console . log ( 'Bot Connected!' ) ;
17
17
cncserver . setHeight ( 'up' ) ;
18
- startReading ( ) ;
18
+ connectLeonardo ( function ( ) {
19
+ startReading ( ) ;
20
+ } ) ;
19
21
} ,
20
22
disconnect : function ( ) {
21
23
console . log ( "Bot disconnected!" )
@@ -123,3 +125,23 @@ function getWater(destPt) {
123
125
} ) ;
124
126
} ) ;
125
127
}
128
+
129
+
130
+ // Helper function for automatically connecting the littleBits leonardo
131
+ function connectLeonardo ( callback ) {
132
+ serialport . list ( function ( err , ports ) {
133
+ for ( var portID in ports ) {
134
+ if ( ports [ portID ] . serialNumber === 'Arduino_LLC_Arduino_Leonardo' ) {
135
+ port = ports [ portID ] . comName ;
136
+ }
137
+ }
138
+
139
+ if ( ! port ) {
140
+ console . error ( 'Littlebits Leonardo not found! ERR 16' ) ;
141
+ process . exit ( 16 ) ;
142
+ } else {
143
+ console . log ( 'Leonardo found on port:' , port ) ;
144
+ callback ( ) ;
145
+ }
146
+ } ) ;
147
+ }
You can’t perform that action at this time.
0 commit comments