// Porte cycle (changement l'etat de sortie toutes les secondes si une des entrees est "On"), herite de Composant
public class Cycle extends Composant {
	
	static int n = 1;
	
	public Cycle(int n_in, int n_out){
		super(n_in, n_out);
		charName 	  = "C1";
		composantName = "Cycle";
		Name		  = "Cycle_"+(n++);
	}
	
	Thread thr = null;
	@SuppressWarnings("deprecation") // thr.stop(), pas important
	protected void doWork() {
		boolean state = false;
		for(Pin pin : pin_in)
			if(pin.isOn()){ state = true; break; }
		if(state){
			if(thr==null){
				final boolean fstate = state;
				thr = new Thread(){public void run(){
					boolean active = false;
					try {
						while(true){
							active = !active;
							for(Pin pin : pin_out)
								pin.setState(active&&fstate);
							Thread.sleep(1000);
						}
					} catch (InterruptedException e) {thr=null;}
				}};
				thr.start();
			}
		}else{
			if(thr!=null){ thr.stop(); thr = null; }
			for(Pin pin : pin_out)
				pin.setState(false);
		}
	}

	
	@SuppressWarnings("deprecation")
	public void Dispose(){
		if(isDisposed()) return;
		super.Dispose();
		if(thr != null){
			thr.stop(); // Thread pas critique
			thr = null;
		}
	}
}
