Skip to content

Commit 7f2f348

Browse files
committed
Ability to set color by hue
1 parent 32f61e4 commit 7f2f348

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

scratch-vm/src/extensions/scratch3_legoble/lib/ble-base-blocks.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const ArgumentType = require('../../../extension-support/argument-type');
22
const BlockType = require('../../../extension-support/block-type');
33
const Cast = require('../../../util/cast');
4+
const UtilColor = require('../../../util/color');
45

56
const Color = require('./color');
67

@@ -273,6 +274,28 @@ class BleBaseBlocks {
273274
defaultValue: 255
274275
}
275276
}
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+
}
276299
}
277300
];
278301

@@ -627,6 +650,15 @@ class BleBaseBlocks {
627650
return this._peripheral.setLEDColorRGB(red, green, blue).then(waitPromise);
628651
}
629652

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+
630662
getHubTilt(args) {
631663
const key = 'tilt' + args.XYZ.toUpperCase();
632664
const value = this._peripheral.internalInputValue(key);

scratch-vm/src/extensions/scratch3_legoble/lib/setup-translations.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const setupTranslations = function (formatMessage, extTranslations = {}) {
2828
'legobluetooth.getTilt': '[PORT] tilt [XY]',
2929
'legobluetooth.setHubLEDColor': 'set hub LED color to [COLOR]',
3030
'legobluetooth.setHubLEDColorRGB': 'set hub LED color to R[RED] G[GREEN] B[BLUE]',
31+
'legobluetooth.setHubLEDColorHSV': 'set hub LED color to H[HUE] S[SATURATION] V[VALUE]',
3132
'legobluetooth.getHubTilt': 'hub tilt [XYZ]',
3233
'legobluetooth.getAngle': '[AXIS] angle',
3334

0 commit comments

Comments
 (0)