2017-12-22 23:00:23 +01:00
|
|
|
/// <reference path="./moduleView.ts" />
|
2017-12-18 22:04:17 +01:00
|
|
|
|
|
|
|
namespace pxsim.visuals {
|
|
|
|
|
|
|
|
export const MOTOR_ROTATION_FPS = 32;
|
|
|
|
|
2017-12-22 23:00:23 +01:00
|
|
|
export class MediumMotorView extends ModuleView implements LayoutElement {
|
2017-12-18 22:04:17 +01:00
|
|
|
|
2017-12-27 23:48:15 +01:00
|
|
|
private static ROTATING_ECLIPSE_ID = "medmotor_Hole";
|
2017-12-18 22:04:17 +01:00
|
|
|
|
|
|
|
private hasPreviousAngle: boolean;
|
|
|
|
private previousAngle: number;
|
|
|
|
|
|
|
|
constructor(port: number) {
|
|
|
|
super(MEDIUM_MOTOR_SVG, "medium-motor", NodeType.MediumMotor, port);
|
|
|
|
}
|
|
|
|
|
|
|
|
public getPaddingRatio() {
|
2017-12-22 23:00:23 +01:00
|
|
|
return 1 / 5;
|
2017-12-18 22:04:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
updateState() {
|
2017-12-28 20:17:18 +01:00
|
|
|
super.updateState();
|
2017-12-18 22:04:17 +01:00
|
|
|
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(MediumMotorView.ROTATING_ECLIPSE_ID))
|
2017-12-27 23:48:15 +01:00
|
|
|
const width = 44.45;
|
|
|
|
const height = 44.45;
|
|
|
|
const transform = `translate(2 1.84) rotate(${angle} ${width / 2} ${height / 2})`;
|
2017-12-18 22:04:17 +01:00
|
|
|
holeEl.setAttribute("transform", transform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|