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,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
}

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

View File

@ -29,7 +29,7 @@ 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)
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 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
@ -77,7 +77,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,7 +89,7 @@ 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) {
let b = mkCmd(out, DAL.opOutputStart, 0)
@ -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,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++
})

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"