Compare commits
47 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 | |||
79fcd1c01e | |||
2d48725c63 | |||
802c3db0ba | |||
4a7e8c5fa8 | |||
0ebffd8549 | |||
988a2b638b | |||
fb743dea74 | |||
e400637ba1 | |||
b2768b1099 | |||
ead69e3c6e |
@ -4,5 +4,12 @@ Here are some fun programs for your @boardname@!
|
||||
|
||||
## Fun stuff
|
||||
|
||||
|
||||
Coming soon.
|
||||
```codecard
|
||||
[
|
||||
{
|
||||
"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
|
||||
|
||||
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 {
|
||||
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
|
||||
const rbfTemplate = `
|
||||
4c45474f580000006d000100000000001c000000000000000e000000821b038405018130813e8053
|
||||
@ -19,6 +26,7 @@ namespace pxt.editor {
|
||||
return pxt.HF2.mkPacketIOAsync()
|
||||
.then(h => {
|
||||
let w = new Ev3Wrapper(h)
|
||||
ev3 = w
|
||||
return w.reconnectAsync(true)
|
||||
.then(() => w)
|
||||
})
|
||||
|
@ -252,6 +252,13 @@ namespace pxt.editor {
|
||||
return loop()
|
||||
}
|
||||
|
||||
|
||||
downloadFileAsync(path: string, cb: (d: Uint8Array) => void) {
|
||||
return this.lock.enqueue("file", () =>
|
||||
this.streamFileOnceAsync(path, cb))
|
||||
}
|
||||
|
||||
|
||||
private initAsync() {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
@ -144,6 +144,12 @@
|
||||
"loops.pause|param|ms": "how long to pause for, eg: 100, 200, 500, 1000, 2000",
|
||||
"loops.timePicker": "Get the time field editor",
|
||||
"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.",
|
||||
"serial": "Reading and writing data over a serial connection.",
|
||||
"serial.writeBuffer": "Send a buffer across the serial connection.",
|
||||
|
@ -17,7 +17,8 @@
|
||||
"control.cpp",
|
||||
"control.ts",
|
||||
"serial.cpp",
|
||||
"serial.ts"
|
||||
"serial.ts",
|
||||
"loops.ts"
|
||||
],
|
||||
"testFiles": [
|
||||
"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,19 +14,22 @@
|
||||
"MMap.setNumber": "Write a number in specified format in the buffer.",
|
||||
"MMap.slice": "Read a range of bytes into a buffer.",
|
||||
"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.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|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._imagePicker": "An image",
|
||||
"brick._imagePicker|param|image": "the image",
|
||||
"brick.buttonDown": "Down button on the EV3 Brick.",
|
||||
"brick.buttonEnter": "Enter button on the EV3 Brick.",
|
||||
"brick.buttonLeft": "Left button on the EV3 Brick.",
|
||||
"brick.buttonRight": "Right button on the EV3 Brick.",
|
||||
"brick.buttonUp": "Up button on the EV3 Brick.",
|
||||
"brick.pattern": "Pattern block.",
|
||||
"brick.pattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green",
|
||||
"brick.lightPattern": "Pattern block.",
|
||||
"brick.lightPattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green",
|
||||
"brick.print": "Show text on the screen.",
|
||||
"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",
|
||||
@ -37,6 +40,8 @@
|
||||
"brick.setPixel|param|y": "the starting position's x coordinate, eg: 0",
|
||||
"brick.setStatusLight": "Set lights.",
|
||||
"brick.setStatusLight|param|pattern": "the lights pattern to use.",
|
||||
"brick.showImage": "Shows an image on screen",
|
||||
"brick.showImage|param|image": "image to draw",
|
||||
"control": "Program controls and events.",
|
||||
"control.allocateNotifyEvent": "Allocates the next user notification event",
|
||||
"control.deviceFirmwareVersion": "Determine the version of system software currently running.",
|
||||
@ -65,35 +70,8 @@
|
||||
"screen.clear": "Clear screen and reset font to normal.",
|
||||
"screen.imageOf": "Makes an image bound to a buffer.",
|
||||
"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.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.writeDmesg": "Send DMESG debug buffer over serial."
|
||||
}
|
@ -2,16 +2,6 @@
|
||||
"ButtonEvent.Click|block": "click",
|
||||
"ButtonEvent.Down|block": "down",
|
||||
"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.GreenPulse|block": "Pulsing Green",
|
||||
"LightsPattern.Green|block": "Green",
|
||||
@ -27,23 +17,21 @@
|
||||
"Output.B|block": "B",
|
||||
"Output.C|block": "C",
|
||||
"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.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._imagePicker|block": "%image",
|
||||
"brick.buttonDown|block": "down",
|
||||
"brick.buttonEnter|block": "enter",
|
||||
"brick.buttonLeft|block": "left",
|
||||
"brick.buttonRight|block": "right",
|
||||
"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.setPixel|block": "`icons.brickDisplay` set pixel %on| at x: %x| y: %y",
|
||||
"brick.setStatusLight|block": "set `icons.brickButtons` to %pattern=led_pattern",
|
||||
"brick.showImage|block": "`icons.brickDisplay` show image %image=scren_image_picker",
|
||||
"brick|block": "brick",
|
||||
"control.raiseEvent|block": "raise event|from %src|with value %value",
|
||||
"control|block": "control",
|
||||
@ -67,50 +55,12 @@
|
||||
"motors|block": "motors",
|
||||
"output|block": "output",
|
||||
"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.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.gyro2|block": "2",
|
||||
"sensors.gyro3|block": "3",
|
||||
"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",
|
||||
"{id:category}Brick": "Brick",
|
||||
"{id:category}Control": "Control",
|
||||
@ -123,13 +73,8 @@
|
||||
"{id:category}Sensors": "Sensors",
|
||||
"{id:category}Serial": "Serial",
|
||||
"{id:group}Buttons": "Buttons",
|
||||
"{id:group}Color Sensor": "Color Sensor",
|
||||
"{id:group}Gyro Sensor": "Gyro Sensor",
|
||||
"{id:group}Infrared Sensor": "Infrared Sensor",
|
||||
"{id:group}Light": "Light",
|
||||
"{id:group}Motors": "Motors",
|
||||
"{id:group}Remote Infrared Beacon": "Remote Infrared Beacon",
|
||||
"{id:group}Screen": "Screen",
|
||||
"{id:group}Touch Sensor": "Touch Sensor",
|
||||
"{id:group}Ultrasonic Sensor": "Ultrasonic Sensor"
|
||||
"{id:group}Screen": "Screen"
|
||||
}
|
@ -4,34 +4,34 @@
|
||||
*/
|
||||
const enum LightsPattern {
|
||||
//% block=Off enumval=0
|
||||
//% blockIdentity=output.pattern
|
||||
//% blockIdentity=brick.lightPattern
|
||||
Off = 0,
|
||||
//% block=Green enumval=1
|
||||
//% blockIdentity=output.pattern
|
||||
//% blockIdentity=brick.lightPattern
|
||||
Green = 1,
|
||||
//% block=Red enumval=2
|
||||
//% blockIdentity=output.pattern
|
||||
//% blockIdentity=brick.lightPattern
|
||||
Red = 2,
|
||||
//% block=Orange enumval=3
|
||||
//% blockIdentity=output.pattern
|
||||
//% blockIdentity=brick.lightPattern
|
||||
Orange = 3,
|
||||
//% block="Flashing Green" enumval=4
|
||||
//% blockIdentity=output.pattern
|
||||
//% blockIdentity=brick.lightPattern
|
||||
GreenFlash = 4,
|
||||
//% block="Flashing Red" enumval=5
|
||||
//% blockIdentity=output.pattern
|
||||
//% blockIdentity=brick.lightPattern
|
||||
RedFlash = 5,
|
||||
//% block="Flashing Orange" enumval=6
|
||||
//% blockIdentity=output.pattern
|
||||
//% blockIdentity=brick.lightPattern
|
||||
OrangeFlash = 6,
|
||||
//% block="Pulsing Green" enumval=7
|
||||
//% blockIdentity=output.pattern
|
||||
//% blockIdentity=brick.lightPattern
|
||||
GreenPulse = 7,
|
||||
//% block="Pulsing Red" enumval=8
|
||||
//% blockIdentity=output.pattern
|
||||
//% blockIdentity=brick.lightPattern
|
||||
RedPulse = 8,
|
||||
//% block="Pulsing Orange" enumval=9
|
||||
//% blockIdentity=output.pattern
|
||||
//% blockIdentity=brick.lightPattern
|
||||
OrangePulse = 9,
|
||||
}
|
||||
|
||||
@ -69,13 +69,14 @@ namespace brick {
|
||||
if (this._isPressed == curr) return
|
||||
this._isPressed = curr
|
||||
if (curr) {
|
||||
this._wasPressed = true;
|
||||
this.downTime = control.millis()
|
||||
control.raiseEvent(this._id, ButtonEvent.Down)
|
||||
} else {
|
||||
control.raiseEvent(this._id, ButtonEvent.Up)
|
||||
let delta = control.millis() - this.downTime
|
||||
const delta = control.millis() - this.downTime;
|
||||
if (delta < 500)
|
||||
control.raiseEvent(this._id, ButtonEvent.Click)
|
||||
//control.raiseEvent(this._id, delta > 500 ? ButtonEvent.LongClick : ButtonEvent.Click)
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,6 +127,20 @@ namespace brick {
|
||||
onEvent(ev: ButtonEvent, body: () => void) {
|
||||
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"
|
||||
//% shim=TD_ID colorSecondary="#6e9a36" group="Light"
|
||||
//% blockHidden=true useEnumVal=1 pattern.fieldOptions.decompileLiterals=1
|
||||
export function pattern(pattern: LightsPattern): number {
|
||||
export function lightPattern(pattern: LightsPattern): number {
|
||||
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
|
||||
}
|
||||
|
||||
getId() {
|
||||
id() {
|
||||
return this._id;
|
||||
}
|
||||
}
|
||||
|
@ -132,26 +132,26 @@ namespace sensors.internal {
|
||||
}
|
||||
|
||||
export class Sensor extends control.Component {
|
||||
protected port: number // this is 0-based
|
||||
protected _port: number // this is 0-based
|
||||
|
||||
constructor(port_: number) {
|
||||
super()
|
||||
if (!(1 <= port_ && port_ <= DAL.NUM_INPUTS))
|
||||
control.panic(120)
|
||||
this.port = port_ - 1
|
||||
this._port = port_ - 1
|
||||
init()
|
||||
sensorInfos[this.port].sensors.push(this)
|
||||
sensorInfos[this._port].sensors.push(this)
|
||||
}
|
||||
|
||||
_activated() { }
|
||||
|
||||
// 1-based
|
||||
getPort() {
|
||||
return this.port + 1
|
||||
port() {
|
||||
return this._port + 1
|
||||
}
|
||||
|
||||
isActive() {
|
||||
return sensorInfos[this.port].sensor == this
|
||||
return sensorInfos[this._port].sensor == this
|
||||
}
|
||||
|
||||
_query() {
|
||||
@ -173,11 +173,85 @@ namespace sensors.internal {
|
||||
|
||||
_readPin6() {
|
||||
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 {
|
||||
protected mode: number // the mode user asked for
|
||||
@ -202,18 +276,18 @@ namespace sensors.internal {
|
||||
if (!this.isActive()) return
|
||||
if (this.realmode != this.mode) {
|
||||
this.realmode = v
|
||||
setUartMode(this.port, v)
|
||||
setUartMode(this._port, v)
|
||||
}
|
||||
}
|
||||
|
||||
getBytes(): Buffer {
|
||||
return getUartBytes(this.isActive() ? this.port : -1)
|
||||
return getUartBytes(this.isActive() ? this._port : -1)
|
||||
}
|
||||
|
||||
getNumber(fmt: NumberFormat, off: number) {
|
||||
if (!this.isActive())
|
||||
return 0
|
||||
return getUartNumber(fmt, off, this.port)
|
||||
return getUartNumber(fmt, off, this._port)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <time.h>
|
||||
#include <cstdarg>
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <signal.h>
|
||||
@ -15,6 +14,8 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define THREAD_DBG(...)
|
||||
|
||||
void *operator new(size_t size) {
|
||||
return malloc(size);
|
||||
}
|
||||
@ -229,6 +230,8 @@ static void runAct(Thread *thr) {
|
||||
disposeThread(thr);
|
||||
}
|
||||
|
||||
static void mainThread(Thread *) {}
|
||||
|
||||
void setupThread(Action a, TValue arg = 0, void (*runner)(Thread *) = NULL, TValue d0 = 0,
|
||||
TValue d1 = 0) {
|
||||
if (runner == NULL)
|
||||
@ -242,8 +245,13 @@ void setupThread(Action a, TValue arg = 0, void (*runner)(Thread *) = NULL, TVal
|
||||
thr->data0 = incr(d0);
|
||||
thr->data1 = incr(d1);
|
||||
pthread_cond_init(&thr->waitCond, NULL);
|
||||
if (runner == mainThread) {
|
||||
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) {
|
||||
@ -263,8 +271,10 @@ void runForever(Action a) {
|
||||
}
|
||||
|
||||
void waitForEvent(int source, int value) {
|
||||
THREAD_DBG("waitForEv: %d %d", source, value);
|
||||
auto self = pthread_self();
|
||||
for (auto t = allThreads; t; t = t->next) {
|
||||
THREAD_DBG("t: %p", t);
|
||||
if (t->pid == self) {
|
||||
pthread_mutex_lock(&eventMutex);
|
||||
t->waitSource = source;
|
||||
@ -279,7 +289,8 @@ void waitForEvent(int source, int value) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
assert(0);
|
||||
DMESG("current thread not registered!");
|
||||
target_panic(901);
|
||||
}
|
||||
|
||||
static void dispatchEvent(Event &e) {
|
||||
@ -342,7 +353,8 @@ void raiseEvent(int id, int event) {
|
||||
auto e = mkEvent(id, event);
|
||||
pthread_mutex_lock(&eventMutex);
|
||||
if (eventTail == NULL) {
|
||||
assert(eventHead == NULL);
|
||||
if (eventHead != NULL)
|
||||
target_panic(902);
|
||||
eventHead = eventTail = e;
|
||||
} else {
|
||||
eventTail->next = e;
|
||||
@ -467,6 +479,7 @@ void initRuntime() {
|
||||
pthread_t disp;
|
||||
pthread_create(&disp, NULL, evtDispatcher, NULL);
|
||||
pthread_detach(disp);
|
||||
setupThread(0, 0, mainThread);
|
||||
target_init();
|
||||
screen_init();
|
||||
startUser();
|
||||
@ -508,4 +521,4 @@ void dmesg(const char *format, ...) {
|
||||
fflush(dmesgFile);
|
||||
fdatasync(fileno(dmesgFile));
|
||||
}
|
||||
}
|
||||
} // namespace pxt
|
||||
|
@ -97,7 +97,8 @@ namespace motors {
|
||||
power(power: number) {
|
||||
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)
|
||||
writePWM(b)
|
||||
if (power) {
|
||||
|
@ -18,11 +18,7 @@
|
||||
"output.ts",
|
||||
"core.ts",
|
||||
"input.ts",
|
||||
"ir.ts",
|
||||
"color.ts",
|
||||
"gyro.ts",
|
||||
"ultrasonic.ts",
|
||||
"touch.ts",
|
||||
"shims.d.ts",
|
||||
"enums.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);
|
||||
DMESG("map %p", mappedFrameBuffer);
|
||||
if (mappedFrameBuffer == MAP_FAILED) {
|
||||
target_panic(111);
|
||||
target_panic(903);
|
||||
}
|
||||
clear();
|
||||
|
||||
|
@ -133,6 +133,33 @@ namespace brick {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows an image on screen
|
||||
* @param image image to draw
|
||||
*/
|
||||
//% blockId=screen_show_image block="`icons.brickDisplay` show image %image=scren_image_picker"
|
||||
//% weight=95 group="Screen" blockGap=8
|
||||
export function showImage(image: Image, delay: number = 400) {
|
||||
if (!image) return;
|
||||
image.draw(0, 0, Draw.Normal);
|
||||
delay = Math.max(0, delay);
|
||||
if (delay > 0)
|
||||
loops.pause(delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* An image
|
||||
* @param image the image
|
||||
*/
|
||||
//% blockId=scren_image_picker block="%image" shim=TD_ID
|
||||
//% image.fieldEditor="imagedropdown"
|
||||
//% image.fieldOptions.columns=6
|
||||
//% block.fieldOptions.hasSearchBar=true
|
||||
//% group="Screen" weight=0 blockHidden=1
|
||||
export function _imagePicker(image: Image): Image {
|
||||
return image;
|
||||
}
|
||||
|
||||
export function drawRect(x: number, y: number, w: number, h: number, mode = Draw.Normal) {
|
||||
x |= 0;
|
||||
y |= 0;
|
||||
|
@ -8,7 +8,11 @@
|
||||
"dependencies": {
|
||||
"base": "file:../base",
|
||||
"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
|
||||
}
|
||||
|
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"
|
||||
}
|
@ -138,12 +138,12 @@ namespace sensors {
|
||||
//% fixedInstances
|
||||
export class InfraredSensor extends internal.UartSensor {
|
||||
private channel: IrRemoteChannel;
|
||||
private proximityThreshold: number;
|
||||
private proximityThreshold: sensors.internal.ThresholdDetector;
|
||||
|
||||
constructor(port: number) {
|
||||
super(port)
|
||||
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
|
||||
|
||||
// and set the mode, as otherwise button events won't work
|
||||
@ -154,10 +154,7 @@ namespace sensors {
|
||||
if (this.mode == IrSensorMode.RemoteControl)
|
||||
return mapButton(this.getNumber(NumberFormat.UInt8LE, this.channel));
|
||||
else if (this.mode == IrSensorMode.Proximity) {
|
||||
const d = this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff;
|
||||
return d < this.proximityThreshold ? UltrasonicSensorEvent.ObjectNear
|
||||
: d > this.proximityThreshold + 5 ? UltrasonicSensorEvent.ObjectDetected
|
||||
: 0;
|
||||
return this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff;
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@ -168,9 +165,8 @@ namespace sensors {
|
||||
let v = !!(curr & (1 << i))
|
||||
buttons[i]._update(v)
|
||||
}
|
||||
} else {
|
||||
if (curr)
|
||||
control.raiseEvent(this._id, curr);
|
||||
} else if (this.mode == IrSensorMode.Proximity) {
|
||||
this.proximityThreshold.setLevel(curr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,7 +177,7 @@ namespace sensors {
|
||||
setRemoteChannel(c: IrRemoteChannel) {
|
||||
c = Math.clamp(0, 3, c | 0)
|
||||
this.channel = c
|
||||
this._setMode(IrSensorMode.RemoteControl)
|
||||
this.setMode(IrSensorMode.RemoteControl)
|
||||
}
|
||||
|
||||
setMode(m: IrSensorMode) {
|
||||
@ -199,24 +195,22 @@ namespace sensors {
|
||||
//% blockNamespace=sensors
|
||||
//% weight=100 blockGap=8
|
||||
//% group="Infrared Sensor"
|
||||
on(event: InfraredSensorEvent, handler: () => void) {
|
||||
control.onEvent(this._id, InfraredSensorEvent.ObjectNear, handler);
|
||||
if ( this.proximity() == InfraredSensorEvent.ObjectNear)
|
||||
control.runInBackground(handler);
|
||||
onEvent(event: InfraredSensorEvent, handler: () => void) {
|
||||
control.onEvent(this._id, event, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for the event to occur
|
||||
*/
|
||||
//% help=input/ultrasonic/wait
|
||||
//% block="wait `icons.infraredSensor` %sensor|for %event"
|
||||
//% block="wait until `icons.infraredSensor` %sensor| %event"
|
||||
//% blockId=infraredwait
|
||||
//% parts="infraredsensor"
|
||||
//% blockNamespace=sensors
|
||||
//% weight=99 blockGap=8
|
||||
//% group="Infrared Sensor"
|
||||
wait(event: InfraredSensorEvent) {
|
||||
// TODO
|
||||
waitUntil(event: InfraredSensorEvent) {
|
||||
control.waitForEvent(this._id, event);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -230,7 +224,7 @@ namespace sensors {
|
||||
//% blockNamespace=sensors
|
||||
//% weight=65 blockGap=8
|
||||
//% group="Infrared Sensor"
|
||||
proximity() {
|
||||
proximity(): number {
|
||||
this._setMode(IrSensorMode.Proximity)
|
||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||
}
|
||||
@ -246,7 +240,7 @@ namespace sensors {
|
||||
//% blockNamespace=sensors
|
||||
//% weight=65 blockGap=8
|
||||
//% group="Infrared Sensor"
|
||||
remoteCommand() {
|
||||
remoteCommand(): number {
|
||||
this._setMode(IrSensorMode.RemoteControl)
|
||||
return this.getNumber(NumberFormat.UInt8LE, this.channel)
|
||||
}
|
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
@ -2,6 +2,8 @@
|
||||
"Sound.buffer": "Returns the underlaying Buffer object.",
|
||||
"Sound.play": "Play sound.",
|
||||
"music": "Generation of music tones.",
|
||||
"music._soundPicker": "A sound",
|
||||
"music._soundPicker|param|sound": "the sound",
|
||||
"music.beat": "Return the duration of a beat in milliseconds (the beat fraction).",
|
||||
"music.beat|param|fraction": "the fraction of the current whole note, eg: BeatFraction.Half",
|
||||
"music.changeTempoBy": "Change the tempo up or down by some amount of beats per minute (bpm).",
|
||||
@ -10,6 +12,8 @@
|
||||
"music.noteFrequency": "Get the frequency of a note.",
|
||||
"music.noteFrequency|param|name": "the note name, eg: Note.C",
|
||||
"music.playSound": "Start playing a sound and don't wait for it to finish.\nNotes are expressed as a string of characters with this format: NOTE[octave][:duration]",
|
||||
"music.playSoundEffect": "Plays a sound",
|
||||
"music.playSoundEffect|param|sound": "the sound to play",
|
||||
"music.playSoundUntilDone": "Play a sound and wait until the sound is done.\nNotes are expressed as a string of characters with this format: NOTE[octave][:duration]",
|
||||
"music.playSoundUntilDone|param|sound": "the melody to play, eg: music.sounds(Sounds.PowerUp)",
|
||||
"music.playSound|param|sound": "the melody to play, eg: music.sounds(Sounds.PowerUp)",
|
||||
|
@ -28,9 +28,11 @@
|
||||
"Sounds.PowerUp|block": "power up",
|
||||
"Sounds.Siren|block": "siren",
|
||||
"Sounds.Wawawawaa|block": "wawawawaa",
|
||||
"music._soundPicker|block": "%sound",
|
||||
"music.beat|block": "%fraction|beat",
|
||||
"music.changeTempoBy|block": "change tempo by %value|(bpm)",
|
||||
"music.noteFrequency|block": "%note",
|
||||
"music.playSoundEffect|block": "play %sound",
|
||||
"music.playSoundUntilDone|block": "play sound %sound=music_sounds|until done",
|
||||
"music.playSound|block": "play sound %sound=music_sounds",
|
||||
"music.playTone|block": "play tone|at %note=device_note|for %duration=device_beat",
|
||||
@ -42,6 +44,133 @@
|
||||
"music.stopAllSounds|block": "stop all sounds",
|
||||
"music.tempo|block": "tempo (bpm)",
|
||||
"music|block": "music",
|
||||
"sounds.animalsCatPurr|block": "Animals cat purr",
|
||||
"sounds.animalsDogBark1|block": "Animals dog bark 1",
|
||||
"sounds.animalsDogBark2|block": "Animals dog bark 2",
|
||||
"sounds.animalsDogGrowl|block": "Animals dog growl",
|
||||
"sounds.animalsDogSniff|block": "Animals dog sniff",
|
||||
"sounds.animalsDogWhine|block": "Animals dog whine",
|
||||
"sounds.animalsElephantCall|block": "Animals elephant call",
|
||||
"sounds.animalsInsectBuzz1|block": "Animals insect buzz1",
|
||||
"sounds.animalsInsectBuzz2|block": "Animals insect buzz2",
|
||||
"sounds.animalsInsectChirp|block": "Animals insect chirp",
|
||||
"sounds.animalsSnakeHiss|block": "Animals snake hiss",
|
||||
"sounds.animalsSnakeRattle|block": "Animals snake rattle",
|
||||
"sounds.animalsTRexRoar|block": "Animals trex roar",
|
||||
"sounds.colorsBlack|block": "Colors black",
|
||||
"sounds.colorsBlue|block": "Colors blue",
|
||||
"sounds.colorsBrown|block": "Colors brown",
|
||||
"sounds.colorsGreen|block": "Colors green",
|
||||
"sounds.colorsRed|block": "Colors red",
|
||||
"sounds.colorsWhite|block": "Colors white",
|
||||
"sounds.colorsYellow|block": "Colors yellow",
|
||||
"sounds.communicationBravo|block": "Communication bravo",
|
||||
"sounds.communicationEv3|block": "Communication ev3",
|
||||
"sounds.communicationFantastic|block": "Communication fantastic",
|
||||
"sounds.communicationGameOver|block": "Communication game over",
|
||||
"sounds.communicationGoodJob|block": "communicationGoodJob",
|
||||
"sounds.communicationGoodbye|block": "communication goodbye",
|
||||
"sounds.communicationGood|block": "communication good",
|
||||
"sounds.communicationGo|block": "Communication go",
|
||||
"sounds.communicationHello|block": "communication hello",
|
||||
"sounds.communicationHi|block": "communication hi",
|
||||
"sounds.communicationLego|block": "communication lego",
|
||||
"sounds.communicationMindstorms|block": "communication mindstorms",
|
||||
"sounds.communicationMorning|block": "communication morning",
|
||||
"sounds.communicationNo|block": "communication no",
|
||||
"sounds.communicationOkay|block": "communication okay",
|
||||
"sounds.communicationOkeyDokey|block": "communication okey dokey",
|
||||
"sounds.communicationSorry|block": "communication sorry",
|
||||
"sounds.communicationThankYou|block": "communication thank you",
|
||||
"sounds.communicationYes|block": "communication yes",
|
||||
"sounds.expressionsBoing|block": "expressions boing",
|
||||
"sounds.expressionsBoo|block": "expressions boo",
|
||||
"sounds.expressionsCheering|block": "expressions cheering",
|
||||
"sounds.expressionsCrunching|block": "expressions crunching",
|
||||
"sounds.expressionsCrying|block": "expressions crying",
|
||||
"sounds.expressionsFanfare|block": "expressions fanfare",
|
||||
"sounds.expressionsKungFu|block": "expressions kung fu",
|
||||
"sounds.expressionsLaughing1|block": "expressions laughing1",
|
||||
"sounds.expressionsLaughing2|block": "expressions laughing2",
|
||||
"sounds.expressionsMagicWand|block": "expressions magic wand",
|
||||
"sounds.expressionsOuch|block": "expressions ouch",
|
||||
"sounds.expressionsShouting|block": "expressions shouting",
|
||||
"sounds.expressionsSmack|block": "expressions smack",
|
||||
"sounds.expressionsSneezing|block": "expressions sneezing",
|
||||
"sounds.expressionsSnoring|block": "expressions snoring",
|
||||
"sounds.expressionsUhOh|block": "expressions uh oh",
|
||||
"sounds.informationActivate|block": "information activate",
|
||||
"sounds.informationAnalyze|block": "information analyze",
|
||||
"sounds.informationBackwards|block": "information backwards",
|
||||
"sounds.informationColor|block": "information color",
|
||||
"sounds.informationDetected|block": "information detected",
|
||||
"sounds.informationDown|block": "information down",
|
||||
"sounds.informationErrorAlarm|block": "information error alarm",
|
||||
"sounds.informationError|block": "information error",
|
||||
"sounds.informationFlashing|block": "information flashing",
|
||||
"sounds.informationForward|block": "information forward",
|
||||
"sounds.informationLeft|block": "information left",
|
||||
"sounds.informationObject|block": "information object",
|
||||
"sounds.informationRight|block": "information right",
|
||||
"sounds.informationSearching|block": "information searching",
|
||||
"sounds.informationStart|block": "information start",
|
||||
"sounds.informationStop|block": "information stop",
|
||||
"sounds.informationTouch|block": "information touch",
|
||||
"sounds.informationTurn|block": "information turn",
|
||||
"sounds.informationUp|block": "information up",
|
||||
"sounds.mechanicalAirRelease|block": "mechanical air release",
|
||||
"sounds.mechanicalAirbrake|block": "mechanical airbrake",
|
||||
"sounds.mechanicalBackingAlert|block": "mechanical backing alert",
|
||||
"sounds.mechanicalBlip1|block": "mechanical blip1",
|
||||
"sounds.mechanicalBlip2|block": "mechanical blip2",
|
||||
"sounds.mechanicalBlip3|block": "mechanical blip3",
|
||||
"sounds.mechanicalBlip4|block": "mechanical blip4",
|
||||
"sounds.mechanicalHorn1|block": "mechanical horn1",
|
||||
"sounds.mechanicalHorn2|block": "mechanical horn2",
|
||||
"sounds.mechanicalLaser|block": "mechanical laser",
|
||||
"sounds.mechanicalMotorIdle|block": "mechanical motor idle",
|
||||
"sounds.mechanicalMotorStart|block": "mechanical motor start",
|
||||
"sounds.mechanicalMotorStop|block": "mechanical motor stop",
|
||||
"sounds.mechanicalRatchet|block": "mechanical ratchet",
|
||||
"sounds.mechanicalSonar|block": "\"mechanical sonar\"",
|
||||
"sounds.mechanicalTickTack|block": "mechanical tick tack",
|
||||
"sounds.mechanicalWalk|block": "mechanical walk",
|
||||
"sounds.movementsArm1|block": "movements arm1",
|
||||
"sounds.movementsArm2|block": "movements arm2",
|
||||
"sounds.movementsArm3|block": "movements arm3",
|
||||
"sounds.movementsArm4|block": "movements arm4",
|
||||
"sounds.movementsDropLoad|block": "movements drop load",
|
||||
"sounds.movementsLiftLoad|block": "movements lift load",
|
||||
"sounds.movementsServo1|block": "movements servo1",
|
||||
"sounds.movementsServo2|block": "movements servo2",
|
||||
"sounds.movementsServo3|block": "movements servo3",
|
||||
"sounds.movementsServo4|block": "movements servo4",
|
||||
"sounds.movementsSlideLoad|block": "movements slide load",
|
||||
"sounds.movementsSnap|block": "movements snap",
|
||||
"sounds.movementsSpeedDown|block": "movements speed down",
|
||||
"sounds.movementsSpeedIdle|block": "movements speed idle",
|
||||
"sounds.movementsSpeedUp|block": "movements speed up",
|
||||
"sounds.movementsSpeeding|block": "movements speeding",
|
||||
"sounds.numbersEight|block": "numbers eight",
|
||||
"sounds.numbersFive|block": "numbers five",
|
||||
"sounds.numbersFour|block": "numbers four",
|
||||
"sounds.numbersNine|block": "numbers nine",
|
||||
"sounds.numbersOne|block": "numbers one",
|
||||
"sounds.numbersSeven|block": "numbers seven",
|
||||
"sounds.numbersSix|block": "numbers six",
|
||||
"sounds.numbersTen|block": "numbers ten",
|
||||
"sounds.numbersThree|block": "numbers three",
|
||||
"sounds.numbersTwo|block": "numbers two",
|
||||
"sounds.numbersZero|block": "numbers zero",
|
||||
"sounds.systemClick|block": "system click",
|
||||
"sounds.systemConfirm|block": "system confirm",
|
||||
"sounds.systemConnect|block": "system connect",
|
||||
"sounds.systemDownload|block": "system download",
|
||||
"sounds.systemGeneralAlert|block": "system general alert",
|
||||
"sounds.systemOverpower|block": "system overpower",
|
||||
"sounds.systemPowerDown|block": "system power down",
|
||||
"sounds.systemReady|block": "system ready",
|
||||
"sounds.systemStartUp|block": "S",
|
||||
"{id:category}Music": "Music",
|
||||
"{id:category}Sound": "Sound",
|
||||
"{id:category}Sounds": "Sounds"
|
||||
|
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",
|
||||
"melodies.ts",
|
||||
"music.ts",
|
||||
"piano.ts",
|
||||
"sounds.jres",
|
||||
"sounds.ts",
|
||||
"ns.ts"
|
||||
|
@ -1,256 +1,280 @@
|
||||
namespace sounds {
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Animals cat purr"
|
||||
export const animalsCatPurr = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Animals dog bark 1"
|
||||
export const animalsDogBark1 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Animals dog bark 2"
|
||||
export const animalsDogBark2 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Animals dog growl"
|
||||
export const animalsDogGrowl = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Animals dog sniff"
|
||||
export const animalsDogSniff = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Animals dog whine"
|
||||
export const animalsDogWhine = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Animals elephant call"
|
||||
export const animalsElephantCall = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Animals insect buzz1"
|
||||
export const animalsInsectBuzz1 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Animals insect buzz2"
|
||||
export const animalsInsectBuzz2 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Animals insect chirp"
|
||||
export const animalsInsectChirp = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Animals snake hiss"
|
||||
export const animalsSnakeHiss = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Animals snake rattle"
|
||||
export const animalsSnakeRattle = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Animals trex roar"
|
||||
export const animalsTRexRoar = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Colors black"
|
||||
export const colorsBlack = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Colors blue"
|
||||
export const colorsBlue = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Colors brown"
|
||||
export const colorsBrown = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Colors green"
|
||||
export const colorsGreen = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Colors red"
|
||||
export const colorsRed = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Colors white"
|
||||
export const colorsWhite = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Colors yellow"
|
||||
export const colorsYellow = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Communication bravo"
|
||||
export const communicationBravo = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Communication ev3"
|
||||
export const communicationEv3 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Communication fantastic"
|
||||
export const communicationFantastic = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Communication game over"
|
||||
export const communicationGameOver = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="Communication go"
|
||||
export const communicationGo = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="communicationGoodJob"
|
||||
export const communicationGoodJob = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="communication good"
|
||||
export const communicationGood = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="communication goodbye"
|
||||
export const communicationGoodbye = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="communication hello"
|
||||
export const communicationHello = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="communication hi"
|
||||
export const communicationHi = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="communication lego"
|
||||
export const communicationLego = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="communication mindstorms"
|
||||
export const communicationMindstorms = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="communication morning"
|
||||
export const communicationMorning = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="communication no"
|
||||
export const communicationNo = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="communication okay"
|
||||
export const communicationOkay = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="communication okey dokey"
|
||||
export const communicationOkeyDokey = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="communication sorry"
|
||||
export const communicationSorry = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="communication thank you"
|
||||
export const communicationThankYou = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="communication yes"
|
||||
export const communicationYes = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="expressions boing"
|
||||
export const expressionsBoing = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="expressions boo"
|
||||
export const expressionsBoo = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="expressions cheering"
|
||||
export const expressionsCheering = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="expressions crunching"
|
||||
export const expressionsCrunching = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="expressions crying"
|
||||
export const expressionsCrying = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="expressions fanfare"
|
||||
export const expressionsFanfare = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="expressions kung fu"
|
||||
export const expressionsKungFu = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="expressions laughing1"
|
||||
export const expressionsLaughing1 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="expressions laughing2"
|
||||
export const expressionsLaughing2 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="expressions magic wand"
|
||||
export const expressionsMagicWand = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="expressions ouch"
|
||||
export const expressionsOuch = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="expressions shouting"
|
||||
export const expressionsShouting = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="expressions smack"
|
||||
export const expressionsSmack = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="expressions sneezing"
|
||||
export const expressionsSneezing = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="expressions snoring"
|
||||
export const expressionsSnoring = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="expressions uh oh"
|
||||
export const expressionsUhOh = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information activate"
|
||||
export const informationActivate = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information analyze"
|
||||
export const informationAnalyze = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information backwards"
|
||||
export const informationBackwards = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information color"
|
||||
export const informationColor = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information detected"
|
||||
export const informationDetected = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information down"
|
||||
export const informationDown = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information error alarm"
|
||||
export const informationErrorAlarm = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information error"
|
||||
export const informationError = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information flashing"
|
||||
export const informationFlashing = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information forward"
|
||||
export const informationForward = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information left"
|
||||
export const informationLeft = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information object"
|
||||
export const informationObject = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information right"
|
||||
export const informationRight = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information searching"
|
||||
export const informationSearching = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information start"
|
||||
export const informationStart = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information stop"
|
||||
export const informationStop = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information touch"
|
||||
export const informationTouch = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information turn"
|
||||
export const informationTurn = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="information up"
|
||||
export const informationUp = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="mechanical air release"
|
||||
export const mechanicalAirRelease = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="mechanical airbrake"
|
||||
export const mechanicalAirbrake = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="mechanical backing alert"
|
||||
export const mechanicalBackingAlert = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="mechanical blip1"
|
||||
export const mechanicalBlip1 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="mechanical blip2"
|
||||
export const mechanicalBlip2 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="mechanical blip3"
|
||||
export const mechanicalBlip3 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="mechanical blip4"
|
||||
export const mechanicalBlip4 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="mechanical horn1"
|
||||
export const mechanicalHorn1 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="mechanical horn2"
|
||||
export const mechanicalHorn2 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="mechanical laser"
|
||||
export const mechanicalLaser = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="mechanical motor idle"
|
||||
export const mechanicalMotorIdle = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="mechanical motor start"
|
||||
export const mechanicalMotorStart = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="mechanical motor stop"
|
||||
export const mechanicalMotorStop = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="mechanical ratchet"
|
||||
export const mechanicalRatchet = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block='"mechanical sonar"'
|
||||
export const mechanicalSonar = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="mechanical tick tack"
|
||||
export const mechanicalTickTack = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="mechanical walk"
|
||||
export const mechanicalWalk = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="movements arm1"
|
||||
export const movementsArm1 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="movements arm2"
|
||||
export const movementsArm2 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="movements arm3"
|
||||
export const movementsArm3 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="movements arm4"
|
||||
export const movementsArm4 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="movements drop load"
|
||||
export const movementsDropLoad = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="movements lift load"
|
||||
export const movementsLiftLoad = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="movements servo1"
|
||||
export const movementsServo1 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="movements servo2"
|
||||
export const movementsServo2 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="movements servo3"
|
||||
export const movementsServo3 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="movements servo4"
|
||||
export const movementsServo4 = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="movements slide load"
|
||||
export const movementsSlideLoad = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="movements snap"
|
||||
export const movementsSnap = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="movements speed down"
|
||||
export const movementsSpeedDown = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="movements speed idle"
|
||||
export const movementsSpeedIdle = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="movements speed up"
|
||||
export const movementsSpeedUp = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="movements speeding"
|
||||
export const movementsSpeeding = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="numbers eight"
|
||||
export const numbersEight = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="numbers five"
|
||||
export const numbersFive = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="numbers four"
|
||||
export const numbersFour = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="numbers nine"
|
||||
export const numbersNine = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="numbers one"
|
||||
export const numbersOne = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="numbers seven"
|
||||
export const numbersSeven = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="numbers six"
|
||||
export const numbersSix = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="numbers ten"
|
||||
export const numbersTen = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="numbers three"
|
||||
export const numbersThree = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="numbers two"
|
||||
export const numbersTwo = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="numbers zero"
|
||||
export const numbersZero = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="system click"
|
||||
export const systemClick = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="system confirm"
|
||||
export const systemConfirm = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="system connect"
|
||||
export const systemConnect = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="system download"
|
||||
export const systemDownload = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="system general alert"
|
||||
export const systemGeneralAlert = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="system overpower"
|
||||
export const systemOverpower = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="system power down"
|
||||
export const systemPowerDown = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block="system ready"
|
||||
export const systemReady = music.fromWAV(hex``);
|
||||
//% fixedInstance jres
|
||||
//% fixedInstance jres block=S
|
||||
export const systemStartUp = music.fromWAV(hex``);
|
||||
}
|
||||
|
||||
namespace music {
|
||||
/**
|
||||
* Plays a sound
|
||||
* @param sound the sound to play
|
||||
*/
|
||||
//% blockId=music_play_sound_effect block="play %sound"
|
||||
//% weight=98
|
||||
export function playSoundEffect(sound: Sound) {
|
||||
if (!sound) return;
|
||||
|
||||
sound.play();
|
||||
}
|
||||
|
||||
/**
|
||||
* A sound
|
||||
* @param sound the sound
|
||||
*/
|
||||
//% blockId=music_sound_picker block="%sound" shim=TD_ID
|
||||
//% weight=0 blockHidden=1
|
||||
export function _soundPicker(sound: Sound): Sound {
|
||||
return sound;
|
||||
}
|
||||
}
|
||||
|
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 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"
|
||||
//% parts="touch"
|
||||
//% blockNamespace=sensors
|
||||
@ -51,20 +51,50 @@ namespace sensors {
|
||||
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.
|
||||
* @param sensor the port to query the request
|
||||
*/
|
||||
//% help=input/touch/is-touched
|
||||
//% block="`icons.touchSensor` %sensor|is touched"
|
||||
//% blockId=touchIsTouched
|
||||
//% help=input/touch-sensor/is-pressed
|
||||
//% block="`icons.touchSensor` %sensor|is pressed"
|
||||
//% blockId=touchIsPressed
|
||||
//% parts="touch"
|
||||
//% blockNamespace=sensors
|
||||
//% weight=81 blockGap=8
|
||||
//% group="Touch Sensor"
|
||||
isTouched() {
|
||||
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
|
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 {
|
||||
//% block="object near"
|
||||
ObjectNear = 1,
|
||||
enum UltrasonicSensorEvent {
|
||||
//% 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 {
|
||||
|
||||
//% fixedInstances
|
||||
export class UltraSonicSensor extends internal.UartSensor {
|
||||
private promixityThreshold: number;
|
||||
private promixityThreshold: sensors.internal.ThresholdDetector;
|
||||
private movementThreshold: number;
|
||||
|
||||
constructor(port: number) {
|
||||
super(port)
|
||||
this.promixityThreshold = 10;
|
||||
this.promixityThreshold = new sensors.internal.ThresholdDetector(this.id(), 0, 255, 10, 100); // range is 0..255cm
|
||||
this.movementThreshold = 1;
|
||||
}
|
||||
|
||||
@ -28,12 +30,11 @@ namespace sensors {
|
||||
|
||||
_update(prev: number, curr: number) {
|
||||
// is there an object near?
|
||||
if (prev >= this.promixityThreshold && curr < this.promixityThreshold)
|
||||
control.raiseEvent(this._id, UltrasonicSensorEvent.ObjectNear); // TODO proper HI-LO sensor
|
||||
this.promixityThreshold.setLevel(curr);
|
||||
|
||||
// did something change?
|
||||
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
|
||||
//% weight=100 blockGap=8
|
||||
//% group="Ultrasonic Sensor"
|
||||
on(event: UltrasonicSensorEvent, handler: () => void) {
|
||||
onEvent(event: UltrasonicSensorEvent, handler: () => void) {
|
||||
control.onEvent(this._id, event, handler);
|
||||
if (event == UltrasonicSensorEvent.ObjectNear
|
||||
&& this.distance() < this.promixityThreshold)
|
||||
control.runInBackground(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for the event to occur
|
||||
*/
|
||||
//% help=input/ultrasonic/wait
|
||||
//% block="wait `icons.ultrasonicSensor` %sensor|for %event"
|
||||
//% block="wait until `icons.ultrasonicSensor` %sensor| %event"
|
||||
//% blockId=ultrasonicWait
|
||||
//% parts="ultrasonicsensor"
|
||||
//% blockNamespace=sensors
|
||||
//% weight=99 blockGap=8
|
||||
//% group="Ultrasonic Sensor"
|
||||
wait(event: UltrasonicSensorEvent) {
|
||||
// TODO
|
||||
waitUntil(event: UltrasonicSensorEvent) {
|
||||
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
|
||||
*/
|
||||
//% help=input/ultrasonic/distance
|
||||
@ -79,10 +77,10 @@ namespace sensors {
|
||||
//% blockNamespace=sensors
|
||||
//% weight=65 blockGap=8
|
||||
//% group="Ultrasonic Sensor"
|
||||
distance() {
|
||||
distance(): number {
|
||||
// it supposedly also has an inch mode, but we stick to cm
|
||||
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",
|
||||
"version": "0.0.30",
|
||||
"version": "0.0.35",
|
||||
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
|
||||
"private": true,
|
||||
"keywords": [
|
||||
@ -39,8 +39,8 @@
|
||||
"semantic-ui-less": "^2.2.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-common-packages": "0.14.2",
|
||||
"pxt-core": "2.3.27"
|
||||
"pxt-common-packages": "0.14.5",
|
||||
"pxt-core": "2.3.31"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
||||
|
@ -10,6 +10,10 @@
|
||||
"libs/base",
|
||||
"libs/core",
|
||||
"libs/music",
|
||||
"libs/color-sensor",
|
||||
"libs/touch-sensor",
|
||||
"libs/ultrasonic-sensor",
|
||||
"libs/infrared-sensor",
|
||||
"libs/ev3"
|
||||
],
|
||||
"simulator": {
|
||||
|
Reference in New Issue
Block a user