pxt-ev3/libs/core/gyro.ts

56 lines
1.4 KiB
TypeScript
Raw Normal View History

2017-07-10 16:07:23 +02:00
const enum GyroSensorMode {
None = -1,
Angle = 0,
Rate = 1,
}
namespace input {
2017-10-24 14:30:05 +02:00
//% fixedInstances
2017-07-10 16:07:23 +02:00
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)
}
2017-10-24 14:30:05 +02:00
/**
* Get the current angle from the gyroscope.
* @param color the gyroscope to query the request
*/
//% help=input/gyro/angle
//% block="%color|angle"
//% blockId=gyroGetAngle
//% parts="gyroscope"
//% blockNamespace=input
//% weight=65 blockGap=8
angle() {
2017-07-10 16:07:23 +02:00
this.setMode(GyroSensorMode.Angle)
return this.getNumber(NumberFormat.Int16LE, 0)
}
2017-10-24 14:30:05 +02:00
/**
* Get the current rotation rate from the gyroscope.
* @param color the gyroscope to query the request
*/
//% help=input/gyro/rate
//% block="%color|rotation rate"
//% blockId=gyroGetRate
//% parts="gyroscope"
//% blockNamespace=input
//% weight=65 blockGap=8
rate() {
2017-07-10 16:07:23 +02:00
this.setMode(GyroSensorMode.Rate)
return this.getNumber(NumberFormat.Int16LE, 0)
}
}
//% whenUsed
export const gyro: GyroSensor = new GyroSensor()
}