From 98fd8d3a7b9b4d1b93dd331840d8e5fe064ff72d Mon Sep 17 00:00:00 2001 From: wellu Date: Thu, 25 Sep 2008 13:43:09 +0000 Subject: [PATCH] 0.4 release git-svn-id: file:///svnroot/speedometer/trunk@36 df364472-da61-43ef-8a67-511c89aa921b --- Makefile | 13 +++---------- callbacks.c | 10 ++++++++-- debian/changelog | 7 +++++++ util.c | 47 +++++++++++------------------------------------ 4 files changed, 29 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index e13141e..9c1b324 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ PKGS = gtk+-2.0 liblocation gconf-2.0 CC = gcc LINK = gcc -CFLAGS = -g -Wall -O0 +CFLAGS = -g INCPATH = `pkg-config --cflags $(PKGS)` LIBS = `pkg-config --libs $(PKGS)` @@ -10,20 +10,13 @@ OBJECTS = main.o callbacks.o ui.o util.o TARGET = speedometer - - - - - - - all: $(TARGET) $(TARGET): $(OBJECTS) - $(LINK) -o $(TARGET) $(OBJECTS) $(LIBS) + $(LINK) $(LIBS) $(OBJECTS) -o $(TARGET) $(OBJECTS): $(SOURCES) - $(CC) -c $(SOURCES) $(INCPATH) + $(CC) $(INCPATH) $(CFLAGS) -c $(SOURCES) clean: rm -f $(OBJECTS) $(TARGET) diff --git a/callbacks.c b/callbacks.c index 950c202..479cca7 100644 --- a/callbacks.c +++ b/callbacks.c @@ -16,6 +16,8 @@ along with this program. If not, see . ****/ +#include + #include "callbacks.h" #include "appdata.h" #include "util.h" @@ -34,12 +36,16 @@ static void print_location(LocationGPSDevice* device) { void location_changed(LocationGPSDevice* device, gpointer data) { //print_location(device); + g_assert(data); + g_assert(device); AppData* appdata = (AppData*) data; + // check for NaN before passing values if(device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) { - g_print("Speed is %.2f km/h\n", device->fix->speed); - interpret_speed_from_gps(appdata, device->fix->speed); + if(!isnan(device->fix->speed)) { + interpret_speed_from_gps(appdata, device->fix->speed); + } } } diff --git a/debian/changelog b/debian/changelog index 00c5d43..541ad99 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +speedometer (0.4) unstable; urgency=low + + * Simplified interpret_speed_from_gps a lot. + * Proper NaN handling in all floating point numbers. + + -- Wellu Mäkinen Thu, 25 Sep 2008 16:39:02 +0300 + speedometer (0.3-alpha3) unstable; urgency=low * Drop me a postcard -dialog implemented with GConf flag. diff --git a/util.c b/util.c index 3c90f9f..ed20591 100644 --- a/util.c +++ b/util.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ****/ - +#include #include #include #include @@ -58,50 +58,25 @@ void stop_gps(AppData* appdata) { void interpret_speed_from_gps(AppData* appdata, gdouble speed) { g_assert(appdata); + g_assert(!isnan(speed)); - // if speed is below one then it's zero - if(speed < 1) { - set_nth_digit(appdata, 0, 0); - set_nth_digit(appdata, 1, 0); - set_nth_digit(appdata, 2, 0); - return; - } - - // speed => 1 - // first let's convert the number to string - gchar* cspeed = g_malloc(30); // alloc - g_sprintf(cspeed, "%f", speed); - - // split the string using comma as delimiter - gchar** splitted = g_strsplit(cspeed, ",", 2); // alloc - - gchar* ckm = splitted[0]; // contains the km/h part e.g 123 assuming speed was 123,034510 - gchar* cm = splitted[1]; // contains the m/h part e.g 034510 assuming speed was 123,034510 + // convert float to a 6 digits (including dot) wide string with leading zeros + gchar* charspeed = g_malloc(10); // alloc + g_sprintf(charspeed, "%0*.2f", 6, speed); - g_print("Original speed %c, splitted speed %c and %c\n", cspeed, ckm, cm); + g_print("Speed is %s km/h\n", charspeed); - // we need to pad km part in order to ensure it is *atleast* 3 digits long - gchar* padding = "00"; - gchar* padded = g_strconcat(padding, cm, NULL); // alloc - - g_print("Original speed %c, padded speed %c (km) and %c (m)\n", cspeed, padded, cm); - - - guint i = 2; - guint pspeedl = strlen(padded); - - while(i+1) { - guint value = g_ascii_digit_value(padded[pspeedl]); - set_nth_digit(appdata, i, value); + guint i = 3; + while(i) { i--; + set_nth_digit(appdata, i, g_ascii_digit_value(charspeed[i])); } repaint_all_digits(appdata); - g_free(padded); - g_free(cspeed); - g_strfreev(splitted); + g_free(charspeed); } + static show_dialog() { GtkWidget *dialog = gtk_message_dialog_new( NULL, -- 1.7.9.5