Compare commits

...

4 Commits

Author SHA1 Message Date
Peli
3f598a3eee 1.2.27 2020-01-19 21:49:57 -08:00
Peli
ded2e9d82c don't close bt connection 2020-01-19 21:41:43 -08:00
Peli de Halleux
c8381d7626 1.2.26 2019-10-20 09:02:44 -07:00
Peli de Halleux
62b5941143 is color detected (#952)
* added query function

* reshuffle
2019-10-20 09:02:17 -07:00
4 changed files with 62 additions and 11 deletions

View File

@@ -64,6 +64,7 @@ class WebSerialPackageIO implements pxt.HF2.PacketIO {
private _writer: any; private _writer: any;
constructor(private port: SerialPort, private options: SerialOptions) { constructor(private port: SerialPort, private options: SerialOptions) {
console.log(`serial: new io`)
} }
async readSerialAsync() { async readSerialAsync() {
@@ -90,17 +91,24 @@ class WebSerialPackageIO implements pxt.HF2.PacketIO {
return !!(<any>navigator).serial; return !!(<any>navigator).serial;
} }
static portIos: WebSerialPackageIO[] = [];
static async mkPacketIOAsync(): Promise<pxt.HF2.PacketIO> { static async mkPacketIOAsync(): Promise<pxt.HF2.PacketIO> {
const serial = (<any>navigator).serial; const serial = (<any>navigator).serial;
if (serial) { if (serial) {
try { try {
const requestOptions: SerialPortRequestOptions = {}; const requestOptions: SerialPortRequestOptions = {};
const port = await serial.requestPort(requestOptions); const port = await serial.requestPort(requestOptions);
const options: SerialOptions = {
baudrate: 460800, let io = WebSerialPackageIO.portIos.filter(i => i.port == port)[0];
buffersize: 4096 if (!io) {
}; const options: SerialOptions = {
return new WebSerialPackageIO(port, options); baudrate: 460800,
buffersize: 4096
};
io = new WebSerialPackageIO(port, options);
WebSerialPackageIO.portIos.push(io);
}
return io;
} catch (e) { } catch (e) {
console.log(`connection error`, e) console.log(`connection error`, e)
} }
@@ -125,11 +133,8 @@ class WebSerialPackageIO implements pxt.HF2.PacketIO {
}); });
} }
private closeAsync() { private async closeAsync() {
console.log(`serial: closing port`); // don't close port
this.port.close();
this._reader = undefined;
this._writer = undefined;
return Promise.delay(500); return Promise.delay(500);
} }

View File

@@ -179,6 +179,22 @@ namespace sensors {
return this.getNumber(NumberFormat.UInt8LE, 0) return this.getNumber(NumberFormat.UInt8LE, 0)
} }
/**
* Checks the color is being detected
* @param color the color to detect
*/
//% help=sensors/color-sensor/is-color-detected
//% block="is **color sensor** %this|detected|%color=colorEnumPicker"
//% blockId=colorisColorDetectedDetected
//% parts="colorsensor"
//% blockNamespace=sensors
//% this.fieldEditor="ports"
//% weight=99 blockGap=8
//% group="Color Sensor"
isColorDetected(color: number) {
return this.color() == color;
}
/** /**
* Get the current raw rgb values as an array from the color sensor. * Get the current raw rgb values as an array from the color sensor.
* @param sensor the color sensor to query the request * @param sensor the color sensor to query the request

View File

@@ -0,0 +1,30 @@
# Is Color Detected
Checks the color is detected
```sig
let b = sensors.color1.isColorDetected(ColorSensorColor.Blue)
```
The [color](/reference/sensors/color) you choose to look for is one of the colors that the sensor can detect. If you want to use colors for tracking, it's best to use a color that is the same or very close to the ones the sensor detects.
## Parameters
* **color**: the [color](/reference/sensors/color) to watch for.
## Example
Wait for the sensor to see ``blue``. Then, show an expression on the screen.
```blocks
brick.showString("Waiting for blue", 1)
while(!sensors.color1.isColorDetected(ColorSensorColor.Blue)) {
pause(20)
}
brick.clearScreen()
brick.showImage(images.expressionsSick)
```
## See also
[on color detected](/reference/sensors/color-sensor/on-color-detected), [color](/reference/sensors/color)

View File

@@ -1,6 +1,6 @@
{ {
"name": "pxt-ev3", "name": "pxt-ev3",
"version": "1.2.25", "version": "1.2.27",
"description": "LEGO MINDSTORMS EV3 for Microsoft MakeCode", "description": "LEGO MINDSTORMS EV3 for Microsoft MakeCode",
"private": false, "private": false,
"keywords": [ "keywords": [