From 4627328bcd92f7fa5a5fa7e9729cc68152986a2d Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 11 Apr 2018 08:48:07 -0600 Subject: [PATCH] Output set Type fix (#487) * properly send outputsettype info * fix simulator * bump pxt * typo in docs --- libs/core/output.ts | 32 ++++++++++++------- .../reference/sensors/ultrasonic/distance.md | 2 +- package.json | 2 +- sim/state/output.ts | 7 ++-- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/libs/core/output.ts b/libs/core/output.ts index 4481f05e..27218a9f 100644 --- a/libs/core/output.ts +++ b/libs/core/output.ts @@ -298,6 +298,23 @@ namespace motors { pauseUntilReady(timeOut?: number) { pauseUntil(() => this.isReady(), timeOut); } + + protected setOutputType(large: boolean) { + /* + Instruction opOutput_Set_Type (LAYER, NO, TYPE) + Opcode 0xA1 Arguments (Data8) LAYER – Specify chain layer number [0 - 3] + (Data8) NO – Port number [0 - 3] + (Data8) TYPE – Output device type, (0x07: Large motor, Medium motor = 0x08) Dispatch status Unchanged + Description This function enables specifying the output device type + */ + for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) { + if (this._port & (1 << i)) { + const b = mkCmd(i, DAL.opOutputSetType, 1) + b.setNumber(NumberFormat.Int8LE, 2, large ? 0x07 : 0x08) + writePWM(b) + } + } + } } //% fixedInstances @@ -316,11 +333,8 @@ namespace motors { motors.__motorUsed(this._port, this._large); } - private __init() { - // specify motor size on this port - const b = mkCmd(outOffset(this._port), DAL.opOutputSetType, 1) - b.setNumber(NumberFormat.Int8LE, 2, this._large ? 0x07 : 0x08) - writePWM(b) + private __init() { + this.setOutputType(this._large); } private __setSpeed(speed: number) { @@ -453,13 +467,7 @@ namespace motors { } private __init() { - for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) { - if (this._port & (1 << i)) { - const b = mkCmd(outOffset(1 << i), DAL.opOutputSetType, 1) - b.setNumber(NumberFormat.Int8LE, 2, 0x07) // large motor - writePWM(b) - } - } + this.setOutputType(true); } private __setSpeed(speed: number) { diff --git a/libs/ultrasonic-sensor/docs/reference/sensors/ultrasonic/distance.md b/libs/ultrasonic-sensor/docs/reference/sensors/ultrasonic/distance.md index ab1ea38c..ee35daa4 100644 --- a/libs/ultrasonic-sensor/docs/reference/sensors/ultrasonic/distance.md +++ b/libs/ultrasonic-sensor/docs/reference/sensors/ultrasonic/distance.md @@ -18,7 +18,7 @@ The distance value returned is the number of centimeters to the object that the When the ultrasonic sensor on port 4 detects a near object, display its distance on the screen. ```blocks -sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjecNear, function () { +sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectNear, function () { brick.showString("Object detected at:", 1) brick.showNumber(sensors.ultrasonic4.distance(), 2) brick.showString("centimeters", 3) diff --git a/package.json b/package.json index d214810f..30ee2e69 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ }, "dependencies": { "pxt-common-packages": "0.20.38", - "pxt-core": "3.8.6" + "pxt-core": "3.8.8" }, "scripts": { "test": "node node_modules/pxt-core/built/pxt.js travis" diff --git a/sim/state/output.ts b/sim/state/output.ts index 00551ef5..f0229fe5 100644 --- a/sim/state/output.ts +++ b/sim/state/output.ts @@ -122,10 +122,11 @@ namespace pxsim { return 2; } case DAL.opOutputSetType: { - const port = buf.data[1]; + const portIndex = buf.data[1]; // not a port but a port index 0..3 const large = buf.data[2] == 0x07; - const motors = ev3board().getMotor(port); - motors.forEach(motor => motor.setLarge(large)); + const motor = ev3board().getMotors()[portIndex]; + if (motor) + motor.setLarge(large); return 2; } default: