@@ -9,6 +9,7 @@ class GoDice {
99 BATTERY_LEVEL : 3 ,
1010 DICE_COLOUR : 23 ,
1111 SET_LED : 8 ,
12+ SET_LED_TOGGLE : 16 ,
1213 }
1314
1415 diceColour = {
@@ -278,10 +279,11 @@ class GoDice {
278279
279280 /**
280281 * Turn On/Off RGB LEDs, will turn off if led1 and led2 are null
281- * @param {Array } led1 - an array to control the 1st LED in the following format '[R,G,B]'
282- * where R,G and B are numbers in the range of 0-255
283- * @param {Array } led2 - an array to control the 2nd LED in the following format '[R,G,B]'
284- * where R,G and B are numbers in the range of 0-255
282+ * @param {Array } led1 - an array to control the 1st LED in the following format '[R, G, B]'
283+ * where R,G and B are numbers in the range of 0-255
284+ *
285+ * @param {Array } led2 - an array to control the 2nd LED in the following format '[R, G, B]'
286+ * where R,G and B are numbers in the ran ge of 0-255
285287 */
286288 setLed ( led1 , led2 ) {
287289 console . log ( led1 , led2 )
@@ -296,6 +298,22 @@ class GoDice {
296298 console . debug ( "messageArray" , messageArray ) ;
297299 this . sendMessage ( messageArray ) ;
298300 }
301+
302+ /**
303+ * Pulses LEDs for set time and color
304+ * @param {number } pulseCount - an integer of how many times the pulse will repeat (max 255)
305+ * @param {number } onTime - how much time should the LED be ON each pulse (units of 10ms, max 255)
306+ * @param {number } offTime - how much time should the LED be OFF each pulse (units of 10ms, max 255)
307+ * @param {Array } RGB - an array to control both LEDs color's in the following format '[R, G, B]'
308+ * where R, G and B are number in the range of 0-255
309+ */
310+ pulseLed ( pulseCount , onTime , offTime , RGB ) {
311+ if ( RGB . length === 3 ) {
312+ let rgbColor = RGB . map ( ( i ) => Math . max ( Math . min ( i , 255 ) , 0 ) ) ;
313+ const messageArray = [ this . messageIdentifiers . SET_LED_TOGGLE , pulseCount , onTime , offTime , ...rgbColor , 1 , 0 ]
314+ this . sendMessage ( messageArray ) ;
315+ }
316+ }
299317
300318 /******* Internal Helper Functions *******/
301319
@@ -442,7 +460,7 @@ class GoDice {
442460 const diceCurrentNumber = this . getDieValue ( data , 1 ) ;
443461 const xyzArray = this . getXyzFromBytes ( data , 1 )
444462 this . rolledValue = diceCurrentNumber ;
445- this . onStable ( deviceId , diceCurrentNumber , xyzArray ) ;
463+ this . onStable ( deviceId , diceCurrentNumber , xyzArray ) ;
446464 }
447465
448466 if ( firstByte === 70 && secondByte === 83 ) {
0 commit comments