This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 148
/
roadmap_adjust.c
93 lines (69 loc) · 2.62 KB
/
roadmap_adjust.c
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
/* roadmap_adjust.c - Convert a GPS position into a map position.
*
* LICENSE:
*
* Copyright 2002 Pascal F. Martin
*
* This file is part of RoadMap.
*
* RoadMap is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* RoadMap is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RoadMap; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* SYNOPSYS:
*
* See roadmap_adjust.h
*
* BUGS:
*
* At this time this module only perfoms a fixed adjustment.
*/
#include "roadmap_config.h"
#include "roadmap_adjust.h"
static RoadMapConfigDescriptor RoadMapConfigGPSOffsetLat =
ROADMAP_CONFIG_ITEM("Map", "GPS map offset latitude");
static RoadMapConfigDescriptor RoadMapConfigGPSOffsetLong =
ROADMAP_CONFIG_ITEM("Map", "GPS map offset longitude");
static RoadMapGpsPosition RoadMapAdjustLatestGps;
static RoadMapPosition RoadMapAdjustLatestMap;
int roadmap_adjust_offset_latitude (void) {
return roadmap_config_get_integer (&RoadMapConfigGPSOffsetLat);
}
int roadmap_adjust_offset_longitude (void) {
return roadmap_config_get_integer (&RoadMapConfigGPSOffsetLong);
}
static void roadmap_adjust_convert (const RoadMapGpsPosition *gps) {
RoadMapAdjustLatestMap.longitude =
gps->longitude + roadmap_adjust_offset_longitude();
RoadMapAdjustLatestMap.latitude =
gps->latitude + roadmap_adjust_offset_latitude();
RoadMapAdjustLatestGps = *gps;
}
void roadmap_adjust_position
(const RoadMapGpsPosition *gps, RoadMapPosition *map) {
/* Because the conversion might be expensive, and requested
* several times for the same GPS position (from different
* modules), we cache the latest result.
*/
if ((gps->latitude != RoadMapAdjustLatestGps.latitude) ||
(gps->longitude != RoadMapAdjustLatestGps.longitude)) {
roadmap_adjust_convert (gps);
}
*map = RoadMapAdjustLatestMap;
}
void roadmap_adjust_initialize (void) {
roadmap_config_declare
("preferences", &RoadMapConfigGPSOffsetLat, "0", NULL);
roadmap_config_declare
("preferences", &RoadMapConfigGPSOffsetLong, "0", NULL);
}