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)
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user