Add LED support
This commit is contained in:
parent
9f8377f893
commit
0aeba646bd
@ -16,17 +16,35 @@ enum class ButtonEvent {
|
|||||||
Down = 4,
|
Down = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Patterns for lights under the buttons.
|
||||||
|
*/
|
||||||
|
enum class LightsPattern {
|
||||||
|
Off = LED_BLACK,
|
||||||
|
Green = LED_GREEN,
|
||||||
|
Red = LED_RED,
|
||||||
|
Orange = LED_ORANGE,
|
||||||
|
GreenFlash = LED_GREEN_FLASH,
|
||||||
|
RedFlash = LED_RED_FLASH,
|
||||||
|
OrangeFlash = LED_ORANGE_FLASH,
|
||||||
|
GreenPulse = LED_GREEN_PULSE,
|
||||||
|
RedPulse = LED_RED_PULSE,
|
||||||
|
OrangePulse = LED_ORANGE_PULSE,
|
||||||
|
};
|
||||||
|
|
||||||
namespace pxt {
|
namespace pxt {
|
||||||
|
|
||||||
void *buttonPoll(void *);
|
void *buttonPoll(void *);
|
||||||
|
|
||||||
class Button {
|
class Button {
|
||||||
public:
|
public:
|
||||||
|
void *ptr;
|
||||||
int id;
|
int id;
|
||||||
bool wasPressed;
|
bool wasPressed;
|
||||||
bool isPressed;
|
bool isPressed;
|
||||||
int timePressed;
|
int timePressed;
|
||||||
Button(int ev3id) {
|
Button(int ev3id) {
|
||||||
|
ptr = 0; // make sure we're not treated as ref-counted object
|
||||||
id = ev3id;
|
id = ev3id;
|
||||||
wasPressed = false;
|
wasPressed = false;
|
||||||
isPressed = false;
|
isPressed = false;
|
||||||
@ -121,7 +139,30 @@ Button *getButton(int id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//% noRefCounting fixedInstances
|
namespace control {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the version of system software currently running.
|
||||||
|
*/
|
||||||
|
//%
|
||||||
|
String deviceFirmwareVersion() {
|
||||||
|
return mkString(HardwareVersionString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO rename this? move it somewhere?
|
||||||
|
namespace output {
|
||||||
|
/**
|
||||||
|
* Set lights.
|
||||||
|
*/
|
||||||
|
//% blockId=setLights block="set lights %pattern"
|
||||||
|
void setLights(LightsPattern pattern) {
|
||||||
|
SetLedPattern((uint8_t)pattern);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//% fixedInstances
|
||||||
namespace ButtonMethods {
|
namespace ButtonMethods {
|
||||||
/**
|
/**
|
||||||
* Do something when a button (`A`, `B` or both `A` + `B`) is clicked, double clicked, etc...
|
* Do something when a button (`A`, `B` or both `A` + `B`) is clicked, double clicked, etc...
|
||||||
|
18
libs/core/enums.d.ts
vendored
18
libs/core/enums.d.ts
vendored
@ -16,4 +16,22 @@
|
|||||||
Down = 4,
|
Down = 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Patterns for lights under the buttons.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare enum LightsPattern {
|
||||||
|
Off = 0, // LED_BLACK
|
||||||
|
Green = 1, // LED_GREEN
|
||||||
|
Red = 2, // LED_RED
|
||||||
|
Orange = 3, // LED_ORANGE
|
||||||
|
GreenFlash = 4, // LED_GREEN_FLASH
|
||||||
|
RedFlash = 5, // LED_RED_FLASH
|
||||||
|
OrangeFlash = 6, // LED_ORANGE_FLASH
|
||||||
|
GreenPulse = 7, // LED_GREEN_PULSE
|
||||||
|
RedPulse = 8, // LED_RED_PULSE
|
||||||
|
OrangePulse = 9, // LED_ORANGE_PULSE
|
||||||
|
}
|
||||||
|
|
||||||
// Auto-generated. Do not edit. Really.
|
// Auto-generated. Do not edit. Really.
|
||||||
|
10
libs/core/shims.d.ts
vendored
10
libs/core/shims.d.ts
vendored
@ -38,10 +38,18 @@ declare namespace input {
|
|||||||
//% block="button exit" weight=95 fixedInstance shim=pxt::getButton(5)
|
//% block="button exit" weight=95 fixedInstance shim=pxt::getButton(5)
|
||||||
const buttonExit: Button;
|
const buttonExit: Button;
|
||||||
}
|
}
|
||||||
|
declare namespace output {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set lights.
|
||||||
|
*/
|
||||||
|
//% blockId=setLights block="set lights %pattern" shim=output::setLights
|
||||||
|
function setLights(pattern: LightsPattern): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//% noRefCounting fixedInstances
|
//% fixedInstances
|
||||||
declare interface Button {
|
declare interface Button {
|
||||||
/**
|
/**
|
||||||
* Do something when a button (`A`, `B` or both `A` + `B`) is clicked, double clicked, etc...
|
* Do something when a button (`A`, `B` or both `A` + `B`) is clicked, double clicked, etc...
|
||||||
|
Loading…
Reference in New Issue
Block a user