1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
Index: apps/gui/gwps-common.c
===================================================================
--- apps/gui/gwps-common.c	(Revision 20571)
+++ apps/gui/gwps-common.c	(Arbeitskopie)
@@ -356,7 +356,7 @@
     {
         gwps->state->id3 = id3 = audio_current_track();

-        if (cuesheet_is_enabled() && id3->cuesheet_type
+        if (cuesheet_is_enabled() && id3 && id3->cuesheet_type
             && strcmp(id3->path, curr_cue->audio_filename))
         {
             /* the current cuesheet isn't the right one any more */
@@ -375,7 +375,7 @@
         }
     }

-    if (cuesheet_is_enabled() && id3->cuesheet_type
+    if (cuesheet_is_enabled() && id3 && id3->cuesheet_type
         && (id3->elapsed < curr_cue->curr_track->offset
             || (curr_cue->curr_track_idx < curr_cue->track_count - 1
                 && id3->elapsed >= (curr_cue->curr_track+1)->offset)))
@@ -1873,6 +1873,15 @@
     }
 }

+static void reset_sublines(struct wps_data *data)
+{
+    int i;
+    for (i = 0; i <= data->num_lines; i++)
+    {
+        data->lines[i].curr_subline = SUBLINE_RESET;
+    }
+}
+
 bool gui_wps_redraw(struct gui_wps *gwps,
                      int ffwd_offset,
                      unsigned refresh_mode)
@@ -1913,18 +1922,64 @@

 #endif

+#ifdef HAVE_BACKLIGHT
+    if (global_settings.caption_backlight)
+    {
+        /* turn on backlight n seconds before track ends, and turn it off n
+           seconds into the new track. n == backlight_timeout, or 5s */
+        int n = global_settings.backlight_timeout * 1000;
+
+        if ( n < 1000 )
+            n = 5000; /* use 5s if backlight is always on or off */
+
+        if (((id3->elapsed < 1000) ||
+             ((id3->length - id3->elapsed) < (unsigned)n)) &&
+            (state->paused == false))
+            backlight_on();
+    }
+#endif
+#ifdef HAVE_REMOTE_LCD
+    if (global_settings.remote_caption_backlight)
+    {
+        /* turn on remote backlight n seconds before track ends, and turn it
+           off n seconds into the new track. n == remote_backlight_timeout,
+           or 5s */
+        int n = global_settings.remote_backlight_timeout * 1000;
+
+        if ( n < 1000 )
+            n = 5000; /* use 5s if backlight is always on or off */
+
+        if (((id3->elapsed < 1000) ||
+             ((id3->length - id3->elapsed) < (unsigned)n)) &&
+            (state->paused == false))
+            remote_backlight_on();
+    }
+#endif
+
+#if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
+    if (!lcd_active()
+#ifdef HAVE_REMOTE_LCD
+        /* currently, all remotes are readable without backlight */
+            && (display->screen_type == SCREEN_MAIN)
+#endif
+                                                    )
+    {
+        /* lcd inactive, updates won't be visible, so just return */
+        /* reset sublines to avoid fast subline changing when backlight is
+         * on again */
+        reset_sublines(data);
+        return true;
+    }
+#endif
+
     /* reset to first subline if refresh all flag is set */
     if (refresh_mode == WPS_REFRESH_ALL)
     {
         display->set_viewport(&data->viewports[0].vp);
         display->clear_viewport();
-
-        for (i = 0; i <= data->num_lines; i++)
-        {
-            data->lines[i].curr_subline = SUBLINE_RESET;
-        }
+        reset_sublines(data);
     }
