summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/screensaver.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp
index 45da9ed..088ed19 100644
--- a/core/launcher/screensaver.cpp
+++ b/core/launcher/screensaver.cpp
@@ -175,32 +175,34 @@ void OpieScreenSaver::setBacklight ( int bright )
175 175
176 killTimers ( ); 176 killTimers ( );
177 if ( m_use_light_sensor ) { 177 if ( m_use_light_sensor ) {
178 QStringList sl = config. readListEntry ( "LightSensorData", ';' ); 178 QStringList sl = config. readListEntry ( "LightSensorData", ';' );
179 179
180 m_sensordata [LS_SensorMin] = 40; 180 m_sensordata [LS_SensorMin] = 40;
181 m_sensordata [LS_SensorMax] = 215; 181 m_sensordata [LS_SensorMax] = 215;
182 m_sensordata [LS_LightMin] = 1; 182 m_sensordata [LS_LightMin] = 1;
183 m_sensordata [LS_LightMax] = 255; 183 m_sensordata [LS_LightMax] = 255;
184 m_sensordata [LS_Steps] = 12; 184 m_sensordata [LS_Steps] = 12;
185 m_sensordata [LS_Interval] = 2000; 185 m_sensordata [LS_Interval] = 2000;
186 186
187 for ( uint i = 0; i < LS_Count; i++ ) { 187 for ( uint i = 0; i < LS_Count; i++ ) {
188 if ( i < sl. count ( )) 188 if ( i < sl. count ( ))
189 m_sensordata [i] = sl [i]. toInt ( ); 189 m_sensordata [i] = sl [i]. toInt ( );
190 } 190 }
191 if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE
192 m_sensordata [LS_Steps] = 2;
191 193
192 timerEvent ( 0 ); 194 timerEvent ( 0 );
193 startTimer ( m_sensordata [LS_Interval] ); 195 startTimer ( m_sensordata [LS_Interval] );
194 } 196 }
195 197
196 setBacklightInternal ( bright ); 198 setBacklightInternal ( bright );
197} 199}
198 200
199 201
200void OpieScreenSaver::setBacklightInternal ( int bright ) 202void OpieScreenSaver::setBacklightInternal ( int bright )
201{ 203{
202 if ( bright == -3 ) { 204 if ( bright == -3 ) {
203 // Forced on 205 // Forced on
204 m_backlight_forcedoff = false; 206 m_backlight_forcedoff = false;
205 bright = -1; 207 bright = -1;
206 } 208 }
@@ -220,33 +222,33 @@ void OpieScreenSaver::setBacklightInternal ( int bright )
220 } 222 }
221} 223}
222 224
223 225
224void OpieScreenSaver::timerEvent ( QTimerEvent * ) 226void OpieScreenSaver::timerEvent ( QTimerEvent * )
225{ 227{
226 int s = ODevice::inst ( )-> readLightSensor ( ); 228 int s = ODevice::inst ( )-> readLightSensor ( );
227 229
228 if ( s < m_sensordata [LS_SensorMin] ) 230 if ( s < m_sensordata [LS_SensorMin] )
229 m_backlight_sensor = m_sensordata [LS_LightMax]; 231 m_backlight_sensor = m_sensordata [LS_LightMax];
230 else if ( s >= m_sensordata [LS_SensorMax] ) 232 else if ( s >= m_sensordata [LS_SensorMax] )
231 m_backlight_sensor = m_sensordata [LS_LightMin]; 233 m_backlight_sensor = m_sensordata [LS_LightMin];
232 else { 234 else {
233 int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; 235 int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin];
234 int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; 236 int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin];
235 237
236 int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; 238 int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0
237 239
238 m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); 240 m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 );
239 } 241 }
240 if ( !m_backlight_sensor ) 242 if ( !m_backlight_sensor )
241 m_backlight_sensor = 1; 243 m_backlight_sensor = 1;
242 244
243 // 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] ); 245 // 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] );
244 246
245 if ( m_level <= 0 ) 247 if ( m_level <= 0 )
246 setBacklightInternal ( -1 ); 248 setBacklightInternal ( -1 );
247} 249}
248 250
249 251
250void OpieScreenSaver::setDisplayState ( bool on ) 252void OpieScreenSaver::setDisplayState ( bool on )
251{ 253{
252 if ( m_lcd_status != on ) { 254 if ( m_lcd_status != on ) {