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() {
|
2017-07-11 16:18:59 +02:00
|
|
|
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()
|
|
|
|
}
|