Code cleanup ++

This commit is contained in:
id101010
2015-12-03 02:39:01 +01:00
parent d0b38011d2
commit 10d7a5ee8e

View File

@@ -7,6 +7,7 @@
* ----------- * -----------
* - Arduino UNO R3 * - Arduino UNO R3
* - Ultimate GPS logger shield * - Ultimate GPS logger shield
* - 16x2 LCD Shield
* - 9V Battery * - 9V Battery
*/ */
#include <math.h> #include <math.h>
@@ -23,6 +24,7 @@ const float deg2rad = 0.01745329251994;
const float rEarth = 6371000.0; // Earths radius in meters const float rEarth = 6371000.0; // Earths radius in meters
float range = 9999; // Distance between src and pos float range = 9999; // Distance between src and pos
String destination = "N46 59.776, E007 27.771"; String destination = "N46 59.776, E007 27.771";
//String destination = "N46 55.090, E007 26.442"; // Gurten
String position = ""; // read from GPS String position = ""; // read from GPS
String tmp = ""; String tmp = "";
@@ -38,10 +40,13 @@ float lon2 = 0;
// Prototypes // Prototypes
void useInterrupt(boolean); void useInterrupt(boolean);
void print_message(String Line1, String Line2); void print_message(String Line1, String Line2);
void useInterrupt(boolean v);
/*******************************************/ void print_message(String Line1, String Line2);
//String destination = "N46 55.090, W7 26.442"; // Gurten: N 46 55.090 E 7 26.442 float haversine (float lat1, float lon1, float lat2, float lon2);
/*******************************************/ float string2lon(String position);
float string2lat(String position);
String gps2string(void);
String int2fw(int x, int n);
void setup() void setup()
{ {
@@ -79,7 +84,7 @@ void loop()
tmp = String(range); tmp = String(range);
tmp += " [m]"; tmp += " [m]";
print_message("I wand up.", tmp); print_message("Me wants up!", tmp);
} else { } else {
print_message("Hello Mischa!", "Take me outside!"); // No fix available print_message("Hello Mischa!", "Take me outside!"); // No fix available
@@ -119,7 +124,7 @@ SIGNAL(TIMER0_COMPA_vect)
{ {
char c = GPS.read(); // Read from serial input char c = GPS.read(); // Read from serial input
if (GPSECHO){ // If GPSECHO is enabled if (GPSECHO) { // If GPSECHO is enabled
if (c) { if (c) {
UDR0 = c; // Send nmea char by char UDR0 = c; // Send nmea char by char
} }
@@ -228,7 +233,7 @@ float string2lat(String position)
* Descr: returns the float representation of * Descr: returns the float representation of
* the current longitude. * the current longitude.
**************************************************/ **************************************************/
float string2lon (String position) float string2lon(String position)
{ {
// returns radians: e.g. String position = "N38 58.892, W076 29.177"; // returns radians: e.g. String position = "N38 58.892, W076 29.177";
float lon = ((position.charAt(13) - '0') * 100.0) + \ float lon = ((position.charAt(13) - '0') * 100.0) + \
@@ -256,12 +261,12 @@ float string2lon (String position)
* Descr: Calculates the distance between * Descr: Calculates the distance between
* two points given by (lat1/2 lon1/2) * two points given by (lat1/2 lon1/2)
**************************************************/ **************************************************/
float haversine (float lat1, float lon1, float lat2, float lon2) float haversine(float lat1, float lon1, float lat2, float lon2)
{ {
// returns the great-circle distance between two points // returns the great-circle distance between two points
float h = sq((sin((lat1 - lat2) / 2.0))) + \ float h = sq((sin((lat1 - lat2) / 2.0))) + \
(cos(lat1) * cos(lat2) * \ (cos(lat1) * cos(lat2) * \
sq((sin((lon1 - lon2) / 2.0)))); sq((sin((lon1 - lon2) / 2.0))));
float d = 2.0 * rEarth * asin (sqrt(h)); float d = 2.0 * rEarth * asin (sqrt(h));