Skip to content

Commit

Permalink
iotjs: Port to alt runtime using async-lite
Browse files Browse the repository at this point in the history
i2c is not needed because native I2C module will be used

Usage:

```
git clone https://github.com/rzr/async-lite iotjs_modules/async
iotjs test
{
  "pressure": 99406.04496626806,
  "temperature": 22.5
}
```

Forwarded: dbridges#7
Change-Id: I97d4248d87f59cd9468dc7fb90c1f2c04dd1d55c
Signed-off-by: Philippe Coval <[email protected]>
  • Loading branch information
rzr committed Nov 9, 2018
1 parent 9621e60 commit 891be0d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion bmp085-sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,25 @@ module.exports = function BMP085(options) {
units: 'metric'
};
options.address = options.address || 0x77;
var wire = new i2c(options.address);
var wire;
if (process.iotjs) {
options.bus = options.bus || 1;
options.device = options.device || '/dev/i2c-1';
wire = i2c.openSync(options);
wire.writeBytes = function(offset, bytes, callback) {
var bytes = [offset].concat(bytes);
this.writeSync(bytes);
callback && callback(null);
}
wire.readBytes = function(offset, len, callback) {
this.writeSync([offset]);
this.read(len, function(err, res) {
callback && callback(err, res);
});
}
} else {
wire = new i2c(options.address);
}
var cal = {};

var BMP085_CONTROL_REGISTER = 0xF4;
Expand Down

0 comments on commit 891be0d

Please sign in to comment.