-rw-r--r-- | core/launcher/screensaver.cpp | 4 |
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 @@ -179,24 +179,26 @@ void OpieScreenSaver::setBacklight ( int bright ) m_sensordata [LS_SensorMin] = 40; m_sensordata [LS_SensorMax] = 215; m_sensordata [LS_LightMin] = 1; m_sensordata [LS_LightMax] = 255; m_sensordata [LS_Steps] = 12; m_sensordata [LS_Interval] = 2000; for ( uint i = 0; i < LS_Count; i++ ) { if ( i < sl. count ( )) m_sensordata [i] = sl [i]. toInt ( ); } + if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE + m_sensordata [LS_Steps] = 2; timerEvent ( 0 ); startTimer ( m_sensordata [LS_Interval] ); } setBacklightInternal ( bright ); } void OpieScreenSaver::setBacklightInternal ( int bright ) { if ( bright == -3 ) { @@ -224,25 +226,25 @@ void OpieScreenSaver::setBacklightInternal ( int bright ) void OpieScreenSaver::timerEvent ( QTimerEvent * ) { int s = ODevice::inst ( )-> readLightSensor ( ); if ( s < m_sensordata [LS_SensorMin] ) m_backlight_sensor = m_sensordata [LS_LightMax]; else if ( s >= m_sensordata [LS_SensorMax] ) m_backlight_sensor = m_sensordata [LS_LightMin]; else { int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; - int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; + int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0 m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); } if ( !m_backlight_sensor ) m_backlight_sensor = 1; // 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] ); if ( m_level <= 0 ) setBacklightInternal ( -1 ); } |