Compare commits

..

8 Commits

Author SHA1 Message Date
337d42287a 0.0.58 2018-01-09 22:14:43 -08:00
ce3383f1b7 Turn ratio field editor (#225)
* Turn ratio field editor (initial draft)

* Add field turn ratio editor

* Fix arrow rotation

* Fix left and right direction, remove unnecessary SVG circles.

* Update UI a little. add marker.

* updated math for turnratio angle

* slightly cuter

* cleanup

* consistent naming

* more cleanup

* fixing motor node issue

* updated package version
2018-01-09 22:05:26 -08:00
e51721303a Merge pull request #224 from Microsoft/fixportlabels
Fix port labels in the simulator.
2018-01-09 14:43:26 -08:00
50f6c77fdb Fix port labels in the simulator. Fixes #219 2018-01-09 14:43:01 -08:00
5ed0135124 cleaning up images (#223)
* cleaning up images

* extra comma
2018-01-09 12:51:44 -08:00
892a2d585f Thresholds (#222)
* add threshold blocks

* updated strings

* added gap

* reorg color/gyro blocks

* fixing sound names

* adding stop block

* fixing exanmples
2018-01-09 12:46:48 -08:00
9890f2340a Add no-drag class and set on synced motor labels. Fixes #213 (#221) 2018-01-09 12:04:37 -08:00
109b809909 Sort field port values. Fixes #212 (#220) 2018-01-09 12:01:42 -08:00
38 changed files with 290 additions and 358 deletions

View File

@ -14,7 +14,7 @@ function accelerate() {
} }
function update() { function update() {
brick.clearScreen() brick.clearScreen()
brick.printLine("speed: " + speed, 1) brick.showString("speed: " + speed, 1)
motors.largeBC.setSpeed(speed) motors.largeBC.setSpeed(speed)
} }
sensors.touch2.onEvent(TouchSensorEvent.Pressed, function () { sensors.touch2.onEvent(TouchSensorEvent.Pressed, function () {

View File

@ -7,5 +7,5 @@ loops.forever(function () {
}) })
motors.largeBC.setSpeed(-20); motors.largeBC.setSpeed(-20);
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear); sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
motors.stopAllMotors(); motors.largeBC.stop();
``` ```

View File

@ -9,5 +9,5 @@ loops.forever(function () {
}) })
motors.largeBC.setSpeed(-20); motors.largeBC.setSpeed(-20);
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear); sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
motors.stopAllMotors(); motors.largeBC.stop();
``` ```

View File

@ -4,10 +4,9 @@
let beep = false let beep = false
beep = true beep = true
control.runInBackground(function () { control.runInBackground(function () {
motors.largeB.setSpeed(-20) motors.largeBC.setSpeed(-20)
motors.largeC.setSpeed(-20)
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear) sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear)
motors.stopAllMotors() motors.largeBC.stop()
beep = false beep = false
}) })
control.runInBackground(function () { control.runInBackground(function () {

View File

@ -4,10 +4,11 @@
import { deployCoreAsync, initAsync } from "./deploy"; import { deployCoreAsync, initAsync } from "./deploy";
import { FieldPorts } from "./field_ports"; import { FieldPorts } from "./field_ports";
import { FieldImages } from "./field_images"; import { FieldImages } from "./field_images";
import {FieldSpeed} from "./field_speed"; import { FieldSpeed } from "./field_speed";
import { FieldBrickButtons } from "./field_brickbuttons"; import { FieldBrickButtons } from "./field_brickbuttons";
import { FieldTurnRatio } from "./field_turnratio";
pxt.editor.initExtensionsAsync = function (opts: pxt.editor.ExtensionOptions): Promise<pxt.editor.ExtensionResult> { pxt.editor.initExtensionsAsync = function(opts: pxt.editor.ExtensionOptions): Promise<pxt.editor.ExtensionResult> {
pxt.debug('loading pxt-ev3 target extensions...') pxt.debug('loading pxt-ev3 target extensions...')
updateBlocklyShape(); updateBlocklyShape();
const res: pxt.editor.ExtensionResult = { const res: pxt.editor.ExtensionResult = {
@ -23,6 +24,9 @@ pxt.editor.initExtensionsAsync = function (opts: pxt.editor.ExtensionOptions): P
}, { }, {
selector: "brickbuttons", selector: "brickbuttons",
editor: FieldBrickButtons editor: FieldBrickButtons
}, {
selector: "turnratio",
editor: FieldTurnRatio
}], }],
deployCoreAsync deployCoreAsync
}; };

View File

@ -24,6 +24,9 @@ export class FieldPorts extends Blockly.FieldDropdown implements Blockly.FieldCu
this.width_ = parseInt(options.width) || 300; this.width_ = parseInt(options.width) || 300;
} }
trimOptions_() {
}
/** /**
* Create a dropdown menu under the text. * Create a dropdown menu under the text.
* @private * @private
@ -42,7 +45,8 @@ export class FieldPorts extends Blockly.FieldDropdown implements Blockly.FieldCu
// Accessibility properties // Accessibility properties
contentDiv.setAttribute('role', 'menu'); contentDiv.setAttribute('role', 'menu');
contentDiv.setAttribute('aria-haspopup', 'true'); contentDiv.setAttribute('aria-haspopup', 'true');
const options = this.getOptions(); let options = this.getOptions();
options = options.sort();
for (let i = 0, option: any; option = options[i]; i++) { for (let i = 0, option: any; option = options[i]; i++) {
let content = (options[i] as any)[0]; // Human-readable text or image. let content = (options[i] as any)[0]; // Human-readable text or image.
const value = (options[i] as any)[1]; // Language-neutral value. const value = (options[i] as any)[1]; // Language-neutral value.

108
editor/field_turnratio.ts Normal file
View File

@ -0,0 +1,108 @@
/// <reference path="../node_modules/pxt-core/localtypings/blockly.d.ts"/>
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
export interface FieldTurnRatioOptions extends Blockly.FieldCustomOptions {
}
export class FieldTurnRatio extends Blockly.FieldSlider implements Blockly.FieldCustom {
public isFieldCustom_ = true;
private params: any;
private path_: SVGPathElement;
private reporter_: SVGTextElement;
/**
* Class for a color wheel field.
* @param {number|string} value The initial content of the field.
* @param {Function=} opt_validator An optional function that is called
* to validate any constraints on what the user entered. Takes the new
* text as an argument and returns either the accepted text, a replacement
* text, or null to abort the change.
* @extends {Blockly.FieldNumber}
* @constructor
*/
constructor(value_: any, params: FieldTurnRatioOptions, opt_validator?: Function) {
super(String(value_), '-100', '100', null, '10', 'TurnRatio', opt_validator);
this.params = params;
(this as any).sliderColor_ = '#a8aaa8';
}
static HALF = 80;
static HANDLE_RADIUS = 30;
static RADIUS = FieldTurnRatio.HALF - FieldTurnRatio.HANDLE_RADIUS - 1;
createLabelDom_(labelText: string) {
let labelContainer = document.createElement('div');
let svg = Blockly.utils.createSvgElement('svg', {
'xmlns': 'http://www.w3.org/2000/svg',
'xmlns:html': 'http://www.w3.org/1999/xhtml',
'xmlns:xlink': 'http://www.w3.org/1999/xlink',
'version': '1.1',
'height': (FieldTurnRatio.HALF + FieldTurnRatio.HANDLE_RADIUS + 10) + 'px',
'width': (FieldTurnRatio.HALF * 2) + 'px'
}, labelContainer);
let defs = Blockly.utils.createSvgElement('defs', {}, svg);
let marker = Blockly.utils.createSvgElement('marker', {
'id': 'head',
'orient': "auto",
'markerWidth': '2',
'markerHeight': '4',
'refX': '0.1', 'refY': '1.5'
}, defs);
let markerPath = Blockly.utils.createSvgElement('path', {
'd': 'M0,0 V3 L1.5,1.5 Z',
'fill': '#f12a21'
}, marker);
this.reporter_ = pxsim.svg.child(svg, "text", {
'x': FieldTurnRatio.HALF, 'y': 96,
'text-anchor': 'middle', 'alignment-baseline': 'middle',
'style': 'font-size: 50px',
'class': 'sim-text inverted number'
}) as SVGTextElement;
this.path_ = Blockly.utils.createSvgElement('path', {
'x1': FieldTurnRatio.HALF,
'y1': FieldTurnRatio.HALF,
'marker-end': 'url(#head)',
'style': 'fill: none; stroke: #f12a21; stroke-width: 10'
}, svg);
this.updateGraph_();
let readout = document.createElement('span');
readout.setAttribute('class', 'blocklyFieldSliderReadout');
return [labelContainer, readout];
};
updateGraph_() {
if (!this.path_) {
return;
}
let v = goog.math.clamp(parseFloat(this.getText()), -100, 100);
if (isNaN(v)) {
v = 0;
}
const x = goog.math.clamp(parseFloat(this.getText()), -100, 100) / 100;
const theta = x * Math.PI / 2;
const cx = FieldTurnRatio.HALF;
const cy = FieldTurnRatio.HALF - 14;
const gamma = Math.PI - 2 * theta;
const r = FieldTurnRatio.RADIUS;
const alpha = 0.2 + Math.abs(x) * 0.5;
const x1 = 0;
const y1 = r * alpha;
const y2 = r * Math.sin(Math.PI / 2 - theta);
const x2 = r * Math.cos(Math.PI / 2 - theta);
const y3 = y2 - r * alpha * Math.cos(2 * theta);
const x3 = x2 - r * alpha * Math.sin(2 * theta);
const d = `M ${cx} ${cy} C ${cx} ${cy - y1} ${cx + x3} ${cy - y3} ${cx + x2} ${cy - y2}`;
this.path_.setAttribute('d', d);
this.reporter_.textContent = `${v}`;
}
setReadout_(readout: Element, value: string) {
this.updateGraph_();
}
}

