pxt-ev3/libs/core/battery.ts

40 lines
1.0 KiB
TypeScript
Raw Normal View History

2018-01-05 06:50:13 +01:00
const enum BatteryProperty {
//% block="level (%)"
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"
//% group="Battery"
//% help=brick/battery-level
//% deprecated blockHidden=1
2018-01-05 06:50:13 +01:00
export function batteryLevel(): number {
const info = sensors.internal.getBatteryInfo();
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
}
}