possible fix for #118, always return resolve
* changed _finished pointer to array to not overwrite callbacks * all completed and discarded commands get resolved * 0x10 bitset exists in documentation only? -> not implemented
This commit is contained in:
parent
a3f66d5df0
commit
a51aac1066
@ -51,7 +51,6 @@ export class AbsoluteMotor extends TachoMotor {
|
||||
}
|
||||
this.cancelEventTimer();
|
||||
return new Promise<void>((resolve) => {
|
||||
this._busy = true;
|
||||
if (speed === undefined || speed === null) {
|
||||
speed = 100;
|
||||
}
|
||||
@ -65,9 +64,9 @@ export class AbsoluteMotor extends TachoMotor {
|
||||
message.writeInt32LE(normalizeAngle(angle), 4);
|
||||
}
|
||||
this.send(message);
|
||||
this._finished = () => {
|
||||
this._finishedCallbacks.push(() => {
|
||||
return resolve();
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ export class Device extends EventEmitter {
|
||||
|
||||
protected _mode: number | undefined;
|
||||
protected _busy: boolean = false;
|
||||
protected _finished: (() => void) | undefined;
|
||||
protected _finishedCallbacks: (() => void)[] = [];
|
||||
|
||||
private _hub: IDeviceInterface;
|
||||
private _portId: number;
|
||||
@ -167,11 +167,13 @@ export class Device extends EventEmitter {
|
||||
this.send(Buffer.from([0x21, this.portId, 0x00]));
|
||||
}
|
||||
|
||||
public finish () {
|
||||
this._busy = false;
|
||||
if (this._finished) {
|
||||
this._finished();
|
||||
this._finished = undefined;
|
||||
public finish (message: number) {
|
||||
this._busy = (message & 0x01) === 0x01;
|
||||
while(this._finishedCallbacks.length > Number(this._busy)) {
|
||||
const callback = this._finishedCallbacks.shift();
|
||||
if(callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,6 @@ export class TachoMotor extends BasicMotor {
|
||||
}
|
||||
this.cancelEventTimer();
|
||||
return new Promise<void>((resolve) => {
|
||||
this._busy = true;
|
||||
if (speed === undefined || speed === null) {
|
||||
speed = 100;
|
||||
}
|
||||
@ -124,9 +123,9 @@ export class TachoMotor extends BasicMotor {
|
||||
}
|
||||
}
|
||||
this.send(message);
|
||||
this._finished = () => {
|
||||
this._finishedCallbacks.push(() => {
|
||||
return resolve();
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -146,7 +145,6 @@ export class TachoMotor extends BasicMotor {
|
||||
}
|
||||
this.cancelEventTimer();
|
||||
return new Promise<void>((resolve) => {
|
||||
this._busy = true;
|
||||
if (speed === undefined || speed === null) {
|
||||
speed = 100;
|
||||
}
|
||||
@ -158,9 +156,9 @@ export class TachoMotor extends BasicMotor {
|
||||
}
|
||||
message.writeUInt32LE(degrees, 4);
|
||||
this.send(message);
|
||||
this._finished = () => {
|
||||
this._finishedCallbacks.push(() => {
|
||||
return resolve();
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -353,10 +353,7 @@ export class LPF2Hub extends BaseHub {
|
||||
const device = this._getDeviceByPortId(portId);
|
||||
|
||||
if (device) {
|
||||
const finished = (message[4] === 0x0a);
|
||||
if (finished) {
|
||||
device.finish();
|
||||
}
|
||||
device.finish(message[4]);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user