View File

@ -11,5 +11,8 @@
"sensors.ColorSensor.onLightChanged|param|handler": "the code to run when detected", "sensors.ColorSensor.onLightChanged|param|handler": "the code to run when detected",
"sensors.ColorSensor.pauseForColor": "Waits for the given color to be detected", "sensors.ColorSensor.pauseForColor": "Waits for the given color to be detected",
"sensors.ColorSensor.pauseForColor|param|color": "the color to detect", "sensors.ColorSensor.pauseForColor|param|color": "the color to detect",
"sensors.ColorSensor.pauseForLight": "Waits for the given color to be detected" "sensors.ColorSensor.pauseForLight": "Waits for the given color to be detected",
"sensors.ColorSensor.setThreshold": "Sets a threshold value",
"sensors.ColorSensor.setThreshold|param|condition": "the dark or bright light condition",
"sensors.ColorSensor.setThreshold|param|value": "the value threshold"
} }

View File

@ -19,11 +19,13 @@
"sensors.ColorSensor.onLightChanged|block": "on %sensor|%mode|%condition", "sensors.ColorSensor.onLightChanged|block": "on %sensor|%mode|%condition",
"sensors.ColorSensor.pauseForColor|block": "pause %sensor|for color %color", "sensors.ColorSensor.pauseForColor|block": "pause %sensor|for color %color",
"sensors.ColorSensor.pauseForLight|block": "pause %sensor|for %mode|%condition", "sensors.ColorSensor.pauseForLight|block": "pause %sensor|for %mode|%condition",
"sensors.ColorSensor.setThreshold|block": "set %condition|to %value",
"sensors.color1|block": "color 1", "sensors.color1|block": "color 1",
"sensors.color2|block": "color 2", "sensors.color2|block": "color 2",
"sensors.color3|block": "color 3", "sensors.color3|block": "color 3",
"sensors.color4|block": "color 4", "sensors.color4|block": "color 4",
"sensors|block": "sensors", "sensors|block": "sensors",
"{id:category}Sensors": "Sensors", "{id:category}Sensors": "Sensors",
"{id:group}Color Sensor": "Color Sensor" "{id:group}Color Sensor": "Color Sensor",
"{id:group}Threshold": "Threshold"
} }

View File

