Skip to content

Commit

Permalink
added:core:make it switch to nightlayout when we are in a tunnel (#1089)
Browse files Browse the repository at this point in the history
* Address ToDo : make it switch to nightlayout when we are in a tunne

Nightlayout is enabled when available and streetflags & AF_UNDERGROUND is true

* Addresses ToDo: make it switch to nightlayout when we are in a tunnel

* Delete navit.c

* Applied suggested changes from review

* Applied changes from review

* Fix: Fix formatting of file to pass sanity check

* Using tracking->tunnel

* Update update_download_center.sh

* Update config.yml

* attributes tunnel_nightlayout, nightlayout_auto, sunrise_degrees added

* Use tracking_get_current_tunnel to access tracking object

* Revert "Update update_download_center.sh"

This reverts commit 0df8099.

* Revert "Update config.yml"

This reverts commit c1cae2e.

* removed todo for nightlayout in tunnel

* removed debug output

* Update navit.c

Do not return if there is a day layout

Co-authored-by: Stefan Wildemann <stefan.wildemann@corpuls.com>
Co-authored-by: Stefan Wildemann <metalstrolch@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 3, 2021
1 parent 1e32e2e commit 1effb24
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 7 deletions.
3 changes: 3 additions & 0 deletions navit/attr_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ ATTR(nav_status)
ATTR(virtual_dpi)
ATTR(real_dpi)
ATTR(underground_alpha)
ATTR(sunrise_degrees)
ATTR2(0x00027500,type_rel_abs_begin)
/* These attributes are int that can either hold relative or absolute values. See the
* documentation of ATTR_REL_RELSHIFT for details.
Expand Down Expand Up @@ -264,6 +265,8 @@ ATTR(no_warning_if_map_file_missing)
ATTR(duplicate)
ATTR(has_menu_button)
ATTR(oneway)
ATTR(tunnel_nightlayout)
ATTR(layout_daynightauto)
ATTR2(0x0002ffff,type_int_end)
ATTR2(0x00030000,type_string_begin)
ATTR(type)
Expand Down
61 changes: 59 additions & 2 deletions navit/navit.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ struct navit {
int waypoints_flag;
struct coord_geo center;
int auto_switch; /*auto switching between day/night layout enabled ?*/
int tunnel_nightlayout; /* switch to nightlayout if we are in a tunnel? */
char* layout_before_tunnel;
int sunrise_degrees;
};

