2017-07-10 16:07:23 +02:00
|
|
|
namespace input {
|
|
|
|
|
|
|
|
export class UltraSonicSensor extends internal.UartSensor {
|
2017-10-24 20:58:52 +02:00
|
|
|
constructor(port: number) {
|
|
|
|
super(port)
|
2017-07-10 16:07:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_deviceType() {
|
2017-07-11 16:18:59 +02:00
|
|
|
return DAL.DEVICE_TYPE_ULTRASONIC
|
2017-07-10 16:07:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Get distance in mm */
|
|
|
|
getDistance() {
|
|
|
|
// it supposedly also has an inch mode, but we stick to mm
|
|
|
|
this._setMode(0)
|
|
|
|
return this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//% whenUsed
|
2017-10-24 20:58:52 +02:00
|
|
|
export const ultrasonic1: UltraSonicSensor = new UltraSonicSensor(1)
|
|
|
|
|
|
|
|
//% whenUsed
|
|
|
|
export const ultrasonic2: UltraSonicSensor = new UltraSonicSensor(2)
|
|
|
|
|
|
|
|
//% whenUsed
|
|
|
|
export const ultrasonic3: UltraSonicSensor = new UltraSonicSensor(3)
|
|
|
|
|
|
|
|
//% whenUsed
|
|
|
|
export const ultrasonic4: UltraSonicSensor = new UltraSonicSensor(4)
|
2017-07-10 16:07:23 +02:00
|
|
|
}
|