-
Notifications
You must be signed in to change notification settings - Fork 1
/
sg35.ts
80 lines (63 loc) · 1.59 KB
/
sg35.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//%color=#444444 icon="\uf07b"
namespace SG35 {
let initialized = false
let onReceivedDataHandler: (pm1: number, pm25: number, pm10: number) => void;
//%shim=sg35::begin
function begin(): void {
return
}
//%shim=sg35::read
export function read(): boolean {
return true
}
//%shim=sg35::pm1
export function pm1(): number {
return 1
}
//%shim=sg35::pm25
export function pm25(): number {
return 1
}
//%shim=sg35::pm10
export function pm10(): number {
return 1
}
//%shim=sg35::turnPowerSavingModeOn
//%block="SG35 sleep"
export function sleepSG35(): void{
return;
}
//%shim=sg35::wakeUpSG35
//%block="SG35 wake up"
export function wakeSG35(): void{
return;
}
//%shim=sg35::onDataReceived
function onDataReceived(body: Action): void {
return;
}
function init() {
startParallel(function(){
while(true)
{
let rcv = read()
if(rcv)
{
onReceivedDataHandler(pm1(), pm25(), pm10())
}
basic.pause(1)
}
})
}
//% block="SG35 on received "
//% draggableParameters=reporter
export function onReceivedData(cb: (receivedPM1: number,receivedPM25: number,receivedPM10: number) => void): void {
init()
onReceivedDataHandler = cb
}
//% shim=parall::startParallel
export function startParallel(u: () => void) {
return 1;
}
begin()
}