Skip to content

Commit

Permalink
Merge pull request #18 from WasabiFan/develop
Browse files Browse the repository at this point in the history
Merge changes for release of v1.0
  • Loading branch information
WasabiFan committed May 21, 2016
2 parents 113efdf + c773dee commit fcc96be
Show file tree
Hide file tree
Showing 34 changed files with 1,986 additions and 558 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "ev3dev-lang"]
path = ev3dev-lang
url = https://github.com/ev3dev/ev3dev-lang
[submodule "test/fake-sys"]
path = test/fake-sys
url = https://github.com/ddemidov/ev3dev-lang-fake-sys.git
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: node_js
node_js:
- "4.1"
- "0.10"
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Node.js Language Binding for ev3dev

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.

**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.

**Current supported kernel version:** `*-11-ev3dev-*`

## Quickstart

Install the module from `npm`:
Expand Down Expand Up @@ -89,5 +93,6 @@ Situations to use JavaScript:


Situations in which you should use other languages:
- Sequential actions that run linearly
- Sequential actions that must run in a specific order
- Precise timing and delay
- Coordinating multiple motors, sensors, or other hardware devices
8 changes: 4 additions & 4 deletions autogen-config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"files": [
"extras.ts",
"motors.ts",
"sensors.ts",
"index.ts"
"src/extras.ts",
"src/motors.ts",
"src/sensors.ts",
"src/index.ts"
],
"templateDir": "templates/"
}
2 changes: 1 addition & 1 deletion docs
Submodule docs updated 41 files
+1 −1 assets/js/search.js
+249 −35 classes/_extras_.led.html
+9 −9 classes/_extras_.ledgroup.html
+242 −28 classes/_extras_.legoport.html
+242 −28 classes/_extras_.powersupply.html
+25 −20 classes/_index_.brickpileds.html
+31 −26 classes/_index_.ev3leds.html
+322 −23 classes/_io_.device.html
+437 −0 classes/_io_.eventnotificationrequest.html
+950 −0 classes/_io_.indexeddevice.html
+15 −6 classes/_io_.traceerror.html
+13 −4 classes/_io_.xerror.html
+439 −70 classes/_motors_.dcmotor.html
+869 −292 classes/_motors_.largemotor.html
+869 −292 classes/_motors_.mediummotor.html
+920 −278 classes/_motors_.motor.html
+273 −44 classes/_motors_.motorbase.html
+9 −9 classes/_motors_.motorspeedsp.html
+369 −49 classes/_motors_.servomotor.html
+270 −41 classes/_sensors_.colorsensor.html
+266 −37 classes/_sensors_.gyrosensor.html
+267 −38 classes/_sensors_.i2csensor.html
+265 −36 classes/_sensors_.infraredsensor.html
+266 −37 classes/_sensors_.lightsensor.html
+264 −35 classes/_sensors_.sensor.html
+271 −39 classes/_sensors_.sensorbase.html
+266 −37 classes/_sensors_.soundsensor.html
+265 −36 classes/_sensors_.touchsensor.html
+267 −38 classes/_sensors_.ultrasonicsensor.html
+3 −3 globals.html
+9 −6 index.html
+2 −2 modules/_extras_.html
+212 −0 modules/_index_.dcmotor.html
+50 −84 modules/_index_.html
+240 −0 modules/_index_.motor.html
+198 −0 modules/_index_.servomotor.html
+32 −2 modules/_io_.html
+4 −8 modules/_motors_.html
+243 −0 modules/_motors_.largemotor.motor.html
+243 −0 modules/_motors_.mediummotor.motor.html
+2 −2 modules/_sensors_.html
27 changes: 27 additions & 0 deletions examples/fade-leds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var ev3dev = require('../bin/index.js');

console.log('fading LEDs from green to red...');

for (var pct = 0; pct < 100; pct += 1) {
var brightnessVal = (pct / 100);
var invertedBrightnessVal = 1 - brightnessVal;

ev3dev.Ev3Leds.left.setColor([ brightnessVal, invertedBrightnessVal ]);
ev3dev.Ev3Leds.right.setColor([ brightnessVal, invertedBrightnessVal ]);

if(pct % 10 == 0)
console.log(pct + '%');

{ //Hack to sleep for time
// SHOULD NOT BE USED IN PRODUCTION CODE
var start = new Date().getTime();
while(new Date().getTime() < start + 100) {
;
}
}
}

console.log('done');

ev3dev.Ev3Leds.left.allOff();
ev3dev.Ev3Leds.right.allOff();
23 changes: 17 additions & 6 deletions examples/led-from-motor-speed.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var ev3dev = require('../bin/index.js');
var stoppedBlinkInterval = 200;

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

console.log("Connected to motor " + motor.portName);
console.log("Connected to motor " + motor.address);
motor.stopAction = motor.stopActionValues.coast;

console.log("Timer running... Rotate the motor and watch the on-board LEDs.");

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

