Skip to content

Commit c2f2d4d

Browse files
author
Jason Kridner
committed
input.js: still stopping after some time
This mostly works, but it stops getting events on occasion. Events can be missed if the main loop runs across them. Disabled fibers for now as my current build was giving me fits.
1 parent cb5202f commit c2f2d4d

File tree

4 files changed

+37
-23
lines changed

4 files changed

+37
-23
lines changed

.settings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<settings version="0.0.4" ><auto><configurations debug="0" ><config path="blinkled.js" name="blinkled" extension="js" args="" /><config path="bone101.js" name="bone101" extension="js" args="" /><config path="footest.js" name="footest" extension="" args="" /><config path="input.js" name="input" extension="" args="" /></configurations><panel>{"ext/editors/editors":{"parent":{"visible":2,"flex":1},"visible":2,"flex":1},"ext/tree/tree":{"parent":{"visible":true,"width":"200"},"visible":true,"flex":1,"state":"normal"},"ext/console/console":{"parent":{"visible":2,"height":320},"visible":true,"flex":1},"ext/settings/settings":{"parent":{"visible":true,"width":"200"},"visible":false,"flex":1,"state":"normal"},"ext/openfiles/openfiles":{"parent":{"visible":true,"width":"200"},"visible":false,"flex":1,"state":"normal"}}</panel><tree_selection path="/workspace/bonescript/misctest.js" type="file"/><tree>["folder[1]","folder[1]/folder[2]"]</tree><console><input>this.subdir
22

33

