diff --git a/manager/repo/state.php b/manager/repo/state.php index 303d75d..2dca7c5 100644 --- a/manager/repo/state.php +++ b/manager/repo/state.php @@ -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"); diff --git a/test/client/interface.php b/test/client/interface.php index 702a4f6..4b29100 100644 --- a/test/client/interface.php +++ b/test/client/interface.php @@ -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]) ); + + } + + break; + } } - console.log('---'); - - /* (1) Si machine bloquée */ - if( STATE[2] ){ - STATE[0] = false; - STATE[1] = false; - led.style.background = '#f00'; - } - - /* (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'); - }