Dependencies:   mbed

Revision:
0:bec310bde899
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/verwerking/route.cpp	Tue Sep 27 19:46:30 2011 +0000
@@ -0,0 +1,110 @@
+#include "route.h"
+
+Route::Route(Gps * g){
+    loop = 0;
+    len = 0;
+    active = 0;
+    gps = g;
+    klaar = 0;
+}
+
+void Route::loopMode(int l){
+    loop = l;
+}
+
+int Route::getLoopMode(void){
+    return loop;
+}
+
+void Route::setActive(int index){
+    active = index;
+}
+int Route::getActive(void){
+    return active;
+}
+
+
+void Route::add(pos nieuw){
+    waypoints[len] = nieuw;
+    len++;
+}
+
+void Route::del(int index){
+    if (index < len && index >= 0){
+        for (int x = index;x < len; x++){
+            waypoints[x] = waypoints[x+1];
+        }
+        len--;
+    }
+}
+
+void Route::up(int index){
+    index--;
+    if (index < len -1 && index >= 0){
+        pos tmp = waypoints[index];
+        waypoints[index] = waypoints[index+1];
+        waypoints[index+1] = tmp;
+    }
+}
+
+void Route::down(int index){
+    if (index < len && index >= 1){
+        pos tmp = waypoints[index];
+        waypoints[index] = waypoints[index - 1];
+        waypoints[index - 1] = tmp;
+    }
+}        
+
+const char* Route::list(void){
+    string s;
+    char *t;
+    for (int x = 0;x!=len;x++){
+        sprintf(t,"%d) %f %f\r\n",x,waypoints[x].lat,waypoints[x].lon);
+        s += t;
+    }
+    
+    
+    return s.c_str();
+}
+
+pos Route::get(void){
+    if (afstand(&gps->get(),&waypoints[active]) < 0.01){
+        active++;
+        if (active = len){
+            if (loop)
+                active = 0;
+            else
+                active = len -1;
+                klaar = 1;
+        }
+    }
+    else{
+        klaar = 0;
+    }
+    return waypoints[active];
+}
+
+int Route::isklaar(void){
+    return klaar;
+}
+
+double Route::afstand_tot_doel(void){
+    return afstand(&gps->get(),&waypoints[active]);
+}
+
+double Route::koers_tot_doel(void){
+    return koers(&gps->get(),&waypoints[active]);
+}
+
+
+
+pos Route::read(int i){
+    return waypoints[i];
+}
+
+int Route::getlen(void){
+    return len;
+}
+
+
+    
\ No newline at end of file