Skip to content

Test/use mocks - test setup #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*~
tmp/
node_modules/
sys/
16 changes: 10 additions & 6 deletions lib/gpio.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var fs = require('fs');
var util = require('util');
var path = require('path');
var EventEmitter = require('events').EventEmitter;
var exists = fs.existsSync || path.exists;

var gpiopath = '/sys/class/gpio/';
var DIRECTION = { 'IN': 'in', 'OUT': 'out' };
Expand Down Expand Up @@ -42,12 +41,15 @@ var _unexport = function(number, fn) {
if(typeof fn === 'function') fn();
}, 1);
};

var _export = function(n, fn) {
if(exists(gpiopath + 'gpio'+n)) {
try {
fs.accessSync(gpiopath + 'gpio'+n)
// already exported, unexport and export again
logMessage('Header already exported');
_unexport(n, function() { _export(n, fn); });
} else {

} catch (e) {
logMessage('Exporting gpio' + n);
_write(n, gpiopath + 'export', function(err) {
// if there's an error when exporting, unexport and repeat
Expand All @@ -63,7 +65,7 @@ var _testwrite = function(file, fn) {
return;
}
fs.close(fd, function(err){
fn(true, null);
fn(true, null);
});
});
};
Expand Down Expand Up @@ -204,7 +206,7 @@ GPIO.prototype.setDirection = function(dir, fn) {
self.emit('directionChange', dir);
}
}, 1);

});
};

Expand Down Expand Up @@ -255,4 +257,6 @@ exports.logging = false;
exports.export = function(headerNum, opts) { return new GPIO(headerNum, opts); };
exports.DIRECTION = DIRECTION;
exports.unexport = _unexport;

exports.setConfig = function (config) {
gpiopath = config.gpiopath || gpiopath
}
Loading