-
+    
 #ifdef HAVE_LCD_CHARCELLS
     for (i = 0; i < 8; i++)
     {
@@ -2085,38 +2140,5 @@

     display->update();

-#ifdef HAVE_BACKLIGHT
-    if (global_settings.caption_backlight)
-    {
-        /* turn on backlight n seconds before track ends, and turn it off n
-           seconds into the new track. n == backlight_timeout, or 5s */
-        int n = global_settings.backlight_timeout * 1000;
-
-        if ( n < 1000 )
-            n = 5000; /* use 5s if backlight is always on or off */
-
-        if (((id3->elapsed < 1000) ||
-             ((id3->length - id3->elapsed) < (unsigned)n)) &&
-            (state->paused == false))
-            backlight_on();
-    }
-#endif
-#ifdef HAVE_REMOTE_LCD
-    if (global_settings.remote_caption_backlight)
-    {
-        /* turn on remote backlight n seconds before track ends, and turn it
-           off n seconds into the new track. n == remote_backlight_timeout,
-           or 5s */
-        int n = global_settings.remote_backlight_timeout * 1000;
-
-        if ( n < 1000 )
-            n = 5000; /* use 5s if backlight is always on or off */
-
-        if (((id3->elapsed < 1000) ||
-             ((id3->length - id3->elapsed) < (unsigned)n)) &&
-            (state->paused == false))
-            remote_backlight_on();
-    }
-#endif
     return true;
 }
Index: apps/gui/gwps.c
===================================================================
--- apps/gui/gwps.c	(Revision 20571)
+++ apps/gui/gwps.c	(Arbeitskopie)
@@ -175,6 +175,13 @@
 #endif
 }

+#if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
+static void wps_lcd_activation_hook(void)
+{
+    queue_post(&button_queue, SYS_LCD_ACTIVATED, 0);
+}
+#endif
+
 static void gwps_fix_statusbars(void)
 {
 #ifdef HAVE_LCD_BITMAP
@@ -212,6 +219,9 @@
     show_remote_main_backdrop();
 #endif
     viewportmanager_set_statusbar(oldbars);
+#if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
+    lcd_activation_set_hook(NULL);
+#endif
 }

 void gwps_draw_statusbars(void)
@@ -651,6 +661,7 @@
             case ACTION_REDRAW: /* yes are locked, just redraw */
                 restore = true;
                 break;
+            case SYS_LCD_ACTIVATED:
             case ACTION_NONE: /* Timeout */
                 update_track = true;
                 ffwd_rew(button); /* hopefully fix the ffw/rwd bug */
@@ -685,13 +696,16 @@
             ((restoretimer == RESTORE_WPS_INSTANTLY) ||
              TIME_AFTER(current_tick, restoretimer)))
         {
-            restore = false;
-            restoretimer = RESTORE_WPS_INSTANTLY;
             FOR_NB_SCREENS(i)
             {
                 screens[i].stop_scroll();
                 gui_wps_display(&gui_wps[i]);
             }
+            restore = false;
+            restoretimer = RESTORE_WPS_INSTANTLY;
+#if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
+            lcd_activation_set_hook(wps_lcd_activation_hook);
+#endif
         }

         if (exit) {
Index: apps/misc.c
===================================================================
--- apps/misc.c	(Revision 20571)
+++ apps/misc.c	(Arbeitskopie)
@@ -615,6 +615,8 @@
 	    iap_handlepkt();
 	    return SYS_IAP_HANDLEPKT;
 #endif
+    case SYS_LCD_ACTIVATED:
+        return SYS_LCD_ACTIVATED;
     }
     return 0;
 }
Index: firmware/export/kernel.h
===================================================================
--- firmware/export/kernel.h	(Revision 20571)
+++ firmware/export/kernel.h	(Arbeitskopie)
@@ -82,6 +82,7 @@
 #define SYS_CAR_ADAPTER_RESUME    MAKE_SYS_EVENT(SYS_EVENT_CLS_MISC, 0)
 #define SYS_IAP_PERIODIC          MAKE_SYS_EVENT(SYS_EVENT_CLS_MISC, 1)
 #define SYS_IAP_HANDLEPKT         MAKE_SYS_EVENT(SYS_EVENT_CLS_MISC, 2)
+#define SYS_LCD_ACTIVATED         MAKE_SYS_EVENT(SYS_EVENT_CLS_MISC, 3)

 #define IS_SYSEVENT(ev)           ((ev & SYS_EVENT) == SYS_EVENT)