38 |
#define SAT_WIDTH 330 |
#define SAT_WIDTH 330 |
39 |
#define SAT_HEIGHT 60 |
#define SAT_HEIGHT 60 |
40 |
|
|
41 |
|
#ifdef ESPEAK |
42 |
|
#include <espeak/speak_lib.h> |
43 |
|
|
44 |
|
#define ESPEAK_TIMEOUT (15000) // every 15 seconds |
45 |
|
|
46 |
|
char *espeak_make_string(float dist, gboolean imperial) { |
47 |
|
char *retval = NULL; |
48 |
|
|
49 |
|
if(!imperial) { |
50 |
|
/* distance is in kilometers */ |
51 |
|
if(dist < 2.0/1000.0) |
52 |
|
retval = g_strdup(_("1 meter")); |
53 |
|
else if(dist < 1.0) |
54 |
|
retval = g_strdup_printf(_("%u meters"), (int)(dist*1000)); |
55 |
|
else if(dist < 2.0) |
56 |
|
retval = g_strdup(_("1 kilometer")); |
57 |
|
else |
58 |
|
retval = g_strdup_printf(_("%u kilometers"), (int)dist); |
59 |
|
} else { |
60 |
|
|
61 |
|
/* 1 mil = 1760 yd = 5280 ft ... */ |
62 |
|
if(dist < (2.0/5280.0)) |
63 |
|
retval = g_strdup(_("1 foot")); |
64 |
|
else if(dist < (1.0/1760.0)) |
65 |
|
retval = g_strdup_printf(_("%u feet"), (int)(dist*5280)); |
66 |
|
else if(dist < (2.0/1760.0)) |
67 |
|
retval = g_strdup(_("1 yard")); |
68 |
|
else if(dist < 1.0) |
69 |
|
retval = g_strdup_printf(_("%u yard"), (int)(dist*1760)); |
70 |
|
else if(dist < 2.0) |
71 |
|
retval = g_strdup(_("1 mile")); |
72 |
|
else |
73 |
|
retval = g_strdup_printf(_("%u miles"), (int)dist); |
74 |
|
} |
75 |
|
return retval; |
76 |
|
} |
77 |
|
|
78 |
|
static gboolean espeak_do(gpointer data) { |
79 |
|
cache_context_t *context = (cache_context_t*)data; |
80 |
|
|
81 |
|
pos_t *pos = gps_get_pos(context->appdata); |
82 |
|
if(pos && !isnan(pos->lat) && !isnan(pos->lon) && |
83 |
|
!isnan(context->gotoc.pos.lat) && !isnan(context->gotoc.pos.lon)) { |
84 |
|
|
85 |
|
/* build distance */ |
86 |
|
float dist = |
87 |
|
gpx_pos_get_distance(*pos, context->gotoc.pos, |
88 |
|
context->appdata->imperial); |
89 |
|
|
90 |
|
char *talk = espeak_make_string(dist, context->appdata->imperial); |
91 |
|
|
92 |
|
unsigned int unique_identifier=0; |
93 |
|
espeak_Synth(talk, strlen(talk)+1, 0, 0, 0, espeakCHARS_AUTO, |
94 |
|
&unique_identifier, NULL); |
95 |
|
|
96 |
|
g_free(talk); |
97 |
|
} |
98 |
|
|
99 |
|
return TRUE; // speak again |
100 |
|
} |
101 |
|
|
102 |
|
static void espeak_enable(cache_context_t *context, gboolean enable) { |
103 |
|
if(enable) { |
104 |
|
g_assert(!context->gotoc.espeak_handler); |
105 |
|
|
106 |
|
context->gotoc.espeak_handler = |
107 |
|
gtk_timeout_add(ESPEAK_TIMEOUT, espeak_do, context); |
108 |
|
|
109 |
|
espeak_do(context); |
110 |
|
|
111 |
|
} else { |
112 |
|
if(context->gotoc.espeak_handler) { |
113 |
|
gtk_timeout_remove(context->gotoc.espeak_handler); |
114 |
|
context->gotoc.espeak_handler = 0; |
115 |
|
} |
116 |
|
} |
117 |
|
} |
118 |
|
#endif |
119 |
|
|
120 |
static float rad2deg(float rad) { |
static float rad2deg(float rad) { |
121 |
return fmodf(360.0 + (180.0/M_PI) * rad, 360.0); |
return fmodf(360.0 + (180.0/M_PI) * rad, 360.0); |
122 |
} |
} |
271 |
|
|
272 |
pos_t *pos = gps_get_pos(context->appdata); |
pos_t *pos = gps_get_pos(context->appdata); |
273 |
if(pos && !isnan(pos->lat) && !isnan(pos->lon)) { |
if(pos && !isnan(pos->lat) && !isnan(pos->lon)) { |
274 |
context->appdata->gps = *pos; /* save position */ |
context->appdata->gps.saved = *pos; /* save position */ |
275 |
|
|
276 |
float arot = |
float arot = |
277 |
gpx_pos_get_bearing(*pos, context->gotoc.pos) * |
gpx_pos_get_bearing(*pos, context->gotoc.pos) * |
353 |
0, 0, width, height); |
0, 0, width, height); |
354 |
|
|
355 |
gps_sat_t *sat = gps_get_sats(context->appdata); |
gps_sat_t *sat = gps_get_sats(context->appdata); |
356 |
if(sat && sat->num) { |
gint sat_num = gps_get_satnum(context->appdata); |
357 |
|
|
358 |
|
if(sat && sat_num) { |
359 |
/* setup required colors */ |
/* setup required colors */ |
360 |
GdkGC *used_gc = gdk_gc_new(context->gotoc.sat_pixmap); |
GdkGC *used_gc = gdk_gc_new(context->gotoc.sat_pixmap); |
361 |
gdk_gc_copy(used_gc, widget->style->black_gc); |
gdk_gc_copy(used_gc, widget->style->black_gc); |
365 |
|
|
366 |
#define SAT_SPACING 3 |
#define SAT_SPACING 3 |
367 |
int i, x; |
int i, x; |
368 |
int swid = (width-SAT_SPACING*(sat->num-1))/sat->num; |
int swid = (width-SAT_SPACING*(sat_num-1))/sat_num; |
369 |
|
|
370 |
/* as of xgps, a ss of 40 and more is "plenty" */ |
/* as of xgps, a ss of 40 and more is "plenty" */ |
371 |
int max_ss = 40; |
int max_ss = 40; |
372 |
for(i=0;i<sat->num;i++) |
for(i=0;i<sat_num;i++) |
373 |
if(sat->ss[i] > max_ss) sat->ss[i] = max_ss; |
if(sat[i].ss > max_ss) sat[i].ss = max_ss; |
374 |
|
|
375 |
if(swid > 40) { |
if(swid > 40) { |
376 |
swid = 40; |
swid = 40; |
377 |
x = (width-sat->num*swid)/2; |
x = (width-sat_num*swid)/2; |
378 |
} else |
} else |
379 |
x = 0; |
x = 0; |
380 |
|
|
381 |
for(i=0;i<sat->num;i++) { |
for(i=0;i<sat_num;i++) { |
382 |
char str[32]; |
char str[32]; |
383 |
#ifdef USE_MAEMO |
#ifdef USE_MAEMO |
384 |
snprintf(str, sizeof(str), "<span size=\"small\">%d</span>", sat->PRN[i]); |
snprintf(str, sizeof(str), "<span size=\"small\">%d</span>", sat[i].prn); |
385 |
PangoLayout *layout = gtk_widget_create_pango_layout(widget, NULL); |
PangoLayout *layout = gtk_widget_create_pango_layout(widget, NULL); |
386 |
pango_layout_set_markup(layout, str, strlen(str)); |
pango_layout_set_markup(layout, str, strlen(str)); |
387 |
#else |
#else |
388 |
snprintf(str, sizeof(str), "%d", sat->PRN[i]); |
snprintf(str, sizeof(str), "%d", sat[i].prn); |
389 |
PangoLayout *layout = gtk_widget_create_pango_layout(widget, str); |
PangoLayout *layout = gtk_widget_create_pango_layout(widget, str); |
390 |
#endif |
#endif |
391 |
|
|
397 |
|
|
398 |
g_object_unref(layout); |
g_object_unref(layout); |
399 |
|
|
400 |
int h = (height-th) * sat->ss[i] / max_ss; |
int h = (height-th) * sat[i].ss / max_ss; |
401 |
|
|
402 |
gdk_draw_rectangle(context->gotoc.sat_pixmap, |
gdk_draw_rectangle(context->gotoc.sat_pixmap, |
403 |
sat->used[i]?used_gc:widget->style->fg_gc[GTK_STATE_NORMAL], |
sat[i].used?used_gc:widget->style->fg_gc[GTK_STATE_NORMAL], |
404 |
TRUE, x, height-h-th, swid, h); |
TRUE, x, height-h-th, swid, h); |
405 |
|
|
406 |
x += SAT_SPACING+swid; |
x += SAT_SPACING+swid; |
407 |
} |
} |
408 |
|
|
|
/* free sat infos */ |
|
|
free(sat->PRN); |
|
|
free(sat->ss); |
|
|
free(sat->used); |
|
409 |
} else { |
} else { |
410 |
PangoLayout *layout = |
PangoLayout *layout = |
411 |
gtk_widget_create_pango_layout(widget, _("No SAT info")); |
gtk_widget_create_pango_layout(widget, _("No SAT info")); |
417 |
|
|
418 |
g_object_unref(layout); |
g_object_unref(layout); |
419 |
} |
} |
|
|
|
|
/* free the sat structure */ |
|
|
if(sat) |
|
|
free(sat); |
|
420 |
} |
} |
421 |
|
|
422 |
/* Create a new backing pixmap of the appropriate size */ |
/* Create a new backing pixmap of the appropriate size */ |
456 |
|
|
457 |
printf("destroying goto view\n"); |
printf("destroying goto view\n"); |
458 |
|
|
459 |
|
#ifdef ESPEAK |
460 |
|
espeak_enable(context, FALSE); |
461 |
|
#endif |
462 |
|
|
463 |
/* stop timer */ |
/* stop timer */ |
464 |
if(context->gotoc.handler_id) |
if(context->gotoc.handler_id) |
465 |
gtk_timeout_remove(context->gotoc.handler_id); |
gtk_timeout_remove(context->gotoc.handler_id); |
554 |
goto_update(context); |
goto_update(context); |
555 |
} |
} |
556 |
|
|
557 |
|
#ifdef ESPEAK |
558 |
|
static void espeak_clicked(GtkWidget *widget, gpointer data) { |
559 |
|
cache_context_t *context = (cache_context_t*)data; |
560 |
|
|
561 |
|
GtkWidget *icon = gtk_button_get_image(GTK_BUTTON(widget)); |
562 |
|
gtk_widget_destroy(icon); |
563 |
|
context->appdata->espeak.enabled = !context->appdata->espeak.enabled; |
564 |
|
gtk_button_set_image(GTK_BUTTON(widget), icon_get_widget(ICON_MISC, |
565 |
|
context->appdata->espeak.enabled?6:7)); |
566 |
|
|
567 |
|
espeak_enable(context, context->appdata->espeak.enabled); |
568 |
|
} |
569 |
|
#endif |
570 |
|
|
571 |
|
/* create "goto" tab */ |
572 |
GtkWidget *goto_cache(cache_context_t *context) { |
GtkWidget *goto_cache(cache_context_t *context) { |
573 |
int i; |
int i; |
574 |
|
|
626 |
/* -------------- distance label ------------------------- */ |
/* -------------- distance label ------------------------- */ |
627 |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Distance:")), 0,1,2,3); |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Distance:")), 0,1,2,3); |
628 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), |
629 |
(context->gotoc.distance_label = left_label_new("-----")), 1,2,2,3); |
(context->gotoc.distance_label = gtk_label_new("-----")), 1,2,2,3); |
630 |
|
|
631 |
/* -------------- bearing label ------------------------- */ |
/* -------------- bearing label ------------------------- */ |
632 |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Bearing:")), 0,1,3,4); |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Bearing:")), 0,1,3,4); |
633 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), |
634 |
(context->gotoc.bearing_label = left_label_new("-----")), 1,2,3,4); |
(context->gotoc.bearing_label = gtk_label_new("-----")), 1,2,3,4); |
635 |
|
|
636 |
/* -------------- error label ------------------------- */ |
/* -------------- error label ------------------------- */ |
637 |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Est. error:")), 0,1,4,5); |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Est. error:")), 0,1,4,5); |
638 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), |
639 |
(context->gotoc.eph_label = left_label_new("-----")), 1,2,4,5); |
(context->gotoc.eph_label = gtk_label_new("-----")), 1,2,4,5); |
640 |
|
|
641 |
gtk_table_set_row_spacing(GTK_TABLE(table), 4, 16); |
gtk_table_set_row_spacing(GTK_TABLE(table), 4, 16); |
642 |
|
|
656 |
|
|
657 |
gtk_box_pack_start(GTK_BOX(ihbox), context->gotoc.sat_area, 1,0,0); |
gtk_box_pack_start(GTK_BOX(ihbox), context->gotoc.sat_area, 1,0,0); |
658 |
|
|
659 |
|
#ifdef ESPEAK |
660 |
|
GtkWidget *ivbox = gtk_vbox_new(FALSE, 0); |
661 |
|
GtkWidget *button = button_new(); |
662 |
|
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_MISC, |
663 |
|
context->appdata->espeak.enabled?6:7)); |
664 |
|
gtk_signal_connect (GTK_OBJECT(button), "clicked", |
665 |
|
GTK_SIGNAL_FUNC(espeak_clicked), context); |
666 |
|
if(context->appdata->espeak.sample_rate < 0) |
667 |
|
gtk_widget_set_sensitive(button, FALSE); |
668 |
|
else |
669 |
|
if(context->appdata->espeak.enabled) |
670 |
|
espeak_enable(context, TRUE); |
671 |
|
|
672 |
|
gtk_box_pack_start(GTK_BOX(ivbox), button, 1,0,0); |
673 |
|
gtk_box_pack_start(GTK_BOX(ihbox), ivbox, 1,0,0); |
674 |
|
#endif |
675 |
|
|
676 |
gtk_table_attach_defaults(GTK_TABLE(table), ihbox, 0,3,5,6); |
gtk_table_attach_defaults(GTK_TABLE(table), ihbox, 0,3,5,6); |
677 |
|
|
678 |
/* ------------------------------------------------------- */ |
/* ------------------------------------------------------- */ |