2017-12-18 22:04:17 +01:00
|
|
|
/// <reference path="./sensor.ts"/>
|
|
|
|
|
|
|
|
namespace pxsim {
|
|
|
|
export class UltrasonicSensorNode extends UartSensorNode {
|
|
|
|
id = NodeType.UltrasonicSensor;
|
|
|
|
|
2017-12-19 05:30:56 +01:00
|
|
|
private distance: number = 127; // in cm
|
2017-12-18 22:04:17 +01:00
|
|
|
|
|
|
|
constructor(port: number) {
|
|
|
|
super(port);
|
|
|
|
}
|
|
|
|
|
|
|
|
getDeviceType() {
|
|
|
|
return DAL.DEVICE_TYPE_ULTRASONIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
setDistance(distance: number) {
|
|
|
|
if (this.distance != distance) {
|
|
|
|
this.distance = distance;
|
2017-12-19 23:20:35 +01:00
|
|
|
this.setChangedState();
|
2017-12-18 22:04:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getValue() {
|
2017-12-19 05:30:56 +01:00
|
|
|
return this.distance * 10; // convert to 0.1 cm
|
2017-12-18 22:04:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|