Generalizing motorView for both medium and large motor views. Initial work towards synced motor views. Adding sync label for controller motor.
This commit is contained in:
@ -2,35 +2,17 @@
|
||||
|
||||
namespace pxsim.visuals {
|
||||
|
||||
export const MOTOR_ROTATION_FPS = 32;
|
||||
|
||||
export class MediumMotorView extends ModuleView implements LayoutElement {
|
||||
|
||||
private static ROTATING_ECLIPSE_ID = "medmotor_Hole";
|
||||
|
||||
private hasPreviousAngle: boolean;
|
||||
private previousAngle: number;
|
||||
export class MediumMotorView extends MotorView implements LayoutElement {
|
||||
|
||||
constructor(port: number) {
|
||||
super(MEDIUM_MOTOR_SVG, "medium-motor", NodeType.MediumMotor, port);
|
||||
super(MEDIUM_MOTOR_SVG, "medium-motor", NodeType.MediumMotor, port, "medmotor_Hole");
|
||||
}
|
||||
|
||||
public getPaddingRatio() {
|
||||
return 1 / 5;
|
||||
}
|
||||
|
||||
updateState() {
|
||||
super.updateState();
|
||||
const motorState = ev3board().getMotors()[this.port];
|
||||
if (!motorState) return;
|
||||
const speed = motorState.getSpeed();
|
||||
|
||||
if (!speed) return;
|
||||
this.setMotorAngle(motorState.getAngle());
|
||||
}
|
||||
|
||||
private setMotorAngle(angle: number) {
|
||||
const holeEl = this.content.getElementById(this.normalizeId(MediumMotorView.ROTATING_ECLIPSE_ID))
|
||||
protected renderMotorAngle(holeEl: Element, angle: number) {
|
||||
const width = 44.45;
|
||||
const height = 44.45;
|
||||
const transform = `translate(2 1.84) rotate(${angle} ${width / 2} ${height / 2})`;
|
||||
|
Reference in New Issue
Block a user