]> err.no Git - mapper/blob - src/gps.c
Move macros and some functions to better places
[mapper] / src / gps.c
1 /*
2  * This file is part of mapper
3  *
4  * Copyright (C) 2007 Kaj-Michael Lang
5  * Copyright (C) 2006-2007 John Costigan.
6  *
7  * POI and GPS-Info code originally written by Cezary Jackiewicz.
8  *
9  * Default map data provided by http://www.openstreetmap.org/
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #include "gps.h"
27 #include "latlon.h"
28
29 void
30 gps_init(void)
31 {
32 _gps.lat = 0;
33 _gps.lon = 0;
34 _gps.heading = 0;
35 _gps.lheading = 0;
36 _gps.fix = 1;
37 _gps.satinuse = 0;
38 _gps.satinview = 0;
39 _gps.speed = 0.f;
40 _pos.unitx = 0;
41 _pos.unity = 0;
42
43 integerize_data(&_gps, &_pos);
44 }
45
46 /**
47  * Convert the float lat/lon/speed/heading data into integer units.
48  */
49 void 
50 integerize_data(GpsData *gps, Point *pos)
51 {
52 gdouble tmp;
53
54 latlon2unit(gps->lat, gps->lon, pos->unitx, pos->unity);
55
56 tmp=(gps->heading*(1.f/180.f))*G_PI;
57 gps->vel_offsetx=(gint)(floorf(gps->speed*sinf(tmp)+0.5f));
58 gps->vel_offsety=-(gint)(floorf(gps->speed*cosf(tmp)+0.5f));
59 }