From 9aeb87dcb0a697a271cba6df33a1c715a030e2c0 Mon Sep 17 00:00:00 2001 From: Nazmus Nasir Date: Thu, 31 Oct 2019 23:52:20 -0400 Subject: [PATCH 1/5] localized dependencies --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index b126878..74f1f9e 100644 --- a/index.html +++ b/index.html @@ -5,8 +5,8 @@ Easy Programming - RGBW Lights - - + + From 639fed1c79f9a24bb690ae97ff8cdbd9fa83fa7e Mon Sep 17 00:00:00 2001 From: Nazmus Nasir Date: Thu, 31 Oct 2019 23:52:32 -0400 Subject: [PATCH 2/5] added more colors to pallette --- script.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/script.js b/script.js index 944b38a..9d99efd 100644 --- a/script.js +++ b/script.js @@ -21,11 +21,15 @@ $(document).ready(function() { swatches: [ 'rgba(255, 0, 0, 1)', + 'rgba(255, 82, 0, 1)', 'rgba(0, 255, 0, 1)', 'rgba(0, 0, 255, 1)', + 'rgba(27, 161, 17, 1)', 'rgba(255, 255, 0, 1)', // yellow broken 'rgba(255, 0, 255, 1)', + 'rgba(108, 16, 157, 1)', 'rgba(0, 255, 255, 1)', + 'rgba(24, 139, 167, 1)', 'rgba(255, 255, 255, 1)', 'rgba(0, 0, 0, 1)', ], From 8480b3ff905e31a85b3d0d1dd1d03aee2a5cc8e8 Mon Sep 17 00:00:00 2001 From: Nazmus Nasir Date: Fri, 1 Nov 2019 01:04:01 -0400 Subject: [PATCH 3/5] white led brightness working --- index.html | 22 +++++++++++++++++++++- script.js | 46 ++++++++++++++++++++++++++++++++++++++++------ style.css | 6 ++++++ 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 74f1f9e..054d68c 100644 --- a/index.html +++ b/index.html @@ -21,15 +21,35 @@
-
+
+ + + + + +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
\ No newline at end of file diff --git a/script.js b/script.js index 9d99efd..fb781c5 100644 --- a/script.js +++ b/script.js @@ -63,6 +63,16 @@ $(document).ready(function() { sendData(e); }); + $(".rgbBrightness").on('click', function (e) { + console.log($(this).val()); + let newRed = Math.floor(pickr.getColor().toRGBA()[0] * ($(this).val())); + let newGreen = Math.floor(pickr.getColor().toRGBA()[1] * ($(this).val())); + let newBlue = Math.floor(pickr.getColor().toRGBA()[2] * ($(this).val())); + console.log(newRed, newGreen, newBlue); + pickr.setColor(`rgb(${newRed}, ${newGreen}, ${newBlue})`); + console.log(pickr.getColor().toRGBA().toString()); + }); + function sendData(e){ let obj = e.toRGBA(); let red = Math.floor(obj[0]); @@ -82,25 +92,49 @@ $(document).ready(function() { } $('#btnToggle').on('click', function(e){ - - // let state; if(whiteStatus == 0) { whiteStatus = Math.floor(255); } else { whiteStatus = 0; } - //right + changeWhiteLed(whiteStatus); + e.preventDefault(); + }); + + $('.whiteBrightness').on('click', function(e){ + let freq = 0; + switch ($(this).val()) { + case '25': + freq = 64; + break; + case '50': + freq = 128; + break; + case '75': + freq = 192; + break; + case '100': + freq = 255; + break; + default: + freq = 0; + break; + } + changeWhiteLed(freq); + e.preventDefault(); + }); + + function changeWhiteLed(frequency){ $.ajax({ - url: `${config.url}/api/lr/white?white=${whiteStatus}&${cacheBuster}`, + url: `${config.url}/api/lr/white?white=${frequency}&${cacheBuster}`, method: 'GET', success: function(result) { console.log(result); }, complete: btnStatus }); - e.preventDefault(); - }); + } // Main big button - uses kitchenRight for master data. function btnStatus() { diff --git a/style.css b/style.css index f7c8351..cb6863b 100644 --- a/style.css +++ b/style.css @@ -15,6 +15,12 @@ body { box-shadow: 10px 15px 15px 0 rgba(0,0,0,0.33), 0 6px 8px 0 rgba(0,0,0,0.19); } +.rgbBrightness, .whiteBrightness { + padding: 1em 0.5em; + font-size: 0.9rem; + margin-bottom: 35px; +} + #kitchenLeft, #kitchenRight { font-size: 1.5rem; padding: 0.5em 0.7em !important; From 9a828ce09907e0e46581412c20a62659ef3c579c Mon Sep 17 00:00:00 2001 From: Nazmus Nasir Date: Sat, 2 Nov 2019 01:06:42 -0400 Subject: [PATCH 4/5] buttons added for RGB Brightness control --- index.html | 22 +++++++++++++++------- script.js | 29 +++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index 054d68c..646ae60 100644 --- a/index.html +++ b/index.html @@ -21,15 +21,23 @@
-
+
- - - - - - +
+
+
+ +
+
+ +
+
+ +
+
+ +
diff --git a/script.js b/script.js index fb781c5..8a6b51a 100644 --- a/script.js +++ b/script.js @@ -3,6 +3,8 @@ let config = { }; let whiteStatus = 0; +let currentColors = {}; +let rgbBrightnessChange = false; $(document).ready(function() { // Cache buster added because caching was a big problem on mobile @@ -56,21 +58,35 @@ $(document).ready(function() { }); pickr.off().on('swatchselect', e => { - sendData(e); + // sendData(e); // Swatchselect apparently triggers save so it triggers sendData() automatically pickr.setColor(e.toRGBA().toString(0)); + + }); pickr.on('save', e => { + + // If 'save' is being triggered by brightness changes instead + if(rgbBrightnessChange == false) { + let tempColors = pickr.getColor().toRGBA(); + currentColors.red = Math.floor(tempColors[0]); + currentColors.green = Math.floor(tempColors[1]); + currentColors.blue = Math.floor(tempColors[2]); + } else { + rgbBrightnessChange = false; + } sendData(e); }); $(".rgbBrightness").on('click', function (e) { console.log($(this).val()); - let newRed = Math.floor(pickr.getColor().toRGBA()[0] * ($(this).val())); - let newGreen = Math.floor(pickr.getColor().toRGBA()[1] * ($(this).val())); - let newBlue = Math.floor(pickr.getColor().toRGBA()[2] * ($(this).val())); + let newRed = Math.floor(currentColors.red * ($(this).val())); + let newGreen = Math.floor(currentColors.green * ($(this).val())); + let newBlue = Math.floor(currentColors.blue * ($(this).val())); + rgbBrightnessChange = true; console.log(newRed, newGreen, newBlue); pickr.setColor(`rgb(${newRed}, ${newGreen}, ${newBlue})`); console.log(pickr.getColor().toRGBA().toString()); + console.log(currentColors); }); function sendData(e){ @@ -87,6 +103,7 @@ $(document).ready(function() { cache: false, success: function (result) { console.log(result); + console.log(currentColors); } }); } @@ -155,7 +172,11 @@ $(document).ready(function() { success: function(result) { if(color == 'rgb') { let colors = `rgb(${result.red}, ${result.green}, ${result.blue})`; + currentColors.red = result.red; + currentColors.green = result.green; + currentColors.blue = result.blue; pickr.setColor(colors); + console.log(currentColors); } else { whiteStatus = result.white; btnStatus(); From e58cdd3f53fdace4297cb79f903623ae696bf666 Mon Sep 17 00:00:00 2001 From: Nazmus Nasir Date: Sat, 2 Nov 2019 01:53:26 -0400 Subject: [PATCH 5/5] nUiSlider added for RGB brightness control --- includes/nouislider.min.css | 2 + includes/nouislider.min.js | 2 + includes/wNumb.js | 335 ++++++++++++++++++++++++++++++++++++ index.html | 21 +-- script.js | 41 ++++- style.css | 6 +- 6 files changed, 384 insertions(+), 23 deletions(-) create mode 100644 includes/nouislider.min.css create mode 100644 includes/nouislider.min.js create mode 100644 includes/wNumb.js diff --git a/includes/nouislider.min.css b/includes/nouislider.min.css new file mode 100644 index 0000000..ca4ed7d --- /dev/null +++ b/includes/nouislider.min.css @@ -0,0 +1,2 @@ +/*! nouislider - 14.0.3 - 10/10/2019 */ +.noUi-target,.noUi-target *{-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent;-webkit-user-select:none;-ms-touch-action:none;touch-action:none;-ms-user-select:none;-moz-user-select:none;user-select:none;-moz-box-sizing:border-box;box-sizing:border-box}.noUi-target{position:relative;direction:ltr}.noUi-base,.noUi-connects{width:100%;height:100%;position:relative;z-index:1}.noUi-connects{overflow:hidden;z-index:0}.noUi-connect,.noUi-origin{will-change:transform;position:absolute;z-index:1;top:0;left:0;-ms-transform-origin:0 0;-webkit-transform-origin:0 0;-webkit-transform-style:preserve-3d;transform-origin:0 0;transform-style:flat}.noUi-connect{height:100%;width:100%}.noUi-origin{height:10%;width:10%}html:not([dir=rtl]) .noUi-horizontal .noUi-origin{left:auto;right:0}.noUi-vertical .noUi-origin{width:0}.noUi-horizontal .noUi-origin{height:0}.noUi-handle{-webkit-backface-visibility:hidden;backface-visibility:hidden;position:absolute}.noUi-touch-area{height:100%;width:100%}.noUi-state-tap .noUi-connect,.noUi-state-tap .noUi-origin{-webkit-transition:transform .3s;transition:transform .3s}.noUi-state-drag *{cursor:inherit!important}.noUi-horizontal{height:18px}.noUi-horizontal .noUi-handle{width:34px;height:28px;left:-17px;top:-6px}.noUi-vertical{width:18px}.noUi-vertical .noUi-handle{width:28px;height:34px;left:-6px;top:-17px}html:not([dir=rtl]) .noUi-horizontal .noUi-handle{right:-17px;left:auto}.noUi-target{background:#FAFAFA;border-radius:4px;border:1px solid #D3D3D3;box-shadow:inset 0 1px 1px #F0F0F0,0 3px 6px -5px #BBB}.noUi-connects{border-radius:3px}.noUi-connect{background:#3FB8AF}.noUi-draggable{cursor:ew-resize}.noUi-vertical .noUi-draggable{cursor:ns-resize}.noUi-handle{border:1px solid #D9D9D9;border-radius:3px;background:#FFF;cursor:default;box-shadow:inset 0 0 1px #FFF,inset 0 1px 7px #EBEBEB,0 3px 6px -3px #BBB}.noUi-active{box-shadow:inset 0 0 1px #FFF,inset 0 1px 7px #DDD,0 3px 6px -3px #BBB}.noUi-handle:after,.noUi-handle:before{content:"";display:block;position:absolute;height:14px;width:1px;background:#E8E7E6;left:14px;top:6px}.noUi-handle:after{left:17px}.noUi-vertical .noUi-handle:after,.noUi-vertical .noUi-handle:before{width:14px;height:1px;left:6px;top:14px}.noUi-vertical .noUi-handle:after{top:17px}[disabled] .noUi-connect{background:#B8B8B8}[disabled] .noUi-handle,[disabled].noUi-handle,[disabled].noUi-target{cursor:not-allowed}.noUi-pips,.noUi-pips *{-moz-box-sizing:border-box;box-sizing:border-box}.noUi-pips{position:absolute;color:#999}.noUi-value{position:absolute;white-space:nowrap;text-align:center}.noUi-value-sub{color:#ccc;font-size:10px}.noUi-marker{position:absolute;background:#CCC}.noUi-marker-sub{background:#AAA}.noUi-marker-large{background:#AAA}.noUi-pips-horizontal{padding:10px 0;height:80px;top:100%;left:0;width:100%}.noUi-value-horizontal{-webkit-transform:translate(-50%,50%);transform:translate(-50%,50%)}.noUi-rtl .noUi-value-horizontal{-webkit-transform:translate(50%,50%);transform:translate(50%,50%)}.noUi-marker-horizontal.noUi-marker{margin-left:-1px;width:2px;height:5px}.noUi-marker-horizontal.noUi-marker-sub{height:10px}.noUi-marker-horizontal.noUi-marker-large{height:15px}.noUi-pips-vertical{padding:0 10px;height:100%;top:0;left:100%}.noUi-value-vertical{-webkit-transform:translate(0,-50%);transform:translate(0,-50%);padding-left:25px}.noUi-rtl .noUi-value-vertical{-webkit-transform:translate(0,50%);transform:translate(0,50%)}.noUi-marker-vertical.noUi-marker{width:5px;height:2px;margin-top:-1px}.noUi-marker-vertical.noUi-marker-sub{width:10px}.noUi-marker-vertical.noUi-marker-large{width:15px}.noUi-tooltip{display:block;position:absolute;border:1px solid #D9D9D9;border-radius:3px;background:#fff;color:#000;padding:5px;text-align:center;white-space:nowrap}.noUi-horizontal .noUi-tooltip{-webkit-transform:translate(-50%,0);transform:translate(-50%,0);left:50%;bottom:120%}.noUi-vertical .noUi-tooltip{-webkit-transform:translate(0,-50%);transform:translate(0,-50%);top:50%;right:120%} \ No newline at end of file diff --git a/includes/nouislider.min.js b/includes/nouislider.min.js new file mode 100644 index 0000000..58b8489 --- /dev/null +++ b/includes/nouislider.min.js @@ -0,0 +1,2 @@ +/*! nouislider - 14.0.3 - 10/10/2019 */ +!function(t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():window.noUiSlider=t()}(function(){"use strict";var lt="14.0.3";function ut(t){t.parentElement.removeChild(t)}function s(t){return null!=t}function ct(t){t.preventDefault()}function i(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)}function pt(t,e,r){0=e[r];)r+=1;return r}function r(t,e,r){if(r>=t.slice(-1)[0])return 100;var n,i,o=f(r,t),a=t[o-1],s=t[o],l=e[o-1],u=e[o];return l+(i=r,p(n=[a,s],n[0]<0?i+Math.abs(n[0]):i-n[0])/c(l,u))}function n(t,e,r,n){if(100===n)return n;var i,o,a=f(n,t),s=t[a-1],l=t[a];return r?(l-s)/2= 2) required for mode 'count'.");var n=e-1,i=100/n;for(e=[];n--;)e[n]=n*i;e.push(100),t="positions"}return"positions"===t?e.map(function(t){return E.fromStepping(r?E.getStep(t):t)}):"values"===t?r?e.map(function(t){return E.fromStepping(E.getStep(E.toStepping(t)))}):e:void 0}(n,t.values||!1,t.stepped||!1),s=(m=i,g=n,v=a,b={},e=E.xVal[0],r=E.xVal[E.xVal.length-1],x=S=!1,w=0,(v=v.slice().sort(function(t,e){return t-e}).filter(function(t){return!this[t]&&(this[t]=!0)},{}))[0]!==e&&(v.unshift(e),S=!0),v[v.length-1]!==r&&(v.push(r),x=!0),v.forEach(function(t,e){var r,n,i,o,a,s,l,u,c,p,f=t,d=v[e+1],h="steps"===g;if(h&&(r=E.xNumSteps[e]),r||(r=d-f),!1!==f&&void 0!==d)for(r=Math.max(r,1e-7),n=f;n<=d;n=(n+r).toFixed(7)/1){for(u=(a=(o=E.toStepping(n))-w)/m,p=a/(c=Math.round(u)),i=1;i<=c;i+=1)b[(s=w+i*p).toFixed(5)]=[E.fromStepping(s),0];l=-1r.stepAfter.startValue&&(i=r.stepAfter.startValue-n),o=n>r.thisStep.startValue?r.thisStep.step:!1!==r.stepBefore.step&&n-r.stepBefore.highestStep,100===e?i=null:0===e&&(o=null);var a=E.countStepDecimals();return null!==i&&!1!==i&&(i=Number(i.toFixed(a))),null!==o&&!1!==o&&(o=Number(o.toFixed(a))),[o,i]}return ht(e=y,f.cssClasses.target),0===f.dir?ht(e,f.cssClasses.ltr):ht(e,f.cssClasses.rtl),0===f.ort?ht(e,f.cssClasses.horizontal):ht(e,f.cssClasses.vertical),l=V(e,f.cssClasses.base),function(t,e){var r=V(e,f.cssClasses.connects);u=[],(a=[]).push(O(r,t[0]));for(var n=0;n= 0 && optionValue < 8 ) { + filteredOptions[optionName] = optionValue; + } else { + throw new Error(optionName); + } + + // These options, when provided, must be functions. + } else if ( optionName === 'encoder' || optionName === 'decoder' || optionName === 'edit' || optionName === 'undo' ) { + if ( typeof optionValue === 'function' ) { + filteredOptions[optionName] = optionValue; + } else { + throw new Error(optionName); + } + + // Other options are strings. + } else { + + if ( typeof optionValue === 'string' ) { + filteredOptions[optionName] = optionValue; + } else { + throw new Error(optionName); + } + } + } + + // Some values can't be extracted from a + // string if certain combinations are present. + throwEqualError(filteredOptions, 'mark', 'thousand'); + throwEqualError(filteredOptions, 'prefix', 'negative'); + throwEqualError(filteredOptions, 'prefix', 'negativeBefore'); + + return filteredOptions; + } + + // Pass all options as function arguments + function passAll ( options, method, input ) { + var i, args = []; + + // Add all options in order of FormatOptions + for ( i = 0; i < FormatOptions.length; i+=1 ) { + args.push(options[FormatOptions[i]]); + } + + // Append the input, then call the method, presenting all + // options as arguments. + args.push(input); + return method.apply('', args); + } + + /** @constructor */ + function wNumb ( options ) { + + if ( !(this instanceof wNumb) ) { + return new wNumb ( options ); + } + + if ( typeof options !== "object" ) { + return; + } + + options = validate(options); + + // Call 'formatTo' with proper arguments. + this.to = function ( input ) { + return passAll(options, formatTo, input); + }; + + // Call 'formatFrom' with proper arguments. + this.from = function ( input ) { + return passAll(options, formatFrom, input); + }; + } + + /** @export */ + window.wNumb = wNumb; + +}()); diff --git a/index.html b/index.html index 646ae60..8c55146 100644 --- a/index.html +++ b/index.html @@ -1,7 +1,6 @@ - + - Easy Programming - RGBW Lights @@ -13,6 +12,9 @@ + + +