Output set Type fix (#487)
* properly send outputsettype info * fix simulator * bump pxt * typo in docs
This commit is contained in:
parent
80989cf4c9
commit
4627328bcd
@ -298,6 +298,23 @@ namespace motors {
|
|||||||
pauseUntilReady(timeOut?: number) {
|
pauseUntilReady(timeOut?: number) {
|
||||||
pauseUntil(() => this.isReady(), timeOut);
|
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
|
//% fixedInstances
|
||||||
@ -317,10 +334,7 @@ namespace motors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private __init() {
|
private __init() {
|
||||||
// specify motor size on this port
|
this.setOutputType(this._large);
|
||||||
const b = mkCmd(outOffset(this._port), DAL.opOutputSetType, 1)
|
|
||||||
b.setNumber(NumberFormat.Int8LE, 2, this._large ? 0x07 : 0x08)
|
|
||||||
writePWM(b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private __setSpeed(speed: number) {
|
private __setSpeed(speed: number) {
|
||||||
@ -453,13 +467,7 @@ namespace motors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private __init() {
|
private __init() {
|
||||||
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
|
this.setOutputType(true);
|
||||||
if (this._port & (1 << i)) {
|
|
||||||
const b = mkCmd(outOffset(1 << i), DAL.opOutputSetType, 1)
|
|
||||||
b.setNumber(NumberFormat.Int8LE, 2, 0x07) // large motor
|
|
||||||
writePWM(b)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private __setSpeed(speed: number) {
|
private __setSpeed(speed: number) {
|
||||||
|
@ -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.
|
When the ultrasonic sensor on port 4 detects a near object, display its distance on the screen.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjecNear, function () {
|
sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectNear, function () {
|
||||||
brick.showString("Object detected at:", 1)
|
brick.showString("Object detected at:", 1)
|
||||||
brick.showNumber(sensors.ultrasonic4.distance(), 2)
|
brick.showNumber(sensors.ultrasonic4.distance(), 2)
|
||||||
brick.showString("centimeters", 3)
|
brick.showString("centimeters", 3)
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pxt-common-packages": "0.20.38",
|
"pxt-common-packages": "0.20.38",
|
||||||
"pxt-core": "3.8.6"
|
"pxt-core": "3.8.8"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
||||||
|
@ -122,10 +122,11 @@ namespace pxsim {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
case DAL.opOutputSetType: {
|
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 large = buf.data[2] == 0x07;
|
||||||
const motors = ev3board().getMotor(port);
|
const motor = ev3board().getMotors()[portIndex];
|
||||||
motors.forEach(motor => motor.setLarge(large));
|
if (motor)
|
||||||
|
motor.setLarge(large);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user