pxt-ev3/libs/core/battery.ts
Peli de Halleux bc4b71e0d6
Pulling updates from master (#951)
* show ports on start

* don't run show ports automatically

* polarity in synched motor (#945)

* account for polarity

* more comments

* handle dual motor in runtime

* invert steer

* don't use firmware polarity

* add block to stop program (#943)

* add block to stop program

* renaming

* fix translation
2019-10-18 22:53:30 -07:00

41 lines
1.1 KiB
TypeScript

const enum BatteryProperty {
//% block="level (%)"
Level,
//% block="current (I)"
Current,
//% block="voltage (V)"
Voltage
}
namespace brick {
/**
* Returns the current battery level
*/
//% blockId=brickBatteryLevel block="battery level"
//% group="Battery"
//% help=brick/battery-level
//% deprecated blockHidden=1
export function batteryLevel(): number {
const info = sensors.internal.getBatteryInfo();
return info.level;
}
/**
* Returns information about the battery
*/
//% blockId=brickBatteryProperty block="battery %property"
//% group="Battery"
//% blockGap=8
//% 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;
}
}
}