@@ -237,6 +237,7 @@ class GoDice {
237237 onTiltStable ( ) { } ;
238238 onMoveStable ( ) { } ;
239239 onDiceConnected ( ) { } ;
240+ onDiceDisconnected ( ) { } ;
240241
241242 /******* API functions *******/
242243
@@ -271,8 +272,11 @@ class GoDice {
271272 } )
272273 . then ( device => {
273274 this . GlobalDeviceId = device . id . toString ( ) ;
274- this . bluetoothDevice = device ;
275- this . bluetoothDevice . addEventListener ( 'gattserverdisconnected' , this . onDisconnected ) ;
275+ this . bluetoothDevice = device ;
276+ var _self = this
277+ this . bluetoothDevice . addEventListener ( 'gattserverdisconnected' , function ( ) {
278+ _self . onDiceDisconnected ( _self . GlobalDeviceId , _self )
279+ } )
276280 this . connectDeviceAndCacheCharacteristics ( ) ;
277281 } ) ;
278282 }
@@ -300,17 +304,19 @@ class GoDice {
300304 }
301305
302306 /**
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- */
307+ * Pulses LEDs for set time and color
308+ * @param {number } pulseCOunt - an integer of how many times the pulse will repeat (max 255)
309+ * @param {number } onTime - how much time should the LED be on each pulse (units of 10ms, max 255)
310+ * @param {number } offTOme - how much time should the LED be off each pulse (units of 10ms, max 255)
311+ * @param {Array } RGB - an array to control both LEDs color's in the following format '[R, G, B]'
312+ * where R, G and B are number in the range of 0-255
313+ */
310314 pulseLed ( pulseCount , onTime , offTime , RGB ) {
315+ // first boolean - isMix
316+ // second boolean - onlyOneLED
311317 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 ]
318+ let adjRGB = RGB . map ( ( i ) => Math . max ( Math . min ( i , 255 ) , 0 ) ) ;
319+ const messageArray = [ this . messageIdentifiers . SET_LED_TOGGLE , pulseCount , onTime , offTime , ...adjRGB , 1 , 0 ]
314320 this . sendMessage ( messageArray ) ;
315321 }
316322 }
@@ -524,6 +530,7 @@ class GoDice {
524530 . then ( _ => {
525531 console . debug ( 'onDiceConnected' ) ;
526532 this . onDiceConnected ( this . GlobalDeviceId , this ) ;
533+ console . log ( this )
527534 } )
528535 . catch ( error => {
529536 console . error ( 'Argh! ' + error ) ;
@@ -548,7 +555,4 @@ class GoDice {
548555 this . bluetoothDevice = null ;
549556 }
550557
551- onDisconnected ( event ) {
552- console . debug ( '> Bluetooth Device disconnected:' + event ) ;
553- }
554558}
0 commit comments