From 5f1b37dfab15a9134361a8a22ae60f508c027061 Mon Sep 17 00:00:00 2001
From: Philippe Coval
Date: Mon, 20 Aug 2018 18:37:01 +0200
Subject: [PATCH] iotjs: fallback to array
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
---
bh1750.js | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/bh1750.js b/bh1750.js
index bd038f4..bf21be0 100644
--- a/bh1750.js
+++ b/bh1750.js
@@ -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;