|
1 | 1 | const ArgumentType = require('../../../extension-support/argument-type'); |
2 | 2 | const BlockType = require('../../../extension-support/block-type'); |
3 | 3 | const Cast = require('../../../util/cast'); |
| 4 | +const UtilColor = require('../../../util/color'); |
4 | 5 |
|
5 | 6 | const Color = require('./color'); |
6 | 7 |
|
@@ -273,6 +274,42 @@ class BleBaseBlocks { |
273 | 274 | defaultValue: 255 |
274 | 275 | } |
275 | 276 | } |
| 277 | + }, |
| 278 | + { |
| 279 | + opcode: 'setHubLEDColorToScratchColor', |
| 280 | + text: formatMessage({ |
| 281 | + id: 'legobluetooth.setHubLEDColorToScratchColor', |
| 282 | + default: 'set hub LED color to [COLOR]', |
| 283 | + }), |
| 284 | + blockType: BlockType.COMMAND, |
| 285 | + arguments: { |
| 286 | + COLOR: { |
| 287 | + type: ArgumentType.COLOR, |
| 288 | + defaultValue: 100 |
| 289 | + }, |
| 290 | + } |
| 291 | + }, |
| 292 | + { |
| 293 | + opcode: 'setHubLEDColorCSB', |
| 294 | + text: formatMessage({ |
| 295 | + id: 'legobluetooth.setHubLEDColorCSB', |
| 296 | + default: 'set hub LED color to C[COLOR] S[SATURATION] B[BRIGHTNESS]', |
| 297 | + }), |
| 298 | + blockType: BlockType.COMMAND, |
| 299 | + arguments: { |
| 300 | + COLOR: { |
| 301 | + type: ArgumentType.NUMBER, |
| 302 | + defaultValue: 100 |
| 303 | + }, |
| 304 | + SATURATION: { |
| 305 | + type: ArgumentType.NUMBER, |
| 306 | + defaultValue: 100 |
| 307 | + }, |
| 308 | + BRIGHTNESS: { |
| 309 | + type: ArgumentType.NUMBER, |
| 310 | + defaultValue: 100 |
| 311 | + } |
| 312 | + } |
276 | 313 | } |
277 | 314 | ]; |
278 | 315 |
|
@@ -627,6 +664,20 @@ class BleBaseBlocks { |
627 | 664 | return this._peripheral.setLEDColorRGB(red, green, blue).then(waitPromise); |
628 | 665 | } |
629 | 666 |
|
| 667 | + setHubLEDColorToScratchColor(args) { |
| 668 | + const rgb = Cast.toRgbColorObject(args.COLOR); |
| 669 | + return this._peripheral.setLEDColorRGB(rgb.r, rgb.g, rgb.b).then(waitPromise); |
| 670 | + } |
| 671 | + |
| 672 | + setHubLEDColorCSB(args) { |
| 673 | + const rgb = UtilColor.hsvToRgb({ |
| 674 | + h: Cast.toNumber(args.COLOR) * 360 / 100, |
| 675 | + s: Cast.toNumber(args.SATURATION) / 100, |
| 676 | + v: Cast.toNumber(args.BRIGHTNESS) / 100 |
| 677 | + }); |
| 678 | + return this._peripheral.setLEDColorRGB(rgb.r, rgb.g, rgb.b).then(waitPromise); |
| 679 | + } |
| 680 | + |
630 | 681 | getHubTilt(args) { |
631 | 682 | const key = 'tilt' + args.XYZ.toUpperCase(); |
632 | 683 | const value = this._peripheral.internalInputValue(key); |
|
0 commit comments