From fee4e14210fe1031c807a4f93c905f061b44d532 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Mon, 1 Dec 2014 20:58:44 +0000 Subject: [PATCH] Support showing a climb (vertical speed) value in the statusbar. Requires adding 'B' to a format message code. Presently choose not to store a vertical speed in trackpoints, as the climb value is only from GPSD. On tracks the value is calculated from the altitude and time difference. --- help/C/viking.xml | 1 + src/vikgpslayer.c | 2 +- src/viktrwlayer.c | 3 ++- src/vikutils.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- src/vikutils.h | 2 +- 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/help/C/viking.xml b/help/C/viking.xml index 58bc72cf..aa170b59 100644 --- a/help/C/viking.xml +++ b/help/C/viking.xml @@ -3324,6 +3324,7 @@ Accept: */* K = Some text to display at the start of the message - Trkpt A = Altitude of a Trackpoint S = Speed of a Trackpoint + B = Vertical Speed (Climb) C = Course of a Trackpoint L = Location of a Trackpoint T = Time of a Trackpoint diff --git a/src/vikgpslayer.c b/src/vikgpslayer.c index 207f487f..fd065de0 100644 --- a/src/vikgpslayer.c +++ b/src/vikgpslayer.c @@ -1590,7 +1590,7 @@ static void update_statusbar ( VikGpsLayer *vgl, VikWindow *vw ) need2free = TRUE; } - gchar *msg = vu_trackpoint_formatted_message ( statusbar_format_code, vgl->trkpt, vgl->trkpt_prev, vgl->realtime_track ); + gchar *msg = vu_trackpoint_formatted_message ( statusbar_format_code, vgl->trkpt, vgl->trkpt_prev, vgl->realtime_track, vgl->last_fix.fix.climb ); vik_statusbar_set_message ( vik_window_get_statusbar (vw), VIK_STATUSBAR_INFO, msg ); g_free ( msg ); diff --git a/src/viktrwlayer.c b/src/viktrwlayer.c index 4e3c3d18..3b33acba 100644 --- a/src/viktrwlayer.c +++ b/src/viktrwlayer.c @@ -2999,13 +2999,14 @@ static void set_statusbar_msg_info_trkpt ( VikTrwLayer *vtl, VikTrackpoint *trkp { gchar *statusbar_format_code = NULL; gboolean need2free = FALSE; + VikTrackpoint *trkpt_prev = NULL; if ( !a_settings_get_string ( VIK_SETTINGS_TRKPT_SELECTED_STATUSBAR_FORMAT, &statusbar_format_code ) ) { // Otherwise use default statusbar_format_code = g_strdup ( "KEATDN" ); need2free = TRUE; } - gchar *msg = vu_trackpoint_formatted_message ( statusbar_format_code, trkpt, NULL, vtl->current_tp_track ); + gchar *msg = vu_trackpoint_formatted_message ( statusbar_format_code, trkpt, trkpt_prev, vtl->current_tp_track, NAN ); vik_statusbar_set_message ( vik_window_get_statusbar (VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(vtl))), VIK_STATUSBAR_INFO, msg ); g_free ( msg ); diff --git a/src/vikutils.c b/src/vikutils.c index 1ec8b017..ab950642 100644 --- a/src/vikutils.c +++ b/src/vikutils.c @@ -47,12 +47,13 @@ * @trkpt: The trackpoint for which the message is generated about * @trkpt_prev: A trackpoint (presumed previous) for interpolating values with the other trackpoint (such as speed) * @trk: The track in which the trackpoints reside + * @climb: Vertical speed (Out of band (i.e. not in a trackpoint) value for display currently only for GPSD usage) * * TODO: One day replace this cryptic format code with some kind of tokenizer parsing * thus would make it more user friendly and maybe even GUI controlable. * However for now at least there is some semblance of user control */ -gchar* vu_trackpoint_formatted_message ( gchar *format_code, VikTrackpoint *trkpt, VikTrackpoint *trkpt_prev, VikTrack *trk ) +gchar* vu_trackpoint_formatted_message ( gchar *format_code, VikTrackpoint *trkpt, VikTrackpoint *trkpt_prev, VikTrack *trk, gdouble climb ) { if ( !trkpt ) return NULL; @@ -137,6 +138,48 @@ gchar* vu_trackpoint_formatted_message ( gchar *format_code, VikTrackpoint *trkp break; } + case 'B': { + gdouble speed = 0.0; + gchar *speedtype = NULL; + if ( isnan(climb) && trkpt_prev ) { + if ( trkpt->has_timestamp && trkpt_prev->has_timestamp ) { + if ( trkpt->timestamp != trkpt_prev->timestamp ) { + // Work out from previous trackpoint altitudes and time difference + // 'speed' can be negative if going downhill + speed = (trkpt->altitude - trkpt_prev->altitude) / ABS(trkpt->timestamp - trkpt_prev->timestamp); + speedtype = g_strdup ( "*" ); // Interpolated + } + else + speedtype = g_strdup ( "**" ); // Unavailable + } + else + speedtype = g_strdup ( "**" ); + } + else { + speed = climb; + speedtype = g_strdup ( "" ); + } + switch (speed_units) { + case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR: + speed = VIK_MPS_TO_KPH(speed); + break; + case VIK_UNITS_SPEED_MILES_PER_HOUR: + speed = VIK_MPS_TO_MPH(speed); + break; + case VIK_UNITS_SPEED_KNOTS: + speed = VIK_MPS_TO_KNOTS(speed); + break; + default: + // VIK_UNITS_SPEED_METRES_PER_SECOND: + // Already in m/s so nothing to do + break; + } + // Go for 2dp as expect low values for vertical speeds + values[i] = g_strdup_printf ( _("%sClimb%s %.2f%s"), separator, speedtype, speed, speed_units_str ); + g_free ( speedtype ); + break; + } + case 'A': { vik_units_height_t height_units = a_vik_get_units_height (); switch (height_units) { diff --git a/src/vikutils.h b/src/vikutils.h index 3fc94ee8..9fd3b7e0 100644 --- a/src/vikutils.h +++ b/src/vikutils.h @@ -27,7 +27,7 @@ G_BEGIN_DECLS -gchar* vu_trackpoint_formatted_message ( gchar *format_code, VikTrackpoint *trkpt, VikTrackpoint *trkpt_prev, VikTrack *trk ); +gchar* vu_trackpoint_formatted_message ( gchar *format_code, VikTrackpoint *trkpt, VikTrackpoint *trkpt_prev, VikTrack *trk, gdouble climb ); void vu_check_latest_version ( GtkWindow *window ); -- 2.39.5