mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
Merge pull request #1611 from evhan55/fixes/hardware-extensions
Hardware extensions bug fixes
This commit is contained in:
commit
4583cb821b
3 changed files with 40 additions and 47 deletions
|
@ -158,7 +158,7 @@ class EV3Motor {
|
|||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this._power = 100;
|
||||
this._power = 50;
|
||||
|
||||
/**
|
||||
* This motor's current position, in the range [0,360].
|
||||
|
@ -231,14 +231,10 @@ class EV3Motor {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return {int} - this motor's current position, in the range [0,360].
|
||||
* @return {int} - this motor's current position, in the range [-inf,inf].
|
||||
*/
|
||||
get position () {
|
||||
let value = this._position;
|
||||
value = value % 360;
|
||||
value = value < 0 ? value * -1 : value;
|
||||
|
||||
return value;
|
||||
return this._position;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -688,17 +684,18 @@ class EV3 {
|
|||
// GET DEVICE LIST
|
||||
byteCommands[0] = Ev3Opcode.OPINPUT_DEVICE_LIST;
|
||||
byteCommands[1] = Ev3Value.NUM8; // 1 byte to follow
|
||||
byteCommands[2] = 33; // 0x21 ARRAY // TODO: ????
|
||||
byteCommands[3] = 96; // 0x60 CHANGED // TODO: ????
|
||||
byteCommands[4] = 225; // 0xE1 size of global var - 1 byte to follow // TODO: ????
|
||||
byteCommands[5] = 32; // 0x20 global var index "0" 0b00100000 // TODO: ????
|
||||
byteCommands[2] = 33; // 0x21 ARRAY // TODO: document
|
||||
byteCommands[3] = 96; // 0x60 CHANGED // TODO: document
|
||||
byteCommands[4] = 225; // 0xE1 size of global var - 1 byte to follow // TODO: document
|
||||
byteCommands[5] = 32; // 0x20 global var index "0" 0b00100000 // TODO: document
|
||||
|
||||
// Command and payload lengths
|
||||
allocation = 33;
|
||||
|
||||
// Clear sensor data // TODO: is this enough?
|
||||
this._updateDevices = true;
|
||||
|
||||
// TODO: need to clar sensor data?
|
||||
|
||||
} else {
|
||||
// GET SENSOR VALUES FOR CONNECTED SENSORS
|
||||
let index = 0;
|
||||
|
@ -711,8 +708,8 @@ class EV3 {
|
|||
byteCommands[index + 2] = i; // PORT
|
||||
byteCommands[index + 3] = Ev3Value.DO_NOT_CHANGE_TYPE;
|
||||
byteCommands[index + 4] = Ev3Mode[this._sensorPorts[i]];
|
||||
byteCommands[index + 5] = 225; // 0xE1 one byte to follow // TODO: ????
|
||||
byteCommands[index + 6] = sensorCount * 4; // global index // TODO: ????
|
||||
byteCommands[index + 5] = 225; // 0xE1 one byte to follow // TODO: document
|
||||
byteCommands[index + 6] = sensorCount * 4; // global index // TODO: document
|
||||
index += 7;
|
||||
}
|
||||
sensorCount++;
|
||||
|
@ -725,9 +722,9 @@ class EV3 {
|
|||
for (let i = 0; i < 4; i++) {
|
||||
byteCommands[index + 0] = Ev3Opcode.OPOUTPUT_GET_COUNT;
|
||||
byteCommands[index + 1] = Ev3Value.LAYER;
|
||||
byteCommands[index + 2] = i; // port
|
||||
byteCommands[index + 3] = 225; // 0xE1 byte following
|
||||
byteCommands[index + 4] = sensorCount * 4; // global index
|
||||
byteCommands[index + 2] = i; // PORT TODO: explain incorrect documentation as 'Output bit field'
|
||||
byteCommands[index + 3] = 225; // 0xE1 byte following TODO: document
|
||||
byteCommands[index + 4] = sensorCount * 4; // global index TODO: document
|
||||
index += 5;
|
||||
sensorCount++;
|
||||
}
|
||||
|
@ -976,7 +973,7 @@ class Scratch3Ev3Blocks {
|
|||
},
|
||||
POWER: {
|
||||
type: ArgumentType.NUMBER,
|
||||
defaultValue: 50
|
||||
defaultValue: 100
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -1161,8 +1158,12 @@ class Scratch3Ev3Blocks {
|
|||
}
|
||||
|
||||
const motor = this._peripheral.motor(port);
|
||||
let position = 0;
|
||||
if (motor) {
|
||||
position = MathUtil.wrapClamp(motor.position, 0, 360);
|
||||
}
|
||||
|
||||
return motor ? motor.position : 0;
|
||||
return position;
|
||||
}
|
||||
|
||||
whenButtonPressed (args) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue