Compare commits

..

7 Commits

Author SHA1 Message Date
8b3064f4e0 0.0.13 2017-08-08 13:05:00 -07:00
138709285a bump pxt-core to 2.0.9, 2017-08-08 13:04:55 -07:00
65dd4617f1 Add get speed block 2017-08-08 13:02:11 -07:00
bdc8c1c62c bump pxt-core to 2.0.8, 2017-08-08 12:04:54 -07:00
ebcde71950 Fix hid deployment from command line 2017-08-08 11:47:10 +02:00
d42117a2a5 Add reading motor speed data (untested) 2017-08-08 11:41:47 +02:00
b0145cf378 Fix test.ts so it compiles 2017-08-08 11:41:31 +02:00
6 changed files with 87 additions and 32 deletions

View File

@ -28,9 +28,22 @@ namespace pxt.editor {
let initPromise: Promise<Ev3Wrapper>
function initAsync() {
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) {
if (!initPromise)
if (Cloud.isLocalHost() && Cloud.localToken && !forceHexDownload)
canHID = true
}
if (noHID)
canHID = false
if (canHID) {
initPromise = hf2Async()
.catch(err => {
initPromise = null
@ -41,6 +54,7 @@ namespace pxt.editor {
noHID = true
initPromise = Promise.reject(new Error("no HID"))
}
return initPromise
}

View File

@ -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.",

View File

@ -16,6 +16,7 @@
"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",

View File

@ -101,11 +101,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.

View File

@ -1,5 +1,5 @@
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)
@ -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++
})

View File

@ -1,6 +1,6 @@
{
"name": "pxt-ev3",
"version": "0.0.12",
"version": "0.0.13",
"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.9"
},
"scripts": {
"test": "node node_modules/pxt-core/built/pxt.js travis"