basic ports view (#115)

* basic ports view

* slight adjustement of rendering
This commit is contained in:
Peli de Halleux 2017-12-19 14:26:57 -08:00 committed by GitHub
parent eac3e183c3
commit d78d9c8686
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 6 deletions

View File

@ -32,6 +32,7 @@
"brick.lightPattern": "Pattern block.", "brick.lightPattern": "Pattern block.",
"brick.lightPattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green", "brick.lightPattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green",
"brick.print": "Show text on the screen.", "brick.print": "Show text on the screen.",
"brick.printPorts": "Prints the port states on the screen",
"brick.print|param|text": "the text to print on the screen, eg: \"Hello world\"", "brick.print|param|text": "the text to print on the screen, eg: \"Hello world\"",
"brick.print|param|x": "the starting position's x coordinate, eg: 0", "brick.print|param|x": "the starting position's x coordinate, eg: 0",
"brick.print|param|y": "the starting position's x coordinate, eg: 0", "brick.print|param|y": "the starting position's x coordinate, eg: 0",

View File

@ -36,6 +36,7 @@
"brick.buttonUp|block": "up", "brick.buttonUp|block": "up",
"brick.clearScreen|block": "`icons.brickDisplay` clear screen", "brick.clearScreen|block": "`icons.brickDisplay` clear screen",
"brick.lightPattern|block": "%pattern", "brick.lightPattern|block": "%pattern",
"brick.printPorts|block": "print ports",
"brick.print|block": "`icons.brickDisplay` print %text| at x: %x| y: %y", "brick.print|block": "`icons.brickDisplay` print %text| at x: %x| y: %y",
"brick.setPixel|block": "`icons.brickDisplay` set pixel %on| at x: %x| y: %y", "brick.setPixel|block": "`icons.brickDisplay` set pixel %on| at x: %x| y: %y",
"brick.setStatusLight|block": "set `icons.brickButtons` to %pattern=led_pattern", "brick.setStatusLight|block": "set `icons.brickButtons` to %pattern=led_pattern",

View File

@ -59,7 +59,6 @@ namespace console {
namespace console.screen { namespace console.screen {
const maxLines = 100; const maxLines = 100;
const screenLines = 8; const screenLines = 8;
const lineHeight = 12;
let lines: string[]; let lines: string[];
let scrollPosition = 0; let scrollPosition = 0;
@ -78,7 +77,7 @@ namespace console.screen {
for (let i = 0; i < screenLines; ++i) { for (let i = 0; i < screenLines; ++i) {
const line = lines[i + scrollPosition]; const line = lines[i + scrollPosition];
if (line) if (line)
brick.print(line, 0, 4 + i * lineHeight) brick.print(line, 0, 4 + i * brick.LINE_HEIGHT)
} }
} }

View File

@ -74,6 +74,11 @@ namespace sensors.internal {
} }
export function getActiveSensors(): Sensor[] {
init();
return sensorInfos.filter(si => si.sensor && si.sensor.isActive()).map(si => si.sensor);
}
function readUartInfo(port: number, mode: number) { function readUartInfo(port: number, mode: number) {
let buf = output.createBuffer(UartCtlOff.Size) let buf = output.createBuffer(UartCtlOff.Size)
buf[UartCtlOff.Port] = port buf[UartCtlOff.Port] = port

View File

@ -548,7 +548,7 @@ namespace motors {
return 0 return 0
} }
interface MotorData { export interface MotorData {
actualSpeed: number; // -100..+100 actualSpeed: number; // -100..+100
tachoCount: number; tachoCount: number;
count: number; count: number;
@ -557,7 +557,7 @@ namespace motors {
// only a single output at a time // only a single output at a time
function getMotorData(out: Output): MotorData { function getMotorData(out: Output): MotorData {
init() init()
let buf = motorMM.slice(outOffset(out), MotorDataOff.Size) const buf = motorMM.slice(outOffset(out), MotorDataOff.Size)
return { return {
actualSpeed: buf.getNumber(NumberFormat.Int8LE, MotorDataOff.Speed), actualSpeed: buf.getNumber(NumberFormat.Int8LE, MotorDataOff.Speed),
tachoCount: buf.getNumber(NumberFormat.Int32LE, MotorDataOff.TachoCounts), tachoCount: buf.getNumber(NumberFormat.Int32LE, MotorDataOff.TachoCounts),
@ -565,6 +565,11 @@ namespace motors {
} }
} }
export function getAllMotorData(): MotorData[] {
init();
return [Output.A, Output.B, Output.C, Output.D].map(out => getMotorData(out));
}
interface SyncOptions { interface SyncOptions {
useSteps?: boolean; useSteps?: boolean;
speed: number; speed: number;

View File

@ -1,4 +1,6 @@
namespace brick { namespace brick {
export const LINE_HEIGHT = 12;
//% shim=screen::_setPixel //% shim=screen::_setPixel
function _setPixel(p0: uint32, p1: uint32, mode: Draw): void { } function _setPixel(p0: uint32, p1: uint32, mode: Draw): void { }
@ -208,5 +210,29 @@ namespace brick {
setLineCore(x, x1, y, mode); setLineCore(x, x1, y, mode);
} }
/**
* Prints the port states on the screen
*/
//% blockId=brickPrintPorts block="print ports"
//% weight=1 group="Screen"
export function printPorts() {
clearScreen();
// motors
const datas = motors.getAllMotorData();
for(let i = 0; i < datas.length; ++i) {
const x = i * 52;
const data = datas[i];
print(`${data.actualSpeed}%`, x, brick.LINE_HEIGHT)
print(`${data.count}>`, x, 2 * brick.LINE_HEIGHT)
}
// sensors
const sis = sensors.internal.getActiveSensors();
for(let i =0; i < sis.length; ++i) {
const si = sis[i];
const x = (si.port() - 1) * 52;
print(`${si._query()}`, x, 9 * brick.LINE_HEIGHT)
}
}
} }

View File

@ -25,7 +25,7 @@ namespace sensors {
} }
_query(): number { _query(): number {
return (this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff) * 0.1; // range is 0..2550, in 0.1 cm increments. return ((this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff) / 10) >> 0; // range is 0..2550, in 0.1 cm increments.
} }
_update(prev: number, curr: number) { _update(prev: number, curr: number) {
@ -80,7 +80,7 @@ namespace sensors {
distance(): number { distance(): number {
// it supposedly also has an inch mode, but we stick to cm // it supposedly also has an inch mode, but we stick to cm
this._setMode(0) this._setMode(0)
return (this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff) * 0.1; // range is 0..2550, in 0.1 cm increments. return this._query();
} }
} }