bringing back show ports (#377)
* bringing back show ports * added firmware links in docs * updated color rendering * better rendering of touch/ultra/ir * better data per sensor
This commit is contained in:
@ -96,6 +96,22 @@ namespace sensors {
|
||||
return 0
|
||||
}
|
||||
|
||||
_info(): string {
|
||||
switch (this.mode) {
|
||||
case ColorSensorMode.Color:
|
||||
return ["none",
|
||||
"black",
|
||||
"blue",
|
||||
"green",
|
||||
"yellow",
|
||||
"red",
|
||||
"white",
|
||||
"brown"][this._query()];
|
||||
default:
|
||||
return this._query().toString();
|
||||
}
|
||||
}
|
||||
|
||||
_update(prev: number, curr: number) {
|
||||
if (this.calibrating) return; // simply ignore data updates while calibrating
|
||||
if (this.mode == ColorSensorMode.Color)
|
||||
|
@ -177,6 +177,10 @@ namespace sensors.internal {
|
||||
return 0
|
||||
}
|
||||
|
||||
_info(): string {
|
||||
return this._query().toString();
|
||||
}
|
||||
|
||||
_update(prev: number, curr: number) {
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ namespace sensors {
|
||||
|
||||
const __remoteButtons: RemoteInfraredBeaconButton[] = [];
|
||||
function __irButton(id: InfraredRemoteButton): RemoteInfraredBeaconButton {
|
||||
for(let i = 0; i < __remoteButtons.length; ++i) {
|
||||
for (let i = 0; i < __remoteButtons.length; ++i) {
|
||||
if (__remoteButtons[i].position == id)
|
||||
return __remoteButtons[i];
|
||||
}
|
||||
@ -161,6 +161,14 @@ namespace sensors {
|
||||
return 0
|
||||
}
|
||||
|
||||
_info(): string {
|
||||
if (this.mode == InfraredSensorMode.RemoteControl)
|
||||
return "remote";
|
||||
else if (this.mode == InfraredSensorMode.Proximity)
|
||||
return `${this._query()}%`;
|
||||
return "";
|
||||
}
|
||||
|
||||
_update(prev: number, curr: number) {
|
||||
if (this.mode == InfraredSensorMode.RemoteControl) {
|
||||
for (let i = 0; i < __remoteButtons.length; ++i) {
|
||||
|
@ -9,9 +9,9 @@ let screen = image.create(DAL.LCD_WIDTH, DAL.LCD_HEIGHT)
|
||||
|
||||
namespace _screen_internal {
|
||||
//% shim=pxt::updateScreen
|
||||
function updateScreen(img: Image): void {}
|
||||
function updateScreen(img: Image): void { }
|
||||
//% shim=pxt::updateStats
|
||||
function updateStats(msg: string): void {}
|
||||
function updateStats(msg: string): void { }
|
||||
|
||||
control.setupScreenRefresh(() => updateScreen(screen))
|
||||
|
||||
@ -63,7 +63,7 @@ namespace brick {
|
||||
//% line.min=1 line.max=10
|
||||
export function showValue(name: string, value: number, line: number) {
|
||||
value = Math.round(value * 1000) / 1000;
|
||||
showString((name ? name + ": " : "") + value, line);
|
||||
showString((name ? name + ": " : "") + value, line);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,6 +78,43 @@ namespace brick {
|
||||
screen.drawImage(image, 0, 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the sensor and motor states attached to ports
|
||||
*/
|
||||
//% blockId=brickShowPorts block="show ports"
|
||||
//% help=brick/show-ports blockGap=8
|
||||
//% weight=10 group="Screen"
|
||||
export function showPorts() {
|
||||
const col = 44;
|
||||
clearScreen();
|
||||
|
||||
function scale(x: number) {
|
||||
if (Math.abs(x) > 1000) return Math.round(x / 100) / 10 + "k";
|
||||
return ("" + (x >> 0));
|
||||
}
|
||||
|
||||
// motors
|
||||
const datas = motors.getAllMotorData();
|
||||
for (let i = 0; i < datas.length; ++i) {
|
||||
const data = datas[i];
|
||||
if (!data.actualSpeed && !data.count) continue;
|
||||
const x = i * col;
|
||||
screen.print("ABCD"[i], x, brick.LINE_HEIGHT)
|
||||
screen.print(`${scale(data.actualSpeed)}%`, x, 2* brick.LINE_HEIGHT)
|
||||
screen.print(`${scale(data.count)}>`, x, 3 * 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) * col;
|
||||
const inf = si._info();
|
||||
screen.print(si.port() + "", x, 8 * brick.LINE_HEIGHT)
|
||||
screen.print(inf, x, 9 * brick.LINE_HEIGHT)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An image
|
||||
* @param image the image
|
||||
@ -96,7 +133,7 @@ namespace brick {
|
||||
*/
|
||||
//% blockId=screen_clear_screen block="clear screen"
|
||||
//% weight=90 group="Screen"
|
||||
//% help=brick/clear-screen
|
||||
//% help=brick/clear-screen weight=1
|
||||
export function clearScreen() {
|
||||
screen.fill(0)
|
||||
}
|
||||
|
@ -15,6 +15,10 @@ namespace sensors {
|
||||
return this._readPin6() > 2500 ? 1 : 0
|
||||
}
|
||||
|
||||
_info(): string {
|
||||
return this._query() ? "pres" : "rel";
|
||||
}
|
||||
|
||||
_update(prev: number, curr: number) {
|
||||
this.button._update(curr > 0)
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ namespace sensors {
|
||||
super(port)
|
||||
this.promixityThreshold = new sensors.ThresholdDetector(this.id(), 0, 255, 10, 100); // range is 0..255cm
|
||||
this.movementThreshold = 1;
|
||||
this._setMode(0);
|
||||
}
|
||||
|
||||
_deviceType() {
|
||||
@ -28,6 +29,10 @@ namespace sensors {
|
||||
return ((this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff) / 10) >> 0; // range is 0..2550, in 0.1 cm increments.
|
||||
}
|
||||
|
||||
_info(): string {
|
||||
return `${this.distance()}cm`
|
||||
}
|
||||
|
||||
_update(prev: number, curr: number) {
|
||||
// is there an object near?
|
||||
this.promixityThreshold.setLevel(curr);
|
||||
@ -38,7 +43,7 @@ namespace sensors {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers code to run when the given color is close
|
||||
* Registers code to run when an object is close or far
|
||||
* @param handler the code to run when detected
|
||||
*/
|
||||
//% help=sensors/ultrasonic/on-event
|
||||
|
Reference in New Issue
Block a user