Fixed compiler errors in Arduino 1.6.8. Added color swatch buttons.

This commit is contained in:
Jason Coon
2016-03-12 11:28:33 -06:00
parent b9398eac51
commit 0d3d32258d
3 changed files with 91 additions and 33 deletions

View File

@ -77,6 +77,19 @@ $("#inputColor").change(function() {
delaySetColor(rgb);
});
$(".btn-color").click(function() {
if(ignoreColorChange) return;
var rgb = $(this).css('backgroundColor');
var components = rgbToComponents(rgb);
delaySetColor(components);
var hexString = rgbToHex(components.r, components.g, components.b);
ignoreColorChange = true;
$("#inputColor").minicolors('value', hexString);
ignoreColorChange = false;
});
function getAll() {
$.get(urlBase + "all", function(data) {
allData = data;
@ -163,3 +176,14 @@ function componentToHex(c) {
function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
function rgbToComponents(rgb){
var components = {};
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
components.r = parseInt(rgb[1]);
components.g = parseInt(rgb[2]);
components.b = parseInt(rgb[3]);
return components;
}