SMMP/public_html/test/client/lib-min.js

9 lines
2.8 KiB
JavaScript
Executable File

var Pin;(function(){Pin=function(a){parseInt(a)==a&&0<=a&&255>=a?this.value=parseInt(a):this.value=0};Pin.prototype={value:this.value};Pin.prototype.set=function(a){parseInt(a)==a&&0<=a&&255>=a&&(this.value=parseInt(a))};Pin.prototype.get=function(){return this.value}})();var Board;
(function(){Board=function(a){if(!(parseInt(a)!=a||1>a)){this.maxPin=a;this.pins=[];this.listener=[];for(a=0;a<this.maxPin;a++)this.pins[a]=!1;this.listener[a]=null}};Board.prototype={maxPin:this.maxPin,pins:this.pins,listener:this.listener};Board.prototype.plug=function(a){if(!(a.chip instanceof Chip))return!1;for(var b=0;b<a.chip.pins.length;b++)if(this.pins[a.chip.pins[b]]instanceof Pin)return!1;for(b=0;b<a.chip.pins.length;b++)this.pins[a.chip.pins[b]]=a.chip.values[b],this.listener[a.chip.pins[b]]=
a};Board.prototype.set=function(a,b){if(!(parseInt(a)!=a||a>this.maxPin)&&this.pins[a]instanceof Pin){if("boolean"==typeof b)b=b?255:0;else if(b!=parseInt(b)||0>b||255<b)return;b=parseInt(b);this.pins[a].set(b);"function"===typeof this.listener[a].update&&this.listener[a].update()}}})();var Chip;
(function(){Chip=function(a,b){if("string"==typeof a&&(a=a.toLowerCase(),-1!=["spi","i2c","serial"].indexOf(a)&&b instanceof Array)){for(var c=0;c<b.length;c++)if(parseInt(b[c])!=b[c])return;this.type=a;this.pins=b;this.values=[];for(c=0;c<this.pins.length;c++)this.values[c]=new Pin(0)}};Chip.prototype={type:this.type,pins:this.pins,values:this.values};Chip.prototype.setPin=function(a,b){if(!(parseInt(a)!=a||this.pins.length>=a)){if("boolean"==typeof b)b=b?255:0;else if(b!=parseInt(b)||0>b||255<b)return;
b=parseInt(b);this.values[a].set(b)}};Chip.prototype.setPins=function(a){for(var b=0;b<this.pins.length;b++)this.setPin(b,a[b])};Chip.prototype.getPin=function(a){return parseInt(a)!=a||this.pins.length<=a?!1:this.values[a].get()};Chip.prototype.getPins=function(){for(var a=[],b=0;b<this.pins.length;b++)a[b]=this.getPin(b);return a}})();var LedInterface;
(function(){LedInterface=function(a,b){a instanceof Chip&&b instanceof Element&&(this.chip=a,this.container=b)};LedInterface.prototype={chip:this.chip,container:this.container};LedInterface.prototype.update=function(){this.container.style.backgroundColor="rgb("+this.chip.getPin(0)+","+this.chip.getPin(1)+","+this.chip.getPin(2)+")"}})();var RelayInterface;
(function(){RelayInterface=function(a,b){a instanceof Chip&&b instanceof Element&&(this.chip=a,this.container=b)};RelayInterface.prototype={chip:this.chip,container:this.container};RelayInterface.prototype.update=function(){1<this.chip.getPin(0)?this.container.addClass("active"):this.container.remClass("active")}})();var previous,action;
(function(){previous=function(a,b){console.warn(a);a=a.toLowerCase();for(var c=0;c<a.length;c++)if("x"!=a[c]&&a[c]!=b[c])return!1;return!0};action=function(a,b){a=a.toLowerCase();for(var c=0;c<a.length;c++)"x"!=a[c]&&(b[c]=parseInt(a[c]))}})();