13 #include <glib/gstdio.h>
16 #include <gdk/gdkkeysyms.h>
17 #include <libgnomevfs/gnome-vfs.h>
18 #include <curl/multi.h>
19 #include <gconf/gconf-client.h>
20 #include <libxml/parser.h>
23 #include <hildon-widgets/hildon-system-sound.h>
28 #include "mapper-types.h"
32 void sound_noise(void)
35 hildon_play_system_sound("/usr/share/sounds/ui-information_note.wav");
41 void sound_speak(gchar * phrase)
43 #define _voice_synth_path "/usr/bin/flite"
47 /* We are the fork child. Synthesize the voice. */
50 printf("%s %s\n", _voice_synth_path, _last_spoken_phrase);
51 execl(_voice_synth_path, _voice_synth_path,
52 "-t", _last_spoken_phrase, (char *)NULL);
61 void latlon2unit(gfloat lat, gfloat lon, gint *unitx_, gint *unity_)
68 unitx = (lon + 180.f) * (WORLD_SIZE_UNITS / 360.f) + 0.5f;
69 tmp = sinf(lat * (PI / 180.f));
70 unity = 0.5f + (WORLD_SIZE_UNITS / MERCATOR_SPAN)
71 * (logf((1.f + tmp) / (1.f - tmp)) * 0.5f - MERCATOR_TOP);
74 void unit2latlon(gint unitx, gint unity, gfloat *lat, gfloat *lon)
76 (lon) = ((unitx) * (360.f / WORLD_SIZE_UNITS)) - 180.f;
77 (lat) = (360.f * (atanf(expf(((unity)
78 * (MERCATOR_SPAN / WORLD_SIZE_UNITS))
79 + MERCATOR_TOP)))) * (1.f / PI) - 90.f;
84 deg_format(DegFormat degformat, gfloat coor, gchar * scoor, gchar neg_char,
88 gfloat acoor = fabs(coor);
89 printf("%s()\n", __PRETTY_FUNCTION__);
93 sprintf(scoor, "%.5f°", coor);
96 sprintf(scoor, "%.5f° %c", acoor,
97 coor < 0.f ? neg_char : pos_char);
101 sprintf(scoor, "%d°%06.3f'",
102 (int)coor, (acoor - (int)acoor) * 60.0);
105 sprintf(scoor, "%d°%06.3f' %c",
106 (int)acoor, (acoor - (int)acoor) * 60.0,
107 coor < 0.f ? neg_char : pos_char);
111 min = (acoor - (int)acoor) * 60.0;
112 sprintf(scoor, "%d°%02d'%04.1f\"", (int)coor, (int)min,
113 ((min - (int)min) * 60.0));
115 case DD_MM_SSPS_NSEW:
116 min = (acoor - (int)acoor) * 60.0;
117 sprintf(scoor, "%d°%02d'%04.1f\" %c", (int)acoor, (int)min,
118 ((min - (int)min) * 60.0),
119 coor < 0.f ? neg_char : pos_char);
123 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
127 * Calculate the distance between two lat/lon pairs. The distance is returned
128 * in kilometers and should be converted using UNITS_CONVERT[_units].
130 gfloat calculate_distance(gfloat lat1, gfloat lon1, gfloat lat2, gfloat lon2)
132 gdouble dlat, dlon, slat, slon, a;
134 /* Convert to radians. */
135 lat1 *= (PI / 180.f);
136 lon1 *= (PI / 180.f);
137 lat2 *= (PI / 180.f);
138 lon2 *= (PI / 180.f);
143 slat = sinf(dlat / 2.f);
144 slon = sinf(dlon / 2.f);
145 a = (slat * slat) + (cosf(lat1) * cosf(lat2) * slon * slon);
147 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
148 return ((2.f * atan2f(sqrtf(a), sqrtf(1.f - a))) * EARTH_RADIUS);
152 * Convert the float lat/lon/speed/heading data into integer units.
154 void integerize_data()
157 printf("%s()\n", __PRETTY_FUNCTION__);
159 latlon2unit(_gps.lat, _gps.lon, _pos.unitx, _pos.unity);
161 tmp = (_gps.heading * (1.f / 180.f)) * PI;
162 _vel_offsetx = (gint) (floorf(_gps.speed * sinf(tmp) + 0.5f));
163 _vel_offsety = -(gint) (floorf(_gps.speed * cosf(tmp) + 0.5f));
165 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
169 download_comparefunc(const ProgressUpdateInfo * a,
170 const ProgressUpdateInfo * b, gpointer user_data)
172 gint diff = (a->priority - b->priority);
175 diff = (a->tilex - b->tilex);
178 diff = (a->tiley - b->tiley);
181 diff = (a->zoom - b->zoom);
184 diff = (a->repo - b->repo);
187 /* Otherwise, deletes are "greatest" (least priority). */
189 return (b->retries ? -1 : 0);
190 else if (!b->retries)
191 return (a->retries ? 1 : 0);
192 /* Do updates after non-updates (because they'll both be done anyway). */
193 return (a->retries - b->retries);
197 void reset_bluetooth()
199 printf("%s()\n", __PRETTY_FUNCTION__);
201 ("/usr/bin/sudo -l | grep -q '/usr/sbin/hciconfig *hci0 *reset'"
202 " && sudo /usr/sbin/hciconfig hci0 reset"))
205 ("An error occurred while trying to reset the bluetooth "
207 "Did you make sure to modify\nthe /etc/sudoers file?"));
208 else if (_conn_state > RCVR_OFF) {
209 set_conn_state(RCVR_DOWN);
210 rcvr_connect_later();
212 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
215 void reset_bluetooth()