Skip to content

Commit fcc96be

Browse files
committed
Merge pull request #18 from WasabiFan/develop
Merge changes for release of v1.0
2 parents 113efdf + c773dee commit fcc96be

34 files changed

+1986
-558
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "ev3dev-lang"]
55
path = ev3dev-lang
66
url = https://github.com/ev3dev/ev3dev-lang
7+
[submodule "test/fake-sys"]
8+
path = test/fake-sys
9+
url = https://github.com/ddemidov/ev3dev-lang-fake-sys.git

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: node_js
2+
node_js:
3+
- "4.1"
4+
- "0.10"

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Node.js Language Binding for ev3dev
33

44
This is a Node.js module that exposes the features of the [ev3dev](http://github.com/ev3dev/ev3dev) API in an easy-to-use structure. It is part of the "unified" bindings project for ev3dev, which means it implements our abstract API specification. This specification is implemented in multiple languages so that one can easily carry the same code concepts from one language to another, and all the core ev3dev APIs are supported universally.
55

6+
**Note:** Node.js can take 4+ seconds to load on the EV3, whicih makes it hard to iterate on code quickly. If you are looking for a way to get started with ev3dev development quickly and do not fit any of the use cases outlined in the "Use cases for JavaScript on the EV3" section below, I recommend that you look into other language options. Python is a good choice for beginners.
7+
8+
**Current supported kernel version:** `*-11-ev3dev-*`
9+
610
## Quickstart
711

812
Install the module from `npm`:
@@ -89,5 +93,6 @@ Situations to use JavaScript:
8993

9094

9195
Situations in which you should use other languages:
92-
- Sequential actions that run linearly
96+
- Sequential actions that must run in a specific order
9397
- Precise timing and delay
98+
- Coordinating multiple motors, sensors, or other hardware devices

autogen-config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"files": [
3-
"extras.ts",
4-
"motors.ts",
5-
"sensors.ts",
6-
"index.ts"
3+
"src/extras.ts",
4+
"src/motors.ts",
5+
"src/sensors.ts",
6+
"src/index.ts"
77
],
88
"templateDir": "templates/"
99
}

docs

examples/fade-leds.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var ev3dev = require('../bin/index.js');
2+
3+
console.log('fading LEDs from green to red...');
4+
5+
for (var pct = 0; pct < 100; pct += 1) {
6+
var brightnessVal = (pct / 100);
7+
var invertedBrightnessVal = 1 - brightnessVal;
8+
9+
ev3dev.Ev3Leds.left.setColor([ brightnessVal, invertedBrightnessVal ]);
10+
ev3dev.Ev3Leds.right.setColor([ brightnessVal, invertedBrightnessVal ]);
11+
12+
if(pct % 10 == 0)
13+
console.log(pct + '%');
14+
15+
{ //Hack to sleep for time
16+
// SHOULD NOT BE USED IN PRODUCTION CODE
17+
var start = new Date().getTime();
18+
while(new Date().getTime() < start + 100) {
19+
;
20+
}
21+
}
22+
}
23+
24+
console.log('done');
25+
26+
ev3dev.Ev3Leds.left.allOff();
27+
ev3dev.Ev3Leds.right.allOff();

examples/led-from-motor-speed.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var ev3dev = require('../bin/index.js');
2+
var stoppedBlinkInterval = 200;
23

34
if(!ev3dev.Ev3Leds.isConnected) {
45
console.error("This sample can only run on the EV3 brick. Other platforms are not supported by this script.");
@@ -12,13 +13,23 @@ if(!motor.connected) {
1213
process.exit(1);
1314
}
1415

15-
console.log("Connected to motor " + motor.portName);
16+
console.log("Connected to motor " + motor.address);
17+
motor.stopAction = motor.stopActionValues.coast;
18+
1619
console.log("Timer running... Rotate the motor and watch the on-board LEDs.");
1720

1821
setInterval(function() {
19-
var rpsSpeed = Math.min(Math.abs(motor.speed) / motor.countPerRot, 1);
2022

21-
var ledColor = [rpsSpeed, 1 - rpsSpeed];
22-
ev3dev.Ev3Leds.left.setColor(ledColor);
23-
ev3dev.Ev3Leds.right.setColor(ledColor);
24-
}, 10);
23+
if(motor.speed > 1) {
24+
var rpsSpeed = Math.min(Math.abs(motor.speed) / motor.countPerRot, 1);
25+
var ledColor = [rpsSpeed, 1 - rpsSpeed];
26+
ev3dev.Ev3Leds.left.setColor(ledColor);
27+
ev3dev.Ev3Leds.right.setColor(ledColor);
28+
}
29+
else {
30+
var blinkOn = (new Date()).getTime() % stoppedBlinkInterval > (stoppedBlinkInterval / 2);
31+
ev3dev.Ev3Leds.left.setColor([0, blinkOn? 0 : 1]);
32+
ev3dev.Ev3Leds.right.setColor([0, 1]);
33+
}
34+
35+
}, 80);

examples/raw-device-events.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var ev3dev = require('../bin/index.js');
2+
3+
var greenANSI = "\033[42m";
4+
var redANSI = "\033[41m";
5+
var resetANSI = "\033[0m";
6+
7+
var touchSensor = new ev3dev.TouchSensor();
8+
if (!touchSensor.connected) {
9+
console.error("No touch sensor could be found! Please verify that a touch sensor is plugged in and try again.");
10+
process.exit(1);
11+
}
12+
13+
touchSensor.registerEventCallback(function(error, touchInfo) {
14+
if(error) throw error;
15+
console.log("Sensor is " + (touchInfo.lastPressed ? greenANSI + "PRESSED" : redANSI + "RELEASED") + resetANSI);
16+
},
17+
function(userData) {
18+
var isPressed = touchSensor.isPressed;
19+
var changed = isPressed != userData.lastPressed;
20+
21+
userData.lastPressed = isPressed;
22+
return changed;
23+
}, false, { lastPressed: false });
24+
25+
console.log("Press the touch sensor to trigger the press event.");

examples/run-specific-motor.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ if(!motor.connected) {
66
process.exit(1);
77
}
88

9-
motor.speedRegulationEnabled = 'on';
10-
motor.positionSp = 180;
11-
motor.speedSp = 500;
12-
motor.stopCommand = 'brake';
13-
motor.command = "run-to-rel-pos";
9+
motor.runForDistance(360 * 10, 500, motor.stopActionValues.brake);
1410

1511
console.log("Running the motor for 180 tacho counts...");
1612

1713
// Prevent Node from exiting until motor is done
1814
var cancellationToken = setInterval(function() {
19-
if(motor.state.indexOf("running") == -1)
15+
if(!motor.isRunning)
2016
clearInterval(cancellationToken);
21-
}, 10);
17+
}, 200);

0 commit comments

Comments
 (0)