-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpower.ts
82 lines (72 loc) · 1.76 KB
/
power.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
81
82
/*******************************************************************************
* Functions for edu:bit power supply.
*
* Company: Cytron Technologies Sdn Bhd
* Website: http://www.cytron.io
* Email: [email protected]
*******************************************************************************/
/**
* Blocks for power supply.
*/
//% weight=9 color=#ff8000 icon="\uf011" block="Power"
namespace edubitPower {
/**
* Return true if power is on.
*/
//% weight=20
//% blockGap=8
//% blockId=edubit_is_power_on
//% block="power on"
//% blockHidden=true
export function isPowerOn(): boolean {
if (edubit.i2cRead(REG_ADD_PWR_STATE) != 0) {
return true;
}
else {
return false;
}
}
/**
* Return true if low batt.
*/
//% weight=19
//% blockGap=8
//% blockId=edubit_is_low_batt
//% block="low batt"
//% blockHidden=true
export function isLowBatt(): boolean {
if (edubit.i2cRead(REG_ADD_LB_STATE) != 0) {
return true;
}
else {
return false;
}
}
/**
* Return true if overvoltage.
*/
//% weight=18
//% blockGap=40
//% blockId=edubit_is_overvoltage
//% block="overvoltage"
//% blockHidden=true
export function isOvervoltage(): boolean {
if (edubit.i2cRead(REG_ADD_OV_STATE) != 0) {
return true;
}
else {
return false;
}
}
/**
* Return power input voltage.
*/
//% weight=17
//% blockGap=8
//% blockId=edubit_read_vin
//% block="power input voltage"
//% blockHidden=true
export function readVin(): number {
return (edubit.i2cRead(REG_ADD_VIN) / 10);
}
}