Client Virtuel : Gestion par 'machineDefault/init' des 'actions' + des 'states'
This commit is contained in:
parent
053e8a8e5e
commit
541849fcf2
|
@ -219,7 +219,7 @@
|
||||||
/* [0] Initialisation et éléments
|
/* [0] Initialisation et éléments
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
/* (1) Etats du système */
|
/* (1) Etats du système */
|
||||||
var STATE = [ false, false, false ];
|
var STATE = [ 0, 0, 0 ];
|
||||||
|
|
||||||
/* (2) Elements du DOM */
|
/* (2) Elements du DOM */
|
||||||
var mBox = document.getElementById('machine-box');
|
var mBox = document.getElementById('machine-box');
|
||||||
|
@ -273,6 +273,19 @@
|
||||||
/* (1) Gestion de mise à jour de la led en fonction de l'état
|
/* (1) Gestion de mise à jour de la led en fonction de l'état
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
function updateChips(){
|
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 */
|
/* (1) Si machine bloquée */
|
||||||
if( STATE[2] ){
|
if( STATE[2] ){
|
||||||
STATE[0] = false;
|
STATE[0] = false;
|
||||||
|
@ -329,20 +342,34 @@
|
||||||
|
|
||||||
/* [4] Passage de carte
|
/* [4] Passage de carte
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
var INTERVAL = null;
|
var INTERVAL = null;
|
||||||
var COUNT = 0;
|
var COUNT = 0;
|
||||||
var ACTIONS = lsi.export('ACTIONS.CNF');
|
var ACTIONS = lsi.export('ACTIONS.CNF');
|
||||||
|
|
||||||
/* (0) Routine de comptage de temps
|
/* (0) Routine de comptage de temps
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
function countRoutine(){
|
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];
|
// Si aucune action pour ce timeout, on quitte
|
||||||
if( COUNT == 2 ) STATE[0] = STATE[1] = true;
|
if( !exists ) return;
|
||||||
if( COUNT == 3 ) STATE[2] = true;
|
|
||||||
|
/* (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();
|
updateChips();
|
||||||
|
COUNT++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (1) Appui carte
|
/* (1) Appui carte
|
||||||
|
|
|
@ -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;
|
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(){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(){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])}})();
|
||||||
|
|
|
@ -382,7 +382,7 @@ var action;
|
||||||
|
|
||||||
for( var i = 0 ; i < action.length ; i++ )
|
for( var i = 0 ; i < action.length ; i++ )
|
||||||
if( action[i] == 'x' ) continue;
|
if( action[i] == 'x' ) continue;
|
||||||
else state[i] = parseInt(action[i]);
|
else state[i] = action[i];
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue