background show ports (#924)

* background show ports

* render once at least

* better rendering

* bumped up scale
This commit is contained in:
Peli de Halleux 2019-09-27 16:45:57 -07:00 committed by GitHub
parent 0285711954
commit a0e133864a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,6 +26,7 @@ namespace brick {
None, None,
ShowLines, ShowLines,
Image, Image,
Ports,
Custom Custom
} }
let screenMode = ScreenMode.None; let screenMode = ScreenMode.None;
@ -124,15 +125,30 @@ namespace brick {
//% help=brick/show-ports blockGap=8 //% help=brick/show-ports blockGap=8
//% weight=10 group="Screen" //% weight=10 group="Screen"
export function showPorts() { export function showPorts() {
screenMode = ScreenMode.Custom; if (screenMode == ScreenMode.Ports) return;
screenMode = ScreenMode.Ports;
renderPorts();
control.runInParallel(function() {
while(screenMode == ScreenMode.Ports) {
renderPorts();
pause(50);
}
})
}
function renderPorts() {
const col = 44; const col = 44;
const lineHeight8 = image.font8.charHeight + 2; const lineHeight8 = image.font8.charHeight + 2;
clearScreen(); clearScreen();
function scale(x: number) { function scale(x: number) {
if (Math.abs(x) > 1000) return Math.round(x / 100) / 10 + "k"; if (Math.abs(x) >= 5000) {
return ("" + (x >> 0)); const k = Math.floor(x / 1000);
const r = Math.round((x - 1000 * k) / 100);
return `${k}.${r}k`
}
return ("" + (x || 0));
} }
// motors // motors
@ -143,7 +159,7 @@ namespace brick {
const x = i * col; const x = i * col;
screen.print("ABCD"[i], x + 2, 1 * lineHeight8, 1, image.font8) screen.print("ABCD"[i], x + 2, 1 * lineHeight8, 1, image.font8)
screen.print(`${scale(data.actualSpeed)}%`, x + 2, 3 * lineHeight8, 1, image.font8) screen.print(`${scale(data.actualSpeed)}%`, x + 2, 3 * lineHeight8, 1, image.font8)
screen.print(`${scale(data.count)}>`, x + 2, 4 * lineHeight8, 1, image.font5) screen.print(`${scale(data.count)}>`, x + 2, 4 * lineHeight8, 1, image.font8)
} }
screen.drawLine(0, 5 * lineHeight8, screen.width, 5 * lineHeight8, 1); screen.drawLine(0, 5 * lineHeight8, screen.width, 5 * lineHeight8, 1);