-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 | |||
@@ -159,110 +159,112 @@ void OpieScreenSaver::setMode ( int mode ) | |||
159 | if ( mode > m_disable_suspend ) | 159 | if ( mode > m_disable_suspend ) |
160 | setInterval ( -1 ); | 160 | setInterval ( -1 ); |
161 | m_disable_suspend = mode; | 161 | m_disable_suspend = mode; |
162 | } | 162 | } |
163 | 163 | ||
164 | 164 | ||
165 | void OpieScreenSaver::setBacklight ( int bright ) | 165 | void OpieScreenSaver::setBacklight ( int bright ) |
166 | { | 166 | { |
167 | // Read from config | 167 | // Read from config |
168 | Config config ( "apm" ); | 168 | Config config ( "apm" ); |
169 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); | 169 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); |
170 | m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); | 170 | m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); |
171 | 171 | ||
172 | m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); | 172 | m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); |
173 | 173 | ||
174 | //qDebug ( "setBacklight: %d (ls: %d)", m_backlight_normal, m_use_light_sensor ? 1 : 0 ); | 174 | //qDebug ( "setBacklight: %d (ls: %d)", m_backlight_normal, m_use_light_sensor ? 1 : 0 ); |
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 | ||
200 | void OpieScreenSaver::setBacklightInternal ( int bright ) | 202 | void 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 | } |
207 | if ( m_backlight_forcedoff && bright != -2 ) | 209 | if ( m_backlight_forcedoff && bright != -2 ) |
208 | return ; | 210 | return ; |
209 | if ( bright == -2 ) { | 211 | if ( bright == -2 ) { |
210 | // Toggle between off and on | 212 | // Toggle between off and on |
211 | bright = m_backlight_current ? 0 : -1; | 213 | bright = m_backlight_current ? 0 : -1; |
212 | m_backlight_forcedoff = !bright; | 214 | m_backlight_forcedoff = !bright; |
213 | } | 215 | } |
214 | if ( bright == -1 ) | 216 | if ( bright == -1 ) |
215 | bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; | 217 | bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; |
216 | 218 | ||
217 | if ( bright != m_backlight_current ) { | 219 | if ( bright != m_backlight_current ) { |
218 | ODevice::inst ( )-> setDisplayBrightness ( bright ); | 220 | ODevice::inst ( )-> setDisplayBrightness ( bright ); |
219 | m_backlight_current = bright; | 221 | m_backlight_current = bright; |
220 | } | 222 | } |
221 | } | 223 | } |
222 | 224 | ||
223 | 225 | ||
224 | void OpieScreenSaver::timerEvent ( QTimerEvent * ) | 226 | void 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 | ||
250 | void OpieScreenSaver::setDisplayState ( bool on ) | 252 | void OpieScreenSaver::setDisplayState ( bool on ) |
251 | { | 253 | { |
252 | if ( m_lcd_status != on ) { | 254 | if ( m_lcd_status != on ) { |
253 | ODevice::inst ( ) -> setDisplayStatus ( on ); | 255 | ODevice::inst ( ) -> setDisplayStatus ( on ); |
254 | m_lcd_status = on; | 256 | m_lcd_status = on; |
255 | } | 257 | } |
256 | } | 258 | } |
257 | 259 | ||
258 | 260 | ||
259 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) | 261 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) |
260 | { | 262 | { |
261 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); | 263 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); |
262 | 264 | ||
263 | if ( newonac != m_on_ac ) { | 265 | if ( newonac != m_on_ac ) { |
264 | m_on_ac = newonac; | 266 | m_on_ac = newonac; |
265 | setInterval ( -1 ); | 267 | setInterval ( -1 ); |
266 | setBacklight ( -1 ); | 268 | setBacklight ( -1 ); |
267 | restore ( ); | 269 | restore ( ); |
268 | } | 270 | } |