separating touch sensor stuff
This commit is contained in:
parent
e6ef86101f
commit
46175fc7db
@ -9,6 +9,7 @@
|
|||||||
"MMap.setNumber": "Write a number in specified format in the buffer.",
|
"MMap.setNumber": "Write a number in specified format in the buffer.",
|
||||||
"MMap.slice": "Read a range of bytes into a buffer.",
|
"MMap.slice": "Read a range of bytes into a buffer.",
|
||||||
"MMap.write": "Perform write(2) on the underlaying file",
|
"MMap.write": "Perform write(2) on the underlaying file",
|
||||||
|
"TouchSensorEvent": "Touch sensor interactions",
|
||||||
"control": "Program controls and events.",
|
"control": "Program controls and events.",
|
||||||
"control.allocateNotifyEvent": "Allocates the next user notification event",
|
"control.allocateNotifyEvent": "Allocates the next user notification event",
|
||||||
"control.deviceFirmwareVersion": "Determine the version of system software currently running.",
|
"control.deviceFirmwareVersion": "Determine the version of system software currently running.",
|
||||||
@ -30,6 +31,9 @@
|
|||||||
"input.GyroSensor.rate": "Get the current rotation rate from the gyroscope.",
|
"input.GyroSensor.rate": "Get the current rotation rate from the gyroscope.",
|
||||||
"input.IrSensor.distance": "Get the distance measured by the infrared sensor.",
|
"input.IrSensor.distance": "Get the distance measured by the infrared sensor.",
|
||||||
"input.IrSensor.remoteCommand": "Get the remote commandreceived the infrared sensor.",
|
"input.IrSensor.remoteCommand": "Get the remote commandreceived the infrared sensor.",
|
||||||
|
"input.TouchSensor.isTouched": "Check if touch sensor is touched.",
|
||||||
|
"input.TouchSensor.onEvent": "Do something when a touch sensor is touched...",
|
||||||
|
"input.TouchSensor.onEvent|param|body": "code to run when the event is raised",
|
||||||
"input.UltraSonicSensor.distance": "Gets the distance from the sonar in millimeters",
|
"input.UltraSonicSensor.distance": "Gets the distance from the sonar in millimeters",
|
||||||
"input.buttonDown": "Down button.",
|
"input.buttonDown": "Down button.",
|
||||||
"input.buttonEnter": "Enter button.",
|
"input.buttonEnter": "Enter button.",
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"ButtonEvent.Click|block": "click",
|
"ButtonEvent.Click|block": "click",
|
||||||
"ButtonEvent.Down|block": "down",
|
"ButtonEvent.Down|block": "down",
|
||||||
"ButtonEvent.LongClick|block": "long click",
|
|
||||||
"ButtonEvent.Up|block": "up",
|
"ButtonEvent.Up|block": "up",
|
||||||
"LightsPattern.GreenFlash|block": "Flashing Green",
|
"LightsPattern.GreenFlash|block": "Flashing Green",
|
||||||
"LightsPattern.GreenPulse|block": "Pulsing Green",
|
"LightsPattern.GreenPulse|block": "Pulsing Green",
|
||||||
@ -13,6 +12,9 @@
|
|||||||
"LightsPattern.RedFlash|block": "Flashing Red",
|
"LightsPattern.RedFlash|block": "Flashing Red",
|
||||||
"LightsPattern.RedPulse|block": "Pulsing Red",
|
"LightsPattern.RedPulse|block": "Pulsing Red",
|
||||||
"LightsPattern.Red|block": "Red",
|
"LightsPattern.Red|block": "Red",
|
||||||
|
"TouchSensorEvent.Bumped|block": "bumped",
|
||||||
|
"TouchSensorEvent.Released|block": "released",
|
||||||
|
"TouchSensorEvent.Touched|block": "touched",
|
||||||
"control.raiseEvent|block": "raise event|from %src|with value %value",
|
"control.raiseEvent|block": "raise event|from %src|with value %value",
|
||||||
"control|block": "control",
|
"control|block": "control",
|
||||||
"input.Button.isPressed|block": "%button|is pressed",
|
"input.Button.isPressed|block": "%button|is pressed",
|
||||||
@ -25,6 +27,8 @@
|
|||||||
"input.GyroSensor.rate|block": "%sensor|rotation rate",
|
"input.GyroSensor.rate|block": "%sensor|rotation rate",
|
||||||
"input.IrSensor.distance|block": "%infrared|distance",
|
"input.IrSensor.distance|block": "%infrared|distance",
|
||||||
"input.IrSensor.remoteCommand|block": "%infrared|remote command",
|
"input.IrSensor.remoteCommand|block": "%infrared|remote command",
|
||||||
|
"input.TouchSensor.isTouched|block": "%sensor|is touched",
|
||||||
|
"input.TouchSensor.onEvent|block": "on %sensor|%event",
|
||||||
"input.UltraSonicSensor.distance|block": "%sensor|distance",
|
"input.UltraSonicSensor.distance|block": "%sensor|distance",
|
||||||
"input.buttonDown|block": "button down",
|
"input.buttonDown|block": "button down",
|
||||||
"input.buttonEnter|block": "button enter",
|
"input.buttonEnter|block": "button enter",
|
||||||
@ -77,5 +81,6 @@
|
|||||||
"{id:group}Lights": "Lights",
|
"{id:group}Lights": "Lights",
|
||||||
"{id:group}Motors": "Motors",
|
"{id:group}Motors": "Motors",
|
||||||
"{id:group}Screen": "Screen",
|
"{id:group}Screen": "Screen",
|
||||||
|
"{id:group}Touch sensor": "Touch sensor",
|
||||||
"{id:group}Ultrasonic sensor": "Ultrasonic sensor"
|
"{id:group}Ultrasonic sensor": "Ultrasonic sensor"
|
||||||
}
|
}
|
@ -41,8 +41,6 @@ const enum LightsPattern {
|
|||||||
const enum ButtonEvent {
|
const enum ButtonEvent {
|
||||||
//% block="click"
|
//% block="click"
|
||||||
Click = 1,
|
Click = 1,
|
||||||
//% block="long click"
|
|
||||||
LongClick = 2,
|
|
||||||
//% block="up"
|
//% block="up"
|
||||||
Up = 3,
|
Up = 3,
|
||||||
//% block="down"
|
//% block="down"
|
||||||
@ -76,7 +74,8 @@ namespace input {
|
|||||||
} else {
|
} else {
|
||||||
control.raiseEvent(this._id, ButtonEvent.Up)
|
control.raiseEvent(this._id, ButtonEvent.Up)
|
||||||
let delta = control.millis() - this.downTime
|
let delta = control.millis() - this.downTime
|
||||||
control.raiseEvent(this._id, delta > 500 ? ButtonEvent.LongClick : ButtonEvent.Click)
|
control.raiseEvent(this._id, ButtonEvent.Click)
|
||||||
|
//control.raiseEvent(this._id, delta > 500 ? ButtonEvent.LongClick : ButtonEvent.Click)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +130,7 @@ namespace input {
|
|||||||
//% button.fieldEditor="gridpicker"
|
//% button.fieldEditor="gridpicker"
|
||||||
//% button.fieldOptions.width=220
|
//% button.fieldOptions.width=220
|
||||||
//% button.fieldOptions.columns=3
|
//% button.fieldOptions.columns=3
|
||||||
//% weight=99
|
//% weight=99 blockGap=8
|
||||||
//% group="Buttons"
|
//% group="Buttons"
|
||||||
onEvent(ev: ButtonEvent, body: () => void) {
|
onEvent(ev: ButtonEvent, body: () => void) {
|
||||||
control.onEvent(this._id, ev, body)
|
control.onEvent(this._id, ev, body)
|
||||||
|
@ -1,12 +1,26 @@
|
|||||||
|
// keep TouchSensorEvent in sync with ButtonEvent
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Touch sensor interactions
|
||||||
|
*/
|
||||||
|
const enum TouchSensorEvent {
|
||||||
|
//% block="touched"
|
||||||
|
Touched = 4,
|
||||||
|
//% block="bumped"
|
||||||
|
Bumped = 1,
|
||||||
|
//% block="released"
|
||||||
|
Released = 3,
|
||||||
|
}
|
||||||
|
|
||||||
namespace input {
|
namespace input {
|
||||||
|
|
||||||
//% fixedInstances
|
//% fixedInstances
|
||||||
export class TouchSensor extends internal.AnalogSensor {
|
export class TouchSensor extends internal.AnalogSensor {
|
||||||
button: Button;
|
private button: Button;
|
||||||
|
|
||||||
constructor(port: number) {
|
constructor(port: number) {
|
||||||
super(port)
|
super(port)
|
||||||
this.button = new Button()
|
this.button = new Button();
|
||||||
}
|
}
|
||||||
|
|
||||||
_query() {
|
_query() {
|
||||||
@ -20,26 +34,45 @@ namespace input {
|
|||||||
_deviceType() {
|
_deviceType() {
|
||||||
return DAL.DEVICE_TYPE_TOUCH
|
return DAL.DEVICE_TYPE_TOUCH
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if touch sensor is touched.
|
||||||
|
* @param sensor the port to query the request
|
||||||
|
*/
|
||||||
|
//% help=input/touch/is-touched
|
||||||
|
//% block="%sensor|is touched"
|
||||||
|
//% blockId=touchIsTouched
|
||||||
|
//% parts="touch"
|
||||||
|
//% blockNamespace=input
|
||||||
|
//% weight=81 blockGap=8
|
||||||
|
//% group="Touch sensor"
|
||||||
|
isTouched() {
|
||||||
|
return this.button.isPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
//% whenUsed
|
/**
|
||||||
export const touchSensorImpl1: TouchSensor = new TouchSensor(1)
|
* Do something when a touch sensor is touched...
|
||||||
//% whenUsed
|
* @param sensor the touch sensor that needs to be clicked or used
|
||||||
export const touchSensorImpl2: TouchSensor = new TouchSensor(2)
|
* @param event the kind of button gesture that needs to be detected
|
||||||
//% whenUsed
|
* @param body code to run when the event is raised
|
||||||
export const touchSensorImpl3: TouchSensor = new TouchSensor(3)
|
*/
|
||||||
//% whenUsed
|
//% help=input/touch/on-event
|
||||||
export const touchSensorImpl4: TouchSensor = new TouchSensor(4)
|
//% blockId=touchEvent block="on %sensor|%event"
|
||||||
|
//% parts="touch"
|
||||||
|
//% blockNamespace=input
|
||||||
|
//% weight=99 blockGap=8
|
||||||
|
//% group="Touch sensor"
|
||||||
|
onEvent(ev: TouchSensorEvent, body: () => void) {
|
||||||
|
this.button.onEvent(<ButtonEvent><number>ev, body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//% whenUsed block="touch sensor 1" weight=95 fixedInstance
|
//% whenUsed block="touch sensor 1" weight=95 fixedInstance
|
||||||
export const touchSensor1: Button = touchSensorImpl1.button
|
export const touchSensor1: TouchSensor = new TouchSensor(1)
|
||||||
|
|
||||||
//% whenUsed block="touch sensor 2" weight=95 fixedInstance
|
//% whenUsed block="touch sensor 2" weight=95 fixedInstance
|
||||||
export const touchSensor2: Button = touchSensorImpl2.button
|
export const touchSensor2: TouchSensor = new TouchSensor(2)
|
||||||
|
|
||||||
//% whenUsed block="touch sensor 3" weight=95 fixedInstance
|
//% whenUsed block="touch sensor 3" weight=95 fixedInstance
|
||||||
export const touchSensor3: Button = touchSensorImpl3.button
|
export const touchSensor3: TouchSensor = new TouchSensor(3)
|
||||||
|
|
||||||
//% whenUsed block="touch sensor 4" weight=95 fixedInstance
|
//% whenUsed block="touch sensor 4" weight=95 fixedInstance
|
||||||
export const touchSensor4: Button = touchSensorImpl4.button
|
export const touchSensor4: TouchSensor = new TouchSensor(4)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user