import java.io.IOException;
import jcontrol.comm.DisplayConsole;
import jcontrol.lang.ThreadExt;

/**
 * <p>LM75Test shows how to read the LM75 temperature
 * detector class of the jcontrol.bus.i2c library.</p>
 *
 * <p>(C) DOMOLOGIC Home Automation GmbH 2003-2005</p>
 */
public class LM75Test {

  /** DisplayConsole */
  DisplayConsole console;
  int deviceAddress = 0x90;

  /**
   * Application Constructor.
   */
  public LM75Test() {

    // init DisplayConsole
    console = new DisplayConsole();

    // display startup message
    console.println("LM75 Test Program.");
    console.println();
	
    LM75 lm75 = new LM75(deviceAddress);

    for (;;) {
      int temp = 0;
      for (;;) {
			  try{
          temp = lm75.getTemp();//get temperature value
        }catch(IOException e){
	        console.println("Error: Sensor not responding!");
        }
        console.print("Read: ".concat(String.valueOf(temp)));
        //temperature resolution is 1/10 centigrade
        int whole = temp/10;
        int parts = temp%10;
        console.println(" = ".concat(Integer.toString(whole))
                             .concat(".")
                             .concat(Integer.toString(parts))
                             .concat("\u00b0C"));			
        try{
          ThreadExt.sleep(500);//do nothing for 500 msecs
        }catch(InterruptedException e) {}
      }
    }
  }


  /**
   * Main method. Program execution starts here.
   */
  public static void main(String[] args) {
    new LM75Test();// start measuring
  }
}
