84 |
return NULL; |
return NULL; |
85 |
} |
} |
86 |
|
|
87 |
|
|
88 |
|
pos_t *map_gps_get_pos(map_context_t *context) { |
89 |
|
static pos_t pos; |
90 |
|
|
91 |
|
if(context->gps.set & FIX_LATLON_SET) { |
92 |
|
pos.lat = context->gps.fix.latitude; |
93 |
|
pos.lon = context->gps.fix.longitude; |
94 |
|
return &pos; |
95 |
|
} |
96 |
|
|
97 |
|
return NULL; |
98 |
|
} |
99 |
|
|
100 |
|
pos_t *map_get_pos(map_context_t *context) { |
101 |
|
pos_t *pos = &context->appdata->home; |
102 |
|
|
103 |
|
if(context->appdata->active_location) { |
104 |
|
int i = context->appdata->active_location-1; |
105 |
|
location_t *loc = context->appdata->location; |
106 |
|
while(i--) loc = loc->next; |
107 |
|
pos = &loc->pos; |
108 |
|
} |
109 |
|
|
110 |
|
if(context->appdata->use_gps) |
111 |
|
pos = map_gps_get_pos(context); |
112 |
|
|
113 |
|
return pos; |
114 |
|
} |
115 |
|
|
116 |
|
float map_gps_get_heading(map_context_t *context) { |
117 |
|
if(context->gps.set & FIX_TRACK_SET) |
118 |
|
return context->gps.fix.track; |
119 |
|
|
120 |
|
return NAN; |
121 |
|
} |
122 |
|
|
123 |
|
float map_gps_get_eph(map_context_t *context) { |
124 |
|
if(context->gps.set & FIX_HERR_SET) |
125 |
|
return context->gps.fix.eph; |
126 |
|
|
127 |
|
return NAN; |
128 |
|
} |
129 |
|
|
130 |
|
/* callback called by the gps layer whenever gps state changes */ |
131 |
|
static void |
132 |
|
gps_callback(gps_mask_t set, struct gps_t *fix, void *data) { |
133 |
|
map_context_t *context = (map_context_t*)data; |
134 |
|
|
135 |
|
printf("map: gps callback\n"); |
136 |
|
|
137 |
|
context->gps.set = set; |
138 |
|
memcpy(&context->gps.fix, fix, sizeof(struct gps_t)); |
139 |
|
} |
140 |
|
|
141 |
static void |
static void |
142 |
cb_map_gps(osd_button_t but, map_context_t *context) { |
cb_map_gps(osd_button_t but, map_context_t *context) { |
143 |
|
|
180 |
#endif |
#endif |
181 |
|
|
182 |
/* get reference position ... */ |
/* get reference position ... */ |
183 |
pos_t *refpos = get_pos(context->appdata); |
pos_t *refpos = map_get_pos(context); |
184 |
gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); |
gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); |
185 |
|
|
186 |
/* ... and enable "goto" button if it's valid */ |
/* ... and enable "goto" button if it's valid */ |
195 |
int radius = 0; |
int radius = 0; |
196 |
|
|
197 |
if(context->appdata->use_gps) { |
if(context->appdata->use_gps) { |
198 |
heading = gps_get_heading(context->appdata); |
heading = map_gps_get_heading(context); |
199 |
|
|
200 |
/* get error */ |
/* get error */ |
201 |
float eph = gps_get_eph(context->appdata); |
float eph = map_gps_get_eph(context); |
202 |
if(!isnan(eph)) |
if(!isnan(eph)) |
203 |
radius = dist2pixel(context, eph/1000, refpos->lat); |
radius = dist2pixel(context, eph/1000, refpos->lat); |
204 |
} |
} |
879 |
g_object_get(map, "zoom", &zoom, NULL); |
g_object_get(map, "zoom", &zoom, NULL); |
880 |
context->appdata->map.zoom = zoom; |
context->appdata->map.zoom = zoom; |
881 |
|
|
882 |
|
gboolean dpix; |
883 |
|
g_object_get(map, "double-pixel", &dpix, NULL); |
884 |
|
context->appdata->map.dpix = dpix; |
885 |
|
|
886 |
gfloat lat, lon; |
gfloat lat, lon; |
887 |
g_object_get(map, "latitude", &lat, "longitude", &lon, NULL); |
g_object_get(map, "latitude", &lat, "longitude", &lon, NULL); |
888 |
context->appdata->map.pos.lat = lat; |
context->appdata->map.pos.lat = lat; |
898 |
#endif |
#endif |
899 |
|
|
900 |
gtk_timeout_remove(context->handler_id); |
gtk_timeout_remove(context->handler_id); |
|
gps_unregister_callback(appdata, context->cb_id); |
|
901 |
|
|
902 |
if(context->caches_displayed) { |
if(context->caches_displayed) { |
903 |
g_free(context->caches_displayed); |
g_free(context->caches_displayed); |
944 |
context->handler_id = gtk_timeout_add(1000, map_gps_update, context); |
context->handler_id = gtk_timeout_add(1000, map_gps_update, context); |
945 |
#endif |
#endif |
946 |
|
|
947 |
|
gps_register_callback(context->appdata->gps_state, |
948 |
|
LATLON_CHANGED | HERR_CHANGED | TRACK_CHANGED, |
949 |
|
gps_callback, context); |
950 |
|
|
951 |
map_setup(context); |
map_setup(context); |
952 |
return FALSE; |
return FALSE; |
953 |
} |
} |
970 |
context->handler_id = 0; |
context->handler_id = 0; |
971 |
#endif |
#endif |
972 |
|
|
973 |
|
gps_unregister_callback(context->appdata->gps_state, gps_callback); |
974 |
|
|
975 |
return FALSE; |
return FALSE; |
976 |
} |
} |
977 |
|
|
983 |
#endif |
#endif |
984 |
} |
} |
985 |
|
|
|
/* callback called by the gps layer whenever gps state changes */ |
|
|
static void |
|
|
gps_callback(struct gps_state *state, gpointer data) { |
|
|
printf("map: gps callback\n"); |
|
|
} |
|
|
|
|
986 |
void map(appdata_t *appdata) { |
void map(appdata_t *appdata) { |
987 |
map_context_t *context = NULL; |
map_context_t *context = NULL; |
988 |
|
|
1035 |
"auto-center", FALSE, |
"auto-center", FALSE, |
1036 |
"record-trip-history", FALSE, |
"record-trip-history", FALSE, |
1037 |
"show-trip-history", FALSE, |
"show-trip-history", FALSE, |
1038 |
|
"double-pixel", context->appdata->map.dpix, |
1039 |
proxy?"proxy-uri":NULL, proxy, |
proxy?"proxy-uri":NULL, proxy, |
1040 |
NULL); |
NULL); |
1041 |
|
|
1103 |
|
|
1104 |
/* install handler for timed updates of the gps button */ |
/* install handler for timed updates of the gps button */ |
1105 |
context->handler_id = gtk_timeout_add(1000, map_gps_update, context); |
context->handler_id = gtk_timeout_add(1000, map_gps_update, context); |
|
context->cb_id = gps_register_callback(appdata, gps_callback, context); |
|
1106 |
|
|
1107 |
#if MAEMO_VERSION_MAJOR == 5 |
#if MAEMO_VERSION_MAJOR == 5 |
1108 |
/* prevent some of the main screen things */ |
/* prevent some of the main screen things */ |