var ledColor = [rpsSpeed, 1 - rpsSpeed];
ev3dev.Ev3Leds.left.setColor(ledColor);
ev3dev.Ev3Leds.right.setColor(ledColor);
}, 10);
if(motor.speed > 1) {
var rpsSpeed = Math.min(Math.abs(motor.speed) / motor.countPerRot, 1);
var ledColor = [rpsSpeed, 1 - rpsSpeed];
ev3dev.Ev3Leds.left.setColor(ledColor);
ev3dev.Ev3Leds.right.setColor(ledColor);
}
else {
var blinkOn = (new Date()).getTime() % stoppedBlinkInterval > (stoppedBlinkInterval / 2);
ev3dev.Ev3Leds.left.setColor([0, blinkOn? 0 : 1]);
ev3dev.Ev3Leds.right.setColor([0, 1]);
}

}, 80);
25 changes: 25 additions & 0 deletions examples/raw-device-events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var ev3dev = require('../bin/index.js');

var greenANSI = "\033[42m";
var redANSI = "\033[41m";
var resetANSI = "\033[0m";

var touchSensor = new ev3dev.TouchSensor();
if (!touchSensor.connected) {
console.error("No touch sensor could be found! Please verify that a touch sensor is plugged in and try again.");
process.exit(1);
}

touchSensor.registerEventCallback(function(error, touchInfo) {
if(error) throw error;
console.log("Sensor is " + (touchInfo.lastPressed ? greenANSI + "PRESSED" : redANSI + "RELEASED") + resetANSI);
},
function(userData) {
var isPressed = touchSensor.isPressed;
var changed = isPressed != userData.lastPressed;

userData.lastPressed = isPressed;
return changed;
}, false, { lastPressed: false });

console.log("Press the touch sensor to trigger the press event.");
10 changes: 3 additions & 7 deletions examples/run-specific-motor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ if(!motor.connected) {
process.exit(1);
}

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

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

// Prevent Node from exiting until motor is done
var cancellationToken = setInterval(function() {
if(motor.state.indexOf("running") == -1)
if(!motor.isRunning)
clearInterval(cancellationToken);
}, 10);
}, 200);
49 changes: 0 additions & 49 deletions examples/test-battery-led.js

This file was deleted.

14 changes: 6 additions & 8 deletions examples/test-motor-sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ var motor = new ev3dev.Motor();
if (!motor.connected)
console.log("No motor could be found. Are you sure that one is connected?");

console.log(' Port: ' + motor.portName);
console.log(' Port: ' + motor.address);
console.log(' Driver: ' + motor.driverName);
console.log(' Available commands: ' + motor.commands);

console.log('Sending motor command...');

console.log('Setting motor properties...');
motor.rampUpSp = 100;
motor.rampDownSp = 100;
motor.timeSp = 1000;
motor.dutyCycleSp = 50;
console.log('Available commands: ' + motor.commands);
console.log('Sending motor command...');
motor.command = 'run-timed';
motor.runForTime(1000, motor.maxSpeed / 2, motor.stopActionValues.brake);

do {
console.log("Motor speed: " + motor.speed);
Expand All @@ -44,7 +42,7 @@ var sensor = new ev3dev.Sensor();
if (!sensor.connected)
console.log("No sensor could be found. Are you sure that one is connected?");

console.log(' Port: ' + sensor.portName);
console.log(' Port: ' + sensor.address);
console.log(' Driver: ' + sensor.driverName);

console.log('Reading all sensor values...');
Expand Down
5 changes: 1 addition & 4 deletions examples/touch-sensor-motor-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ if(!motor.connected) {
process.exit(1);
}

motor.speedRegulationEnabled = 'off';

console.log("Connected to touch sensor at address " + touchSensor.address + " and tacho motor at address " + motor.address);
console.log("Press the touch sensor to spin the motor.");

setInterval(function() {
motor.dutyCycleSp = 100 * touchSensor.getValue(0);
motor.command = 'run-forever';
motor.start(motor.maxSpeed * touchSensor.getValue(0), motor.stopActionValues.hold);
}, 10);
22 changes: 8 additions & 14 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-typescript');
grunt.loadNpmTasks('grunt-ts');
grunt.loadNpmTasks('grunt-typedoc');

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
typescript: {
ts: {
main: {
src: "index.ts",
src: "src/index.ts",
dest: 'bin/',
options: {
target: 'es5',
Expand All @@ -19,24 +18,19 @@ module.exports = function (grunt) {
},
typedoc: {
doc: {
src: "index.ts",
src: "src/index.ts",
options: {
out: './docs',
name: 'ev3dev-lang for Node.JS',
name: 'ev3dev-lang for Node.js',
target: 'es5',
disableOutputCheck: '',
module: 'commonjs'
}
}
},
watch: {
files: __dirname + '/*.ts',
tasks: ['shell']
}
});

grunt.registerTask('default', ['typescript', 'typedoc']);
grunt.registerTask('watch', ['watch']); //Has issues, shouldn't use
grunt.registerTask('tsc', ['typescript']);
grunt.registerTask('doc', ['typescript', 'typedoc']);
grunt.registerTask('default', ['ts', 'typedoc']);
grunt.registerTask('tsc', ['ts']);
grunt.registerTask('doc', ['ts', 'typedoc']);
}
Loading

0 comments on commit fcc96be

Please sign in to comment.