pxt-ev3/sim/state/touch.ts

43 lines
929 B
TypeScript
Raw Normal View History

2017-12-18 22:04:17 +01:00
namespace pxsim {
export const TOUCH_SENSOR_ANALOG_PRESSED = 2600;
export class TouchSensorNode extends AnalogSensorNode {
id = NodeType.TouchSensor;
private pressed: boolean[];
constructor(port: number) {
super(port);
this.pressed = [];
}
public setPressed(pressed: boolean) {
this.pressed.push(pressed);
this.changed = true;
this.valueChanged = true;
}
public isPressed() {
return this.pressed;
}
public getValue() {
if (this.pressed.length) {
if (this.pressed.pop())
return TOUCH_SENSOR_ANALOG_PRESSED;
}
return 0;
}
getDeviceType() {
return DAL.DEVICE_TYPE_TOUCH;
}
public hasData() {
return this.pressed.length > 0;
}
}
}