Buttons rename (#287)
* renaming up/down/click to released/pressed/bump * missing images * fixing signature issue * updated strings * white lego logo
This commit is contained in:
@ -9,9 +9,9 @@
|
||||
"BrickLight.RedFlash|block": "red flash",
|
||||
"BrickLight.RedPulse|block": "red pulse",
|
||||
"BrickLight.Red|block": "red",
|
||||
"ButtonEvent.Click|block": "click",
|
||||
"ButtonEvent.Down|block": "down",
|
||||
"ButtonEvent.Up|block": "up",
|
||||
"ButtonEvent.Bumped|block": "bumped",
|
||||
"ButtonEvent.Pressed|block": "pressed",
|
||||
"ButtonEvent.Released|block": "released",
|
||||
"MoveUnit.Degrees|block": "degrees",
|
||||
"MoveUnit.MilliSeconds|block": "milliseconds",
|
||||
"MoveUnit.Rotations|block": "rotations",
|
||||
|
@ -29,14 +29,15 @@ const enum BrickLight {
|
||||
* User interaction on buttons
|
||||
*/
|
||||
const enum ButtonEvent {
|
||||
//% block="click"
|
||||
Click = 1,
|
||||
//% block="up"
|
||||
Up = 3,
|
||||
//% block="down"
|
||||
Down = 4,
|
||||
//% block="pressed"
|
||||
Pressed = 4,
|
||||
//% block="bumped"
|
||||
Bumped = 1,
|
||||
//% block="released"
|
||||
Released = 3,
|
||||
}
|
||||
|
||||
|
||||
namespace brick {
|
||||
/**
|
||||
* Generic button class, for device buttons and sensors.
|
||||
@ -62,12 +63,12 @@ namespace brick {
|
||||
if (curr) {
|
||||
this._wasPressed = true;
|
||||
this.downTime = control.millis()
|
||||
control.raiseEvent(this._id, ButtonEvent.Down)
|
||||
control.raiseEvent(this._id, ButtonEvent.Pressed)
|
||||
} else {
|
||||
control.raiseEvent(this._id, ButtonEvent.Up)
|
||||
control.raiseEvent(this._id, ButtonEvent.Released)
|
||||
const delta = control.millis() - this.downTime;
|
||||
if (delta < 500)
|
||||
control.raiseEvent(this._id, ButtonEvent.Click)
|
||||
control.raiseEvent(this._id, ButtonEvent.Bumped)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,8 +66,8 @@ namespace console.screen {
|
||||
if (!lines) {
|
||||
lines = [];
|
||||
console.addListener(log);
|
||||
brick.buttonUp.onEvent(ButtonEvent.Click, () => scroll(-3))
|
||||
brick.buttonDown.onEvent(ButtonEvent.Click, () => scroll(3))
|
||||
brick.buttonUp.onEvent(ButtonEvent.Bumped, () => scroll(-3))
|
||||
brick.buttonDown.onEvent(ButtonEvent.Bumped, () => scroll(3))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,25 +6,25 @@ brick.setLight(BrickLight.Orange)
|
||||
|
||||
brick.heart.doubled().draw(100, 50, Draw.Double | Draw.Transparent)
|
||||
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, () => {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => {
|
||||
screen.clear()
|
||||
})
|
||||
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Click, () => {
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Bumped, () => {
|
||||
brick.drawRect(10, 70, 20, 10, Draw.Fill)
|
||||
brick.setLight(BrickLight.Red)
|
||||
brick.setFont(brick.microbitFont())
|
||||
})
|
||||
|
||||
brick.buttonRight.onEvent(ButtonEvent.Click, () => {
|
||||
brick.buttonRight.onEvent(ButtonEvent.Bumped, () => {
|
||||
brick.print("Right!", 10, 60)
|
||||
})
|
||||
|
||||
brick.buttonDown.onEvent(ButtonEvent.Click, () => {
|
||||
brick.buttonDown.onEvent(ButtonEvent.Bumped, () => {
|
||||
brick.print("Down! ", 10, 60)
|
||||
})
|
||||
|
||||
brick.buttonUp.onEvent(ButtonEvent.Click, () => {
|
||||
brick.buttonUp.onEvent(ButtonEvent.Bumped, () => {
|
||||
brick.print("Up! ", 10, 60)
|
||||
})
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
{
|
||||
"TouchSensorEvent": "Touch sensor interactions",
|
||||
"sensors.TouchSensor.isPressed": "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",
|
||||
|
@ -1,7 +1,4 @@
|
||||
{
|
||||
"TouchSensorEvent.Bumped|block": "bumped",
|
||||
"TouchSensorEvent.Pressed|block": "pressed",
|
||||
"TouchSensorEvent.Released|block": "released",
|
||||
"sensors.TouchSensor.isPressed|block": "%sensor|is pressed",
|
||||
"sensors.TouchSensor.onEvent|block": "on %sensor|%event",
|
||||
"sensors.TouchSensor.pauseUntil|block": "pause until %sensor|%event",
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Touch Sensor
|
||||
|
||||
```cards
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.expressionsBigSmile)
|
||||
})
|
||||
sensors.touch1.isPressed();
|
||||
|
@ -1,7 +1,7 @@
|
||||
# On Event
|
||||
|
||||
```sig
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Released, function () { })
|
||||
sensors.touch1.onEvent(ButtonEvent.Released, function () { })
|
||||
```
|
||||
|
||||
# Parameters
|
||||
@ -10,7 +10,7 @@ sensors.touch1.onEvent(TouchSensorEvent.Released, function () { })
|
||||
|
||||
|
||||
```blocks
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Released, function () {
|
||||
sensors.touch1.onEvent(ButtonEvent.Released, function () {
|
||||
brick.showImage(images.expressionsSick)
|
||||
})
|
||||
```
|
||||
|
@ -1,8 +1,8 @@
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
})
|
||||
sensors.touch2.onEvent(TouchSensorEvent.Bumped, function () {
|
||||
sensors.touch2.onEvent(ButtonEvent.Bumped, function () {
|
||||
})
|
||||
sensors.touch3.onEvent(TouchSensorEvent.Released, function () {
|
||||
sensors.touch3.onEvent(ButtonEvent.Released, function () {
|
||||
})
|
||||
sensors.touch4.isPressed();
|
||||
sensors.touch4.wasPressed();
|
||||
|
@ -1,17 +1,5 @@
|
||||
// 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
|
||||
@ -48,8 +36,8 @@ namespace sensors {
|
||||
//% sensor.fieldEditor="ports"
|
||||
//% weight=99 blockGap=8
|
||||
//% group="Touch Sensor"
|
||||
onEvent(ev: TouchSensorEvent, body: () => void) {
|
||||
this.button.onEvent(<ButtonEvent><number>ev, body)
|
||||
onEvent(ev: ButtonEvent, body: () => void) {
|
||||
this.button.onEvent(ev, body)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,7 +52,7 @@ namespace sensors {
|
||||
//% sensor.fieldEditor="ports"
|
||||
//% weight=98 blockGap=8
|
||||
//% group="Touch Sensor"
|
||||
pauseUntil(ev: TouchSensorEvent) {
|
||||
pauseUntil(ev: ButtonEvent) {
|
||||
this.button.pauseUntil(<ButtonEvent><number>ev);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user