@@ -2,7 +2,6 @@ var fs = require('fs');
2
2
var util = require ( 'util' ) ;
3
3
var path = require ( 'path' ) ;
4
4
var EventEmitter = require ( 'events' ) . EventEmitter ;
5
- var exists = fs . exists || path . exists ;
6
5
7
6
var gpiopath = '/sys/class/gpio/' ;
8
7
@@ -40,12 +39,15 @@ var _unexport = function(number, fn) {
40
39
if ( typeof fn === 'function' ) fn ( ) ;
41
40
} , 1 ) ;
42
41
} ;
42
+
43
43
var _export = function ( n , fn ) {
44
- if ( exists ( gpiopath + 'gpio' + n ) ) {
44
+ try {
45
+ fs . accessSync ( gpiopath + 'gpio' + n )
45
46
// already exported, unexport and export again
46
47
logMessage ( 'Header already exported' ) ;
47
48
_unexport ( n , function ( ) { _export ( n , fn ) ; } ) ;
48
- } else {
49
+
50
+ } catch ( e ) {
49
51
logMessage ( 'Exporting gpio' + n ) ;
50
52
_write ( n , gpiopath + 'export' , function ( err ) {
51
53
// if there's an error when exporting, unexport and repeat
@@ -61,7 +63,7 @@ var _testwrite = function(file, fn) {
61
63
return ;
62
64
}
63
65
fs . close ( fd , function ( err ) {
64
- fn ( true , null ) ;
66
+ fn ( true , null ) ;
65
67
} ) ;
66
68
} ) ;
67
69
} ;
@@ -202,7 +204,7 @@ GPIO.prototype.setDirection = function(dir, fn) {
202
204
self . emit ( 'directionChange' , dir ) ;
203
205
}
204
206
} , 1 ) ;
205
-
207
+
206
208
} ) ;
207
209
} ;
208
210
@@ -252,4 +254,6 @@ GPIO.prototype.reset = function(fn) { this.set(0, fn); };
252
254
exports . logging = false ;
253
255
exports . export = function ( headerNum , direction ) { return new GPIO ( headerNum , direction ) ; } ;
254
256
exports . unexport = _unexport ;
255
-
257
+ exports . setConfig = function ( config ) {
258
+ gpiopath = config . gpiopath || gpiopath
259
+ }
0 commit comments