#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <avr/io.h>
#include <avr/eeprom.h>

#include "lcd.h"
#include "auto_track.h"
#include "rotor.h"
#include "main.h"

extern FILE lcd_out;
void update_display(void){

    lcd_gotoxy(0, 0);

    switch(mode){
    case CALIBRATE:
        fprintf(&lcd_out, "* CALIBRATING * ");
        fprintf(&lcd_out, "CAL AP=%2.d EP=%2.d ",
                            az_rotor.pulse_count,
                            el_rotor.pulse_count
                            );
        break;
    case MANUAL:
        fprintf(&lcd_out, "AZ=%3.d EL=%3.d %c%c",
                      az_rotor.bearing,
                      el_rotor.bearing,
                      az_rotor.calibrated,
                      el_rotor.calibrated);
        fprintf(&lcd_out, "MAN AP=%2.d EP=%2.d ",
                            az_rotor.pulse_count,
                            el_rotor.pulse_count
                            );
        break;
    case INITIALIZE:
        fprintf(&lcd_out, "INI AP=%2.d EP=%2.d ",
                            az_rotor.pulse_count,
                            el_rotor.pulse_count
                            );
        break;
    case IDLE:
        break;
    case AUTO:
        fprintf(&lcd_out, "AZ=%3.d EL=%3.d %c%c",
                      az_rotor.bearing,
                      el_rotor.bearing,
                      az_rotor.calibrated,
                      el_rotor.calibrated);
         lcd_gotoxy(0, 1);
        fprintf(&lcd_out, "%8s %3.d %3.d",
                            sat_name[0]==0?"AUTO":sat_name,
                            az_rotor.auto_bearing,
                            el_rotor.auto_bearing
                            );
        break;
    case DETECT:
        fprintf(&lcd_out, "DETECT   ROTORS ");    
        if(az_rotor.type == 'P')
            fprintf(&lcd_out, "AZ - OK ");
            else fprintf(&lcd_out, "AZ - ND");
        if(el_rotor.type == 'P')
            fprintf(&lcd_out, "EL - OK ");
            else fprintf(&lcd_out, "EL - ND");
        break;
    }
}
