-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.ts
47 lines (41 loc) · 1.13 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
enum TemperatureLocation {
//%block="Object"
Object,
//%block="Ambiant"
Ambiant
}
//%color=#F79532 icon="\uf2cb" block="MLX90614"
namespace MLX90614 {
const addr = 0x5A
const obTempAddr = 0x07
const amTempAddr = 0x06
function read16(reg: NumberFormat.UInt8BE): number {
pins.i2cWriteNumber(addr, reg, NumberFormat.UInt8BE, true);
let ret = pins.i2cReadNumber(addr, NumberFormat.UInt16LE, true);
//ret |= pins.i2cReadNumber(addr, NumberFormat.UInt16LE) << 8
return ret
}
function readTemp(reg: NumberFormat.UInt8BE): number {
let temp = read16(reg)
temp *= .02
temp -= 273.15
return temp
}
function objectTemp(): number{
return readTemp(obTempAddr)
}
function ambientTemp(): number{
return readTemp(amTempAddr)
}
//%block="Temperature %loc"
export function temperature(loc: TemperatureLocation): number{
switch (loc){
case 0:
return objectTemp();
case 1:
return ambientTemp();
default:
return 0;
}
}
}