@@ -79,16 +79,88 @@ static inline void debug_mtinfo(iv_mtinfo *mti) {
79
79
printf ("\n" );
80
80
}
81
81
82
+ /*
83
+ * The PocketBook has an auto-suspend-feature, which puts the reader to sleep
84
+ * after approximately two seconds "inactivity in the current eventhandler".
85
+ *
86
+ * The handler (pb_event_handle) runs via InkViewMain in a forked-off process
87
+ * and just relays incoming events like keypress / touch via a pipe to the
88
+ * main-koreader-process when they occur. In consequence, the forked process
89
+ * quickly becomes idle w/o external events, leading to suspension of the
90
+ * whole device.
91
+ *
92
+ * This breaks the initial loading of modules and books.
93
+ *
94
+ * There are multiple functions which can affect auto-suspension: Beside
95
+ * iv_sleepmode() which controls if auto-suspension is enabled at all, the
96
+ * function SetHardTimer() makes it possible to execute a callback after a
97
+ * given amount of time. SetHardTimer() will wake the Reader if it is
98
+ * suspended and suspension will not occur while the callback is executed.
99
+ *
100
+ * However, both functions will not work properly if not called _from within
101
+ * the current eventhandler_.
102
+ *
103
+ * SendEventTo() can be used to send an event to the current eventhandler of a
104
+ * specific (system) task. GetCurrentTask() returns the caller's currently
105
+ * active task.
106
+ */
107
+
108
+ /*
109
+ * define a fake-event which can be send via SendEventTo into
110
+ * pb_event_handle()
111
+ */
112
+ #define PB_SPECIAL_SUSPEND 333
113
+
114
+ /* callback to disable suspension */
115
+ void disable_suspend (void ) {
116
+ iv_sleepmode (0 );
117
+ }
118
+
119
+ /* callback to enable suspension */
120
+ void enable_suspend (void ) {
121
+ iv_sleepmode (1 );
122
+ }
123
+
124
+ static int external_suspend_control = 0 ;
125
+
126
+ void fallback_enable_suspend (void ) {
127
+ if (external_suspend_control == 0 )
128
+ enable_suspend ();
129
+ }
130
+
131
+ static int send_to_event_handler (int type , int par1 , int par2 ) {
132
+ SendEventTo (GetCurrentTask (), type , par1 , par2 );
133
+ }
134
+
135
+
136
+ static int setSuspendState (lua_State * L ) {
137
+ send_to_event_handler (
138
+ PB_SPECIAL_SUSPEND ,
139
+ luaL_checkint (L , 1 ),
140
+ luaL_checkint (L ,2 )
141
+ );
142
+ }
143
+
82
144
int touch_pointers = 0 ;
83
145
static int pb_event_handler (int type , int par1 , int par2 ) {
84
- //printf("ev:%d %d %d\n", type, par1, par2);
85
- //fflush(stdout);
146
+ // printf("ev:%d %d %d\n", type, par1, par2);
147
+ // fflush(stdout);
86
148
int i ;
87
149
iv_mtinfo * mti ;
150
+
88
151
// general settings in only possible in forked process
89
152
if (type == EVT_INIT ) {
90
153
SetPanelType (PANEL_DISABLED );
91
154
get_gti_pointer ();
155
+ /* disable suspend to make uninterrupted loading possible. */
156
+ disable_suspend ();
157
+ /*
158
+ * re-enable suspending after a minute. This is normally handled by a
159
+ * plugin on onReaderReady(). However, if loading of the plugin fails
160
+ * for some reason, suspension would stay inactive consuming a lot of
161
+ * power
162
+ */
163
+ SetHardTimer ("fallback_enable_suspend" , fallback_enable_suspend , 1000 * 60 );
92
164
}
93
165
94
166
if (type == EVT_POINTERDOWN ) {
@@ -132,6 +204,12 @@ static int pb_event_handler(int type, int par1, int par2) {
132
204
genEmuEvent (inputfds [0 ], EV_ABS , ABS_MT_TRACKING_ID , -1 );
133
205
}
134
206
touch_pointers = 0 ;
207
+ } else if (type == PB_SPECIAL_SUSPEND ) {
208
+ external_suspend_control = 1 ;
209
+ if (par1 == 0 )
210
+ SetHardTimer ("disable_suspend" , disable_suspend , par2 );
211
+ else
212
+ SetHardTimer ("enable_suspend" , enable_suspend , par2 );
135
213
} else {
136
214
genEmuEvent (inputfds [0 ], type , par1 , par2 );
137
215
}
0 commit comments