2 Speedometer, shows your current speed using GPS
3 Copyright (C) 2008 Wellu Mäkinen <wellu@wellu.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <location/location-gps-device.h>
20 #include <location/location-gpsd-control.h>
21 #include <gconf/gconf-client.h>
25 #include "callbacks.h"
28 #define GCONF_KEY "/apps/Maemo/speedometer/disclaimer"
30 static LocationGPSDevice *device = NULL;
31 static LocationGPSDControl *control = NULL;
33 void start_gps(AppData* appdata) {
37 device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
38 g_signal_connect(device, "changed", G_CALLBACK(location_changed), appdata);
40 control = location_gpsd_control_get_default();
41 location_gpsd_control_request_status(control);
42 if(control->can_control) {
43 location_gpsd_control_start(control);
48 void stop_gps(AppData* appdata) {
51 control = location_gpsd_control_get_default();
52 location_gpsd_control_request_status(control);
53 if(control->can_control) {
54 location_gpsd_control_stop(control);
59 void interpret_speed_from_gps(AppData* appdata, gdouble speed) {
62 // if speed is below one then it's zero
64 set_nth_digit(appdata, 0, 0);
65 set_nth_digit(appdata, 1, 0);
66 set_nth_digit(appdata, 2, 0);
71 // first let's convert the number to string
72 gchar* cspeed = g_malloc(30); // alloc
73 g_sprintf(cspeed, "%f", speed);
75 // split the string using comma as delimiter
76 gchar** splitted = g_strsplit(cspeed, ",", 2); // alloc
78 gchar* ckm = splitted[0]; // contains the km/h part e.g 123 assuming speed was 123,034510
79 gchar* cm = splitted[1]; // contains the m/h part e.g 034510 assuming speed was 123,034510
81 g_print("Original speed %c, splitted speed %c and %c\n", cspeed, ckm, cm);
83 // we need to pad km part in order to ensure it is *atleast* 3 digits long
84 gchar* padding = "00";
85 gchar* padded = g_strconcat(padding, cm, NULL); // alloc
87 g_print("Original speed %c, padded speed %c (km) and %c (m)\n", cspeed, padded, cm);
91 guint pspeedl = strlen(padded);
94 guint value = g_ascii_digit_value(padded[pspeedl]);
95 set_nth_digit(appdata, i, value);
98 repaint_all_digits(appdata);
102 g_strfreev(splitted);
105 static show_dialog() {
106 GtkWidget *dialog = gtk_message_dialog_new(
111 "This program is licensed under GNU General Public License, "
112 "which means (among other things) that you don't have to pay "
114 "If you think, however, that this software is worth it, you "
115 "can always drop me a postcard.\n\n"
120 gtk_dialog_run(GTK_DIALOG(dialog));
121 gtk_widget_destroy(dialog);
124 void show_cardware_dialog() {
125 GConfClient* client = gconf_client_get_default();
126 g_assert(GCONF_IS_CLIENT(client));
128 GConfValue* gcvalue = NULL;
129 gcvalue = gconf_client_get_without_default(client, GCONF_KEY, NULL);
131 if(gcvalue == NULL) {
132 g_print("GConf key not found so show dialog.");
134 gconf_client_set_bool(client, GCONF_KEY, TRUE, NULL);
136 g_object_unref(client);