struct gui *main_loop_gui;
Expand Down Expand Up @@ -1484,6 +1487,9 @@ navit_new(struct attr *parent, struct attr **attrs) {
this_->radius = 30;
this_->border = 16;
this_->auto_switch = TRUE;
this_->tunnel_nightlayout = FALSE;
this_->layout_before_tunnel = "";
this_->sunrise_degrees = -5;

transform_from_geo(pro, &g, &co);
center.x=co.x;
Expand Down Expand Up @@ -2731,6 +2737,18 @@ static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init) {
attr_updated=(this_->waypoints_flag != !!attr->u.num);
this_->waypoints_flag=!!attr->u.num;
break;
case attr_tunnel_nightlayout:
attr_updated = (this_->tunnel_nightlayout != !!attr->u.num);
this_->tunnel_nightlayout = !!attr->u.num;
break;
case attr_layout_daynightauto:
attr_updated = (this_->auto_switch != !!attr->u.num);
this_->auto_switch = !!attr->u.num;
break;
case attr_sunrise_degrees:
attr_updated = (this_->sunrise_degrees != attr->u.num);
this_->sunrise_degrees = attr->u.num;
break;
default:
dbg(lvl_debug, "calling generic setter method for attribute type %s", attr_to_name(attr->type))
return navit_object_set_attr((struct navit_object *) this_, attr);
Expand Down Expand Up @@ -2946,6 +2964,15 @@ int navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr,
case attr_waypoints_flag:
attr->u.num=this_->waypoints_flag;
break;
case attr_tunnel_nightlayout:
attr->u.num=this_->tunnel_nightlayout;
break;
case attr_layout_daynightauto:
attr->u.num=this_->auto_switch;
break;
case attr_sunrise_degrees:
attr->u.num=this_->sunrise_degrees;
break;
default:
dbg(lvl_debug, "calling generic getter method for attribute type %s", attr_to_name(type))
return navit_object_get_attr((struct navit_object *) this_, type, attr, iter);
Expand Down Expand Up @@ -3462,7 +3489,6 @@ navit_get_displaylist(struct navit *this_) {
return this_->displaylist;
}

/*todo : make it switch to nightlayout when we are in a tunnel */
void navit_layout_switch(struct navit *n) {

int currTs=0;
Expand All @@ -3472,6 +3498,7 @@ void navit_layout_switch(struct navit *n) {
int year, month, day;
int after_sunrise = FALSE;
int after_sunset = FALSE;
int tunnel = tracking_get_current_tunnel(n->tracking);

if (navit_get_attr(n,attr_layout,&layout_attr,NULL)!=1) {
return; //No layout - nothing to switch
Expand All @@ -3493,6 +3520,33 @@ void navit_layout_switch(struct navit *n) {
if (n->auto_switch == FALSE)
return;

if (n->tunnel_nightlayout) {
if (tunnel) {
// store the current layout name
if(!strcmp(n->layout_before_tunnel, ""))
n->layout_before_tunnel = n->layout_current->name;

// We are in a tunnel and if we have a nightlayout -> switch to nightlayout
if (l->nightname) {
navit_set_layout_by_name(n, l->nightname);
dbg(lvl_debug, "tunnel -> nightlayout");
}
return;

} else {
if (l->dayname) {
if (!strcmp(l->dayname, n->layout_before_tunnel)) {
// restore previous layout
navit_set_layout_by_name(n, l->dayname);
dbg(lvl_debug, "tunnel end -> daylayout");
}

// We were in nightlayout before the tunnel, keep it
n->layout_before_tunnel="";
}
}
}

if (currTs-(n->prevTs)<60) {
//We've have to wait a little
return;
Expand All @@ -3504,12 +3558,15 @@ void navit_layout_switch(struct navit *n) {
&& valid_attr.u.num==attr_position_valid_invalid) {
return; //No valid fix yet
}

if (vehicle_get_attr(n->vehicle->vehicle, attr_position_coord_geo,&geo_attr,NULL)!=1) {
//No position - no sun
return;
}

//We calculate sunrise anyway, cause it is needed both for day and for night
if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) {
if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,n->sunrise_degrees,1,&trise,
&tset)!=0) {
dbg(lvl_debug,"near the pole sun never rises/sets, so we should never switch profiles");
dbg(lvl_debug,"trise: %u:%u",HOURS(trise),MINUTES(trise));
dbg(lvl_debug,"tset: %u:%u",HOURS(tset),MINUTES(tset));
Expand Down
3 changes: 3 additions & 0 deletions navit/navit.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<!ATTLIST navit recent_dest CDATA #IMPLIED>
<!ATTLIST navit drag_bitmap CDATA #IMPLIED>
<!ATTLIST navit default_layout CDATA #IMPLIED>
<!ATTLIST navit tunnel_nightlayout CDATA #IMPLIED>
<!ATTLIST navit nightlayout_auto CDATA #IMPLIED>
<!ATTLIST navit sunrise_degrees CDATA #IMPLIED>
<!ELEMENT gui ANY>
<!ATTLIST gui type CDATA #REQUIRED>
<!ATTLIST gui menubar CDATA #IMPLIED>
Expand Down
7 changes: 5 additions & 2 deletions navit/track.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ struct tracking {
};




static void tracking_init_cdf(struct cdf_data *cdf, int hist_size) {
cdf->extrapolating = 0;
cdf->available = 0;
Expand Down Expand Up @@ -400,6 +398,10 @@ int *tracking_get_current_flags(struct tracking *_this) {
return &_this->curr_line->street->flags;
}

int tracking_get_current_tunnel(struct tracking *_this) {
return _this->tunnel;
}

static void tracking_get_angles(struct tracking_line *tl) {
int i;
struct street_data *sd=tl->street;
Expand Down Expand Up @@ -853,6 +855,7 @@ tracking_new(struct attr *parent, struct attr **attrs) {
this->offroad_limit_pref=5000;
this->route_pref=300;
this->callback_list=callback_list_new();
this->tunnel=0;


if (! attr_generic_get_attr(attrs, NULL, attr_cdf_histsize, &hist_size, NULL)) {
Expand Down
4 changes: 4 additions & 0 deletions navit/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
#ifndef NAVIT_TRACK_H
#define NAVIT_TRACK_H
#include <time.h>
#include "xmlconfig.h"
#include "coord.h"
#ifdef __cplusplus
extern "C" {
#endif

/* prototypes */
enum attr_type;
enum projection;
Expand All @@ -45,6 +48,7 @@ struct street_data *tracking_get_street_data(struct tracking *tr);
int tracking_get_attr(struct tracking *_this, enum attr_type type, struct attr *attr, struct attr_iter *attr_iter);
struct item *tracking_get_current_item(struct tracking *_this);
int *tracking_get_current_flags(struct tracking *_this);
int tracking_get_current_tunnel(struct tracking *_this);
void tracking_flush(struct tracking *tr);
void tracking_update(struct tracking *tr, struct vehicle *v, struct vehicleprofile *vehicleprofile, enum projection pro);
int tracking_set_attr(struct tracking *tr, struct attr *attr);
Expand Down
8 changes: 5 additions & 3 deletions navit/vehicle/gpsd/vehicle_gpsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <gpsbt.h>
#include <errno.h>
#endif
#include "config.h"
#include "debug.h"
#include "callback.h"
#include "plugin.h"
Expand Down Expand Up @@ -208,9 +209,10 @@ vehicle_gpsd_callback(struct gps_data_t *data, const char *buf, size_t len,
data->set &= ~LATLON_SET;
}
// If data->fix.speed is NAN, then the drawing gets jumpy.
if (! isnan(data->fix.speed) && priv->fix_type > 0) {
callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
//if (! isnan(data->fix.speed) && priv->fix_type > 0) {

callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);

dbg(lvl_info,"speed ok");
}

Expand Down

0 comments on commit 1effb24

Please sign in to comment.