Willem Melching
/
bootje_v4
verwerking/route.cpp
- Committer:
- pd0wm
- Date:
- 2011-09-27
- Revision:
- 0:bec310bde899
File content as of revision 0:bec310bde899:
#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; }