diff options
author | tegzed <tegzed@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2011-02-19 20:55:51 +0000 |
---|---|---|
committer | tegzed <tegzed@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2011-02-19 20:55:51 +0000 |
commit | 383d66b16fad5595e687ac2acd4d186fbd238d6f (patch) | |
tree | db409193e206a33592f20704db0e93a0bc312963 /navit/osd | |
parent | ab21acb71ca05ede813adbc9771b2fb679582038 (diff) | |
download | navit-383d66b16fad5595e687ac2acd4d186fbd238d6f.tar.gz |
Fix:osd/core:improve time accuracy in odometer speed caculation and double click handling
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@4219 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/osd')
-rw-r--r-- | navit/osd/core/osd_core.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/navit/osd/core/osd_core.c b/navit/osd/core/osd_core.c index eba7d85a0..7ee276c43 100644 --- a/navit/osd/core/osd_core.c +++ b/navit/osd/core/osd_core.c @@ -234,10 +234,10 @@ struct odometer { int bActive; //counting or not int autosave_period; //autosave period in seconds double sum_dist; //sum of distance ofprevious intervals in meters - int sum_time; //sum of time of previous intervals in seconds (needed for avg spd calculation) - int time_all; - time_t last_click_time; //time of last click (for double click handling) - time_t last_start_time; //time of last start of counting + double sum_time; //sum of time of previous intervals in seconds (needed for avg spd calculation) + double time_all; + double last_click_time; //time of last click (for double click handling) + double last_start_time; //time of last start of counting double last_update_time; //time of last position update struct coord last_coord; double last_speed; @@ -288,7 +288,7 @@ str_replace(char*output, char*input, char*pattern, char*replacement) */ static char *osd_odometer_to_string(struct odometer* this_) { - return g_strdup_printf("odometer %s %lf %d %d\n",this_->name,this_->sum_dist,this_->time_all,this_->bActive); + return g_strdup_printf("odometer %s %lf %lf %d\n",this_->name,this_->sum_dist,this_->time_all,this_->bActive); } /* @@ -323,7 +323,7 @@ static void osd_odometer_from_string(struct odometer* this_, char*str) } this_->name = name_str; this_->sum_dist = atof(sum_dist_str); - this_->sum_time = atoi(sum_time_str); + this_->sum_time = atof(sum_time_str); this_->bActive = atoi(active_str); this_->last_coord.x = -1; } @@ -389,7 +389,7 @@ osd_odometer_draw(struct odometer *this, struct navit *nav, if(dCurrDist<=cStepDistLimit) { this->sum_dist += dCurrDist; } - this->time_all = time(0)-this->last_click_time+this->sum_time; + this->time_all = curr_time-this->last_click_time+this->sum_time; spd = 3.6*(double)this->sum_dist/(double)this->time_all; if(dt != 0) { if(vehicle_get_attr(curr_vehicle, attr_position_speed,&speed_attr, NULL)) { @@ -410,7 +410,7 @@ osd_odometer_draw(struct odometer *this, struct navit *nav, dist_buffer = format_distance(this->sum_dist,"",imperial); spd_buffer = format_speed(spd,"","value",imperial); acc_buffer = g_strdup_printf("%.3f m/s2",this->acceleration); - remainder = this->time_all; + remainder = (int)this->time_all; days = remainder / (24*60*60); remainder = remainder % (24*60*60); hours = remainder / (60*60); @@ -464,6 +464,9 @@ static void osd_odometer_click(struct odometer *this, struct navit *nav, int pressed, int button, struct point *p) { struct point bp = this->osd_item.p; + struct timeval tv; + double curr_time; + const double double_click_timewin = .5; osd_wrap_point(&bp, nav); if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + this->osd_item.w || p->y > bp.y + this->osd_item.h || !this->osd_item.configured ) && !this->osd_item.pressed) return; @@ -473,20 +476,24 @@ osd_odometer_click(struct odometer *this, struct navit *nav, int pressed, int bu return; if (!!pressed == !!this->osd_item.pressed) return; + + gettimeofday(&tv,NULL); + curr_time = (double)(tv.tv_usec)/1000000.0+tv.tv_sec; + if (pressed) { //single click handling if(this->bActive) { //being stopped this->last_coord.x = -1; this->last_coord.y = -1; - this->sum_time += time(0)-this->last_click_time; + this->sum_time += curr_time-this->last_click_time; } this->bActive ^= 1; //toggle active flag - if (this->last_click_time == time(0)) { //double click handling + if (curr_time-double_click_timewin <= this->last_click_time) { //double click handling osd_odometer_reset(this); } - this->last_click_time = time(0); + this->last_click_time = curr_time; osd_odometer_draw(this, nav,NULL); } |