@ -152,7 +152,7 @@ namespace sensors {
//% parts="colorsensor" //% parts="colorsensor"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% sensor.fieldEditor="ports"
//% weight=99 //% weight=98
//% group="Color Sensor" //% group="Color Sensor"
color(): ColorSensorColor { color(): ColorSensorColor {
this.setMode(ColorSensorMode.Color) this.setMode(ColorSensorMode.Color)
@ -221,6 +221,20 @@ namespace sensors {
reflectedLight() { reflectedLight() {
return this.light(LightIntensityMode.Reflected); return this.light(LightIntensityMode.Reflected);
} }
/**
* Sets a threshold value
* @param condition the dark or bright light condition
* @param value the value threshold
*/
//% blockId=colorSetThreshold block="set %condition|to %value"
//% group="Threshold" blockGap=8 weight=90
setThreshold(condition: LightCondition, value: number) {
if (condition == LightCondition.Dark)
this.thresholdDetector.setLowThreshold(value)
else
this.thresholdDetector.setHighThreshold(value);
}
} }
//% whenUsed block="color 3" weight=90 fixedInstance jres=icons.port3 //% whenUsed block="color 3" weight=90 fixedInstance jres=icons.port3

View File

@ -71,7 +71,7 @@
"motors.MotorBase.setBrake": "Sets the automatic brake on or off when the motor is off", "motors.MotorBase.setBrake": "Sets the automatic brake on or off when the motor is off",
"motors.MotorBase.setBrake|param|brake": "a value indicating if the motor should break when off", "motors.MotorBase.setBrake|param|brake": "a value indicating if the motor should break when off",
"motors.MotorBase.setReversed": "Reverses the motor polarity", "motors.MotorBase.setReversed": "Reverses the motor polarity",
"motors.MotorBase.setSpeed": "Sets the motor speed for limited time or distance", "motors.MotorBase.setSpeed": "Sets the motor speed for limited time or distance.",
"motors.MotorBase.setSpeed|param|speed": "the speed from ``100`` full forward to ``-100`` full backward, eg: 50", "motors.MotorBase.setSpeed|param|speed": "the speed from ``100`` full forward to ``-100`` full backward, eg: 50",
"motors.MotorBase.setSpeed|param|unit": "(optional) unit of the value", "motors.MotorBase.setSpeed|param|unit": "(optional) unit of the value",
"motors.MotorBase.setSpeed|param|value": "(optional) measured distance or rotation", "motors.MotorBase.setSpeed|param|value": "(optional) measured distance or rotation",

View File

@ -58,7 +58,8 @@
"motors.MotorBase.setBrake|block": "set %motor|brake %brake", "motors.MotorBase.setBrake|block": "set %motor|brake %brake",
"motors.MotorBase.setReversed|block": "set %motor|reversed %reversed", "motors.MotorBase.setReversed|block": "set %motor|reversed %reversed",
"motors.MotorBase.setSpeed|block": "set %motor|speed to %speed=motorSpeedPicker|%", "motors.MotorBase.setSpeed|block": "set %motor|speed to %speed=motorSpeedPicker|%",
"motors.SynchedMotorPair.steer|block": "steer %chassis|turn ratio %turnRatio|speed %speed=motorSpeedPicker|%", "motors.MotorBase.stop|block": "%motors|stop",
"motors.SynchedMotorPair.steer|block": "steer %chassis|turn ratio %turnRatio=motorTurnRatioPicker|speed %speed=motorSpeedPicker|%",
"motors.SynchedMotorPair.tank|block": "tank %motors|%speedLeft=motorSpeedPicker|%|%speedRight=motorSpeedPicker|%", "motors.SynchedMotorPair.tank|block": "tank %motors|%speedLeft=motorSpeedPicker|%|%speedRight=motorSpeedPicker|%",
"motors.largeAB|block": "large A+B", "motors.largeAB|block": "large A+B",
"motors.largeAD|block": "large A+D", "motors.largeAD|block": "large A+D",

View File

@ -114,23 +114,7 @@
"progressWaterLevel3": "iVBORw0KGgoAAAANSUhEUgAAALIAAACAAQAAAACHQw5jAAABP0lEQVR42u2VMWrEMBBFRxGsGrNqXYT4CltuFV9lj5EqVlhImyPkKoKFbJcrrHKCKJ2XKFb+BGxsGBdbBRJ/mGHm+VtjJGNT/srQO6cG8cnFKXvKLVdHRFcjfXD3xDyybY9IFVJgbpgHtilEa5E8XJ1m/gJbVwJFXuwRrqSYa9hSCZt/A1/B1VLjqdMG1mu0bgeD4W5Te2r1A6YVJne0qfNP57fWU9AY5dYKd29tDgodldoTqagjGaoc3VAiiibQmlg1ApeIQIjuufDUq+C0Q1z1xaJFi/60iluZ28aJ3Jy9yPU5iFxlmesZvsry+kUz8/z/5qTuZKyizM2F3IYZfnDyuR7kc61fL+P4qYmq0mCZ+tuhfHZjPvhV8iKnMVejuZNXrjnK3O77aeo03hEzNGqyUcbNnJdfPjqLFv2+vgH+JtBJ4nz/SAAAAABJRU5ErkJggg==", "progressWaterLevel3": "iVBORw0KGgoAAAANSUhEUgAAALIAAACAAQAAAACHQw5jAAABP0lEQVR42u2VMWrEMBBFRxGsGrNqXYT4CltuFV9lj5EqVlhImyPkKoKFbJcrrHKCKJ2XKFb+BGxsGBdbBRJ/mGHm+VtjJGNT/srQO6cG8cnFKXvKLVdHRFcjfXD3xDyybY9IFVJgbpgHtilEa5E8XJ1m/gJbVwJFXuwRrqSYa9hSCZt/A1/B1VLjqdMG1mu0bgeD4W5Te2r1A6YVJne0qfNP57fWU9AY5dYKd29tDgodldoTqagjGaoc3VAiiibQmlg1ApeIQIjuufDUq+C0Q1z1xaJFi/60iluZ28aJ3Jy9yPU5iFxlmesZvsry+kUz8/z/5qTuZKyizM2F3IYZfnDyuR7kc61fL+P4qYmq0mCZ+tuhfHZjPvhV8iKnMVejuZNXrjnK3O77aeo03hEzNGqyUcbNnJdfPjqLFv2+vgH+JtBJ4nz/SAAAAABJRU5ErkJggg==",
"systemAccept1": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAQAQAAAAAkX4I4AAAAQElEQVR42mM4wMDMsP//X4b6//+AWI6h/p8dQ/2fOob6H/8YKj/+Y6h4/I+hxvkfQx07UJ4fiOf/A6sF6QHqBQDsYh9jNdETHwAAAABJRU5ErkJggg==", "systemAccept1": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAQAQAAAAAkX4I4AAAAQElEQVR42mM4wMDMsP//X4b6//+AWI6h/p8dQ/2fOob6H/8YKj/+Y6h4/I+hxvkfQx07UJ4fiOf/A6sF6QHqBQDsYh9jNdETHwAAAABJRU5ErkJggg==",
"systemAccept2": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAQAQAAAAAkX4I4AAAAQUlEQVR42mM4wMDMsP//X4YEBjYGB4ZHDA6MhxgcmJsYHNiZGNz4mBjcZZgYnPcwMTj+YGJw+ADECUxgtSA9QL0A+IIPxwiZFtwAAAAASUVORK5CYII=", "systemAccept2": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAQAQAAAAAkX4I4AAAAQUlEQVR42mM4wMDMsP//X4YEBjYGB4ZHDA6MhxgcmJsYHNiZGNz4mBjcZZgYnPcwMTj+YGJw+ADECUxgtSA9QL0A+IIPxwiZFtwAAAAASUVORK5CYII=",
"systemAlert": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAVAQAAAAB0khOLAAAARUlEQVR42iXD0QmAIAAE0IvWCtqmMbLG8MtVhAZwjBvALyE85XzwoE/QO8f5WPsd0K+An6c3Jq8sThIUUVg9qfmDDRn7AD/WMAQEJ+pCAAAAAElFTkSuQmCC",
"systemBox": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAQAQAAAAAkX4I4AAAAGklEQVR42mM4wMDMsP//X4b6//9IwiA9QL0AlQYkzY8nCoAAAAAASUVORK5CYII=", "systemBox": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAQAQAAAAAkX4I4AAAAGklEQVR42mM4wMDMsP//X4b6//9IwiA9QL0AlQYkzY8nCoAAAAAASUVORK5CYII=",
"systemBusy0": "iVBORw0KGgoAAAANSUhEUgAAABMAAAAPAQAAAAAuP8mBAAAAMElEQVR42mPY/38Bg/x/BgbnHw4Msd8dGKLeA+k4IL0XSGdB6TioOFAepA6kHqgPAJCPFdTsOCPGAAAAAElFTkSuQmCC",
"systemBusy1": "iVBORw0KGgoAAAANSUhEUgAAAA8AAAATAQAAAABnuWoHAAAAOUlEQVR42mNoYGKw/8EAJO9/A6GrYQyv1jF8jWP4tY/hbx3D730M3+4xvH/HcO8bw90yhlvbGGDqAdjhGYsKgwC5AAAAAElFTkSuQmCC",
"systemDecline1": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAQAQAAAAAkX4I4AAAANUlEQVR42mM4wMDMsP//X4b6//8Y6urtGOrt6hjq5/xjqD8JxI+hGMQGiQHlwGqAakF6gHoBybUeX0RcSJEAAAAASUVORK5CYII=", "systemDecline1": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAQAQAAAAAkX4I4AAAANUlEQVR42mM4wMDMsP//X4b6//8Y6urtGOrt6hjq5/xjqD8JxI+hGMQGiQHlwGqAakF6gHoBybUeX0RcSJEAAAAASUVORK5CYII=",
"systemDecline2": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAQAQAAAAAkX4I4AAAANUlEQVR42mM4wMDMsP//X4YEBjYGx4ZDDA4HmxgckpkYHMyAWAaKQWyQGFAOpAakFqQHqBcAGz4QyzSHE/gAAAAASUVORK5CYII=", "systemDecline2": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAQAQAAAAAkX4I4AAAANUlEQVR42mM4wMDMsP//X4YEBjYGx4ZDDA4HmxgckpkYHMyAWAaKQWyQGFAOpAakFqQHqBcAGz4QyzSHE/gAAAAASUVORK5CYII="
"systemDotEmpty": "iVBORw0KGgoAAAANSUhEUgAAAB8AAAAfAQAAAAA31SuUAAAAYklEQVR42oWOMQ5AQBRE5yZ7FEfSKTmC25CQuILehkahkc12IvgjRqHUTPX/ew+MzsByNlhxGq7ochz90mFL9gmBFjCSGTxZoSUb1OTwTkquP/Md61cU8USWQzZ5VaCWp+oGeLZn9EklJaAAAAAASUVORK5CYII=",
"systemDotFull": "iVBORw0KGgoAAAANSUhEUgAAAB8AAAAfAQAAAAA31SuUAAAAX0lEQVR42mP4/0H+H8P//sf/GP7V//nH8PeDfB3D7wPs+xi+MzDeY3jHAER3GBjKGG4wMJgx7GBgsGLYwMAgBSESGBh4CBAIxWC9YFPA5oFNBtsBtg1sL9gFYLeAXAUAPIwyHWLMTS8AAAAASUVORK5CYII=",
"systemEv3small": "iVBORw0KGgoAAAANSUhEUgAAACsAAAANAQAAAAAY06pGAAAAPUlEQVR42mNg4LFvYwACFEr+n32fPYiS5/8P5PLLyz8AUXwQqs8eSMn/b7H/D6IO1NmDBA/UgbTzP/gHpwBcwBWO2QYBDwAAAABJRU5ErkJggg==",
"systemPlay": "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQAAAAA3iMLMAAAAMElEQVR42mP4Y8/wsZ/h+XOG858Z5v5k2POXwcaGoUYOhIAMIBcoCJQCKgAq+2MPAAFKFVmziLfGAAAAAElFTkSuQmCC",
"systemSlider0": "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAbAQAAAABg3VNpAAAAEklEQVR42mM4YMBwfwPV0AEDAHmKKNims3dJAAAAAElFTkSuQmCC",
"systemSlider1": "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAbAQAAAABg3VNpAAAAGklEQVR42mM4YMBwfwNFCAKuGjCc2sBwwAAAT7olG9TpXdAAAAAASUVORK5CYII=",
"systemSlider2": "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAbAQAAAABg3VNpAAAAG0lEQVR42mM4YMBwfwM5CAJObWC4aoAgDxgAACpUJGftPg+WAAAAAElFTkSuQmCC",
"systemSlider3": "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAbAQAAAABg3VNpAAAAG0lEQVR42mM4YMBwfwMJCAKuGjCc2oCFPGAAAPSIIz417p4OAAAAAElFTkSuQmCC",
"systemSlider4": "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAbAQAAAABg3VNpAAAAG0lEQVR42mM4YMBwfwNhBAGnNjBcNcBHHjAAAMJ6IooqNLP/AAAAAElFTkSuQmCC",
"systemSlider5": "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAbAQAAAABg3VNpAAAAG0lEQVR42mM4YMBwfwNOBAFXDRhObSCKPGAAAHfbIWHuFKlNAAAAAElFTkSuQmCC",
"systemSlider6": "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAbAQAAAABg3VNpAAAAG0lEQVR42mM4YMBwfwM6goBTGxiuGpBGHjAAADklIK1PooVQAAAAAElFTkSuQmCC",
"systemSlider7": "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAbAQAAAABg3VNpAAAAG0lEQVR42mM4YMBwfwMUQcBVA4ZTG8gkDxgAANmVH4SOiUHMAAAAAElFTkSuQmCC",
"systemSlider8": "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAbAQAAAABg3VNpAAAAFElEQVR42mM4YMBwagPDVSqRBwwASoohT92wVBIAAAAASUVORK5CYII="
} }

