summaryrefslogtreecommitdiff
authorerik <erik>2007-02-21 16:59:03 (UTC)
committer erik <erik>2007-02-21 16:59:03 (UTC)
commit6b0fa616c4aac654c549621eb0009ab3eb32fe34 (patch) (unidiff)
treeb5a592194a9cbf3b02b38b0d2e412201beb5b49c
parent45f2e4cdc6e185439ef4bde6e2b8181a4decd032 (diff)
downloadopie-6b0fa616c4aac654c549621eb0009ab3eb32fe34.zip
opie-6b0fa616c4aac654c549621eb0009ab3eb32fe34.tar.gz
opie-6b0fa616c4aac654c549621eb0009ab3eb32fe34.tar.bz2
This commit fixes Opie bug 1839:
http://opie-bugs.oszine.de/view.php?id=1839
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_ipaq.cpp24
1 files changed, 10 insertions, 14 deletions
diff --git a/libopie2/opiecore/device/odevice_ipaq.cpp b/libopie2/opiecore/device/odevice_ipaq.cpp
index 02b685a..6dc1295 100644
--- a/libopie2/opiecore/device/odevice_ipaq.cpp
+++ b/libopie2/opiecore/device/odevice_ipaq.cpp
@@ -128,402 +128,398 @@ struct i_button ipaq_buttons [] = {
128 "addressbook", "beamBusinessCard()" }, 128 "addressbook", "beamBusinessCard()" },
129 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, 129 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx,
130 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 130 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
131 "devicebuttons/ipaq_menu", 131 "devicebuttons/ipaq_menu",
132 "QPE/TaskBar", "toggleMenu()", 132 "QPE/TaskBar", "toggleMenu()",
133 "QPE/TaskBar", "toggleStartMenu()" }, 133 "QPE/TaskBar", "toggleStartMenu()" },
134 { Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, 134 { Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx,
135 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), 135 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"),
136 "devicebuttons/ipaq_mail", 136 "devicebuttons/ipaq_mail",
137 "opiemail", "raise()", 137 "opiemail", "raise()",
138 "opiemail", "newMail()" }, 138 "opiemail", "newMail()" },
139 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, 139 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx,
140 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 140 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
141 "devicebuttons/ipaq_home", 141 "devicebuttons/ipaq_home",
142 "QPE/Launcher", "home()", 142 "QPE/Launcher", "home()",
143 "buttonsettings", "raise()" }, 143 "buttonsettings", "raise()" },
144 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, 144 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx,
145 Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), 145 Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"),
146 "devicebuttons/ipaq_record", 146 "devicebuttons/ipaq_record",
147 "QPE/VMemo", "toggleRecord()", 147 "QPE/VMemo", "toggleRecord()",
148 "sound", "raise()" }, 148 "sound", "raise()" },
149 149
150}; 150};
151 151
152void iPAQ::init(const QString& model) 152void iPAQ::init(const QString& model)
153{ 153{
154 d->m_vendorstr = "HP"; 154 d->m_vendorstr = "HP";
155 d->m_vendor = Vendor_HP; 155 d->m_vendor = Vendor_HP;
156 156
157 d->m_modelstr = model.mid(model.findRev('H')); 157 d->m_modelstr = model.mid(model.findRev('H'));
158 158
159 if ( d->m_modelstr == "H3100" ) 159 if ( d->m_modelstr == "H3100" )
160 d->m_model = Model_iPAQ_H31xx; 160 d->m_model = Model_iPAQ_H31xx;
161 else if ( d->m_modelstr == "H3600" ) 161 else if ( d->m_modelstr == "H3600" )
162 d->m_model = Model_iPAQ_H36xx; 162 d->m_model = Model_iPAQ_H36xx;
163 else if ( d->m_modelstr == "H3700" ) 163 else if ( d->m_modelstr == "H3700" )
164 d->m_model = Model_iPAQ_H37xx; 164 d->m_model = Model_iPAQ_H37xx;
165 else if ( d->m_modelstr == "H3800" ) 165 else if ( d->m_modelstr == "H3800" )
166 d->m_model = Model_iPAQ_H38xx; 166 d->m_model = Model_iPAQ_H38xx;
167 else if ( d->m_modelstr == "H3900" ) 167 else if ( d->m_modelstr == "H3900" )
168 d->m_model = Model_iPAQ_H39xx; 168 d->m_model = Model_iPAQ_H39xx;
169 else if ( d->m_modelstr == "H5400" ) 169 else if ( d->m_modelstr == "H5400" )
170 d->m_model = Model_iPAQ_H5xxx; 170 d->m_model = Model_iPAQ_H5xxx;
171 else if ( d->m_modelstr == "H2200" ) 171 else if ( d->m_modelstr == "H2200" )
172 d->m_model = Model_iPAQ_H22xx; 172 d->m_model = Model_iPAQ_H22xx;
173 else if ( d->m_modelstr == "H1910" ) 173 else if ( d->m_modelstr == "H1910" )
174 d->m_model = Model_iPAQ_H191x; 174 d->m_model = Model_iPAQ_H191x;
175 else if ( d->m_modelstr == "H1940" ) 175 else if ( d->m_modelstr == "H1940" )
176 d->m_model = Model_iPAQ_H1940; 176 d->m_model = Model_iPAQ_H1940;
177 else if ( d->m_modelstr == "HX4700" ) 177 else if ( d->m_modelstr == "HX4700" )
178 d->m_model = Model_iPAQ_HX4700; 178 d->m_model = Model_iPAQ_HX4700;
179 else if ( d->m_modelstr == "H4000" ) 179 else if ( d->m_modelstr == "H4000" )
180 d->m_model = Model_iPAQ_H4xxx; 180 d->m_model = Model_iPAQ_H4xxx;
181 181
182 else 182 else
183 d->m_model = Model_Unknown; 183 d->m_model = Model_Unknown;
184 184
185 switch ( d->m_model ) { 185 switch ( d->m_model ) {
186 case Model_iPAQ_H31xx: 186 case Model_iPAQ_H31xx:
187 case Model_iPAQ_H38xx: 187 case Model_iPAQ_H38xx:
188 d->m_rotation = Rot90; 188 d->m_rotation = Rot90;
189 break; 189 break;
190 case Model_iPAQ_H5xxx: 190 case Model_iPAQ_H5xxx:
191 case Model_iPAQ_H22xx: 191 case Model_iPAQ_H22xx:
192 case Model_iPAQ_H191x: 192 case Model_iPAQ_H191x:
193 case Model_iPAQ_H1940: 193 case Model_iPAQ_H1940:
194 case Model_iPAQ_HX4700: 194 case Model_iPAQ_HX4700:
195 case Model_iPAQ_H4xxx: 195 case Model_iPAQ_H4xxx:
196 d->m_rotation = Rot0; 196 d->m_rotation = Rot0;
197 break; 197 break;
198 case Model_iPAQ_H36xx: 198 case Model_iPAQ_H36xx:
199 case Model_iPAQ_H37xx: 199 case Model_iPAQ_H37xx:
200 case Model_iPAQ_H39xx: 200 case Model_iPAQ_H39xx:
201 default: 201 default:
202 d->m_rotation = Rot270; 202 d->m_rotation = Rot270;
203 break; 203 break;
204 204
205 } 205 }
206 206
207 m_leds [0] = m_leds [1] = Led_Off; 207 m_leds [0] = m_leds [1] = Led_Off;
208 208
209 m_power_timer = 0; 209 m_power_timer = 0;
210 210
211} 211}
212 212
213void iPAQ::initButtons() 213void iPAQ::initButtons()
214{ 214{
215 if ( d->m_buttons ) 215 if ( d->m_buttons )
216 return; 216 return;
217 217
218 if ( isQWS( ) ) { 218 if ( isQWS( ) ) {
219 addPreHandler(this); 219 addPreHandler(this);
220 } 220 }
221 221
222 d->m_buttons = new QValueList <ODeviceButton>; 222 d->m_buttons = new QValueList <ODeviceButton>;
223 223
224 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 224 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
225 i_button *ib = ipaq_buttons + i; 225 i_button *ib = ipaq_buttons + i;
226 ODeviceButton b; 226 ODeviceButton b;
227 227
228 if (( ib->model & d->m_model ) == d->m_model ) { 228 if (( ib->model & d->m_model ) == d->m_model ) {
229 b. setKeycode ( ib->code ); 229 b. setKeycode ( ib->code );
230 b. setUserText ( QObject::tr ( "Button", ib->utext )); 230 b. setUserText ( QObject::tr ( "Button", ib->utext ));
231 b. setPixmap ( OResource::loadPixmap ( ib->pix )); 231 b. setPixmap ( OResource::loadPixmap ( ib->pix ));
232 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib->fpressedservice ), ib->fpressedaction )); 232 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib->fpressedservice ), ib->fpressedaction ));
233 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib->fheldservice ), ib->fheldaction )); 233 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib->fheldservice ), ib->fheldaction ));
234 234
235 d->m_buttons->append ( b ); 235 d->m_buttons->append ( b );
236 } 236 }
237 } 237 }
238 reloadButtonMapping(); 238 reloadButtonMapping();
239} 239}
240 240
241QValueList <OLed> iPAQ::ledList() const 241QValueList <OLed> iPAQ::ledList() const
242{ 242{
243 QValueList <OLed> vl; 243 QValueList <OLed> vl;
244 vl << Led_Power; 244 vl << Led_Power;
245 245
246 if ( d->m_model == Model_iPAQ_H38xx ) 246 if ( d->m_model == Model_iPAQ_H38xx )
247 vl << Led_BlueTooth; 247 vl << Led_BlueTooth;
248 return vl; 248 return vl;
249} 249}
250 250
251QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const 251QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const
252{ 252{
253 QValueList <OLedState> vl; 253 QValueList <OLedState> vl;
254 254
255 if ( l == Led_Power ) 255 if ( l == Led_Power )
256 vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; 256 vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast;
257 else if ( l == Led_BlueTooth && d->m_model == Model_iPAQ_H38xx ) 257 else if ( l == Led_BlueTooth && d->m_model == Model_iPAQ_H38xx )
258 vl << Led_Off; // << Led_On << ??? 258 vl << Led_Off; // << Led_On << ???
259 259
260 return vl; 260 return vl;
261} 261}
262 262
263OLedState iPAQ::ledState ( OLed l ) const 263OLedState iPAQ::ledState ( OLed l ) const
264{ 264{
265 switch ( l ) { 265 switch ( l ) {
266 case Led_Power: 266 case Led_Power:
267 return m_leds [0]; 267 return m_leds [0];
268 case Led_BlueTooth: 268 case Led_BlueTooth:
269 return m_leds [1]; 269 return m_leds [1];
270 default: 270 default:
271 return Led_Off; 271 return Led_Off;
272 } 272 }
273} 273}
274 274
275bool iPAQ::setLedState ( OLed l, OLedState st ) 275bool iPAQ::setLedState ( OLed l, OLedState st )
276{ 276{
277 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK ); 277 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK );
278 278
279 if ( l == Led_Power ) { 279 if ( l == Led_Power ) {
280 if ( fd >= 0 ) { 280 if ( fd >= 0 ) {
281 LED_IN leds; 281 LED_IN leds;
282 ::memset ( &leds, 0, sizeof( leds )); 282 ::memset ( &leds, 0, sizeof( leds ));
283 leds. TotalTime = 0; 283 leds. TotalTime = 0;
284 leds. OnTime = 0; 284 leds. OnTime = 0;
285 leds. OffTime = 1; 285 leds. OffTime = 1;
286 leds. OffOnBlink = 2; 286 leds. OffOnBlink = 2;
287 287
288 switch ( st ) { 288 switch ( st ) {
289 case Led_Off : leds. OffOnBlink = 0; break; 289 case Led_Off : leds. OffOnBlink = 0; break;
290 case Led_On : leds. OffOnBlink = 1; break; 290 case Led_On : leds. OffOnBlink = 1; break;
291 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; 291 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break;
292 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; 292 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break;
293 } 293 }
294 294
295 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { 295 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) {
296 m_leds [0] = st; 296 m_leds [0] = st;
297 return true; 297 return true;
298 } 298 }
299 } 299 }
300 } 300 }
301 return false; 301 return false;
302} 302}
303 303
304 304
305bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) 305bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
306{ 306{
307 int newkeycode = keycode; 307 int newkeycode = keycode;
308 308
309 switch ( keycode ) { 309 switch ( keycode ) {
310 // H38xx/H39xx have no "Q" key anymore - this is now the Mail key 310 // H38xx/H39xx have no "Q" key anymore - this is now the Mail key
311 case HardKey_Menu: { 311 case HardKey_Menu: {
312 if (( d->m_model == Model_iPAQ_H38xx ) || 312 if (( d->m_model == Model_iPAQ_H38xx ) ||
313 ( d->m_model == Model_iPAQ_H39xx ) || 313 ( d->m_model == Model_iPAQ_H39xx ) ||
314 ( d->m_model == Model_iPAQ_H5xxx)) { 314 ( d->m_model == Model_iPAQ_H5xxx)) {
315 newkeycode = HardKey_Mail; 315 newkeycode = HardKey_Mail;
316 } 316 }
317 break; 317 break;
318 } 318 }
319 319
320 // Rotate cursor keys 180 or 270 320 // QT has strange screen coordinate system, so depending
321 // on native device screen orientation, we need to rotate cursor keys
321 case Key_Left : 322 case Key_Left :
322 case Key_Right: 323 case Key_Right:
323 case Key_Up : 324 case Key_Up :
324 case Key_Down : { 325 case Key_Down : {
325 if (( d->m_model == Model_iPAQ_H31xx ) || 326 int quarters;
326 ( d->m_model == Model_iPAQ_H38xx )) { 327 switch (d->m_rotation) {
327 newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4; 328 case Rot0: quarters = 3/*270deg*/; break;
328 } 329 case Rot90: quarters = 2/*270deg*/; break;
329 // Rotate the cursor keys by 270 330 case Rot180: quarters = 1/*270deg*/; break;
330 // keycode - Key_Left = position of the button starting from left clockwise 331 case Rot270: quarters = 0/*270deg*/; break;
331 // add the rotation to it and modolo. No we've the original offset 332 }
332 // add the offset to the Key_Left key 333 newkeycode = Key_Left + ( keycode - Key_Left + quarters ) % 4;
333 if (( d->m_model == Model_iPAQ_H5xxx ) ||
334 ( d->m_model == Model_iPAQ_H191x ) ||
335 ( d->m_model == Model_iPAQ_H4xxx ) ||
336 ( d->m_model == Model_iPAQ_H1940 ))
337 newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4;
338 break; 334 break;
339 } 335 }
340 336
341 // map Power Button short/long press to F34/F35 337 // map Power Button short/long press to F34/F35
342 case HardKey_Suspend: // Hope we don't have infinite recursion here 338 case HardKey_Suspend: // Hope we don't have infinite recursion here
343 case Key_SysReq: { 339 case Key_SysReq: {
344 if ( isPress ) { 340 if ( isPress ) {
345 if ( m_power_timer ) 341 if ( m_power_timer )
346 killTimer ( m_power_timer ); 342 killTimer ( m_power_timer );
347 m_power_timer = startTimer ( 500 ); 343 m_power_timer = startTimer ( 500 );
348 } 344 }
349 else if ( m_power_timer ) { 345 else if ( m_power_timer ) {
350 killTimer ( m_power_timer ); 346 killTimer ( m_power_timer );
351 m_power_timer = 0; 347 m_power_timer = 0;
352 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); 348 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false );
353 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); 349 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false );
354 } 350 }
355 newkeycode = Key_unknown; 351 newkeycode = Key_unknown;
356 break; 352 break;
357 } 353 }
358 } 354 }
359 355
360 if ( newkeycode != keycode ) { 356 if ( newkeycode != keycode ) {
361 if ( newkeycode != Key_unknown ) 357 if ( newkeycode != Key_unknown )
362 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); 358 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
363 return true; 359 return true;
364 } 360 }
365 else 361 else
366 return false; 362 return false;
367} 363}
368 364
369void iPAQ::timerEvent ( QTimerEvent * ) 365void iPAQ::timerEvent ( QTimerEvent * )
370{ 366{
371 killTimer ( m_power_timer ); 367 killTimer ( m_power_timer );
372 m_power_timer = 0; 368 m_power_timer = 0;
373 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); 369 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false );
374 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); 370 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false );
375} 371}
376 372
377 373
378void iPAQ::playAlarmSound() 374void iPAQ::playAlarmSound()
379{ 375{
380#ifndef QT_NO_SOUND 376#ifndef QT_NO_SOUND
381 static Sound snd ( "alarm" ); 377 static Sound snd ( "alarm" );
382 if(!snd.isFinished()) 378 if(!snd.isFinished())
383 return; 379 return;
384 380
385 changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); 381 changeMixerForAlarm(0, "/dev/sound/mixer", &snd );
386 snd. play(); 382 snd. play();
387#endif 383#endif
388} 384}
389 385
390bool iPAQ::setDisplayBrightness ( int bright ) 386bool iPAQ::setDisplayBrightness ( int bright )
391{ 387{
392 bool res = false; 388 bool res = false;
393 int fd; 389 int fd;
394 390
395 if ( bright > 255 ) 391 if ( bright > 255 )
396 bright = 255; 392 bright = 255;
397 if ( bright < 0 ) 393 if ( bright < 0 )
398 bright = 0; 394 bright = 0;
399 395
400 QDir sysClass( "/sys/class/backlight/" ); 396 QDir sysClass( "/sys/class/backlight/" );
401 sysClass.setFilter(QDir::Dirs); 397 sysClass.setFilter(QDir::Dirs);
402 if ( sysClass.exists() && sysClass.count() > 2 ) { 398 if ( sysClass.exists() && sysClass.count() > 2 ) {
403 QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/brightness" ); 399 QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/brightness" );
404 int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); 400 int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK );
405 if ( fd ) { 401 if ( fd ) {
406 char buf[100]; 402 char buf[100];
407 int val = bright * displayBrightnessResolution() / 255; 403 int val = bright * displayBrightnessResolution() / 255;
408 int len = ::snprintf( &buf[0], sizeof buf, "%d", val ); 404 int len = ::snprintf( &buf[0], sizeof buf, "%d", val );
409 res = ( ::write( fd, &buf[0], len ) == 0 ); 405 res = ( ::write( fd, &buf[0], len ) == 0 );
410 ::close( fd ); 406 ::close( fd );
411 } 407 }
412 } else { 408 } else {
413 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { 409 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
414 FLITE_IN bl; 410 FLITE_IN bl;
415 bl. mode = 1; 411 bl. mode = 1;
416 bl. pwr = bright ? 1 : 0; 412 bl. pwr = bright ? 1 : 0;
417 bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; 413 bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255;
418 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); 414 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 );
419 ::close ( fd ); 415 ::close ( fd );
420 } 416 }
421 } 417 }
422 418
423 return res; 419 return res;
424} 420}
425 421
426int iPAQ::displayBrightnessResolution() const 422int iPAQ::displayBrightnessResolution() const
427{ 423{
428 int res = 16; 424 int res = 16;
429 425
430 QDir sysClass( "/sys/class/backlight/" ); 426 QDir sysClass( "/sys/class/backlight/" );
431 sysClass.setFilter(QDir::Dirs); 427 sysClass.setFilter(QDir::Dirs);
432 if ( sysClass.exists() && sysClass.count() > 2 ) { 428 if ( sysClass.exists() && sysClass.count() > 2 ) {
433 QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/max_brightness" ); 429 QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/max_brightness" );
434 int fd = ::open( sysClassPath, O_RDONLY|O_NONBLOCK ); 430 int fd = ::open( sysClassPath, O_RDONLY|O_NONBLOCK );
435 if ( fd ) { 431 if ( fd ) {
436 char buf[100]; 432 char buf[100];
437 if ( ::read( fd, &buf[0], sizeof buf ) ) 433 if ( ::read( fd, &buf[0], sizeof buf ) )
438 ::sscanf( &buf[0], "%d", &res ); 434 ::sscanf( &buf[0], "%d", &res );
439 ::close( fd ); 435 ::close( fd );
440 } 436 }
441 return res; 437 return res;
442 } 438 }
443 439
444 switch ( model()) { 440 switch ( model()) {
445 case Model_iPAQ_H31xx: 441 case Model_iPAQ_H31xx:
446 case Model_iPAQ_H36xx: 442 case Model_iPAQ_H36xx:
447 case Model_iPAQ_H37xx: 443 case Model_iPAQ_H37xx:
448 return 128; // really 256, but >128 could damage the LCD 444 return 128; // really 256, but >128 could damage the LCD
449 445
450 case Model_iPAQ_H38xx: 446 case Model_iPAQ_H38xx:
451 case Model_iPAQ_H39xx: 447 case Model_iPAQ_H39xx:
452 return 64; 448 return 64;
453 case Model_iPAQ_H5xxx: 449 case Model_iPAQ_H5xxx:
454 case Model_iPAQ_HX4700: 450 case Model_iPAQ_HX4700:
455 case Model_iPAQ_H4xxx: 451 case Model_iPAQ_H4xxx:
456 return 255; 452 return 255;
457 case Model_iPAQ_H191x: 453 case Model_iPAQ_H191x:
458 return 7; 454 return 7;
459 case Model_iPAQ_H1940: 455 case Model_iPAQ_H1940:
460 return 44; 456 return 44;
461 default: 457 default:
462 return 2; 458 return 2;
463 } 459 }
464} 460}
465 461
466bool iPAQ::setDisplayStatus ( bool on ) 462bool iPAQ::setDisplayStatus ( bool on )
467{ 463{
468 bool res = false; 464 bool res = false;
469 465
470 QString cmdline; 466 QString cmdline;
471 467
472 QDir sysClass( "/sys/class/lcd/" ); 468 QDir sysClass( "/sys/class/lcd/" );
473 sysClass.setFilter(QDir::Dirs); 469 sysClass.setFilter(QDir::Dirs);
474 if ( sysClass.exists() && sysClass.count() > 2 ) { 470 if ( sysClass.exists() && sysClass.count() > 2 ) {
475 QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/power" ); 471 QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/power" );
476 int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); 472 int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK );
477 if ( fd ) { 473 if ( fd ) {
478 char buf[10]; 474 char buf[10];
479 buf[0] = on ? 0 : 4; 475 buf[0] = on ? 0 : 4;
480 buf[1] = '\0'; 476 buf[1] = '\0';
481 res = ( ::write( fd, &buf[0], 2 ) == 0 ); 477 res = ( ::write( fd, &buf[0], 2 ) == 0 );
482 ::close( fd ); 478 ::close( fd );
483 } 479 }
484 } else { 480 } else {
485 res = OAbstractMobileDevice::setDisplayStatus(on); 481 res = OAbstractMobileDevice::setDisplayStatus(on);
486 } 482 }
487 483
488 return res; 484 return res;
489} 485}
490 486
491bool iPAQ::hasLightSensor() const 487bool iPAQ::hasLightSensor() const
492{ 488{
493 switch (model()) { 489 switch (model()) {
494 case Model_iPAQ_H191x: 490 case Model_iPAQ_H191x:
495 case Model_iPAQ_H22xx: 491 case Model_iPAQ_H22xx:
496 case Model_iPAQ_H4xxx: 492 case Model_iPAQ_H4xxx:
497 return false; 493 return false;
498 default: 494 default:
499 return true; 495 return true;
500 } 496 }
501} 497}
502 498
503int iPAQ::readLightSensor() 499int iPAQ::readLightSensor()
504{ 500{
505 int fd; 501 int fd;
506 int val = -1; 502 int val = -1;
507 503
508 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { 504 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) {
509 char buffer [8]; 505 char buffer [8];
510 506
511 if ( ::read ( fd, buffer, 5 ) == 5 ) { 507 if ( ::read ( fd, buffer, 5 ) == 5 ) {
512 char *endptr; 508 char *endptr;
513 509
514 buffer [4] = 0; 510 buffer [4] = 0;
515 val = ::strtol ( buffer + 2, &endptr, 16 ); 511 val = ::strtol ( buffer + 2, &endptr, 16 );
516 512
517 if ( *endptr != 0 ) 513 if ( *endptr != 0 )
518 val = -1; 514 val = -1;
519 } 515 }
520 ::close ( fd ); 516 ::close ( fd );
521 } 517 }
522 518
523 return val; 519 return val;
524} 520}
525 521
526int iPAQ::lightSensorResolution() const 522int iPAQ::lightSensorResolution() const
527{ 523{
528 return 256; 524 return 256;
529} 525}