-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
dstemp.ts
58 lines (52 loc) · 1.62 KB
/
dstemp.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
//% color=#0000FF
//% icon="\uf2c8"
//% block="DS Temp"
namespace dstemp {
//% whenUsed
let errorHandler:Action = null;
//% whenUsed
let errorObjectIdx : number = 0;
//% whenUsed
let errorPort : number = -1;
// TODO: Localization
const errorMsgs = [ "No Error", "Not Connected", "Start Error", "Read Timeout", "Conversion Failure"];
//% blockId="celsius" block="temperature (\u00B0\\C) on %pin|"
//% shim=dstemp::celsius
//% parts=dstemp trackArgs=0
export function celsius(pin: DigitalPin) : number {
return 32.6;
}
// Helper function
//% shim=dstemp::setErrorHandler
export function setErrorHandler(a: Action) {
errorHandler = a;
}
// Helper function
//% shim=dstemp::getErrorObjectIdx
export function getErrorObjectIdx() : number {
return errorObjectIdx;
}
// Helper function
//% shim=dstemp::getErrorPort
export function getErrorPort() : number {
return errorPort;
}
/**
* Set a handler for errors
* @param errCallback The error handler
*/
//% blockId="error" block="temperature sensor error"
//% draggableParameters="reporter" weight=0
export function sensorError(errCallback: (errorMessage: string, errorCode: number, port: number) => void) {
if(errCallback) {
errorHandler = () => {
let i = getErrorObjectIdx();
let p = getErrorPort();
errCallback(errorMsgs[i], i, p);
};
} else {
errorHandler = null;
}
setErrorHandler(errorHandler);
};
}