summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2005-01-03 16:23:24 +0000
committerEric S. Raymond <esr@thyrsus.com>2005-01-03 16:23:24 +0000
commit693df1b6a6c838074eef2c94f2552ab7de018419 (patch)
tree89c5ddef17e655d87a33e59d485c39b2f78d24f8
parent05fcee1c373954095a7be95756bd92c7d7105255 (diff)
downloadgpsd-693df1b6a6c838074eef2c94f2552ab7de018419.tar.gz
James Cameron's --unit patch.
-rw-r--r--gps.h2
-rw-r--r--gpsd.xml15
-rw-r--r--xgpsspeed.c35
3 files changed, 37 insertions, 15 deletions
diff --git a/gps.h b/gps.h
index f892badb..777b8a1f 100644
--- a/gps.h
+++ b/gps.h
@@ -108,7 +108,7 @@ void gps_set_raw_hook(struct gps_data_t *gpsdata, void (*hook)(char *buf));
#define METERS_TO_FEET 3.2808399 /* Imperial (U.S./British) feet */
#define METERS_TO_MILES 0.00062137119 /* International miles */
#define KNOTS_TO_MPH 1.1507794 /* International miles and knots */
-#define KNOTS_TO_KMPH 1.852 /* Kilometers and knots */
+#define KNOTS_TO_KPH 1.852 /* International knots */
#define PI 3.14159265358979323846 /* for radians-to-degrees and vv. */
/* gps_open() error return values */
diff --git a/gpsd.xml b/gpsd.xml
index 8f730da9..5bd538d0 100644
--- a/gpsd.xml
+++ b/gpsd.xml
@@ -33,7 +33,6 @@ and speedometer</refpurpose>
<cmdsynopsis>
<command>xgps</command>
<arg choice='opt'><replaceable>X-options</replaceable></arg>
- <arg choice='opt'>-k </arg>
<arg choice='opt'>-h </arg>
<arg choice='opt'>-v </arg>
<arg choice='opt'><replaceable>server</replaceable></arg>
@@ -44,6 +43,7 @@ and speedometer</refpurpose>
<arg choice='opt'>-nc <replaceable>X-color</replaceable></arg>
<arg choice='opt'>-h </arg>
<arg choice='opt'>-v </arg>
+ <arg choice='opt'>--units <replaceable>kph</replaceable></arg>
<arg choice='opt'><replaceable>server</replaceable></arg>
</cmdsynopsis>
@@ -306,11 +306,6 @@ confused state but can be soft-reset by pulling down DTR.</para>
current GPS animation and (for GPSes that support the feature) the
locations of accessible satellites.</para>
-<para><application>xgps</application> accepts a -k option to change
-speed reporting to use km/h as a unit, rather than mp/h. This option
-is experimental and may be dropped or replaced by an X resource
-un a future release.</para>
-
<para><application>xgps</application> accepts an -h option as for
<application>gpsd</application>, or a -v option to dump the package
version and exit. An optional argument may specify an
@@ -325,9 +320,11 @@ direct-connect to the serial device has been removed.</para>
position information from the GPS. It accepts an -h option and
optional argument as for <application>gps</application>, or a -v
option to dump the package version and exit. Additionally, it accepts
--rv (reverse video) and -nc (needle color) options. The misfeature of
-previous versions that allowed it to direct-connect to the serial
-device has been removed.</para>
+-rv (reverse video) and -nc (needle color) options.</para>
+
+<para>The --units option can be used to set the units for display;
+follow the keyword with either kph for kilometres per hour, or mph for
+miles per hour. The default is miles per hour.</para>
</refsect2>
</refsect1>
diff --git a/xgpsspeed.c b/xgpsspeed.c
index 2031d68b..532748ed 100644
--- a/xgpsspeed.c
+++ b/xgpsspeed.c
@@ -9,6 +9,7 @@
#include <X11/Shell.h>
#include <X11/Xaw/Label.h>
#include <X11/Xaw/Paned.h>
+#include <Xm/XmStrDefs.h>
#include <Tachometer.h>
#include "xgpsspeed.icon"
@@ -19,12 +20,14 @@ static XrmOptionDescRec options[] = {
{"-rv", "*reverseVideo", XrmoptionNoArg, "TRUE"},
{"-nc", "*needleColor", XrmoptionSepArg, NULL},
{"-needlecolor","*needleColor", XrmoptionSepArg, NULL},
+{"--units", "*units", XrmoptionSepArg, NULL},
};
String fallback_resources[] = {NULL};
static struct gps_data_t *gpsdata;
static Widget tacho;
-static double speedfactor = KNOTS_TO_MPH;
+static double speedfactor;
+static Widget toplevel;
static void update_display(char *buf UNUSED)
{
@@ -37,27 +40,49 @@ static void handle_input(XtPointer client_data UNUSED,
gps_poll(gpsdata);
}
+static char *get_resource(char *name, char *default_value)
+{
+ XtResource xtr;
+ char *value = NULL;
+
+ xtr.resource_name = name;
+ xtr.resource_class = "AnyClass";
+ xtr.resource_type = XmRString;
+ xtr.resource_size = sizeof(String);
+ xtr.resource_offset = 0;
+ xtr.default_type = XmRImmediate;
+ xtr.default_addr = default_value;
+ XtGetApplicationResources(toplevel, &value, &xtr, 1, NULL, 0);
+ if (value) return value;
+ return default_value;
+}
+
int main(int argc, char **argv)
{
Arg args[10];
XtAppContext app;
int option;
- char *colon, *server = NULL, *port = DEFAULT_GPSD_PORT;
- Widget toplevel, base;
+ char *colon, *server = NULL, *port = DEFAULT_GPSD_PORT, *units;
+ Widget base;
toplevel = XtVaAppInitialize(&app, "xpsspeed.ad",
options, XtNumber(options),
&argc, argv, fallback_resources, NULL);
+
+ speedfactor = KNOTS_TO_MPH;
+ units = get_resource("units", "mph");
+ if (!strcmp(units, "kph")) speedfactor = KNOTS_TO_KPH;
+
while ((option = getopt(argc, argv, "?hkv")) != -1) {
switch (option) {
case 'k':
- speedfactor = KNOTS_TO_KMPH;
+ speedfactor = KNOTS_TO_KPH;
break;
case 'v':
printf("xgpsspeed %s\n", VERSION);
exit(0);
case 'h': case '?': default:
- fputs("usage: gps [-?] [-h] [-v] [-rv] [-nc] [-needlecolor] [server[:port]]\n", stderr);
+ fputs("usage: gps [-?] [-h] [-v] [-rv] [-nc] [-needlecolor] [--units {kph,mph}] [server[:port]]\n", stderr);
exit(1);
}
}