summaryrefslogtreecommitdiff
path: root/navit
diff options
context:
space:
mode:
authorPierre GRANDIN <pgrandin@users.noreply.github.com>2016-04-06 10:20:11 -0700
committerPierre GRANDIN <pgrandin@users.noreply.github.com>2016-04-06 10:20:11 -0700
commitf0942985cd2ce2b8dabe38dafe2f0ef12fb82e39 (patch)
treeec13b57cdd4438aeb6c7e2cdd1d22c667d23391c /navit
parent3ba562883658482cf63ca1f86438aaa3c5331d9b (diff)
parent37c93602acbe502d523fa6293e0a7ab0f44bd502 (diff)
downloadnavit-f0942985cd2ce2b8dabe38dafe2f0ef12fb82e39.tar.gz
Merge pull request #90 from navit-gps/layoutswitcherR6647
Layoutswitcher
Diffstat (limited to 'navit')
-rw-r--r--navit/navit.c191
1 files changed, 133 insertions, 58 deletions
diff --git a/navit/navit.c b/navit/navit.c
index 5eb0353db..d93302e3b 100644
--- a/navit/navit.c
+++ b/navit/navit.c
@@ -176,6 +176,7 @@ struct navit {
int imperial;
int waypoints_flag;
struct coord_geo center;
+ int auto_switch; /*auto switching between day/night layout enabled ?*/
};
struct gui *main_loop_gui;
@@ -199,6 +200,7 @@ static void navit_cmd_set_center_cursor(struct navit *this_);
static void navit_cmd_announcer_toggle(struct navit *this_);
static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv);
static int navit_set_vehicleprofile(struct navit *this_, struct vehicleprofile *vp);
+static void navit_cmd_switch_layout_day_night(struct navit *this_, char *function, struct attr **in, struct attr ***out, int valid);
struct object_func navit_func;
struct navit *global_navit;
@@ -770,7 +772,7 @@ static GHashTable *cmd_attr_var_hash = NULL;
* Store key value pair for the command system (for int typed values)
*
* @param navit The navit instance
- * @param function unused (needed to match command function signiture)
+ * @param function unused (needed to match command function signature)
* @param in input attributes in[0] is the key string, in[1] is the integer value to store
* @param out output attributes, unused
* @param valid unused
@@ -799,7 +801,7 @@ navit_cmd_set_int_var(struct navit *this, char *function, struct attr **in, stru
* Store key value pair for the command system (for attr typed values, can be used as opaque handles)
*
* @param navit The navit instance
- * @param function unused (needed to match command function signiture)
+ * @param function unused (needed to match command function signature)
* @param in input attributes in[0] is the key string, in[1] is the attr* value to store
* @param out output attributes, unused
* @param valid unused
@@ -830,7 +832,7 @@ navit_cmd_set_attr_var(struct navit *this, char *function, struct attr **in, str
* command to toggle the active state of a named layer of the current layout
*
* @param navit The navit instance
- * @param function unused (needed to match command function signiture)
+ * @param function unused (needed to match command function signature)
* @param in input attribute in[0] is the name of the layer
* @param out output unused
* @param valid unused
@@ -859,7 +861,7 @@ navit_cmd_toggle_layer(struct navit *this, char *function, struct attr **in, str
* adds an item with the current coordinate of the vehicle to a named map
*
* @param navit The navit instance
- * @param function unused (needed to match command function signiture)
+ * @param function unused (needed to match command function signature)
* @param in input attribute in[0] is the name of the map
* @param out output attribute, 0 on error or the id of the created item on success
* @param valid unused
@@ -950,7 +952,7 @@ navit_cmd_map_add_curr_pos(struct navit *this, char *function, struct attr **in,
* sets an attribute (name value pair) of a map item specified by map name and item id
*
* @param navit The navit instance
- * @param function unused (needed to match command function signiture)
+ * @param function unused (needed to match command function signature)
* @param in input attribute in[0] - name of the map ; in[1] - item ; in[2] - attr name ; in[3] - attr value
* @param out output attribute, 0 on error, 1 on success
* @param valid unused
@@ -1015,7 +1017,7 @@ navit_cmd_map_item_set_attr(struct navit *this, char *function, struct attr **in
* Get attr variable given a key string for the command system (for opaque usage)
*
* @param navit The navit instance
- * @param function unused (needed to match command function signiture)
+ * @param function unused (needed to match command function signature)
* @param in input attribute in[0] is the key string
* @param out output attribute, the attr for the given key string if exists or NULL
* @param valid unused
@@ -1053,7 +1055,7 @@ navit_cmd_get_attr_var(struct navit *this, char *function, struct attr **in, str
* Get value given a key string for the command system
*
* @param navit The navit instance
- * @param function unused (needed to match command function signiture)
+ * @param function unused (needed to match command function signature)
* @param in input attribute in[0] is the key string
* @param out output attribute, the value for the given key string if exists or 0
* @param valid unused
@@ -1092,7 +1094,7 @@ GList *cmd_int_var_stack = NULL;
* Push an integer to the stack for the command system
*
* @param navit The navit instance
- * @param function unused (needed to match command function signiture)
+ * @param function unused (needed to match command function signature)
* @param in input attribute in[0] is the integer attibute to push
* @param out output attributes, unused
* @param valid unused
@@ -1112,7 +1114,7 @@ navit_cmd_push_int(struct navit *this, char *function, struct attr **in, struct
* Pop an integer from the command system's integer stack
*
* @param navit The navit instance
- * @param function unused (needed to match command function signiture)
+ * @param function unused (needed to match command function signature)
* @param in input attributes unused
* @param out output attribute, the value popped if stack isn't empty or 0
* @param valid unused
@@ -1140,7 +1142,7 @@ navit_cmd_pop_int(struct navit *this, char *function, struct attr **in, struct a
* Get current size of command system's integer stack
*
* @param navit The navit instance
- * @param function unused (needed to match command function signiture)
+ * @param function unused (needed to match command function signature)
* @param in input attributes unused
* @param out output attribute, the size of stack
* @param valid unused
@@ -1268,7 +1270,7 @@ navit_cmd_fmt_coordinates(struct navit *this, char *function, struct attr **in,
* Join several string attributes into one
*
* @param navit The navit instance
- * @param function unused (needed to match command function signiture)
+ * @param function unused (needed to match command function signature)
* @param in input attributes in[0] - separator, in[1..] - attributes to join
* @param out output attribute joined attribute as string
* @param valid unused
@@ -1305,7 +1307,7 @@ navit_cmd_strjoin(struct navit *this, char *function, struct attr **in, struct a
* Call external program
*
* @param navit The navit instance
- * @param function unused (needed to match command function signiture)
+ * @param function unused (needed to match command function signature)
* @param in input attributes in[0] - name of executable, in[1..] - parameters
* @param out output attribute unused
* @param valid unused
@@ -1387,6 +1389,7 @@ static struct command_table commands[] = {
{"map_item_set_attr",command_cast(navit_cmd_map_item_set_attr)},
{"set_attr_var",command_cast(navit_cmd_set_attr_var)},
{"get_attr_var",command_cast(navit_cmd_get_attr_var)},
+ {"switch_layout_day_night",command_cast(navit_cmd_switch_layout_day_night)},
};
void
@@ -1430,6 +1433,7 @@ navit_new(struct attr *parent, struct attr **attrs)
this_->follow_cursor = 1;
this_->radius = 30;
this_->border = 16;
+ this_->auto_switch = TRUE;
transform_from_geo(pro, &g, &co);
center.x=co.x;
@@ -3361,24 +3365,27 @@ 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;
- struct attr iso8601_attr,geo_attr,valid_attr,layout_attr;
- double trise,tset,trise_actual;
- struct layout *l;
- int year, month, day;
-
- if (navit_get_attr(n,attr_layout,&layout_attr,NULL)!=1) {
- return; //No layout - nothing to switch
- }
- if (!n->vehicle)
- return;
- l=layout_attr.u.layout;
-
- if (l->dayname || l->nightname) {
+ int currTs=0;
+ struct attr iso8601_attr,geo_attr,valid_attr,layout_attr;
+ double trise,tset,trise_actual;
+ struct layout *l;
+ int year, month, day;
+ int after_sunrise = FALSE;
+ int after_sunset = FALSE;
+
+ if (navit_get_attr(n,attr_layout,&layout_attr,NULL)!=1) {
+ return; //No layout - nothing to switch
+ }
+ if (!n->vehicle)
+ return;
+ l=layout_attr.u.layout;
+
+ if (l->dayname || l->nightname) {
//Ok, we know that we have profile to switch
//Check that we aren't calculating too fast
@@ -3386,10 +3393,13 @@ navit_layout_switch(struct navit *n)
currTs=iso8601_to_secs(iso8601_attr.u.str);
dbg(lvl_debug,"currTs: %u:%u\n",currTs%86400/3600,((currTs%86400)%3600)/60);
}
+ dbg(lvl_debug,"prevTs: %u:%u\n",n->prevTs%86400/3600,((n->prevTs%86400)%3600)/60);
if (currTs-(n->prevTs)<60) {
- //We've have to wait a little
- return;
+ //We've have to wait a little
+ return;
}
+ if (n->auto_switch == FALSE)
+ return;
if (sscanf(iso8601_attr.u.str,"%d-%02d-%02dT",&year,&month,&day) != 3)
return;
if (vehicle_get_attr(n->vehicle->vehicle, attr_position_valid, &valid_attr,NULL) && valid_attr.u.num==attr_position_valid_invalid) {
@@ -3399,47 +3409,112 @@ navit_layout_switch(struct navit *n)
//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,-5,1,&trise,&tset)!=0) {
//near the pole sun never rises/sets, so we should never switch profiles
- dbg(lvl_warning,"trise: %u:%u, sun never visible, never switch profile\n",HOURS(trise),MINUTES(trise));
+ dbg(lvl_debug,"trise: %u:%u, sun never visible, never switch profile\n",HOURS(trise),MINUTES(trise));
n->prevTs=currTs;
return;
- }
-
- trise_actual=trise;
- dbg(lvl_debug,"trise: %u:%u\n",HOURS(trise),MINUTES(trise));
- if (l->dayname) {
-
- if ((HOURS(trise)*60+MINUTES(trise)==(currTs%86400)/60) ||
- (n->prevTs==0 && ((HOURS(trise)*60+MINUTES(trise)<(currTs%86400)/60)))) {
- //The sun is rising now!
- if (strcmp(l->name,l->dayname)) {
- navit_set_layout_by_name(n,l->dayname);
}
- }
+ trise_actual=trise;
+ dbg(lvl_debug,"trise: %u:%u\n",HOURS(trise),MINUTES(trise));
+ dbg(lvl_debug,"dayname = %s, name =%s \n",l->dayname, l->name);
+ if (HOURS(trise)*60+MINUTES(trise)<(currTs%86400)/60) {
+ after_sunrise = TRUE;
}
- if (l->nightname) {
- if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) {
+ dbg(lvl_debug,"nightname = %s, name = %s \n",l->nightname, l->name);
+ if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) {
//near the pole sun never rises/sets, so we should never switch profiles
- dbg(lvl_warning,"tset: %u:%u, sun always visible, never switch profile\n",HOURS(tset),MINUTES(tset));
+ dbg(lvl_debug,"tset: %u:%u, sun always visible, never switch profile\n",HOURS(tset),MINUTES(tset));
n->prevTs=currTs;
return;
- }
- dbg(lvl_debug,"tset: %u:%u\n",HOURS(tset),MINUTES(tset));
- if (HOURS(tset)*60+MINUTES(tset)==((currTs%86400)/60)
- || (n->prevTs==0 && (((HOURS(tset)*60+MINUTES(tset)<(currTs%86400)/60)) ||
- ((HOURS(trise_actual)*60+MINUTES(trise_actual)>(currTs%86400)/60))))) {
- //Time to sleep
- if (strcmp(l->name,l->nightname)) {
- navit_set_layout_by_name(n,l->nightname);
- }
- }
}
-
+ dbg(lvl_debug,"tset: %u:%u\n",HOURS(tset),MINUTES(tset));
+ if (((HOURS(tset)*60+MINUTES(tset)<(currTs%86400)/60)) ||
+ ((HOURS(trise_actual)*60+MINUTES(trise_actual)>(currTs%86400)/60))) {
+ after_sunset = TRUE;
+ }
+ if (after_sunrise && !after_sunset && l->dayname) {
+ navit_set_layout_by_name(n,l->dayname);
+ dbg(lvl_debug,"layout set to day\n");
+ }
+ else if (after_sunset && l->nightname) {
+ navit_set_layout_by_name(n,l->nightname);
+ dbg(lvl_debug,"layout set to night\n");
+ }
n->prevTs=currTs;
- }
+ }
+}
+
+/**
+ * @brief this command is used to change the layout and enable/disable the automatic layout switcher
+ *
+ * @param this_ The navit instance
+ * @param function unused
+ * @param in input attributes in[0], a string, see usage below
+ * @param out output attribute unused
+ * @param valid unused
+ *
+ *
+ * usage :
+ * manual : disable autoswitcher
+ * auto : enable autoswitcher
+ * manual_toggle : disable autoswitcher and toggle between day / night layout
+ * manual_day : disable autoswitcher and set to day layout
+ * manual_night : disable autoswitcher and set to night layout
+ *
+ * todo : make it return the state of the autoswitcher and
+ * the version of the active layout (day/night/undefined)
+ */
+static
+void navit_cmd_switch_layout_day_night(struct navit *this_, char *function, struct attr **in, struct attr ***out, int valid)
+{
+
+ if (!(in && in[0] && ATTR_IS_STRING(in[0]->type))) {
+ return;
+ }
+
+ dbg(lvl_debug," called with mode =%s\n",in[0]->u.str);
+
+ if (!this_->layout_current)
+ return;
+
+ if (!this_->vehicle)
+ return;
+
+ if (!strcmp(in[0]->u.str,"manual")) {
+ this_->auto_switch = FALSE;
+ }
+ else if (!strcmp(in[0]->u.str,"auto")) {
+ this_->auto_switch = TRUE;
+ this_->prevTs = 0;
+ navit_layout_switch(this_);
+ }
+ else if (!strcmp(in[0]->u.str,"manual_toggle")) {
+ if (this_->layout_current->dayname) {
+ navit_set_layout_by_name(this_,this_->layout_current->dayname);
+ this_->auto_switch = FALSE;
+ dbg(lvl_debug,"toggeled layout to = %s\n",this_->layout_current->name);
+ }
+ else if (this_->layout_current->nightname) {
+ navit_set_layout_by_name(this_,this_->layout_current->nightname);
+ this_->auto_switch = FALSE;
+ dbg(lvl_debug,"toggeled layout to = %s\n",this_->layout_current->name);
+ }
+ }
+ else if (!strcmp(in[0]->u.str,"manual_day") && this_->layout_current->dayname) {
+ navit_set_layout_by_name(this_,this_->layout_current->dayname);
+ this_->auto_switch = FALSE;
+ dbg(lvl_debug,"switched layout to = %s\n",this_->layout_current->name);
+ }
+ else if (!strcmp(in[0]->u.str,"manual_night") && this_->layout_current->nightname) {
+ navit_set_layout_by_name(this_,this_->layout_current->nightname);
+ this_->auto_switch = FALSE;
+ dbg(lvl_debug,"switched layout to = %s\n",this_->layout_current->name);
+ }
+
+ dbg(lvl_debug,"auto = %i\n",this_->auto_switch);
+ return;
}
int