View File

@ -220,41 +220,10 @@ namespace images {
//% fixedInstance jres blockIdentity=brick.__imagePicker //% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemAccept2 = screen.unpackPNG(hex``); export const systemAccept2 = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker //% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemAlert = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemBox = screen.unpackPNG(hex``); export const systemBox = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker //% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemBusy0 = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemBusy1 = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemDecline1 = screen.unpackPNG(hex``); export const systemDecline1 = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker //% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemDecline2 = screen.unpackPNG(hex``); export const systemDecline2 = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker //% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemDotEmpty = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemDotFull = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemEv3small = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemPlay = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemSlider0 = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemSlider1 = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemSlider2 = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemSlider3 = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemSlider4 = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemSlider5 = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemSlider6 = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemSlider7 = screen.unpackPNG(hex``);
//% fixedInstance jres blockIdentity=brick.__imagePicker
export const systemSlider8 = screen.unpackPNG(hex``);
} }

View File

@ -11,4 +11,15 @@ namespace motors {
export function __speedPicker(speed: number): number { export function __speedPicker(speed: number): number {
return speed; return speed;
} }
/**
* A turn ratio picker
* @param turnratio the turn ratio, eg: 0
*/
//% blockId=motorTurnRatioPicker block="%turnratio" shim=TD_ID
//% turnratio.fieldEditor="turnratio" colorSecondary="#FFFFFF"
//% weight=0 blockHidden=1 turnRatio.fieldOptions.decompileLiterals=1
export function __turnRatioPicker(turnratio: number): number {
return turnratio;
}
} }

View File

