struct vehicle_priv {
int interval;
+ int position_set;
struct callback_list *cbl;
struct navit *navit;
struct coord_geo geo;
attr->u.numd = &priv->direction;
break;
case attr_position_coord_geo:
- dbg(1, "coord %f,%f\n", priv->geo.lat, priv->geo.lng);
attr->u.coord_geo = &priv->geo;
break;
default:
static int
vehicle_demo_timer(struct vehicle_priv *priv)
{
- struct route_path_coord_handle *h;
- struct coord *c, *pos, ci;
+ struct route_path_coord_handle *h=NULL;
+ struct coord *c, *pos=NULL, ci;
int slen, len, dx, dy;
len = (priv->speed * priv->interval / 1000)/ 3.6;
return 1;
}
struct route *vehicle_route = navit_get_route(priv->navit);
- if (!vehicle_route) {
- dbg(1, "navit_get_route NOK\n");
- return 1;
- }
-
- h = route_path_coord_open(vehicle_route);
- if (!h) {
- dbg(1, "navit_path_coord_open NOK\n");
- return 1;
- }
- pos = route_path_coord_get(h);
+ if (vehicle_route)
+ h = route_path_coord_open(vehicle_route);
+ if (h)
+ pos = route_path_coord_get(h);
dbg(1, "current pos=%p\n", pos);
if (pos) {
+ priv->position_set=0;
dbg(1, "current pos=0x%x,0x%x\n", pos->x, pos->y);
dbg(1, "last pos=0x%x,0x%x\n", priv->last.x, priv->last.y);
if (priv->last.x == pos->x && priv->last.y == pos->y) {
break;
}
}
+ } else {
+ if (priv->position_set)
+ callback_list_call_0(priv->cbl);
}
return 1;
}
*cbl, struct attr **attrs)
{
struct vehicle_priv *ret;
- struct attr *interval,*speed;
+ struct attr *interval,*speed,*position_coord_geo;
dbg(1, "enter\n");
ret = g_new0(struct vehicle_priv, 1);
ret->speed=speed->u.num;
if ((interval=attr_search(attrs, NULL, attr_interval)))
ret->interval=speed->u.num;
+ if ((position_coord_geo=attr_search(attrs, NULL, attr_position_coord_geo))) {
+ ret->geo=*(position_coord_geo->u.coord_geo);
+ ret->position_set=1;
+ dbg(0,"position_set %f %f\n", ret->geo.lat, ret->geo.lng);
+ }
*meth = vehicle_demo_methods;
g_timeout_add(ret->interval, (GSourceFunc) vehicle_demo_timer, ret);
return ret;