Skip to content

Commit 4606a08

Browse files
author
Jason Kridner
committed
attachInterrupt: almost working
1 parent dea32cd commit 4606a08

2 files changed

Lines changed: 33 additions & 16 deletions

File tree

.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":200},"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/polltest.c" 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":"input.js","value":"/workspace/input.js"},{"caption":"polltest.c","value":"/workspace/polltest.c"},{"caption":"misc.cpp","value":"/workspace/bonescript/misc.cpp"},{"caption":"misctest.js","value":"/workspace/bonescript/misctest.js"},{"caption":"epolltest.c","value":"/workspace/epolltest.c"},{"caption":"blinkled.js","value":"/workspace/blinkled.js"},{"caption":"index.js","value":"/workspace/bonescript/index.js"},{"caption":"footest.js","value":"/workspace/footest.js"},{"caption":"wscript","value":"/workspace/bonescript/wscript"},{"caption":"LICENSE","value":"/workspace/LICENSE"}]</recentfiles><extensions/><files active="/workspace/bonescript/index.js"><file path="/workspace/bonescript/index.js" type="file" size="19586" name="index.js" contenttype="application/javascript; charset=utf-8" modifieddate="Fri, 04 May 2012 22:35:00 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/bonescript/index.js" changed="0" state="{&quot;scrolltop&quot;:4372,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:286,&quot;column&quot;:0},&quot;end&quot;:{&quot;row&quot;:286,&quot;column&quot;:0}}}"/><file path="/workspace/input.js" type="file" size="745" name="input.js" contenttype="application/javascript; charset=utf-8" modifieddate="Fri, 04 May 2012 22:35:00 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/input.js" changed="0" state="{&quot;scrolltop&quot;:4372,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:6,&quot;column&quot;:63},&quot;end&quot;:{&quot;row&quot;:6,&quot;column&quot;:63}}}"/><file path="/workspace/blinkled.js" type="file" size="364" name="blinkled.js" contenttype="application/javascript; charset=utf-8" modifieddate="Fri, 04 May 2012 22:35:00 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/blinkled.js"/><file path="/workspace/bonescript/misc.cpp" type="file" size="1372" name="misc.cpp" contenttype="text/x-c; charset=utf-8" modifieddate="Fri, 04 May 2012 22:35:00 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/bonescript/misc.cpp" changed="0" state="{&quot;scrolltop&quot;:4372,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:111,&quot;column&quot;:8},&quot;end&quot;:{&quot;row&quot;:111,&quot;column&quot;:8}}}"/><file path="/workspace/epolltest.c" type="file" size="1012" name="epolltest.c" contenttype="text/x-c; charset=utf-8" modifieddate="Fri, 04 May 2012 22:35:00 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/epolltest.c" changed="0" state="{&quot;scrolltop&quot;:4372,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:28,&quot;column&quot;:24},&quot;end&quot;:{&quot;row&quot;:28,&quot;column&quot;:24}}}"/><file type="file" name="misctest.js" path="/workspace/bonescript/misctest.js" scriptname="/var/lib/cloud9/bonescript/misctest.js" changed="0" modifieddate="Fri, 04 May 2012 22:35:00 +0100" state="{&quot;scrolltop&quot;:4372,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:5,&quot;column&quot;:0},&quot;end&quot;:{&quot;row&quot;:10,&quot;column&quot;:26}}}"/><file path="/workspace/polltest.c" type="file" size="6849" name="polltest.c" contenttype="text/x-c; charset=utf-8" modifieddate="Fri, 04 May 2012 22:35:00 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/polltest.c" changed="0" state="{&quot;scrolltop&quot;:4372,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:262,&quot;column&quot;:3},&quot;end&quot;:{&quot;row&quot;:262,&quot;column&quot;:3}}}"/></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="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":"polltest.c","value":"/workspace/polltest.c"},{"caption":"index.js","value":"/workspace/bonescript/index.js"},{"caption":"misctest.js","value":"/workspace/bonescript/misctest.js"},{"caption":"epolltest.c","value":"/workspace/epolltest.c"},{"caption":"misc.cpp","value":"/workspace/bonescript/misc.cpp"},{"caption":"blinkled.js","value":"/workspace/blinkled.js"},{"caption":"input.js","value":"/workspace/input.js"},{"caption":"footest.js","value":"/workspace/footest.js"},{"caption":"wscript","value":"/workspace/bonescript/wscript"},{"caption":"LICENSE","value":"/workspace/LICENSE"}]</recentfiles><extensions/><files active="/workspace/bonescript/misc.cpp"><file path="/workspace/bonescript/index.js" type="file" size="19586" name="index.js" contenttype="application/javascript; charset=utf-8" modifieddate="Sat, 05 May 2012 21:34:40 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/bonescript/index.js" changed="0" state="{&quot;scrolltop&quot;:0,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:292,&quot;column&quot;:32},&quot;end&quot;:{&quot;row&quot;:292,&quot;column&quot;:32}}}"/><file path="/workspace/input.js" type="file" size="745" name="input.js" contenttype="application/javascript; charset=utf-8" modifieddate="Sat, 05 May 2012 21:34:40 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/input.js" changed="0" state="{&quot;scrolltop&quot;:0,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:6,&quot;column&quot;:63},&quot;end&quot;:{&quot;row&quot;:6,&quot;column&quot;:63}}}"/><file path="/workspace/blinkled.js" type="file" size="364" name="blinkled.js" contenttype="application/javascript; charset=utf-8" modifieddate="Sat, 05 May 2012 21:34:40 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/blinkled.js"/><file path="/workspace/bonescript/misc.cpp" type="file" size="1372" name="misc.cpp" contenttype="text/x-c; charset=utf-8" modifieddate="Sat, 05 May 2012 21:34:40 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/bonescript/misc.cpp" changed="0" state="{&quot;scrolltop&quot;:0,&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="Sat, 05 May 2012 21:34:40 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/epolltest.c" changed="0" state="{&quot;scrolltop&quot;:0,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:31,&quot;column&quot;:0},&quot;end&quot;:{&quot;row&quot;:36,&quot;column&quot;:0}}}"/><file type="file" name="misctest.js" path="/workspace/bonescript/misctest.js" scriptname="/var/lib/cloud9/bonescript/misctest.js" changed="0" modifieddate="Sat, 05 May 2012 21:34:40 +0100" state="{&quot;scrolltop&quot;:0,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:4,&quot;column&quot;:0},&quot;end&quot;:{&quot;row&quot;:4,&quot;column&quot;:0}}}"/><file path="/workspace/polltest.c" type="file" size="6849" name="polltest.c" contenttype="text/x-c; charset=utf-8" modifieddate="Sat, 05 May 2012 21:34:41 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/polltest.c" changed="0" state="{&quot;scrolltop&quot;:0,&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}}}"/></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="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/misc.cpp

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <stdio.h>
1010
#include <errno.h>
1111