@ -187,7 +187,9 @@ namespace motors {
/** /**
* Stops the motor(s). * Stops the motor(s).
*/ */
//% //% weight=6 blockGap=8
//% group="Move"
//% blockId=motorStop block="%motors|stop"
stop() { stop() {
this.init(); this.init();
stop(this._port, this._brake); stop(this._port, this._brake);
@ -203,7 +205,7 @@ namespace motors {
} }
/** /**
* Sets the motor speed for limited time or distance * Sets the motor speed for limited time or distance.
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50 * @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
* @param value (optional) measured distance or rotation * @param value (optional) measured distance or rotation
* @param unit (optional) unit of the value * @param unit (optional) unit of the value
@ -474,7 +476,7 @@ namespace motors {
* @param value (optional) move duration or rotation * @param value (optional) move duration or rotation
* @param unit (optional) unit of the value * @param unit (optional) unit of the value
*/ */
//% blockId=motorPairSteer block="steer %chassis|turn ratio %turnRatio|speed %speed=motorSpeedPicker|%" //% blockId=motorPairSteer block="steer %chassis|turn ratio %turnRatio=motorTurnRatioPicker|speed %speed=motorSpeedPicker|%"
//% weight=95 //% weight=95
//% turnRatio.min=-200 turnRatio=200 //% turnRatio.min=-200 turnRatio=200
//% inlineInputMode=inline //% inlineInputMode=inline

View File

@ -8,7 +8,7 @@ namespace brick {
//% color="#C8509B" weight=95 icon="\uf10f" //% color="#C8509B" weight=95 icon="\uf10f"
//% labelLineWidth=0 //% labelLineWidth=0
//% groups='["Ultrasonic Sensor", "Touch Sensor", "Color Sensor", "Infrared Sensor", "Remote Infrared Beacon", "Gyro Sensor"]' //% groups='["Touch Sensor", "Color Sensor", "Ultrasonic Sensor", "Gyro Sensor", "Infrared Sensor", "Remote Infrared Beacon", "Threshold"]'
//% groupIcons='["\uf101","\uf103","\uf102","","","\uf104"]' //% groupIcons='["\uf101","\uf103","\uf102","","","\uf104"]'
namespace sensors { namespace sensors {
} }

View File

@ -31,7 +31,7 @@ namespace sensors {
//% parts="gyroscope" //% parts="gyroscope"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% sensor.fieldEditor="ports"
//% weight=65 blockGap=8 //% weight=64 blockGap=8
//% group="Gyro Sensor" //% group="Gyro Sensor"
angle(): number { angle(): number {
if (this.calibrating) if (this.calibrating)
@ -70,7 +70,7 @@ namespace sensors {
//% parts="gyroscope" //% parts="gyroscope"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% sensor.fieldEditor="ports"
//% weight=65 blockGap=8 //% weight=50 blockGap=8
//% group="Gyro Sensor" //% group="Gyro Sensor"
calibrate(): void { calibrate(): void {
if (this.calibrating) return; // already in calibration mode if (this.calibrating) return; // already in calibration mode

View File

@ -4,6 +4,9 @@
"sensors.InfraredSensor.pauseUntil": "Waits for the event to occur", "sensors.InfraredSensor.pauseUntil": "Waits for the event to occur",
"sensors.InfraredSensor.proximity": "Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far)", "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.remoteCommand": "Get the remote commandreceived the infrared sensor.",
"sensors.InfraredSensor.setThreshold": "Sets a threshold value",
"sensors.InfraredSensor.setThreshold|param|condition": "the dark or bright light condition",
"sensors.InfraredSensor.setThreshold|param|value": "the value threshold",
"sensors.RemoteInfraredBeaconButton.isPressed": "Check if a remote button is currently pressed or not.", "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": "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.onEvent|param|body": "code to run when the event is raised",

View File

@ -5,6 +5,7 @@
"sensors.InfraredSensor.pauseUntil|block": "pause until %sensor| %event", "sensors.InfraredSensor.pauseUntil|block": "pause until %sensor| %event",
"sensors.InfraredSensor.proximity|block": "%sensor|proximity", "sensors.InfraredSensor.proximity|block": "%sensor|proximity",
"sensors.InfraredSensor.remoteCommand|block": "%sensor|remote command", "sensors.InfraredSensor.remoteCommand|block": "%sensor|remote command",
"sensors.InfraredSensor.setThreshold|block": "set %condition|to %value",
"sensors.RemoteInfraredBeaconButton.isPressed|block": "%button|is pressed", "sensors.RemoteInfraredBeaconButton.isPressed|block": "%button|is pressed",
"sensors.RemoteInfraredBeaconButton.onEvent|block": "on %button|%event", "sensors.RemoteInfraredBeaconButton.onEvent|block": "on %button|%event",
"sensors.RemoteInfraredBeaconButton.wasPressed|block": "%button|was pressed", "sensors.RemoteInfraredBeaconButton.wasPressed|block": "%button|was pressed",
@ -20,5 +21,6 @@
"sensors|block": "sensors", "sensors|block": "sensors",
"{id:category}Sensors": "Sensors", "{id:category}Sensors": "Sensors",
"{id:group}Infrared Sensor": "Infrared Sensor", "{id:group}Infrared Sensor": "Infrared Sensor",
"{id:group}Remote Infrared Beacon": "Remote Infrared Beacon" "{id:group}Remote Infrared Beacon": "Remote Infrared Beacon",
"{id:group}Threshold": "Threshold"
} }

View File

@ -250,6 +250,21 @@ namespace sensors {
this._setMode(IrSensorMode.Seek) this._setMode(IrSensorMode.Seek)
return this.getNumber(NumberFormat.UInt16LE, this.channel * 2) return this.getNumber(NumberFormat.UInt16LE, this.channel * 2)
} }
/**
* Sets a threshold value
* @param condition the dark or bright light condition
* @param value the value threshold
*/
//% blockId=irSetThreshold block="set %condition|to %value"
//% group="Threshold" blockGap=8
setThreshold(condition: InfraredSensorEvent, value: number) {
if (condition == InfraredSensorEvent.ObjectNear)
this.proximityThreshold.setLowThreshold(value)
else
this.proximityThreshold.setHighThreshold(value);
}
} }
//% fixedInstance whenUsed block="infrared 1" jres=icons.port1 //% fixedInstance whenUsed block="infrared 1" jres=icons.port1

View File

@ -1 +0,0 @@
# Matrix

View File

@ -1,15 +0,0 @@
{
"matrix.Matrix": "A 2D matrix",
"matrix.Matrix.add": "Returns a new matrix as the sum of both matrices",
"matrix.Matrix.cholesky": "Performs a Cholesky factorized for a symmetric and positive definite",
"matrix.Matrix.clone": "Clones the matrix",
"matrix.Matrix.get": "Gets a value from the matrix",
"matrix.Matrix.get|param|row": "@param col ",
"matrix.Matrix.identity": "Creates an identity matrix",
"matrix.Matrix.logToConsole": "Renders the matrix to the console",
"matrix.Matrix.multiply": "Multiplies the current matrix with the other matrix and returns a new matrix",
"matrix.Matrix.scale": "Returns a new matrix with scaled values",
"matrix.Matrix.set": "Sets a value in the array",
"matrix.Matrix.set|param|row": "@param col ",
"matrix.Matrix.transpose": "Returns a transposed matrix"
}

View File

@ -1,4 +0,0 @@
{
"matrix|block": "matrix",
"{id:category}Matrix": "Matrix"
}

View File

@ -1,186 +0,0 @@
namespace matrix {
function pre(check: boolean) {
if (!check)
control.reset();
}
/**
* A 2D matrix
*/
export class Matrix {
private _rows: number;
private _cols: number;
private _values: number[];
constructor(rows: number, cols: number, values: number[] = undefined) {
pre(rows > 0);
pre(cols > 0);
this._rows = rows;
this._cols = cols;
const n = this._rows * this._cols;
this._values = values || [];
// fill gaps
while (this._values.length < n)
this._values.push(0);
}
/**
* Creates an identity matrix
* @param size
*/
static identity(size: number): Matrix {
const m = new Matrix(size, size);
for (let i = 0; i < size; ++i)
m._values[i * size] = 1;
return m;
}
/**
* Sets a value in the array
* @param row
* @param col
* @param val
*/
set(row: number, col: number, val: number) {
pre(row == row >> 0 && row >= 0 && row < this._rows && col == col >> 0 && col >= 0 && col < this._cols);
this._values[row * this._cols + col] = val;
}
/**
* Gets a value from the matrix
* @param row
* @param col
*/
get(row: number, col: number): number {
pre(row == row >> 0 && row >= 0 && row < this._rows && col == col >> 0 && col >= 0 && col < this._cols);
return this._values[row * this._cols + col];
}
/**
* Gets the number of rows
*/
get rows(): number {
return this._rows;
}
/**
* Gets the number of colums
*/
get cols(): number {
return this._cols;
}
/**
* Gets the raw storage buffer
*/
get values(): number[] {
return this._values;
}
/**
* Returns a new matrix as the sum of both matrices
* @param other
*/
add(other: Matrix): Matrix {
pre(this._rows != other._rows || this._cols != other._cols)
const n = this._rows * this._cols;
const r: number[] = [];
for (let i = 0; i < n; ++i) {
r[i] = this._values[i] + other._values[i];
}
return new Matrix(this._rows, this._cols, r);
}
/**
* Returns a new matrix with scaled values
* @param factor
*/
scale(factor: number): Matrix {
const n = this._rows * this._cols;
const r: number[] = [];
for (let i = 0; i < n; ++i) {
r[i] = this._values[i] * factor;
}
return new Matrix(this._rows, this._cols, r);
}
/**
* Multiplies the current matrix with the other matrix and returns a new matrix
* @param other
*/
multiply(other: Matrix): Matrix {
pre(this._cols == other._rows);
const r: number[] = [];
for (let i = 0; i < this._rows; ++i) {
for (let j = 0; j < other._cols; ++j) {
let s = 0;
for (let k = 0; k < this._cols; ++k) {
s += this._values[i * this._cols + k] * other._values[k * other._cols + j];
}
r[i * other._cols + j];
}
}
return new Matrix(this._rows, other._cols, r);
}
/**
* Returns a transposed matrix
*/
transpose(): Matrix {
const R = new Matrix(this._cols, this._rows);
const r: number[] = R._values;
for (let i = 0; i < this._rows; ++i) {
for (let j = 0; j < this._cols; ++j) {
r[i + j * this._rows] = this._values[i * this._cols + j];
}
}
return R;
}
/**
* Clones the matrix
*/
clone(): Matrix {
const r = new Matrix(this._rows, this._cols, this._values.slice(0));
return r;
}
/**
* Performs a Cholesky factorized for a symmetric and positive definite
*
*/
cholesky(): Matrix {
pre(this._rows == this._cols);
const l = this.clone();
const n = this._rows;
const L = l._values;
for (let j = 0; j < n; j++) {
const jj = L[j * n + j] = Math.sqrt(L[j * n + j]);
for (let i = j + 1; i < n; ++i)
L[i * n + j] /= jj;
for (let k = j + 1; k < n; k++)
for (let i = k; i < n; i++)
L[i * n + j] -= L[i * n + j] * L[k * n + j];
}
return l;
}
/**
* Renders the matrix to the console
*/
logToConsole(): void {
let k = 0;
for(let i = 0; i < this._rows; ++i) {
let s = ""
for(let j = 0; j < this._cols; ++j) {
if (j > 0)
s += " "
s += Math.round((this._values[k++] * 100) / 100);
}
console.log(s)
}
}
}
}

View File

@ -1,15 +0,0 @@
{
"name": "matrix",
"description": "Matrix algebra",
"files": [
"README.md",
"matrix.ts"
],
"testFiles": [
"test.ts"
],
"public": true,
"dependencies": {
"core": "file:../core"
}
}

View File

@ -1 +0,0 @@
// add tests here

View File

@ -33,34 +33,34 @@
"music.stopAllSounds|block": "stop all sounds", "music.stopAllSounds|block": "stop all sounds",
"music.tempo|block": "tempo (bpm)", "music.tempo|block": "tempo (bpm)",
"music|block": "music", "music|block": "music",
"sounds.animalsCatPurr|block": "Animals cat purr", "sounds.animalsCatPurr|block": "animals cat purr",
"sounds.animalsDogBark1|block": "Animals dog bark 1", "sounds.animalsDogBark1|block": "animals dog bark 1",
"sounds.animalsDogBark2|block": "Animals dog bark 2", "sounds.animalsDogBark2|block": "animals dog bark 2",
"sounds.animalsDogGrowl|block": "Animals dog growl", "sounds.animalsDogGrowl|block": "animals dog growl",
"sounds.animalsDogSniff|block": "Animals dog sniff", "sounds.animalsDogSniff|block": "animals dog sniff",
"sounds.animalsDogWhine|block": "Animals dog whine", "sounds.animalsDogWhine|block": "animals dog whine",
"sounds.animalsElephantCall|block": "Animals elephant call", "sounds.animalsElephantCall|block": "animals elephant call",
"sounds.animalsInsectBuzz1|block": "Animals insect buzz1", "sounds.animalsInsectBuzz1|block": "animals insect buzz1",
"sounds.animalsInsectBuzz2|block": "Animals insect buzz2", "sounds.animalsInsectBuzz2|block": "animals insect buzz2",
"sounds.animalsInsectChirp|block": "Animals insect chirp", "sounds.animalsInsectChirp|block": "animals insect chirp",
"sounds.animalsSnakeHiss|block": "Animals snake hiss", "sounds.animalsSnakeHiss|block": "animals snake hiss",
"sounds.animalsSnakeRattle|block": "Animals snake rattle", "sounds.animalsSnakeRattle|block": "animals snake rattle",
"sounds.animalsTRexRoar|block": "Animals trex roar", "sounds.animalsTRexRoar|block": "animals trex roar",
"sounds.colorsBlack|block": "Colors black", "sounds.colorsBlack|block": "colors black",
"sounds.colorsBlue|block": "Colors blue", "sounds.colorsBlue|block": "colors blue",
"sounds.colorsBrown|block": "Colors brown", "sounds.colorsBrown|block": "colors brown",
"sounds.colorsGreen|block": "Colors green", "sounds.colorsGreen|block": "colors green",
"sounds.colorsRed|block": "Colors red", "sounds.colorsRed|block": "colors red",
"sounds.colorsWhite|block": "Colors white", "sounds.colorsWhite|block": "colors white",
"sounds.colorsYellow|block": "Colors yellow", "sounds.colorsYellow|block": "colors yellow",
"sounds.communicationBravo|block": "Communication bravo", "sounds.communicationBravo|block": "communication bravo",
"sounds.communicationEv3|block": "Communication ev3", "sounds.communicationEv3|block": "communication ev3",
"sounds.communicationFantastic|block": "Communication fantastic", "sounds.communicationFantastic|block": "communication fantastic",
"sounds.communicationGameOver|block": "Communication game over", "sounds.communicationGameOver|block": "communication game over",
"sounds.communicationGoodJob|block": "communicationGoodJob", "sounds.communicationGoodJob|block": "communicationGoodJob",
"sounds.communicationGoodbye|block": "communication goodbye", "sounds.communicationGoodbye|block": "communication goodbye",
"sounds.communicationGood|block": "communication good", "sounds.communicationGood|block": "communication good",
"sounds.communicationGo|block": "Communication go", "sounds.communicationGo|block": "communication go",
"sounds.communicationHello|block": "communication hello", "sounds.communicationHello|block": "communication hello",
"sounds.communicationHi|block": "communication hi", "sounds.communicationHi|block": "communication hi",
"sounds.communicationLego|block": "communication lego", "sounds.communicationLego|block": "communication lego",
@ -159,7 +159,7 @@
"sounds.systemOverpower|block": "system overpower", "sounds.systemOverpower|block": "system overpower",
"sounds.systemPowerDown|block": "system power down", "sounds.systemPowerDown|block": "system power down",
"sounds.systemReady|block": "system ready", "sounds.systemReady|block": "system ready",
"sounds.systemStartUp|block": "S", "sounds.systemStartUp|block": "system start up",
"{id:category}Music": "Music", "{id:category}Music": "Music",
"{id:category}Sound": "Sound", "{id:category}Sound": "Sound",
"{id:category}Sounds": "Sounds" "{id:category}Sounds": "Sounds"

View File

@ -1,53 +1,53 @@
namespace sounds { namespace sounds {
//% fixedInstance jres block="Animals cat purr" //% fixedInstance jres block="animals cat purr"
export const animalsCatPurr = music.fromWAV(hex``); export const animalsCatPurr = music.fromWAV(hex``);
//% fixedInstance jres block="Animals dog bark 1" //% fixedInstance jres block="animals dog bark 1"
export const animalsDogBark1 = music.fromWAV(hex``); export const animalsDogBark1 = music.fromWAV(hex``);
//% fixedInstance jres block="Animals dog bark 2" //% fixedInstance jres block="animals dog bark 2"
export const animalsDogBark2 = music.fromWAV(hex``); export const animalsDogBark2 = music.fromWAV(hex``);
//% fixedInstance jres block="Animals dog growl" //% fixedInstance jres block="animals dog growl"
export const animalsDogGrowl = music.fromWAV(hex``); export const animalsDogGrowl = music.fromWAV(hex``);
//% fixedInstance jres block="Animals dog sniff" //% fixedInstance jres block="animals dog sniff"
export const animalsDogSniff = music.fromWAV(hex``); export const animalsDogSniff = music.fromWAV(hex``);
//% fixedInstance jres block="Animals dog whine" //% fixedInstance jres block="animals dog whine"
export const animalsDogWhine = music.fromWAV(hex``); export const animalsDogWhine = music.fromWAV(hex``);
//% fixedInstance jres block="Animals elephant call" //% fixedInstance jres block="animals elephant call"
export const animalsElephantCall = music.fromWAV(hex``); export const animalsElephantCall = music.fromWAV(hex``);
//% fixedInstance jres block="Animals insect buzz1" //% fixedInstance jres block="animals insect buzz1"
export const animalsInsectBuzz1 = music.fromWAV(hex``); export const animalsInsectBuzz1 = music.fromWAV(hex``);
//% fixedInstance jres block="Animals insect buzz2" //% fixedInstance jres block="animals insect buzz2"
export const animalsInsectBuzz2 = music.fromWAV(hex``); export const animalsInsectBuzz2 = music.fromWAV(hex``);
//% fixedInstance jres block="Animals insect chirp" //% fixedInstance jres block="animals insect chirp"
export const animalsInsectChirp = music.fromWAV(hex``); export const animalsInsectChirp = music.fromWAV(hex``);
//% fixedInstance jres block="Animals snake hiss" //% fixedInstance jres block="animals snake hiss"
export const animalsSnakeHiss = music.fromWAV(hex``); export const animalsSnakeHiss = music.fromWAV(hex``);
//% fixedInstance jres block="Animals snake rattle" //% fixedInstance jres block="animals snake rattle"
export const animalsSnakeRattle = music.fromWAV(hex``); export const animalsSnakeRattle = music.fromWAV(hex``);
//% fixedInstance jres block="Animals trex roar" //% fixedInstance jres block="animals trex roar"
export const animalsTRexRoar = music.fromWAV(hex``); export const animalsTRexRoar = music.fromWAV(hex``);
//% fixedInstance jres block="Colors black" //% fixedInstance jres block="colors black"
export const colorsBlack = music.fromWAV(hex``); export const colorsBlack = music.fromWAV(hex``);
//% fixedInstance jres block="Colors blue" //% fixedInstance jres block="colors blue"
export const colorsBlue = music.fromWAV(hex``); export const colorsBlue = music.fromWAV(hex``);
//% fixedInstance jres block="Colors brown" //% fixedInstance jres block="colors brown"
export const colorsBrown = music.fromWAV(hex``); export const colorsBrown = music.fromWAV(hex``);
//% fixedInstance jres block="Colors green" //% fixedInstance jres block="colors green"
export const colorsGreen = music.fromWAV(hex``); export const colorsGreen = music.fromWAV(hex``);
//% fixedInstance jres block="Colors red" //% fixedInstance jres block="colors red"
export const colorsRed = music.fromWAV(hex``); export const colorsRed = music.fromWAV(hex``);
//% fixedInstance jres block="Colors white" //% fixedInstance jres block="colors white"
export const colorsWhite = music.fromWAV(hex``); export const colorsWhite = music.fromWAV(hex``);
//% fixedInstance jres block="Colors yellow" //% fixedInstance jres block="colors yellow"
export const colorsYellow = music.fromWAV(hex``); export const colorsYellow = music.fromWAV(hex``);
//% fixedInstance jres block="Communication bravo" //% fixedInstance jres block="communication bravo"
export const communicationBravo = music.fromWAV(hex``); export const communicationBravo = music.fromWAV(hex``);
//% fixedInstance jres block="Communication ev3" //% fixedInstance jres block="communication ev3"
export const communicationEv3 = music.fromWAV(hex``); export const communicationEv3 = music.fromWAV(hex``);
//% fixedInstance jres block="Communication fantastic" //% fixedInstance jres block="communication fantastic"
export const communicationFantastic = music.fromWAV(hex``); export const communicationFantastic = music.fromWAV(hex``);
//% fixedInstance jres block="Communication game over" //% fixedInstance jres block="communication game over"
export const communicationGameOver = music.fromWAV(hex``); export const communicationGameOver = music.fromWAV(hex``);
//% fixedInstance jres block="Communication go" //% fixedInstance jres block="communication go"
export const communicationGo = music.fromWAV(hex``); export const communicationGo = music.fromWAV(hex``);
//% fixedInstance jres block="communicationGoodJob" //% fixedInstance jres block="communicationGoodJob"
export const communicationGoodJob = music.fromWAV(hex``); export const communicationGoodJob = music.fromWAV(hex``);
@ -251,7 +251,7 @@ namespace sounds {
export const systemPowerDown = music.fromWAV(hex``); export const systemPowerDown = music.fromWAV(hex``);
//% fixedInstance jres block="system ready" //% fixedInstance jres block="system ready"
export const systemReady = music.fromWAV(hex``); export const systemReady = music.fromWAV(hex``);
//% fixedInstance jres block=S //% fixedInstance jres block="system start up"
export const systemStartUp = music.fromWAV(hex``); export const systemStartUp = music.fromWAV(hex``);
} }

View File

@ -2,5 +2,8 @@
"sensors.UltraSonicSensor.distance": "Gets the distance from the sonar in centimeters", "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": "Registers code to run when the given color is close",
"sensors.UltraSonicSensor.onEvent|param|handler": "the code to run when detected", "sensors.UltraSonicSensor.onEvent|param|handler": "the code to run when detected",
"sensors.UltraSonicSensor.pauseUntil": "Waits for the event to occur" "sensors.UltraSonicSensor.pauseUntil": "Waits for the event to occur",
"sensors.UltraSonicSensor.setThreshold": "Sets a threshold value",
"sensors.UltraSonicSensor.setThreshold|param|condition": "the dark or bright light condition",
"sensors.UltraSonicSensor.setThreshold|param|value": "the value threshold"
} }

View File

@ -5,10 +5,12 @@
"sensors.UltraSonicSensor.distance|block": "%sensor|distance", "sensors.UltraSonicSensor.distance|block": "%sensor|distance",
"sensors.UltraSonicSensor.onEvent|block": "on %sensor|%event", "sensors.UltraSonicSensor.onEvent|block": "on %sensor|%event",
"sensors.UltraSonicSensor.pauseUntil|block": "pause until %sensor| %event", "sensors.UltraSonicSensor.pauseUntil|block": "pause until %sensor| %event",
"sensors.UltraSonicSensor.setThreshold|block": "set %condition|to %value",
"sensors.ultrasonic1|block": "ultrasonic 1", "sensors.ultrasonic1|block": "ultrasonic 1",
"sensors.ultrasonic2|block": "ultrasonic 2", "sensors.ultrasonic2|block": "ultrasonic 2",
"sensors.ultrasonic3|block": "ultrasonic 3", "sensors.ultrasonic3|block": "ultrasonic 3",
"sensors.ultrasonic4|block": "ultrasonic 4", "sensors.ultrasonic4|block": "ultrasonic 4",
"{id:category}Sensors": "Sensors", "{id:category}Sensors": "Sensors",
"{id:group}Threshold": "Threshold",
"{id:group}Ultrasonic Sensor": "Ultrasonic Sensor" "{id:group}Ultrasonic Sensor": "Ultrasonic Sensor"
} }

View File

@ -85,6 +85,22 @@ namespace sensors {
this._setMode(0) this._setMode(0)
return this._query(); return this._query();
} }
/**
* Sets a threshold value
* @param condition the dark or bright light condition
* @param value the value threshold
*/
//% blockId=ultrasonicSetThreshold block="set %condition|to %value"
//% group="Threshold" blockGap=8
setThreshold(condition: UltrasonicSensorEvent, value: number) {
switch(condition) {
case UltrasonicSensorEvent.ObjectNear: this.promixityThreshold.setLowThreshold(value); break;
case UltrasonicSensorEvent.ObjectFar: this.promixityThreshold.setHighThreshold(value); break;
case UltrasonicSensorEvent.ObjectDetected: this.movementThreshold = value; break;
}
}
} }
//% fixedInstance whenUsed block="ultrasonic 4" jres=icons.port4 //% fixedInstance whenUsed block="ultrasonic 4" jres=icons.port4

