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_DIR "/apps/Maemo/speedometer/"
30 static LocationGPSDevice *device = NULL;
31 static LocationGPSDControl *control = NULL;
33 void start_gps(AppData* appdata) {
36 device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
37 g_signal_connect(device, "changed", G_CALLBACK(location_changed), appdata);
39 control = location_gpsd_control_get_default();
40 location_gpsd_control_request_status(control);
41 if(control->can_control) {
42 location_gpsd_control_start(control);
47 void stop_gps(AppData* appdata) {
49 control = location_gpsd_control_get_default();
50 location_gpsd_control_request_status(control);
51 if(control->can_control) {
52 location_gpsd_control_stop(control);
57 void interpret_speed_from_gps(AppData* appdata, gdouble speed) {
59 // if speed is below one then it's zero
61 set_nth_digit(appdata, 0, 0);
62 set_nth_digit(appdata, 1, 0);
63 set_nth_digit(appdata, 2, 0);
68 // first let's convert the number to string
69 gchar* cspeed = g_malloc(30); // alloc
70 g_sprintf(cspeed, "%f", speed);
72 // split the string using comma as delimiter
73 gchar** splitted = g_strsplit(cspeed, ",", 2); // alloc
75 gchar* ckm = splitted[0]; // contains the km/h part e.g 123 assuming speed was 123,034510
76 gchar* cm = splitted[1]; // contains the m/h part e.g 034510 assuming speed was 123,034510
78 g_print("Original speed %c, splitted speed %c and %c\n", cspeed, ckm, cm);
80 // we need to pad km part in order to ensure it is *atleast* 3 digits long
81 gchar* padding = "00";
82 gchar* padded = g_strconcat(padding, cm, NULL); // alloc
84 g_print("Original speed %c, padded speed %c (km) and %c (m)\n", cspeed, padded, cm);
88 guint pspeedl = strlen(padded);
91 guint value = g_ascii_digit_value(padded[pspeedl]);
92 set_nth_digit(appdata, i, value);
95 repaint_all_digits(appdata);
102 void show_postcard_dialog() {
103 GConfClient* client = gconf_client_get_default();
104 g_assert(GCONF_IS_CLIENT(client));
107 GConfValue* gcvalue = NULL;
108 gcvalue = gconf_client_get_without_default(client, GCONF_DIR "disclaimer", NULL);
110 if(gcvalue == NULL) {
111 g_warning("key %sdisclaimer not found\n", GCONF_DIR);
112 gconf_client_set_bool(client, GCONF_DIR "disclaimer", TRUE, NULL);
115 g_print("key %sdisclaimer was found\n", GCONF_DIR);
117 g_object_unref(client);