1/* Please insert below lines to app.json file if you want to enable lm75:
2
3      "I2C0": {
4        "type": "I2C",
5        "port": 0,
6        "addrWidth": 7,
7        "freq": 400000,
8        "mode": "master",
9        "devAddr": 72
10      },
11
12*/
13
14var i2c = require('i2c');
15var lm75 =
16
17function lm75Init()
18{
19    lm75 = i2c.open({
20        id: 'I2C0'
21    });
22}
23
24function lm75tmpGet()
25{
26    var sig = 1;
27    var temp;
28    var regval = lm75.readMem(0x00, 2);
29    var tempAll = (regval[0] << 8) + regval[1];
30
31    if (regval[0] & 0x80 != 0) {
32        tempAll = ~(tempAll) + 1;
33        sig = -1;
34    }
35
36    tempAll = tempAll >> 5;
37    temp = tempAll * 0.125 * sig;
38
39    return temp;
40}
41
42module.exports = {
43    lm75Init,
44    lm75tmpGet
45}
46