+void change_unit() {
+ unit++;
+
+ if(unit >= UNIT_COUNT) {
+ unit = 0;
+ }
+ g_print("Unit used in conversion: %f\n", conversion[unit]);
+
+ GdkPixbuf* buf = small_graphics[10 + unit];
+ gtk_image_set_from_pixbuf(GTK_IMAGE(unit_graphic), buf);
+}
+
+void interpret_and_set_speed(gdouble speed) {
+ g_assert(!isnan(speed));
+
+ /* speed is in m/s so let's convert
+ * it to the unit that we are using
+ */
+ speed *= conversion[unit];
+
+ /* Convert float to a 6 digits (including dot) wide
+ * string with leading zeros. After conversion
+ * the speed looks like:
+ *
+ * 009.20 (9,20 km/h) or
+ * 010.90 (10,90 km/h) or
+ * 120.10 (120,10 km/h)
+ *
+ * Now, regardless of speed we know the position
+ * of the digits and can access the array directly.
+ */
+ gchar* charspeed = g_malloc(10); // alloc
+ g_sprintf(charspeed, "%0*.2f", 6, speed);
+
+ g_print("Speed is %s km/h\n", charspeed);
+
+ // these three lines will set the big digits
+ set_nth_digit(0, g_ascii_digit_value(charspeed[0]));
+ set_nth_digit(1, g_ascii_digit_value(charspeed[1]));
+ set_nth_digit(2, g_ascii_digit_value(charspeed[2]));
+
+ // these two lines will set the small digits
+ set_nth_digit(3, g_ascii_digit_value(charspeed[4]));
+ set_nth_digit(4, g_ascii_digit_value(charspeed[5]));
+
+ repaint_all_digits();
+
+ g_free(charspeed);
+}
+
+static void show_dialog() {
+ GtkWidget *dialog = gtk_message_dialog_new(
+ NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ "This program is licensed under GNU General Public License, "
+ "which means (among other things) that you don't have to pay "
+ "a dime for it. "
+ "If you think, however, that this software is worth it, you "
+ "can always drop me a postcard.\n\n"
+ "Wellu Mäkinen\n"
+ "PO BOX\n"
+ "33580 Tampere\n"
+ "FINLAND");
+ gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+}
+
+void show_cardware_dialog() {
+ GConfClient* client = gconf_client_get_default();
+ g_assert(GCONF_IS_CLIENT(client));
+
+ GConfValue* gcvalue = NULL;
+ gcvalue = gconf_client_get_without_default(client, GCONF_KEY, NULL);
+
+ if(gcvalue == NULL) {
+ g_print("GConf key not found so show dialog.\n");
+ show_dialog();
+ gconf_client_set_bool(client, GCONF_KEY, TRUE, NULL);
+ }
+ g_object_unref(client);