moving touch stuff into separate projects
This commit is contained in:
@ -14,7 +14,6 @@
|
||||
"MMap.setNumber": "Write a number in specified format in the buffer.",
|
||||
"MMap.slice": "Read a range of bytes into a buffer.",
|
||||
"MMap.write": "Perform write(2) on the underlaying file",
|
||||
"TouchSensorEvent": "Touch sensor interactions",
|
||||
"brick.Button": "Generic button class, for device buttons and sensors.",
|
||||
"brick.Button.isPressed": "Check if button is currently pressed or not.",
|
||||
"brick.Button.onEvent": "Do something when a button or sensor is clicked, up or down.",
|
||||
@ -86,9 +85,6 @@
|
||||
"sensors.RemoteInfraredBeaconButton.onEvent": "Do something when a button or sensor is clicked, up or down",
|
||||
"sensors.RemoteInfraredBeaconButton.onEvent|param|body": "code to run when the event is raised",
|
||||
"sensors.RemoteInfraredBeaconButton.wasPressed": "See if the remote button was pressed again since the last time you checked.",
|
||||
"sensors.TouchSensor.isTouched": "Check if touch sensor is touched.",
|
||||
"sensors.TouchSensor.onEvent": "Do something when a touch sensor is touched...",
|
||||
"sensors.TouchSensor.onEvent|param|body": "code to run when the event is raised",
|
||||
"sensors.UltraSonicSensor.distance": "Gets the distance from the sonar in millimeters",
|
||||
"sensors.UltraSonicSensor.on": "Registers code to run when the given color is close",
|
||||
"sensors.UltraSonicSensor.on|param|handler": "the code to run when detected",
|
||||
|
@ -27,9 +27,6 @@
|
||||
"Output.B|block": "B",
|
||||
"Output.C|block": "C",
|
||||
"Output.D|block": "D",
|
||||
"TouchSensorEvent.Bumped|block": "bumped",
|
||||
"TouchSensorEvent.Pressed|block": "pressed",
|
||||
"TouchSensorEvent.Released|block": "released",
|
||||
"UltrasonicSensorEvent.ObjectDetected|block": "object detected",
|
||||
"UltrasonicSensorEvent.ObjectNear|block": "object near",
|
||||
"brick.Button.isPressed|block": "`icons.brickButtons` %button|is pressed",
|
||||
@ -82,8 +79,6 @@
|
||||
"sensors.RemoteInfraredBeaconButton.isPressed|block": "`icons.infraredSensor` %button|is pressed",
|
||||
"sensors.RemoteInfraredBeaconButton.onEvent|block": "on `icons.infraredSensor` %button|%event",
|
||||
"sensors.RemoteInfraredBeaconButton.wasPressed|block": "`icons.infraredSensor` %button|was pressed",
|
||||
"sensors.TouchSensor.isTouched|block": "`icons.touchSensor` %sensor|is touched",
|
||||
"sensors.TouchSensor.onEvent|block": "on `icons.touchSensor` %sensor|%event",
|
||||
"sensors.UltraSonicSensor.distance|block": "`icons.ultrasonicSensor` %sensor|distance",
|
||||
"sensors.UltraSonicSensor.on|block": "on `icons.ultrasonicSensor` %sensor|%event",
|
||||
"sensors.UltraSonicSensor.wait|block": "wait `icons.ultrasonicSensor` %sensor|for %event",
|
||||
@ -104,10 +99,6 @@
|
||||
"sensors.remoteButtonCenter|block": "center",
|
||||
"sensors.remoteButtonTopLeft|block": "top-left",
|
||||
"sensors.remoteButtonTopRight|block": "top-right",
|
||||
"sensors.touchSensor1|block": "1",
|
||||
"sensors.touchSensor2|block": "2",
|
||||
"sensors.touchSensor3|block": "3",
|
||||
"sensors.touchSensor4|block": "4",
|
||||
"sensors.ultrasonic1|block": "1",
|
||||
"sensors.ultrasonic2|block": "2",
|
||||
"sensors.ultrasonic3|block": "3",
|
||||
@ -132,6 +123,5 @@
|
||||
"{id:group}Motors": "Motors",
|
||||
"{id:group}Remote Infrared Beacon": "Remote Infrared Beacon",
|
||||
"{id:group}Screen": "Screen",
|
||||
"{id:group}Touch Sensor": "Touch Sensor",
|
||||
"{id:group}Ultrasonic Sensor": "Ultrasonic Sensor"
|
||||
}
|
@ -22,7 +22,6 @@
|
||||
"color.ts",
|
||||
"gyro.ts",
|
||||
"ultrasonic.ts",
|
||||
"touch.ts",
|
||||
"shims.d.ts",
|
||||
"enums.d.ts",
|
||||
"dal.d.ts",
|
||||
|
@ -1,78 +0,0 @@
|
||||
// keep TouchSensorEvent in sync with ButtonEvent
|
||||
|
||||
/**
|
||||
* Touch sensor interactions
|
||||
*/
|
||||
const enum TouchSensorEvent {
|
||||
//% block="pressed"
|
||||
Pressed = 4,
|
||||
//% block="bumped"
|
||||
Bumped = 1,
|
||||
//% block="released"
|
||||
Released = 3,
|
||||
}
|
||||
|
||||
namespace sensors {
|
||||
|
||||
//% fixedInstances
|
||||
export class TouchSensor extends internal.AnalogSensor {
|
||||
private button: brick.Button;
|
||||
|
||||
constructor(port: number) {
|
||||
super(port)
|
||||
this.button = new brick.Button();
|
||||
}
|
||||
|
||||
_query() {
|
||||
return this._readPin6() > 2500 ? 1 : 0
|
||||
}
|
||||
|
||||
_update(prev: number, curr: number) {
|
||||
this.button._update(curr > 0)
|
||||
}
|
||||
|
||||
_deviceType() {
|
||||
return DAL.DEVICE_TYPE_TOUCH
|
||||
}
|
||||
|
||||
/**
|
||||
* Do something when a touch sensor is touched...
|
||||
* @param sensor the touch sensor that needs to be clicked or used
|
||||
* @param event the kind of button gesture that needs to be detected
|
||||
* @param body code to run when the event is raised
|
||||
*/
|
||||
//% help=input/touch/on-event
|
||||
//% blockId=touchEvent block="on `icons.touchSensor` %sensor|%event"
|
||||
//% parts="touch"
|
||||
//% blockNamespace=sensors
|
||||
//% weight=99 blockGap=8
|
||||
//% group="Touch Sensor"
|
||||
onEvent(ev: TouchSensorEvent, body: () => void) {
|
||||
this.button.onEvent(<ButtonEvent><number>ev, body)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if touch sensor is touched.
|
||||
* @param sensor the port to query the request
|
||||
*/
|
||||
//% help=input/touch/is-touched
|
||||
//% block="`icons.touchSensor` %sensor|is touched"
|
||||
//% blockId=touchIsTouched
|
||||
//% parts="touch"
|
||||
//% blockNamespace=sensors
|
||||
//% weight=81 blockGap=8
|
||||
//% group="Touch Sensor"
|
||||
isTouched() {
|
||||
return this.button.isPressed();
|
||||
}
|
||||
}
|
||||
|
||||
//% whenUsed block="1" weight=95 fixedInstance
|
||||
export const touchSensor1: TouchSensor = new TouchSensor(1)
|
||||
//% whenUsed block="2" weight=95 fixedInstance
|
||||
export const touchSensor2: TouchSensor = new TouchSensor(2)
|
||||
//% whenUsed block="3" weight=95 fixedInstance
|
||||
export const touchSensor3: TouchSensor = new TouchSensor(3)
|
||||
//% whenUsed block="4" weight=95 fixedInstance
|
||||
export const touchSensor4: TouchSensor = new TouchSensor(4)
|
||||
}
|
Reference in New Issue
Block a user