2018-01-05 06:50:13 +01:00
|
|
|
|
2019-09-04 21:56:45 +02:00
|
|
|
const enum BatteryProperty {
|
2019-09-06 15:22:12 +02:00
|
|
|
//% block="level (%)"
|
2019-09-04 21:56:45 +02:00
|
|
|
Level,
|
|
|
|
//% block="current (I)"
|
|
|
|
Current,
|
|
|
|
//% block="voltage (V)"
|
|
|
|
Voltage
|
|
|
|
}
|
|
|
|
|
2018-01-05 06:50:13 +01:00
|
|
|
namespace brick {
|
|
|
|
/**
|
|
|
|
* Returns the current battery level
|
|
|
|
*/
|
|
|
|
//% blockId=brickBatteryLevel block="battery level"
|
2019-09-04 21:56:45 +02:00
|
|
|
//% group="Battery"
|
2018-01-31 05:58:18 +01:00
|
|
|
//% help=brick/battery-level
|
2019-09-04 21:56:45 +02:00
|
|
|
//% deprecated blockHidden=1
|
2018-01-05 06:50:13 +01:00
|
|
|
export function batteryLevel(): number {
|
|
|
|
const info = sensors.internal.getBatteryInfo();
|
2019-09-04 21:56:45 +02:00
|
|
|
return info.level;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns information about the battery
|
|
|
|
*/
|
|
|
|
//% blockId=brickBatteryProperty block="battery %property"
|
|
|
|
//% group="Battery"
|
|
|
|
//% help=brick/battery-property
|
|
|
|
export function batteryInfo(property: BatteryProperty): number {
|
|
|
|
const info = sensors.internal.getBatteryInfo();
|
|
|
|
switch(property) {
|
|
|
|
case BatteryProperty.Level: return info.level;
|
|
|
|
case BatteryProperty.Current: return info.Ibatt;
|
|
|
|
case BatteryProperty.Voltage: return info.Vbatt;
|
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-05 06:50:13 +01:00
|
|
|
}
|
|
|
|
}
|