4-
</input></console><customtypes/><zen>0.7</zen><recentfiles>[{"caption":"misc.cpp","value":"/workspace/bonescript/misc.cpp"},{"caption":"misctest.js","value":"/workspace/bonescript/misctest.js"},{"caption":"input.js","value":"/workspace/input.js"},{"caption":"evlibtest.c","value":"/workspace/evlibtest.c"},{"caption":"polltest.c","value":"/workspace/polltest.c"},{"caption":"epolltest.c","value":"/workspace/epolltest.c"},{"caption":"index.js","value":"/workspace/bonescript/index.js"},{"caption":"blinkled.js","value":"/workspace/blinkled.js"},{"caption":"footest.js","value":"/workspace/footest.js"},{"caption":"wscript","value":"/workspace/bonescript/wscript"}]</recentfiles><extensions/><files active="/workspace/input.js"><file path="/workspace/bonescript/index.js" type="file" size="19586" name="index.js" contenttype="application/javascript; charset=utf-8" modifieddate="Wed, 09 May 2012 03:24:39 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/bonescript/index.js" changed="0" state="{&quot;scrolltop&quot;:47,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:45,&quot;column&quot;:42},&quot;end&quot;:{&quot;row&quot;:45,&quot;column&quot;:42}}}"/><file path="/workspace/input.js" type="file" size="745" name="input.js" contenttype="application/javascript; charset=utf-8" modifieddate="Wed, 09 May 2012 03:24:40 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/input.js" changed="0" state="{&quot;scrolltop&quot;:47,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:27,&quot;column&quot;:30},&quot;end&quot;:{&quot;row&quot;:27,&quot;column&quot;:30}}}"/><file path="/workspace/bonescript/misc.cpp" type="file" size="1372" name="misc.cpp" contenttype="text/x-c; charset=utf-8" modifieddate="Wed, 09 May 2012 03:25:15 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/bonescript/misc.cpp" changed="0" state="{&quot;scrolltop&quot;:47,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:11,&quot;column&quot;:14},&quot;end&quot;:{&quot;row&quot;:11,&quot;column&quot;:14}}}"/><file path="/workspace/epolltest.c" type="file" size="1012" name="epolltest.c" contenttype="text/x-c; charset=utf-8" modifieddate="Wed, 09 May 2012 03:24:39 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/epolltest.c" changed="0" state="{&quot;scrolltop&quot;:47,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:31,&quot;column&quot;:12},&quot;end&quot;:{&quot;row&quot;:31,&quot;column&quot;:12}}}"/><file path="/workspace/polltest.c" type="file" size="6849" name="polltest.c" contenttype="text/x-c; charset=utf-8" modifieddate="Wed, 09 May 2012 03:24:39 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/polltest.c" changed="0" state="{&quot;scrolltop&quot;:47,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:248,&quot;column&quot;:27},&quot;end&quot;:{&quot;row&quot;:248,&quot;column&quot;:27}}}"/><file path="/workspace/evlibtest.c" type="file" size="1229" name="evlibtest.c" contenttype="text/x-c; charset=utf-8" modifieddate="Wed, 09 May 2012 03:24:39 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/evlibtest.c" changed="0" state="{&quot;scrolltop&quot;:47,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:5,&quot;column&quot;:19},&quot;end&quot;:{&quot;row&quot;:5,&quot;column&quot;:19}}}"/><file path="/workspace/bonescript/misctest.js" type="file" size="305" name="misctest.js" contenttype="application/javascript; charset=utf-8" modifieddate="Wed, 09 May 2012 03:24:39 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/bonescript/misctest.js" changed="0" state="{&quot;scrolltop&quot;:47,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:10,&quot;column&quot;:11},&quot;end&quot;:{&quot;row&quot;:10,&quot;column&quot;:11}}}"/></files></auto><general name="General" saveallbeforerun="true" openfiles="true"/><beautify name="Beautify"><jsbeautify name="JS Beautify" preserveemptylines="true" keeparrayindentation="false" braces="end-expand"/></beautify><editors name="Editor"><code name="Code Editor" overwrite="false" selectstyle="line" activeline="true" showinvisibles="false" showprintmargin="true" printmargincolumn="80" softtabs="true" tabsize="4" scrollspeed="2" fontsize="12" wrapmode="false" wraplimitmin="" wraplimitmax="" gutter="true" highlightselectedword="true" autohidehorscrollbar="true"/></editors><search><word key="ref"/><word key="event_watcher"/><word key="emit"/><word key="EV_READ"/><word key="pollpri_request"/><word key="emit"/><word key="event_watcher"/><word key="event_"/><word key="pollpri_event"/><word key="event_watcher"/><word key="pollpri_watcher"/><word key="watcher"/><word key="ev_io_set"/><word key="ping"/><word key="pollpri_request"/><word key="unref"/><word key="EV_DEFAULT"/><word key="pollpri_prepare"/><word key="pollpri_prepare_cb"/><word key="pollpri_event"/><word key="close"/><word key="events"/><word key="exists"/><word key="printf"/><word key="gpio[pin]"/><word key="epoll_ctl"/><word key="Pollpri"/><word key="pollpri_event"/><word key="sleep"/><word key="event"/><word key="attachInterrupt"/><word key="rx"/><word key="analogRead"/><word key="digitalWrite"/><word key="HIGH"/><word key="output"/><word key="socket"/><word key="readFile"/><word key="pinmode"/><word key="eeproms"/><word key="eeprom"/><word key="eeproms"/><word key="socket.emit"/><word key="muxOption"/><word key="ex"/><word key="export"/><word key="getpinmode"/><word key="omap_mux"/><word key="readout"/><word key="omap_mux"/><word key="muxstruct"/><word key="socket.emit"/><word key="mode"/><word key="socket"/><word key="spawn"/><word key="socket.on"/><word key="fibers"/><word key="pinObject"/><word key="pull"/><word key="pinmode"/><word key="events"/><word key="gpmc_ben1"/><word key="opensync"/></search><breakpoints /></settings>
4+
</input></console><customtypes/><zen>0.7</zen><recentfiles>[{"caption":"index.js","value":"/workspace/bonescript/index.js"},{"caption":"polltest.c","value":"/workspace/polltest.c"},{"caption":"epolltest.c","value":"/workspace/epolltest.c"},{"caption":"misc.cpp","value":"/workspace/bonescript/misc.cpp"},{"caption":"input.js","value":"/workspace/input.js"},{"caption":"evlibtest.c","value":"/workspace/evlibtest.c"},{"caption":"misctest.js","value":"/workspace/bonescript/misctest.js"},{"caption":"blinkled.js","value":"/workspace/blinkled.js"},{"caption":"footest.js","value":"/workspace/footest.js"},{"caption":"wscript","value":"/workspace/bonescript/wscript"}]</recentfiles><extensions/><files active="/workspace/input.js"><file path="/workspace/bonescript/index.js" type="file" size="19586" name="index.js" contenttype="application/javascript; charset=utf-8" modifieddate="Wed, 09 May 2012 21:22:31 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/bonescript/index.js" changed="0" state="{&quot;scrolltop&quot;:1,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:325,&quot;column&quot;:2},&quot;end&quot;:{&quot;row&quot;:325,&quot;column&quot;:2}}}"/><file path="/workspace/input.js" type="file" size="745" name="input.js" contenttype="application/javascript; charset=utf-8" modifieddate="Wed, 09 May 2012 21:22:31 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/input.js" changed="0" state="{&quot;scrolltop&quot;:1,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:28,&quot;column&quot;:0},&quot;end&quot;:{&quot;row&quot;:28,&quot;column&quot;:0}}}"/><file path="/workspace/bonescript/misc.cpp" type="file" size="1372" name="misc.cpp" contenttype="text/x-c; charset=utf-8" modifieddate="Wed, 09 May 2012 21:22:31 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/bonescript/misc.cpp" changed="0" state="{&quot;scrolltop&quot;:1,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:28,&quot;column&quot;:15},&quot;end&quot;:{&quot;row&quot;:28,&quot;column&quot;:15}}}"/><file path="/workspace/epolltest.c" type="file" size="1012" name="epolltest.c" contenttype="text/x-c; charset=utf-8" modifieddate="Wed, 09 May 2012 21:22:31 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/epolltest.c" changed="0" state="{&quot;scrolltop&quot;:1,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:31,&quot;column&quot;:12},&quot;end&quot;:{&quot;row&quot;:31,&quot;column&quot;:12}}}"/><file path="/workspace/polltest.c" type="file" size="6849" name="polltest.c" contenttype="text/x-c; charset=utf-8" modifieddate="Wed, 09 May 2012 21:22:31 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/polltest.c" changed="0" state="{&quot;scrolltop&quot;:1,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:248,&quot;column&quot;:27},&quot;end&quot;:{&quot;row&quot;:248,&quot;column&quot;:27}}}"/><file path="/workspace/evlibtest.c" type="file" size="1229" name="evlibtest.c" contenttype="text/x-c; charset=utf-8" modifieddate="Wed, 09 May 2012 21:22:31 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/evlibtest.c" changed="0" state="{&quot;scrolltop&quot;:1,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:5,&quot;column&quot;:19},&quot;end&quot;:{&quot;row&quot;:5,&quot;column&quot;:19}}}"/></files></auto><general name="General" saveallbeforerun="true" openfiles="true"/><beautify name="Beautify"><jsbeautify name="JS Beautify" preserveemptylines="true" keeparrayindentation="false" braces="end-expand"/></beautify><editors name="Editor"><code name="Code Editor" overwrite="false" selectstyle="line" activeline="true" showinvisibles="false" showprintmargin="true" printmargincolumn="80" softtabs="true" tabsize="4" scrollspeed="2" fontsize="12" wrapmode="false" wraplimitmin="" wraplimitmax="" gutter="true" highlightselectedword="true" autohidehorscrollbar="true"/></editors><search><word key="delay"/><word key="sleep"/><word key="delay"/><word key="ref"/><word key="event_watcher"/><word key="emit"/><word key="EV_READ"/><word key="pollpri_request"/><word key="emit"/><word key="event_watcher"/><word key="event_"/><word key="pollpri_event"/><word key="event_watcher"/><word key="pollpri_watcher"/><word key="watcher"/><word key="ev_io_set"/><word key="ping"/><word key="pollpri_request"/><word key="unref"/><word key="EV_DEFAULT"/><word key="pollpri_prepare"/><word key="pollpri_prepare_cb"/><word key="pollpri_event"/><word key="close"/><word key="events"/><word key="exists"/><word key="printf"/><word key="gpio[pin]"/><word key="epoll_ctl"/><word key="Pollpri"/><word key="pollpri_event"/><word key="sleep"/><word key="event"/><word key="attachInterrupt"/><word key="rx"/><word key="analogRead"/><word key="digitalWrite"/><word key="HIGH"/><word key="output"/><word key="socket"/><word key="readFile"/><word key="pinmode"/><word key="eeproms"/><word key="eeprom"/><word key="eeproms"/><word key="socket.emit"/><word key="muxOption"/><word key="ex"/><word key="export"/><word key="getpinmode"/><word key="omap_mux"/><word key="readout"/><word key="omap_mux"/><word key="muxstruct"/><word key="socket.emit"/><word key="mode"/><word key="socket"/><word key="spawn"/><word key="socket.on"/><word key="fibers"/><word key="pinObject"/><word key="pull"/><word key="pinmode"/><word key="events"/><word key="gpmc_ben1"/><word key="opensync"/></search><breakpoints /></settings>

