2017-12-22 23:00:23 +01:00
|
|
|
/// <reference path="./moduleView.ts" />
|
2017-12-18 22:04:17 +01:00
|
|
|
|
|
|
|
namespace pxsim.visuals {
|
2017-12-22 23:00:23 +01:00
|
|
|
export class LargeMotorView extends ModuleView implements LayoutElement {
|
2017-12-18 22:04:17 +01:00
|
|
|
|
|
|
|
private static ROTATING_ECLIPSE_ID = "1eb2ae58-2419-47d4-86bf-4f26a7f0cf61";
|
|
|
|
|
|
|
|
constructor(port: number) {
|
|
|
|
super(LARGE_MOTOR_SVG, "large-motor", NodeType.LargeMotor, port);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateState() {
|
|
|
|
const motorState = ev3board().getMotors()[this.port];
|
|
|
|
if (!motorState) return;
|
|
|
|
const speed = motorState.getSpeed();
|
|
|
|
|
|
|
|
if (!speed) return;
|
2017-12-19 23:20:35 +01:00
|
|
|
this.setMotorAngle(motorState.getAngle());
|
2017-12-18 22:04:17 +01:00
|
|
|
}
|
|
|
|
|
2017-12-19 23:20:35 +01:00
|
|
|
private setMotorAngle(angle: number) {
|
2017-12-18 22:04:17 +01:00
|
|
|
const holeEl = this.content.getElementById(this.normalizeId(LargeMotorView.ROTATING_ECLIPSE_ID))
|
|
|
|
const width = 34;
|
|
|
|
const height = 34;
|
|
|
|
const transform = `rotate(${angle} ${width / 2} ${height / 2})`;
|
|
|
|
holeEl.setAttribute("transform", transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
getWiringRatio() {
|
|
|
|
return 0.62;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|