summaryrefslogtreecommitdiff
path: root/xgpsspeed.c
diff options
context:
space:
mode:
authorChris Kuethe <chris.kuethe@gmail.com>2006-02-15 06:50:39 +0000
committerChris Kuethe <chris.kuethe@gmail.com>2006-02-15 06:50:39 +0000
commite751d4cb05a28e9dd6e15fa96e0aadf81aa796ce (patch)
tree1084b71768ca5d78ae37ad6e6e7b0c64b1783a01 /xgpsspeed.c
parent239ee1189e25e3d0d9ff220d5f8441c99945144c (diff)
downloadgpsd-e751d4cb05a28e9dd6e15fa96e0aadf81aa796ce.tar.gz
Bug fixes for xgpsspeed
>From Bill Marr on gpsd-dev .------------------------------ Attached is a patch against 'xgpsspeed.c' in the 2.30 release of 'gpsd'. It fixes the following bugs in the 'xgpsspeed' application: (1) Missing limit-checks on the tachometer widget can result in the tachometer needle spinning madly if invalid vehicle speeds are reported by 'gpsd'. (2) The display of speed units (e.g. "Miles per Hour") above the "speedometer" was erroneously always displaying "Km per Hour", regardless of the speed units in use. Furthermore, although there was already a provision to select "knots" as the speed units ("-speedunits knots"), there was never any code to display the proper text! (3) An erroneous conversion factor (the reciprocal of the correct value) was used to convert the native 'meters per second' GPS-reported speed into knots. This results in an erroneous needle position when "-speedunits knots" has been specified on the command line. .------------------------------
Diffstat (limited to 'xgpsspeed.c')
-rw-r--r--xgpsspeed.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/xgpsspeed.c b/xgpsspeed.c
index bb55d5de..3564e430 100644
--- a/xgpsspeed.c
+++ b/xgpsspeed.c
@@ -36,7 +36,12 @@ static Widget toplevel;
static void update_display(struct gps_data_t *gpsdata,
char *buf UNUSED, size_t len UNUSED, int level UNUSED)
{
- (void)TachometerSetValue(tacho, (int)rint(gpsdata->fix.speed*speedfactor));
+ int temp_int = (int)rint(gpsdata->fix.speed * speedfactor);
+
+ if (temp_int < 0) temp_int = 0;
+ else if (temp_int > 100) temp_int = 100;
+
+ (void)TachometerSetValue(tacho, temp_int);
}
static void handle_input(XtPointer client_data UNUSED,
@@ -88,7 +93,7 @@ int main(int argc, char **argv)
if (strcmp(speedunits, "kph")==0)
speedfactor = MPS_TO_KPH;
else if (strcmp(speedunits, "knots")==0)
- speedfactor = 1/MPS_TO_KNOTS;
+ speedfactor = MPS_TO_KNOTS;
while ((option = getopt(argc, argv, "hv")) != -1) {
switch (option) {
@@ -140,10 +145,13 @@ int main(int argc, char **argv)
(void)XtCreateManagedWidget("title", labelWidgetClass, base, args, 1);
/**** Label widget ****/
- if (speedfactor == KNOTS_TO_MPH)
+ if (speedfactor == MPS_TO_MPH)
(void)XtSetArg(args[0], XtNlabel, "Miles per Hour");
- else
+ else if (speedfactor == MPS_TO_KPH)
(void)XtSetArg(args[0], XtNlabel, "Km per Hour");
+ else
+ (void)XtSetArg(args[0], XtNlabel, "Knots");
+
/*@ +immediatetrans +usedef +observertrans +statictrans @*/
(void)XtCreateManagedWidget("name", labelWidgetClass, base, args, 1);