Hi!
I had time to implement the keyboard, and distance. Code is below, project is almost complete, route calculation is not working yet.
#include <TVout.h>
#include <math.h>
#include "NMEAGPS.h"
#include "pollserial/pollserial.cpp"
#include "TVoutfonts/font6x8.cpp"
#include <Keypad.h>
#define NEO6M_DISABLE(m) F("PUBX,40," #m ",0,0,0,0,0,0")
#define NEO6M_ENABLE(m) F("PUBX,40," #m ",0,1,0,0,0,0")
//DÉFINITION DU CLAVIER
const byte ROWS = 1; //one row
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'3','4','1','2'},
};
byte rowPins[ROWS] = {3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
int menu = 0; //menu reference (0=temp 1=radar 2=gpsinfo 3=gpstarget)
int index = 0; //index of the menu
int po = 0; //position du curseur
char customKey;
float clat,clon =0;
int mclat[14] ={1,0,5,1,5,9,7,0,5,2,6,5,0,2};
const float R = 6371.0088; // radius earth in Km
float a,c,dist,haverDLat,haverDLon,dLat,dLon,lat1,long1,lat2,long2,route;
int routei, routed;
NMEAGPS gps;
TVout TV;
pollserial pserial;
volatile bool vbi = false;
void setVBIflag()
{
vbi = true;
}
const char *banner = "NTSC NeoGPS\n-- Version 0.1 --";
void setup() {
Serial.begin( 9600 );
// Serial.println( banner );
// Serial.println( F("Date/Time,CS errors") );
// Serial.flush();
pt2Funct fn = pserial.begin(9600); // save the return value for later
// Turn off the other NMEA sentences, they're wasting our time
gps.send_P( &pserial, NEO6M_DISABLE(GLL) );
gps.send_P( &pserial, NEO6M_DISABLE(GSA) );
gps.send_P( &pserial, NEO6M_DISABLE(GSV) );
gps.send_P( &pserial, NEO6M_DISABLE(VTG) );
// Turn on these two
gps.send_P( &pserial, NEO6M_ENABLE(RMC) );
gps.send_P( &pserial, NEO6M_ENABLE(GGA) );
TV.begin(_NTSC,184,72);
TV.set_hbi_hook(pserial.begin(9600));
TV.set_vbi_hook( setVBIflag );
TV.select_font(font6x8);
// TV.println( banner );
TV.set_hbi_hook(pserial.begin(9600));
// TV.print("HEURE GMT: : : Sat:\nLatitude: \nLongitude: \nAltitude: Cap:"); // the static labels
}
void loop() {
clat=mclat[1]*10+mclat[2]+mclat[3]*0.1+mclat[4]*0.01+mclat[5]*0.001+mclat[6]*0.0001;
if((mclat[0]%2)<=0)
{
clat=-clat;
}
lat2=clat;
clon=mclat[8]*10+mclat[9]+mclat[10]*0.1+mclat[11]*0.01+mclat[12]*0.001+mclat[13]*0.0001;
if((mclat[7]%2)<=0)
{
clon=-clon;
}
long2=clon;
customKey = customKeypad.getKey();
if(customKey=='1'){
po = po+1;
index = 0;
if(po>14)
{
po = 0;
}
}
else
if(customKey=='2')
{
index = index+1;
if(index > 9)
{index = 0;}
}
else
if(customKey=='3'){
menu = menu+1;
index = 0;
if( menu > 4){menu = 0;};
}
mclat[po-1]=index;
if (gps.available( pserial )) {
gps_fix fix = gps.read();
while (!vbi)
;
vbi = false;
TV.print(0,0,"HEURE GMT: : : Sat:\nLatitude: \nLongitude: \nAltitude: Cap:\n TARGET\n\n\n\n"); // the static labels
TV.set_cursor( 11*6, 0*8 );
if (fix.dateTime.hours < 10)
TV.write( '0' );
TV.print( fix.dateTime.hours , DEC );
TV.set_cursor( 14*6, 0*8 );
if (fix.dateTime.minutes < 10)
TV.write( '0' );
TV.print(fix.dateTime.minutes, DEC );
TV.set_cursor( 17*6, 0*8 );
if (fix.dateTime.seconds < 10)
TV.write('0');
TV.print( fix.dateTime.seconds, DEC );
TV.set_cursor (28*6,0*8);
if (fix.satellites < 10)
TV.write(' ');
TV.print(fix.satellites, DEC );
TV.print( 11*6, 1*8, fix.latitude(), 4);
lat1=(fix.latitude());
TV.print( 11*6, 2*8, fix.longitude(),4);
long1=(fix.longitude());
TV.print( 11*6, 3*8, fix.altitude(),0 );
//Target latitude
TV.set_cursor( 0*6, 5*8);
if((mclat[0]%2)!=0){
TV.print("+");}
else
TV.print("-");
TV.set_cursor( 1*6, 5*8);
TV.print(mclat[1]);
TV.print(mclat[2]);
TV.print(".");
TV.print(mclat[3]);
TV.print(mclat[4]);
TV.print(mclat[5]) ;
TV.print(mclat[6]) ;
//Target Longitude
TV.set_cursor( 11*6, 5*8);
if((mclat[7]%2)!=0){
TV.print("+");}
else
TV.print("-");
TV.set_cursor( 12*6, 5*8);
TV.print(mclat[8]);
TV.print(mclat[9]);
TV.print(".");
TV.print(mclat[10]);
TV.print(mclat[11]);
TV.print(mclat[12]) ;
TV.print(mclat[13]) ;
distance();
}
}
void distance(){
dLat = ((lat2*PI/180)-(lat1*PI/180));
haverDLat = sin(dLat/2.0);
haverDLat *= haverDLat; // squared
dLon = ((long2-long1)*PI/180);
haverDLon = sin(dLon/2.0);
haverDLon *= haverDLon; // squared
a = haverDLat + cos(lat1*PI/180) * cos(lat2*PI/180) * haverDLon;
c = 2 * atan2( sqrt(a), sqrt(1-a) );
dist = R * c;
TV.set_cursor(0*6, 6*8);
if (dist < 1000)
TV.print(" ");
if (dist < 100)
TV.print(" ");
if (dist < 10)
TV.print(" ");
TV.print(dist,0);
TV.print(5*6,6*8," km");
/* //Route calculation, not working yet
route=atan2(cos(lat1*PI/180)*sin(lat2*PI/180)-sin(lat1*PI/180)*cos(lat2*PI/180)*cos(long2*PI/180-long1*PI/180),sin(long2*PI/180-long1*PI/180)*cos(lat2*PI/180)) ;
TV.set_cursor(18*6, 6*8);
routei= route/PI*180;
Serial.println(routei);
routed=(-routei+90) % 360;
Serial.println(routed);
TV.print(routed);
TV.print(" deg");
*/
}
As I will implement another menu (temperature monitoring and maybe ultrasonic radar when button 3 is pressed), I had to remove the tags in the setup.
Only the time and the altitude are blinking once a second