Permalink
Browse files

input.js: committed actual forking version

  • Loading branch information...
1 parent e168098 commit f24f4347da0dac7d3dd8361d827728726100f3e5 @jadonk committed May 15, 2012
Showing with 14 additions and 10 deletions.
  1. +5 −6 bonescript/gpioint.js
  2. +9 −4 bonescript/index.js
View
@@ -1,26 +1,25 @@
var events = require('events');
var misc = require('./misc');
-for(var x in events.EventEmitter.prototype) {
- misc.Pollpri.prototype[x] = events.EventEmitter.prototype[x];
-}
+misc.Pollpri.prototype.__proto__ = events.EventEmitter.prototype;
if(process.argv.length > 2) {
var file = process.argv[2];
var gpioPoll = new misc.Pollpri(file);
var gpioHandler = function(value) {
+ value = value.replace(/\s*$/, '');
console.log(''+value);
};
gpioPoll.on('edge', gpioHandler);
} else {
var onMessage = function(m) {
- console.log('Attaching handler to ' + m.file);
+ //console.log('Attaching handler to ' + m.file);
var gpioPoll = new misc.Pollpri(m.file);
var gpioHandler = function(value) {
- console.log('Got interrupt event');
+ //console.log('Got interrupt event');
process.send({'value': value});
};
gpioPoll.on('edge', gpioHandler);
};
process.on('message', onMessage);
- console.log('Started GPIO interrupt listener');
+ //console.log('Started GPIO interrupt listener');
}
View
@@ -9,7 +9,6 @@ var path = require('path');
var events = require('events');
var eeprom = require('./eeprom');
bone = require('./bone').bone;
-var fork = require('fork');
var myrequire = function(packageName, onfail) {
var y = {};
@@ -284,9 +283,15 @@ attachInterrupt = exports.attachInterrupt = function(pin, handler, mode) {
var intHandler = function(m) {
handler(pin, m.value);
};
- if(0) {
- console.log('Forking gpioint.js');
- var intProc = fork.fork(__dirname + '/gpioint.js');
+ if(1) {
+ //console.log('Forking gpioint.js');
+ var intProc;
+ if(child_process.fork) {
+ intProc = child_process.fork(__dirname + '/gpioint.js');
+ } else {
+ var fork = require('fork');
+ intProc = fork.fork(__dirname + '/gpioint.js');
+ }
intProc.on('message', intHandler);
intProc.send({'pin': pin, 'mode': mode, 'file': gpioFile});
gpio[pin.gpio].intProc = intProc;

0 comments on commit f24f434

Please sign in to comment.