Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to johnny-five v0.11.1 #8

Merged
merged 20 commits into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,10 @@ os:
- osx
language: node_js
node_js:
- "0.10"
- "0.12"
- "4"
- "5"
- "6"
- 4
- 6
sudo: false
compiler: clang
before_install:
- npm install -g npm@3
- npm install -g grunt-cli
install: npm install
before_script:
- grunt test-examples
notifications:
webhooks:
urls:
Expand All @@ -26,5 +17,16 @@ notifications:
env:
- NO_SERIALPORT_INSTALL=1

before_install:
- npm install -g npm@3
- npm install -g grunt-cli

install: npm install

before_script:
- grunt test-examples

script: npm run test-cover

after_success:
- npm run test-cover && npm run coveralls
- npm run coveralls
3 changes: 0 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ clone_depth: 10

environment:
matrix:
- nodejs_version: 0.10
- nodejs_version: 0.12
- nodejs_version: 4
- nodejs_version: 5
- nodejs_version: 6

install:
Expand Down
21 changes: 18 additions & 3 deletions lib/imu.js
Original file line number Diff line number Diff line change
Expand Up @@ -1531,12 +1531,13 @@ var Drivers = {
CONFIG: 0xF5,
MEASURE_H: 0xF2,
MEASURE_TP: 0xF4,
PRESSURE: 0xF7,
// 0xF7, 0xF8, 0xF9
// MSB, LSB, XLSB
PRESSURE: 0xF7,
TEMPERATURE: 0xFA,
// 0xFA, 0xFB, 0xFC
// MSB, LSB, XLSB
TEMPERATURE: 0xFA,
HUMIDITY: 0xFD,
// 0xFD, 0xFE
// MSB, LSB
RESET: 0xE0,
Expand Down Expand Up @@ -1690,7 +1691,7 @@ var Drivers = {
io.i2cWrite(address, this.REGISTER.MEASURE_H, 0x05);

/*
Table 22: Register 0xF2 "ctrl_meas"
Table 22: Register 0xF4 "ctrl_meas"

Bit 7, 6, 5
Controls oversampling of temperature data
Expand Down Expand Up @@ -1746,7 +1747,21 @@ var Drivers = {
// 3.3.2 Temperature measurement
//

var standby = Date.now();

io.i2cRead(address, this.REGISTER.PRESSURE, 8, function(data) {
//
// Response time to complete 63% of a step is 1 second.
// Don't emit a reading until a complete step has occurred.
// This will be ~1587ms
// (1 / 63 * 100) * 1000 = 1587.3015873015872ms
// if ((standby + 1587) > Date.now()) {
if (!process.env.IS_TEST_MODE) {
if ((standby + 1000) > Date.now()) {
return;
}
}

var compensated = 0;

// Page 45
Expand Down
41 changes: 34 additions & 7 deletions lib/lcd.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,29 @@ var RGB = require("./led/rgb");

var priv = new Map();

/**
* This atrocity is unfortunately necessary.
* If any other approach can be found, patches
* will gratefully be accepted.
*/
function sleepus(usDelay) {
var startTime = process.hrtime();
var deltaTime;
var usWaited = 0;

while (usDelay > usWaited) {
deltaTime = process.hrtime(startTime);
usWaited = (deltaTime[0] * 1E9 + deltaTime[1]) / 1000;
}
}

/**
* This atrocity is unfortunately necessary.
* If any other approach can be found, patches
* will gratefully be accepted.
*/
function sleep(ms) {
var start = Date.now();
// Wait 1ms longer than requested. For further information see:
// https://github.com/rwaldron/johnny-five/issues/326#issuecomment-230125813
while (Date.now() < start + ms + 1) {}
sleepus(ms * 1000);
}


Expand Down Expand Up @@ -809,9 +822,23 @@ LCD.prototype.send = function(value) {
pin++;
}

["LOW", "HIGH", "LOW"].forEach(function(val) {
this.io.digitalWrite(this.pins.en, this.io[val]);
}, this);
// At VCC = 3.3V, the minimum enable pulse width is specified as 450
// nanoseconds on page 49 of the HD44780 datasheet.
// https://www.sparkfun.com/datasheets/LCD/HD44780.pdf
// We therefore wait for 1 microsecond here to ensure that fast IO plugins
// like Pi-IO generate an enable pulse that's wide enough.
this.io.digitalWrite(this.pins.en, this.io.LOW);
this.io.digitalWrite(this.pins.en, this.io.HIGH);
sleepus(1);
this.io.digitalWrite(this.pins.en, this.io.LOW);

// The execution time for the vast majority of instructions is at least
// 37 microseconds. See datasheet pages 24 and 25.
// https://www.sparkfun.com/datasheets/LCD/HD44780.pdf
// It's important to wait 37 microseconds here to prevent fast IO plugins
// like Pi-IO from executing the next instruction before the current
// instruction has completed.
sleepus(37);

return this;
};
Expand Down
12 changes: 6 additions & 6 deletions lib/light.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ var Controllers = {
];

// Gain and Tint defaults;
var gain = GAIN_1X;
var TintIndex = 2;
var gain = GAIN_16X;
var TintIndex = 0;
var Tint = TintMs[TintIndex];
var lux = 0;

Expand Down Expand Up @@ -313,17 +313,17 @@ var Controllers = {

// Page 26
// CalculateLux(...)
var scale = chScales[TintIndex];
var chScale = chScales[TintIndex];


if (!gain) {
scale = scale << 4;
chScale = chScale << 4;
}

// Page 27
// CalculateLux(...)
ch0 = (ch0 * scale) >> 10;
ch1 = (ch1 * scale) >> 10;
ch0 = (ch0 * chScale) >> 10;
ch1 = (ch1 * chScale) >> 10;

var ratio1 = 0;

Expand Down
8 changes: 8 additions & 0 deletions lib/mixins/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ function Collection(numsOrObjects) {
}
}

if (typeof Symbol !== "undefined" && Symbol.iterator) {
Collection.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
}

Collection.prototype.add = function() {
var length = this.length;
var aLen = arguments.length;
Expand Down Expand Up @@ -230,6 +234,10 @@ util.inherits(Collection.Emitter, Collection);

Object.assign(Collection.Emitter.prototype, Emitter.prototype);

if (typeof Symbol !== "undefined" && Symbol.iterator) {
Collection.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
}

Collection.Emitter.prototype.add = function() {
var inputs = Array.from(arguments);

Expand Down
102 changes: 82 additions & 20 deletions lib/thermometer.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,6 @@ function Thermometer(opts) {
this, opts = Board.Options(opts)
);

var freq = opts.freq || 25;

// Analog Reference Voltage (default to board.io.aref || 5)
this.aref = opts.aref || this.io.aref || 5;

Expand All @@ -943,7 +941,13 @@ function Thermometer(opts) {
controller = Controllers.ANALOG;
}

priv.set(this, {});
var state = {
enabled: typeof opts.enabled === "undefined" ? true : opts.enabled,
intervalId: null,
freq: opts.freq || 25,
previousFreq: opts.freq || 25,
};
priv.set(this, state);

Board.Controller.call(this, controller, opts);

Expand All @@ -953,6 +957,25 @@ function Thermometer(opts) {
};
}

// TODO: Move this out of the constructor
var eventProcessing = function() {
if (raw == null) {
return;
}

var data = {};
data.C = data.celsius = this.celsius;
data.F = data.fahrenheit = this.fahrenheit;
data.K = data.kelvin = this.kelvin;

this.emit("data", data);

if (this.celsius !== last) {
last = this.celsius;
this.emit("change", data);
}
}.bind(this);

var descriptors = {
celsius: {
get: function() {
Expand All @@ -968,7 +991,22 @@ function Thermometer(opts) {
get: function() {
return toFixed(this.celsius + CELSIUS_TO_KELVIN, 2);
}
}
},
freq: {
get: function() {
return state.freq;
},
set: function(newFreq) {
state.freq = newFreq;
if (state.intervalId) {
clearInterval(state.intervalId);
}

if (state.freq !== null) {
state.intervalId = setInterval(eventProcessing, newFreq);
}
}
},
};
// Convenience aliases
descriptors.C = descriptors.celsius;
Expand All @@ -983,26 +1021,50 @@ function Thermometer(opts) {
});
}

setInterval(function() {
if (raw == null) {
return;
}
// Set the freq property only after the get and set functions are defined
// and only if the sensor is not `enabled: false`
if (state.enabled) {
this.freq = state.freq;
}
}

var data = {};
data.C = data.celsius = this.celsius;
data.F = data.fahrenheit = this.fahrenheit;
data.K = data.kelvin = this.kelvin;
util.inherits(Thermometer, Emitter);

this.emit("data", data);
/**
* enable Enable a disabled thermometer.
*
* @return {Object} instance
*
*/
Thermometer.prototype.enable = function() {
var state = priv.get(this);

/* istanbul ignore else */
if (!state.enabled) {
this.freq = state.freq || state.previousFreq;
}

if (this.celsius !== last) {
last = this.celsius;
this.emit("change", data);
}
}.bind(this), freq);
}
return this;
};

