0.4 release
authorwellu <wellu@wellu.org>
Thu, 25 Sep 2008 13:43:09 +0000 (13:43 +0000)
committerwellu <wellu@wellu.org>
Thu, 25 Sep 2008 13:43:09 +0000 (13:43 +0000)
git-svn-id: file:///svnroot/speedometer/trunk@36 df364472-da61-43ef-8a67-511c89aa921b

Makefile
callbacks.c
debian/changelog
util.c

index e13141e..9c1b324 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 PKGS     = gtk+-2.0 liblocation gconf-2.0
 CC       = gcc
 LINK     = gcc
 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)`
 
 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
 
 
 TARGET   = speedometer
 
 
-
-
-
-
-
-
-
 all: $(TARGET)
 
 $(TARGET):  $(OBJECTS)
 all: $(TARGET)
 
 $(TARGET):  $(OBJECTS)
-       $(LINK) -o $(TARGET) $(OBJECTS) $(LIBS)
+       $(LINK) $(LIBS) $(OBJECTS) -o $(TARGET) 
 
 $(OBJECTS): $(SOURCES)
 
 $(OBJECTS): $(SOURCES)
-       $(CC) -c $(SOURCES) $(INCPATH)
+       $(CC) $(INCPATH) $(CFLAGS) -c $(SOURCES) 
 
 clean:
        rm -f $(OBJECTS) $(TARGET)
 
 clean:
        rm -f $(OBJECTS) $(TARGET)
index 950c202..479cca7 100644 (file)
@@ -16,6 +16,8 @@
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ****/
 
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ****/
 
+#include <math.h>
+
 #include "callbacks.h"
 #include "appdata.h"
 #include "util.h"
 #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);
 
 void location_changed(LocationGPSDevice* device, gpointer data) {
        //print_location(device);
+       g_assert(data);
+       g_assert(device);
 
        AppData* appdata = (AppData*) data;
 
 
        AppData* appdata = (AppData*) data;
 
+       // check for NaN before passing values
        if(device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) {
        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);
+                       }
        }
 }
 
        }
 }
 
index 00c5d43..541ad99 100644 (file)
@@ -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 <wellu@wellu.org>  Thu, 25 Sep 2008 16:39:02 +0300
+
 speedometer (0.3-alpha3) unstable; urgency=low
 
   * Drop me a postcard -dialog implemented with GConf flag.
 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 (file)
--- 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 <http://www.gnu.org/licenses/>.
  ****/
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
  ****/
-
+#include <math.h>
 #include <location/location-gps-device.h>
 #include <location/location-gpsd-control.h>
 #include <gconf/gconf-client.h>
 #include <location/location-gps-device.h>
 #include <location/location-gpsd-control.h>
 #include <gconf/gconf-client.h>
@@ -58,50 +58,25 @@ void stop_gps(AppData* appdata) {
 
 void interpret_speed_from_gps(AppData* appdata, gdouble speed) {
        g_assert(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--;
                i--;
+               set_nth_digit(appdata, i, g_ascii_digit_value(charspeed[i]));
        }
        repaint_all_digits(appdata);
 
        }
        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,
 static show_dialog() {
        GtkWidget *dialog = gtk_message_dialog_new(
                        NULL,