pxt-ev3/libs/core/gyro.ts

35 lines
710 B
TypeScript
Raw Normal View History

2017-07-10 16:07:23 +02:00
const enum GyroSensorMode {
None = -1,
Angle = 0,
Rate = 1,
}
namespace input {
export class GyroSensor extends internal.UartSensor {
constructor() {
super()
}
_deviceType() {
return DAL.DEVICE_TYPE_GYRO
2017-07-10 16:07:23 +02:00
}
setMode(m: GyroSensorMode) {
this._setMode(m)
}
getAngle() {
this.setMode(GyroSensorMode.Angle)
return this.getNumber(NumberFormat.Int16LE, 0)
}
getRate() {
this.setMode(GyroSensorMode.Rate)
return this.getNumber(NumberFormat.Int16LE, 0)
}
}
//% whenUsed
export const gyro: GyroSensor = new GyroSensor()
}