-rw-r--r-- | core/launcher/screensaver.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp index a7d23c4..f818d62 100644 --- a/core/launcher/screensaver.cpp +++ b/core/launcher/screensaver.cpp | |||
@@ -1,31 +1,32 @@ | |||
1 | 1 | ||
2 | #include "screensaver.h" | 2 | #include "screensaver.h" |
3 | 3 | ||
4 | #include <qpe/config.h> | 4 | #include <qpe/config.h> |
5 | #include <qpe/network.h> | 5 | #include <qpe/network.h> |
6 | 6 | ||
7 | #include <opie2/odevice.h> | 7 | #include <opie2/odevice.h> |
8 | #include <opie2/odebug.h> | ||
8 | 9 | ||
9 | 10 | ||
10 | using namespace Opie::Core; | 11 | using namespace Opie::Core; |
11 | 12 | ||
12 | 13 | ||
13 | 14 | ||
14 | OpieScreenSaver::OpieScreenSaver ( ) | 15 | OpieScreenSaver::OpieScreenSaver ( ) |
15 | : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) | 16 | : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) |
16 | { | 17 | { |
17 | m_disable_suspend = 100; | 18 | m_disable_suspend = 100; |
18 | m_enable_dim = false; | 19 | m_enable_dim = false; |
19 | m_enable_lightoff = false; | 20 | m_enable_lightoff = false; |
20 | m_enable_suspend = false; | 21 | m_enable_suspend = false; |
21 | m_onlylcdoff = false; | 22 | m_onlylcdoff = false; |
22 | 23 | ||
23 | m_enable_dim_ac = false; | 24 | m_enable_dim_ac = false; |
24 | m_enable_lightoff_ac = false; | 25 | m_enable_lightoff_ac = false; |
25 | m_enable_suspend_ac = false; | 26 | m_enable_suspend_ac = false; |
26 | m_onlylcdoff_ac = false; | 27 | m_onlylcdoff_ac = false; |
27 | 28 | ||
28 | m_use_light_sensor = false; | 29 | m_use_light_sensor = false; |
29 | m_backlight_sensor = -1; | 30 | m_backlight_sensor = -1; |
30 | ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] )); | 31 | ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] )); |
31 | 32 | ||
@@ -189,49 +190,50 @@ void OpieScreenSaver::setMode ( int mode ) | |||
189 | if ( mode > m_disable_suspend ) | 190 | if ( mode > m_disable_suspend ) |
190 | setInterval ( -1 ); | 191 | setInterval ( -1 ); |
191 | m_disable_suspend = mode; | 192 | m_disable_suspend = mode; |
192 | } | 193 | } |
193 | 194 | ||
194 | 195 | ||
195 | /** | 196 | /** |
196 | * Set display brightness | 197 | * Set display brightness |
197 | * | 198 | * |
198 | * Get's default values for backlight, contrast and light sensor from config file. | 199 | * Get's default values for backlight, contrast and light sensor from config file. |
199 | * | 200 | * |
200 | * @param bright desired brighness (-1 to use automatic sensor data or value | 201 | * @param bright desired brighness (-1 to use automatic sensor data or value |
201 | * from config file, -2 to toggle backlight on and off, -3 to | 202 | * from config file, -2 to toggle backlight on and off, -3 to |
202 | * force backlight off) | 203 | * force backlight off) |
203 | */ | 204 | */ |
204 | void OpieScreenSaver::setBacklight ( int bright ) | 205 | void OpieScreenSaver::setBacklight ( int bright ) |
205 | { | 206 | { |
206 | // Read from config | 207 | // Read from config |
207 | Config config ( "apm" ); | 208 | Config config ( "apm" ); |
208 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); | 209 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); |
209 | m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); | 210 | m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); |
210 | int contrast = config. readNumEntry ( "Contrast", 127); | 211 | int contrast = config. readNumEntry ( "Contrast", 127); |
211 | m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); | 212 | m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); |
212 | 213 | ||
213 | //qDebug ( "setBacklight: %d (norm: %d) (ls: %d)", bright, m_backlight_normal, m_use_light_sensor ? 1 : 0 ); | 214 | //odebug << "setBacklight: " << bright << " (norm: " << m_backlight_normal << ") (ls: " |
215 | // << ( m_use_light_sensor ? 1 : 0 ) << ")" << oendl; | ||
214 | 216 | ||
215 | killTimers ( ); | 217 | killTimers ( ); |
216 | if (( bright < 0 ) && m_use_light_sensor ) { | 218 | if (( bright < 0 ) && m_use_light_sensor ) { |
217 | QStringList sl = config. readListEntry ( "LightSensorData", ';' ); | 219 | QStringList sl = config. readListEntry ( "LightSensorData", ';' ); |
218 | 220 | ||
219 | m_sensordata [LS_SensorMin] = 40; | 221 | m_sensordata [LS_SensorMin] = 40; |
220 | m_sensordata [LS_SensorMax] = 215; | 222 | m_sensordata [LS_SensorMax] = 215; |
221 | m_sensordata [LS_LightMin] = 1; | 223 | m_sensordata [LS_LightMin] = 1; |
222 | m_sensordata [LS_LightMax] = 255; | 224 | m_sensordata [LS_LightMax] = 255; |
223 | m_sensordata [LS_Steps] = 12; | 225 | m_sensordata [LS_Steps] = 12; |
224 | m_sensordata [LS_Interval] = 2000; | 226 | m_sensordata [LS_Interval] = 2000; |
225 | 227 | ||
226 | for ( uint i = 0; i < LS_Count; i++ ) { | 228 | for ( uint i = 0; i < LS_Count; i++ ) { |
227 | if ( i < sl. count ( )) | 229 | if ( i < sl. count ( )) |
228 | m_sensordata [i] = sl [i]. toInt ( ); | 230 | m_sensordata [i] = sl [i]. toInt ( ); |
229 | } | 231 | } |
230 | if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE | 232 | if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE |
231 | m_sensordata [LS_Steps] = 2; | 233 | m_sensordata [LS_Steps] = 2; |
232 | 234 | ||
233 | timerEvent ( 0 ); | 235 | timerEvent ( 0 ); |
234 | startTimer ( m_sensordata [LS_Interval] ); | 236 | startTimer ( m_sensordata [LS_Interval] ); |
235 | } | 237 | } |
236 | 238 | ||
237 | setBacklightInternal ( bright ); | 239 | setBacklightInternal ( bright ); |
@@ -272,49 +274,51 @@ void OpieScreenSaver::setBacklightInternal ( int bright ) | |||
272 | } | 274 | } |
273 | 275 | ||
274 | 276 | ||
275 | /** | 277 | /** |
276 | * Timer event used for automatic setting the backlight according to a light sensor | 278 | * Timer event used for automatic setting the backlight according to a light sensor |
277 | * and to set the default brightness | 279 | * and to set the default brightness |
278 | */ | 280 | */ |
279 | void OpieScreenSaver::timerEvent ( QTimerEvent * ) | 281 | void OpieScreenSaver::timerEvent ( QTimerEvent * ) |
280 | { | 282 | { |
281 | int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( ); | 283 | int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( ); |
282 | 284 | ||
283 | if ( s < m_sensordata [LS_SensorMin] ) | 285 | if ( s < m_sensordata [LS_SensorMin] ) |
284 | m_backlight_sensor = m_sensordata [LS_LightMax]; | 286 | m_backlight_sensor = m_sensordata [LS_LightMax]; |
285 | else if ( s >= m_sensordata [LS_SensorMax] ) | 287 | else if ( s >= m_sensordata [LS_SensorMax] ) |
286 | m_backlight_sensor = m_sensordata [LS_LightMin]; | 288 | m_backlight_sensor = m_sensordata [LS_LightMin]; |
287 | else { | 289 | else { |
288 | int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; | 290 | int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; |
289 | int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; | 291 | int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; |
290 | 292 | ||
291 | int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0 | 293 | int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0 |
292 | 294 | ||
293 | m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); | 295 | m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); |
294 | } | 296 | } |
295 | 297 | ||
296 | //qDebug ( "f(%d) = %d [%d - %d] -> [%d - %d] / %d", s, m_backlight_sensor, m_sensordata [LS_SensorMin], m_sensordata [LS_SensorMax], m_sensordata [LS_LightMin], m_sensordata [LS_LightMax], m_sensordata [LS_Steps] ); | 298 | odebug << "f(" << s << ") = " << m_backlight_sensor << " [" << m_sensordata [LS_SensorMin] |
299 | << " - " << m_sensordata [LS_SensorMax] << " ] -> [" << m_sensordata [LS_LightMin] | ||
300 | << " - " << m_sensordata [LS_LightMax] << "] / " << m_sensordata [LS_Steps] << oendl; | ||
297 | 301 | ||
298 | if ( m_level <= 0 ) | 302 | if ( m_level <= 0 ) |
299 | setBacklightInternal ( -1 ); | 303 | setBacklightInternal ( -1 ); |
300 | } | 304 | } |
301 | 305 | ||
302 | 306 | ||
303 | /** | 307 | /** |
304 | * Like ODevice::setDisplayStatus(), but keep current state in m_lcd_status. | 308 | * Like ODevice::setDisplayStatus(), but keep current state in m_lcd_status. |
305 | */ | 309 | */ |
306 | void OpieScreenSaver::setDisplayState ( bool on ) | 310 | void OpieScreenSaver::setDisplayState ( bool on ) |
307 | { | 311 | { |
308 | if ( m_lcd_status != on ) { | 312 | if ( m_lcd_status != on ) { |
309 | ODevice::inst ( ) -> setDisplayStatus ( on ); | 313 | ODevice::inst ( ) -> setDisplayStatus ( on ); |
310 | m_lcd_status = on; | 314 | m_lcd_status = on; |
311 | } | 315 | } |
312 | } | 316 | } |
313 | 317 | ||
314 | 318 | ||
315 | /** | 319 | /** |
316 | * Set display to default ac/battery settings when power status changed. | 320 | * Set display to default ac/battery settings when power status changed. |
317 | */ | 321 | */ |
318 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) | 322 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) |
319 | { | 323 | { |
320 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); | 324 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); |