Compare commits
38 Commits
Author | SHA1 | Date | |
---|---|---|---|
3d29c5e323 | |||
15d59269d4 | |||
73b5e7dc3f | |||
a92edcffee | |||
305a650125 | |||
34a5aeb7d2 | |||
32f524ddd8 | |||
b690c1634b | |||
8089841892 | |||
3d8c697586 | |||
e365e3d1be | |||
4ed41adb6a | |||
39b7f99741 | |||
ad17191ae2 | |||
4a8633f506 | |||
3690f409b0 | |||
97663d2b83 | |||
4d2b7ced71 | |||
5676103052 | |||
cb8c14fbb1 | |||
815d438d86 | |||
da8de1e31e | |||
b028916025 | |||
b9be74bad8 | |||
7e502b1749 | |||
f22edac84d | |||
ef2807a84e | |||
580b40876c | |||
b57ae5d588 | |||
71479d0caa | |||
7e39cdde9d | |||
85ca6b3698 | |||
2c89848fda | |||
ed1c187514 | |||
52816e6de7 | |||
60ac3a9d00 | |||
d2c7a5ace0 | |||
ead69e3c6e |
@ -4,5 +4,12 @@ Here are some fun programs for your @boardname@!
|
|||||||
|
|
||||||
## Fun stuff
|
## Fun stuff
|
||||||
|
|
||||||
|
```codecard
|
||||||
Coming soon.
|
[
|
||||||
|
{
|
||||||
|
"name": "Happy unhappy",
|
||||||
|
"description": "Keep your brick entertained and happy",
|
||||||
|
"url":"/examples/happy-unhappy",
|
||||||
|
"cardType": "example"
|
||||||
|
}]
|
||||||
|
```
|
12
docs/examples/happy-unhappy.md
Normal file
12
docs/examples/happy-unhappy.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# Happy unhappy
|
||||||
|
|
||||||
|
Use a touch sensor to make the brick happy.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
sensors.touchSensor1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||||
|
brick.showImage(images.expressionsBigSmile)
|
||||||
|
})
|
||||||
|
sensors.touchSensor1.onEvent(TouchSensorEvent.Released, function () {
|
||||||
|
brick.showImage(images.expressionsSick)
|
||||||
|
})
|
||||||
|
```
|
@ -1,3 +1,8 @@
|
|||||||
# Reference
|
# Reference
|
||||||
|
|
||||||
TODO
|
|
||||||
|
|
||||||
|
## See Also
|
||||||
|
|
||||||
|
[touch sensor](/reference/sensors/touch-sensor),
|
||||||
|
[color sensor](/reference/sensors/color-sensor)
|
@ -9,6 +9,13 @@ eval("if (typeof process === 'object' && process + '' === '[object process]') px
|
|||||||
namespace pxt.editor {
|
namespace pxt.editor {
|
||||||
import UF2 = pxtc.UF2;
|
import UF2 = pxtc.UF2;
|
||||||
|
|
||||||
|
export let ev3: Ev3Wrapper
|
||||||
|
|
||||||
|
export function debug() {
|
||||||
|
return initAsync()
|
||||||
|
.then(w => w.downloadFileAsync("/tmp/dmesg.txt", v => console.log(pxt.Util.uint8ArrayToString(v))))
|
||||||
|
}
|
||||||
|
|
||||||
// this comes from aux/pxt.lms
|
// this comes from aux/pxt.lms
|
||||||
const rbfTemplate = `
|
const rbfTemplate = `
|
||||||
4c45474f580000006d000100000000001c000000000000000e000000821b038405018130813e8053
|
4c45474f580000006d000100000000001c000000000000000e000000821b038405018130813e8053
|
||||||
@ -19,6 +26,7 @@ namespace pxt.editor {
|
|||||||
return pxt.HF2.mkPacketIOAsync()
|
return pxt.HF2.mkPacketIOAsync()
|
||||||
.then(h => {
|
.then(h => {
|
||||||
let w = new Ev3Wrapper(h)
|
let w = new Ev3Wrapper(h)
|
||||||
|
ev3 = w
|
||||||
return w.reconnectAsync(true)
|
return w.reconnectAsync(true)
|
||||||
.then(() => w)
|
.then(() => w)
|
||||||
})
|
})
|
||||||
|
@ -252,6 +252,13 @@ namespace pxt.editor {
|
|||||||
return loop()
|
return loop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
downloadFileAsync(path: string, cb: (d: Uint8Array) => void) {
|
||||||
|
return this.lock.enqueue("file", () =>
|
||||||
|
this.streamFileOnceAsync(path, cb))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private initAsync() {
|
private initAsync() {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
|
@ -144,6 +144,12 @@
|
|||||||
"loops.pause|param|ms": "how long to pause for, eg: 100, 200, 500, 1000, 2000",
|
"loops.pause|param|ms": "how long to pause for, eg: 100, 200, 500, 1000, 2000",
|
||||||
"loops.timePicker": "Get the time field editor",
|
"loops.timePicker": "Get the time field editor",
|
||||||
"loops.timePicker|param|ms": "time duration in milliseconds, eg: 500, 1000",
|
"loops.timePicker|param|ms": "time duration in milliseconds, eg: 500, 1000",
|
||||||
|
"loops.waitUntil": "Busy wait for a condition to be true",
|
||||||
|
"loops.waitUntil|param|condition": "condition to test for",
|
||||||
|
"loops.waitUntil|param|timeOut": "if positive, maximum duration to wait for in milliseconds",
|
||||||
|
"loops.when": "Runs code when the condition becomes true",
|
||||||
|
"loops.when|param|condition": "condition to test",
|
||||||
|
"loops.when|param|handler": "code to run",
|
||||||
"parseInt": "Convert a string to an integer.",
|
"parseInt": "Convert a string to an integer.",
|
||||||
"serial": "Reading and writing data over a serial connection.",
|
"serial": "Reading and writing data over a serial connection.",
|
||||||
"serial.writeBuffer": "Send a buffer across the serial connection.",
|
"serial.writeBuffer": "Send a buffer across the serial connection.",
|
||||||
|
@ -17,7 +17,8 @@
|
|||||||
"control.cpp",
|
"control.cpp",
|
||||||
"control.ts",
|
"control.ts",
|
||||||
"serial.cpp",
|
"serial.cpp",
|
||||||
"serial.ts"
|
"serial.ts",
|
||||||
|
"loops.ts"
|
||||||
],
|
],
|
||||||
"testFiles": [
|
"testFiles": [
|
||||||
"test.ts"
|
"test.ts"
|
||||||
|
3
libs/color-sensor/README.md
Normal file
3
libs/color-sensor/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Color sensor
|
||||||
|
|
||||||
|
The library to interact with the Touch Sensor.
|
12
libs/color-sensor/_locales/color-sensor-jsdoc-strings.json
Normal file
12
libs/color-sensor/_locales/color-sensor-jsdoc-strings.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"sensors.ColorSensor": "The color sensor is a digital sensor that can detect the color or intensity\nof light that enters the small window on the face of the sensor.",
|
||||||
|
"sensors.ColorSensor.color": "Get the current color from the color sensor.",
|
||||||
|
"sensors.ColorSensor.colorMode": "Gets the current color mode",
|
||||||
|
"sensors.ColorSensor.light": "Measures the ambient or reflected light value from 0 (darkest) to 100 (brightest).",
|
||||||
|
"sensors.ColorSensor.onColorDetected": "Registers code to run when the given color is detected.",
|
||||||
|
"sensors.ColorSensor.onColorDetected|param|color": "the color to detect, eg: ColorSensorColor.Blue",
|
||||||
|
"sensors.ColorSensor.onColorDetected|param|handler": "the code to run when detected",
|
||||||
|
"sensors.ColorSensor.onLightChanged": "Registers code to run when the ambient light changes.",
|
||||||
|
"sensors.ColorSensor.onLightChanged|param|condition": "the light condition",
|
||||||
|
"sensors.ColorSensor.onLightChanged|param|handler": "the code to run when detected"
|
||||||
|
}
|
27
libs/color-sensor/_locales/color-sensor-strings.json
Normal file
27
libs/color-sensor/_locales/color-sensor-strings.json
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"ColorSensorColor.Black|block": "black",
|
||||||
|
"ColorSensorColor.Blue|block": "blue",
|
||||||
|
"ColorSensorColor.Brown|block": "brown",
|
||||||
|
"ColorSensorColor.Green|block": "green",
|
||||||
|
"ColorSensorColor.None|block": "none",
|
||||||
|
"ColorSensorColor.Red|block": "red",
|
||||||
|
"ColorSensorColor.White|block": "white",
|
||||||
|
"ColorSensorColor.Yellow|block": "yellow",
|
||||||
|
"ColorSensorMode.AmbientLightIntensity|block": "ambient light intensity",
|
||||||
|
"ColorSensorMode.Color|block": "color",
|
||||||
|
"ColorSensorMode.ReflectedLightIntensity|block": "reflected light intensity",
|
||||||
|
"LightCondition.Dark|block": "dark",
|
||||||
|
"LightIntensityMode.Ambient|block": "ambient light",
|
||||||
|
"LightIntensityMode.Reflected|block": "reflected light",
|
||||||
|
"sensors.ColorSensor.color|block": "`icons.colorSensor` %color| color",
|
||||||
|
"sensors.ColorSensor.light|block": "`icons.colorSensor` %color|%mode",
|
||||||
|
"sensors.ColorSensor.onColorDetected|block": "on `icons.colorSensor` %sensor|detected color %color",
|
||||||
|
"sensors.ColorSensor.onLightChanged|block": "on `icons.colorSensor` %sensor|%mode|%condition",
|
||||||
|
"sensors.color1|block": "1",
|
||||||
|
"sensors.color2|block": "2",
|
||||||
|
"sensors.color3|block": "3",
|
||||||
|
"sensors.color4|block": "4",
|
||||||
|
"sensors|block": "sensors",
|
||||||
|
"{id:category}Sensors": "Sensors",
|
||||||
|
"{id:group}Color Sensor": "Color Sensor"
|
||||||
|
}
|
185
libs/color-sensor/color.ts
Normal file
185
libs/color-sensor/color.ts
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
const enum ColorSensorMode {
|
||||||
|
None = -1,
|
||||||
|
//% block="reflected light intensity"
|
||||||
|
ReflectedLightIntensity = 0,
|
||||||
|
//% block="ambient light intensity"
|
||||||
|
AmbientLightIntensity = 1,
|
||||||
|
//% block="color"
|
||||||
|
Color = 2,
|
||||||
|
RefRaw = 3,
|
||||||
|
RgbRaw = 4,
|
||||||
|
ColorCal = 5,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum LightIntensityMode {
|
||||||
|
//% block="reflected light"
|
||||||
|
Reflected = ColorSensorMode.ReflectedLightIntensity,
|
||||||
|
//% block="ambient light"
|
||||||
|
Ambient = ColorSensorMode.AmbientLightIntensity
|
||||||
|
}
|
||||||
|
|
||||||
|
const enum ColorSensorColor {
|
||||||
|
//% block="none"
|
||||||
|
None,
|
||||||
|
//% block="black"
|
||||||
|
Black,
|
||||||
|
//% block="blue"
|
||||||
|
Blue,
|
||||||
|
//% block="green"
|
||||||
|
Green,
|
||||||
|
//% block="yellow"
|
||||||
|
Yellow,
|
||||||
|
//% block="red"
|
||||||
|
Red,
|
||||||
|
//% block="white"
|
||||||
|
White,
|
||||||
|
//% block="brown"
|
||||||
|
Brown,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum LightCondition {
|
||||||
|
//% block="dark"
|
||||||
|
Dark = sensors.internal.ThresholdState.Low,
|
||||||
|
//$ block="bright"
|
||||||
|
Bright = sensors.internal.ThresholdState.High
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace sensors {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The color sensor is a digital sensor that can detect the color or intensity
|
||||||
|
* of light that enters the small window on the face of the sensor.
|
||||||
|
*/
|
||||||
|
//% fixedInstances
|
||||||
|
export class ColorSensor extends internal.UartSensor {
|
||||||
|
thresholdDetector: sensors.internal.ThresholdDetector;
|
||||||
|
|
||||||
|
constructor(port: number) {
|
||||||
|
super(port)
|
||||||
|
this.thresholdDetector = new sensors.internal.ThresholdDetector(this.id());
|
||||||
|
}
|
||||||
|
|
||||||
|
_colorEventValue(value: number) {
|
||||||
|
return 0xff00 | value;
|
||||||
|
}
|
||||||
|
|
||||||
|
_deviceType() {
|
||||||
|
return DAL.DEVICE_TYPE_COLOR
|
||||||
|
}
|
||||||
|
|
||||||
|
setMode(m: ColorSensorMode) {
|
||||||
|
this._setMode(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current color mode
|
||||||
|
*/
|
||||||
|
colorMode() {
|
||||||
|
return <ColorSensorMode>this.mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
_query() {
|
||||||
|
if (this.mode == ColorSensorMode.Color)
|
||||||
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
_update(prev: number, curr: number) {
|
||||||
|
if (this.mode == ColorSensorMode.Color)
|
||||||
|
control.raiseEvent(this._id, this._colorEventValue(curr));
|
||||||
|
else
|
||||||
|
this.thresholdDetector.setLevel(curr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers code to run when the given color is detected.
|
||||||
|
* @param color the color to detect, eg: ColorSensorColor.Blue
|
||||||
|
* @param handler the code to run when detected
|
||||||
|
*/
|
||||||
|
//% help=sensors/color-sensor/on-color-detected
|
||||||
|
//% block="on `icons.colorSensor` %sensor|detected color %color"
|
||||||
|
//% blockId=colorOnColorDetected
|
||||||
|
//% parts="colorsensor"
|
||||||
|
//% blockNamespace=sensors
|
||||||
|
//% weight=100 blockGap=8
|
||||||
|
//% group="Color Sensor"
|
||||||
|
onColorDetected(color: ColorSensorColor, handler: () => void) {
|
||||||
|
const v = this._colorEventValue(<number>color);
|
||||||
|
control.onEvent(this._id, v, handler);
|
||||||
|
this.setMode(ColorSensorMode.Color)
|
||||||
|
if (this.color() == color)
|
||||||
|
control.raiseEvent(this._id, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current color from the color sensor.
|
||||||
|
* @param color the color sensor to query the request
|
||||||
|
*/
|
||||||
|
//% help=sensors/color-sensor/color
|
||||||
|
//% block="`icons.colorSensor` %color| color"
|
||||||
|
//% blockId=colorGetColor
|
||||||
|
//% parts="colorsensor"
|
||||||
|
//% blockNamespace=sensors
|
||||||
|
//% weight=99
|
||||||
|
//% group="Color Sensor"
|
||||||
|
color(): ColorSensorColor {
|
||||||
|
this.setMode(ColorSensorMode.Color)
|
||||||
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers code to run when the ambient light changes.
|
||||||
|
* @param condition the light condition
|
||||||
|
* @param handler the code to run when detected
|
||||||
|
*/
|
||||||
|
//% help=sensors/color-sensor/on-light-changed
|
||||||
|
//% block="on `icons.colorSensor` %sensor|%mode|%condition"
|
||||||
|
//% blockId=colorOnLightChanged
|
||||||
|
//% parts="colorsensor"
|
||||||
|
//% blockNamespace=sensors
|
||||||
|
//% weight=89 blockGap=8
|
||||||
|
//% group="Color Sensor"
|
||||||
|
onLightChanged(mode: LightIntensityMode, condition: LightCondition, handler: () => void) {
|
||||||
|
control.onEvent(this._id, <number>condition, handler);
|
||||||
|
this.setMode(<ColorSensorMode><number>mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Measures the ambient or reflected light value from 0 (darkest) to 100 (brightest).
|
||||||
|
* @param color the color sensor port
|
||||||
|
*/
|
||||||
|
//% help=sensors/color-sensor/light
|
||||||
|
//% block="`icons.colorSensor` %color|%mode"
|
||||||
|
//% blockId=colorLight
|
||||||
|
//% parts="colorsensor"
|
||||||
|
//% blockNamespace=sensors
|
||||||
|
//% weight=88
|
||||||
|
//% group="Color Sensor"
|
||||||
|
light(mode: LightIntensityMode) {
|
||||||
|
this.setMode(<ColorSensorMode><number>mode)
|
||||||
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
//%
|
||||||
|
ambientLight() {
|
||||||
|
return this.light(LightIntensityMode.Ambient);
|
||||||
|
}
|
||||||
|
|
||||||
|
//%
|
||||||
|
reflectedLight() {
|
||||||
|
return this.light(LightIntensityMode.Reflected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//% whenUsed block="1" weight=95 fixedInstance
|
||||||
|
export const color1: ColorSensor = new ColorSensor(1)
|
||||||
|
|
||||||
|
//% whenUsed block="3" weight=90 fixedInstance
|
||||||
|
export const color3: ColorSensor = new ColorSensor(3)
|
||||||
|
|
||||||
|
//% whenUsed block="2" weight=90 fixedInstance
|
||||||
|
export const color2: ColorSensor = new ColorSensor(2)
|
||||||
|
|
||||||
|
//% whenUsed block="4" weight=90 fixedInstance
|
||||||
|
export const color4: ColorSensor = new ColorSensor(4)
|
||||||
|
}
|
16
libs/color-sensor/docs/reference/sensors/color-sensor.md
Normal file
16
libs/color-sensor/docs/reference/sensors/color-sensor.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# Color Sensor
|
||||||
|
|
||||||
|
```cards
|
||||||
|
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {
|
||||||
|
})
|
||||||
|
sensors.color1.color();
|
||||||
|
sensors.color1.ambientLight();
|
||||||
|
sensors.color1.reflectedLight();
|
||||||
|
```
|
||||||
|
|
||||||
|
## See Also
|
||||||
|
|
||||||
|
[on color detected](/reference/sensors/color-sensor/on-color-detected),
|
||||||
|
[color](/reference/sensors/color-sensor/color),
|
||||||
|
[ambient light](/reference/sensors/color-sensor/ambient-light),
|
||||||
|
[reflected light](/reference/sensors/color-sensor/reflected-light),
|
@ -0,0 +1,11 @@
|
|||||||
|
# Ambient Light
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
loops.forever(function () {
|
||||||
|
if (sensors.color1.ambientLight() > 20) {
|
||||||
|
brick.setStatusLight(LightsPattern.Green)
|
||||||
|
} else {
|
||||||
|
brick.setStatusLight(LightsPattern.Orange)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
@ -0,0 +1,11 @@
|
|||||||
|
# color
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
loops.forever(function () {
|
||||||
|
if (sensors.color1.color() == ColorSensorColor.Green) {
|
||||||
|
brick.setStatusLight(LightsPattern.Green)
|
||||||
|
} else {
|
||||||
|
brick.setStatusLight(LightsPattern.Orange)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
@ -0,0 +1,16 @@
|
|||||||
|
# On Color Detected
|
||||||
|
|
||||||
|
```sig
|
||||||
|
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () { })
|
||||||
|
```
|
||||||
|
|
||||||
|
# Parameters
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {
|
||||||
|
brick.showImage(images.expressionsSick)
|
||||||
|
})
|
||||||
|
```
|
@ -0,0 +1,11 @@
|
|||||||
|
# Reflected Light
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
loops.forever(function () {
|
||||||
|
if (sensors.color1.reflectedLight() > 20) {
|
||||||
|
brick.setStatusLight(LightsPattern.Green)
|
||||||
|
} else {
|
||||||
|
brick.setStatusLight(LightsPattern.Orange)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
15
libs/color-sensor/pxt.json
Normal file
15
libs/color-sensor/pxt.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "color-sensor",
|
||||||
|
"description": "Color Sensor support",
|
||||||
|
"files": [
|
||||||
|
"README.md",
|
||||||
|
"color.ts"
|
||||||
|
],
|
||||||
|
"testFiles": [
|
||||||
|
"test.ts"
|
||||||
|
],
|
||||||
|
"public": true,
|
||||||
|
"dependencies": {
|
||||||
|
"core": "file:../core"
|
||||||
|
}
|
||||||
|
}
|
0
libs/color-sensor/test.ts
Normal file
0
libs/color-sensor/test.ts
Normal file
@ -14,11 +14,12 @@
|
|||||||
"MMap.setNumber": "Write a number in specified format in the buffer.",
|
"MMap.setNumber": "Write a number in specified format in the buffer.",
|
||||||
"MMap.slice": "Read a range of bytes into a buffer.",
|
"MMap.slice": "Read a range of bytes into a buffer.",
|
||||||
"MMap.write": "Perform write(2) on the underlaying file",
|
"MMap.write": "Perform write(2) on the underlaying file",
|
||||||
"TouchSensorEvent": "Touch sensor interactions",
|
|
||||||
"brick.Button": "Generic button class, for device buttons and sensors.",
|
"brick.Button": "Generic button class, for device buttons and sensors.",
|
||||||
"brick.Button.isPressed": "Check if button is currently pressed or not.",
|
"brick.Button.isPressed": "Check if button is currently pressed or not.",
|
||||||
"brick.Button.onEvent": "Do something when a button or sensor is clicked, up or down.",
|
"brick.Button.onEvent": "Do something when a button or sensor is clicked, up or down.",
|
||||||
"brick.Button.onEvent|param|body": "code to run when the event is raised",
|
"brick.Button.onEvent|param|body": "code to run when the event is raised",
|
||||||
|
"brick.Button.waitUntil": "Waits until the event is raised",
|
||||||
|
"brick.Button.waitUntil|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._imagePicker": "An image",
|
"brick._imagePicker": "An image",
|
||||||
"brick._imagePicker|param|image": "the image",
|
"brick._imagePicker|param|image": "the image",
|
||||||
@ -27,8 +28,8 @@
|
|||||||
"brick.buttonLeft": "Left button on the EV3 Brick.",
|
"brick.buttonLeft": "Left button on the EV3 Brick.",
|
||||||
"brick.buttonRight": "Right button on the EV3 Brick.",
|
"brick.buttonRight": "Right button on the EV3 Brick.",
|
||||||
"brick.buttonUp": "Up button on the EV3 Brick.",
|
"brick.buttonUp": "Up button on the EV3 Brick.",
|
||||||
"brick.pattern": "Pattern block.",
|
"brick.lightPattern": "Pattern block.",
|
||||||
"brick.pattern|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.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",
|
||||||
@ -69,35 +70,8 @@
|
|||||||
"screen.clear": "Clear screen and reset font to normal.",
|
"screen.clear": "Clear screen and reset font to normal.",
|
||||||
"screen.imageOf": "Makes an image bound to a buffer.",
|
"screen.imageOf": "Makes an image bound to a buffer.",
|
||||||
"screen.unpackPNG": "Decompresses a 1-bit gray scale PNG image to image format.",
|
"screen.unpackPNG": "Decompresses a 1-bit gray scale PNG image to image format.",
|
||||||
"sensors.ColorSensor.ambientLight": "Get current ambient light value from the color sensor.",
|
|
||||||
"sensors.ColorSensor.color": "Get the current color from the color sensor.",
|
|
||||||
"sensors.ColorSensor.onColorDetected": "Registers code to run when the given color is detected",
|
|
||||||
"sensors.ColorSensor.onColorDetected|param|color": "the color to dtect",
|
|
||||||
"sensors.ColorSensor.onColorDetected|param|handler": "the code to run when detected",
|
|
||||||
"sensors.ColorSensor.reflectedLight": "Get current reflected light value from the color sensor.",
|
|
||||||
"sensors.GyroSensor.angle": "Get the current angle from the gyroscope.",
|
"sensors.GyroSensor.angle": "Get the current angle from the gyroscope.",
|
||||||
"sensors.GyroSensor.rate": "Get the current rotation rate from the gyroscope.",
|
"sensors.GyroSensor.rate": "Get the current rotation rate from the gyroscope.",
|
||||||
"sensors.InfraredSensor.on": "Registers code to run when an object is getting near.",
|
|
||||||
"sensors.InfraredSensor.on|param|handler": "the code to run when detected",
|
|
||||||
"sensors.InfraredSensor.proximity": "Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far)",
|
|
||||||
"sensors.InfraredSensor.remoteCommand": "Get the remote commandreceived the infrared sensor.",
|
|
||||||
"sensors.InfraredSensor.wait": "Waits for the event to occur",
|
|
||||||
"sensors.RemoteInfraredBeaconButton.isPressed": "Check if a remote button is currently pressed or not.",
|
|
||||||
"sensors.RemoteInfraredBeaconButton.onEvent": "Do something when a button or sensor is clicked, up or down",
|
|
||||||
"sensors.RemoteInfraredBeaconButton.onEvent|param|body": "code to run when the event is raised",
|
|
||||||
"sensors.RemoteInfraredBeaconButton.wasPressed": "See if the remote button was pressed again since the last time you checked.",
|
|
||||||
"sensors.TouchSensor.isTouched": "Check if touch sensor is touched.",
|
|
||||||
"sensors.TouchSensor.onEvent": "Do something when a touch sensor is touched...",
|
|
||||||
"sensors.TouchSensor.onEvent|param|body": "code to run when the event is raised",
|
|
||||||
"sensors.UltraSonicSensor.distance": "Gets the distance from the sonar in millimeters",
|
|
||||||
"sensors.UltraSonicSensor.on": "Registers code to run when the given color is close",
|
|
||||||
"sensors.UltraSonicSensor.on|param|handler": "the code to run when detected",
|
|
||||||
"sensors.UltraSonicSensor.wait": "Waits for the event to occur",
|
|
||||||
"sensors.remoteButtonBottomLeft": "Remote bottom-left button.",
|
|
||||||
"sensors.remoteButtonBottomRight": "Remote bottom-right button.",
|
|
||||||
"sensors.remoteButtonCenter": "Remote beacon (center) button.",
|
|
||||||
"sensors.remoteButtonTopLeft": "Remote top-left button.",
|
|
||||||
"sensors.remoteButtonTopRight": "Remote top-right button.",
|
|
||||||
"serial": "Reading and writing data over a serial connection.",
|
"serial": "Reading and writing data over a serial connection.",
|
||||||
"serial.writeDmesg": "Send DMESG debug buffer over serial."
|
"serial.writeDmesg": "Send DMESG debug buffer over serial."
|
||||||
}
|
}
|
@ -2,16 +2,6 @@
|
|||||||
"ButtonEvent.Click|block": "click",
|
"ButtonEvent.Click|block": "click",
|
||||||
"ButtonEvent.Down|block": "down",
|
"ButtonEvent.Down|block": "down",
|
||||||
"ButtonEvent.Up|block": "up",
|
"ButtonEvent.Up|block": "up",
|
||||||
"ColorSensorColor.Black|block": "black",
|
|
||||||
"ColorSensorColor.Blue|block": "blue",
|
|
||||||
"ColorSensorColor.Brown|block": "brown",
|
|
||||||
"ColorSensorColor.Green|block": "green",
|
|
||||||
"ColorSensorColor.None|block": "none",
|
|
||||||
"ColorSensorColor.Red|block": "red",
|
|
||||||
"ColorSensorColor.White|block": "white",
|
|
||||||
"ColorSensorColor.Yellow|block": "yellow",
|
|
||||||
"InfraredSensorEvent.ObjectDetected|block": "object detected",
|
|
||||||
"InfraredSensorEvent.ObjectNear|block": "object near",
|
|
||||||
"LightsPattern.GreenFlash|block": "Flashing Green",
|
"LightsPattern.GreenFlash|block": "Flashing Green",
|
||||||
"LightsPattern.GreenPulse|block": "Pulsing Green",
|
"LightsPattern.GreenPulse|block": "Pulsing Green",
|
||||||
"LightsPattern.Green|block": "Green",
|
"LightsPattern.Green|block": "Green",
|
||||||
@ -27,13 +17,9 @@
|
|||||||
"Output.B|block": "B",
|
"Output.B|block": "B",
|
||||||
"Output.C|block": "C",
|
"Output.C|block": "C",
|
||||||
"Output.D|block": "D",
|
"Output.D|block": "D",
|
||||||
"TouchSensorEvent.Bumped|block": "bumped",
|
|
||||||
"TouchSensorEvent.Pressed|block": "pressed",
|
|
||||||
"TouchSensorEvent.Released|block": "released",
|
|
||||||
"UltrasonicSensorEvent.ObjectDetected|block": "object detected",
|
|
||||||
"UltrasonicSensorEvent.ObjectNear|block": "object near",
|
|
||||||
"brick.Button.isPressed|block": "`icons.brickButtons` %button|is pressed",
|
"brick.Button.isPressed|block": "`icons.brickButtons` %button|is pressed",
|
||||||
"brick.Button.onEvent|block": "on `icons.brickButtons` %button|%event",
|
"brick.Button.onEvent|block": "on `icons.brickButtons` %button|%event",
|
||||||
|
"brick.Button.waitUntil|block": "wait until `icons.brickButtons` %button|%event",
|
||||||
"brick.Button.wasPressed|block": "`icons.brickButtons` %button|was pressed",
|
"brick.Button.wasPressed|block": "`icons.brickButtons` %button|was pressed",
|
||||||
"brick._imagePicker|block": "%image",
|
"brick._imagePicker|block": "%image",
|
||||||
"brick.buttonDown|block": "down",
|
"brick.buttonDown|block": "down",
|
||||||
@ -41,7 +27,7 @@
|
|||||||
"brick.buttonLeft|block": "left",
|
"brick.buttonLeft|block": "left",
|
||||||
"brick.buttonRight|block": "right",
|
"brick.buttonRight|block": "right",
|
||||||
"brick.buttonUp|block": "up",
|
"brick.buttonUp|block": "up",
|
||||||
"brick.pattern|block": "%pattern",
|
"brick.lightPattern|block": "%pattern",
|
||||||
"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",
|
||||||
@ -69,50 +55,12 @@
|
|||||||
"motors|block": "motors",
|
"motors|block": "motors",
|
||||||
"output|block": "output",
|
"output|block": "output",
|
||||||
"screen|block": "screen",
|
"screen|block": "screen",
|
||||||
"sensors.ColorSensor.ambientLight|block": "`icons.colorSensor` %color| ambient light",
|
|
||||||
"sensors.ColorSensor.color|block": "`icons.colorSensor` %color| color",
|
|
||||||
"sensors.ColorSensor.onColorDetected|block": "on `icons.colorSensor` %sensor|detected %color",
|
|
||||||
"sensors.ColorSensor.reflectedLight|block": "`icons.colorSensor` %color| reflected light",
|
|
||||||
"sensors.GyroSensor.angle|block": "`icons.gyroSensor` %sensor|angle",
|
"sensors.GyroSensor.angle|block": "`icons.gyroSensor` %sensor|angle",
|
||||||
"sensors.GyroSensor.rate|block": "`icons.gyroSensor` %sensor|rotation rate",
|
"sensors.GyroSensor.rate|block": "`icons.gyroSensor` %sensor|rotation rate",
|
||||||
"sensors.InfraredSensor.on|block": "on `icons.infraredSensor` %sensor|%event",
|
|
||||||
"sensors.InfraredSensor.proximity|block": "`icons.infraredSensor` %infrared|proximity",
|
|
||||||
"sensors.InfraredSensor.remoteCommand|block": "`icons.infraredSensor` %infrared|remote command",
|
|
||||||
"sensors.InfraredSensor.wait|block": "wait `icons.infraredSensor` %sensor|for %event",
|
|
||||||
"sensors.RemoteInfraredBeaconButton.isPressed|block": "`icons.infraredSensor` %button|is pressed",
|
|
||||||
"sensors.RemoteInfraredBeaconButton.onEvent|block": "on `icons.infraredSensor` %button|%event",
|
|
||||||
"sensors.RemoteInfraredBeaconButton.wasPressed|block": "`icons.infraredSensor` %button|was pressed",
|
|
||||||
"sensors.TouchSensor.isTouched|block": "`icons.touchSensor` %sensor|is touched",
|
|
||||||
"sensors.TouchSensor.onEvent|block": "on `icons.touchSensor` %sensor|%event",
|
|
||||||
"sensors.UltraSonicSensor.distance|block": "`icons.ultrasonicSensor` %sensor|distance",
|
|
||||||
"sensors.UltraSonicSensor.on|block": "on `icons.ultrasonicSensor` %sensor|%event",
|
|
||||||
"sensors.UltraSonicSensor.wait|block": "wait `icons.ultrasonicSensor` %sensor|for %event",
|
|
||||||
"sensors.color1|block": "1",
|
|
||||||
"sensors.color2|block": "2",
|
|
||||||
"sensors.color3|block": "3",
|
|
||||||
"sensors.color4|block": "4",
|
|
||||||
"sensors.gyro1|block": "1",
|
"sensors.gyro1|block": "1",
|
||||||
"sensors.gyro2|block": "2",
|
"sensors.gyro2|block": "2",
|
||||||
"sensors.gyro3|block": "3",
|
"sensors.gyro3|block": "3",
|
||||||
"sensors.gyro4|block": "4",
|
"sensors.gyro4|block": "4",
|
||||||
"sensors.infraredSensor1|block": "1",
|
|
||||||
"sensors.infraredSensor2|block": "2",
|
|
||||||
"sensors.infraredSensor3|block": "3",
|
|
||||||
"sensors.infraredSensor4|block": "4",
|
|
||||||
"sensors.remoteButtonBottomLeft|block": "bottom-left",
|
|
||||||
"sensors.remoteButtonBottomRight|block": "bottom-right",
|
|
||||||
"sensors.remoteButtonCenter|block": "center",
|
|
||||||
"sensors.remoteButtonTopLeft|block": "top-left",
|
|
||||||
"sensors.remoteButtonTopRight|block": "top-right",
|
|
||||||
"sensors.touchSensor1|block": "1",
|
|
||||||
"sensors.touchSensor2|block": "2",
|
|
||||||
"sensors.touchSensor3|block": "3",
|
|
||||||
"sensors.touchSensor4|block": "4",
|
|
||||||
"sensors.ultrasonic1|block": "1",
|
|
||||||
"sensors.ultrasonic2|block": "2",
|
|
||||||
"sensors.ultrasonic3|block": "3",
|
|
||||||
"sensors.ultrasonic4|block": "4",
|
|
||||||
"sensors|block": "sensors",
|
|
||||||
"serial|block": "serial",
|
"serial|block": "serial",
|
||||||
"{id:category}Brick": "Brick",
|
"{id:category}Brick": "Brick",
|
||||||
"{id:category}Control": "Control",
|
"{id:category}Control": "Control",
|
||||||
@ -125,13 +73,8 @@
|
|||||||
"{id:category}Sensors": "Sensors",
|
"{id:category}Sensors": "Sensors",
|
||||||
"{id:category}Serial": "Serial",
|
"{id:category}Serial": "Serial",
|
||||||
"{id:group}Buttons": "Buttons",
|
"{id:group}Buttons": "Buttons",
|
||||||
"{id:group}Color Sensor": "Color Sensor",
|
|
||||||
"{id:group}Gyro Sensor": "Gyro Sensor",
|
"{id:group}Gyro Sensor": "Gyro Sensor",
|
||||||
"{id:group}Infrared Sensor": "Infrared Sensor",
|
|
||||||
"{id:group}Light": "Light",
|
"{id:group}Light": "Light",
|
||||||
"{id:group}Motors": "Motors",
|
"{id:group}Motors": "Motors",
|
||||||
"{id:group}Remote Infrared Beacon": "Remote Infrared Beacon",
|
"{id:group}Screen": "Screen"
|
||||||
"{id:group}Screen": "Screen",
|
|
||||||
"{id:group}Touch Sensor": "Touch Sensor",
|
|
||||||
"{id:group}Ultrasonic Sensor": "Ultrasonic Sensor"
|
|
||||||
}
|
}
|
@ -4,34 +4,34 @@
|
|||||||
*/
|
*/
|
||||||
const enum LightsPattern {
|
const enum LightsPattern {
|
||||||
//% block=Off enumval=0
|
//% block=Off enumval=0
|
||||||
//% blockIdentity=output.pattern
|
//% blockIdentity=brick.lightPattern
|
||||||
Off = 0,
|
Off = 0,
|
||||||
//% block=Green enumval=1
|
//% block=Green enumval=1
|
||||||
//% blockIdentity=output.pattern
|
//% blockIdentity=brick.lightPattern
|
||||||
Green = 1,
|
Green = 1,
|
||||||
//% block=Red enumval=2
|
//% block=Red enumval=2
|
||||||
//% blockIdentity=output.pattern
|
//% blockIdentity=brick.lightPattern
|
||||||
Red = 2,
|
Red = 2,
|
||||||
//% block=Orange enumval=3
|
//% block=Orange enumval=3
|
||||||
//% blockIdentity=output.pattern
|
//% blockIdentity=brick.lightPattern
|
||||||
Orange = 3,
|
Orange = 3,
|
||||||
//% block="Flashing Green" enumval=4
|
//% block="Flashing Green" enumval=4
|
||||||
//% blockIdentity=output.pattern
|
//% blockIdentity=brick.lightPattern
|
||||||
GreenFlash = 4,
|
GreenFlash = 4,
|
||||||
//% block="Flashing Red" enumval=5
|
//% block="Flashing Red" enumval=5
|
||||||
//% blockIdentity=output.pattern
|
//% blockIdentity=brick.lightPattern
|
||||||
RedFlash = 5,
|
RedFlash = 5,
|
||||||
//% block="Flashing Orange" enumval=6
|
//% block="Flashing Orange" enumval=6
|
||||||
//% blockIdentity=output.pattern
|
//% blockIdentity=brick.lightPattern
|
||||||
OrangeFlash = 6,
|
OrangeFlash = 6,
|
||||||
//% block="Pulsing Green" enumval=7
|
//% block="Pulsing Green" enumval=7
|
||||||
//% blockIdentity=output.pattern
|
//% blockIdentity=brick.lightPattern
|
||||||
GreenPulse = 7,
|
GreenPulse = 7,
|
||||||
//% block="Pulsing Red" enumval=8
|
//% block="Pulsing Red" enumval=8
|
||||||
//% blockIdentity=output.pattern
|
//% blockIdentity=brick.lightPattern
|
||||||
RedPulse = 8,
|
RedPulse = 8,
|
||||||
//% block="Pulsing Orange" enumval=9
|
//% block="Pulsing Orange" enumval=9
|
||||||
//% blockIdentity=output.pattern
|
//% blockIdentity=brick.lightPattern
|
||||||
OrangePulse = 9,
|
OrangePulse = 9,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,13 +69,14 @@ namespace brick {
|
|||||||
if (this._isPressed == curr) return
|
if (this._isPressed == curr) return
|
||||||
this._isPressed = curr
|
this._isPressed = curr
|
||||||
if (curr) {
|
if (curr) {
|
||||||
|
this._wasPressed = true;
|
||||||
this.downTime = control.millis()
|
this.downTime = control.millis()
|
||||||
control.raiseEvent(this._id, ButtonEvent.Down)
|
control.raiseEvent(this._id, ButtonEvent.Down)
|
||||||
} else {
|
} else {
|
||||||
control.raiseEvent(this._id, ButtonEvent.Up)
|
control.raiseEvent(this._id, ButtonEvent.Up)
|
||||||
let delta = control.millis() - this.downTime
|
const delta = control.millis() - this.downTime;
|
||||||
control.raiseEvent(this._id, ButtonEvent.Click)
|
if (delta < 500)
|
||||||
//control.raiseEvent(this._id, delta > 500 ? ButtonEvent.LongClick : ButtonEvent.Click)
|
control.raiseEvent(this._id, ButtonEvent.Click)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,6 +127,20 @@ namespace brick {
|
|||||||
onEvent(ev: ButtonEvent, body: () => void) {
|
onEvent(ev: ButtonEvent, body: () => void) {
|
||||||
control.onEvent(this._id, ev, body)
|
control.onEvent(this._id, ev, body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Waits until the event is raised
|
||||||
|
* @param ev the event to wait for
|
||||||
|
*/
|
||||||
|
//% help=input/button/wait-until
|
||||||
|
//% blockId=buttonWaitUntil block="wait until `icons.brickButtons` %button|%event"
|
||||||
|
//% parts="brick"
|
||||||
|
//% blockNamespace=brick
|
||||||
|
//% weight=98 blockGap=8
|
||||||
|
//% group="Buttons"
|
||||||
|
waitUntil(ev: ButtonEvent) {
|
||||||
|
control.waitForEvent(this._id, ev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +267,7 @@ namespace brick {
|
|||||||
//% blockId=led_pattern block="%pattern"
|
//% blockId=led_pattern block="%pattern"
|
||||||
//% shim=TD_ID colorSecondary="#6e9a36" group="Light"
|
//% shim=TD_ID colorSecondary="#6e9a36" group="Light"
|
||||||
//% blockHidden=true useEnumVal=1 pattern.fieldOptions.decompileLiterals=1
|
//% blockHidden=true useEnumVal=1 pattern.fieldOptions.decompileLiterals=1
|
||||||
export function pattern(pattern: LightsPattern): number {
|
export function lightPattern(pattern: LightsPattern): number {
|
||||||
return pattern;
|
return pattern;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,135 +0,0 @@
|
|||||||
const enum ColorSensorMode {
|
|
||||||
None = -1,
|
|
||||||
Reflect = 0,
|
|
||||||
Ambient = 1,
|
|
||||||
Color = 2,
|
|
||||||
RefRaw = 3,
|
|
||||||
RgbRaw = 4,
|
|
||||||
ColorCal = 5,
|
|
||||||
}
|
|
||||||
|
|
||||||
const enum ColorSensorColor {
|
|
||||||
//% block="none"
|
|
||||||
None,
|
|
||||||
//% block="black"
|
|
||||||
Black,
|
|
||||||
//% block="blue"
|
|
||||||
Blue,
|
|
||||||
//% block="green"
|
|
||||||
Green,
|
|
||||||
//% block="yellow"
|
|
||||||
Yellow,
|
|
||||||
//% block="red"
|
|
||||||
Red,
|
|
||||||
//% block="white"
|
|
||||||
White,
|
|
||||||
//% block="brown"
|
|
||||||
Brown,
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace sensors {
|
|
||||||
|
|
||||||
//% fixedInstances
|
|
||||||
export class ColorSensor extends internal.UartSensor {
|
|
||||||
constructor(port: number) {
|
|
||||||
super(port)
|
|
||||||
}
|
|
||||||
|
|
||||||
_deviceType() {
|
|
||||||
return DAL.DEVICE_TYPE_COLOR
|
|
||||||
}
|
|
||||||
|
|
||||||
setMode(m: ColorSensorMode) {
|
|
||||||
this._setMode(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
_query() {
|
|
||||||
if (this.mode == ColorSensorMode.Color)
|
|
||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
_update(prev: number, curr: number) {
|
|
||||||
control.raiseEvent(this._id, curr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers code to run when the given color is detected
|
|
||||||
* @param color the color to dtect
|
|
||||||
* @param handler the code to run when detected
|
|
||||||
*/
|
|
||||||
//% help=input/color/on-color-detected
|
|
||||||
//% block="on `icons.colorSensor` %sensor|detected %color"
|
|
||||||
//% blockId=colorOnColorDetected
|
|
||||||
//% parts="colorsensor"
|
|
||||||
//% blockNamespace=sensors
|
|
||||||
//% weight=100 blockGap=8
|
|
||||||
//% group="Color Sensor"
|
|
||||||
onColorDetected(color: ColorSensorColor, handler: () => void) {
|
|
||||||
control.onEvent(this._id, <number>color, handler);
|
|
||||||
this.setMode(ColorSensorMode.Color)
|
|
||||||
if (this.color() == color)
|
|
||||||
control.runInBackground(handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get current ambient light value from the color sensor.
|
|
||||||
* @param color the color sensor to query the request
|
|
||||||
*/
|
|
||||||
//% help=input/color/ambient-light
|
|
||||||
//% block="`icons.colorSensor` %color| ambient light"
|
|
||||||
//% blockId=colorGetAmbient
|
|
||||||
//% parts="colorsensor"
|
|
||||||
//% blockNamespace=sensors
|
|
||||||
//% weight=65 blockGap=8
|
|
||||||
//% group="Color Sensor"
|
|
||||||
ambientLight() {
|
|
||||||
this.setMode(ColorSensorMode.Ambient)
|
|
||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get current reflected light value from the color sensor.
|
|
||||||
* @param color the color sensor to query the request
|
|
||||||
*/
|
|
||||||
//% help=input/color/refelected-light
|
|
||||||
//% block="`icons.colorSensor` %color| reflected light"
|
|
||||||
//% blockId=colorGetReflected
|
|
||||||
//% parts="colorsensor"
|
|
||||||
//% blockNamespace=sensors
|
|
||||||
//% weight=64 blockGap=8
|
|
||||||
//% group="Color Sensor"
|
|
||||||
reflectedLight(): number {
|
|
||||||
this.setMode(ColorSensorMode.Reflect)
|
|
||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current color from the color sensor.
|
|
||||||
* @param color the color sensor to query the request
|
|
||||||
*/
|
|
||||||
//% help=input/color/color
|
|
||||||
//% block="`icons.colorSensor` %color| color"
|
|
||||||
//% blockId=colorGetColor
|
|
||||||
//% parts="colorsensor"
|
|
||||||
//% blockNamespace=sensors
|
|
||||||
//% weight=66 blockGap=8
|
|
||||||
//% group="Color Sensor"
|
|
||||||
color(): ColorSensorColor {
|
|
||||||
this.setMode(ColorSensorMode.Color)
|
|
||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//% whenUsed block="1" weight=95 fixedInstance
|
|
||||||
export const color1: ColorSensor = new ColorSensor(1)
|
|
||||||
|
|
||||||
//% whenUsed block="3" weight=90 fixedInstance
|
|
||||||
export const color3: ColorSensor = new ColorSensor(3)
|
|
||||||
|
|
||||||
//% whenUsed block="2" weight=90 fixedInstance
|
|
||||||
export const color2: ColorSensor = new ColorSensor(2)
|
|
||||||
|
|
||||||
//% whenUsed block="4" weight=90 fixedInstance
|
|
||||||
export const color4: ColorSensor = new ColorSensor(4)
|
|
||||||
}
|
|
@ -10,7 +10,7 @@ namespace control {
|
|||||||
this._id = id
|
this._id = id
|
||||||
}
|
}
|
||||||
|
|
||||||
getId() {
|
id() {
|
||||||
return this._id;
|
return this._id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,26 +132,26 @@ namespace sensors.internal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Sensor extends control.Component {
|
export class Sensor extends control.Component {
|
||||||
protected port: number // this is 0-based
|
protected _port: number // this is 0-based
|
||||||
|
|
||||||
constructor(port_: number) {
|
constructor(port_: number) {
|
||||||
super()
|
super()
|
||||||
if (!(1 <= port_ && port_ <= DAL.NUM_INPUTS))
|
if (!(1 <= port_ && port_ <= DAL.NUM_INPUTS))
|
||||||
control.panic(120)
|
control.panic(120)
|
||||||
this.port = port_ - 1
|
this._port = port_ - 1
|
||||||
init()
|
init()
|
||||||
sensorInfos[this.port].sensors.push(this)
|
sensorInfos[this._port].sensors.push(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
_activated() { }
|
_activated() { }
|
||||||
|
|
||||||
// 1-based
|
// 1-based
|
||||||
getPort() {
|
port() {
|
||||||
return this.port + 1
|
return this._port + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
isActive() {
|
isActive() {
|
||||||
return sensorInfos[this.port].sensor == this
|
return sensorInfos[this._port].sensor == this
|
||||||
}
|
}
|
||||||
|
|
||||||
_query() {
|
_query() {
|
||||||
@ -173,11 +173,85 @@ namespace sensors.internal {
|
|||||||
|
|
||||||
_readPin6() {
|
_readPin6() {
|
||||||
if (!this.isActive()) return 0
|
if (!this.isActive()) return 0
|
||||||
return analogMM.getNumber(NumberFormat.Int16LE, AnalogOff.InPin6 + 2 * this.port)
|
return analogMM.getNumber(NumberFormat.Int16LE, AnalogOff.InPin6 + 2 * this._port)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ThresholdState {
|
||||||
|
Normal = 1,
|
||||||
|
High = 2,
|
||||||
|
Low = 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ThresholdDetector {
|
||||||
|
public id: number;
|
||||||
|
private min: number;
|
||||||
|
private max: number;
|
||||||
|
private lowThreshold: number;
|
||||||
|
private highThreshold: number;
|
||||||
|
private level: number;
|
||||||
|
private state: ThresholdState;
|
||||||
|
|
||||||
|
constructor(id: number, min = 0, max = 100, lowThreshold = 20, highThreshold = 80) {
|
||||||
|
this.id = id;
|
||||||
|
this.min = min;
|
||||||
|
this.max = max;
|
||||||
|
this.lowThreshold = lowThreshold;
|
||||||
|
this.highThreshold = highThreshold;
|
||||||
|
this.level = Math.ceil((max - min) / 2);
|
||||||
|
this.state = ThresholdState.Normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public setLevel(level: number) {
|
||||||
|
this.level = this.clampValue(level);
|
||||||
|
|
||||||
|
if (this.level >= this.highThreshold) {
|
||||||
|
this.setState(ThresholdState.High);
|
||||||
|
}
|
||||||
|
else if (this.level <= this.lowThreshold) {
|
||||||
|
this.setState(ThresholdState.Low);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.setState(ThresholdState.Normal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public setLowThreshold(value: number) {
|
||||||
|
this.lowThreshold = this.clampValue(value);
|
||||||
|
this.highThreshold = Math.max(this.lowThreshold + 1, this.highThreshold);
|
||||||
|
}
|
||||||
|
|
||||||
|
public setHighThreshold(value: number) {
|
||||||
|
this.highThreshold = this.clampValue(value);
|
||||||
|
this.lowThreshold = Math.min(this.highThreshold - 1, this.lowThreshold);
|
||||||
|
}
|
||||||
|
|
||||||
|
private clampValue(value: number) {
|
||||||
|
if (value < this.min) {
|
||||||
|
return this.min;
|
||||||
|
}
|
||||||
|
else if (value > this.max) {
|
||||||
|
return this.max;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private setState(state: ThresholdState) {
|
||||||
|
if (this.state == state) return;
|
||||||
|
|
||||||
|
this.state = state;
|
||||||
|
switch (state) {
|
||||||
|
case ThresholdState.High:
|
||||||
|
control.raiseEvent(this.id, ThresholdState.High);
|
||||||
|
break;
|
||||||
|
case ThresholdState.Low:
|
||||||
|
control.raiseEvent(this.id, ThresholdState.Low);
|
||||||
|
break;
|
||||||
|
case ThresholdState.Normal:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class UartSensor extends Sensor {
|
export class UartSensor extends Sensor {
|
||||||
protected mode: number // the mode user asked for
|
protected mode: number // the mode user asked for
|
||||||
@ -202,18 +276,18 @@ namespace sensors.internal {
|
|||||||
if (!this.isActive()) return
|
if (!this.isActive()) return
|
||||||
if (this.realmode != this.mode) {
|
if (this.realmode != this.mode) {
|
||||||
this.realmode = v
|
this.realmode = v
|
||||||
setUartMode(this.port, v)
|
setUartMode(this._port, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getBytes(): Buffer {
|
getBytes(): Buffer {
|
||||||
return getUartBytes(this.isActive() ? this.port : -1)
|
return getUartBytes(this.isActive() ? this._port : -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
getNumber(fmt: NumberFormat, off: number) {
|
getNumber(fmt: NumberFormat, off: number) {
|
||||||
if (!this.isActive())
|
if (!this.isActive())
|
||||||
return 0
|
return 0
|
||||||
return getUartNumber(fmt, off, this.port)
|
return getUartNumber(fmt, off, this._port)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@ -15,6 +14,8 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#define THREAD_DBG(...)
|
||||||
|
|
||||||
void *operator new(size_t size) {
|
void *operator new(size_t size) {
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
@ -229,6 +230,8 @@ static void runAct(Thread *thr) {
|
|||||||
disposeThread(thr);
|
disposeThread(thr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void mainThread(Thread *) {}
|
||||||
|
|
||||||
void setupThread(Action a, TValue arg = 0, void (*runner)(Thread *) = NULL, TValue d0 = 0,
|
void setupThread(Action a, TValue arg = 0, void (*runner)(Thread *) = NULL, TValue d0 = 0,
|
||||||
TValue d1 = 0) {
|
TValue d1 = 0) {
|
||||||
if (runner == NULL)
|
if (runner == NULL)
|
||||||
@ -242,8 +245,13 @@ void setupThread(Action a, TValue arg = 0, void (*runner)(Thread *) = NULL, TVal
|
|||||||
thr->data0 = incr(d0);
|
thr->data0 = incr(d0);
|
||||||
thr->data1 = incr(d1);
|
thr->data1 = incr(d1);
|
||||||
pthread_cond_init(&thr->waitCond, NULL);
|
pthread_cond_init(&thr->waitCond, NULL);
|
||||||
pthread_create(&thr->pid, NULL, (void *(*)(void *))runner, thr);
|
if (runner == mainThread) {
|
||||||
pthread_detach(thr->pid);
|
thr->pid = pthread_self();
|
||||||
|
} else {
|
||||||
|
pthread_create(&thr->pid, NULL, (void *(*)(void *))runner, thr);
|
||||||
|
THREAD_DBG("setup thread: %p (pid %p)", thr, thr->pid);
|
||||||
|
pthread_detach(thr->pid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void runInBackground(Action a) {
|
void runInBackground(Action a) {
|
||||||
@ -263,8 +271,10 @@ void runForever(Action a) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void waitForEvent(int source, int value) {
|
void waitForEvent(int source, int value) {
|
||||||
|
THREAD_DBG("waitForEv: %d %d", source, value);
|
||||||
auto self = pthread_self();
|
auto self = pthread_self();
|
||||||
for (auto t = allThreads; t; t = t->next) {
|
for (auto t = allThreads; t; t = t->next) {
|
||||||
|
THREAD_DBG("t: %p", t);
|
||||||
if (t->pid == self) {
|
if (t->pid == self) {
|
||||||
pthread_mutex_lock(&eventMutex);
|
pthread_mutex_lock(&eventMutex);
|
||||||
t->waitSource = source;
|
t->waitSource = source;
|
||||||
@ -279,7 +289,8 @@ void waitForEvent(int source, int value) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(0);
|
DMESG("current thread not registered!");
|
||||||
|
target_panic(901);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dispatchEvent(Event &e) {
|
static void dispatchEvent(Event &e) {
|
||||||
@ -342,7 +353,8 @@ void raiseEvent(int id, int event) {
|
|||||||
auto e = mkEvent(id, event);
|
auto e = mkEvent(id, event);
|
||||||
pthread_mutex_lock(&eventMutex);
|
pthread_mutex_lock(&eventMutex);
|
||||||
if (eventTail == NULL) {
|
if (eventTail == NULL) {
|
||||||
assert(eventHead == NULL);
|
if (eventHead != NULL)
|
||||||
|
target_panic(902);
|
||||||
eventHead = eventTail = e;
|
eventHead = eventTail = e;
|
||||||
} else {
|
} else {
|
||||||
eventTail->next = e;
|
eventTail->next = e;
|
||||||
@ -467,6 +479,7 @@ void initRuntime() {
|
|||||||
pthread_t disp;
|
pthread_t disp;
|
||||||
pthread_create(&disp, NULL, evtDispatcher, NULL);
|
pthread_create(&disp, NULL, evtDispatcher, NULL);
|
||||||
pthread_detach(disp);
|
pthread_detach(disp);
|
||||||
|
setupThread(0, 0, mainThread);
|
||||||
target_init();
|
target_init();
|
||||||
screen_init();
|
screen_init();
|
||||||
startUser();
|
startUser();
|
||||||
@ -508,4 +521,4 @@ void dmesg(const char *format, ...) {
|
|||||||
fflush(dmesgFile);
|
fflush(dmesgFile);
|
||||||
fdatasync(fileno(dmesgFile));
|
fdatasync(fileno(dmesgFile));
|
||||||
}
|
}
|
||||||
}
|
} // namespace pxt
|
||||||
|
@ -97,7 +97,8 @@ namespace motors {
|
|||||||
power(power: number) {
|
power(power: number) {
|
||||||
power = Math.clamp(-100, 100, power >> 0);
|
power = Math.clamp(-100, 100, power >> 0);
|
||||||
|
|
||||||
const b = mkCmd(this.port, DAL.opOutputPower, 1)
|
// per LEGO: call it power, use speed
|
||||||
|
const b = mkCmd(this.port, DAL.opOutputSpeed, 1)
|
||||||
b.setNumber(NumberFormat.Int8LE, 2, power)
|
b.setNumber(NumberFormat.Int8LE, 2, power)
|
||||||
writePWM(b)
|
writePWM(b)
|
||||||
if (power) {
|
if (power) {
|
||||||
|
@ -18,11 +18,7 @@
|
|||||||
"output.ts",
|
"output.ts",
|
||||||
"core.ts",
|
"core.ts",
|
||||||
"input.ts",
|
"input.ts",
|
||||||
"ir.ts",
|
|
||||||
"color.ts",
|
|
||||||
"gyro.ts",
|
"gyro.ts",
|
||||||
"ultrasonic.ts",
|
|
||||||
"touch.ts",
|
|
||||||
"shims.d.ts",
|
"shims.d.ts",
|
||||||
"enums.d.ts",
|
"enums.d.ts",
|
||||||
"dal.d.ts",
|
"dal.d.ts",
|
||||||
|
@ -180,7 +180,7 @@ void init() {
|
|||||||
mappedFrameBuffer = (uint8_t *)mmap(NULL, FB_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
mappedFrameBuffer = (uint8_t *)mmap(NULL, FB_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
DMESG("map %p", mappedFrameBuffer);
|
DMESG("map %p", mappedFrameBuffer);
|
||||||
if (mappedFrameBuffer == MAP_FAILED) {
|
if (mappedFrameBuffer == MAP_FAILED) {
|
||||||
target_panic(111);
|
target_panic(903);
|
||||||
}
|
}
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
|
@ -143,7 +143,8 @@ namespace brick {
|
|||||||
if (!image) return;
|
if (!image) return;
|
||||||
image.draw(0, 0, Draw.Normal);
|
image.draw(0, 0, Draw.Normal);
|
||||||
delay = Math.max(0, delay);
|
delay = Math.max(0, delay);
|
||||||
loops.pause(delay);
|
if (delay > 0)
|
||||||
|
loops.pause(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,7 +8,11 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"base": "file:../base",
|
"base": "file:../base",
|
||||||
"core": "file:../core",
|
"core": "file:../core",
|
||||||
"music": "file:../music"
|
"music": "file:../music",
|
||||||
|
"color-sensor": "file:../color-sensor",
|
||||||
|
"touch-sensor": "file:../touch-sensor",
|
||||||
|
"ultrasonic-sensor": "file:../ultrasonic-sensor",
|
||||||
|
"infrared-sensor": "file:../infrared-sensor"
|
||||||
},
|
},
|
||||||
"public": true
|
"public": true
|
||||||
}
|
}
|
||||||
|
3
libs/infrared-sensor/README.md
Normal file
3
libs/infrared-sensor/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Infrared sensor
|
||||||
|
|
||||||
|
The library to interact with the Infrared Sensor.
|
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"sensors.InfraredSensor.onEvent": "Registers code to run when an object is getting near.",
|
||||||
|
"sensors.InfraredSensor.onEvent|param|handler": "the code to run when detected",
|
||||||
|
"sensors.InfraredSensor.proximity": "Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far)",
|
||||||
|
"sensors.InfraredSensor.remoteCommand": "Get the remote commandreceived the infrared sensor.",
|
||||||
|
"sensors.InfraredSensor.waitUntil": "Waits for the event to occur",
|
||||||
|
"sensors.RemoteInfraredBeaconButton.isPressed": "Check if a remote button is currently pressed or not.",
|
||||||
|
"sensors.RemoteInfraredBeaconButton.onEvent": "Do something when a button or sensor is clicked, up or down",
|
||||||
|
"sensors.RemoteInfraredBeaconButton.onEvent|param|body": "code to run when the event is raised",
|
||||||
|
"sensors.RemoteInfraredBeaconButton.wasPressed": "See if the remote button was pressed again since the last time you checked.",
|
||||||
|
"sensors.remoteButtonBottomLeft": "Remote bottom-left button.",
|
||||||
|
"sensors.remoteButtonBottomRight": "Remote bottom-right button.",
|
||||||
|
"sensors.remoteButtonCenter": "Remote beacon (center) button.",
|
||||||
|
"sensors.remoteButtonTopLeft": "Remote top-left button.",
|
||||||
|
"sensors.remoteButtonTopRight": "Remote top-right button."
|
||||||
|
}
|
24
libs/infrared-sensor/_locales/infrared-sensor-strings.json
Normal file
24
libs/infrared-sensor/_locales/infrared-sensor-strings.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"InfraredSensorEvent.ObjectDetected|block": "object detected",
|
||||||
|
"InfraredSensorEvent.ObjectNear|block": "object near",
|
||||||
|
"sensors.InfraredSensor.onEvent|block": "on `icons.infraredSensor` %sensor|%event",
|
||||||
|
"sensors.InfraredSensor.proximity|block": "`icons.infraredSensor` %infrared|proximity",
|
||||||
|
"sensors.InfraredSensor.remoteCommand|block": "`icons.infraredSensor` %infrared|remote command",
|
||||||
|
"sensors.InfraredSensor.waitUntil|block": "wait until `icons.infraredSensor` %sensor| %event",
|
||||||
|
"sensors.RemoteInfraredBeaconButton.isPressed|block": "`icons.infraredSensor` %button|is pressed",
|
||||||
|
"sensors.RemoteInfraredBeaconButton.onEvent|block": "on `icons.infraredSensor` %button|%event",
|
||||||
|
"sensors.RemoteInfraredBeaconButton.wasPressed|block": "`icons.infraredSensor` %button|was pressed",
|
||||||
|
"sensors.infraredSensor1|block": "1",
|
||||||
|
"sensors.infraredSensor2|block": "2",
|
||||||
|
"sensors.infraredSensor3|block": "3",
|
||||||
|
"sensors.infraredSensor4|block": "4",
|
||||||
|
"sensors.remoteButtonBottomLeft|block": "bottom-left",
|
||||||
|
"sensors.remoteButtonBottomRight|block": "bottom-right",
|
||||||
|
"sensors.remoteButtonCenter|block": "center",
|
||||||
|
"sensors.remoteButtonTopLeft|block": "top-left",
|
||||||
|
"sensors.remoteButtonTopRight|block": "top-right",
|
||||||
|
"sensors|block": "sensors",
|
||||||
|
"{id:category}Sensors": "Sensors",
|
||||||
|
"{id:group}Infrared Sensor": "Infrared Sensor",
|
||||||
|
"{id:group}Remote Infrared Beacon": "Remote Infrared Beacon"
|
||||||
|
}
|
@ -134,16 +134,16 @@ namespace sensors {
|
|||||||
this.button.onEvent(ev, body);
|
this.button.onEvent(ev, body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//% fixedInstances
|
//% fixedInstances
|
||||||
export class InfraredSensor extends internal.UartSensor {
|
export class InfraredSensor extends internal.UartSensor {
|
||||||
private channel: IrRemoteChannel;
|
private channel: IrRemoteChannel;
|
||||||
private proximityThreshold: number;
|
private proximityThreshold: sensors.internal.ThresholdDetector;
|
||||||
|
|
||||||
constructor(port: number) {
|
constructor(port: number) {
|
||||||
super(port)
|
super(port)
|
||||||
this.channel = IrRemoteChannel.Ch0
|
this.channel = IrRemoteChannel.Ch0
|
||||||
this.proximityThreshold = 10;
|
this.proximityThreshold = new sensors.internal.ThresholdDetector(this._id, 0, 100, 10, 90);
|
||||||
irButton(0) // make sure buttons array is initalized
|
irButton(0) // make sure buttons array is initalized
|
||||||
|
|
||||||
// and set the mode, as otherwise button events won't work
|
// and set the mode, as otherwise button events won't work
|
||||||
@ -154,10 +154,7 @@ namespace sensors {
|
|||||||
if (this.mode == IrSensorMode.RemoteControl)
|
if (this.mode == IrSensorMode.RemoteControl)
|
||||||
return mapButton(this.getNumber(NumberFormat.UInt8LE, this.channel));
|
return mapButton(this.getNumber(NumberFormat.UInt8LE, this.channel));
|
||||||
else if (this.mode == IrSensorMode.Proximity) {
|
else if (this.mode == IrSensorMode.Proximity) {
|
||||||
const d = this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff;
|
return this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff;
|
||||||
return d < this.proximityThreshold ? UltrasonicSensorEvent.ObjectNear
|
|
||||||
: d > this.proximityThreshold + 5 ? UltrasonicSensorEvent.ObjectDetected
|
|
||||||
: 0;
|
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -168,9 +165,8 @@ namespace sensors {
|
|||||||
let v = !!(curr & (1 << i))
|
let v = !!(curr & (1 << i))
|
||||||
buttons[i]._update(v)
|
buttons[i]._update(v)
|
||||||
}
|
}
|
||||||
} else {
|
} else if (this.mode == IrSensorMode.Proximity) {
|
||||||
if (curr)
|
this.proximityThreshold.setLevel(curr);
|
||||||
control.raiseEvent(this._id, curr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +177,7 @@ namespace sensors {
|
|||||||
setRemoteChannel(c: IrRemoteChannel) {
|
setRemoteChannel(c: IrRemoteChannel) {
|
||||||
c = Math.clamp(0, 3, c | 0)
|
c = Math.clamp(0, 3, c | 0)
|
||||||
this.channel = c
|
this.channel = c
|
||||||
this._setMode(IrSensorMode.RemoteControl)
|
this.setMode(IrSensorMode.RemoteControl)
|
||||||
}
|
}
|
||||||
|
|
||||||
setMode(m: IrSensorMode) {
|
setMode(m: IrSensorMode) {
|
||||||
@ -199,26 +195,24 @@ namespace sensors {
|
|||||||
//% blockNamespace=sensors
|
//% blockNamespace=sensors
|
||||||
//% weight=100 blockGap=8
|
//% weight=100 blockGap=8
|
||||||
//% group="Infrared Sensor"
|
//% group="Infrared Sensor"
|
||||||
on(event: InfraredSensorEvent, handler: () => void) {
|
onEvent(event: InfraredSensorEvent, handler: () => void) {
|
||||||
control.onEvent(this._id, InfraredSensorEvent.ObjectNear, handler);
|
control.onEvent(this._id, event, handler);
|
||||||
if ( this.proximity() == InfraredSensorEvent.ObjectNear)
|
|
||||||
control.runInBackground(handler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits for the event to occur
|
* Waits for the event to occur
|
||||||
*/
|
*/
|
||||||
//% help=input/ultrasonic/wait
|
//% help=input/ultrasonic/wait
|
||||||
//% block="wait `icons.infraredSensor` %sensor|for %event"
|
//% block="wait until `icons.infraredSensor` %sensor| %event"
|
||||||
//% blockId=infraredwait
|
//% blockId=infraredwait
|
||||||
//% parts="infraredsensor"
|
//% parts="infraredsensor"
|
||||||
//% blockNamespace=sensors
|
//% blockNamespace=sensors
|
||||||
//% weight=99 blockGap=8
|
//% weight=99 blockGap=8
|
||||||
//% group="Infrared Sensor"
|
//% group="Infrared Sensor"
|
||||||
wait(event: InfraredSensorEvent) {
|
waitUntil(event: InfraredSensorEvent) {
|
||||||
// TODO
|
control.waitForEvent(this._id, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far)
|
* Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far)
|
||||||
* @param ir the infrared sensor
|
* @param ir the infrared sensor
|
||||||
@ -230,7 +224,7 @@ namespace sensors {
|
|||||||
//% blockNamespace=sensors
|
//% blockNamespace=sensors
|
||||||
//% weight=65 blockGap=8
|
//% weight=65 blockGap=8
|
||||||
//% group="Infrared Sensor"
|
//% group="Infrared Sensor"
|
||||||
proximity() {
|
proximity(): number {
|
||||||
this._setMode(IrSensorMode.Proximity)
|
this._setMode(IrSensorMode.Proximity)
|
||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
}
|
}
|
||||||
@ -246,7 +240,7 @@ namespace sensors {
|
|||||||
//% blockNamespace=sensors
|
//% blockNamespace=sensors
|
||||||
//% weight=65 blockGap=8
|
//% weight=65 blockGap=8
|
||||||
//% group="Infrared Sensor"
|
//% group="Infrared Sensor"
|
||||||
remoteCommand() {
|
remoteCommand(): number {
|
||||||
this._setMode(IrSensorMode.RemoteControl)
|
this._setMode(IrSensorMode.RemoteControl)
|
||||||
return this.getNumber(NumberFormat.UInt8LE, this.channel)
|
return this.getNumber(NumberFormat.UInt8LE, this.channel)
|
||||||
}
|
}
|
||||||
@ -276,7 +270,7 @@ namespace sensors {
|
|||||||
*/
|
*/
|
||||||
//% whenUsed block="center" weight=95 fixedInstance
|
//% whenUsed block="center" weight=95 fixedInstance
|
||||||
export const remoteButtonCenter = irButton(IrRemoteButton.CenterBeacon)
|
export const remoteButtonCenter = irButton(IrRemoteButton.CenterBeacon)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote top-left button.
|
* Remote top-left button.
|
||||||
*/
|
*/
|
15
libs/infrared-sensor/pxt.json
Normal file
15
libs/infrared-sensor/pxt.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "infrared-sensor",
|
||||||
|
"description": "Infrared Sensor support",
|
||||||
|
"files": [
|
||||||
|
"README.md",
|
||||||
|
"ir.ts"
|
||||||
|
],
|
||||||
|
"testFiles": [
|
||||||
|
"test.ts"
|
||||||
|
],
|
||||||
|
"public": true,
|
||||||
|
"dependencies": {
|
||||||
|
"core": "file:../core"
|
||||||
|
}
|
||||||
|
}
|
0
libs/infrared-sensor/test.ts
Normal file
0
libs/infrared-sensor/test.ts
Normal file
18
libs/music/piano.ts
Normal file
18
libs/music/piano.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
namespace music {
|
||||||
|
/**
|
||||||
|
* Get the frequency of a note.
|
||||||
|
* @param name the note name, eg: Note.C
|
||||||
|
*/
|
||||||
|
//% weight=1 help=music/note-frequency
|
||||||
|
//% blockId=device_note block="%note"
|
||||||
|
//% shim=TD_ID color="#FFFFFF" colorSecondary="#FFFFFF"
|
||||||
|
//% note.fieldEditor="note" note.defl="262"
|
||||||
|
//% note.fieldOptions.editorColour="#FF1493" note.fieldOptions.decompileLiterals=true
|
||||||
|
//% note.fieldOptions.minNote=52 note.fieldOptions.maxNote=75
|
||||||
|
//% useEnumVal=1
|
||||||
|
//% weight=10 blockGap=8
|
||||||
|
export function noteFrequency(name: Note): number {
|
||||||
|
//TODO fill in actual min/max note values
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@
|
|||||||
"shims.d.ts",
|
"shims.d.ts",
|
||||||
"melodies.ts",
|
"melodies.ts",
|
||||||
"music.ts",
|
"music.ts",
|
||||||
|
"piano.ts",
|
||||||
"sounds.jres",
|
"sounds.jres",
|
||||||
"sounds.ts",
|
"sounds.ts",
|
||||||
"ns.ts"
|
"ns.ts"
|
||||||
|
3
libs/touch-sensor/README.md
Normal file
3
libs/touch-sensor/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Touch sensor
|
||||||
|
|
||||||
|
The library to interact with the Touch Sensor.
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"TouchSensorEvent": "Touch sensor interactions",
|
||||||
|
"sensors.TouchSensor.isPressed": "Check if touch sensor is touched.",
|
||||||
|
"sensors.TouchSensor.onEvent": "Do something when a touch sensor is touched...",
|
||||||
|
"sensors.TouchSensor.onEvent|param|body": "code to run when the event is raised",
|
||||||
|
"sensors.TouchSensor.waitUntil": "Wait until the touch sensor is touched",
|
||||||
|
"sensors.TouchSensor.wasPressed": "Check if touch sensor is touched since it was last checked."
|
||||||
|
}
|
15
libs/touch-sensor/_locales/touch-sensor-strings.json
Normal file
15
libs/touch-sensor/_locales/touch-sensor-strings.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"TouchSensorEvent.Bumped|block": "bumped",
|
||||||
|
"TouchSensorEvent.Pressed|block": "pressed",
|
||||||
|
"TouchSensorEvent.Released|block": "released",
|
||||||
|
"sensors.TouchSensor.isPressed|block": "`icons.touchSensor` %sensor|is pressed",
|
||||||
|
"sensors.TouchSensor.onEvent|block": "on `icons.touchSensor` %sensor|%event",
|
||||||
|
"sensors.TouchSensor.waitUntil|block": "wait until `icons.touchSensor` %sensor|%event",
|
||||||
|
"sensors.TouchSensor.wasPressed|block": "`icons.touchSensor` %sensor|was pressed",
|
||||||
|
"sensors.touchSensor1|block": "1",
|
||||||
|
"sensors.touchSensor2|block": "2",
|
||||||
|
"sensors.touchSensor3|block": "3",
|
||||||
|
"sensors.touchSensor4|block": "4",
|
||||||
|
"{id:category}Sensors": "Sensors",
|
||||||
|
"{id:group}Touch Sensor": "Touch Sensor"
|
||||||
|
}
|
15
libs/touch-sensor/docs/reference/sensors/touch-sensor.md
Normal file
15
libs/touch-sensor/docs/reference/sensors/touch-sensor.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Touch Sensor
|
||||||
|
|
||||||
|
```cards
|
||||||
|
sensors.touchSensor1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||||
|
brick.showImage(images.expressionsBigSmile)
|
||||||
|
})
|
||||||
|
sensors.touchSensor1.isPressed();
|
||||||
|
sensors.touchSensor1.wasPressed();
|
||||||
|
```
|
||||||
|
|
||||||
|
## See Also
|
||||||
|
|
||||||
|
[on Event](/reference/sensors/touch-sensor/on-event),
|
||||||
|
[is pressed](reference/sensors/touch-sensor/is-pressed),
|
||||||
|
[was pressed](reference/sensors/touch-sensor/was-pressed)
|
@ -0,0 +1,11 @@
|
|||||||
|
# is Pressed
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
loops.forever(function () {
|
||||||
|
if (sensors.touchSensor1.isPressed()) {
|
||||||
|
brick.setStatusLight(LightsPattern.Green)
|
||||||
|
} else {
|
||||||
|
brick.setStatusLight(LightsPattern.Orange)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
@ -0,0 +1,16 @@
|
|||||||
|
# On Event
|
||||||
|
|
||||||
|
```sig
|
||||||
|
sensors.touchSensor1.onEvent(TouchSensorEvent.Released, function () { })
|
||||||
|
```
|
||||||
|
|
||||||
|
# Parameters
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
sensors.touchSensor1.onEvent(TouchSensorEvent.Released, function () {
|
||||||
|
brick.showImage(images.expressionsSick)
|
||||||
|
})
|
||||||
|
```
|
@ -0,0 +1,11 @@
|
|||||||
|
# was Pressed
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
loops.forever(function () {
|
||||||
|
if (sensors.touchSensor1.wasPressed()) {
|
||||||
|
brick.setStatusLight(LightsPattern.Green)
|
||||||
|
} else {
|
||||||
|
brick.setStatusLight(LightsPattern.Orange)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
15
libs/touch-sensor/pxt.json
Normal file
15
libs/touch-sensor/pxt.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "touch-sensor",
|
||||||
|
"description": "Touch Sensor support",
|
||||||
|
"files": [
|
||||||
|
"README.md",
|
||||||
|
"touch.ts"
|
||||||
|
],
|
||||||
|
"testFiles": [
|
||||||
|
"test.ts"
|
||||||
|
],
|
||||||
|
"public": true,
|
||||||
|
"dependencies": {
|
||||||
|
"core": "file:../core"
|
||||||
|
}
|
||||||
|
}
|
8
libs/touch-sensor/test.ts
Normal file
8
libs/touch-sensor/test.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
sensors.touchSensor1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||||
|
})
|
||||||
|
sensors.touchSensor2.onEvent(TouchSensorEvent.Bumped, function () {
|
||||||
|
})
|
||||||
|
sensors.touchSensor3.onEvent(TouchSensorEvent.Released, function () {
|
||||||
|
})
|
||||||
|
sensors.touchSensor4.isPressed();
|
||||||
|
sensors.touchSensor4.wasPressed();
|
@ -41,7 +41,7 @@ namespace sensors {
|
|||||||
* @param event the kind of button gesture that needs to be detected
|
* @param event the kind of button gesture that needs to be detected
|
||||||
* @param body code to run when the event is raised
|
* @param body code to run when the event is raised
|
||||||
*/
|
*/
|
||||||
//% help=input/touch/on-event
|
//% help=input/touch-sensor/on-event
|
||||||
//% blockId=touchEvent block="on `icons.touchSensor` %sensor|%event"
|
//% blockId=touchEvent block="on `icons.touchSensor` %sensor|%event"
|
||||||
//% parts="touch"
|
//% parts="touch"
|
||||||
//% blockNamespace=sensors
|
//% blockNamespace=sensors
|
||||||
@ -51,20 +51,50 @@ namespace sensors {
|
|||||||
this.button.onEvent(<ButtonEvent><number>ev, body)
|
this.button.onEvent(<ButtonEvent><number>ev, body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wait until the touch sensor is touched
|
||||||
|
* @param sensor the touch sensor that needs to be clicked or used
|
||||||
|
* @param event the kind of button gesture that needs to be detected
|
||||||
|
*/
|
||||||
|
//% help=input/touch-sensor/wait-until
|
||||||
|
//% blockId=touchWaitUntil block="wait until `icons.touchSensor` %sensor|%event"
|
||||||
|
//% parts="touch"
|
||||||
|
//% blockNamespace=sensors
|
||||||
|
//% weight=98 blockGap=8
|
||||||
|
//% group="Touch Sensor"
|
||||||
|
waitUntil(ev: TouchSensorEvent) {
|
||||||
|
this.button.waitUntil(<ButtonEvent><number>ev);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if touch sensor is touched.
|
* Check if touch sensor is touched.
|
||||||
* @param sensor the port to query the request
|
* @param sensor the port to query the request
|
||||||
*/
|
*/
|
||||||
//% help=input/touch/is-touched
|
//% help=input/touch-sensor/is-pressed
|
||||||
//% block="`icons.touchSensor` %sensor|is touched"
|
//% block="`icons.touchSensor` %sensor|is pressed"
|
||||||
//% blockId=touchIsTouched
|
//% blockId=touchIsPressed
|
||||||
//% parts="touch"
|
//% parts="touch"
|
||||||
//% blockNamespace=sensors
|
//% blockNamespace=sensors
|
||||||
//% weight=81 blockGap=8
|
//% weight=81 blockGap=8
|
||||||
//% group="Touch Sensor"
|
//% group="Touch Sensor"
|
||||||
isTouched() {
|
isPressed() {
|
||||||
return this.button.isPressed();
|
return this.button.isPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if touch sensor is touched since it was last checked.
|
||||||
|
* @param sensor the port to query the request
|
||||||
|
*/
|
||||||
|
//% help=input/touch-sensor/was-pressed
|
||||||
|
//% block="`icons.touchSensor` %sensor|was pressed"
|
||||||
|
//% blockId=touchWasPressed
|
||||||
|
//% parts="touch"
|
||||||
|
//% blockNamespace=sensors
|
||||||
|
//% weight=81 blockGap=8
|
||||||
|
//% group="Touch Sensor"
|
||||||
|
wasPressed() {
|
||||||
|
return this.button.wasPressed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//% whenUsed block="1" weight=95 fixedInstance
|
//% whenUsed block="1" weight=95 fixedInstance
|
3
libs/ultrasonic-sensor/README.md
Normal file
3
libs/ultrasonic-sensor/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Ultrasonic sensor
|
||||||
|
|
||||||
|
The library to interact with the Ultrasonic Sensor.
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"sensors.UltraSonicSensor.distance": "Gets the distance from the sonar in centimeters",
|
||||||
|
"sensors.UltraSonicSensor.onEvent": "Registers code to run when the given color is close",
|
||||||
|
"sensors.UltraSonicSensor.onEvent|param|handler": "the code to run when detected",
|
||||||
|
"sensors.UltraSonicSensor.waitUntil": "Waits for the event to occur"
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"UltrasonicSensorEvent.ObjectDetected|block": "object detected",
|
||||||
|
"UltrasonicSensorEvent.ObjectFar|block": "object far",
|
||||||
|
"UltrasonicSensorEvent.ObjectNear|block": "object near",
|
||||||
|
"sensors.UltraSonicSensor.distance|block": "`icons.ultrasonicSensor` %sensor|distance",
|
||||||
|
"sensors.UltraSonicSensor.onEvent|block": "on `icons.ultrasonicSensor` %sensor|%event",
|
||||||
|
"sensors.UltraSonicSensor.waitUntil|block": "wait until `icons.ultrasonicSensor` %sensor| %event",
|
||||||
|
"sensors.ultrasonic1|block": "1",
|
||||||
|
"sensors.ultrasonic2|block": "2",
|
||||||
|
"sensors.ultrasonic3|block": "3",
|
||||||
|
"sensors.ultrasonic4|block": "4",
|
||||||
|
"{id:category}Sensors": "Sensors",
|
||||||
|
"{id:group}Ultrasonic Sensor": "Ultrasonic Sensor"
|
||||||
|
}
|
15
libs/ultrasonic-sensor/pxt.json
Normal file
15
libs/ultrasonic-sensor/pxt.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "ultrasonic-sensor",
|
||||||
|
"description": "Ultrasonic Sensor support",
|
||||||
|
"files": [
|
||||||
|
"README.md",
|
||||||
|
"ultrasonic.ts"
|
||||||
|
],
|
||||||
|
"testFiles": [
|
||||||
|
"test.ts"
|
||||||
|
],
|
||||||
|
"public": true,
|
||||||
|
"dependencies": {
|
||||||
|
"core": "file:../core"
|
||||||
|
}
|
||||||
|
}
|
0
libs/ultrasonic-sensor/test.ts
Normal file
0
libs/ultrasonic-sensor/test.ts
Normal file
@ -1,20 +1,22 @@
|
|||||||
const enum UltrasonicSensorEvent {
|
enum UltrasonicSensorEvent {
|
||||||
//% block="object near"
|
|
||||||
ObjectNear = 1,
|
|
||||||
//% block="object detected"
|
//% block="object detected"
|
||||||
ObjectDetected = 2
|
ObjectDetected = 10,
|
||||||
|
//% block="object near"
|
||||||
|
ObjectNear = sensors.internal.ThresholdState.Low,
|
||||||
|
//% block="object far"
|
||||||
|
ObjectFar = sensors.internal.ThresholdState.High
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace sensors {
|
namespace sensors {
|
||||||
|
|
||||||
//% fixedInstances
|
//% fixedInstances
|
||||||
export class UltraSonicSensor extends internal.UartSensor {
|
export class UltraSonicSensor extends internal.UartSensor {
|
||||||
private promixityThreshold: number;
|
private promixityThreshold: sensors.internal.ThresholdDetector;
|
||||||
private movementThreshold: number;
|
private movementThreshold: number;
|
||||||
|
|
||||||
constructor(port: number) {
|
constructor(port: number) {
|
||||||
super(port)
|
super(port)
|
||||||
this.promixityThreshold = 10;
|
this.promixityThreshold = new sensors.internal.ThresholdDetector(this.id(), 0, 255, 10, 100); // range is 0..255cm
|
||||||
this.movementThreshold = 1;
|
this.movementThreshold = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,12 +30,11 @@ namespace sensors {
|
|||||||
|
|
||||||
_update(prev: number, curr: number) {
|
_update(prev: number, curr: number) {
|
||||||
// is there an object near?
|
// is there an object near?
|
||||||
if (prev >= this.promixityThreshold && curr < this.promixityThreshold)
|
this.promixityThreshold.setLevel(curr);
|
||||||
control.raiseEvent(this._id, UltrasonicSensorEvent.ObjectNear); // TODO proper HI-LO sensor
|
|
||||||
|
|
||||||
// did something change?
|
// did something change?
|
||||||
if (Math.abs(prev - curr) > this.movementThreshold)
|
if (Math.abs(prev - curr) > this.movementThreshold)
|
||||||
control.raiseEvent(this._id, UltrasonicSensorEvent.ObjectDetected); // TODO debouncing
|
control.raiseEvent(this._id, UltrasonicSensorEvent.ObjectDetected);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,29 +48,26 @@ namespace sensors {
|
|||||||
//% blockNamespace=sensors
|
//% blockNamespace=sensors
|
||||||
//% weight=100 blockGap=8
|
//% weight=100 blockGap=8
|
||||||
//% group="Ultrasonic Sensor"
|
//% group="Ultrasonic Sensor"
|
||||||
on(event: UltrasonicSensorEvent, handler: () => void) {
|
onEvent(event: UltrasonicSensorEvent, handler: () => void) {
|
||||||
control.onEvent(this._id, event, handler);
|
control.onEvent(this._id, event, handler);
|
||||||
if (event == UltrasonicSensorEvent.ObjectNear
|
|
||||||
&& this.distance() < this.promixityThreshold)
|
|
||||||
control.runInBackground(handler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits for the event to occur
|
* Waits for the event to occur
|
||||||
*/
|
*/
|
||||||
//% help=input/ultrasonic/wait
|
//% help=input/ultrasonic/wait
|
||||||
//% block="wait `icons.ultrasonicSensor` %sensor|for %event"
|
//% block="wait until `icons.ultrasonicSensor` %sensor| %event"
|
||||||
//% blockId=ultrasonicWait
|
//% blockId=ultrasonicWait
|
||||||
//% parts="ultrasonicsensor"
|
//% parts="ultrasonicsensor"
|
||||||
//% blockNamespace=sensors
|
//% blockNamespace=sensors
|
||||||
//% weight=99 blockGap=8
|
//% weight=99 blockGap=8
|
||||||
//% group="Ultrasonic Sensor"
|
//% group="Ultrasonic Sensor"
|
||||||
wait(event: UltrasonicSensorEvent) {
|
waitUntil(event: UltrasonicSensorEvent) {
|
||||||
// TODO
|
control.waitForEvent(this._id, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the distance from the sonar in millimeters
|
* Gets the distance from the sonar in centimeters
|
||||||
* @param sensor the ultrasonic sensor port
|
* @param sensor the ultrasonic sensor port
|
||||||
*/
|
*/
|
||||||
//% help=input/ultrasonic/distance
|
//% help=input/ultrasonic/distance
|
||||||
@ -79,10 +77,10 @@ namespace sensors {
|
|||||||
//% blockNamespace=sensors
|
//% blockNamespace=sensors
|
||||||
//% weight=65 blockGap=8
|
//% weight=65 blockGap=8
|
||||||
//% group="Ultrasonic Sensor"
|
//% group="Ultrasonic Sensor"
|
||||||
distance() {
|
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;
|
return this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff; // range is 0..255
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pxt-ev3",
|
"name": "pxt-ev3",
|
||||||
"version": "0.0.33",
|
"version": "0.0.35",
|
||||||
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
|
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
|
||||||
"private": true,
|
"private": true,
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@ -39,8 +39,8 @@
|
|||||||
"semantic-ui-less": "^2.2.4"
|
"semantic-ui-less": "^2.2.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pxt-common-packages": "0.14.3",
|
"pxt-common-packages": "0.14.5",
|
||||||
"pxt-core": "2.3.28"
|
"pxt-core": "2.3.31"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
||||||
|
@ -10,6 +10,10 @@
|
|||||||
"libs/base",
|
"libs/base",
|
||||||
"libs/core",
|
"libs/core",
|
||||||
"libs/music",
|
"libs/music",
|
||||||
|
"libs/color-sensor",
|
||||||
|
"libs/touch-sensor",
|
||||||
|
"libs/ultrasonic-sensor",
|
||||||
|
"libs/infrared-sensor",
|
||||||
"libs/ev3"
|
"libs/ev3"
|
||||||
],
|
],
|
||||||
"simulator": {
|
"simulator": {
|
||||||
|
Reference in New Issue
Block a user