Skip to content

Commit

Permalink
iotjs: fallback to array
Browse files Browse the repository at this point in the history
IoT.js is an alternate javascript runtime
powered by Jerryscript engine
(designed for contrainted devices).

Buffer/Arrays objects have limited API too,
so this extra test will make the code working on both runtime.

Change-Id: I73861a3fd47047fd5c8f9d3ab24cb6f46c4b37b4
Signed-off-by: Philippe Coval <p.coval@samsung.com>
  • Loading branch information
rzr committed Aug 23, 2018
1 parent 2aa72da commit 5f1b37d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions bh1750.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ BH1750.prototype.readLight = function (cb) {
console.error("error: I/O failure on BH1750 - command: ", self.options.command);
return cb(err, null);
}
var hi = res.readUInt8(0);
var lo = res.readUInt8(1);
var hi = res[0];
var lo = res[1];
if (Buffer.isBuffer(res)) {
hi = res.readUInt8(0);
lo = res.readUInt8(1);
}

var lux = ((hi << 8) + lo)/1.2;
if (self.options.command === 0x11) {
lux = lux/2;
Expand Down

0 comments on commit 5f1b37d

Please sign in to comment.