pxt-calliope/libs/core/input.ts
Juri Wolf 77ed2ccfb1
V4 updates (#210)
* update pxt.json files

* Fix button event enums

fixes https://github.com/microsoft/pxt-calliope/issues/206

* Fix Safari CSS Rule for iOS app

fixes https://github.com/microsoft/pxt-calliope/issues/205

* aprove preffered repos

should fix https://github.com/microsoft/pxt-calliope/issues/167
2023-01-11 09:51:27 -08:00

82 lines
2.2 KiB
TypeScript

enum ButtonEvent {
//% blockIdentity="input.buttonEventValueId"
//% block="pressed down"
Down = ButtonEvents.Down,
//% blockIdentity="input.buttonEventValueId"
//% block="released up"
Up = ButtonEvents.Up,
//% blockIdentity="input.buttonEventValueId"
//% block="clicked"
Click = ButtonEvents.Click,
//% blockIdentity="input.buttonEventValueId"
//% block="long clicked"
LongClick = ButtonEvents.LongClick,
//% blockIdentity="input.buttonEventValueId"
//% block="hold"
Hold = ButtonEvents.Hold,
};
/**
* Events and data from sensors
*/
//% color=#C90072 weight=99 icon="\uf192"
//% groups=['Events', 'States', 'Sensors', 'Configuration', 'System', 'others']
namespace input {
/**
* Returns the ID of an Button Event
*/
//% help=input/button-event
//% weight=19 blockId="control_button_event_value" block="%id"
//% advanced=true
//% group="Events"
export function buttonEventValue(id: ButtonEvent): number {
return id;
}
/**
* Returns the ID of an Click Event
*/
//% blockId="control_button_event_click" block="clicked"
//% advanced=true
//% blockHidden=true
export function buttonEventClick(): number {
return ButtonEvent.Click;
}
/**
* Returns the ID of an Down Event
*/
//% blockId="control_button_event_down" block="pressed down"
//% advanced=true
//% blockHidden=true
export function buttonEventDown(): number {
return ButtonEvent.Down;
}
/**
* Gets the number of milliseconds elapsed since power on.
*/
//% help=input/running-time weight=50 blockGap=8
//% blockId=device_get_running_time block="running time (ms)"
//% advanced=true
//% group="System"
export function runningTime() {
return control.millis();
}
/**
* Gets the number of microseconds elapsed since power on.
*/
//% help=input/running-time-micros weight=49 blockGap=8
//% blockId=device_get_running_time_micros block="running time (micros)"
//% advanced=true
//% group="System"
export function runningTimeMicros() {
return control.micros();
}
}