Input blocks revision

- add Button and Pin event types
- merge onPinPressed & onPinReleased in new onPinEvent function
- create new onButtonEvent function
This commit is contained in:
Amerlander
2020-02-20 03:24:13 +01:00
parent 9c8595afdd
commit 38cf0ec0c6
9 changed files with 120 additions and 57 deletions

View File

@ -1,4 +1,14 @@
namespace pxsim.input {
export function onButtonEvent(button: number, buttonEvent: number, handler: RefAction): void {
let b = board().buttonPairState;
if (button == b.props.ID_BUTTON_AB && !b.usesButtonAB) {
b.usesButtonAB = true;
runtime.queueDisplayUpdate();
}
pxtcore.registerWithDal(button, buttonEvent, handler);
}
// Deprecated
export function onButtonPressed(button: number, handler: RefAction): void {
let b = board().buttonPairState;
if (button == b.props.ID_BUTTON_AB && !b.usesButtonAB) {

View File

@ -1,4 +1,13 @@
namespace pxsim.input {
export function onPinEvent(pinId: number, pinEvent: number, handler: RefAction) {
let pin = getPin(pinId);
if (!pin) return;
pin.isTouched();
runtime.queueDisplayUpdate();
pxtcore.registerWithDal(pin.id, pinEvent, handler);
}
// Deprecated
export function onPinPressed(pinId: number, handler: RefAction) {
let pin = getPin(pinId);
if (!pin) return;
@ -7,6 +16,7 @@ namespace pxsim.input {
pxtcore.registerWithDal(pin.id, DAL.MICROBIT_BUTTON_EVT_CLICK, handler);
}
// Deprecated
export function onPinReleased(pinId: number, handler: RefAction) {
let pin = getPin(pinId);
if (!pin) return;