author | sandman <sandman> | 2002-11-01 18:09:18 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-11-01 18:09:18 (UTC) |
commit | 7b7b760ca3886d5b6562a88b5c2ef8e610b73eb8 (patch) (unidiff) | |
tree | 55cf704333cb124a4764822432078de3caa05037 | |
parent | 75909e820818cc792e42d9c68fd50d05151b311d (diff) | |
download | opie-7b7b760ca3886d5b6562a88b5c2ef8e610b73eb8.zip opie-7b7b760ca3886d5b6562a88b5c2ef8e610b73eb8.tar.gz opie-7b7b760ca3886d5b6562a88b5c2ef8e610b73eb8.tar.bz2 |
- light sensor data was not scaled (no effect for iPAQs though)
- light sensor can now switch off the lcd backlight
- setBacklight ( -3 / -2 ) doesn't switch off the sensor mode anymore
-rw-r--r-- | core/launcher/screensaver.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp index 088ed19..b9bb64c 100644 --- a/core/launcher/screensaver.cpp +++ b/core/launcher/screensaver.cpp | |||
@@ -89,184 +89,182 @@ bool OpieScreenSaver::save( int level ) | |||
89 | } | 89 | } |
90 | 90 | ||
91 | if (( m_on_ac && m_onlylcdoff_ac ) || | 91 | if (( m_on_ac && m_onlylcdoff_ac ) || |
92 | ( !m_on_ac && m_onlylcdoff )) { | 92 | ( !m_on_ac && m_onlylcdoff )) { |
93 | ODevice::inst ( ) -> setDisplayStatus ( false ); | 93 | ODevice::inst ( ) -> setDisplayStatus ( false ); |
94 | m_lcd_status = false; | 94 | m_lcd_status = false; |
95 | return true; | 95 | return true; |
96 | } | 96 | } |
97 | 97 | ||
98 | // We're going to suspend the whole machine | 98 | // We're going to suspend the whole machine |
99 | 99 | ||
100 | if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { | 100 | if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { |
101 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | 101 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); |
102 | return true; | 102 | return true; |
103 | } | 103 | } |
104 | 104 | ||
105 | break; | 105 | break; |
106 | } | 106 | } |
107 | return false; | 107 | return false; |
108 | } | 108 | } |
109 | 109 | ||
110 | 110 | ||
111 | void OpieScreenSaver::setIntervals ( int i1, int i2, int i3 ) | 111 | void OpieScreenSaver::setIntervals ( int i1, int i2, int i3 ) |
112 | { | 112 | { |
113 | Config config ( "apm" ); | 113 | Config config ( "apm" ); |
114 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); | 114 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); |
115 | 115 | ||
116 | int v[ 4 ]; | 116 | int v[ 4 ]; |
117 | if ( i1 < 0 ) | 117 | if ( i1 < 0 ) |
118 | i1 = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); | 118 | i1 = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); |
119 | if ( i2 < 0 ) | 119 | if ( i2 < 0 ) |
120 | i2 = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); | 120 | i2 = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); |
121 | if ( i3 < 0 ) | 121 | if ( i3 < 0 ) |
122 | i3 = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); | 122 | i3 = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); |
123 | 123 | ||
124 | if ( m_on_ac ) { | 124 | if ( m_on_ac ) { |
125 | m_enable_dim_ac = ( i1 > 0 ); | 125 | m_enable_dim_ac = ( i1 > 0 ); |
126 | m_enable_lightoff_ac = ( i2 > 0 ); | 126 | m_enable_lightoff_ac = ( i2 > 0 ); |
127 | m_enable_suspend_ac = ( i3 > 0 ); | 127 | m_enable_suspend_ac = ( i3 > 0 ); |
128 | m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); | 128 | m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); |
129 | } | 129 | } |
130 | else { | 130 | else { |
131 | m_enable_dim = ( i1 > 0 ); | 131 | m_enable_dim = ( i1 > 0 ); |
132 | m_enable_lightoff = ( i2 > 0 ); | 132 | m_enable_lightoff = ( i2 > 0 ); |
133 | m_enable_suspend = ( i3 > 0 ); | 133 | m_enable_suspend = ( i3 > 0 ); |
134 | m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); | 134 | m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); |
135 | } | 135 | } |
136 | 136 | ||
137 | qDebug("screen saver intervals: %d %d %d", i1, i2, i3); | 137 | //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); |
138 | 138 | ||
139 | v [ 0 ] = QMAX( 1000 * i1, 100 ); | 139 | v [ 0 ] = QMAX( 1000 * i1, 100 ); |
140 | v [ 1 ] = QMAX( 1000 * i2, 100 ); | 140 | v [ 1 ] = QMAX( 1000 * i2, 100 ); |
141 | v [ 2 ] = QMAX( 1000 * i3, 100 ); | 141 | v [ 2 ] = QMAX( 1000 * i3, 100 ); |
142 | v [ 3 ] = 0; | 142 | v [ 3 ] = 0; |
143 | 143 | ||
144 | if ( !i1 && !i2 && !i3 ) | 144 | if ( !i1 && !i2 && !i3 ) |
145 | QWSServer::setScreenSaverInterval( 0 ); | 145 | QWSServer::setScreenSaverInterval( 0 ); |
146 | else | 146 | else |
147 | QWSServer::setScreenSaverIntervals( v ); | 147 | QWSServer::setScreenSaverIntervals( v ); |
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
151 | void OpieScreenSaver::setInterval ( int interval ) | 151 | void OpieScreenSaver::setInterval ( int interval ) |
152 | { | 152 | { |
153 | setIntervals ( -1, -1, interval ); | 153 | setIntervals ( -1, -1, interval ); |
154 | } | 154 | } |
155 | 155 | ||
156 | 156 | ||
157 | void OpieScreenSaver::setMode ( int mode ) | 157 | void OpieScreenSaver::setMode ( int mode ) |
158 | { | 158 | { |
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 (norm: %d) (ls: %d)", bright, m_backlight_normal, m_use_light_sensor ? 1 : 0 ); |
175 | 175 | ||
176 | killTimers ( ); | 176 | killTimers ( ); |
177 | if ( m_use_light_sensor ) { | 177 | if (( bright < 0 ) && 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 | 191 | if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE |
192 | m_sensordata [LS_Steps] = 2; | 192 | m_sensordata [LS_Steps] = 2; |
193 | 193 | ||
194 | timerEvent ( 0 ); | 194 | timerEvent ( 0 ); |
195 | startTimer ( m_sensordata [LS_Interval] ); | 195 | startTimer ( m_sensordata [LS_Interval] ); |
196 | } | 196 | } |
197 | 197 | ||
198 | setBacklightInternal ( bright ); | 198 | setBacklightInternal ( bright ); |
199 | } | 199 | } |
200 | 200 | ||
201 | 201 | ||
202 | void OpieScreenSaver::setBacklightInternal ( int bright ) | 202 | void OpieScreenSaver::setBacklightInternal ( int bright ) |
203 | { | 203 | { |
204 | if ( bright == -3 ) { | 204 | if ( bright == -3 ) { |
205 | // Forced on | 205 | // Forced on |
206 | m_backlight_forcedoff = false; | 206 | m_backlight_forcedoff = false; |
207 | bright = -1; | 207 | bright = -1; |
208 | } | 208 | } |
209 | if ( m_backlight_forcedoff && bright != -2 ) | 209 | if ( m_backlight_forcedoff && bright != -2 ) |
210 | return ; | 210 | return ; |
211 | if ( bright == -2 ) { | 211 | if ( bright == -2 ) { |
212 | // Toggle between off and on | 212 | // Toggle between off and on |
213 | bright = m_backlight_current ? 0 : -1; | 213 | bright = m_backlight_current ? 0 : -1; |
214 | m_backlight_forcedoff = !bright; | 214 | m_backlight_forcedoff = !bright; |
215 | } | 215 | } |
216 | if ( bright == -1 ) | 216 | if ( bright == -1 ) |
217 | bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; | 217 | bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; |
218 | 218 | ||
219 | if ( bright != m_backlight_current ) { | 219 | if ( bright != m_backlight_current ) { |
220 | ODevice::inst ( )-> setDisplayBrightness ( bright ); | 220 | ODevice::inst ( )-> setDisplayBrightness ( bright ); |
221 | m_backlight_current = bright; | 221 | m_backlight_current = bright; |
222 | } | 222 | } |
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
226 | void OpieScreenSaver::timerEvent ( QTimerEvent * ) | 226 | void OpieScreenSaver::timerEvent ( QTimerEvent * ) |
227 | { | 227 | { |
228 | int s = ODevice::inst ( )-> readLightSensor ( ); | 228 | int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( ); |
229 | 229 | ||
230 | if ( s < m_sensordata [LS_SensorMin] ) | 230 | if ( s < m_sensordata [LS_SensorMin] ) |
231 | m_backlight_sensor = m_sensordata [LS_LightMax]; | 231 | m_backlight_sensor = m_sensordata [LS_LightMax]; |
232 | else if ( s >= m_sensordata [LS_SensorMax] ) | 232 | else if ( s >= m_sensordata [LS_SensorMax] ) |
233 | m_backlight_sensor = m_sensordata [LS_LightMin]; | 233 | m_backlight_sensor = m_sensordata [LS_LightMin]; |
234 | else { | 234 | else { |
235 | int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; | 235 | int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; |
236 | int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; | 236 | int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; |
237 | 237 | ||
238 | int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0 | 238 | int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0 |
239 | 239 | ||
240 | 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 ); |
241 | } | 241 | } |
242 | if ( !m_backlight_sensor ) | ||
243 | m_backlight_sensor = 1; | ||
244 | 242 | ||
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] ); | 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] ); |
246 | 244 | ||
247 | if ( m_level <= 0 ) | 245 | if ( m_level <= 0 ) |
248 | setBacklightInternal ( -1 ); | 246 | setBacklightInternal ( -1 ); |
249 | } | 247 | } |
250 | 248 | ||
251 | 249 | ||
252 | void OpieScreenSaver::setDisplayState ( bool on ) | 250 | void OpieScreenSaver::setDisplayState ( bool on ) |
253 | { | 251 | { |
254 | if ( m_lcd_status != on ) { | 252 | if ( m_lcd_status != on ) { |
255 | ODevice::inst ( ) -> setDisplayStatus ( on ); | 253 | ODevice::inst ( ) -> setDisplayStatus ( on ); |
256 | m_lcd_status = on; | 254 | m_lcd_status = on; |
257 | } | 255 | } |
258 | } | 256 | } |
259 | 257 | ||
260 | 258 | ||
261 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) | 259 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) |
262 | { | 260 | { |
263 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); | 261 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); |
264 | 262 | ||
265 | if ( newonac != m_on_ac ) { | 263 | if ( newonac != m_on_ac ) { |
266 | m_on_ac = newonac; | 264 | m_on_ac = newonac; |
267 | setInterval ( -1 ); | 265 | setInterval ( -1 ); |
268 | setBacklight ( -1 ); | 266 | setBacklight ( -1 ); |
269 | restore ( ); | 267 | restore ( ); |
270 | } | 268 | } |
271 | } | 269 | } |
272 | 270 | ||