bonescript/index.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ var myrequire = function(packageName, onfail) {
1717
y.exists = true;
1818
} catch(ex) {
1919
y.exists = false;
20-
console.log("'" + packageName + "' not loaded");
21-
console.log("If desired, try installing it with:");
22-
console.log(" curl http://npmjs.org/install.sh | bash");
23-
console.log(" npm install " + packageName);
20+
console.log("Optional package '" + packageName + "' not loaded");
2421
onfail();
2522
}
2623
return(y);
@@ -30,18 +27,16 @@ var socketio = myrequire('socket.io', function() {
3027
console.log("Dynamic web features not enabled");
3128
});
3229

33-
var binary = myrequire('binary', function() { });
34-
var inotify = myrequire('inotify', function() { });
35-
36-
var fibers = myrequire('fibers', function() {
37-
console.log("Delay operations loops will consume CPU cycles");
38-
console.log("Invoke using 'node-fibers' if node version < 0.5.2");
39-
});
30+
//var fibers = myrequire('fibers', function() {
31+
// console.log("Delay operations loops will consume CPU cycles");
32+
// console.log("Invoke using 'node-fibers' if node version < 0.5.2");
33+
//});
34+
var fibers = {exists: false};
4035

4136
var misc = myrequire('./misc', function () {
4237
console.log("Miscellaneous C++ functions not built");
43-
console.log("If desired, try building them with:");
44-
console.log(" cd bonescript");
38+
console.log("To build them from a shell window:");
39+
console.log(" cd /var/lib/cloud9/bonescript");
4540
console.log(" node-waf configure build");
4641
throw("./misc is currently required");
4742
});
@@ -297,6 +292,7 @@ shiftOut = exports.shiftOut = function(dataPin, clockPin, bitOrder, val, callbac
297292

298293
attachInterrupt = exports.attachInterrupt = function(pin, handler, mode) {
299294
var gpioFile = '/sys/class/gpio/gpio' + pin.gpio + '/value';
295+
fs.writeFileSync('/sys/class/gpio/gpio' + pin.gpio + '/edge', mode);
300296
var gpioPoll = new misc.Pollpri(gpioFile);
301297
gpio[pin.gpio].handler = handler;
302298
var gpioHandler = function(value) {
@@ -315,6 +311,8 @@ if(fibers.exists) {
315311
setTimeout(run, milliseconds);
316312
yield(null);
317313
};
314+
//} else if(misc.exists) {
315+
// delay = exports.delay = misc.delay;
318316
} else {
319317
delay = exports.delay = function(milliseconds)
320318
{

bonescript/misc.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,18 @@ class Pollpri: ObjectWrap {
3434

3535
static void Init(Handle<Object> target) {
3636
PRINTF("Entering Init\n");
37+
PRINTF("EV_DEFAULT_ = %s\n", TEST_EV_DEFAULT_NAME);
3738
HandleScope scope;
39+
3840
Local<FunctionTemplate> t = FunctionTemplate::New(New);
3941
ct = Persistent<FunctionTemplate>::New(t);
4042
ct->InstanceTemplate()->SetInternalFieldCount(1);
4143
ct->SetClassName(String::NewSymbol("Pollpri"));
42-
4344
target->Set(String::NewSymbol("Pollpri"), ct->GetFunction());
45+
46+
target->Set(String::NewSymbol("delay"),
47+
FunctionTemplate::New(delay)->GetFunction());
4448

45-
PRINTF("EV_DEFAULT_ = %s\n", TEST_EV_DEFAULT_NAME);
4649
PRINTF("Leaving Init\n");
4750
}
4851

@@ -61,7 +64,19 @@ class Pollpri: ObjectWrap {
6164
if(fd) close(fd);
6265
ev_io_stop(EV_DEFAULT_ &event_watcher);
6366
}
64-
67+
68+
static Handle<Value> delay(const Arguments& args) {
69+
PRINTF("Entered delay\n");
70+
HandleScope scope;
71+
const char *usage = "usage: new delay(duration)";
72+
if((args.Length() != 1) || !args[0]->IsNumber()) {
73+
return ThrowException(Exception::Error(String::New(usage)));
74+
}
75+
int duration = args[0]->NumberValue();
76+
usleep(duration*1000);
77+
return(Undefined());
78+
}
79+
6580
static Handle<Value> New(const Arguments& args) {
6681
PRINTF("Entered New\n");
6782
HandleScope scope;
@@ -156,5 +171,5 @@ extern "C" {
156171
Pollpri::Init(target);
157172
}
158173

159-
NODE_MODULE(pollpri, init);
174+
NODE_MODULE(pollpri, init)
160175
}

input.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,30 @@ var bb = require('./bonescript');
33
var outputPin = bone.P8_3;
44
var inputPin = bone.P8_5;
55

6+
var timeEvent = 0;
7+
68
var handler = function(pin, value) {
79
console.log(pin.key + ' changed to ' + ((value == HIGH) ? 'HIGH' : 'LOW'));
10+
console.timeEnd(''+timeEvent);
811
};
912

1013
setup = function() {
11-
console.log('inputPin mode: ' + JSON.stringify(getPinMode(inputPin)));
12-
console.log('outputPin mode: ' + JSON.stringify(getPinMode(outputPin)));
1314
pinMode(inputPin, INPUT);
1415
pinMode(outputPin, OUTPUT);
15-
console.log('inputPin mode: ' + JSON.stringify(getPinMode(inputPin)));
16-
console.log('outputPin mode: ' + JSON.stringify(getPinMode(outputPin)));
1716
attachInterrupt(inputPin, handler, CHANGE);
1817
};
1918

2019
var nextState = LOW;
2120
var toggleGPIO = function() {
2221
console.log('Setting ' + outputPin.key +
2322
((nextState == HIGH) ? ' HIGH' : ' LOW'));
23+
timeEvent++;
24+
console.time(''+timeEvent);
2425
digitalWrite(outputPin, nextState);
2526
nextState = (nextState == HIGH) ? LOW : HIGH;
2627
};
2728

28-
setInterval(toggleGPIO, 1000);
29+
setInterval(toggleGPIO, 500);
2930

3031
loop = function() {
3132
};

0 commit comments

Comments
 (0)