basic reading of battery level (#182)
This commit is contained in:
parent
0db6987ee5
commit
1e460eef9e
@ -21,6 +21,7 @@
|
|||||||
"brick.Button.pauseUntil": "Waits until the event is raised",
|
"brick.Button.pauseUntil": "Waits until the event is raised",
|
||||||
"brick.Button.pauseUntil|param|ev": "the event to wait for",
|
"brick.Button.pauseUntil|param|ev": "the event to wait for",
|
||||||
"brick.Button.wasPressed": "See if the button was pressed again since the last time you checked.",
|
"brick.Button.wasPressed": "See if the button was pressed again since the last time you checked.",
|
||||||
|
"brick.batteryLevel": "Returns the current battery level",
|
||||||
"brick.buttonDown": "Down button on the EV3 Brick.",
|
"brick.buttonDown": "Down button on the EV3 Brick.",
|
||||||
"brick.buttonEnter": "Enter button on the EV3 Brick.",
|
"brick.buttonEnter": "Enter button on the EV3 Brick.",
|
||||||
"brick.buttonLeft": "Left button on the EV3 Brick.",
|
"brick.buttonLeft": "Left button on the EV3 Brick.",
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
"brick.Button.onEvent|block": "on %button|%event",
|
"brick.Button.onEvent|block": "on %button|%event",
|
||||||
"brick.Button.pauseUntil|block": "pause until %button|%event",
|
"brick.Button.pauseUntil|block": "pause until %button|%event",
|
||||||
"brick.Button.wasPressed|block": "%button|was pressed",
|
"brick.Button.wasPressed|block": "%button|was pressed",
|
||||||
|
"brick.batteryLevel|block": "battery level",
|
||||||
"brick.buttonDown|block": "down",
|
"brick.buttonDown|block": "down",
|
||||||
"brick.buttonEnter|block": "enter",
|
"brick.buttonEnter|block": "enter",
|
||||||
"brick.buttonLeft|block": "left",
|
"brick.buttonLeft|block": "left",
|
||||||
@ -89,6 +90,7 @@
|
|||||||
"{id:group}Buttons": "Buttons",
|
"{id:group}Buttons": "Buttons",
|
||||||
"{id:group}Chassis": "Chassis",
|
"{id:group}Chassis": "Chassis",
|
||||||
"{id:group}Light": "Light",
|
"{id:group}Light": "Light",
|
||||||
|
"{id:group}More": "More",
|
||||||
"{id:group}Motion": "Motion",
|
"{id:group}Motion": "Motion",
|
||||||
"{id:group}Screen": "Screen",
|
"{id:group}Screen": "Screen",
|
||||||
"{id:group}Sensors": "Sensors"
|
"{id:group}Sensors": "Sensors"
|
||||||
|
12
libs/core/battery.ts
Normal file
12
libs/core/battery.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
namespace brick {
|
||||||
|
/**
|
||||||
|
* Returns the current battery level
|
||||||
|
*/
|
||||||
|
//% blockId=brickBatteryLevel block="battery level"
|
||||||
|
//% group="More"
|
||||||
|
export function batteryLevel(): number {
|
||||||
|
const info = sensors.internal.getBatteryInfo();
|
||||||
|
return info.current;
|
||||||
|
}
|
||||||
|
}
|
@ -89,6 +89,14 @@ namespace sensors.internal {
|
|||||||
//serial.writeLine("UART " + port + " / " + mode + " - " + info)
|
//serial.writeLine("UART " + port + " / " + mode + " - " + info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getBatteryInfo(): { temp: number; current: number } {
|
||||||
|
init();
|
||||||
|
return {
|
||||||
|
temp: analogMM.getNumber(NumberFormat.Int16LE, AnalogOff.BatteryTemp),
|
||||||
|
current: analogMM.getNumber(NumberFormat.Int16LE, AnalogOff.BatteryCurrent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function detectDevices() {
|
function detectDevices() {
|
||||||
let conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS)
|
let conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS)
|
||||||
let numChanged = 0
|
let numChanged = 0
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
"png.cpp",
|
"png.cpp",
|
||||||
"screen.cpp",
|
"screen.cpp",
|
||||||
"screen.ts",
|
"screen.ts",
|
||||||
|
"battery.ts",
|
||||||
"output.cpp",
|
"output.cpp",
|
||||||
"output.ts",
|
"output.ts",
|
||||||
"core.ts",
|
"core.ts",
|
||||||
|
@ -24,13 +24,14 @@ namespace pxsim {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class EV3AnalogState {
|
export class EV3AnalogState {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
let data = new Uint8Array(5172)
|
let data = new Uint8Array(5172)
|
||||||
MMapMethods.register("/dev/lms_analog", {
|
MMapMethods.register("/dev/lms_analog", {
|
||||||
data,
|
data,
|
||||||
beforeMemRead: () => {
|
beforeMemRead: () => {
|
||||||
//console.log("analog before read");
|
//console.log("analog before read");
|
||||||
|
data[AnalogOff.BatteryTemp] = 21; // TODO simulate this
|
||||||
|
data[AnalogOff.BatteryCurrent] = 100; // TODO simulate this
|
||||||
const inputNodes = ev3board().getInputNodes();
|
const inputNodes = ev3board().getInputNodes();
|
||||||
for (let port = 0; port < DAL.NUM_INPUTS; port++) {
|
for (let port = 0; port < DAL.NUM_INPUTS; port++) {
|
||||||
const node = inputNodes[port];
|
const node = inputNodes[port];
|
||||||
|
Loading…
Reference in New Issue
Block a user