12+
#define PRINTF
13+
1214
using namespace std;
1315
using namespace node;
1416
using namespace v8;
@@ -51,7 +53,7 @@ class Pollpri: ObjectWrap {
5153
}
5254

5355
static Handle<Value> New(const Arguments &args) {
54-
printf("Entered New\n");
56+
PRINTF("Entered New\n");
5557
HandleScope scope;
5658
const char *usage = "usage: new Pollpri(path)";
5759
if(args.Length() != 1) {
@@ -62,12 +64,12 @@ class Pollpri: ObjectWrap {
6264
p->Wrap(args.This());
6365
p->path = (char *)malloc(path.length() + 1);
6466
strncpy(p->path, *path, path.length() + 1);
65-
printf("Leaving New\n");
67+
PRINTF("Leaving New\n");
6668
return(args.This());
6769
}
6870

6971
static Handle<Value> pollpri(const Arguments& args) {
70-
printf("Entered pollpri\n");
72+
PRINTF("Entered pollpri\n");
7173
HandleScope scope;
7274
const char *usage = "usage: pollpri(cb)";
7375
if(args.Length() != 1) {
@@ -84,49 +86,64 @@ class Pollpri: ObjectWrap {
8486

8587
eio_custom(pollpri_thread, EIO_PRI_DEFAULT, pollpri_after, pr);
8688
ev_ref(EV_DEFAULT_UC);
87-
printf("Leaving pollpri\n");
89+
PRINTF("Leaving pollpri\n");
8890
return(Undefined());
8991
}
9092

9193
static int pollpri_thread(eio_req *req) {
92-
printf("Entered pollpri_thread\n");
94+
PRINTF("Entered pollpri_thread\n");
9395
struct pollpri_request * pr = (struct pollpri_request *)req->data;
9496
Pollpri *p = pr->p;
9597
int epfd = p->epfd;
9698
int fd = p->fd;
9799
if(!fd) {
98100
fd = open(p->path, O_RDWR | O_NONBLOCK);
99101
pr->p->fd = fd;
100-
printf("open(%s) returned %d: %s\n", p->path, fd, strerror(errno));
102+
PRINTF("open(%s) returned %d: %s\n", p->path, fd, strerror(errno));
101103
}
102104
if(!epfd) {
103105
epfd = epoll_create(1);
104106
pr->p->epfd = epfd;
105-
printf("epoll_create(1) returned %d: %s\n", epfd, strerror(errno));
107+
PRINTF("epoll_create(1) returned %d: %s\n", epfd, strerror(errno));
106108
struct epoll_event ev;
107109
ev.events = EPOLLPRI;
108110
ev.data.fd = fd;
109111
int n = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev);
110-
printf("epoll_ctl(%d) returned %d (%d): %s\n", fd, n, epfd, strerror(errno));
112+
PRINTF("epoll_ctl(%d) returned %d (%d): %s\n", fd, n, epfd, strerror(errno));
111113
}
112114
//ev_io pollpri_watcher;
113115
//ev_init(&pollpri_watcher, pollpri_event);
114116
//pollpri_watcher.data = pr;
115117
//ev_io_set(&pollpri_watcher, epfd, EV_READ | EV_WRITE);
116118
//ev_io_start(EV_DEFAULT_ &pollpri_watcher);
117119
struct epoll_event events;
118-
printf("Calling epoll_wait\n");
119-
sleep(1);
120-
int m = epoll_wait(epfd, &events, 1, -1);
121-
printf("epoll_wait(%d) returned %d: %s\n", epfd, m, strerror(errno));
120+
int m = 0;
121+
while(m <= 0) {
122+
PRINTF("Calling epoll_wait\n");
123+
m = epoll_wait(epfd, &events, 1, -1);
124+
PRINTF("epoll_wait(%d) returned %d: %s\n", epfd, m, strerror(errno));
125+
//struct pollfd pfd;
126+
//pfd.fd = fd;
127+
//pfd.events = POLLPRI;
128+
//m = poll(&fdset, 1, -1)
129+
if(m > 0) {
130+
char buf;
131+
int q;
132+
q = lseek(fd, 0, SEEK_SET);
133+
PRINTF("seek %d bytes: %s\n", q, strerror(errno));
134+
q = read(fd, &buf, 1);
135+
PRINTF("read %d bytes: %s\n", q, strerror(errno));
136+
PRINTF("buf = 0x%x\n", buf);
137+
}
138+
}
122139
//close(epfd);
123140
//close(fd);
124-
printf("Leaving pollpri_thread\n");
141+
PRINTF("Leaving pollpri_thread\n");
125142
return(0);
126143
}
127144

128145
static int pollpri_after(eio_req *req) {
129-
printf("Entered pollpri_after\n");
146+
PRINTF("Entered pollpri_after\n");
130147
HandleScope scope;
131148
ev_unref(EV_DEFAULT_UC);
132149
struct pollpri_request * pr = (struct pollpri_request *)req->data;
@@ -138,7 +155,7 @@ class Pollpri: ObjectWrap {
138155
//close(pr->p->epfd);
139156
//close(pr->p->fd);
140157
free(pr);
141-
printf("Leaving pollpri_after\n");
158+
PRINTF("Leaving pollpri_after\n");
142159
return(0);
143160
}
144161

0 commit comments

Comments
 (0)