From 6e2f5302927671aa7e58abba02913eede07742bb Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Sat, 19 Jan 2008 13:29:51 +0200 Subject: [PATCH] Get rid of _pos, move data to gpsdata struct. Prepare for using multiple GPS sources by using a dynamicaly allocated _gps struct. --- src/cb.c | 37 +++---- src/config-gconf.c | 22 ++-- src/gps-nmea-parse.c | 82 +++++++------- src/gps-panels.c | 256 ++++++++----------------------------------- src/gps-panels.h | 7 +- src/gps.c | 26 ++--- src/gps.h | 16 +-- src/gpsdata.h | 8 +- src/map-repo.c | 4 +- src/map.c | 40 +++---- src/map.h | 24 ++-- src/mapper.c | 10 +- src/osm-db.c | 6 +- src/route.c | 32 +++--- src/settings-gconf.h | 2 + src/track.c | 79 ++++++------- src/track.h | 2 +- src/ui-common.c | 22 ++-- src/utils.h | 5 - 19 files changed, 245 insertions(+), 435 deletions(-) diff --git a/src/cb.c b/src/cb.c index 7496a54..96370a9 100644 --- a/src/cb.c +++ b/src/cb.c @@ -244,7 +244,7 @@ gboolean menu_cb_gps_show_info(GtkAction * action) { _gps_info = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)); -gps_show_info(); +gps_show_info(_gps); return TRUE; } @@ -311,7 +311,7 @@ gboolean menu_cb_goto_gps(GtkAction *action) { _center_mode = CENTER_LATLON; -map_center_unit(_pos.unitx, _pos.unity); +map_center_unit(_gps->unitx, _gps->unity); map_update_location_from_center(); MACRO_BANNER_SHOW_INFO(_window, _("At GPS coordinates.")); return TRUE; @@ -340,7 +340,8 @@ poi_info *p; if (_center_mode > 0) { /* Auto-Center is enabled - use the GPS position. */ - unit2latlon(_pos.unitx, _pos.unity, lat, lon); + lat=_gps->lat; + lon=_gps->lon; } else { /* Auto-Center is disabled - use the view center. */ unit2latlon(_center.unitx, _center.unity, lat, lon); @@ -449,13 +450,12 @@ if ((_enable_gps = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) { } if (_enable_gps==FALSE) set_action_activate("autocenter_none", TRUE); -set_action_sensitive("gps_details", _enable_gps); set_action_sensitive("goto_gps", _enable_gps); set_action_sensitive("autocenter_latlon", _enable_gps); set_action_sensitive("autocenter_lead", _enable_gps); map_move_mark(); -gps_show_info(); +gps_show_info(_gps); return TRUE; } @@ -472,13 +472,6 @@ if ((_auto_download = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)) )) return TRUE; } -gboolean -menu_cb_gps_details(GtkAction * action) -{ -gps_details(); -return TRUE; -} - gboolean menu_cb_settings(GtkAction * action) { @@ -750,7 +743,7 @@ gdouble lat, lon; unit2latlon(unitx, unity, lat, lon); g_snprintf(buffer, sizeof(buffer), "%s: %.02lf %s", _("Distance"), - calculate_distance(_gps.lat, _gps.lon, lat, lon) * UNITS_CONVERT[_units], UNITS_TEXT[_units]); + calculate_distance(_gps->lat, _gps->lon, lat, lon) * UNITS_CONVERT[_units], UNITS_TEXT[_units]); MACRO_BANNER_SHOW_INFO(_window, buffer); } @@ -947,8 +940,8 @@ poi_info poi; gdouble lat, lon; if (_center_mode>0) { - lat=_gps.lat; - lon=_gps.lon; + lat=_gps->lat; + lon=_gps->lon; } else { unit2latlon(_center.unitx, _center.unity, lat, lon); } @@ -965,8 +958,8 @@ const gchar *name = gtk_action_get_name(action); poi_info *p; if (_center_mode>0) { - lat=_gps.lat; - lon=_gps.lon; + lat=_gps->lat; + lon=_gps->lon; } else { unit2latlon(_center.unitx, _center.unity, lat, lon); } @@ -992,8 +985,8 @@ menu_cb_search_address(GtkAction *action) gdouble lat, lon; if (_center_mode>0) { - lat=_gps.lat; - lon=_gps.lon; + lat=_gps->lat; + lon=_gps->lon; } else { unit2latlon(_center.unitx, _center.unity, lat, lon); } @@ -1034,9 +1027,9 @@ return TRUE; gboolean cmenu_cb_loc_set_gps(GtkAction * action) { -_pos.unitx = x2unit(_cmenu_position_x); -_pos.unity = y2unit(_cmenu_position_y); -unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon); +_gps->unitx = x2unit(_cmenu_position_x); +_gps->unity = y2unit(_cmenu_position_y); +unit2latlon(_gps->unitx, _gps->unity, _gps->lat, _gps->lon); /* Move mark to new location. */ map_refresh_mark(); diff --git a/src/config-gconf.c b/src/config-gconf.c index 0819af9..2eec3af 100644 --- a/src/config-gconf.c +++ b/src/config-gconf.c @@ -289,8 +289,8 @@ gconf_client_set_string(gconf_client, INFO_FONT_TEXT[_info_font_size], NULL); /* Save last latitude/longiture. */ -gconf_client_set_float(gconf_client, GCONF_KEY_LAT, _gps.lat, NULL); -gconf_client_set_float(gconf_client, GCONF_KEY_LON, _gps.lon, NULL); +gconf_client_set_float(gconf_client, GCONF_KEY_LAT, _gps->lat, NULL); +gconf_client_set_float(gconf_client, GCONF_KEY_LON, _gps->lon, NULL); /* Save last center latitude/longitude. */ unit2latlon(_center.unitx, _center.unity, center_lat, center_lon); @@ -562,10 +562,10 @@ BOUND(_speed_limit, 1, 200); _auto_download = gconf_client_get_bool(gconf_client, GCONF_KEY_AUTO_DOWNLOAD, NULL); /* Get saved location */ -_gps.lat = gconf_client_get_float(gconf_client, GCONF_KEY_LAT, NULL); -_gps.lon = gconf_client_get_float(gconf_client, GCONF_KEY_LON, NULL); -if (_gps.lat==0.0) _gps.lat=64.0; -if (_gps.lon==0.0) _gps.lon=22.0; +_gps->lat = gconf_client_get_float(gconf_client, GCONF_KEY_LAT, NULL); +_gps->lon = gconf_client_get_float(gconf_client, GCONF_KEY_LON, NULL); +if (_gps->lat==0.0) _gps->lat=64.20; +if (_gps->lon==0.0) _gps->lon=22.20; /* Home */ _home.valid=TRUE; @@ -587,8 +587,8 @@ if (value) { /* Turku is default */ if (_home.valid==FALSE) { - _home.lat=64.0; - _home.lon=22.0; + _home.lat=64.20; + _home.lon=22.20; _home.valid=TRUE; } @@ -602,7 +602,7 @@ if (_home.valid==FALSE) { center_lat = gconf_value_get_float(value); gconf_value_free(value); } else { - center_lat = _gps.lat; + center_lat = _gps->lat; } /* Get last saved longitude. Default is last saved longitude. */ @@ -611,7 +611,7 @@ if (_home.valid==FALSE) { center_lon = gconf_value_get_float(value); gconf_value_free(value); } else { - center_lon = _gps.lon; + center_lon = _gps->lon; } latlon2unit(center_lat, center_lon, _center.unitx, _center.unity); @@ -699,7 +699,7 @@ if (value) { _enable_gps = FALSE; } -/* Initialize _conn_state based on _enable_gps. */ +/* Initialize _conn_state based on _enable_gps-> */ _conn_state = (_enable_gps ? RCVR_DOWN : RCVR_OFF); /* Load the route locations. */ diff --git a/src/gps-nmea-parse.c b/src/gps-nmea-parse.c index 5c2ba16..195014d 100644 --- a/src/gps-nmea-parse.c +++ b/src/gps-nmea-parse.c @@ -57,12 +57,11 @@ channel_cb_error(GIOChannel *src, GIOCondition condition, gpointer data) { /* An error has occurred - re-connect(). */ rcvr_disconnect(); -track_add(0, FALSE); +track_add(NULL, FALSE); _speed_excess = FALSE; if (_conn_state > RCVR_OFF) { gps_conn_set_state(RCVR_DOWN); - gps_hide_text(); rcvr_connect_later(); } return FALSE; @@ -111,7 +110,7 @@ channel_parse_rmc(gchar * sentence) /* Data is invalid - not enough satellites?. */ if (_conn_state != RCVR_UP) { gps_conn_set_state(RCVR_UP); - track_add(0, FALSE); + track_add(NULL, FALSE); } } @@ -124,13 +123,13 @@ channel_parse_rmc(gchar * sentence) MACRO_PARSE_FLOAT(tmpd, dpoint - 2); dpoint[-2] = '\0'; MACRO_PARSE_INT(tmpi, token); - _gps.lat = tmpi + (tmpd * (1.0 / 60.0)); + _gps->lat = tmpi + (tmpd * (1.0 / 60.0)); } /* Parse N or S. */ token = strsep(&sentence, DELIM); if (token && *token == 'S') - _gps.lat = -_gps.lat; + _gps->lat = -_gps->lat; /* Parse the longitude. */ token = strsep(&sentence, DELIM); @@ -141,28 +140,27 @@ channel_parse_rmc(gchar * sentence) MACRO_PARSE_FLOAT(tmpd, dpoint - 2); dpoint[-2] = '\0'; MACRO_PARSE_INT(tmpi, token); - _gps.lon = tmpi + (tmpd * (1.0 / 60.0)); + _gps->lon = tmpi + (tmpd * (1.0 / 60.0)); } /* Parse E or W. */ token = strsep(&sentence, DELIM); if (token && *token == 'W') - _gps.lon = -_gps.lon; + _gps->lon = -_gps->lon; /* Parse speed over ground, knots. */ token = strsep(&sentence, DELIM); if (token && *token) { - MACRO_PARSE_FLOAT(_gps.speed, token); - if (_gps.fix > 1) { - _gps.maxspeed = MAX(_gps.maxspeed, _gps.speed); - gps_display_data_speed(info_banner.speed, _gps.speed); + MACRO_PARSE_FLOAT(_gps->speed, token); + if (_gps->fix > FIX_NOFIX) { + _gps->maxspeed=MAX(_gps->maxspeed, _gps->speed); } } /* Parse heading, degrees from true north. */ token = strsep(&sentence, DELIM); if (token && *token) { - MACRO_PARSE_FLOAT(_gps.heading, token); + MACRO_PARSE_FLOAT(_gps->heading, token); } /* Parse date. */ @@ -172,17 +170,19 @@ channel_parse_rmc(gchar * sentence) gpsdate[6] = '\0'; /* Make sure time is 6 chars long. */ strcat(gpsdate, token); strptime(gpsdate, "%H%M%S%d%m%y", &time); - _pos.time = mktime(&time) + _gmtoffset; + _gps->time = mktime(&time) + _gmtoffset; } else - _pos.time = time(NULL); + _gps->time = time(NULL); /* Add new data to track only if we have a fix */ _track_store=TRUE; - if ((_conn_state==RCVR_FIXED) && (_track_store==TRUE) && filter_check(&filter, &_gps, &map_loc)==TRUE) { - gps_integerize_data(&_gps, &_pos); - track_add(_pos.time, newly_fixed); - _gps.lheading=_gps.heading; + gps_integerize_data(_gps); + gps_display_data_speed(info_banner.speed, _gps->speed); + + if ((_conn_state==RCVR_FIXED) && (_track_store==TRUE) && filter_check(&filter, _gps, &map_loc)==TRUE) { + track_add(_gps, newly_fixed); + _gps->lheading=_gps->heading; map_refresh_mark(); } } @@ -235,7 +235,7 @@ channel_parse_gga(gchar * sentence) /* Parse Fix quality */ token = strsep(&sentence, DELIM); if (token && *token) - MACRO_PARSE_INT(_gps.fixquality, token); + MACRO_PARSE_INT(_gps->fixquality, token); /* Skip number of satellites */ token = strsep(&sentence, DELIM); @@ -243,14 +243,14 @@ channel_parse_gga(gchar * sentence) /* Parse Horizontal dilution of position */ token = strsep(&sentence, DELIM); if (token && *token) - MACRO_PARSE_INT(_gps.hdop, token); + MACRO_PARSE_INT(_gps->hdop, token); /* Altitude */ token = strsep(&sentence, DELIM); if (token && *token) { - MACRO_PARSE_FLOAT(_pos.altitude, token); + MACRO_PARSE_FLOAT(_gps->altitude, token); } else - _pos.altitude = NAN; + _gps->altitude = NAN; } static void @@ -280,9 +280,9 @@ channel_parse_gsa(gchar * sentence) /* 3D fix. */ token = strsep(&sentence, DELIM); if (token && *token) - MACRO_PARSE_INT(_gps.fix, token); + MACRO_PARSE_INT(_gps->fix, token); - _gps.satinuse = 0; + _gps->satinuse = 0; for (i = 0; i < 12; i++) { gint fprn; token = strsep(&sentence, DELIM); @@ -291,29 +291,29 @@ channel_parse_gsa(gchar * sentence) else fprn=-1; satforfix[i]=fprn; - _gps.sat[i].fix=FALSE; + _gps->sat[i].fix=FALSE; } for (i=0;i<12;i++) for (si=0;si<12;si++) { - if (_gps.sat[i].prn==satforfix[si]) - _gps.sat[i].fix=TRUE; + if (_gps->sat[i].prn==satforfix[si]) + _gps->sat[i].fix=TRUE; } /* PDOP */ token = strsep(&sentence, DELIM); if (token && *token) - MACRO_PARSE_FLOAT(_gps.pdop, token); + MACRO_PARSE_FLOAT(_gps->pdop, token); /* HDOP */ token = strsep(&sentence, DELIM); if (token && *token) - MACRO_PARSE_FLOAT(_gps.hdop, token); + MACRO_PARSE_FLOAT(_gps->hdop, token); /* VDOP */ token = strsep(&sentence, DELIM); if (token && *token) - MACRO_PARSE_FLOAT(_gps.vdop, token); + MACRO_PARSE_FLOAT(_gps->vdop, token); } static void @@ -335,7 +335,7 @@ channel_parse_gsv(gchar * sentence) static guint running_total = 0; static guint num_sats_used = 0; static guint satcnt = 0; - g_printf("%s(): %s\n", __PRETTY_FUNCTION__, sentence); + /* g_printf("%s(): %s\n", __PRETTY_FUNCTION__, sentence); */ /* Parse number of messages. */ token = strsep(&sentence, DELIM); @@ -350,9 +350,9 @@ channel_parse_gsv(gchar * sentence) /* Parse number of satellites in view. */ token = strsep(&sentence, DELIM); if (token && *token) { - MACRO_PARSE_INT(_gps.satinview, token); - if (_gps.satinview > 12) /* Handle buggy NMEA. */ - _gps.satinview = 12; + MACRO_PARSE_INT(_gps->satinview, token); + if (_gps->satinview > 12) /* Handle buggy NMEA. */ + _gps->satinview = 12; } /* Loop until there are no more satellites to parse. */ @@ -360,23 +360,23 @@ channel_parse_gsv(gchar * sentence) /* Get token for Satellite Number. */ token = strsep(&sentence, DELIM); if (token && *token) - _gps.sat[satcnt].prn = atoi(token); + _gps->sat[satcnt].prn = atoi(token); /* Get token for elevation in degrees (0-90). */ token = strsep(&sentence, DELIM); if (token && *token) - _gps.sat[satcnt].elevation = atoi(token); + _gps->sat[satcnt].elevation = atoi(token); /* Get token for azimuth in degrees to true north (0-359). */ token = strsep(&sentence, DELIM); if (token && *token) - _gps.sat[satcnt].azimuth = atoi(token); + _gps->sat[satcnt].azimuth = atoi(token); /* Get token for SNR. */ token = strsep(&sentence, DELIM); - if (token && *token && (_gps.sat[satcnt].snr = atoi(token))) { + if (token && *token && (_gps->sat[satcnt].snr = atoi(token))) { /* SNR is non-zero - add to total and count as used. */ - running_total += _gps.sat[satcnt].snr; + running_total += _gps->sat[satcnt].snr; num_sats_used++; } satcnt++; @@ -419,10 +419,10 @@ else g_print("Unknown NMEA: [%s]\n", buf); g_free(buf); if (_gps_info) - gps_display_data(); + gps_display_data(_gps); if (_satdetails_on) - gps_display_details(); + gps_display_details(_gps); return FALSE; } diff --git a/src/gps-panels.c b/src/gps-panels.c index 9e99aad..09e5c74 100644 --- a/src/gps-panels.c +++ b/src/gps-panels.c @@ -90,11 +90,11 @@ text_dop = gtk_label_new(NULL); gtk_widget_set_size_request(GTK_WIDGET(text_dop), -1, 30); gtk_box_pack_start(GTK_BOX(vbox), text_dop, FALSE, TRUE, 0); -_gps_signal=gtk_gps_new(GTK_GPS_MODE_SKY, &_gps); +_gps_signal=gtk_gps_new(GTK_GPS_MODE_SKY, _gps); gtk_widget_set_size_request(_gps_signal, -1, 100); gtk_box_pack_start(GTK_BOX(vbox), _gps_signal, TRUE, TRUE, 0); -_gps_compass = gtk_compass_new(&_gps); +_gps_compass = gtk_compass_new(_gps); gtk_widget_set_size_request(_gps_compass, -1, 100); gtk_box_pack_start(GTK_BOX(vbox), _gps_compass, TRUE, TRUE, 0); @@ -132,81 +132,66 @@ gtk_label_set_label(GTK_LABEL(text_lon), " --- "); gtk_label_set_label(GTK_LABEL(text_speed), " --- "); gtk_label_set_label(GTK_LABEL(text_alt), " --- "); gtk_label_set_label(GTK_LABEL(text_dop), " --- "); -gtk_label_set_label(GTK_LABEL(text_time), "--:--:--"); } void -gps_display_data(void) +gps_display_data(GpsData *gps) { gchar buffer[32]; /* local time */ -strftime(buffer, 15, "%X", localtime(&_pos.time)); +strftime(buffer, 15, "%X", localtime(&gps->time)); gtk_label_set_label(GTK_LABEL(text_time), buffer); -if (_gps.fix < 2) { +if (gps->fix==FIX_NOFIX) { /* no fix no fun */ gps_clear_text_fields(); -} else { - /* latitude */ - lat_format(_degformat, _gps.lat, buffer); - gtk_label_set_label(GTK_LABEL(text_lat), buffer); + return; +} - /* longitude */ - lon_format(_degformat, _gps.lon, buffer); - gtk_label_set_label(GTK_LABEL(text_lon), buffer); +/* latitude */ +lat_format(_degformat, gps->lat, buffer); +gtk_label_set_label(GTK_LABEL(text_lat), buffer); - /* speed */ - gps_display_data_speed(text_speed, _gps.speed); +/* longitude */ +lon_format(_degformat, gps->lon, buffer); +gtk_label_set_label(GTK_LABEL(text_lon), buffer); - /* altitude */ - switch (_units) { - case UNITS_MI: - case UNITS_NM: - g_snprintf(buffer, 32, "Alt: %.1f ft", _pos.altitude * 3.2808399f); - break; - default: - g_snprintf(buffer, 32, "Alt: %.1f m", _pos.altitude); - } - gtk_label_set_label(GTK_LABEL(text_alt), buffer); - - /* DOP */ - g_snprintf(buffer, 32, "%.1f/%.1f/%.1f", _gps.hdop, _gps.vdop, _gps.pdop); - gtk_label_set_label(GTK_LABEL(text_dop), buffer); -} +/* speed */ +gps_display_data_speed(text_speed, gps->speed); -return; +/* altitude */ +switch (_units) { +case UNITS_MI: +case UNITS_NM: + g_snprintf(buffer, 32, "Alt: %.1f ft", gps->altitude * 3.2808399f); + break; +default: + g_snprintf(buffer, 32, "Alt: %.1f m", gps->altitude); } +gtk_label_set_label(GTK_LABEL(text_alt), buffer); -void -gps_hide_text(void) -{ -/* Clear gps data */ -_gps.fix = 1; -_gps.satinuse = 0; -_gps.satinview = 0; - -if (_gps_info) - gps_display_data(); +/* DOP */ +g_snprintf(buffer, 32, "%.1f/%.1f/%.1f", gps->hdop, gps->vdop, gps->pdop); +gtk_label_set_label(GTK_LABEL(text_dop), buffer); } void -gps_show_info(void) +gps_show_info(GpsData *gps) { if (_gps_info && _enable_gps) gtk_widget_show_all(GTK_WIDGET(_gps_widget)); else { - gps_hide_text(); gtk_widget_hide_all(GTK_WIDGET(_gps_widget)); } } gboolean -gps_display_details(void) +gps_display_details(GpsData *gps) { gchar buffer[32]; -if (_gps.fix < 2) { +if (gps->fix==FIX_NOFIX) { /* no fix no fun */ gtk_label_set_label(GTK_LABEL(_sdi_lat), " --- "); gtk_label_set_label(GTK_LABEL(_sdi_lon), " --- "); @@ -216,50 +201,50 @@ if (_gps.fix < 2) { gtk_label_set_label(GTK_LABEL(_sdi_tim), " --:--:-- "); } else { /* latitude */ - lat_format(_degformat, _gps.lat, buffer); + lat_format(_degformat, gps->lat, buffer); gtk_label_set_label(GTK_LABEL(_sdi_lat), buffer); /* longitude */ - lon_format(_degformat, _gps.lon, buffer); + lon_format(_degformat, gps->lon, buffer); gtk_label_set_label(GTK_LABEL(_sdi_lon), buffer); /* speed */ - gps_display_data_speed(_sdi_spd, _gps.speed); + gps_display_data_speed(_sdi_spd, gps->speed); /* altitude */ switch (_units) { case UNITS_MI: case UNITS_NM: - g_snprintf(buffer, 32, "%.1f ft", _pos.altitude * 3.2808399f); + g_snprintf(buffer, 32, "%.1f ft", gps->altitude * 3.2808399f); break; default: - g_snprintf(buffer, 32, "%.1f m", _pos.altitude); + g_snprintf(buffer, 32, "%.1f m", gps->altitude); break; } gtk_label_set_label(GTK_LABEL(_sdi_alt), buffer); /* heading */ - g_snprintf(buffer, 32, "%0.0f° (%0.0f)", _gps.heading, fabs(_gps.heading-_gps.lheading)); + g_snprintf(buffer, 32, "%0.0f° (%0.0f)", gps->heading, fabs(gps->heading-gps->lheading)); gtk_label_set_label(GTK_LABEL(_sdi_hea), buffer); /* local time */ - strftime(buffer, 15, "%X", localtime(&_pos.time)); + strftime(buffer, 15, "%X", localtime(&gps->time)); gtk_label_set_label(GTK_LABEL(_sdi_tim), buffer); } /* Sat in view */ -g_snprintf(buffer, 32, "%d", _gps.satinview); +g_snprintf(buffer, 32, "%d", gps->satinview); gtk_label_set_label(GTK_LABEL(_sdi_vie), buffer); /* Sat in use */ -g_snprintf(buffer, 32, "%d", _gps.satinuse); +g_snprintf(buffer, 32, "%d", gps->satinuse); gtk_label_set_label(GTK_LABEL(_sdi_use), buffer); /* fix */ -switch (_gps.fix) { +switch (gps->fix) { case 2: case 3: - g_snprintf(buffer, 32, "%dD fix", _gps.fix); + g_snprintf(buffer, 32, "%dD fix", gps->fix); break; default: g_snprintf(buffer, 32, "nofix"); @@ -267,10 +252,10 @@ break; } gtk_label_set_label(GTK_LABEL(_sdi_fix), buffer); -if (_gps.fix == 1) +if (gps->fix ==FIX_NOFIX) g_snprintf(buffer, 32, "none"); else { - switch (_gps.fixquality) { + switch (gps->fixquality) { case 1: g_strlcat(buffer,_("SPS"),32); break; @@ -303,160 +288,7 @@ else { gtk_label_set_label(GTK_LABEL(_sdi_fqu), buffer); /* max speed */ -gps_display_data_speed(_sdi_msp, _gps.maxspeed); +gps_display_data_speed(_sdi_msp, gps->maxspeed); return TRUE; } - -void -gps_details_dialog(void) -{ -GtkWidget *dialog; - -dialog = gtk_dialog_new_with_buttons(_("GPS Details"), - GTK_WINDOW(_window), - GTK_DIALOG_MODAL, GTK_STOCK_OK, - GTK_RESPONSE_ACCEPT, NULL); - -gtk_window_set_default_size(GTK_WINDOW(dialog), 600, 300); - -gtk_widget_show_all(dialog); -_satdetails_on = TRUE; -gps_display_details(); -while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { - _satdetails_on = FALSE; - break; -} -gtk_widget_destroy(dialog); -} - -void -gps_details(void) -{ -GtkWidget *dialog; -GtkWidget *table; -GtkWidget *label; -GtkWidget *notebook; - -dialog = gtk_dialog_new_with_buttons(_("GPS Details"), - GTK_WINDOW(_window), - GTK_DIALOG_MODAL, GTK_STOCK_OK, - GTK_RESPONSE_ACCEPT, NULL); - -gtk_window_set_default_size(GTK_WINDOW(dialog), 600, 300); -gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), - notebook = gtk_notebook_new(), TRUE, TRUE, 0); - -/* textual info */ -gtk_notebook_append_page(GTK_NOTEBOOK(notebook), - table = gtk_table_new(4, 6, FALSE), - label = gtk_label_new(_("GPS Information"))); - -gtk_table_attach(GTK_TABLE(table), - label = gtk_label_new(_("Latitude")), - 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, 0, 20, 4); -gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); -gtk_table_attach(GTK_TABLE(table), - _sdi_lat = gtk_label_new(" --- "), - 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 4); -gtk_misc_set_alignment(GTK_MISC(_sdi_lat), 0.f, 0.5f); - -gtk_table_attach(GTK_TABLE(table), - label = gtk_label_new(_("Longitude")), - 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, 0, 20, 4); -gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); -gtk_table_attach(GTK_TABLE(table), - _sdi_lon = gtk_label_new(" --- "), - 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4); -gtk_misc_set_alignment(GTK_MISC(_sdi_lon), 0.f, 0.5f); - -gtk_table_attach(GTK_TABLE(table), - label = gtk_label_new(_("Speed")), - 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, 0, 20, 4); -gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); -gtk_table_attach(GTK_TABLE(table), - _sdi_spd = gtk_label_new(" --- "), - 1, 2, 2, 3, GTK_EXPAND | GTK_FILL, 0, 2, 4); -gtk_misc_set_alignment(GTK_MISC(_sdi_spd), 0.f, 0.5f); - -gtk_table_attach(GTK_TABLE(table), - label = gtk_label_new(_("Altitude")), - 0, 1, 3, 4, GTK_EXPAND | GTK_FILL, 0, 20, 4); -gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); -gtk_table_attach(GTK_TABLE(table), - _sdi_alt = gtk_label_new(" --- "), - 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, 0, 2, 4); -gtk_misc_set_alignment(GTK_MISC(_sdi_alt), 0.f, 0.5f); - -gtk_table_attach(GTK_TABLE(table), - label = gtk_label_new(_("Heading")), - 0, 1, 4, 5, GTK_EXPAND | GTK_FILL, 0, 20, 4); -gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); -gtk_table_attach(GTK_TABLE(table), - _sdi_hea = gtk_label_new(" --- "), - 1, 2, 4, 5, GTK_EXPAND | GTK_FILL, 0, 2, 4); -gtk_misc_set_alignment(GTK_MISC(_sdi_hea), 0.f, 0.5f); - -gtk_table_attach(GTK_TABLE(table), - label = gtk_label_new(_("Local time")), - 0, 1, 5, 6, GTK_EXPAND | GTK_FILL, 0, 20, 4); -gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); -gtk_table_attach(GTK_TABLE(table), - _sdi_tim = gtk_label_new(" --:--:-- "), - 1, 2, 5, 6, GTK_EXPAND | GTK_FILL, 0, 2, 4); -gtk_misc_set_alignment(GTK_MISC(_sdi_tim), 0.f, 0.5f); - -gtk_table_attach(GTK_TABLE(table), - label = gtk_label_new(_("Sat in view")), - 2, 3, 0, 1, GTK_EXPAND | GTK_FILL, 0, 20, 4); -gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); -gtk_table_attach(GTK_TABLE(table), - _sdi_vie = gtk_label_new("0"), - 3, 4, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 4); -gtk_misc_set_alignment(GTK_MISC(_sdi_vie), 0.f, 0.5f); - -gtk_table_attach(GTK_TABLE(table), - label = gtk_label_new(_("Sat in use")), - 2, 3, 1, 2, GTK_EXPAND | GTK_FILL, 0, 20, 4); -gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); -gtk_table_attach(GTK_TABLE(table), - _sdi_use = gtk_label_new("0"), - 3, 4, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4); -gtk_misc_set_alignment(GTK_MISC(_sdi_use), 0.f, 0.5f); - -gtk_table_attach(GTK_TABLE(table), - label = gtk_label_new(_("Fix")), - 2, 3, 2, 3, GTK_EXPAND | GTK_FILL, 0, 20, 4); -gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); -gtk_table_attach(GTK_TABLE(table), - _sdi_fix = gtk_label_new(_("nofix")), - 3, 4, 2, 3, GTK_EXPAND | GTK_FILL, 0, 2, 4); -gtk_misc_set_alignment(GTK_MISC(_sdi_fix), 0.f, 0.5f); - -gtk_table_attach(GTK_TABLE(table), - label = gtk_label_new(_("Fix Quality")), - 2, 3, 3, 4, GTK_EXPAND | GTK_FILL, 0, 20, 4); -gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); -gtk_table_attach(GTK_TABLE(table), - _sdi_fqu = gtk_label_new(_("none")), - 3, 4, 3, 4, GTK_EXPAND | GTK_FILL, 0, 2, 4); -gtk_misc_set_alignment(GTK_MISC(_sdi_fqu), 0.f, 0.5f); - -gtk_table_attach(GTK_TABLE(table), - label = gtk_label_new(_("Max speed")), - 2, 3, 5, 6, GTK_EXPAND | GTK_FILL, 0, 20, 4); -gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); -gtk_table_attach(GTK_TABLE(table), - _sdi_msp = gtk_label_new(" --- "), - 3, 4, 5, 6, GTK_EXPAND | GTK_FILL, 0, 2, 4); -gtk_misc_set_alignment(GTK_MISC(_sdi_msp), 0.f, 0.5f); - -gtk_widget_show_all(dialog); -_satdetails_on = TRUE; -gps_display_details(); -while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { - _satdetails_on = FALSE; - break; -} -gtk_widget_destroy(dialog); -} diff --git a/src/gps-panels.h b/src/gps-panels.h index 838d460..6b8198e 100644 --- a/src/gps-panels.h +++ b/src/gps-panels.h @@ -2,10 +2,11 @@ #define _GPS_PANELS_H GtkWidget *gps_info_panel(void); + void gps_display_data_speed(GtkWidget *widget, gfloat s); -void gps_display_data(void); -void gps_show_info(void); -void gps_hide_text(void); +void gps_display_data(GpsData *gps); +void gps_show_info(GpsData *gps); +gboolean gps_display_details(GpsData *gps); void gps_details_dialog(void); #endif diff --git a/src/gps.c b/src/gps.c index fc3c940..4c9e63d 100644 --- a/src/gps.c +++ b/src/gps.c @@ -27,33 +27,27 @@ #include "latlon.h" #include "map.h" -void +GpsData * gps_init(void) { -_gps.lat = 0; -_gps.lon = 0; -_gps.heading = 0; -_gps.lheading = 0; -_gps.fix = 1; -_gps.satinuse = 0; -_gps.satinview = 0; -_gps.speed = 0.f; -_pos.unitx = 0; -_pos.unity = 0; +GpsData *gps; -gps_integerize_data(&_gps, &_pos); +gps=g_slice_new0(GpsData); +gps->fix=FIX_NOFIX; +gps_integerize_data(gps); +return gps; } /** * Convert the float lat/lon/speed/heading data into integer units. */ void -gps_integerize_data(GpsData *gps, Point *pos) +gps_integerize_data(GpsData *gps) { gdouble tmp; -latlon2unit(gps->lat, gps->lon, pos->unitx, pos->unity); tmp=(gps->heading*(1.f/180.f))*G_PI; -gps->vel_offsetx=(gint)(floorf(gps->speed*sinf(tmp)+0.5f)); -gps->vel_offsety=-(gint)(floorf(gps->speed*cosf(tmp)+0.5f)); +latlon2unit(gps->lat, gps->lon, gps->unitx, gps->unity); +gps->vel_offsetx=(gint)(floor(gps->speed*sin(tmp)+0.5f)); +gps->vel_offsety=-(gint)(floor(gps->speed*cos(tmp)+0.5f)); } diff --git a/src/gps.h b/src/gps.h index 1327157..ddcaf76 100644 --- a/src/gps.h +++ b/src/gps.h @@ -41,20 +41,20 @@ typedef enum { typedef struct _GpsIO GpsIO; struct _GpsIO { gint fd; + GIOChannel *channel; + DBusGProxy *rfcomm_req_proxy; + GpsIOSourceType src_type; guint connect_sid; guint error_sid; guint input_sid; guint clater_sid; - GIOChannel *channel; - DBusGProxy *rfcomm_req_proxy; - GpsIOSourceType src_type; - gchar buf[GPS_READ_BUF_SIZE]; gchar *curr; gchar *last; }; GpsIO gpsio; +GpsData *_gps; gchar _gps_read_buf[GPS_READ_BUF_SIZE]; gchar *_gps_read_buf_curr; @@ -70,12 +70,8 @@ guint _clater_sid; gint _gmtoffset; -/** GPS data. */ -GpsData _gps; -Point _pos; - -void gps_init(void); -void gps_integerize_data(GpsData *gps, Point *pos); +GpsData *gps_init(void); +void gps_integerize_data(GpsData *gps); gboolean channel_cb_error(GIOChannel * src, GIOCondition condition, gpointer data); gboolean channel_cb_input(GIOChannel * src, GIOCondition condition, gpointer data); diff --git a/src/gpsdata.h b/src/gpsdata.h index 0c015d0..fe75518 100644 --- a/src/gpsdata.h +++ b/src/gpsdata.h @@ -28,13 +28,17 @@ struct _GpsSatelliteData { */ typedef struct _GpsData GpsData; struct _GpsData { - guint fix; - guint fixquality; gdouble lat; gdouble lon; + guint unitx; + guint unity; + time_t time; + GpsFix fix; + guint fixquality; gfloat speed; gfloat maxspeed; gfloat avgspeed; + gfloat altitude; gfloat heading; gfloat lheading; gfloat hdop; diff --git a/src/map-repo.c b/src/map-repo.c index 8164452..9ba59e6 100644 --- a/src/map-repo.c +++ b/src/map-repo.c @@ -1171,9 +1171,9 @@ gboolean menu_cb_mapman(GtkAction * action) /* Initialize fields. Do no use g_ascii_formatd; these strings will be * output (and parsed) as locale-dependent. */ - g_snprintf(buffer, sizeof(buffer), "%.06f", _gps.lat); + g_snprintf(buffer, sizeof(buffer), "%.06f", _gps->lat); gtk_label_set_text(GTK_LABEL(lbl_gps_lat), buffer); - g_snprintf(buffer, sizeof(buffer), "%.06f", _gps.lon); + g_snprintf(buffer, sizeof(buffer), "%.06f", _gps->lon); gtk_label_set_text(GTK_LABEL(lbl_gps_lon), buffer); unit2latlon(_center.unitx, _center.unity, lat, lon); diff --git a/src/map.c b/src/map.c index 1f323f4..e1223c6 100644 --- a/src/map.c +++ b/src/map.c @@ -233,10 +233,10 @@ gdk_draw_line(_map_widget->window, _conn_state == RCVR_FIXED ? (_show_velvec ? _ void map_set_mark(void) { -mark_x1 = unit2x(_pos.unitx); -mark_y1 = unit2y(_pos.unity); -mark_x2 = mark_x1 + (_show_velvec ? _gps.vel_offsetx : 0); -mark_y2 = mark_y1 + (_show_velvec ? _gps.vel_offsety : 0); +mark_x1 = unit2x(_gps->unitx); +mark_y1 = unit2y(_gps->unity); +mark_x2 = mark_x1 + (_show_velvec ? _gps->vel_offsetx : 0); +mark_y2 = mark_y1 + (_show_velvec ? _gps->vel_offsety : 0); mark_minx = MIN(mark_x1, mark_x2) - (2 * _draw_width); mark_miny = MIN(mark_y1, mark_y2) - (2 * _draw_width); mark_width = abs(mark_x1 - mark_x2) + (4 * _draw_width); @@ -634,7 +634,7 @@ gtk_widget_queue_draw_area(_map_widget, gboolean map_update_location_from_gps(void) { -map_update_location(_gps.lat, _gps.lon, FALSE); +map_update_location(_gps->lat, _gps->lon, FALSE); return FALSE; } @@ -645,10 +645,10 @@ gdouble lat, lon; /* Force re-validation of place if user is clicking around */ map_loc.valid=FALSE; /* XXX: hmm, not the right place for this */ -if (_gps.fix<2) { - _pos.unitx=_center.unitx; - _pos.unity=_center.unity; - unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon); +if (_gps->fix==FIX_NOFIX) { + _gps->unitx=_center.unitx; + _gps->unity=_center.unity; + unit2latlon(_gps->unitx, _gps->unity, _gps->lat, _gps->lon); } unit2latlon(_center.unitx, _center.unity, lat, lon); map_update_location(lat, lon, TRUE); @@ -905,7 +905,7 @@ GdkGC *gc; gfloat cur_speed; gchar *buffer; -cur_speed = _gps.speed * UNITS_CONVERT[_units]; +cur_speed = _gps->speed * UNITS_CONVERT[_units]; gc=(cur_speed > _speed_limit) ? speed_gc1 : speed_gc2; buffer = g_strdup_printf("%0.0f", cur_speed); map_information_text(10, 10, gc, buffer); @@ -1046,11 +1046,11 @@ gint iz; if (zoom_timeout_sid==0) return FALSE; -z=(z+_gps.speed+1)/5; +z=(z+_gps->speed+1)/5; if (z>5) z=5.0; else if (z<1) z=1.0; iz=(gint)roundf(z); #ifdef DEBUG -g_printf("Setting autozoom to: %f %d S:%f\n", z, iz, _gps.speed); +g_printf("Setting autozoom to: %f %d S:%f\n", z, iz, _gps->speed); #endif if (iz>last) iz=last+1; @@ -1067,7 +1067,7 @@ map_set_autozoom(gboolean az) { if (az==TRUE) { MACRO_BANNER_SHOW_INFO(_window, "Autozoom enabled"); - zoom_timeout_sid=g_timeout_add(_gps.speed<5 ? 2000 : 5000, (GSourceFunc) map_autozoomer, NULL); + zoom_timeout_sid=g_timeout_add(_gps->speed<5 ? 2000 : 5000, (GSourceFunc) map_autozoomer, NULL); return; } else { if (zoom_timeout_sid) { @@ -1089,11 +1089,11 @@ cmenu_route_add_way(x, y); static void map_draw_track(gint x, gint y) { -_pos.unitx = x2unit((gint) (x + 0.5)); -_pos.unity = y2unit((gint) (y + 0.5)); -unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon); -_gps.speed = 20.f; -gps_integerize_data(&_gps, &_pos); +_gps->unitx=x2unit((gint) (x + 0.5)); +_gps->unity=y2unit((gint) (y + 0.5)); +unit2latlon(_gps->unitx, _gps->unity, _gps->lat, _gps->lon); +_gps->speed=20.f; +gps_integerize_data(_gps); track_add(time(NULL), FALSE); map_refresh_mark(); } @@ -1193,8 +1193,8 @@ inp=TRUE; ilat=lat2mp_int(lat); ilon=lon2mp_int(lon); -if (_gps.fix>1 && !force) - osm_set_way_range_from_speed(_gps.speed); +if (_gps->fix>1 && !force) + osm_set_way_range_from_speed(_gps->speed); else osm_set_way_range(OSM_RANGE_WAY/4); diff --git a/src/map.h b/src/map.h index 049713c..7b77afd 100644 --- a/src/map.h +++ b/src/map.h @@ -70,8 +70,8 @@ #define unit2y(unit) (unit2pixel(unit) - tile2pixel(_base_tiley) - _offsety) #define y2unit(y) (pixel2unit(y + _offsety) + tile2unit(_base_tiley)) -#define leadx2unit() (_pos.unitx + (_lead_ratio) * pixel2unit(_gps.vel_offsetx)) -#define leady2unit() (_pos.unity + (0.6f*_lead_ratio)*pixel2unit(_gps.vel_offsety)) +#define leadx2unit() (_gps->unitx + (_lead_ratio) * pixel2unit(_gps->vel_offsetx)) +#define leady2unit() (_gps->unity + (0.6f*_lead_ratio)*pixel2unit(_gps->vel_offsety)) /* Pans are done two "grids" at a time, or 64 pixels. */ #define PAN_UNITS (grid2unit(2)) @@ -84,8 +84,8 @@ center_unity = leady2unit(); \ break; \ case CENTER_LATLON: \ - center_unitx = _pos.unitx; \ - center_unity = _pos.unity; \ + center_unitx = _gps->unitx; \ + center_unity = _gps->unity; \ break; \ default: \ center_unitx = _center.unitx; \ @@ -95,14 +95,8 @@ }; #define MACRO_RECALC_OFFSET() { \ - _offsetx = grid2pixel( \ - unit2grid(_center.unitx) \ - - _screen_grids_halfwidth \ - - tile2grid(_base_tilex)); \ - _offsety = grid2pixel( \ - unit2grid(_center.unity) \ - - _screen_grids_halfheight \ - - tile2grid(_base_tiley)); \ + _offsetx = grid2pixel(unit2grid(_center.unitx) - _screen_grids_halfwidth - tile2grid(_base_tilex)); \ + _offsety = grid2pixel(unit2grid(_center.unity) - _screen_grids_halfheight - tile2grid(_base_tiley)); \ } #define MACRO_RECALC_FOCUS_BASE() { \ @@ -111,11 +105,7 @@ } #define MACRO_QUEUE_DRAW_AREA() \ - gtk_widget_queue_draw_area( \ - _map_widget, \ - 0, 0, \ - _screen_width_pixels, \ - _screen_height_pixels) + gtk_widget_queue_draw_area(_map_widget, 0, 0, _screen_width_pixels, _screen_height_pixels) /* Render all on-map metadata an annotations, including POI and paths. */ #define MACRO_MAP_RENDER_DATA() { \ diff --git a/src/mapper.c b/src/mapper.c index b285c0c..dc0a4e4 100644 --- a/src/mapper.c +++ b/src/mapper.c @@ -99,7 +99,6 @@ enum { MAPPER_INIT_START=0, MAPPER_INIT_MISC, MAPPER_INIT_CONFIG, - MAPPER_INIT_GPS, MAPPER_INIT_DB, MAPPER_INIT_POI, MAPPER_INIT_OSM, @@ -204,6 +203,7 @@ switch (mis) { _conn_state = RCVR_OFF; curl_global_init(CURL_GLOBAL_NOTHING); gnome_vfs_init(); + _gps=gps_init(); timezone_init(); gpx_init(); variables_init(); @@ -217,16 +217,10 @@ switch (mis) { case MAPPER_INIT_CONFIG: config_init(); map_download_init(); - mis=MAPPER_INIT_GPS; + mis=MAPPER_INIT_DB; p=0.2; w="Config"; break; - case MAPPER_INIT_GPS: - gps_init(); - mis=MAPPER_INIT_DB; - p=0.3; - w="GPS"; - break; case MAPPER_INIT_DB: if (db_connect(&_db, _mapper_db)) { mis=MAPPER_INIT_POI; diff --git a/src/osm-db.c b/src/osm-db.c index e080b40..566b25d 100644 --- a/src/osm-db.c +++ b/src/osm-db.c @@ -908,7 +908,7 @@ if (map_loc->valid==FALSE) { /* Check if we are still near the same way as last time */ if (map_loc->street && osm_way_distance(lat, lon, map_loc->street->node_f, map_loc->street->node_t, &dist)==TRUE) { /* We are probably on the same way as last time */ - if ( (dist>(gdouble)way_dist_range) || (fabs(_gps.heading-map_loc->heading)>10.0)) { + if ( (dist>(gdouble)way_dist_range) || (fabs(_gps->heading-map_loc->heading)>10.0)) { /* We have moved a large amount, check way again */ g_printf("*** dist %f over range, checking again\n", dist); osm_way_free(map_loc->street); @@ -951,8 +951,8 @@ if (map_loc->street && osm_way_distance(lat, lon, map_loc->street->node_f, map_l } if (map_loc->changed==TRUE) { - map_loc->heading=_gps.heading; - map_loc->speed=_gps.speed; + map_loc->heading=_gps->heading; + map_loc->speed=_gps->speed; } #if 0 diff --git a/src/route.c b/src/route.c index 26c30a0..43dcfed 100644 --- a/src/route.c +++ b/src/route.c @@ -31,6 +31,10 @@ #include "help.h" +#define DISTANCE_SQUARED(a, b) \ + ((guint64)((((gint64)(b).unitx)-(a).unitx)*(((gint64)(b).unitx)-(a).unitx))\ + + (guint64)((((gint64)(b).unity)-(a).unity)*(((gint64)(b).unity)-(a).unity))) + void route_find_nearest_point(void); void cancel_autoroute(gboolean temporary); void route_show_distance_to_last(void); @@ -134,8 +138,8 @@ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle))) { gchar buffer[80]; gchar strlat[32]; gchar strlon[32]; - g_ascii_formatd(strlat, 32, "%.06f", _gps.lat); - g_ascii_formatd(strlon, 32, "%.06f", _gps.lon); + g_ascii_formatd(strlat, 32, "%.06f", _gps->lat); + g_ascii_formatd(strlon, 32, "%.06f", _gps->lon); g_snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon); gtk_entry_set_text(GTK_ENTRY(oti->txt_from), buffer); } else if (toggle == oti->rad_use_route) { @@ -214,8 +218,8 @@ auto_route_dl_idle() { gchar latstr[32], lonstr[32], *latlonstr; -g_ascii_dtostr(latstr, 32, _gps.lat); -g_ascii_dtostr(lonstr, 32, _gps.lon); +g_ascii_dtostr(latstr, 32, _gps->lat); +g_ascii_dtostr(lonstr, 32, _gps->lon); latlonstr = g_strdup_printf("%s,%s", latstr, lonstr); _autoroute_data.src_str = g_strdup_printf(_route_dl_url, latlonstr, _autoroute_data.dest); @@ -533,14 +537,14 @@ if (_next_way) { /* First, set near_dist_squared with the new distance from * _near_point. */ near = _near_point; - near_dist_squared = DISTANCE_SQUARED(_pos, *near); + near_dist_squared = DISTANCE_SQUARED(*_gps, *near); /* Now, search _route for a closer point. If quick is TRUE, then we'll * only search forward, only as long as we keep finding closer points. */ for (curr = _near_point; curr++ != _route.tail;) { if (curr->unity) { - guint dist_squared = DISTANCE_SQUARED(_pos, *curr); + guint dist_squared = DISTANCE_SQUARED(*_gps, *curr); if (dist_squared <= near_dist_squared) { near = curr; near_dist_squared = dist_squared; @@ -555,12 +559,12 @@ if (_next_way) { for (wnext = wcurr = _next_way; wcurr != _route.wtail; wcurr++) { if (wcurr->point < near || (wcurr->point == near && quick - && (_next_wpt && (DISTANCE_SQUARED(_pos, *near) > _next_way_dist_squared - && DISTANCE_SQUARED(_pos, *_next_wpt) < _next_wpt_dist_squared)))) + && (_next_wpt && (DISTANCE_SQUARED(*_gps, *near) > _next_way_dist_squared + && DISTANCE_SQUARED(*_gps, *_next_wpt) < _next_wpt_dist_squared)))) /* Okay, this else if expression warrants explanation. If the * nearest track point happens to be a waypoint, then we want to * check if we have "passed" that waypoint. To check this, we - * test the distance from _pos to the waypoint and from _pos to + * test the distance from _gps to the waypoint and from _gps to * _next_wpt, and if the former is increasing and the latter is * decreasing, then we have passed the waypoint, and thus we * should skip it. Note that if there is no _next_wpt, then @@ -571,8 +575,8 @@ if (_next_way) { } if (wnext == _route.wtail && (wnext->point < near || (wnext->point == near && quick - && (_next_wpt && (DISTANCE_SQUARED (_pos, *near) > _next_way_dist_squared - && DISTANCE_SQUARED(_pos, *_next_wpt) < _next_wpt_dist_squared))))) + && (_next_wpt && (DISTANCE_SQUARED (*_gps, *near) > _next_way_dist_squared + && DISTANCE_SQUARED(*_gps, *_next_wpt) < _next_wpt_dist_squared))))) { _next_way = NULL; _next_wpt = NULL; @@ -598,9 +602,9 @@ if (_next_way) { } ret = TRUE; } - _next_way_dist_squared = DISTANCE_SQUARED(_pos, *wnext->point); + _next_way_dist_squared = DISTANCE_SQUARED(*_gps, *wnext->point); if (_next_wpt) - _next_wpt_dist_squared = DISTANCE_SQUARED(_pos, *_next_wpt); + _next_wpt_dist_squared = DISTANCE_SQUARED(*_gps, *_next_wpt); } } return ret; @@ -654,7 +658,7 @@ if (point == NULL && _next_way) if (point == NULL) return FALSE; -unit2latlon(_pos.unitx, _pos.unity, lat1, lon1); +unit2latlon(_gps->unitx, _gps->unity, lat1, lon1); if (point > _near_point) { Point *curr; /* Skip _near_point in case we have already passed it. */ diff --git a/src/settings-gconf.h b/src/settings-gconf.h index d334104..3fe6db4 100644 --- a/src/settings-gconf.h +++ b/src/settings-gconf.h @@ -60,6 +60,8 @@ /* POI */ #define GCONF_KEY_POI_ZOOM GCONF_KEY_PREFIX"/poi_zoom" +#define GCONF_KEY_POI_THEME_BASE GCONF_KEY_PREFIX"/poi_theme_base" +#define GCONF_KEY_POI_ICON_THEME GCONF_KEY_PREFIX"/poi_icon_theme" #define GCONF_KEY_AUTOCENTER_MODE GCONF_KEY_PREFIX"/autocenter_mode" #define GCONF_KEY_LEAD_AMOUNT GCONF_KEY_PREFIX"/lead_amount" diff --git a/src/track.c b/src/track.c index 2f59da2..3764143 100644 --- a/src/track.c +++ b/src/track.c @@ -52,15 +52,15 @@ if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) { gtk_widget_destroy(confirm); } -gfloat -track_calculate_distance_from(Point * point) +gdouble +track_calculate_distance_from(Point *point) { -gfloat lat1, lon1, lat2, lon2; -gfloat sum = 0.0; +gdouble lat1, lon1, lat2, lon2; +gdouble sum = 0.0; Point *curr; -unit2latlon(_pos.unitx, _pos.unity, lat1, lon1); +unit2latlon(_gps->unitx, _gps->unity, lat1, lon1); -/* Skip _track.tail because that should be _pos. */ +/* Skip _track.tail because that should be _gps. */ for (curr = _track.tail; curr > point; --curr) { if (curr->unity) { unit2latlon(curr->unitx, curr->unity, lat2, lon2); @@ -76,7 +76,7 @@ void track_show_distance_from(Point * point) { gchar buffer[80]; -gfloat sum; +gdouble sum; sum = track_calculate_distance_from(point); @@ -117,20 +117,26 @@ if (_track.head != _track.tail) { * data, as well as calling osso_display_state_on() when we have the focus. * * If a non-zero time is given, then the current position (as taken from the - * _pos variable) is appended to _track with the given time. If time is zero, + * _gps variable) is appended to _track with the given time. If time is zero, * then _point_null is appended to _track with time zero (this produces a "break" * in the track). */ void -track_add(time_t time, gboolean newly_fixed) +track_add(GpsData *gps, gboolean newly_fixed) { gboolean show_directions = TRUE; gint announce_thres_unsquared; -if (abs((gint)_pos.unitx-_track.tail->unitx) > _draw_width || abs((gint)_pos.unity-_track.tail->unity) > _draw_width) { - /* If time != 0, update the nearest-waypoint data. */ - if (time && _route.head != _route.tail && - (newly_fixed ? (route_find_nearest_point(), TRUE) : route_update_nears(TRUE))) { +if (!gps) { + MACRO_PATH_INCREMENT_TAIL(_track); + *_track.tail=_point_null; + return; +} + +if (abs((gint)gps->unitx-_track.tail->unitx) > _draw_width || abs((gint)gps->unity-_track.tail->unity) > _draw_width) { + + /* If gps is available, update the nearest-waypoint data. */ + if (gps && _route.head != _route.tail && (newly_fixed ? (route_find_nearest_point(), TRUE) : route_update_nears(TRUE))) { /* Nearest waypoint has changed - re-render paths. */ map_render_paths(); MACRO_QUEUE_DRAW_AREA(); @@ -141,16 +147,14 @@ if (abs((gint)_pos.unitx-_track.tail->unitx) > _draw_width || abs((gint)_pos.uni /* Instead of calling map_render_paths(), we'll draw the new line * ourselves and call gtk_widget_queue_draw_area(). */ - map_render_segment(_gc[COLORABLE_TRACK], - _gc[COLORABLE_TRACK_BREAK], - _track.tail->unitx, _track.tail->unity, - _pos.unitx, _pos.unity); + map_render_segment(_gc[COLORABLE_TRACK], _gc[COLORABLE_TRACK_BREAK], + _track.tail->unitx, _track.tail->unity, gps->unitx, gps->unity); - if (time && _track.tail->unity) { + if (_track.tail->unity && _track.tail->unitx) { tx1 = unit2x(_track.tail->unitx); ty1 = unit2y(_track.tail->unity); - tx2 = unit2x(_pos.unitx); - ty2 = unit2y(_pos.unity); + tx2 = unit2x(gps->unitx); + ty2 = unit2y(gps->unity); gtk_widget_queue_draw_area(_map_widget, MIN(tx1, tx2) - _draw_width, MIN(ty1, ty2) - _draw_width, @@ -160,27 +164,23 @@ if (abs((gint)_pos.unitx-_track.tail->unitx) > _draw_width || abs((gint)_pos.uni } MACRO_PATH_INCREMENT_TAIL(_track); + _track.tail->unitx=gps->unitx; + _track.tail->unity=gps->unity; + _track.tail->time=gps->time; + _track.tail->altitude=gps->altitude; +} - if (time) - *_track.tail = _pos; - else - *_track.tail = _point_null; - - if (_autoroute_data.enabled && !_autoroute_data.in_progress && _near_point_dist_squared > 400) { - MACRO_BANNER_SHOW_INFO(_window, _("Recalculating directions...")); - _autoroute_data.in_progress = TRUE; - show_directions = FALSE; - g_idle_add((GSourceFunc) auto_route_dl_idle, NULL); - } - - /* Keep the display on. */ - KEEP_DISPLAY_ON(); +if (_autoroute_data.enabled && !_autoroute_data.in_progress && _near_point_dist_squared > 400) { + MACRO_BANNER_SHOW_INFO(_window, _("Recalculating directions...")); + _autoroute_data.in_progress = TRUE; + show_directions = FALSE; + g_idle_add((GSourceFunc)auto_route_dl_idle, NULL); } -announce_thres_unsquared=(20+(guint)_gps.speed)*_announce_notice_ratio*3; +announce_thres_unsquared=(20+(guint)gps->speed)*_announce_notice_ratio*3; /* Check if we should announce upcoming waypoints. */ -if (show_directions && time && _next_way_dist_squared < (announce_thres_unsquared * announce_thres_unsquared)) { +if (gps && show_directions && _next_way_dist_squared < (announce_thres_unsquared * announce_thres_unsquared)) { if (_enable_voice && g_strcmp0(_next_way->desc, _last_spoken_phrase)) { g_free(_last_spoken_phrase); _last_spoken_phrase=g_strdup(_next_way->desc); @@ -188,6 +188,9 @@ if (show_directions && time && _next_way_dist_squared < (announce_thres_unsquare } MACRO_BANNER_SHOW_INFO(_window, _next_way->desc); } + +/* Keep the display on if we are moving. */ +KEEP_DISPLAY_ON(); } void @@ -275,7 +278,7 @@ _track.wtail->desc = text; gboolean track_insert_mark(void) { -gfloat lat, lon; +gdouble lat, lon; gchar tmp1[16], tmp2[16], *p_latlon; GtkWidget *dialog; GtkWidget *table; @@ -295,7 +298,7 @@ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table = gtk_table_new(2, 2 gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Lat, Lon")), 0, 1, 0, 1, GTK_FILL, 0, 2, 4); gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); -unit2latlon(_pos.unitx, _pos.unity, lat, lon); +unit2latlon(_gps->unitx, _gps->unity, lat, lon); lat_format(_degformat, lat, tmp1); lon_format(_degformat, lon, tmp2); p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2); diff --git a/src/track.h b/src/track.h index 6cec294..51f761a 100644 --- a/src/track.h +++ b/src/track.h @@ -24,7 +24,7 @@ struct { void track_init(void); void track_deinit(void); -void track_add(time_t time, gboolean newly_fixed); +void track_add(GpsData *gps, gboolean newly_fixed); void track_insert_break(void); gboolean track_insert_mark(void); gboolean track_save(void); diff --git a/src/ui-common.c b/src/ui-common.c index bc9e968..3c8a094 100644 --- a/src/ui-common.c +++ b/src/ui-common.c @@ -17,6 +17,7 @@ #include #include "gtkgps.h" +#include "gtkcompass.h" #include "hildon-mapper.h" @@ -90,6 +91,10 @@ static const gchar *mapper_ui = " " " " " " +" " +" " +" " +" " " " " " " " @@ -115,7 +120,6 @@ static const gchar *mapper_ui = " " " " " " -" " " " " " " " @@ -144,7 +148,6 @@ static const gchar *mapper_ui = " " " " " " -" " " " " " " " @@ -154,8 +157,6 @@ static const gchar *mapper_ui = " " " " " " -" " -" " " " " " " " @@ -216,10 +217,13 @@ static GtkActionEntry ui_entries[] = { {"poi_settings", GTK_STOCK_PREFERENCES, N_("_Settings..."), NULL, NULL, NULL }, {"poi_add", GTK_STOCK_ADD, N_("_Add"), "A", NULL, G_CALLBACK(cb_poi_add) }, {"poi_quick_add", GTK_STOCK_ABOUT, N_("_Quick Add"), "E", NULL, G_CALLBACK(cb_poi_add) }, - {"poi_search", GTK_STOCK_FIND, N_("_Search..."), NULL, NULL, G_CALLBACK(cb_poi_search) }, {"poi_import", GTK_STOCK_OPEN, N_("_Import..."), NULL, NULL, NULL }, {"poi_export", GTK_STOCK_SAVE, N_("_Export..."), NULL, NULL, NULL }, + {"search", NULL, N_("_Search"), NULL, NULL, NULL }, + {"poi_search", GTK_STOCK_FIND, N_("_Search..."), NULL, NULL, G_CALLBACK(cb_poi_search) }, + {"search_address", GTK_STOCK_FIND, N_("Address..."), NULL, NULL, G_CALLBACK(menu_cb_search_address) }, + {"map", NULL, N_("_Map"), NULL, NULL, NULL }, {"map_maps", NULL, N_("_Maps"), NULL, NULL, NULL }, {"map_manager", NULL, N_("Manager..."), NULL, NULL, G_CALLBACK(menu_cb_mapman) }, @@ -237,13 +241,11 @@ static GtkActionEntry ui_entries[] = { {"goto_home", GTK_STOCK_HOME, N_("_Home"), "H", NULL, G_CALLBACK(menu_cb_goto_home) }, {"goto_destination", GTK_STOCK_JUMP_TO, N_("_Destination"), "J", NULL, G_CALLBACK(menu_cb_goto_destination) }, {"goto_gps", NULL, N_("_GPS"), "G", NULL, G_CALLBACK(menu_cb_goto_gps) }, - {"search_address", GTK_STOCK_FIND, N_("Address..."), NULL, NULL, G_CALLBACK(menu_cb_search_address) }, {"goto_latlon", NULL, N_("Lat/Lon"), NULL, NULL, G_CALLBACK(menu_cb_goto_latlon) }, {"goto_nextway", NULL, N_("Next Waypoint"), NULL, NULL, G_CALLBACK(menu_cb_goto_nextway) }, {"goto_nearpoi", NULL, N_("Near POI"), NULL, NULL, G_CALLBACK(menu_cb_goto_nearpoi) }, {"gps", NULL, N_("Gp_s"), NULL, NULL, NULL }, - {"gps_details", GTK_STOCK_INFO, N_("_Details..."), NULL, NULL, G_CALLBACK(menu_cb_gps_details) }, {"gps_settings", NULL, N_("_Settings..."), NULL, NULL, NULL }, }; static guint n_ui_entries = G_N_ELEMENTS (ui_entries); @@ -745,16 +747,16 @@ gtk_paned_add2(GTK_PANED(hbox), _map_widget); /* GPS Tab */ vbox = gtk_vbox_new(FALSE, 0); label = gtk_label_new("Gps"); -_gps_sat_view = gtk_gps_new(GTK_GPS_MODE_SKY, &_gps); +_gps_sat_view = gtk_gps_new(GTK_GPS_MODE_SKY, _gps); gtk_box_pack_start(GTK_BOX(vbox), _gps_sat_view, TRUE, TRUE, 0); -_gps_sat_view = gtk_gps_new(GTK_GPS_MODE_SIGNAL, &_gps); +_gps_sat_view = gtk_gps_new(GTK_GPS_MODE_SIGNAL, _gps); gtk_box_pack_start(GTK_BOX(vbox), _gps_sat_view, TRUE, TRUE, 0); ui_notebook.gps=gtk_notebook_append_page(notebook, vbox, label); /* Heading Tab */ vbox = gtk_vbox_new(FALSE, 0); label = gtk_label_new("Heading"); -_tab_compass = gtk_compass_new(&_gps); +_tab_compass = gtk_compass_new(_gps); gtk_box_pack_start(GTK_BOX(vbox), _tab_compass, TRUE, TRUE, 0); ui_notebook.heading=gtk_notebook_append_page(notebook, vbox, label); diff --git a/src/utils.h b/src/utils.h index 9e9236b..6bfaa1b 100644 --- a/src/utils.h +++ b/src/utils.h @@ -91,11 +91,6 @@ } \ } -#define DISTANCE_SQUARED(a, b) \ - ((guint64)((((gint64)(b).unitx)-(a).unitx)*(((gint64)(b).unitx)-(a).unitx))\ - + (guint64)((((gint64)(b).unity)-(a).unity)*(((gint64)(b).unity)-(a).unity))) - - #ifdef WITH_OSSO #define KEEP_DISPLAY_ON() { \ /* Note that the flag means keep on ONLY when fullscreen. */ \ -- 2.39.5