import java.text.*;

public class PresThread extends Thread {
	private double pres;
	private double dac;
 	public PresThread() {
 		pres=20.0;
 	}
 	private void readPres() {
	//	dummy: should read pressure from ADC
	pres-=0.4;
	if (pres<0.0)
		pres=20.0;	
	}
	private void writeDAC() {
	//	dummy: should write to DAC
	}
	private void presConvert() {
	//	dummy: should use better algorithm
		try {
			sleep(100);
	 	} catch (InterruptedException e) {}
		dac=10.0-pres;
	}
 	synchronized public void run() {
		NumberFormat nf = NumberFormat.getInstance();
		nf.setMaximumIntegerDigits(2);
 		nf.setMinimumFractionDigits(1);
 		nf.setMaximumFractionDigits(1);
		while (true) {
			readPres();
			synchronized(System.out) {
				System.out.print("pressure = "+nf.format(pres));
				presConvert();
				System.out.println(", DAC = "+nf.format(dac));
			}
			writeDAC();
			try {
				sleep(1000);
		 	} catch (InterruptedException e) {}
		}
	}
}
