pxt-ev3/sim/state/gyro.ts

43 lines
1006 B
TypeScript
Raw Normal View History

2017-12-18 22:04:17 +01:00
namespace pxsim {
export const enum GyroSensorMode {
2017-12-18 22:04:17 +01:00
None = -1,
Angle = 0,
Rate = 1,
}
export class GyroSensorNode extends UartSensorNode {
id = NodeType.GyroSensor;
private angle: number = 0;
private rate: number = 0;
constructor(port: number) {
super(port);
}
getDeviceType() {
return DAL.DEVICE_TYPE_GYRO;
}
setAngle(angle: number) {
angle = angle | 0;
2017-12-18 22:04:17 +01:00
if (this.angle != angle) {
this.angle = angle;
this.setChangedState();
2017-12-18 22:04:17 +01:00
}
}
setRate(rate: number) {
rate = rate | 0;
2017-12-18 22:04:17 +01:00
if (this.rate != rate) {
this.rate = rate;
this.setChangedState();
2017-12-18 22:04:17 +01:00
}
}
getValue() {
return this.mode == GyroSensorMode.Angle ? this.angle :
this.mode == GyroSensorMode.Rate ? this.rate : 0;
}
}
}