moving gyro into separate project
This commit is contained in:
3
libs/gyro-sensor/README.md
Normal file
3
libs/gyro-sensor/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Gyroscope
|
||||
|
||||
The library to interact with the Gyroscope.
|
66
libs/gyro-sensor/gyro.ts
Normal file
66
libs/gyro-sensor/gyro.ts
Normal file
@ -0,0 +1,66 @@
|
||||
const enum GyroSensorMode {
|
||||
None = -1,
|
||||
Angle = 0,
|
||||
Rate = 1,
|
||||
}
|
||||
|
||||
namespace sensors {
|
||||
//% fixedInstances
|
||||
export class GyroSensor extends internal.UartSensor {
|
||||
constructor(port: number) {
|
||||
super(port)
|
||||
}
|
||||
|
||||
_deviceType() {
|
||||
return DAL.DEVICE_TYPE_GYRO
|
||||
}
|
||||
|
||||
setMode(m: GyroSensorMode) {
|
||||
this._setMode(m)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current angle from the gyroscope.
|
||||
* @param sensor the gyroscope to query the request
|
||||
*/
|
||||
//% help=input/gyro/angle
|
||||
//% block="`icons.gyroSensor` %sensor|angle"
|
||||
//% blockId=gyroGetAngle
|
||||
//% parts="gyroscope"
|
||||
//% blockNamespace=sensors
|
||||
//% weight=65 blockGap=8
|
||||
//% group="Gyro Sensor"
|
||||
angle(): number {
|
||||
this.setMode(GyroSensorMode.Angle)
|
||||
return this.getNumber(NumberFormat.Int16LE, 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current rotation rate from the gyroscope.
|
||||
* @param sensor the gyroscope to query the request
|
||||
*/
|
||||
//% help=input/gyro/rate
|
||||
//% block="`icons.gyroSensor` %sensor|rotation rate"
|
||||
//% blockId=gyroGetRate
|
||||
//% parts="gyroscope"
|
||||
//% blockNamespace=sensors
|
||||
//% weight=65 blockGap=8
|
||||
//% group="Gyro Sensor"
|
||||
rate(): number {
|
||||
this.setMode(GyroSensorMode.Rate)
|
||||
return this.getNumber(NumberFormat.Int16LE, 0)
|
||||
}
|
||||
}
|
||||
|
||||
//% fixedInstance whenUsed block="1"
|
||||
export const gyro1: GyroSensor = new GyroSensor(1)
|
||||
|
||||
//% fixedInstance whenUsed block="2" weight=95
|
||||
export const gyro2: GyroSensor = new GyroSensor(2)
|
||||
|
||||
//% fixedInstance whenUsed block="3"
|
||||
export const gyro3: GyroSensor = new GyroSensor(3)
|
||||
|
||||
//% fixedInstance whenUsed block="4"
|
||||
export const gyro4: GyroSensor = new GyroSensor(4)
|
||||
}
|
15
libs/gyro-sensor/pxt.json
Normal file
15
libs/gyro-sensor/pxt.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "gyro-sensor",
|
||||
"description": "Gyroscope support",
|
||||
"files": [
|
||||
"README.md",
|
||||
"gyro.ts"
|
||||
],
|
||||
"testFiles": [
|
||||
"test.ts"
|
||||
],
|
||||
"public": true,
|
||||
"dependencies": {
|
||||
"core": "file:../core"
|
||||
}
|
||||
}
|
0
libs/gyro-sensor/test.ts
Normal file
0
libs/gyro-sensor/test.ts
Normal file
Reference in New Issue
Block a user