Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
8b3064f4e0 | |||
138709285a | |||
65dd4617f1 | |||
bdc8c1c62c | |||
ebcde71950 | |||
d42117a2a5 | |||
b0145cf378 |
@ -28,9 +28,22 @@ namespace pxt.editor {
|
|||||||
|
|
||||||
let initPromise: Promise<Ev3Wrapper>
|
let initPromise: Promise<Ev3Wrapper>
|
||||||
function initAsync() {
|
function initAsync() {
|
||||||
|
if (initPromise)
|
||||||
|
return initPromise
|
||||||
|
|
||||||
|
let canHID = false
|
||||||
|
if (U.isNodeJS) {
|
||||||
|
canHID = true
|
||||||
|
} else {
|
||||||
const forceHexDownload = /forceHexDownload/i.test(window.location.href);
|
const forceHexDownload = /forceHexDownload/i.test(window.location.href);
|
||||||
if (Cloud.isLocalHost() && Cloud.localToken && !forceHexDownload) {
|
if (Cloud.isLocalHost() && Cloud.localToken && !forceHexDownload)
|
||||||
if (!initPromise)
|
canHID = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (noHID)
|
||||||
|
canHID = false
|
||||||
|
|
||||||
|
if (canHID) {
|
||||||
initPromise = hf2Async()
|
initPromise = hf2Async()
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
initPromise = null
|
initPromise = null
|
||||||
@ -41,6 +54,7 @@ namespace pxt.editor {
|
|||||||
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,6 +16,7 @@
|
|||||||
"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",
|
||||||
|
@ -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,5 +1,5 @@
|
|||||||
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)
|
||||||
@ -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