Compare commits

...

29 Commits

Author SHA1 Message Date
868ee826ab 0.0.12 2017-08-07 23:40:14 -07:00
ce489bba56 Update core-strings 2017-08-07 23:39:54 -07:00
b0944ba431 Change say to print. 2017-08-07 21:50:45 -07:00
8736d32f09 Add screen blocks 2017-08-07 21:50:04 -07:00
f8c481555c 0.0.11 2017-08-07 17:39:55 -07:00
15f50966aa Update motor APIs 2017-08-07 17:39:37 -07:00
88e21db35e fixing raiseEvent 2017-08-07 12:07:43 -07:00
4e9d3aa413 0.0.10 2017-08-07 11:33:51 -07:00
1efad776e6 bump pxt-core to 2.0.6, 2017-08-07 11:33:46 -07:00
5e7af872b5 Add setLights shadow block 2017-08-07 10:19:38 -07:00
17683033b1 Add branch info 2017-08-07 12:15:56 +02:00
31f3d108c5 Update build instructions 2017-08-07 12:15:06 +02:00
b45bf7512c 0.0.9 2017-08-07 11:13:05 +02:00
2dec405a9b Catch errors from initAsync 2017-08-07 11:12:52 +02:00
29009aa5e5 0.0.8 2017-08-07 11:08:15 +02:00
86011827dc Fix initialization without HID 2017-08-07 10:56:21 +02:00
c20cfab069 Fix web deployment, only use HF2 when in localhost (#2) 2017-08-05 17:54:18 +01:00
197f9096f8 0.0.7 2017-08-04 22:53:11 -07:00
6d499cb683 Fix package.json 2017-08-04 22:52:53 -07:00
163a4f89f8 0.0.6 2017-08-04 22:41:39 -07:00
b32aa61cd1 Update package.json 2017-08-04 21:17:52 -07:00
db7cf212d4 0.0.5 2017-08-04 21:06:51 -07:00
c8fb59cdde bump pxt-common-packages to 0.9.2, 2017-08-04 21:06:46 -07:00
264156c485 0.0.4 2017-08-04 20:58:47 -07:00
440dbbe82a Update style, use freshcoat 2017-08-04 20:54:22 -07:00
f4660b4366 0.0.3 2017-08-04 15:25:45 -07:00
a4be9f07ea Add robots no index 2017-08-04 15:25:33 -07:00
0c8661808b 0.0.2 2017-08-04 15:16:21 -07:00
b234337dda Update styles 2017-08-04 15:14:24 -07:00
15 changed files with 201 additions and 58 deletions

View File

@ -9,12 +9,12 @@ This repo contains the editor target hosted at https://lego.makecode.com
These instructions assume familiarity with dev tools and languages.
* install Node.js 6+
* install [yotta](http://docs.yottabuild.org/#installing)
* install Docker; make sure `docker` command is in your `PATH`
* (optional) install [Visual Studio Code](https://code.visualstudio.com/)
In a common folder,
* clone https://github.com/Microsoft/pxt to ``pxt`` folder
* clone https://github.com/Microsoft/pxt to ``pxt`` folder (currently, build against `freshcoat` branch)
* clone https://github.com/Microsoft/pxt-common-packages to ``pxt-common-packages`` folder
* clone https://github.com/Microsoft/pxt-ev3 to ``pxt-ev3`` folder
* go to ``pxt`` and run

1
docfiles/robotsmeta.html Normal file
View File

@ -0,0 +1 @@
<meta name="robots" content="noindex">

View File

@ -28,13 +28,19 @@ namespace pxt.editor {
let initPromise: Promise<Ev3Wrapper>
function initAsync() {
if (!initPromise)
initPromise = hf2Async()
.catch(err => {
initPromise = null
noHID = true
return Promise.reject(err)
})
const forceHexDownload = /forceHexDownload/i.test(window.location.href);
if (Cloud.isLocalHost() && Cloud.localToken && !forceHexDownload) {
if (!initPromise)
initPromise = hf2Async()
.catch(err => {
initPromise = null
noHID = true
return Promise.reject(err)
})
} else {
noHID = true
initPromise = Promise.reject(new Error("no HID"))
}
return initPromise
}
@ -116,13 +122,9 @@ namespace pxt.editor {
const res: pxt.editor.ExtensionResult = {
deployCoreAsync,
};
initAsync()
/*
.then(w => w.streamFileAsync("/tmp/serial.txt", buf => {
let str = Util.fromUTF8(Util.uint8ArrayToString(buf))
}))
*/
initAsync().catch(e => {
// probably no HID - we'll try this again upon deployment
})
return Promise.resolve<pxt.editor.ExtensionResult>(res);
}
}

View File

@ -1,4 +1,37 @@
{
"Array": "Add, remove, and replace items in lists.\n\nAdd, remove, and replace items in lists.",
"Array.filter": "Returns the elements of an array that meet the condition specified in a callback function.",
"Array.filter|param|callbackfn": "A function that accepts up to two arguments. The filter method calls the callbackfn function one time for each element in the array.",
"Array.get": "Gets the value at a particular index",
"Array.get|param|index": "the zero-based position in the list of the item, eg: 0",
"Array.indexOf": "Returns the index of the first occurrence of a value in an array.",
"Array.indexOf|param|fromIndex": "The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.",
"Array.indexOf|param|item": "The value to locate in the array.",
"Array.insertAt": "Insert the value at a particular index, increases length by 1",
"Array.insertAt|param|index": "the zero-based position in the list to insert the value, eg: 0",
"Array.length": "Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.",
"Array.map": "Calls a defined callback function on each element of an array, and returns an array that contains the results.",
"Array.map|param|callbackfn": "A function that accepts up to two arguments. The map method calls the callbackfn function one time for each element in the array.",
"Array.pop": "Removes the last element from an array and returns it.",
"Array.push": "Appends new elements to an array.",
"Array.reduce": "Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.",
"Array.reduce|param|callbackfn": "A function that accepts up to three arguments. The reduce method calls the callbackfn function one time for each element in the array.",
"Array.reduce|param|initialValue": "Initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.",
"Array.removeAt": "Removes the object at position index.",
"Array.removeElement": "Removes the first occurence of an object. Returns true if removed.",
"Array.reverse": "Reverses the elements in an Array. The first array element becomes the last, and the last array element becomes the first.",
"Array.set": "Stores the value at a particular index",
"Array.set|param|index": "the zero-based position in the list to store the value, eg: 0",
"Array.shift": "Removes the first element from an array and returns that element. This method changes the length of the array.",
"Array.slice": "Returns a section of an array.",
"Array.slice|param|end": "The end of the specified portion of the array. eg: 0",
"Array.slice|param|start": "The beginning of the specified portion of the array. eg: 0",
"Array.sort": "Sorts the elements of an array in place and returns the array. The sort is not necessarily stable.",
"Array.splice": "Removes elements from an array.",
"Array.splice|param|deleteCount": "The number of elements to remove. eg: 0",
"Array.splice|param|start": "The zero-based location in the array from which to start removing elements. eg: 0",
"Array.unshift": "Adds one element to the beginning of an array and returns the new length of the array.",
"Math": "More complex operations with numbers.",
"Math.abs": "Returns the absolute value of a number (the value without regard to whether it is positive or negative).\nFor example, the absolute value of -5 is the same as the absolute value of 5.",
"Math.abs|param|x": "A numeric expression for which the absolute value is needed.",
"Math.acos": "Returns the arccosine (in radians) of a number",
@ -58,6 +91,7 @@
"Math.tan|param|x": "An angle in radians",
"Math.trunc": "Returns the number with the decimal part truncated.",
"Math.trunc|param|x": "A numeric expression.",
"String": "Combine, split, and search text strings.\n\nCombine, split, and search text strings.",
"String.charAt": "Returns the character at the specified index.",
"String.charAt|param|index": "The zero-based index of the desired character.",
"String.charCodeAt": "Returns the Unicode value of the character at the specified location.",

View File

@ -1,4 +1,14 @@
{
"Array.indexOf|block": "%list| find index of %value",
"Array.insertAt|block": "%list| insert at %index| value %value",
"Array.length|block": "length of %VALUE",
"Array.pop|block": "get and remove last value from %list",
"Array.push|block": "%list| add value %value| to end",
"Array.removeAt|block": "%list| remove value at %index",
"Array.reverse|block": "reverse %list",
"Array.shift|block": "get and remove first value from %list",
"Array.unshift|block": "%list| insert %value| at beginning",
"Array|block": "Array",
"Math.constrain|block": "constrain %value|between %low|and %high",
"Math.map|block": "map %value|from low %fromLow|from high %fromHigh|to low %toLow|to high %toHigh",
"Math.randomRange|block": "pick random %min|to %limit",
@ -27,6 +37,8 @@
"serial.writeString|block": "serial|write string %text",
"serial.writeValue|block": "serial|write value %name|= %value",
"serial|block": "serial",
"{id:category}Array": "Array",
"{id:category}Arrays": "Arrays",
"{id:category}Control": "Control",
"{id:category}Loops": "Loops",
"{id:category}Math": "Math",

View File

@ -20,10 +20,31 @@
"input.remoteTopRight": "Remote top-right button.",
"output.createBuffer": "Create a new zero-initialized buffer.",
"output.createBuffer|param|size": "number of bytes in the buffer",
"output.getPattern": "Pattern block.",
"output.getPattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green",
"output.setLights": "Set lights.",
"output.setLights|param|pattern": "the lights pattern to use.",
"output.setPower": "Set motor power.",
"output.setPower|param|out": "the output connection that the motor is connected to",
"output.setPower|param|power": "the desired power to use. eg: 100",
"output.setSpeed": "Set motor speed.",
"output.setSpeed|param|out": "the output connection that the motor is connected to",
"output.setSpeed|param|speed": "the desired speed to use. eg: 100",
"output.start": "Turn motor on.",
"output.start|param|out": "the output connection that the motor is connected to",
"output.stop": "Turn motor off.",
"output.stop|param|out": "the output connection that the motor is connected to",
"output.turn": "Turn a motor on for a specified number of milliseconds.",
"output.turn|param|ms": "the number of milliseconds to turn the motor on, eg: 500",
"output.turn|param|out": "the output connection that the motor is connected to",
"output.turn|param|useBrake": "whether or not to use the brake, defaults to false",
"screen.clear": "Clear screen and reset font to normal.",
"screen.doubleIcon": "Double size of an icon.",
"screen.drawIcon": "Draw an icon on the screen.",
"screen.drawText": "Show text on the screen.",
"screen.drawText|param|text": "the text to print on the screen, eg: \"Hello world\"",
"screen.drawText|param|x": "the starting position's x coordinate, eg: 0",
"screen.drawText|param|y": "the starting position's x coordinate, eg: 0",
"serial": "Reading and writing data over a serial connection.",
"serial.writeDmesg": "Send DMESG debug buffer over serial."
}

View File

@ -3,7 +3,7 @@
"ButtonEvent.Down|block": "down",
"ButtonEvent.LongClick|block": "long click",
"ButtonEvent.Up|block": "up",
"control.raiseEvent|block": "raise event|from %src|with value value",
"control.raiseEvent|block": "raise event|from %src|with value %value",
"control|block": "control",
"input.buttonDown|block": "button down",
"input.buttonEnter|block": "button enter",
@ -16,13 +16,23 @@
"input.remoteTopLeft|block": "remote top-left",
"input.remoteTopRight|block": "remote top-right",
"input|block": "input",
"output.setLights|block": "set lights %pattern",
"output.getPattern|block": "%pattern",
"output.setLights|block": "set status light %pattern=led_pattern",
"output.setPower|block": "set motor %out| power to %power",
"output.setSpeed|block": "set motor %out| speed to %speed",
"output.start|block": "turn motor %out| on",
"output.stop|block": "turn motor %out| off",
"output.turn|block": "turn motor %out| on for %ms| milliseconds",
"output|block": "output",
"screen.drawText|block": "print %text| at x: %x| y: %y",
"screen|block": "screen",
"serial|block": "serial",
"{id:category}Control": "Control",
"{id:category}Input": "Input",
"{id:category}Output": "Output",
"{id:category}Screen": "Screen",
"{id:category}Serial": "Serial"
"{id:category}Serial": "Serial",
"{id:group}Lights": "Lights",
"{id:group}Motors": "Motors",
"{id:group}Screen": "Screen"
}

View File

@ -70,6 +70,7 @@ namespace input {
//% blockGap=8
//% parts="buttonpair"
//% blockNamespace=input
//% group="Brick buttons"
//% button.fieldEditor="gridpicker"
//% button.fieldOptions.width=220
//% button.fieldOptions.columns=3
@ -86,6 +87,7 @@ namespace input {
//% blockId=buttonWasPressed
//% parts="buttonpair" blockGap=8
//% blockNamespace=input advanced=true
//% group="Brick buttons"
//% button.fieldEditor="gridpicker"
//% button.fieldOptions.width=220
//% button.fieldOptions.columns=3
@ -105,6 +107,7 @@ namespace input {
//% blockId=buttonEvent block="on %button|%event"
//% parts="buttonpair"
//% blockNamespace=input
//% group="Brick buttons"
//% button.fieldEditor="gridpicker"
//% button.fieldOptions.width=220
//% button.fieldOptions.columns=3
@ -215,9 +218,11 @@ namespace output {
/**
* Set lights.
* @param pattern the lights pattern to use.
*/
//% blockId=setLights block="set lights %pattern"
export function setLights(pattern: LightsPattern): void {
//% blockId=setLights block="set status light %pattern=led_pattern"
//% weight=100 group="Lights"
export function setLights(pattern: number): void {
if (currPattern === pattern)
return
currPattern = pattern
@ -225,4 +230,16 @@ namespace output {
cmd[0] = pattern + 48
input.internal.getBtnsMM().write(cmd)
}
/**
* Pattern block.
* @param pattern the lights pattern to use. eg: LightsPattern.Green
*/
//% blockId=led_pattern block="%pattern"
//% shim=TD_ID colorSecondary="#6e9a36"
//% blockHidden=true
export function getPattern(pattern: LightsPattern): number {
return pattern;
}
}

View File

@ -9,7 +9,7 @@ namespace control {
* @param mode optional definition of how the event should be processed after construction.
*/
//% weight=21 blockGap=12 blockId="control_raise_event"
//% block="raise event|from %src|with value value" blockExternalInputs=1
//% block="raise event|from %src|with value %value" blockExternalInputs=1
void raiseEvent(int src, int value) {
pxt::raiseEvent(src, value);
}

View File

@ -42,6 +42,11 @@ namespace output {
pwmMM.write(buf)
}
function readPWM(buf: Buffer): void {
init()
pwmMM.read(buf);
}
function mkCmd(out: Output, cmd: number, addSize: number) {
let b = createBuffer(2 + addSize)
b.setNumber(NumberFormat.UInt8LE, 0, cmd)
@ -49,12 +54,43 @@ namespace output {
return b
}
export function stop(out: Output, useBreak = false) {
/**
* Turn a motor on for a specified number of milliseconds.
* @param out the output connection that the motor is connected to
* @param ms the number of milliseconds to turn the motor on, eg: 500
* @param useBrake whether or not to use the brake, defaults to false
*/
//% blockId=output_turn block="turn motor %out| on for %ms| milliseconds"
//% weight=100 group="Motors"
export function turn(out: Output, ms: number, useBrake = false) {
// TODO: use current power / speed configuration
output.step(out, {
power: 100,
step1: 0,
step2: ms,
step3: 0,
useBrake: useBrake
})
}
/**
* Turn motor off.
* @param out the output connection that the motor is connected to
*/
//% blockId=output_stop block="turn motor %out| off"
//% weight=90 group="Motors"
export function stop(out: Output, useBrake = false) {
let b = mkCmd(out, DAL.opOutputStop, 1)
b.setNumber(NumberFormat.UInt8LE, 2, useBreak ? 1 : 0)
b.setNumber(NumberFormat.UInt8LE, 2, useBrake ? 1 : 0)
writePWM(b)
}
/**
* Turn motor on.
* @param out the output connection that the motor is connected to
*/
//% blockId=output_start block="turn motor %out| on"
//% weight=95 group="Motors"
export function start(out: Output) {
let b = mkCmd(out, DAL.opOutputStart, 0)
writePWM(b)
@ -65,12 +101,34 @@ namespace output {
writePWM(b)
}
/*export function getSpeed(out: Output): number {
let b = mkCmd(out, DAL.opOutputSpeed, 0)
readPWM(b)
return b.getNumber(NumberFormat.Int16LE, 1)
}*/
/**
* Set motor speed.
* @param out the output connection that the motor is connected to
* @param speed the desired speed to use. eg: 100
*/
//% blockId=output_setSpeed block="set motor %out| speed to %speed"
//% weight=81 group="Motors"
//% speed.min=-100 speed.max=100
export function setSpeed(out: Output, speed: number) {
let b = mkCmd(out, DAL.opOutputSpeed, 1)
b.setNumber(NumberFormat.Int8LE, 2, Math.clamp(-100, 100, speed))
writePWM(b)
}
/**
* Set motor power.
* @param out the output connection that the motor is connected to
* @param power the desired power to use. eg: 100
*/
//% blockId=output_setPower block="set motor %out| power to %power"
//% weight=80 group="Motors"
//% power.min=-100 power.max=100
export function setPower(out: Output, power: number) {
let b = mkCmd(out, DAL.opOutputPower, 1)
b.setNumber(NumberFormat.Int8LE, 2, Math.clamp(-100, 100, power))
@ -90,7 +148,7 @@ namespace output {
step2: number;
step3: number;
useSteps?: boolean; // otherwise use milliseconds
useBreak?: boolean;
useBrake?: boolean;
}
export function step(out: Output, opts: StepOptions) {
@ -110,7 +168,7 @@ namespace output {
b.setNumber(NumberFormat.Int32LE, 4 + 4 * 0, opts.step1)
b.setNumber(NumberFormat.Int32LE, 4 + 4 * 1, opts.step2)
b.setNumber(NumberFormat.Int32LE, 4 + 4 * 2, opts.step3)
b.setNumber(NumberFormat.Int8LE, 4 + 4 * 3, opts.useBreak ? 1 : 0)
b.setNumber(NumberFormat.Int8LE, 4 + 4 * 3, opts.useBrake ? 1 : 0)
writePWM(b)
}

View File

@ -84,8 +84,17 @@ namespace screen {
if (0 <= x && x < DAL.LCD_WIDTH && 0 <= y && y < DAL.LCD_HEIGHT)
_setPixel(x, y, mode)
}
export function drawText(x: number, y: number, text: string, mode = Draw.Normal) {
/**
* Show text on the screen.
* @param text the text to print on the screen, eg: "Hello world"
* @param x the starting position's x coordinate, eg: 0
* @param y the starting position's x coordinate, eg: 0
*/
//% blockId=screen_drawText block="print %text| at x: %x| y: %y"
//% weight=99 group="Screen" blockNamespace=output inlineInputMode="inline"
export function drawText(text: string, x: number, y: number, mode = Draw.Normal) {
x |= 0
y |= 0
if (!currFont) currFont = defaultFont()

View File

@ -51,7 +51,7 @@ declare namespace control {
* @param mode optional definition of how the event should be processed after construction.
*/
//% weight=21 blockGap=12 blockId="control_raise_event"
//% block="raise event|from %src|with value value" blockExternalInputs=1 shim=control::raiseEvent
//% block="raise event|from %src|with value %value" blockExternalInputs=1 shim=control::raiseEvent
function raiseEvent(src: int32, value: int32): void;
/**

View File

@ -1,9 +1,11 @@
//% color="#D42878"
//% groups="['Brick buttons']"
namespace input {
}
//% color="#8AC044" weight=90 icon="\uf185"
//% groups="['Lights', 'Screen', Motors']"
namespace output {
}

View File

@ -1,6 +1,6 @@
{
"name": "pxt-ev3",
"version": "0.0.1",
"version": "0.0.12",
"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.9.1",
"pxt-core": "1.8.10"
"pxt-common-packages": "0.9.2",
"pxt-core": "2.0.6"
},
"scripts": {
"test": "node node_modules/pxt-core/built/pxt.js travis"

View File

@ -73,10 +73,6 @@ div.blocklyTreeRow {
box-shadow: inset 0px 0px 0px 3px rgba(0,0,0,0.1);
}
div.blocklyTreeRoot div div div div div.blocklyTreeRow {
padding-top: 0.5rem !important;
}
/* Remove shadow around blockly blocks */
.blocklyPathDark, .blocklyPathLight {
display: none;
@ -98,11 +94,12 @@ span.blocklyTreeLabel {
}
/* Editor menu toggle */
#menubar .ui.menu .item.editor-menuitem {
#menubar .ui.menu.fixed .item.editor-menuitem .ui.grid {
background: @blue !important;
}
#menubar .ui.menu .item.editor-menuitem .item {
color: white !important;
#menubar .ui.menu.fixed .ui.item.editor-menuitem .item:not(.active) {
color: white;
}
/* Search box */
@ -124,11 +121,6 @@ span.blocklyTreeLabel {
#filelist {
background: transparent;
}
div.blocklyTreeRow {
padding-bottom: 2rem !important;
min-height: @blocklyRowHeightMobile;
line-height: @blocklyRowHeightMobile/2;
}
#blocklyTrashIcon {
margin: 0.2rem;
}
@ -136,29 +128,14 @@ span.blocklyTreeLabel {
/* Tablet */
@media only screen and (min-width: @tabletBreakpoint) and (max-width: @largestTabletScreen) {
div.blocklyTreeRow {
padding-left: 0.5rem !important;
min-height: @blocklyRowHeightTablet;
line-height: @blocklyRowHeightTablet/2;
}
}
/* Small Monitor */
@media only screen and (min-width: @computerBreakpoint) and (max-width: @largestSmallMonitor) {
div.blocklyTreeRow {
padding-left: 0.5rem !important;
min-height: @blocklyRowHeightComputer;
line-height: @blocklyRowHeightComputer/2;
}
}
/* Large Monitor */
@media only screen and (min-width: @largeMonitorBreakpoint) {
div.blocklyTreeRow {
padding-left: 0.5rem !important;
min-height: @blocklyRowHeightWide;
line-height: @blocklyRowHeightWide/2;
}
}
/* Mobile, Tablet AND thin screen */
@media only screen and (max-width: @largestTabletScreen) and (max-height: @thinEditorBreakpoint) {