Private
Public Access
2
0

JS examples: refactor for clarity and consistent style

Signed-off-by: Kassandra Perch <the@nodebotani.st>
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
This commit is contained in:
Kas Perch
2017-02-23 00:57:19 -06:00
committed by Alex Tereschenko
parent 43d9f6c400
commit 075a7b1225
12 changed files with 145 additions and 127 deletions

View File

@@ -24,29 +24,32 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var m = require('mraa'); //require mraa
"use strict";
x = new m.I2c(0)
x.address(0x77)
const mraa = require('mraa'); //require mraa
let i2cDevice = new mraa.I2c(0);
i2cDevice.address(0x77);
// initialise device
if (x.readReg(0xd0) != 0x55) {
console.log("error");
if (i2cDevice.readReg(0xd0) != 0x55) {
console.log("error");
}
// we want to read temperature so write 0x2e into control reg
x.writeReg(0xf4, 0x2e)
i2cDevice.writeReg(0xf4, 0x2e);
// read a 16bit reg, obviously it's uncalibrated so mostly a useless value :)
console.log(x.readWordReg(0xf6))
console.log(i2cDevice.readWordReg(0xf6));
// and we can do the same thing with the read()/write() calls if we wished
// thought I'd really not recommend it!
buf = new Buffer(2)
buf[0] = 0xf4
buf[1] = 0x2e
console.log(buf.toString('hex'))
x.write(buf)
let buf = new Buffer(2);
buf[0] = 0xf4;
buf[1] = 0x2e;
console.log(buf.toString('hex'));
i2cDevice.write(buf);
x.writeByte(0xf6)
d = x.read(2)
i2cDevice.writeByte(0xf6);
let result = i2cDevice.read(2);
console.log(result.toString('hex'));