diff options
author | OLFDB <olf@eisenzelt.de> | 2021-04-03 08:11:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-03 08:11:52 +0200 |
commit | 1effb2462fc787894308e0aafcbd7cc10e77390c (patch) | |
tree | 2d4f3cc02bc7f78613a1dda491fc46d1e20ae31b /navit/navit.c | |
parent | 1e32e2ed7d76851dcfcef95280d52bb8693c6c08 (diff) | |
download | navit-1effb2462fc787894308e0aafcbd7cc10e77390c.tar.gz |
added:core:make it switch to nightlayout when we are in a tunnel (#1089)
* 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 0df8099a4533553f837a6f679899cc1a3aefc057.
* Revert "Update config.yml"
This reverts commit c1cae2e5f3f7f0fe48af0ddf1414ac6e86f36bba.
* 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>
Diffstat (limited to 'navit/navit.c')
-rw-r--r-- | navit/navit.c | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/navit/navit.c b/navit/navit.c index d94e123cb..5248e10ea 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -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; @@ -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; @@ -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); @@ -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); @@ -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; @@ -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 @@ -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; @@ -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)); |