Client Virtuel : Gestion de la board avec les 'chips', à terminer

This commit is contained in:
xdrm-brackets 2016-07-19 12:52:14 +02:00
parent 541849fcf2
commit 2f6c09dbae
2 changed files with 30 additions and 37 deletions

View File

@ -21,7 +21,7 @@
public static function getForChip($id_chip){
$req = Database::getPDO()->prepare("SELECT s.state, pm.id_chip, GROUP_CONCAT(s.value) as pin_values
FROM state as s, pin_merge as pm
FROM state as s, (SELECT * FROM pin_merge ORDER BY pin ASC) as pm
WHERE s.id_pin_merge = pm.id_pin_merge
AND pm.id_chip = :id_chip
GROUP BY s.state, pm.id_chip");

View File

@ -255,17 +255,17 @@
/* (5) On initialise la carte + les puces */
var board = new Board(50);
var chip = {
var CHIP = {
led: new LedInterface( new Chip('serial', [1, 2, 3]), led ),
r1: new RelayInterface( new Chip('serial', [4]), r1 ),
r2: new RelayInterface( new Chip('serial', [5]), r2 )
};
var chipList = Object.keys(chip);
var chipList = Object.keys(CHIP);
// Branchement des puces
for( var i = 0 ; i < chipList.length ; i++ )
board.plug( chip[chipList[i]] );
board.plug( CHIP[chipList[i]] );
/* [1] Fonctions
@ -274,44 +274,37 @@
---------------------------------------------------------*/
function updateChips(){
var STATES = lsi.export('STATES.CNF');
var CHIPS = lsi.export('CHIPS.CNF');
/* (1) On vérifie si état correspond */
/* (1) On vérifie quel é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]);
/* (2) Si l'état correspond */
if( previous(STATES[s].global_state, STATE) ){
console.log('STATE', STATE, 'matches', STATES[s].global_state);
/* (3) On applique l'état à chaque CHIP */
for( var c in CHIPS ){
/* (4) Si la puce a bien cet été de défini */
if( !CHIPS[c].states.hasOwnProperty(STATES[s].chips[c]) )
break;
/* (5) On récupère les PIN + les VALUES */
var pins = CHIPS[c].pins;
var values = CHIPS[c].states[STATES[s].chips[c]];
/* (6) On applique les valeurs */
for( var p in pins )
board.set( parseInt(pins[p]), parseInt(values[p]) );
}
console.log('---');
/* (1) Si machine bloquée */
if( STATE[2] ){
STATE[0] = false;
STATE[1] = false;
led.style.background = '#f00';
break;
}
/* (2) Si machine allumée */
else if( STATE[0] ){
// {1} Allumée + signalée //
if( STATE[1] )
led.style.background = '#00f';
// {2} Allumée (non signalée) //
else
led.style.background = '#0f0';
}else
led.style.background = '#000';
if( STATE[0] == true )
r1.addClass('active');
else
r1.remClass('active');
}
}