/* LCD formatting */
/* Steven J. Merrifield, July 2005 */

#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/signal.h>
#include <sys/types.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <math.h>
#include "gps.h"
#include "lcd.h"

extern char * process(char *);
extern int grid_square(double, double);
extern char * process_date_str(char *);
extern char * process_time_str(char *);
extern float process_lat_decdeg(void);
extern char * process_lat_degminsec(char *);
extern float process_lon_decdeg(void);
extern char * process_lon_degminsec(char *);
extern void LCDWriteStr(char *);
extern void LCDClrScr(void);
extern void LCDLine(int);

extern char Estr[20];
extern char Nstr[20];
extern char GRStr[20];
extern int zone;


/*************************************************************/
void LCDScreen0(void)
{
	LCDClrScr();
	LCDLine(1);
	LCDWriteStr("  uClinux GPS");
	LCDLine(2);
	LCDWriteStr("   v 1.0, by");
	LCDLine(3);
	LCDWriteStr("     Steven");
	LCDLine(4);
	LCDWriteStr("   Merrifield");
}

/*************************************************************/
void LCDScreen1(void)
{
	char data[NMEA_LINE];
	char s[20];

	LCDClrScr();

	LCDLine(1);
	if (gga.Fix != 1)
		strcpy(data,"Invalid");
	else
		strcpy(data,"Valid");
	sprintf(s,"Sig: %s",data);
	LCDWriteStr(s);

	LCDLine(2);
	sprintf(s, "Satellites: %d",gga.NumSats);
	LCDWriteStr(s);

	LCDLine(3);
	sprintf(s,"Time: %s",process_time_str(data));
	LCDWriteStr(s);

	LCDLine(4);
	sprintf(s,"Date: %s",process_date_str(data));
	LCDWriteStr(s);
}


/*************************************************************/
void LCDScreen2(void)
{
	char s[20];

        grid_square(process_lat_decdeg(),process_lon_decdeg());

	LCDClrScr();

	LCDLine(1);
	sprintf(s,"E: %s",Estr);
	LCDWriteStr(s);

	LCDLine(2);
	sprintf(s,"N: %s",Nstr);
	LCDWriteStr(s);

	LCDLine(3);
	sprintf(s, "AMG ZONE: %d",zone);
	LCDWriteStr(s);

	LCDLine(4);
	sprintf(s, "GRID: %s",GRStr);
	LCDWriteStr(s);
}

/*************************************************************/
void LCDScreen3(void)
{
	char s[20];

	LCDClrScr();

	LCDLine(1);
	sprintf(s,"Height: %1.1fm",gga.Alt);
	LCDWriteStr(s);

	LCDLine(2);
	sprintf(s, "Speed: %1.1fkm/h",rmc.Speed*1.852);
	LCDWriteStr(s);

	LCDLine(3);
	sprintf(s, "Heading: %1.1f%c ",rmc.Heading,DEG);
	LCDWriteStr(s);
}

/*************************************************************/
void LCDScreen4(void)
{
	char data[NMEA_LINE];
	char s[20];

	LCDClrScr();

	LCDLine(1);
	LCDWriteStr("Longitude:");

	LCDLine(2);
	sprintf(s,"%f",process_lon_decdeg());
	LCDWriteStr(s);

	LCDLine(3);
	sprintf(s, "%s %c",process_lon_degminsec(data),gga.EW);
	LCDWriteStr(s);
}
	
/*************************************************************/
void LCDScreen5(void)
{
	char data[NMEA_LINE];
	char s[20];

	LCDClrScr();

	LCDLine(1);
	LCDWriteStr("Latitude:");

	LCDLine(2);
	sprintf(s,"%f",process_lat_decdeg());
	LCDWriteStr(s);

	LCDLine(3);
	sprintf(s, "%s %c",process_lat_degminsec(data),gga.NS);
	LCDWriteStr(s);
}

