-
Notifications
You must be signed in to change notification settings - Fork 0
/
ozex.cpp
executable file
·167 lines (131 loc) · 2.89 KB
/
ozex.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <iostream>
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "SDL.h"
#include "map_loader.h"
//#include "map_container.h"
#include "map_datums.h"
//#include "map_render.h"
#include "wpt_container.h"
#include "log_stream.h"
#include "ozex_gps.h"
#include "mapwindow.h"
#include "ozex.h"
/*----------------------------------------------------------------------------*/
bool SDLApp::OnInit()
{
gpsOn = 0;
waypoints = new wpt_container();
logstream_to(NULL);
mapdatums_init("./datums.xml");
frame = new MapWindow;
frame->Show();
//SetTopWindow(frame);
return true;
}
/*----------------------------------------------------------------------------*/
int SDLApp::OnRun()
{
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
std::cerr << "unable to init SDL: " << SDL_GetError() << '\n';
return -1;
}
wxPaintEvent event;
event.SetEventObject(frame->getPanel());
frame->getPanel()->AddPendingEvent(event);
return wxApp::OnRun();
}
/*----------------------------------------------------------------------------*/
int SDLApp::OnExit()
{
if (gpsOn)
{
ozex_gps_close();
gpsOn = 0;
}
delete waypoints;
mapdatums_done();
printf("SDLApp::OnExit()\n");
SDL_Quit();
return wxApp::OnExit();
}
int SDLApp::isGpsOn()
{
return gpsOn;
}
void SDLApp::setGpsOn(int on)
{
gpsOn = on;
}
wpt_container* SDLApp::getWaypoints()
{
return waypoints;
}
/*----------------------------------------------------------------------------*/
void SDLApp::gpsOnOff()
{
if (isGpsOn())
{
ozex_gps_close();
setGpsOn(0);
}
else
{
int debug = GET_ENV_INT("OZEX_USE_LOG",0);
if (debug)
{
ozex_gps_start_fromfile(GET_ENV_STR("OZEX_GPS_LOG","logs/gps.log"));
}
else
{
ozex_gps_start(GET_ENV_STR("OZEX_GPS_DEV","/dev/rfcomm0"), GET_ENV_INT("OZEX_GPS_BAUDS",9600));
}
setGpsOn(1);
}
}
time_t lastgpstime =0;
/*----------------------------------------------------------------------------*/
coords_t SDLApp::readGps()
{
coords_t coords;
coords.onPosition = 0;
if (isGpsOn())
{
ozex_gps_update();
time_t thistime = time(NULL);
//if (!lastgpstime || thistime - lastgpstime >= 3 )
// {
lastgpstime = thistime;
coords.lat = ozex_gps_lat();
coords.lon = ozex_gps_lon();
coords.onPosition = 1;
// }
}
return coords;
}
wxString format_dist(double distInM)
{
wxString fmtStr;
double distInKm = distInM / 1000;
if ( distInM < 1000 )
{
fmtStr.Printf ( wxT ( " %.0f m" ), distInM );
}
else
if ( distInM < 1000 * 10 )
{
fmtStr.Printf ( wxT ( " %2.1f km" ),
distInKm );
}
else
{
fmtStr.Printf ( wxT ( " %.0f km" ),
distInKm );
}
return fmtStr;
}
IMPLEMENT_CLASS(SDLApp, wxApp)
IMPLEMENT_APP(SDLApp)