util.inherits(Thermometer, Emitter);
/**
* disable Disable an enabled thermometer.
*
* @return {Object} instance
*
*/
Thermometer.prototype.disable = function() {
var state = priv.get(this);

/* istanbul ignore else */
if (state.enabled) {
state.enabled = false;
state.previousFreq = state.freq;
this.freq = null;
}

return this;
};

Thermometer.Drivers = Drivers;

Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,20 +275,20 @@
"serialport": "^4.0.0"
},
"devDependencies": {
"async": "~0.9.0",
"async": "^2.4.1",
"copy-paste": "^1.3.0",
"coveralls": "^2.11.9",
"grunt": "~0.4.5",
"grunt-cli": "~0.1.13",
"grunt-contrib-jshint": "~1.0.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-watch": "~0.6.1",
"grunt-jsbeautifier": "~0.2.10",
"grunt-jscs": "~2.3.0",
"coveralls": "^2.13.1",
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-nodeunit": "^1.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-jsbeautifier": "^0.2.13",
"grunt-jscs": "^3.0.1",
"keypress": "latest",
"mock-firmata": "latest",
"nyc": "^10.2.0",
"optimist": "~0.6.1",
"nyc": "^11.0.1",
"optimist": "^0.6.1",
"shelljs": "^0.3.0",
"sinon": "~1.10.2"
},
Expand Down
Loading