View File

@ -1,6 +1,6 @@
{ {
"name": "pxt-ev3", "name": "pxt-ev3",
"version": "0.0.57", "version": "0.0.58",
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode", "description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
"private": true, "private": true,
"keywords": [ "keywords": [
@ -45,7 +45,7 @@
}, },
"dependencies": { "dependencies": {
"pxt-common-packages": "0.15.4", "pxt-common-packages": "0.15.4",
"pxt-core": "3.0.5" "pxt-core": "3.0.7"
}, },
"scripts": { "scripts": {
"test": "node node_modules/pxt-core/built/pxt.js travis" "test": "node node_modules/pxt-core/built/pxt.js travis"

View File

@ -18,8 +18,7 @@
"libs/chassis", "libs/chassis",
"libs/ev3", "libs/ev3",
"libs/tests", "libs/tests",
"libs/behaviors", "libs/behaviors"
"libs/matrix"
], ],
"simulator": { "simulator": {
"autoRun": true, "autoRun": true,

View File

@ -40,6 +40,10 @@ namespace pxsim {
} }
setSpeedCmd(cmd: DAL, values: number[]) { setSpeedCmd(cmd: DAL, values: number[]) {
if (this.speedCmd != cmd ||
JSON.stringify(this.speedCmdValues) != JSON.stringify(values))
this.setChangedState();
// new command TODO: values
this.speedCmd = cmd; this.speedCmd = cmd;
this.speedCmdValues = values; this.speedCmdValues = values;
this.speedCmdTacho = this.angle; this.speedCmdTacho = this.angle;

View File

@ -50,6 +50,15 @@ namespace pxsim.visuals {
fill:#5A5A5A; fill:#5A5A5A;
} }
.no-drag, .sim-text, .sim-text-pin {
user-drag: none;
user-select: none;
-moz-user-select: none;
-webkit-user-drag: none;
-webkit-user-select: none;
-ms-user-select: none;
}
/* Color Grid */ /* Color Grid */
.sim-color-grid-circle:hover { .sim-color-grid-circle:hover {
stroke-width: 0.4; stroke-width: 0.4;

View File

@ -173,15 +173,15 @@ namespace pxsim.visuals {
} }
// Inject all ports // Inject all ports
this.setInput(0, new PortView(0, 'A')); this.setInput(0, new PortView(0, '1'));
this.setInput(1, new PortView(1, 'B')); this.setInput(1, new PortView(1, '2'));
this.setInput(2, new PortView(2, 'C')); this.setInput(2, new PortView(2, '3'));
this.setInput(3, new PortView(3, 'D')); this.setInput(3, new PortView(3, '4'));
this.setOutput(0, new PortView(0, '1')); this.setOutput(0, new PortView(0, 'A'));
this.setOutput(1, new PortView(1, '2')); this.setOutput(1, new PortView(1, 'B'));
this.setOutput(2, new PortView(2, '3')); this.setOutput(2, new PortView(2, 'C'));
this.setOutput(3, new PortView(3, '4')); this.setOutput(3, new PortView(3, 'D'));
return this.contentGroup; return this.contentGroup;
} }

View File

@ -34,14 +34,14 @@ namespace pxsim.visuals {
this.syncedLabelG = pxsim.svg.child(this.element, 'g', {'transform': 'scale(0.5)'}) as SVGGElement; this.syncedLabelG = pxsim.svg.child(this.element, 'g', {'transform': 'scale(0.5)'}) as SVGGElement;
pxsim.svg.child(this.syncedLabelG, 'rect', {'rx': 15, 'ry': 15, 'x': 0, 'y': 0, 'width': 84, 'height': 34, 'fill': '#A8A9A8'}); pxsim.svg.child(this.syncedLabelG, 'rect', {'rx': 15, 'ry': 15, 'x': 0, 'y': 0, 'width': 84, 'height': 34, 'fill': '#A8A9A8'});
pxsim.svg.child(this.syncedLabelG, 'circle', {'cx': 17, 'cy': 17, 'r': 15, 'fill': 'white'}); pxsim.svg.child(this.syncedLabelG, 'circle', {'cx': 17, 'cy': 17, 'r': 15, 'fill': 'white'});
const leftLabel = pxsim.svg.child(this.syncedLabelG, 'text', {'transform': 'translate(11, 22)', 'style': 'isolation: isolate;font-size: 16px;fill: #A8A9A8;font-family: ArialMT, Arial'}); const leftLabel = pxsim.svg.child(this.syncedLabelG, 'text', {'transform': 'translate(11, 22)', 'class': 'no-drag', 'style': 'isolation: isolate;font-size: 16px;fill: #A8A9A8;font-family: ArialMT, Arial'});
leftLabel.textContent = a; leftLabel.textContent = a;
pxsim.svg.child(this.syncedLabelG, 'rect', {'rx': 0, 'ry': 0, 'x': 37, 'y': 12, 'width': 10, 'height': 3, 'fill': '#ffffff'}); pxsim.svg.child(this.syncedLabelG, 'rect', {'rx': 0, 'ry': 0, 'x': 37, 'y': 12, 'width': 10, 'height': 3, 'fill': '#ffffff'});
pxsim.svg.child(this.syncedLabelG, 'rect', {'rx': 0, 'ry': 0, 'x': 37, 'y': 18, 'width': 10, 'height': 3, 'fill': '#ffffff'}); pxsim.svg.child(this.syncedLabelG, 'rect', {'rx': 0, 'ry': 0, 'x': 37, 'y': 18, 'width': 10, 'height': 3, 'fill': '#ffffff'});
pxsim.svg.child(this.syncedLabelG, 'circle', {'cx': 67, 'cy': 17, 'r': 15, 'fill': 'white'}); pxsim.svg.child(this.syncedLabelG, 'circle', {'cx': 67, 'cy': 17, 'r': 15, 'fill': 'white'});
const rightLabel = pxsim.svg.child(this.syncedLabelG, 'text', {'transform': 'translate(61, 22)', 'style': 'isolation: isolate;font-size: 16px;fill: #A8A9A8;font-family: ArialMT, Arial'}); const rightLabel = pxsim.svg.child(this.syncedLabelG, 'text', {'transform': 'translate(61, 22)', 'class': 'no-drag', 'style': 'isolation: isolate;font-size: 16px;fill: #A8A9A8;font-family: ArialMT, Arial'});
rightLabel.textContent = b; rightLabel.textContent = b;
} }