summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOLFDB <olf@eisenzelt.de>2021-04-03 08:11:52 +0200
committerGitHub <noreply@github.com>2021-04-03 08:11:52 +0200
commit1effb2462fc787894308e0aafcbd7cc10e77390c (patch)
tree2d4f3cc02bc7f78613a1dda491fc46d1e20ae31b
parent1e32e2ed7d76851dcfcef95280d52bb8693c6c08 (diff)
downloadnavit-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>
-rw-r--r--navit/attr_def.h3
-rw-r--r--navit/navit.c61
-rw-r--r--navit/navit.dtd3
-rw-r--r--navit/track.c7
-rw-r--r--navit/track.h4
-rw-r--r--navit/vehicle/gpsd/vehicle_gpsd.c8
6 files changed, 79 insertions, 7 deletions
diff --git a/navit/attr_def.h b/navit/attr_def.h
index e498a40a8..e5f3033ff 100644
--- a/navit/attr_def.h
+++ b/navit/attr_def.h
@@ -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.
@@ -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)
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));
diff --git a/navit/navit.dtd b/navit/navit.dtd
index 6ab800b96..4d6b4cfe6 100644
--- a/navit/navit.dtd
+++ b/navit/navit.dtd
@@ -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>
diff --git a/navit/track.c b/navit/track.c
index 3330c929c..b729c329a 100644
--- a/navit/track.c
+++ b/navit/track.c
@@ -119,8 +119,6 @@ struct tracking {
};
-
-
static void tracking_init_cdf(struct cdf_data *cdf, int hist_size) {
cdf->extrapolating = 0;
cdf->available = 0;
@@ -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;
@@ -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)) {
diff --git a/navit/track.h b/navit/track.h
index 928ef4b00..5713ea4a6 100644
--- a/navit/track.h
+++ b/navit/track.h
@@ -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;
@@ -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);
diff --git a/navit/vehicle/gpsd/vehicle_gpsd.c b/navit/vehicle/gpsd/vehicle_gpsd.c
index 92d663ef9..9dbc18aa4 100644
--- a/navit/vehicle/gpsd/vehicle_gpsd.c
+++ b/navit/vehicle/gpsd/vehicle_gpsd.c
@@ -26,6 +26,7 @@
#include <gpsbt.h>
#include <errno.h>
#endif
+#include "config.h"
#include "debug.h"
#include "callback.h"
#include "plugin.h"
@@ -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");
}