Skip to content

Commit f511730

Browse files
evhan55Ray Schamp
authored and
Ray Schamp
committed
Fix motor turn for ports C/D. Zero out sensors and motor values on disconnect.
1 parent a220829 commit f511730

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

src/extensions/scratch3_ev3/index.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,16 @@ class EV3 {
171171
disconnectSession () {
172172
this._bt.disconnectSession();
173173
window.clearInterval(this._pollingIntervalID); // TODO: window?
174+
this.speed = 50;
175+
this._sensors = {
176+
distance: 0,
177+
brightness: 0,
178+
buttons: [0, 0, 0, 0]
179+
};
180+
this._motorPositions = [0, 0, 0, 0];
174181
this._sensorPorts = [];
175182
this._motorPorts = [];
183+
this._pollingIntervalID = null;
176184
}
177185

178186
/**
@@ -885,17 +893,39 @@ class Scratch3Ev3Blocks {
885893
}
886894

887895
motorTurnClockwise (args) {
888-
const port = Cast.toNumber(args.PORT);
896+
const port = Cast.toNumber(args.PORT); // TODO: fix
889897
const time = Cast.toNumber(args.TIME) * 1000;
890898

891-
return this._device.motorTurnClockwise(port, time);
899+
let p = null;
900+
if (port === 1) {
901+
p = 1;
902+
} else if (port === 2) {
903+
p = 2;
904+
} else if (port === 3) {
905+
p = 4;
906+
} else if (port === 4) {
907+
p = 8;
908+
}
909+
910+
return this._device.motorTurnClockwise(p, time);
892911
}
893912

894913
motorTurnCounterClockwise (args) {
895-
const port = Cast.toNumber(args.PORT);
914+
const port = Cast.toNumber(args.PORT); // TODO: fix
896915
const time = Cast.toNumber(args.TIME) * 1000;
897916

898-
return this._device.motorTurnCounterClockwise(port, time);
917+
let p = null;
918+
if (port === 1) {
919+
p = 1;
920+
} else if (port === 2) {
921+
p = 2;
922+
} else if (port === 3) {
923+
p = 4;
924+
} else if (port === 4) {
925+
p = 8;
926+
}
927+
928+
return this._device.motorTurnCounterClockwise(p, time);
899929
}
900930

901931
motorRotate (args) {

0 commit comments

Comments
 (0)