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/>.
20 #include <location/location-gps-device.h>
21 #include <location/location-gpsd-control.h>
22 #include <gconf/gconf-client.h>
23 #include <glib/gprintf.h>
27 #include "callbacks.h"
30 /* This is used when converting to other units
31 * number represents a multiplier which is used
32 * when converting the base unit to other units.
33 * Base unit is m/s thus the first multiplier is
34 * one. Units are in following order:
38 gdouble conversion[] = { 1, 3.6, 2.237 };
40 #define GCONF_KEY "/apps/Maemo/speedometer/disclaimer"
42 static LocationGPSDevice *device = NULL;
43 static LocationGPSDControl *control = NULL;
45 void start_gps(AppData* appdata) {
49 device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
50 g_signal_connect(device, "changed", G_CALLBACK(location_changed), appdata);
52 control = location_gpsd_control_get_default();
53 location_gpsd_control_request_status(control);
54 if(control->can_control) {
55 location_gpsd_control_start(control);
60 void stop_gps(AppData* appdata) {
63 control = location_gpsd_control_get_default();
64 location_gpsd_control_request_status(control);
65 if(control->can_control) {
66 location_gpsd_control_stop(control);
71 void interpret_speed_from_gps(AppData* appdata, gdouble speed) {
73 g_assert(!isnan(speed));
75 /* speed is in m/s so let's convert
76 * it to the unit that we are using
78 speed *= conversion[appdata->unit];
80 // convert float to a 6 digits (including dot) wide string with leading zeros
81 gchar* charspeed = g_malloc(10); // alloc
82 g_sprintf(charspeed, "%0*.2f", 6, speed);
84 g_print("Speed is %s km/h\n", charspeed);
86 // set the main digits
90 set_nth_digit(appdata, i, g_ascii_digit_value(charspeed[i]));
93 repaint_all_digits(appdata);
99 static void show_dialog() {
100 GtkWidget *dialog = gtk_message_dialog_new(
105 "This program is licensed under GNU General Public License, "
106 "which means (among other things) that you don't have to pay "
108 "If you think, however, that this software is worth it, you "
109 "can always drop me a postcard.\n\n"
114 gtk_dialog_run(GTK_DIALOG(dialog));
115 gtk_widget_destroy(dialog);
118 void show_cardware_dialog() {
119 GConfClient* client = gconf_client_get_default();
120 g_assert(GCONF_IS_CLIENT(client));
122 GConfValue* gcvalue = NULL;
123 gcvalue = gconf_client_get_without_default(client, GCONF_KEY, NULL);
125 if(gcvalue == NULL) {
126 g_print("GConf key not found so show dialog.");
128 gconf_client_set_bool(client, GCONF_KEY, TRUE, NULL);
130 g_object_unref(client);
133 void load_settings() {