Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
1340fd0162 | |||
a3f56f4c9a | |||
c0e2252157 | |||
92ad67315b | |||
8b3064f4e0 | |||
138709285a | |||
65dd4617f1 | |||
bdc8c1c62c | |||
ebcde71950 | |||
d42117a2a5 | |||
b0145cf378 | |||
868ee826ab | |||
ce489bba56 | |||
b0944ba431 | |||
8736d32f09 |
@ -28,19 +28,33 @@ namespace pxt.editor {
|
||||
|
||||
let initPromise: Promise<Ev3Wrapper>
|
||||
function initAsync() {
|
||||
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)
|
||||
})
|
||||
if (initPromise)
|
||||
return initPromise
|
||||
|
||||
let canHID = false
|
||||
if (U.isNodeJS) {
|
||||
canHID = true
|
||||
} else {
|
||||
const forceHexDownload = /forceHexDownload/i.test(window.location.href);
|
||||
if (Cloud.isLocalHost() && Cloud.localToken && !forceHexDownload)
|
||||
canHID = true
|
||||
}
|
||||
|
||||
if (noHID)
|
||||
canHID = false
|
||||
|
||||
if (canHID) {
|
||||
initPromise = hf2Async()
|
||||
.catch(err => {
|
||||
initPromise = null
|
||||
noHID = true
|
||||
return Promise.reject(err)
|
||||
})
|
||||
} else {
|
||||
noHID = true
|
||||
initPromise = Promise.reject(new Error("no HID"))
|
||||
initPromise = Promise.reject(new Error("no HID"))
|
||||
}
|
||||
|
||||
return initPromise
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,8 @@
|
||||
"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.getCurrentSpeed": "Get motor speed.",
|
||||
"output.getCurrentSpeed|param|out": "the output connection that the motor is connected to",
|
||||
"output.getPattern": "Pattern block.",
|
||||
"output.getPattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green",
|
||||
"output.setLights": "Set lights.",
|
||||
@ -41,6 +43,10 @@
|
||||
"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."
|
||||
}
|
@ -3,6 +3,16 @@
|
||||
"ButtonEvent.Down|block": "down",
|
||||
"ButtonEvent.LongClick|block": "long click",
|
||||
"ButtonEvent.Up|block": "up",
|
||||
"LightsPattern.GreenFlash|block": "Flashing Green",
|
||||
"LightsPattern.GreenPulse|block": "Pulsing Green",
|
||||
"LightsPattern.Green|block": "Green",
|
||||
"LightsPattern.Off|block": "Off",
|
||||
"LightsPattern.OrangeFlash|block": "Flashing Orange",
|
||||
"LightsPattern.OrangePulse|block": "Pulsing Orange",
|
||||
"LightsPattern.Orange|block": "Orange",
|
||||
"LightsPattern.RedFlash|block": "Flashing Red",
|
||||
"LightsPattern.RedPulse|block": "Pulsing Red",
|
||||
"LightsPattern.Red|block": "Red",
|
||||
"control.raiseEvent|block": "raise event|from %src|with value %value",
|
||||
"control|block": "control",
|
||||
"input.buttonDown|block": "button down",
|
||||
@ -16,14 +26,16 @@
|
||||
"input.remoteTopLeft|block": "remote top-left",
|
||||
"input.remoteTopRight|block": "remote top-right",
|
||||
"input|block": "input",
|
||||
"output.getCurrentSpeed|block": "motor %out|speed",
|
||||
"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.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",
|
||||
@ -32,5 +44,6 @@
|
||||
"{id:category}Screen": "Screen",
|
||||
"{id:category}Serial": "Serial",
|
||||
"{id:group}Lights": "Lights",
|
||||
"{id:group}Motors": "Motors"
|
||||
"{id:group}Motors": "Motors",
|
||||
"{id:group}Screen": "Screen"
|
||||
}
|
@ -3,15 +3,35 @@
|
||||
* Patterns for lights under the buttons.
|
||||
*/
|
||||
const enum LightsPattern {
|
||||
//% block=Off enumval=0
|
||||
//% blockIdentity=output.getPattern
|
||||
Off = 0,
|
||||
//% block=Green enumval=1
|
||||
//% blockIdentity=output.getPattern
|
||||
Green = 1,
|
||||
//% block=Red enumval=2
|
||||
//% blockIdentity=output.getPattern
|
||||
Red = 2,
|
||||
//% block=Orange enumval=3
|
||||
//% blockIdentity=output.getPattern
|
||||
Orange = 3,
|
||||
//% block="Flashing Green" enumval=4
|
||||
//% blockIdentity=output.getPattern
|
||||
GreenFlash = 4,
|
||||
//% block="Flashing Red" enumval=5
|
||||
//% blockIdentity=output.getPattern
|
||||
RedFlash = 5,
|
||||
//% block="Flashing Orange" enumval=6
|
||||
//% blockIdentity=output.getPattern
|
||||
OrangeFlash = 6,
|
||||
//% block="Pulsing Green" enumval=7
|
||||
//% blockIdentity=output.getPattern
|
||||
GreenPulse = 7,
|
||||
//% block="Pulsing Red" enumval=8
|
||||
//% blockIdentity=output.getPattern
|
||||
RedPulse = 8,
|
||||
//% block="Pulsing Orange" enumval=9
|
||||
//% blockIdentity=output.getPattern
|
||||
OrangePulse = 9,
|
||||
}
|
||||
|
||||
@ -238,7 +258,7 @@ namespace output {
|
||||
*/
|
||||
//% blockId=led_pattern block="%pattern"
|
||||
//% shim=TD_ID colorSecondary="#6e9a36"
|
||||
//% blockHidden=true
|
||||
//% blockHidden=true useEnumVal=1 pattern.fieldOptions.decompileLiterals=1
|
||||
export function getPattern(pattern: LightsPattern): number {
|
||||
return pattern;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ enum OutputType {
|
||||
namespace output {
|
||||
let pwmMM: MMap
|
||||
let motorMM: MMap
|
||||
let currentSpeed: number[] = []
|
||||
|
||||
const enum MotorDataOff {
|
||||
TachoCounts = 0, // int32
|
||||
@ -29,9 +30,15 @@ namespace output {
|
||||
pwmMM = control.mmap("/dev/lms_pwm", 0, 0)
|
||||
if (!pwmMM) control.fail("no PWM file")
|
||||
motorMM = control.mmap("/dev/lms_motor", MotorDataOff.Size * DAL.NUM_OUTPUTS, 0)
|
||||
|
||||
|
||||
stop(Output.ALL)
|
||||
|
||||
currentSpeed[Output.A] = -1;
|
||||
currentSpeed[Output.B] = -1;
|
||||
currentSpeed[Output.C] = -1;
|
||||
currentSpeed[Output.D] = -1;
|
||||
currentSpeed[Output.ALL] = -1;
|
||||
|
||||
let buf = output.createBuffer(1)
|
||||
buf[0] = DAL.opProgramStart
|
||||
writePWM(buf)
|
||||
@ -60,15 +67,16 @@ namespace output {
|
||||
* @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"
|
||||
//% 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,
|
||||
speed: 100,
|
||||
step1: 0,
|
||||
step2: ms,
|
||||
step3: 0,
|
||||
useSteps: false,
|
||||
useBrake: useBrake
|
||||
})
|
||||
}
|
||||
@ -77,7 +85,7 @@ namespace output {
|
||||
* Turn motor off.
|
||||
* @param out the output connection that the motor is connected to
|
||||
*/
|
||||
//% blockId=output_stop block="turn motor %out| off"
|
||||
//% 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)
|
||||
@ -89,9 +97,10 @@ namespace output {
|
||||
* Turn motor on.
|
||||
* @param out the output connection that the motor is connected to
|
||||
*/
|
||||
//% blockId=output_start block="turn motor %out| on"
|
||||
//% blockId=output_start block="turn motor %out|on"
|
||||
//% weight=95 group="Motors"
|
||||
export function start(out: Output) {
|
||||
if (currentSpeed[out] == -1) setSpeed(out, 50)
|
||||
let b = mkCmd(out, DAL.opOutputStart, 0)
|
||||
writePWM(b)
|
||||
}
|
||||
@ -101,11 +110,49 @@ 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)
|
||||
}*/
|
||||
export function clearCount(out: Output) {
|
||||
let b = mkCmd(out, DAL.opOutputClearCount, 0)
|
||||
writePWM(b)
|
||||
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
|
||||
if (out & (1 << i)) {
|
||||
motorMM.setNumber(NumberFormat.Int32LE, i * MotorDataOff.Size + MotorDataOff.TachoSensor, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function outOffset(out: Output) {
|
||||
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
|
||||
if (out & (1 << i))
|
||||
return i * MotorDataOff.Size
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
export interface MotorData {
|
||||
actualSpeed: number; // -100..+100
|
||||
tachoCount: number;
|
||||
count: number;
|
||||
}
|
||||
|
||||
// only a single output at a time
|
||||
export function getMotorData(out: Output): MotorData {
|
||||
let buf = motorMM.slice(outOffset(out), MotorDataOff.Size)
|
||||
return {
|
||||
actualSpeed: buf.getNumber(NumberFormat.Int8LE, MotorDataOff.Speed),
|
||||
tachoCount: buf.getNumber(NumberFormat.Int32LE, MotorDataOff.TachoCounts),
|
||||
count: buf.getNumber(NumberFormat.Int32LE, MotorDataOff.TachoSensor),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get motor speed.
|
||||
* @param out the output connection that the motor is connected to
|
||||
*/
|
||||
//% blockId=output_getCurrentSpeed block="motor %out|speed"
|
||||
//% weight=70 group="Motors"
|
||||
export function getCurrentSpeed(out: Output) {
|
||||
return getMotorData(out).actualSpeed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set motor speed.
|
||||
@ -116,6 +163,7 @@ namespace output {
|
||||
//% weight=81 group="Motors"
|
||||
//% speed.min=-100 speed.max=100
|
||||
export function setSpeed(out: Output, speed: number) {
|
||||
currentSpeed[out] = speed;
|
||||
let b = mkCmd(out, DAL.opOutputSpeed, 1)
|
||||
b.setNumber(NumberFormat.Int8LE, 2, Math.clamp(-100, 100, speed))
|
||||
writePWM(b)
|
||||
|
@ -84,8 +84,18 @@ 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"
|
||||
//% x.min=0 x.max=178 y.min=0 y.max=128
|
||||
export function drawText(text: string, x: number, y: number, mode = Draw.Normal) {
|
||||
x |= 0
|
||||
y |= 0
|
||||
if (!currFont) currFont = defaultFont()
|
||||
|
@ -1,10 +1,10 @@
|
||||
screen.clear()
|
||||
screen.drawText(10, 30, "PXT!", Draw.Quad)
|
||||
screen.drawText("PXT!", 10, 30, Draw.Quad)
|
||||
|
||||
screen.drawRect(40, 40, 20, 10, Draw.Fill)
|
||||
output.setLights(LightsPattern.Orange)
|
||||
|
||||
screen.drawIcon(100, 50, screen.doubleIcon(screen.heart), Draw.Double|Draw.Transparent)
|
||||
screen.drawIcon(100, 50, screen.doubleIcon(screen.heart), Draw.Double | Draw.Transparent)
|
||||
|
||||
input.buttonEnter.onEvent(ButtonEvent.Click, () => {
|
||||
screen.clear()
|
||||
@ -17,32 +17,32 @@ input.buttonLeft.onEvent(ButtonEvent.Click, () => {
|
||||
})
|
||||
|
||||
input.buttonRight.onEvent(ButtonEvent.Click, () => {
|
||||
screen.drawText(10, 60, "Right!")
|
||||
screen.drawText("Right!", 10, 60)
|
||||
})
|
||||
|
||||
input.buttonDown.onEvent(ButtonEvent.Click, () => {
|
||||
screen.drawText(10, 60, "Down! ")
|
||||
screen.drawText("Down! ", 10, 60)
|
||||
})
|
||||
|
||||
input.buttonUp.onEvent(ButtonEvent.Click, () => {
|
||||
screen.drawText(10, 60, "Up! ")
|
||||
screen.drawText("Up! ", 10, 60)
|
||||
})
|
||||
|
||||
|
||||
let num = 0
|
||||
|
||||
input.touchSensor.onEvent(ButtonEvent.Click, () => {
|
||||
screen.drawText(10, 60, "Click! " + num)
|
||||
screen.drawText("Click! " + num, 10, 60)
|
||||
num++
|
||||
})
|
||||
|
||||
input.remoteTopLeft.onEvent(ButtonEvent.Click, () => {
|
||||
screen.drawText(10, 60, "TOPLEFT " + num)
|
||||
screen.drawText("TOPLEFT " + num, 10, 60)
|
||||
num++
|
||||
})
|
||||
|
||||
input.remoteTopRight.onEvent(ButtonEvent.Down, () => {
|
||||
screen.drawText(10, 60, "TOPRIGH " + num)
|
||||
screen.drawText("TOPRIGH " + num, 10, 60)
|
||||
num++
|
||||
})
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
|
||||
//% color="#D42878"
|
||||
//% groups='["Brick buttons"]'
|
||||
namespace input {
|
||||
}
|
||||
|
||||
//% color="#8AC044" weight=90 icon="\uf185"
|
||||
//% groups="['Lights', 'Motors']"
|
||||
//% groups='["Lights", "Screen", "Motors"]'
|
||||
namespace output {
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-ev3",
|
||||
"version": "0.0.11",
|
||||
"version": "0.0.15",
|
||||
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
|
||||
"private": true,
|
||||
"keywords": [
|
||||
@ -40,7 +40,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-common-packages": "0.9.2",
|
||||
"pxt-core": "2.0.6"
|
||||
"pxt-core": "2.0.10"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
||||
|
Reference in New Issue
Block a user