Client Virtuel : Gestion par 'machineDefault/init' des 'actions' + des 'states'

This commit is contained in:
xdrm-brackets 2016-07-19 12:26:18 +02:00
parent 4131fe8dfd
commit 945d1d3a22
3 changed files with 37 additions and 10 deletions

View File

@ -219,7 +219,7 @@
/* [0] Initialisation et éléments
=========================================================*/
/* (1) Etats du système */
var STATE = [ false, false, false ];
var STATE = [ 0, 0, 0 ];
/* (2) Elements du DOM */
var mBox = document.getElementById('machine-box');
@ -273,6 +273,19 @@
/* (1) Gestion de mise à jour de la led en fonction de l'état
---------------------------------------------------------*/
function updateChips(){
var STATES = lsi.export('STATES.CNF');
/* (1) On vérifie si état correspond */
for( var s in STATES ){
if( previous(STATES[s].global_state, STATE) )
console.log('matches', STATES[s]);
else
console.log('no matches', STATES[s]);
}
console.log('---');
/* (1) Si machine bloquée */
if( STATE[2] ){
STATE[0] = false;
@ -329,20 +342,34 @@
/* [4] Passage de carte
=========================================================*/
var INTERVAL = null;
var COUNT = 0;
var ACTIONS = lsi.export('ACTIONS.CNF');
var INTERVAL = null;
var COUNT = 0;
var ACTIONS = lsi.export('ACTIONS.CNF');
/* (0) Routine de comptage de temps
---------------------------------------------------------*/
function countRoutine(){
COUNT++;
/* (1) Si le TIMEOUT actuel n'est pas défini, on quitte */
var exists = false;
for( var t in Object.keys(ACTIONS) )
if( t == COUNT ) exists = true;
if( COUNT == 1 ) STATE[0] = !STATE[0];
if( COUNT == 2 ) STATE[0] = STATE[1] = true;
if( COUNT == 3 ) STATE[2] = true;
// Si aucune action pour ce timeout, on quitte
if( !exists ) return;
/* (2) Pour chaque action de ce timeout */
for( var a in Object.keys(ACTIONS[COUNT]) ){
/* (3) Si la condition est correcte, On applique la modification de l'état */
if( previous(ACTIONS[COUNT][a].previous, STATE) ){
action(ACTIONS[COUNT][a].action, STATE);
break;
}
}
updateChips();
COUNT++;
}
/* (1) Appui carte

View File

@ -5,4 +5,4 @@ b){if(!(parseInt(a)!=a||a>this.maxPin)&&this.pins[a]instanceof Pin){if("boolean"
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(){this.chip.pin[0]?this.container.addClass("active"):this.container.remClass("active")}})();var previous,action;
(function(){previous=function(a,b){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]))}})();
(function(){previous=function(a,b){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]=a[c])}})();

View File

@ -382,7 +382,7 @@ var action;
for( var i = 0 ; i < action.length ; i++ )
if( action[i] == 'x' ) continue;
else state[i] = parseInt(action[i]);
else state[i] = action[i];
};
})();