Support for multiple motors in "used" logic. (#238)
* handle registerion of dual / single motors * updated puppy
This commit is contained in:
@ -97,28 +97,21 @@ namespace pxsim {
|
||||
return this.brickNode;
|
||||
}
|
||||
|
||||
motorUsed(port: number, large: boolean) {
|
||||
motorUsed(ports: number, large: boolean): boolean {
|
||||
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
|
||||
const p = 1 << i;
|
||||
if (port & p) {
|
||||
const motorPort = this.motorMap[p];
|
||||
if (!this.outputNodes[motorPort])
|
||||
this.outputNodes[motorPort] = new MotorNode(motorPort, large);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hasMotor(port: number) {
|
||||
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
|
||||
const p = 1 << i;
|
||||
if (port & p) {
|
||||
if (ports & p) {
|
||||
const motorPort = this.motorMap[p];
|
||||
const outputNode = this.outputNodes[motorPort];
|
||||
if (outputNode)
|
||||
return true;
|
||||
if (!outputNode) {
|
||||
this.outputNodes[motorPort] = new MotorNode(motorPort, large);
|
||||
continue;
|
||||
}
|
||||
if (outputNode && outputNode.isLarge() != large)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
getMotor(port: number, large?: boolean): MotorNode[] {
|
||||
|
@ -3,15 +3,23 @@
|
||||
import lf = pxsim.localization.lf;
|
||||
|
||||
namespace pxsim.motors {
|
||||
|
||||
export function __motorUsed(port: number, large: boolean) {
|
||||
//console.log("MOTOR INIT " + port);
|
||||
if (!ev3board().hasMotor(port)) {
|
||||
ev3board().motorUsed(port, large);
|
||||
runtime.queueDisplayUpdate();
|
||||
} else {
|
||||
U.userError(`${lf("Multiple motors are connected to Port")} ${String.fromCharCode('A'.charCodeAt(0) + ev3board().motorMap[port])}`);
|
||||
function portsToString(out: number): string {
|
||||
let r = "";
|
||||
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
|
||||
if (out & (1 << i)) {
|
||||
if (r.length > 0) r += "+";
|
||||
r += "ABCD"[i];
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
export function __motorUsed(ports: number, large: boolean) {
|
||||
//console.log("MOTOR INIT " + port);
|
||||
if (ev3board().motorUsed(ports, large))
|
||||
runtime.queueDisplayUpdate();
|
||||
else
|
||||
U.userError(`${lf("Multiple motors are connected to Port")} ${portsToString(ports)}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,10 @@ namespace pxsim {
|
||||
this.rotationsPerMilliSecond = (large ? 170 : 250) / 60000;
|
||||
}
|
||||
|
||||
isLarge(): boolean {
|
||||
return this.id == NodeType.LargeMotor;
|
||||
}
|
||||
|
||||
setPolarity(polarity: number) {
|
||||
// Either 1 or 255 (reverse)
|
||||
/*
|
||||
|
Reference in New Issue
Block a user