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_LATLON_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 |
} |
} |
567 |
|
|
568 |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
569 |
|
|
|
puts("press event"); |
|
|
|
|
570 |
/* check if we actually clicked parts of the OSD */ |
/* check if we actually clicked parts of the OSD */ |
571 |
if(osm_gps_map_osd_check(map, event->x, event->y) != OSD_NONE) |
if(osm_gps_map_osd_check(map, event->x, event->y) != OSD_NONE) |
572 |
return FALSE; |
return FALSE; |
835 |
GdkEventButton *event, map_context_t *context) { |
GdkEventButton *event, map_context_t *context) { |
836 |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
837 |
|
|
|
puts("release event"); |
|
|
|
|
838 |
/* in "MAP_CACHE" state only one cache is visible */ |
/* in "MAP_CACHE" state only one cache is visible */ |
839 |
/* and the map is in navigation mode. the balloon is */ |
/* and the map is in navigation mode. the balloon is */ |
840 |
/* pretty useless there */ |
/* pretty useless there */ |
898 |
#endif |
#endif |
899 |
|
|
900 |
gtk_timeout_remove(context->handler_id); |
gtk_timeout_remove(context->handler_id); |
901 |
gps_unregister_callback(appdata, context->cb_id); |
gps_unregister_callback(appdata->gps_state, gps_callback); |
902 |
|
|
903 |
if(context->caches_displayed) { |
if(context->caches_displayed) { |
904 |
g_free(context->caches_displayed); |
g_free(context->caches_displayed); |
978 |
#endif |
#endif |
979 |
} |
} |
980 |
|
|
|
/* 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"); |
|
|
} |
|
|
|
|
981 |
void map(appdata_t *appdata) { |
void map(appdata_t *appdata) { |
982 |
map_context_t *context = NULL; |
map_context_t *context = NULL; |
983 |
|
|
1098 |
|
|
1099 |
/* install handler for timed updates of the gps button */ |
/* install handler for timed updates of the gps button */ |
1100 |
context->handler_id = gtk_timeout_add(1000, map_gps_update, context); |
context->handler_id = gtk_timeout_add(1000, map_gps_update, context); |
1101 |
context->cb_id = gps_register_callback(appdata, gps_callback, context); |
gps_register_callback(appdata->gps_state, LATLON_CHANGED | HERR_CHANGED, |
1102 |
|
gps_callback, context); |
1103 |
|
|
1104 |
#if MAEMO_VERSION_MAJOR == 5 |
#if MAEMO_VERSION_MAJOR == 5 |
1105 |
/* prevent some of the main screen things */ |
/* prevent some of the main screen things */ |