pxt-ev3/sim/state/input.ts

38 lines
1.1 KiB
TypeScript
Raw Normal View History

2017-12-18 22:04:17 +01:00
import lf = pxsim.localization.lf;
2017-12-18 22:04:17 +01:00
namespace pxsim.motors {
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;
}
2017-12-18 22:04:17 +01:00
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)}`);
2017-12-18 22:04:17 +01:00
}
}
namespace pxsim.sensors {
export function __sensorUsed(port: number, type: number) {
//console.log("SENSOR INIT " + port + ", type: " + type);
if (type == DAL.DEVICE_TYPE_IIC_UNKNOWN) return; // Ignore IIC
if (!ev3board().hasSensor(port)) {
const sensor = ev3board().getSensor(port, type);
runtime.queueDisplayUpdate();
} else {
U.userError(`${lf("Multiple sensors are connected to Port")} ${port + 1}`);
}
2017-12-18 22:04:17 +01:00
}
}