Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
8b3064f4e0 | |||
138709285a | |||
65dd4617f1 | |||
bdc8c1c62c | |||
ebcde71950 | |||
d42117a2a5 | |||
b0145cf378 |
@ -28,19 +28,33 @@ namespace pxt.editor {
|
|||||||
|
|
||||||
let initPromise: Promise<Ev3Wrapper>
|
let initPromise: Promise<Ev3Wrapper>
|
||||||
function initAsync() {
|
function initAsync() {
|
||||||
const forceHexDownload = /forceHexDownload/i.test(window.location.href);
|
if (initPromise)
|
||||||
if (Cloud.isLocalHost() && Cloud.localToken && !forceHexDownload) {
|
return initPromise
|
||||||
if (!initPromise)
|
|
||||||
initPromise = hf2Async()
|
let canHID = false
|
||||||
.catch(err => {
|
if (U.isNodeJS) {
|
||||||
initPromise = null
|
canHID = true
|
||||||
noHID = true
|
} else {
|
||||||
return Promise.reject(err)
|
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 {
|
} else {
|
||||||
noHID = true
|
noHID = true
|
||||||
initPromise = Promise.reject(new Error("no HID"))
|
initPromise = Promise.reject(new Error("no HID"))
|
||||||
}
|
}
|
||||||
|
|
||||||
return initPromise
|
return initPromise
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
"input.remoteTopRight": "Remote top-right button.",
|
"input.remoteTopRight": "Remote top-right button.",
|
||||||
"output.createBuffer": "Create a new zero-initialized buffer.",
|
"output.createBuffer": "Create a new zero-initialized buffer.",
|
||||||
"output.createBuffer|param|size": "number of bytes in the 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": "Pattern block.",
|
||||||
"output.getPattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green",
|
"output.getPattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green",
|
||||||
"output.setLights": "Set lights.",
|
"output.setLights": "Set lights.",
|
||||||
|
@ -16,13 +16,14 @@
|
|||||||
"input.remoteTopLeft|block": "remote top-left",
|
"input.remoteTopLeft|block": "remote top-left",
|
||||||
"input.remoteTopRight|block": "remote top-right",
|
"input.remoteTopRight|block": "remote top-right",
|
||||||
"input|block": "input",
|
"input|block": "input",
|
||||||
|
"output.getCurrentSpeed|block": "motor %out|speed",
|
||||||
"output.getPattern|block": "%pattern",
|
"output.getPattern|block": "%pattern",
|
||||||
"output.setLights|block": "set status light %pattern=led_pattern",
|
"output.setLights|block": "set status light %pattern=led_pattern",
|
||||||
"output.setPower|block": "set motor %out| power to %power",
|
"output.setPower|block": "set motor %out| power to %power",
|
||||||
"output.setSpeed|block": "set motor %out| speed to %speed",
|
"output.setSpeed|block": "set motor %out| speed to %speed",
|
||||||
"output.start|block": "turn motor %out| on",
|
"output.start|block": "turn motor %out|on",
|
||||||
"output.stop|block": "turn motor %out| off",
|
"output.stop|block": "turn motor %out|off",
|
||||||
"output.turn|block": "turn motor %out| on for %ms| milliseconds",
|
"output.turn|block": "turn motor %out| on for %ms|milliseconds",
|
||||||
"output|block": "output",
|
"output|block": "output",
|
||||||
"screen.drawText|block": "print %text| at x: %x| y: %y",
|
"screen.drawText|block": "print %text| at x: %x| y: %y",
|
||||||
"screen|block": "screen",
|
"screen|block": "screen",
|
||||||
|
@ -29,7 +29,7 @@ namespace output {
|
|||||||
pwmMM = control.mmap("/dev/lms_pwm", 0, 0)
|
pwmMM = control.mmap("/dev/lms_pwm", 0, 0)
|
||||||
if (!pwmMM) control.fail("no PWM file")
|
if (!pwmMM) control.fail("no PWM file")
|
||||||
motorMM = control.mmap("/dev/lms_motor", MotorDataOff.Size * DAL.NUM_OUTPUTS, 0)
|
motorMM = control.mmap("/dev/lms_motor", MotorDataOff.Size * DAL.NUM_OUTPUTS, 0)
|
||||||
|
|
||||||
stop(Output.ALL)
|
stop(Output.ALL)
|
||||||
|
|
||||||
let buf = output.createBuffer(1)
|
let buf = output.createBuffer(1)
|
||||||
@ -60,7 +60,7 @@ namespace output {
|
|||||||
* @param ms the number of milliseconds to turn the motor on, eg: 500
|
* @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
|
* @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"
|
//% weight=100 group="Motors"
|
||||||
export function turn(out: Output, ms: number, useBrake = false) {
|
export function turn(out: Output, ms: number, useBrake = false) {
|
||||||
// TODO: use current power / speed configuration
|
// TODO: use current power / speed configuration
|
||||||
@ -77,7 +77,7 @@ namespace output {
|
|||||||
* Turn motor off.
|
* Turn motor off.
|
||||||
* @param out the output connection that the motor is connected to
|
* @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"
|
//% weight=90 group="Motors"
|
||||||
export function stop(out: Output, useBrake = false) {
|
export function stop(out: Output, useBrake = false) {
|
||||||
let b = mkCmd(out, DAL.opOutputStop, 1)
|
let b = mkCmd(out, DAL.opOutputStop, 1)
|
||||||
@ -89,7 +89,7 @@ namespace output {
|
|||||||
* Turn motor on.
|
* Turn motor on.
|
||||||
* @param out the output connection that the motor is connected to
|
* @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"
|
//% weight=95 group="Motors"
|
||||||
export function start(out: Output) {
|
export function start(out: Output) {
|
||||||
let b = mkCmd(out, DAL.opOutputStart, 0)
|
let b = mkCmd(out, DAL.opOutputStart, 0)
|
||||||
@ -101,11 +101,49 @@ namespace output {
|
|||||||
writePWM(b)
|
writePWM(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*export function getSpeed(out: Output): number {
|
export function clearCount(out: Output) {
|
||||||
let b = mkCmd(out, DAL.opOutputSpeed, 0)
|
let b = mkCmd(out, DAL.opOutputClearCount, 0)
|
||||||
readPWM(b)
|
writePWM(b)
|
||||||
return b.getNumber(NumberFormat.Int16LE, 1)
|
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.
|
* Set motor speed.
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
screen.clear()
|
screen.clear()
|
||||||
screen.drawText(10, 30, "PXT!", Draw.Quad)
|
screen.drawText("PXT!", 10, 30, Draw.Quad)
|
||||||
|
|
||||||
screen.drawRect(40, 40, 20, 10, Draw.Fill)
|
screen.drawRect(40, 40, 20, 10, Draw.Fill)
|
||||||
output.setLights(LightsPattern.Orange)
|
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, () => {
|
input.buttonEnter.onEvent(ButtonEvent.Click, () => {
|
||||||
screen.clear()
|
screen.clear()
|
||||||
@ -17,32 +17,32 @@ input.buttonLeft.onEvent(ButtonEvent.Click, () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
input.buttonRight.onEvent(ButtonEvent.Click, () => {
|
input.buttonRight.onEvent(ButtonEvent.Click, () => {
|
||||||
screen.drawText(10, 60, "Right!")
|
screen.drawText("Right!", 10, 60)
|
||||||
})
|
})
|
||||||
|
|
||||||
input.buttonDown.onEvent(ButtonEvent.Click, () => {
|
input.buttonDown.onEvent(ButtonEvent.Click, () => {
|
||||||
screen.drawText(10, 60, "Down! ")
|
screen.drawText("Down! ", 10, 60)
|
||||||
})
|
})
|
||||||
|
|
||||||
input.buttonUp.onEvent(ButtonEvent.Click, () => {
|
input.buttonUp.onEvent(ButtonEvent.Click, () => {
|
||||||
screen.drawText(10, 60, "Up! ")
|
screen.drawText("Up! ", 10, 60)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
let num = 0
|
let num = 0
|
||||||
|
|
||||||
input.touchSensor.onEvent(ButtonEvent.Click, () => {
|
input.touchSensor.onEvent(ButtonEvent.Click, () => {
|
||||||
screen.drawText(10, 60, "Click! " + num)
|
screen.drawText("Click! " + num, 10, 60)
|
||||||
num++
|
num++
|
||||||
})
|
})
|
||||||
|
|
||||||
input.remoteTopLeft.onEvent(ButtonEvent.Click, () => {
|
input.remoteTopLeft.onEvent(ButtonEvent.Click, () => {
|
||||||
screen.drawText(10, 60, "TOPLEFT " + num)
|
screen.drawText("TOPLEFT " + num, 10, 60)
|
||||||
num++
|
num++
|
||||||
})
|
})
|
||||||
|
|
||||||
input.remoteTopRight.onEvent(ButtonEvent.Down, () => {
|
input.remoteTopRight.onEvent(ButtonEvent.Down, () => {
|
||||||
screen.drawText(10, 60, "TOPRIGH " + num)
|
screen.drawText("TOPRIGH " + num, 10, 60)
|
||||||
num++
|
num++
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pxt-ev3",
|
"name": "pxt-ev3",
|
||||||
"version": "0.0.12",
|
"version": "0.0.13",
|
||||||
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
|
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
|
||||||
"private": true,
|
"private": true,
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@ -40,7 +40,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pxt-common-packages": "0.9.2",
|
"pxt-common-packages": "0.9.2",
|
||||||
"pxt-core": "2.0.6"
|
"pxt-core": "2.0.9"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
||||||
|
Reference in New Issue
Block a user