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 b126878..8c55146 100644 --- a/index.html +++ b/index.html @@ -1,18 +1,20 @@ - + - Easy Programming - RGBW Lights - - + + + + +
+
+
+
+
+
@@ -30,6 +37,20 @@
+
+
+ +
+
+ +
+
+ +
+
+ +
+
\ No newline at end of file diff --git a/script.js b/script.js index 944b38a..23498e7 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 @@ -12,6 +14,8 @@ $(document).ready(function() { getLEDStatus('rgb'); getLEDStatus('white'); + let slider = document.getElementById('slider'); + const pickr = Pickr.create({ el: '.color-picker', theme: 'classic', // or 'monolith', or 'nano' @@ -21,11 +25,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)', ], @@ -52,13 +60,60 @@ $(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]); + slider.noUiSlider.set(100); // sets slider value to 100 if color is changed manually + $('.noUi-connect').css('background', `rgb(${currentColors.red}, ${currentColors.green}, ${currentColors.blue}`); + } else { + rgbBrightnessChange = false; + } sendData(e); }); + + noUiSlider.create(slider, { + behavior: "tap", + start: [100], + connect: [true, false], + // direction: 'rtl', + step: 5, + range: { + 'min': [25], + 'max': [100] + }, + pips: { + mode: 'values', + values: [25, 50, 75, 100], + density: 7, + format: wNumb({ + decimals: 0, + postfix: "%" + }) + } + }); + + slider.noUiSlider.on('set', function(e) { + let sliderVal = (slider.noUiSlider.get()/100); + console.log(sliderVal); + let newRed = Math.floor(currentColors.red * sliderVal); + let newGreen = Math.floor(currentColors.green * sliderVal); + let newBlue = Math.floor(currentColors.blue * sliderVal); + 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){ let obj = e.toRGBA(); let red = Math.floor(obj[0]); @@ -73,30 +128,55 @@ $(document).ready(function() { cache: false, success: function (result) { console.log(result); + console.log(currentColors); } }); } $('#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() { @@ -117,7 +197,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(); diff --git a/style.css b/style.css index f7c8351..b1d65fb 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; @@ -52,4 +58,8 @@ body { height: 5em !important; width: 5em !important; box-shadow: 10px 15px 15px 0 rgba(0,0,0,0.33), 0 6px 8px 0 rgba(0,0,0,0.19); -} \ No newline at end of file +} + +#slider { + margin: 0 7px; +}