package fietsv1;
import stamp.core.*;
import stamp.peripheral.display.lcd.serial.BPI216;
import fietsv1.*;
import stamp.util.text.Format;

/**
 * Display for the bikecomputer
 *
 *
 * @version 1.0 28-05-06
 * @author Johnny Kuiper
 */

public class Display {

  private final static int LCDPIN = CPU.pin15;
  private static Uart txOut = new Uart( Uart.dirTransmit, LCDPIN, Uart.invert,Uart.speed9600, Uart.stop1);
  private Processor proc2;
  private static char[] textSpeed = new char[5];
  private static char[] textDistance = new char[8];
  private static char[] textChrono = new char[8];
  private static char[] textAverage = new char[5];
  private int a;

  public Display() {
    proc2 = new Processor();
    proc2.setCircumference(18);
  }

  public void formatSpeed(){
    a=0;
    a = Format.bprintf(textSpeed,a,"%0d.",proc2.calculateSpeed()/10);
    a = Format.bprintf(textSpeed,a,"%d",proc2.calculateSpeed()%10);
    textSpeed[a]=0;
  }

  public void formatDistance(){
    a=0;
    a = Format.bprintf(textDistance,a,"%0d.",proc2.getDistanceKm());
    a = Format.bprintf(textDistance,a,"%d",proc2.getDistanceM());
    textDistance[a]=0;
  }

  public void formatChrono(){
    a=0;
    a = Format.bprintf(textChrono,a,"%0d:",proc2.getChronoHours());
    a = Format.bprintf(textChrono,a,"%0d:",proc2.getChronoMinutes());
    a = Format.bprintf(textChrono,a,"%0d",proc2.getChronoSeconds());
    textChrono[a]=0;
  }

  public void formatAverage(){
    a=0;
    a = Format.bprintf(textAverage,a,"%0d.",proc2.calculateAverage()/10);
    a = Format.bprintf(textAverage,a,"%d",proc2.calculateAverage()%10);
    textAverage[a]=0;
  }
} 