Compare commits

...

8 Commits

24 changed files with 144 additions and 40 deletions

View File

@ -9,6 +9,7 @@
"name": "Autonomous Parking",
"description": "TBD",
"url":"/coding/autonomous-parking",
"imageUrl": "/static/lessons/parking.png",
"cardType": "side"
}, {
"name": "Object Detection",

View File

@ -7,14 +7,14 @@
{
"name": "Make It Move Without Wheels",
"description": "TBD",
"imageUrl": "/static/lessons/make-it-move.png",
"imageUrl": "/static/lessons/make-it-move-1.png",
"url": "/design-engineering/make-it-move",
"cardType": "side"
},
{
"name": "Make It Smarter and Faster",
"description": "TBD",
"imageUrl": "/static/lessons/make-it-smarter.png",
"imageUrl": "/static/lessons/make-it-smarter-1.png",
"url": "/design-engineering/make-it-smarter",
"cardType": "side"
},

Binary file not shown.

Before

Width:  |  Height:  |  Size: 592 KiB

After

Width:  |  Height:  |  Size: 32 KiB

BIN
docs/static/lessons/make-it-move-1.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
docs/static/lessons/make-it-move-2.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
docs/static/lessons/make-it-move-3.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 357 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 KiB

BIN
docs/static/lessons/parking.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
docs/static/lessons/sound-machine.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 236 KiB

After

Width:  |  Height:  |  Size: 48 KiB

View File

@ -7,6 +7,7 @@ import { FieldImages } from "./field_images";
import { FieldSpeed } from "./field_speed";
import { FieldBrickButtons } from "./field_brickbuttons";
import { FieldTurnRatio } from "./field_turnratio";
import { FieldColorEnum } from "./field_color";
pxt.editor.initExtensionsAsync = function (opts: pxt.editor.ExtensionOptions): Promise<pxt.editor.ExtensionResult> {
pxt.debug('loading pxt-ev3 target extensions...')
@ -27,6 +28,9 @@ pxt.editor.initExtensionsAsync = function (opts: pxt.editor.ExtensionOptions): P
}, {
selector: "turnratio",
editor: FieldTurnRatio
}, {
selector: "colorenum",
editor: FieldColorEnum
}],
deployCoreAsync,
showUploadInstructionsAsync: (fn: string, url: string, confirmAsync: (options: any) => Promise<number>) => {

71
editor/field_color.ts Normal file
View File

@ -0,0 +1,71 @@
/// <reference path="../node_modules/pxt-core/localtypings/blockly.d.ts"/>
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
export interface FieldColorEnumOptions extends pxtblockly.FieldColourNumberOptions {
}
export class FieldColorEnum extends pxtblockly.FieldColorNumber implements Blockly.FieldCustom {
public isFieldCustom_ = true;
constructor(text: string, params: FieldColorEnumOptions, opt_validator?: Function) {
super(text, params, opt_validator);
}
mapColour(enumString: string) {
switch(enumString) {
case '#000000': return 'ColorSensorColor.Black';
case '#006db3': return 'ColorSensorColor.Blue';
case '#00934b': return 'ColorSensorColor.Green';
case '#ffd01b': return 'ColorSensorColor.Yellow';
case '#f12a21': return 'ColorSensorColor.Red';
case '#ffffff': return 'ColorSensorColor.White';
case '#6c2d00': return 'ColorSensorColor.Brown';
default: return 'ColorSensorColor.None';
}
}
mapEnum(colorString: string) {
console.log(colorString);
switch(colorString) {
case 'ColorSensorColor.Black': return '#000000';
case 'ColorSensorColor.Blue': return '#006db3';
case 'ColorSensorColor.Green': return '#00934b';
case 'ColorSensorColor.Yellow': return '#ffd01b';
case 'ColorSensorColor.Red': return '#f12a21';
case 'ColorSensorColor.White': return '#ffffff';
case 'ColorSensorColor.Brown': return '#6c2d00';
case 'ColorSensorColor.None': return '#dfe6e9'; // Grey
default: return colorString;
}
}
/**
* Return the current colour.
* @param {boolean} opt_asHex optional field if the returned value should be a hex
* @return {string} Current colour in '#rrggbb' format.
*/
getValue(opt_asHex?: boolean) {
var colour = this.mapColour(this.colour_);
if (!opt_asHex && colour.indexOf('#') > -1) {
return `0x${colour.replace(/^#/, '')}`;
}
return colour;
}
/**
* Set the colour.
* @param {string} colour The new colour in '#rrggbb' format.
*/
setValue(colorStr: string) {
var colour = this.mapEnum(colorStr);
if (this.sourceBlock_ && Blockly.Events.isEnabled() &&
this.colour_ != colour) {
Blockly.Events.fire(new (Blockly as any).Events.BlockChange(
this.sourceBlock_, 'field', this.name, this.colour_, colour));
}
this.colour_ = colour;
if (this.sourceBlock_) {
this.sourceBlock_.setColour(colour, colour, colour);
}
}
}

View File

@ -19,21 +19,21 @@ enum LightIntensityMode {
}
const enum ColorSensorColor {
//% block="none" jres=colors.none blockIdentity=sensors.color
//% block="none" blockIdentity=sensors.__colorEnumPicker
None,
//% block="black" jres=colors.black blockIdentity=sensors.color
//% block="black" blockIdentity=sensors.__colorEnumPicker
Black,
//% block="blue" jres=colors.blue blockIdentity=sensors.color
//% block="blue" blockIdentity=sensors.__colorEnumPicker
Blue,
//% block="green" jres=colors.green blockIdentity=sensors.color
//% block="green" blockIdentity=sensors.__colorEnumPicker
Green,
//% block="yellow" jres=colors.yellow blockIdentity=sensors.color
//% block="yellow" blockIdentity=sensors.__colorEnumPicker
Yellow,
//% block="red" jres=colors.red blockIdentity=sensors.color
//% block="red" blockIdentity=sensors.__colorEnumPicker
Red,
//% block="white" jres=colors.white blockIdentity=sensors.color
//% block="white" blockIdentity=sensors.__colorEnumPicker
White,
//% block="brown" jres=colors.brown blockIdentity=sensors.color
//% block="brown" blockIdentity=sensors.__colorEnumPicker
Brown
}
@ -110,19 +110,14 @@ namespace sensors {
* @param handler the code to run when detected
*/
//% help=sensors/color-sensor/on-color-detected
//% block="on **color** %this|detected color %color"
//% block="on **color** %this|detected color %color=colorEnumPicker"
//% blockId=colorOnColorDetected
//% parts="colorsensor"
//% blockNamespace=sensors
//% this.fieldEditor="ports"
//% weight=100 blockGap=12
//% group="Color Sensor"
//% color.fieldEditor="gridpicker"
//% color.fieldOptions.columns=4
//% color.fieldOptions.tooltips=true
//% color.fieldOptions.hideRect=true
//% color.fieldOptions.width=268
onColorDetected(color: ColorSensorColor, handler: () => void) {
onColorDetected(color: number, handler: () => void) {
this.setMode(ColorSensorMode.Color)
const v = this._colorEventValue(<number>color);
control.onEvent(this._id, v, handler);
@ -135,19 +130,14 @@ namespace sensors {
* @param color the color to detect
*/
//% help=sensors/color-sensor/pause-for-color
//% block="pause **color** %this|for color %color"
//% block="pause **color** %this|for color %color=colorEnumPicker"
//% blockId=colorPauseForColorDetected
//% parts="colorsensor"
//% blockNamespace=sensors
//% this.fieldEditor="ports"
//% weight=99 blockGap=8
//% group="Color Sensor"
//% color.fieldEditor="gridpicker"
//% color.fieldOptions.columns=4
//% color.fieldOptions.tooltips=true
//% color.fieldOptions.hideRect=true
//% color.fieldOptions.width=268
pauseForColor(color: ColorSensorColor) {
pauseForColor(color: number) {
this.setMode(ColorSensorMode.Color);
if (this.color() != color) {
const v = this._colorEventValue(<number>color);
@ -319,16 +309,11 @@ namespace sensors {
* @param color the color sensed by the sensor, eg: ColorSensorColor.Red
*/
//% shim=TD_ID
//% blockId=colorSensorColor block="color %color"
//% blockId=colorSensorColor block="color %color=colorEnumPicker"
//% group="Color Sensor"
//% weight=97
//% help=sensors/color
//% color.fieldEditor="gridpicker"
//% color.fieldOptions.columns=4
//% color.fieldOptions.tooltips=true
//% color.fieldOptions.hideRect=true
//% color.fieldOptions.width=268
export function color(color: ColorSensorColor): ColorSensorColor {
export function color(color: number): ColorSensorColor {
return color;
}

17
libs/color-sensor/ns.ts Normal file
View File

@ -0,0 +1,17 @@
namespace sensors {
/**
* A color enum picker
* @param color to use, eg: ColorSensorColor.Blue
*/
//% blockId=colorEnumPicker block="%color" shim=TD_ID
//% weight=0 blockHidden=1 turnRatio.fieldOptions.decompileLiterals=1
//% color.fieldEditor="colorenum"
//% color.fieldOptions.colours='["#f12a21", "#ffd01b", "#006db3", "#00934b", "#ffffff", "#6c2d00", "#000000"]'
//% color.fieldOptions.columns=2 color.fieldOptions.className='legoColorPicker'
export function __colorEnumPicker(color: ColorSensorColor): number {
return color;
}
}

View File

@ -4,7 +4,8 @@
"files": [
"README.md",
"colors.jres",
"color.ts"
"color.ts",
"ns.ts"
],
"testFiles": [
"test.ts"

View File

@ -41,10 +41,10 @@ namespace brick {
* An image
* @param image the image
*/
//% blockId=mood_image_picker block="%image" shim=TD_ID
//% image.fieldEditor="images"
//% image.fieldOptions.columns=4
//% image.fieldOptions.width=400
//% blockId=mood_image_picker block="%mood" shim=TD_ID
//% mood.fieldEditor="images"
//% mood.fieldOptions.columns=4
//% mood.fieldOptions.width=400
//% group="Screen" weight=0 blockHidden=1
export function __moodImagePicker(mood: Mood): Mood {
return mood;

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "pxt-ev3",
"version": "0.0.107",
"version": "0.0.109",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "pxt-ev3",
"version": "0.0.107",
"version": "0.0.109",
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
"private": true,
"keywords": [
@ -45,8 +45,8 @@
"webfonts-generator": "^0.4.0"
},
"dependencies": {
"pxt-common-packages": "0.19.5",
"pxt-core": "3.4.8"
"pxt-common-packages": "0.20.3",
"pxt-core": "3.4.9"
},
"scripts": {
"test": "node node_modules/pxt-core/built/pxt.js travis"

View File

@ -351,6 +351,10 @@ namespace pxsim.visuals {
private buildScreenCanvas() {
this.screenCanvas = document.createElement("canvas");
this.screenCanvas.id = "board-screen-canvas";
this.screenCanvas.style.userSelect = "none";
this.screenCanvas.style.msUserSelect = "none";
this.screenCanvas.style.webkitUserSelect = "none";
(this.screenCanvas.style as any).MozUserSelect = "none";
this.screenCanvas.style.position = "absolute";
this.screenCanvas.addEventListener(pxsim.pointerEvents.up, ev => {
this.layoutView.selectBrick();

View File

@ -37,3 +37,24 @@
stroke:#fc3;
stroke-width: 4px !important;
}
/* Color enum picker */
.blocklyDropDownDiv {
.goog-palette {
margin-bottom: 0px !important;
}
.legoColorPicker {
.goog-palette-colorswatch {
height: 30px;
width: 30px;
border-radius: 100%;
}
.goog-palette-cell-hover .goog-palette-colorswatch {
border: 2px solid #000;
}
.goog-palette-cell-selected .goog-palette-colorswatch {
border: 3px solid #000;
}
}
}