Skip to content

Commit 0a03b15

Browse files
committed
Ability to set color by hue
1 parent 32f61e4 commit 0a03b15

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

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

Lines changed: 51 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,42 @@ class BleBaseBlocks {
273274
defaultValue: 255
274275
}
275276
}
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+
}
276313
}
277314
];
278315

@@ -627,6 +664,20 @@ class BleBaseBlocks {
627664
return this._peripheral.setLEDColorRGB(red, green, blue).then(waitPromise);
628665
}
629666

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ 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.setHubLEDColorToScratchColor': 'set hub LED color to [COLOR]',
32+
'legobluetooth.setHubLEDColorCSB': 'set hub LED color to C[COLOR] S[SATURATION] B[BRIGHTNESS]',
3133
'legobluetooth.getHubTilt': 'hub tilt [XYZ]',
3234
'legobluetooth.getAngle': '[AXIS] angle',
3335

0 commit comments

Comments
 (0)