diff --git a/libs/core/buttons.cpp b/libs/core/buttons.cpp index a319aa75..127b9f66 100644 --- a/libs/core/buttons.cpp +++ b/libs/core/buttons.cpp @@ -16,17 +16,35 @@ enum class ButtonEvent { 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 { void *buttonPoll(void *); class Button { public: + void *ptr; int id; bool wasPressed; bool isPressed; int timePressed; Button(int ev3id) { + ptr = 0; // make sure we're not treated as ref-counted object id = ev3id; wasPressed = 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 { /** * Do something when a button (`A`, `B` or both `A` + `B`) is clicked, double clicked, etc... diff --git a/libs/core/enums.d.ts b/libs/core/enums.d.ts index 9d19edfc..90b5ca0b 100644 --- a/libs/core/enums.d.ts +++ b/libs/core/enums.d.ts @@ -16,4 +16,22 @@ 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. diff --git a/libs/core/shims.d.ts b/libs/core/shims.d.ts index efb3bfb9..359cfd64 100644 --- a/libs/core/shims.d.ts +++ b/libs/core/shims.d.ts @@ -38,10 +38,18 @@ declare namespace input { //% block="button exit" weight=95 fixedInstance shim=pxt::getButton(5) 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 { /** * Do something when a button (`A`, `B` or both `A` + `B`) is clicked, double clicked, etc...