+PKGS = gtk+-2.0 liblocation gconf-2.0
CC = gcc
LINK = gcc
CFLAGS = -g -Wall -O0
-INCPATH = `pkg-config --cflags gtk+-2.0 liblocation`
-LIBS = `pkg-config --libs gtk+-2.0 liblocation`
+INCPATH = `pkg-config --cflags $(PKGS)`
+LIBS = `pkg-config --libs $(PKGS)`
SOURCES = main.c callbacks.c ui.c util.c
OBJECTS = main.o callbacks.o ui.o util.o
#include <hildon/hildon-program.h>
#include <hildon/hildon-window.h>
-typedef struct _AppData AppData;
-struct _AppData {
+typedef struct _AppData {
HildonProgram *program;
HildonWindow *window;
- GtkImage* image_array[10]; // stores the images
- GtkImage* speed_array[3]; // actual images that are shown
-};
+ GtkWidget* image_array[10]; // original images from the disk
+ GtkWidget* digit_array[3]; // actual images that are shown as speed
+} AppData;
#endif /* APPDATA_H_ */
#include "appdata.h"
#include "util.h"
-// this is just here for debugging and tracing purposes
+// this is just here for debugging
static void print_location(LocationGPSDevice* device) {
g_print("Latitude: %.2f\n"
"Longitude: %.2f\n"
"Altitude: %.2f\n"
- "Speed: %d",
+ "Speed: %d\n",
device->fix->latitude,
device->fix->longitude,
device->fix->altitude,
}
void location_changed(LocationGPSDevice* device, gpointer data) {
- print_location(device);
+ //print_location(device);
AppData* appdata = (AppData*) data;
- if(device->fix && LOCATION_GPS_DEVICE_SPEED_SET) {
- g_print("Speed is %f km/h", device->fix->speed);
+ 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);
}
}
+speedometer (0.3-alpha2) unstable; urgency=low
+
+ * Fixes to interpret_speed_from_gps.
+
+ -- Wellu Mäkinen <wellu@wellu.org> Tue, 9 Sep 2008 14:41:50 +0300
+
speedometer (0.3-alpha1) unstable; urgency=low
* First alpha release.
load_images(appdata);
// set display to 000
- reset_speed(appdata);
+ load_initial_pixbufs(appdata);
// create ui structure
create_ui(appdata);
g_thread_init(NULL);
+ show_postcard_dialog();
+
//g_idle_add(randomize, appdata);
start_gps(appdata);
void load_images(AppData *appdata) {
g_print("Loading images\n");
- int i = 0;
+ guint i = 0;
while(i < 10) {
- char* path = malloc(30);
+ char* path = g_malloc(30);
g_sprintf(path, IMAGE_PATH, i);
- appdata->image_array[i] = (GtkImage*) gtk_image_new_from_file(path);
+ appdata->image_array[i] = gtk_image_new_from_file(path);
g_print(path);
g_print("\n");
- free(path);
+ g_free(path);
i++;
}
}
-void reset_speed(AppData* appdata) {
+void load_initial_pixbufs(AppData* appdata) {
- GdkPixbuf* zero = gtk_image_get_pixbuf(appdata->image_array[0]);
+ GdkPixbuf* zero = gtk_image_get_pixbuf(GTK_IMAGE(appdata->image_array[0]));
- appdata->speed_array[0] = (GtkImage*) gtk_image_new_from_pixbuf(zero);
- appdata->speed_array[1] = (GtkImage*) gtk_image_new_from_pixbuf(zero);
- appdata->speed_array[2] = (GtkImage*) gtk_image_new_from_pixbuf(zero);
+ appdata->digit_array[0] = GTK_WIDGET(gtk_image_new_from_pixbuf(zero));
+ appdata->digit_array[1] = GTK_WIDGET(gtk_image_new_from_pixbuf(zero));
+ appdata->digit_array[2] = GTK_WIDGET(gtk_image_new_from_pixbuf(zero));
}
void set_nth_digit(AppData* appdata, guint n, guint value) {
//assert(nth >= 0 && nth < 3);
- GtkImage* image = appdata->speed_array[n];
- GdkPixbuf* buf = gtk_image_get_pixbuf(appdata->image_array[value]);
- gtk_image_set_from_pixbuf(image, buf);
- gtk_widget_queue_draw(GTK_WIDGET(appdata->speed_array[n]));
+ GtkWidget* image = appdata->digit_array[n];
+ GdkPixbuf* buf = gtk_image_get_pixbuf(GTK_IMAGE(appdata->image_array[value]));
+ gtk_image_set_from_pixbuf(GTK_IMAGE(image), buf);
}
-guint randomize(AppData* appdata) {
+void repaint_all_digits(AppData* appdata) {
+ gtk_widget_queue_draw(GTK_WIDGET(appdata->digit_array[0]));
+ gtk_widget_queue_draw(GTK_WIDGET(appdata->digit_array[1]));
+ gtk_widget_queue_draw(GTK_WIDGET(appdata->digit_array[2]));
+}
+
+void randomize(AppData* appdata) {
gint32 n = g_random_int_range(0, 3);
- GtkImage* image = appdata->speed_array[n];
+ GtkWidget* image = appdata->digit_array[n];
gint32 m = g_random_int_range(0, 10);
- GdkPixbuf* buf = gtk_image_get_pixbuf(appdata->image_array[m]);
+ GdkPixbuf* buf = gtk_image_get_pixbuf(GTK_IMAGE(appdata->image_array[m]));
g_print("Setting number %d to %d.. ", n+1, m);
- gtk_image_set_from_pixbuf(image, buf);
- gtk_widget_queue_draw(GTK_WIDGET(appdata->speed_array[n]));
-
- return TRUE;
+ gtk_image_set_from_pixbuf(GTK_IMAGE(image), buf);
+ gtk_widget_queue_draw(appdata->digit_array[n]);
}
void create_ui(AppData* appdata) {
appdata->window);
// add three digits to the hbox
- gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(appdata->speed_array[0]), FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(appdata->speed_array[1]), FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(appdata->speed_array[2]), FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(appdata->digit_array[0]), FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(appdata->digit_array[1]), FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(appdata->digit_array[2]), FALSE, FALSE, 0);
gtk_box_pack_start_defaults(GTK_BOX(vbox), top_e); // add event box on top
gtk_box_pack_start_defaults(GTK_BOX(vbox), hbox); // numbers to the middle
void load_images(AppData *appdata);
-void reset_speed(AppData* appdata);
+void load_initial_pixbufs(AppData* appdata);
void set_nth_digit(AppData* appdata, guint n, guint value);
-guint randomize(AppData* appdata);
+// queues repaint of all digits on the screen
+void repaint_all_digits(AppData* appdata);
+
+void randomize(AppData* appdata);
void create_ui(AppData* appdata);
#include <location/location-gps-device.h>
#include <location/location-gpsd-control.h>
+#include <gconf/gconf-client.h>
#include "util.h"
#include "appdata.h"
#include "callbacks.h"
#include "ui.h"
+#define GCONF_DIR "/apps/Maemo/speedometer/"
+
static LocationGPSDevice *device = NULL;
static LocationGPSDControl *control = NULL;
location_gpsd_control_request_status(control);
if(control->can_control) {
location_gpsd_control_start(control);
- }
+ }
#endif // __arm__
}
void interpret_speed_from_gps(AppData* appdata, gdouble speed) {
- // first let's convert the number to characters
- gchar* c_digits = calloc(30, 1);
+ // 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
+
+ g_print("Original speed %c, splitted speed %c and %c\n", cspeed, ckm, cm);
+
+ // 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);
- g_sprintf(c_digits, "%f", speed);
- g_print("interpret_speed_from_gps: %s", c_digits);
+ guint i = 2;
+ guint pspeedl = strlen(padded);
- int i = 0;
- while(i < 3) {
- guint value = g_ascii_digit_value(c_digits[i]);
+ while(i+1) {
+ guint value = g_ascii_digit_value(padded[pspeedl]);
set_nth_digit(appdata, i, value);
- i++;
+ i--;
+ }
+ repaint_all_digits(appdata);
+
+ g_free(padded);
+ g_free(cspeed);
+ g_strfreev(splitted);
+}
+
+void show_postcard_dialog() {
+ GConfClient* client = gconf_client_get_default();
+ g_assert(GCONF_IS_CLIENT(client));
+
+
+ GConfValue* gcvalue = NULL;
+ gcvalue = gconf_client_get_without_default(client, GCONF_DIR "disclaimer", NULL);
+
+ if(gcvalue == NULL) {
+ g_warning("key %sdisclaimer not found\n", GCONF_DIR);
+ gconf_client_set_bool(client, GCONF_DIR "disclaimer", TRUE, NULL);
+ }
+ else {
+ g_print("key %sdisclaimer was found\n", GCONF_DIR);
}
- g_free(c_digits);
+ g_object_unref(client);
}
// converts the speed from the gps
void interpret_speed_from_gps(AppData* appdata, gdouble speed);
+// shows instructions how to send me a postcard
+void show_postcard_dialog();
+
#endif /* UTIL_H_ */