From 24f555d1f2450badc2692c553633505282f8c2cb Mon Sep 17 00:00:00 2001 From: Juri Wolf Date: Mon, 29 Apr 2024 13:29:58 +0200 Subject: [PATCH] move rgb led to MBitMore --- libs/core/_locales/core-jsdoc-strings.json | 11 +---- libs/core/_locales/core-strings.json | 3 -- libs/core/enums.d.ts | 2 - libs/core/pxt.json | 1 - libs/core/shims.d.ts | 52 ---------------------- libs/scratch/MbitMoreCommon.h | 1 + libs/scratch/MbitMoreDevice.cpp | 19 ++++++++ libs/scratch/enums.d.ts | 1 + 8 files changed, 22 insertions(+), 68 deletions(-) diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index 39231d0c2..e47c08605 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -251,21 +251,13 @@ "_py.range|param|stop": "The value to end the sequence before. This value will not show up in the result", "_py.slice": "Returns a section of an array according to python's extended slice syntax", "_py.stringSlice": "Returns a section of a string according to python's extended slice syntax", - "basic": "Provides access to basic micro:bit functionality.\n\nProvides access to basic calliope mini functionality.", + "basic": "Provides access to basic micro:bit functionality.", "basic.clearScreen": "Turn off all LEDs", "basic.forever": "Repeats the code forever in the background. On each iteration, allows other codes to run.", "basic.pause": "Pause for the specified time in milliseconds", "basic.pause|param|ms": "how long to pause for, eg: 100, 200, 500, 1000, 2000", "basic.plotLeds": "Draws an image on the LED screen.", "basic.plotLeds|param|leds": "pattern of LEDs to turn on/off", - "basic.setLedColor": "Sets the color on the built-in RGB LED. Set to 0 to turn off.", - "basic.setLedColorDal": "Sets the color on the built-in RGB LED. Set to 0 to turn off.", - "basic.setLedColorsCodal": "Sets the color on the built-in RGB LED. Set to 0 to turn off.", - "basic.setLedColorsCodal|param|brightness": "The LED brightness in percent.", - "basic.setLedColorsCodal|param|color1": "The color of the first LED in RGB format (e.g., 0xFF0000 for red).", - "basic.setLedColorsCodal|param|color2": "The second LED color.", - "basic.setLedColorsCodal|param|color3": "The third LED color.", - "basic.setLedColor|param|color": "The color of the LED in RGB format (e.g., 0xFF0000 for red).", "basic.showAnimation": "Shows a sequence of LED screens as an animation.", "basic.showAnimation|param|interval": "time in milliseconds between each redraw", "basic.showAnimation|param|leds": "pattern of LEDs to turn on/off", @@ -283,7 +275,6 @@ "basic.showString": "Display text on the display, one character at a time. If the string fits on the screen (i.e. is one letter), does not scroll.", "basic.showString|param|interval": "how fast to shift characters; eg: 150, 100, 200, -100", "basic.showString|param|text": "the text to scroll on the screen, eg: \"Hello!\"", - "basic.turnRgbLedOff": "Sets the color on the built-in RGB LED. Set to 0 to turn off.", "console": "Reading and writing data to the console output.", "console.addListener": "Adds a listener for the log messages", "console.inspect": "Convert any object or value to a string representation", diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index ef1090553..355d2b33c 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -298,13 +298,11 @@ "basic.clearScreen|block": "clear screen", "basic.forever|block": "forever", "basic.pause|block": "pause (ms) %pause", - "basic.setLedColor|block": "set LED to %color=colorNumberPicker", "basic.showArrow|block": "show arrow %i=device_arrow", "basic.showIcon|block": "show icon %i", "basic.showLeds|block": "show leds", "basic.showNumber|block": "show|number %number", "basic.showString|block": "show|string %text", - "basic.turnRgbLedOff|block": "turn built-in LED off", "basic|block": "basic", "console|block": "console", "control.deviceName|block": "device name", @@ -514,7 +512,6 @@ "{id:group}Operations": "Operations", "{id:group}Pins": "Pins", "{id:group}Pulse": "Pulse", - "{id:group}RGB LED": "RGB LED", "{id:group}Read": "Read", "{id:group}SPI": "SPI", "{id:group}Servo": "Servo", diff --git a/libs/core/enums.d.ts b/libs/core/enums.d.ts index 78c070b11..2d3478a63 100644 --- a/libs/core/enums.d.ts +++ b/libs/core/enums.d.ts @@ -741,8 +741,6 @@ declare namespace serial { //% block="long pressed" LongPressed = 4, // MICROBIT_BUTTON_EVT_LONG_CLICK } -declare namespace basic { -} declare const enum TouchTargetMode { diff --git a/libs/core/pxt.json b/libs/core/pxt.json index d8a8769c1..a9cc42b69 100644 --- a/libs/core/pxt.json +++ b/libs/core/pxt.json @@ -64,7 +64,6 @@ "light.cpp", "logo.cpp", "loops.ts", - "rgbled.cpp", "touchmode.cpp", "soundexpressions.ts", "soundexpressions.cpp", diff --git a/libs/core/shims.d.ts b/libs/core/shims.d.ts index 5ec12d5b2..798b2842e 100644 --- a/libs/core/shims.d.ts +++ b/libs/core/shims.d.ts @@ -1280,58 +1280,6 @@ declare namespace input { //% help="input/logo-is-pressed" shim=input::logoIsPressed function logoIsPressed(): boolean; } - - - /** - * Provides access to basic calliope mini functionality. - */ - -declare namespace basic { - - /** - * Sets the color on the built-in RGB LED. Set to 0 to turn off. - */ - //% blockId=device_turn_rgb_led_off block="turn built-in LED off" - //% help=basic/turn-rgb-led-off - //% weight=10 - //% group="RGB LED" - //% advanced=true shim=basic::turnRgbLedOff - function turnRgbLedOff(): void; - - /** - * Sets the color on the built-in RGB LED. Set to 0 to turn off. - * @param color1 The color of the first LED in RGB format (e.g., 0xFF0000 for red). - */ - //% blockId=device_set_led_colors-dal - //% hidden=1 shim=basic::setLedColorDal - function setLedColorDal(color: int32): void; - - /** - * Sets the color on the built-in RGB LED. Set to 0 to turn off. - * @param color1 The color of the first LED in RGB format (e.g., 0xFF0000 for red). - * @param color2 The second LED color. - * @param color3 The third LED color. - * @param brightness The LED brightness in percent. - */ - //% blockId=device_set_led_colors-codal brightness.defl=20 shim=basic::setLedColorsCodal - function setLedColorsCodal(color1: int32, color2: int32, color3: int32, brightness?: int32): void; - - /** - * Sets the color on the built-in RGB LED. Set to 0 to turn off. - * @param color The color of the LED in RGB format (e.g., 0xFF0000 for red). - */ - //% help=basic/set-led-color - //% blockId=device_set_led_color - //% block="set LED to %color=colorNumberPicker" - //% expandableArgumentMode="toggle" - //% - //% - //% - //% - //% weight=10 - //% group="RGB LED" color.defl=0xff0000 shim=basic::setLedColor - function setLedColor(color?: int32): void; -} declare namespace pins { /** diff --git a/libs/scratch/MbitMoreCommon.h b/libs/scratch/MbitMoreCommon.h index 89f4b371b..3a7b52a23 100644 --- a/libs/scratch/MbitMoreCommon.h +++ b/libs/scratch/MbitMoreCommon.h @@ -36,6 +36,7 @@ enum MbitMoreCommand // 3 bits (0x00..0x07) CMD_DISPLAY = 0x02, CMD_AUDIO = 0x03, CMD_DATA = 0x04, + CMD_RGB = 0x05, }; enum MbitMorePinCommand diff --git a/libs/scratch/MbitMoreDevice.cpp b/libs/scratch/MbitMoreDevice.cpp index b0567627c..2ffee87e0 100644 --- a/libs/scratch/MbitMoreDevice.cpp +++ b/libs/scratch/MbitMoreDevice.cpp @@ -231,6 +231,25 @@ void MbitMoreDevice::onSerialConnected() { */ void MbitMoreDevice::onCommandReceived(uint8_t *data, size_t length) { const int command = (data[0] >> 5); + if(command == MbitMoreCommand::CMD_RGB) { +#if MICROBIT_CODAL + uint8_t rgbBuffer[9] = {0}; + memset(rgbBuffer, 0, sizeof(rgbBuffer)); // Clear the buffer + rgbBuffer[0] = data[1] * 20 / 100; + rgbBuffer[1] = data[2] * 20 / 100; + rgbBuffer[2] = data[3] * 20 / 100; + rgbBuffer[3] = data[4] * 20 / 100; + rgbBuffer[4] = data[5] * 20 / 100; + rgbBuffer[5] = data[6] * 20 / 100; + rgbBuffer[6] = data[7] * 20 / 100; + rgbBuffer[7] = data[8] * 20 / 100; + rgbBuffer[8] = data[9] * 20 / 100; + neopixel_send_buffer(uBit.io.RGB, rgbBuffer, sizeof(rgbBuffer)); +#else + uBit.rgb.setColour(data[1], data[2], data[3], 0); +#endif + } + else if (command == MbitMoreCommand::CMD_DISPLAY) { const int displayCommand = data[0] & 0b11111; if (displayCommand == MbitMoreDisplayCommand::TEXT) { diff --git a/libs/scratch/enums.d.ts b/libs/scratch/enums.d.ts index 08cd6cf1a..e8a98121d 100644 --- a/libs/scratch/enums.d.ts +++ b/libs/scratch/enums.d.ts @@ -21,6 +21,7 @@ CMD_DISPLAY = 0x02, CMD_AUDIO = 0x03, CMD_DATA = 0x04, + CMD_RGB = 0x05, }