|
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,28 @@ class BleBaseBlocks { |
273 | 274 | defaultValue: 255 |
274 | 275 | } |
275 | 276 | } |
| 277 | + }, |
| 278 | + { |
| 279 | + opcode: 'setHubLEDColorHSV', |
| 280 | + text: formatMessage({ |
| 281 | + id: 'legobluetooth.setHubLEDColorHSV', |
| 282 | + default: 'set hub LED color to H[HUE] S[SATURATION] V[VALUE]', |
| 283 | + }), |
| 284 | + blockType: BlockType.COMMAND, |
| 285 | + arguments: { |
| 286 | + COLOR: { |
| 287 | + type: ArgumentType.NUMBER, |
| 288 | + defaultValue: 360 |
| 289 | + }, |
| 290 | + SATURATION: { |
| 291 | + type: ArgumentType.NUMBER, |
| 292 | + defaultValue: 100 |
| 293 | + }, |
| 294 | + VALUE: { |
| 295 | + type: ArgumentType.NUMBER, |
| 296 | + defaultValue: 100 |
| 297 | + } |
| 298 | + } |
276 | 299 | } |
277 | 300 | ]; |
278 | 301 |
|
@@ -627,6 +650,15 @@ class BleBaseBlocks { |
627 | 650 | return this._peripheral.setLEDColorRGB(red, green, blue).then(waitPromise); |
628 | 651 | } |
629 | 652 |
|
| 653 | + setHubLEDColorHSV(args) { |
| 654 | + const rgb = UtilColor.hsvToRgb({ |
| 655 | + h: Cast.toNumber(args.HUE), |
| 656 | + s: Cast.toNumber(args.SATURATION) / 100, |
| 657 | + v: Cast.toNumber(args.VALUE) / 100 |
| 658 | + }); |
| 659 | + return this._peripheral.setLEDColorRGB(rgb.r, rgb.g, rgb.b).then(waitPromise); |
| 660 | + } |
| 661 | + |
630 | 662 | getHubTilt(args) { |
631 | 663 | const key = 'tilt' + args.XYZ.toUpperCase(); |
632 | 664 | const value = this._peripheral.internalInputValue(key); |
|
0 commit comments