-rw-r--r-- | libopie2/opiecore/device/odevice_ipaq.cpp | 3 | ||||
-rw-r--r-- | libopie2/opiecore/device/odevice_mypal.cpp | 65 |
2 files changed, 32 insertions, 36 deletions
diff --git a/libopie2/opiecore/device/odevice_ipaq.cpp b/libopie2/opiecore/device/odevice_ipaq.cpp index 6dc1295..b18fd32 100644 --- a/libopie2/opiecore/device/odevice_ipaq.cpp +++ b/libopie2/opiecore/device/odevice_ipaq.cpp | |||
@@ -260,266 +260,265 @@ QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const | |||
260 | return vl; | 260 | return vl; |
261 | } | 261 | } |
262 | 262 | ||
263 | OLedState iPAQ::ledState ( OLed l ) const | 263 | OLedState 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 | ||
275 | bool iPAQ::setLedState ( OLed l, OLedState st ) | 275 | bool 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 | ||
305 | bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) | 305 | bool 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 | // QT has strange screen coordinate system, so depending | 320 | // QT has strange screen coordinate system, so depending |
321 | // on native device screen orientation, we need to rotate cursor keys | 321 | // on native device screen orientation, we need to rotate cursor keys |
322 | case Key_Left : | 322 | case Key_Left : |
323 | case Key_Right: | 323 | case Key_Right: |
324 | case Key_Up : | 324 | case Key_Up : |
325 | case Key_Down : { | 325 | case Key_Down : { |
326 | int quarters; | 326 | int quarters; |
327 | switch (d->m_rotation) { | 327 | switch (d->m_rotation) { |
328 | case Rot0: quarters = 3/*270deg*/; break; | 328 | case Rot0: quarters = 3/*270deg*/; break; |
329 | case Rot90: quarters = 2/*270deg*/; break; | 329 | case Rot90: quarters = 2/*270deg*/; break; |
330 | case Rot180: quarters = 1/*270deg*/; break; | 330 | case Rot180: quarters = 1/*270deg*/; break; |
331 | case Rot270: quarters = 0/*270deg*/; break; | 331 | case Rot270: quarters = 0/*270deg*/; break; |
332 | } | 332 | } |
333 | newkeycode = Key_Left + ( keycode - Key_Left + quarters ) % 4; | 333 | newkeycode = Key_Left + ( keycode - Key_Left + quarters ) % 4; |
334 | break; | 334 | break; |
335 | } | 335 | } |
336 | 336 | ||
337 | // map Power Button short/long press to F34/F35 | 337 | // map Power Button short/long press to F34/F35 |
338 | case HardKey_Suspend: // Hope we don't have infinite recursion here | 338 | case HardKey_Suspend: // Hope we don't have infinite recursion here |
339 | case Key_SysReq: { | 339 | case Key_SysReq: { |
340 | if ( isPress ) { | 340 | if ( isPress ) { |
341 | if ( m_power_timer ) | 341 | if ( m_power_timer ) |
342 | killTimer ( m_power_timer ); | 342 | killTimer ( m_power_timer ); |
343 | m_power_timer = startTimer ( 500 ); | 343 | m_power_timer = startTimer ( 500 ); |
344 | } | 344 | } |
345 | else if ( m_power_timer ) { | 345 | else if ( m_power_timer ) { |
346 | killTimer ( m_power_timer ); | 346 | killTimer ( m_power_timer ); |
347 | m_power_timer = 0; | 347 | m_power_timer = 0; |
348 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); | 348 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); |
349 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); | 349 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); |
350 | } | 350 | } |
351 | newkeycode = Key_unknown; | 351 | newkeycode = Key_unknown; |
352 | break; | 352 | break; |
353 | } | 353 | } |
354 | } | 354 | } |
355 | 355 | ||
356 | if ( newkeycode != keycode ) { | 356 | if ( newkeycode != keycode ) { |
357 | if ( newkeycode != Key_unknown ) | 357 | if ( newkeycode != Key_unknown ) |
358 | QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); | 358 | QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); |
359 | return true; | 359 | return true; |
360 | } | 360 | } |
361 | else | 361 | else |
362 | return false; | 362 | return false; |
363 | } | 363 | } |
364 | 364 | ||
365 | void iPAQ::timerEvent ( QTimerEvent * ) | 365 | void iPAQ::timerEvent ( QTimerEvent * ) |
366 | { | 366 | { |
367 | killTimer ( m_power_timer ); | 367 | killTimer ( m_power_timer ); |
368 | m_power_timer = 0; | 368 | m_power_timer = 0; |
369 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); | 369 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); |
370 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); | 370 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); |
371 | } | 371 | } |
372 | 372 | ||
373 | 373 | ||
374 | void iPAQ::playAlarmSound() | 374 | void iPAQ::playAlarmSound() |
375 | { | 375 | { |
376 | #ifndef QT_NO_SOUND | 376 | #ifndef QT_NO_SOUND |
377 | static Sound snd ( "alarm" ); | 377 | static Sound snd ( "alarm" ); |
378 | if(!snd.isFinished()) | 378 | if(!snd.isFinished()) |
379 | return; | 379 | return; |
380 | 380 | ||
381 | changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); | 381 | changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); |
382 | snd. play(); | 382 | snd. play(); |
383 | #endif | 383 | #endif |
384 | } | 384 | } |
385 | 385 | ||
386 | bool iPAQ::setDisplayBrightness ( int bright ) | 386 | bool iPAQ::setDisplayBrightness ( int bright ) |
387 | { | 387 | { |
388 | bool res = false; | 388 | bool res = false; |
389 | int fd; | 389 | int fd; |
390 | 390 | ||
391 | if ( bright > 255 ) | 391 | if ( bright > 255 ) |
392 | bright = 255; | 392 | bright = 255; |
393 | if ( bright < 0 ) | 393 | if ( bright < 0 ) |
394 | bright = 0; | 394 | bright = 0; |
395 | 395 | ||
396 | QDir sysClass( "/sys/class/backlight/" ); | 396 | QDir sysClass( "/sys/class/backlight/" ); |
397 | sysClass.setFilter(QDir::Dirs); | 397 | sysClass.setFilter(QDir::Dirs); |
398 | if ( sysClass.exists() && sysClass.count() > 2 ) { | 398 | if ( sysClass.exists() && sysClass.count() > 2 ) { |
399 | QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/brightness" ); | 399 | QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/brightness" ); |
400 | int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); | 400 | int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); |
401 | if ( fd ) { | 401 | if ( fd ) { |
402 | char buf[100]; | 402 | char buf[100]; |
403 | int val = bright * displayBrightnessResolution() / 255; | 403 | int val = bright * displayBrightnessResolution() / 255; |
404 | int len = ::snprintf( &buf[0], sizeof buf, "%d", val ); | 404 | int len = ::snprintf( &buf[0], sizeof buf, "%d", val ); |
405 | res = ( ::write( fd, &buf[0], len ) == 0 ); | 405 | res = ( ::write( fd, &buf[0], len ) == 0 ); |
406 | ::close( fd ); | 406 | ::close( fd ); |
407 | } | 407 | } |
408 | } else { | 408 | } else { |
409 | if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { | 409 | if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { |
410 | FLITE_IN bl; | 410 | FLITE_IN bl; |
411 | bl. mode = 1; | 411 | bl. mode = 1; |
412 | bl. pwr = bright ? 1 : 0; | 412 | bl. pwr = bright ? 1 : 0; |
413 | bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; | 413 | bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; |
414 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); | 414 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); |
415 | ::close ( fd ); | 415 | ::close ( fd ); |
416 | } | 416 | } |
417 | } | 417 | } |
418 | 418 | ||
419 | return res; | 419 | return res; |
420 | } | 420 | } |
421 | 421 | ||
422 | int iPAQ::displayBrightnessResolution() const | 422 | int iPAQ::displayBrightnessResolution() const |
423 | { | 423 | { |
424 | int res = 16; | 424 | int res = 16; |
425 | 425 | ||
426 | QDir sysClass( "/sys/class/backlight/" ); | 426 | QDir sysClass( "/sys/class/backlight/" ); |
427 | sysClass.setFilter(QDir::Dirs); | 427 | sysClass.setFilter(QDir::Dirs); |
428 | if ( sysClass.exists() && sysClass.count() > 2 ) { | 428 | if ( sysClass.exists() && sysClass.count() > 2 ) { |
429 | QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/max_brightness" ); | 429 | QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/max_brightness" ); |
430 | int fd = ::open( sysClassPath, O_RDONLY|O_NONBLOCK ); | 430 | int fd = ::open( sysClassPath, O_RDONLY|O_NONBLOCK ); |
431 | if ( fd ) { | 431 | if ( fd ) { |
432 | char buf[100]; | 432 | char buf[100]; |
433 | if ( ::read( fd, &buf[0], sizeof buf ) ) | 433 | if ( ::read( fd, &buf[0], sizeof buf ) ) |
434 | ::sscanf( &buf[0], "%d", &res ); | 434 | ::sscanf( &buf[0], "%d", &res ); |
435 | ::close( fd ); | 435 | ::close( fd ); |
436 | } | 436 | } |
437 | return res; | 437 | return res; |
438 | } | 438 | } |
439 | 439 | ||
440 | switch ( model()) { | 440 | switch ( model()) { |
441 | case Model_iPAQ_H31xx: | 441 | case Model_iPAQ_H31xx: |
442 | case Model_iPAQ_H36xx: | 442 | case Model_iPAQ_H36xx: |
443 | case Model_iPAQ_H37xx: | 443 | case Model_iPAQ_H37xx: |
444 | return 128; // really 256, but >128 could damage the LCD | 444 | return 128; // really 256, but >128 could damage the LCD |
445 | 445 | ||
446 | case Model_iPAQ_H38xx: | 446 | case Model_iPAQ_H38xx: |
447 | case Model_iPAQ_H39xx: | 447 | case Model_iPAQ_H39xx: |
448 | return 64; | 448 | return 64; |
449 | case Model_iPAQ_H5xxx: | 449 | case Model_iPAQ_H5xxx: |
450 | case Model_iPAQ_HX4700: | 450 | case Model_iPAQ_HX4700: |
451 | case Model_iPAQ_H4xxx: | 451 | case Model_iPAQ_H4xxx: |
452 | return 255; | ||
453 | case Model_iPAQ_H191x: | 452 | case Model_iPAQ_H191x: |
454 | return 7; | 453 | return 255; |
455 | case Model_iPAQ_H1940: | 454 | case Model_iPAQ_H1940: |
456 | return 44; | 455 | return 44; |
457 | default: | 456 | default: |
458 | return 2; | 457 | return 2; |
459 | } | 458 | } |
460 | } | 459 | } |
461 | 460 | ||
462 | bool iPAQ::setDisplayStatus ( bool on ) | 461 | bool iPAQ::setDisplayStatus ( bool on ) |
463 | { | 462 | { |
464 | bool res = false; | 463 | bool res = false; |
465 | 464 | ||
466 | QString cmdline; | 465 | QString cmdline; |
467 | 466 | ||
468 | QDir sysClass( "/sys/class/lcd/" ); | 467 | QDir sysClass( "/sys/class/lcd/" ); |
469 | sysClass.setFilter(QDir::Dirs); | 468 | sysClass.setFilter(QDir::Dirs); |
470 | if ( sysClass.exists() && sysClass.count() > 2 ) { | 469 | if ( sysClass.exists() && sysClass.count() > 2 ) { |
471 | QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/power" ); | 470 | QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/power" ); |
472 | int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); | 471 | int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); |
473 | if ( fd ) { | 472 | if ( fd ) { |
474 | char buf[10]; | 473 | char buf[10]; |
475 | buf[0] = on ? 0 : 4; | 474 | buf[0] = on ? 0 : 4; |
476 | buf[1] = '\0'; | 475 | buf[1] = '\0'; |
477 | res = ( ::write( fd, &buf[0], 2 ) == 0 ); | 476 | res = ( ::write( fd, &buf[0], 2 ) == 0 ); |
478 | ::close( fd ); | 477 | ::close( fd ); |
479 | } | 478 | } |
480 | } else { | 479 | } else { |
481 | res = OAbstractMobileDevice::setDisplayStatus(on); | 480 | res = OAbstractMobileDevice::setDisplayStatus(on); |
482 | } | 481 | } |
483 | 482 | ||
484 | return res; | 483 | return res; |
485 | } | 484 | } |
486 | 485 | ||
487 | bool iPAQ::hasLightSensor() const | 486 | bool iPAQ::hasLightSensor() const |
488 | { | 487 | { |
489 | switch (model()) { | 488 | switch (model()) { |
490 | case Model_iPAQ_H191x: | 489 | case Model_iPAQ_H191x: |
491 | case Model_iPAQ_H22xx: | 490 | case Model_iPAQ_H22xx: |
492 | case Model_iPAQ_H4xxx: | 491 | case Model_iPAQ_H4xxx: |
493 | return false; | 492 | return false; |
494 | default: | 493 | default: |
495 | return true; | 494 | return true; |
496 | } | 495 | } |
497 | } | 496 | } |
498 | 497 | ||
499 | int iPAQ::readLightSensor() | 498 | int iPAQ::readLightSensor() |
500 | { | 499 | { |
501 | int fd; | 500 | int fd; |
502 | int val = -1; | 501 | int val = -1; |
503 | 502 | ||
504 | if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { | 503 | if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { |
505 | char buffer [8]; | 504 | char buffer [8]; |
506 | 505 | ||
507 | if ( ::read ( fd, buffer, 5 ) == 5 ) { | 506 | if ( ::read ( fd, buffer, 5 ) == 5 ) { |
508 | char *endptr; | 507 | char *endptr; |
509 | 508 | ||
510 | buffer [4] = 0; | 509 | buffer [4] = 0; |
511 | val = ::strtol ( buffer + 2, &endptr, 16 ); | 510 | val = ::strtol ( buffer + 2, &endptr, 16 ); |
512 | 511 | ||
513 | if ( *endptr != 0 ) | 512 | if ( *endptr != 0 ) |
514 | val = -1; | 513 | val = -1; |
515 | } | 514 | } |
516 | ::close ( fd ); | 515 | ::close ( fd ); |
517 | } | 516 | } |
518 | 517 | ||
519 | return val; | 518 | return val; |
520 | } | 519 | } |
521 | 520 | ||
522 | int iPAQ::lightSensorResolution() const | 521 | int iPAQ::lightSensorResolution() const |
523 | { | 522 | { |
524 | return 256; | 523 | return 256; |
525 | } | 524 | } |
diff --git a/libopie2/opiecore/device/odevice_mypal.cpp b/libopie2/opiecore/device/odevice_mypal.cpp index 73b31cb..28e92bf 100644 --- a/libopie2/opiecore/device/odevice_mypal.cpp +++ b/libopie2/opiecore/device/odevice_mypal.cpp | |||
@@ -1,268 +1,265 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | =. (C) 2002-2005 The Opie Team <opie-devel@handhelds.org> | 3 | =. (C) 2002-2005 The Opie Team <opie-devel@handhelds.org> |
4 | .=l. | 4 | .=l. |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; version 2 of the License. | 10 | - . .-<_> .<> Foundation; version 2 of the License. |
11 | ._= =} : | 11 | ._= =} : |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | 27 | ||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "odevice_mypal.h" | 30 | #include "odevice_mypal.h" |
31 | 31 | ||
32 | /* QT */ | 32 | /* QT */ |
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | #include <qdir.h> | 34 | #include <qdir.h> |
35 | #include <qfile.h> | 35 | #include <qfile.h> |
36 | #include <qtextstream.h> | 36 | #include <qtextstream.h> |
37 | #include <qwindowsystem_qws.h> | 37 | #include <qwindowsystem_qws.h> |
38 | 38 | ||
39 | /* OPIE */ | 39 | /* OPIE */ |
40 | #include <qpe/config.h> | 40 | #include <qpe/config.h> |
41 | #include <qpe/sound.h> | 41 | #include <qpe/sound.h> |
42 | #include <qpe/qcopenvelope_qws.h> | 42 | #include <qpe/qcopenvelope_qws.h> |
43 | 43 | ||
44 | #include <opie2/okeyfilter.h> | 44 | #include <opie2/okeyfilter.h> |
45 | #include <opie2/oresource.h> | 45 | #include <opie2/oresource.h> |
46 | 46 | ||
47 | /* STD */ | 47 | /* STD */ |
48 | #include <fcntl.h> | 48 | #include <fcntl.h> |
49 | #include <math.h> | 49 | #include <math.h> |
50 | #include <stdlib.h> | 50 | #include <stdlib.h> |
51 | #include <signal.h> | 51 | #include <signal.h> |
52 | #include <sys/ioctl.h> | 52 | #include <sys/ioctl.h> |
53 | #include <sys/time.h> | 53 | #include <sys/time.h> |
54 | #include <unistd.h> | 54 | #include <unistd.h> |
55 | #ifndef QT_NO_SOUND | 55 | #ifndef QT_NO_SOUND |
56 | #include <linux/soundcard.h> | 56 | #include <linux/soundcard.h> |
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | 59 | ||
60 | using namespace Opie::Core; | 60 | using namespace Opie::Core; |
61 | using namespace Opie::Core::Internal; | 61 | using namespace Opie::Core::Internal; |
62 | 62 | ||
63 | #define Model_Keyboardless_2_6 (Model_MyPal_716) | 63 | #define Model_Keyboardless_2_6 (Model_MyPal_716) |
64 | 64 | ||
65 | struct m_button mypal_buttons [] = { | 65 | struct m_button mypal_buttons [] = { |
66 | // Common button map for all keyboardless devices with 2.6 kernel | 66 | // Common button map for all keyboardless devices with 2.6 kernel |
67 | { Model_Keyboardless_2_6, | 67 | { Model_Keyboardless_2_6, |
68 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), | 68 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), |
69 | "devicebuttons/ipaq_calendar", | 69 | "devicebuttons/ipaq_calendar", |
70 | "datebook", "nextView()", | 70 | "datebook", "nextView()", |
71 | "today", "raise()" }, | 71 | "today", "raise()" }, |
72 | { Model_Keyboardless_2_6, | 72 | { Model_Keyboardless_2_6, |
73 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), | 73 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), |
74 | "devicebuttons/ipaq_contact", | 74 | "devicebuttons/ipaq_contact", |
75 | "addressbook", "raise()", | 75 | "addressbook", "raise()", |
76 | "addressbook", "beamBusinessCard()" }, | 76 | "addressbook", "beamBusinessCard()" }, |
77 | { Model_Keyboardless_2_6, | 77 | { Model_Keyboardless_2_6, |
78 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Mail Button"), | 78 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Mail Button"), |
79 | "devicebuttons/ipaq_mail", | 79 | "devicebuttons/ipaq_mail", |
80 | "opiemail", "raise()", | 80 | "opiemail", "raise()", |
81 | "opiemail", "newMail()" }, | 81 | "opiemail", "newMail()" }, |
82 | { Model_Keyboardless_2_6, | 82 | { Model_Keyboardless_2_6, |
83 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), | 83 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), |
84 | "devicebuttons/ipaq_home", | 84 | "devicebuttons/ipaq_home", |
85 | "QPE/Launcher", "home()", | 85 | "QPE/Launcher", "home()", |
86 | "buttonsettings", "raise()" }, | 86 | "buttonsettings", "raise()" }, |
87 | { Model_Keyboardless_2_6, | 87 | { Model_Keyboardless_2_6, |
88 | Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), | 88 | Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), |
89 | "devicebuttons/ipaq_record", | 89 | "devicebuttons/ipaq_record", |
90 | "QPE/VMemo", "toggleRecord()", | 90 | "QPE/VMemo", "toggleRecord()", |
91 | "sound", "raise()" }, | 91 | "sound", "raise()" }, |
92 | }; | 92 | }; |
93 | 93 | ||
94 | void MyPal::init(const QString& model) | 94 | void MyPal::init(const QString& model) |
95 | { | 95 | { |
96 | d->m_vendorstr = "Asus"; | 96 | d->m_vendorstr = "Asus"; |
97 | d->m_vendor = Vendor_Asus; | 97 | d->m_vendor = Vendor_Asus; |
98 | 98 | ||
99 | d->m_modelstr = model.mid(model.findRev('A')); | 99 | d->m_modelstr = model.mid(model.findRev('A')); |
100 | if ( d->m_modelstr == "A716" ) | 100 | if ( d->m_modelstr == "A716" ) |
101 | d->m_model = Model_MyPal_716; | 101 | d->m_model = Model_MyPal_716; |
102 | else | 102 | else |
103 | d->m_model = Model_Unknown; | 103 | d->m_model = Model_Unknown; |
104 | 104 | ||
105 | d->m_rotation = Rot0; | 105 | d->m_rotation = Rot0; |
106 | 106 | ||
107 | m_power_timer = 0; | 107 | m_power_timer = 0; |
108 | } | 108 | } |
109 | 109 | ||
110 | void MyPal::initButtons() | 110 | void MyPal::initButtons() |
111 | { | 111 | { |
112 | if ( d->m_buttons ) | 112 | if ( d->m_buttons ) |
113 | return; | 113 | return; |
114 | 114 | ||
115 | if ( isQWS( ) ) { | 115 | if ( isQWS( ) ) { |
116 | addPreHandler(this); | 116 | addPreHandler(this); |
117 | } | 117 | } |
118 | 118 | ||
119 | d->m_buttons = new QValueList <ODeviceButton>; | 119 | d->m_buttons = new QValueList <ODeviceButton>; |
120 | 120 | ||
121 | for ( uint i = 0; i < ( sizeof( mypal_buttons ) / sizeof( m_button )); i++ ) { | 121 | for ( uint i = 0; i < ( sizeof( mypal_buttons ) / sizeof( m_button )); i++ ) { |
122 | m_button *mb = mypal_buttons + i; | 122 | m_button *mb = mypal_buttons + i; |
123 | ODeviceButton b; | 123 | ODeviceButton b; |
124 | 124 | ||
125 | if (( mb->model & d->m_model ) == d->m_model ) { | 125 | if (( mb->model & d->m_model ) == d->m_model ) { |
126 | b. setKeycode ( mb->code ); | 126 | b. setKeycode ( mb->code ); |
127 | b. setUserText ( QObject::tr ( "Button", mb->utext )); | 127 | b. setUserText ( QObject::tr ( "Button", mb->utext )); |
128 | b. setPixmap ( OResource::loadPixmap ( mb->pix )); | 128 | b. setPixmap ( OResource::loadPixmap ( mb->pix )); |
129 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( mb->fpressedservice ), mb->fpressedaction )); | 129 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( mb->fpressedservice ), mb->fpressedaction )); |
130 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( mb->fheldservice ), mb->fheldaction )); | 130 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( mb->fheldservice ), mb->fheldaction )); |
131 | 131 | ||
132 | d->m_buttons->append ( b ); | 132 | d->m_buttons->append ( b ); |
133 | } | 133 | } |
134 | } | 134 | } |
135 | reloadButtonMapping(); | 135 | reloadButtonMapping(); |
136 | } | 136 | } |
137 | 137 | ||
138 | bool MyPal::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) | 138 | bool MyPal::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) |
139 | { | 139 | { |
140 | int newkeycode = keycode; | 140 | int newkeycode = keycode; |
141 | 141 | ||
142 | switch ( keycode ) { | 142 | switch ( keycode ) { |
143 | case Key_Left : | 143 | // QT has strange screen coordinate system, so depending |
144 | case Key_Right: | 144 | // on native device screen orientation, we need to rotate cursor keys |
145 | case Key_Up : | 145 | case Key_Left : |
146 | case Key_Down : { | 146 | case Key_Right: |
147 | // Rotate the cursor keys by 270 | 147 | case Key_Up : |
148 | // keycode - Key_Left = position of the button starting from left clockwise | 148 | case Key_Down : { |
149 | // add the rotation to it and modolo. No we've the original offset | 149 | int quarters; |
150 | // add the offset to the Key_Left key | 150 | switch (d->m_rotation) { |
151 | if ( d->m_model == Model_MyPal_716 ) | 151 | case Rot0: quarters = 3/*270deg*/; break; |
152 | newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4; | 152 | case Rot90: quarters = 2/*270deg*/; break; |
153 | break; | 153 | case Rot180: quarters = 1/*270deg*/; break; |
154 | } | 154 | case Rot270: quarters = 0/*270deg*/; break; |
155 | } | ||
156 | newkeycode = Key_Left + ( keycode - Key_Left + quarters ) % 4; | ||
157 | break; | ||
158 | } | ||
155 | 159 | ||
156 | // map Power Button short/long press | 160 | // map Power Button short/long press |
157 | case HardKey_Suspend: { // Hope we don't have infinite recursion here: | 161 | case HardKey_Suspend: { // Hope we don't have infinite recursion here: |
158 | if ( isPress ) { | 162 | if ( isPress ) { |
159 | if ( m_power_timer ) | 163 | if ( m_power_timer ) |
160 | killTimer ( m_power_timer ); | 164 | killTimer ( m_power_timer ); |
161 | m_power_timer = startTimer ( 500 ); | 165 | m_power_timer = startTimer ( 500 ); |
162 | } | 166 | } |
163 | else if ( m_power_timer ) { | 167 | else if ( m_power_timer ) { |
164 | killTimer ( m_power_timer ); | 168 | killTimer ( m_power_timer ); |
165 | m_power_timer = 0; | 169 | m_power_timer = 0; |
166 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); | 170 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); |
167 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); | 171 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); |
168 | } | 172 | } |
169 | newkeycode = Key_unknown; | 173 | newkeycode = Key_unknown; |
170 | break; | 174 | break; |
171 | } | 175 | } |
172 | } | 176 | } |
173 | 177 | ||
174 | if ( newkeycode != keycode ) { | 178 | if ( newkeycode != keycode ) { |
175 | if ( newkeycode != Key_unknown ) | 179 | if ( newkeycode != Key_unknown ) |
176 | QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); | 180 | QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); |
177 | return true; | 181 | return true; |
178 | } | 182 | } |
179 | else | 183 | else |
180 | return false; | 184 | return false; |
181 | } | 185 | } |
182 | 186 | ||
183 | void MyPal::timerEvent ( QTimerEvent * ) | 187 | void MyPal::timerEvent ( QTimerEvent * ) |
184 | { | 188 | { |
185 | killTimer ( m_power_timer ); | 189 | killTimer ( m_power_timer ); |
186 | m_power_timer = 0; | 190 | m_power_timer = 0; |
187 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); | 191 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); |
188 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); | 192 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); |
189 | } | 193 | } |
190 | 194 | ||
191 | 195 | ||
192 | void MyPal::playAlarmSound() | 196 | void MyPal::playAlarmSound() |
193 | { | 197 | { |
194 | #ifndef QT_NO_SOUND | 198 | #ifndef QT_NO_SOUND |
195 | static Sound snd ( "alarm" ); | 199 | static Sound snd ( "alarm" ); |
196 | if(!snd.isFinished()) | 200 | if(!snd.isFinished()) |
197 | return; | 201 | return; |
198 | 202 | ||
199 | changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); | 203 | changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); |
200 | snd. play(); | 204 | snd. play(); |
201 | #endif | 205 | #endif |
202 | } | 206 | } |
203 | 207 | ||
204 | bool MyPal::setDisplayBrightness ( int bright ) | 208 | bool MyPal::setDisplayBrightness ( int bright ) |
205 | { | 209 | { |
206 | bool res = false; | 210 | bool res = false; |
207 | 211 | ||
208 | if ( bright > 255 ) | 212 | if ( bright > 255 ) |
209 | bright = 255; | 213 | bright = 255; |
210 | if ( bright < 0 ) | 214 | if ( bright < 0 ) |
211 | bright = 0; | 215 | bright = 0; |
212 | 216 | ||
213 | QDir sysClass( "/sys/class/backlight/pxafb/" ); | 217 | QDir sysClass( "/sys/class/backlight/" ); |
214 | sysClass.setFilter(QDir::Dirs); | 218 | sysClass.setFilter(QDir::Dirs); |
215 | int fd; | 219 | if ( sysClass.exists() && sysClass.count() > 2 ) { |
216 | if ( sysClass.exists() ) { | 220 | QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/brightness" ); |
217 | QString sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/power" ); | 221 | int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); |
218 | fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); | ||
219 | if ( fd ) { | ||
220 | char buf[10]; | ||
221 | buf[0] = bright ? 0 : 4; | ||
222 | buf[1] = '\0'; | ||
223 | res = ( ::write( fd, &buf[0], 2 ) == 0 ); | ||
224 | ::close( fd ); | ||
225 | } | ||
226 | sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/brightness" ); | ||
227 | fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); | ||
228 | if ( fd ) { | 222 | if ( fd ) { |
229 | char buf[100]; | 223 | char buf[100]; |
230 | int len = ::snprintf( &buf[0], sizeof buf, "%d", bright ); | 224 | int val = bright * displayBrightnessResolution() / 255; |
231 | res = ( ::write( fd, &buf[0], len ) == 0 ); | 225 | int len = ::snprintf( &buf[0], sizeof buf, "%d", val ); |
232 | ::close( fd ); | 226 | res = ( ::write( fd, &buf[0], len ) == 0 ); |
227 | ::close( fd ); | ||
233 | } | 228 | } |
234 | } | 229 | } |
235 | 230 | ||
236 | return res; | 231 | return res; |
237 | } | 232 | } |
238 | 233 | ||
239 | int MyPal::displayBrightnessResolution() const | 234 | int MyPal::displayBrightnessResolution() const |
240 | { | 235 | { |
241 | switch ( model()) { | 236 | switch ( model()) { |
242 | case Model_MyPal_716: | 237 | case Model_MyPal_716: |
243 | return 7; | 238 | return 255; |
244 | default: | 239 | default: |
245 | return OAbstractMobileDevice::displayBrightnessResolution(); | 240 | return OAbstractMobileDevice::displayBrightnessResolution(); |
246 | } | 241 | } |
247 | } | 242 | } |
248 | 243 | ||
249 | bool MyPal::setDisplayStatus ( bool on ) | 244 | bool MyPal::setDisplayStatus ( bool on ) |
250 | { | 245 | { |
251 | bool res = false; | 246 | bool res = false; |
252 | 247 | ||
253 | QDir sysClass( "/sys/class/lcd/" ); | 248 | QDir sysClass( "/sys/class/lcd/" ); |
254 | sysClass.setFilter(QDir::Dirs); | 249 | sysClass.setFilter(QDir::Dirs); |
255 | if ( sysClass.exists() ) { | 250 | if ( sysClass.exists() && sysClass.count() > 2 ) { |
256 | QString sysClassPath = sysClass.absFilePath( "/sys/class/lcd/pxafb/power" ); | 251 | QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/power" ); |
257 | int fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); | 252 | int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); |
258 | if ( fd ) { | 253 | if ( fd ) { |
259 | char buf[10]; | 254 | char buf[10]; |
260 | buf[0] = on ? 0 : 4; | 255 | buf[0] = on ? 0 : 4; |
261 | buf[1] = '\0'; | 256 | buf[1] = '\0'; |
262 | res = ( ::write( fd, &buf[0], 2 ) == 0 ); | 257 | res = ( ::write( fd, &buf[0], 2 ) == 0 ); |
263 | ::close( fd ); | 258 | ::close( fd ); |
264 | } | 259 | } |
260 | } else { | ||
261 | res = OAbstractMobileDevice::setDisplayStatus(on); | ||
265 | } | 262 | } |
266 | 263 | ||
267 | return res; | 264 | return res; |
268 | } | 265 | } |