Skip to content

Commit 3743bd7

Browse files
committed
loops.js: debugged addLoop, removeLoop and getLoops
* Now able to access functions from client * loopId is the process ID
1 parent 3943ea8 commit 3743bd7

3 files changed

Lines changed: 104 additions & 17 deletions

File tree

bone101/client.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ var initClient = function() {
133133
'platform': [],
134134
'shell': [ 'command' ],
135135
'echo': [ 'data' ],
136-
'addLoop': [ 'loopFunc', 'loopDelay' ]
136+
'addLoop': [ 'loopFunc', 'loopDelay' ],
137+
'getLoops': [],
138+
'removeLoop': [ 'loopid' ]
137139
};
138140
for(var x in myfuncs) {
139141
socket.on(x, function(data) {
@@ -143,6 +145,9 @@ var initClient = function() {
143145
var objString = '';
144146
for(var y in myargs) {
145147
if(isNaN(y)) continue; // Need to find the source of this bug
148+
objString += ' if(typeof ' + myargs[y] + ' == "function") {\n';
149+
objString += ' ' + myargs[y] + ' = ' + myargs[y] + '.toString();\n';
150+
objString += ' }\n';
146151
objString += ' calldata.' + myargs[y] + ' = ' + myargs[y] + ';\n';
147152
}
148153
myargs.push('callback');

loops.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
require('bonescript');
2+
3+
ledPin = bone.USR3;
4+
outputPin = bone.P8_3;
5+
6+
setup = function() {
7+
console.log("Running setup");
8+
pinMode(ledPin, OUTPUT);
9+
pinMode(outputPin, OUTPUT);
10+
digitalWrite(ledPin, LOW);
11+
digitalWrite(outputPin, LOW);
12+
console.log("getLoops() = " + JSON.stringify(getLoops()));
13+
14+
// Start toggling after 5 seconds
15+
setTimeout(function() {
16+
console.log("Flashing LED for 5 seconds");
17+
loopid = addLoop(function() {
18+
digitalWrite(ledPin, HIGH);
19+
digitalWrite(outputPin, HIGH);
20+
delay(100);
21+
digitalWrite(ledPin, LOW);
22+
digitalWrite(outputPin, LOW);
23+
}, 150);
24+
console.log("loopid = " + loopid);
25+
console.log("getLoops() = " + JSON.stringify(getLoops()));
26+
27+
// Stop toggling after 5 seconds
28+
setTimeout(function() {
29+
removeLoop(loopid)
30+
console.log("Halting flashing of LED");
31+
}, 5000);
32+
}, 5000);
33+
};
34+
35+
run(setup);

node_modules/bonescript/index.js

Lines changed: 63 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)