summaryrefslogtreecommitdiff
path: root/libopie/odevice.cpp
authorschurig <schurig>2004-09-10 12:18:17 (UTC)
committer schurig <schurig>2004-09-10 12:18:17 (UTC)
commit9d0ccc1c5ca687bc017b2b515a9d3a47e98ce521 (patch) (unidiff)
tree53927c6a19c69d54bb3d0e092ac57180bcb60222 /libopie/odevice.cpp
parented70ec4945c7816ec6e899207ec8b99e20e10da5 (diff)
downloadopie-9d0ccc1c5ca687bc017b2b515a9d3a47e98ce521.zip
opie-9d0ccc1c5ca687bc017b2b515a9d3a47e98ce521.tar.gz
opie-9d0ccc1c5ca687bc017b2b515a9d3a47e98ce521.tar.bz2
added support for DEVFS
Diffstat (limited to 'libopie/odevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 21070bf..9d0bbbf 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -406,385 +406,389 @@ struct yopy_button {
406 "buttonsettings", "raise()" }, 406 "buttonsettings", "raise()" },
407}; 407};
408 408
409static QCString makeChannel ( const char *str ) 409static QCString makeChannel ( const char *str )
410{ 410{
411 if ( str && !::strchr ( str, '/' )) 411 if ( str && !::strchr ( str, '/' ))
412 return QCString ( "QPE/Application/" ) + str; 412 return QCString ( "QPE/Application/" ) + str;
413 else 413 else
414 return str; 414 return str;
415} 415}
416 416
417static inline bool isQWS() 417static inline bool isQWS()
418{ 418{
419 return qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; 419 return qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
420} 420}
421 421
422ODevice *ODevice::inst ( ) 422ODevice *ODevice::inst ( )
423{ 423{
424 static ODevice *dev = 0; 424 static ODevice *dev = 0;
425 425
426 if ( !dev ) { 426 if ( !dev ) {
427 if ( QFile::exists ( "/proc/hal/model" )) 427 if ( QFile::exists ( "/proc/hal/model" ))
428 dev = new iPAQ ( ); 428 dev = new iPAQ ( );
429 else if ( Zaurus::isZaurus() ) 429 else if ( Zaurus::isZaurus() )
430 dev = new Zaurus ( ); 430 dev = new Zaurus ( );
431 else if ( QFile::exists ( "/proc/ucb1x00" ) && QFile::exists ( "/proc/cs3" )) 431 else if ( QFile::exists ( "/proc/ucb1x00" ) && QFile::exists ( "/proc/cs3" ))
432 dev = new SIMpad ( ); 432 dev = new SIMpad ( );
433 else if ( Yopy::isYopy() ) 433 else if ( Yopy::isYopy() )
434 dev = new Yopy ( ); 434 dev = new Yopy ( );
435 else if ( Jornada::isJornada() ) 435 else if ( Jornada::isJornada() )
436 dev = new Jornada ( ); 436 dev = new Jornada ( );
437 else if ( QFile::exists ( "/proc/sys/board/sys_name" )) 437 else if ( QFile::exists ( "/proc/sys/board/sys_name" ))
438 dev = new Ramses ( ); 438 dev = new Ramses ( );
439 else 439 else
440 dev = new ODevice ( ); 440 dev = new ODevice ( );
441 dev-> init ( ); 441 dev-> init ( );
442 } 442 }
443 return dev; 443 return dev;
444} 444}
445 445
446 446
447/************************************************** 447/**************************************************
448 * 448 *
449 * common 449 * common
450 * 450 *
451 **************************************************/ 451 **************************************************/
452 452
453 453
454ODevice::ODevice ( ) 454ODevice::ODevice ( )
455{ 455{
456 d = new ODeviceData; 456 d = new ODeviceData;
457 457
458 d-> m_modelstr = "Unknown"; 458 d-> m_modelstr = "Unknown";
459 d-> m_model = Model_Unknown; 459 d-> m_model = Model_Unknown;
460 d-> m_vendorstr = "Unknown"; 460 d-> m_vendorstr = "Unknown";
461 d-> m_vendor = Vendor_Unknown; 461 d-> m_vendor = Vendor_Unknown;
462 d-> m_systemstr = "Unknown"; 462 d-> m_systemstr = "Unknown";
463 d-> m_system = System_Unknown; 463 d-> m_system = System_Unknown;
464 d-> m_sysverstr = "0.0"; 464 d-> m_sysverstr = "0.0";
465 d-> m_rotation = Rot0; 465 d-> m_rotation = Rot0;
466 d-> m_direction = CW; 466 d-> m_direction = CW;
467 467
468 d-> m_holdtime = 1000; // 1000ms 468 d-> m_holdtime = 1000; // 1000ms
469 d-> m_buttons = 0; 469 d-> m_buttons = 0;
470 d-> m_cpu_frequencies = new QStrList; 470 d-> m_cpu_frequencies = new QStrList;
471} 471}
472 472
473void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) 473void ODevice::systemMessage ( const QCString &msg, const QByteArray & )
474{ 474{
475 if ( msg == "deviceButtonMappingChanged()" ) { 475 if ( msg == "deviceButtonMappingChanged()" ) {
476 reloadButtonMapping ( ); 476 reloadButtonMapping ( );
477 } 477 }
478} 478}
479 479
480void ODevice::init ( ) 480void ODevice::init ( )
481{ 481{
482} 482}
483 483
484/** 484/**
485 * This method initialises the button mapping 485 * This method initialises the button mapping
486 */ 486 */
487void ODevice::initButtons ( ) 487void ODevice::initButtons ( )
488{ 488{
489 if ( d-> m_buttons ) 489 if ( d-> m_buttons )
490 return; 490 return;
491 491
492 // Simulation uses iPAQ 3660 device buttons 492 // Simulation uses iPAQ 3660 device buttons
493 493
494 qDebug ( "init Buttons" ); 494 qDebug ( "init Buttons" );
495 d-> m_buttons = new QValueList <ODeviceButton>; 495 d-> m_buttons = new QValueList <ODeviceButton>;
496 496
497 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 497 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
498 i_button *ib = ipaq_buttons + i; 498 i_button *ib = ipaq_buttons + i;
499 ODeviceButton b; 499 ODeviceButton b;
500 500
501 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { 501 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) {
502 b. setKeycode ( ib-> code ); 502 b. setKeycode ( ib-> code );
503 b. setUserText ( QObject::tr ( "Button", ib-> utext )); 503 b. setUserText ( QObject::tr ( "Button", ib-> utext ));
504 b. setPixmap ( Resource::loadPixmap ( ib-> pix )); 504 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
505 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); 505 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction ));
506 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); 506 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction ));
507 d-> m_buttons-> append ( b ); 507 d-> m_buttons-> append ( b );
508 } 508 }
509 } 509 }
510 reloadButtonMapping ( ); 510 reloadButtonMapping ( );
511 511
512 QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); 512 QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
513 connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); 513 connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&)));
514} 514}
515 515
516ODevice::~ODevice ( ) 516ODevice::~ODevice ( )
517{ 517{
518// we leak m_devicebuttons and m_cpu_frequency 518// we leak m_devicebuttons and m_cpu_frequency
519// but it's a singleton and it is not so importantant 519// but it's a singleton and it is not so importantant
520// -zecke 520// -zecke
521 delete d; 521 delete d;
522} 522}
523 523
524bool ODevice::setSoftSuspend ( bool /*soft*/ ) 524bool ODevice::setSoftSuspend ( bool /*soft*/ )
525{ 525{
526 return false; 526 return false;
527} 527}
528 528
529//#include <linux/apm_bios.h> 529//#include <linux/apm_bios.h>
530 530
531#define APM_IOC_SUSPEND OD_IO( 'A', 2 ) 531#define APM_IOC_SUSPEND OD_IO( 'A', 2 )
532 532
533/** 533/**
534 * This method will try to suspend the device 534 * This method will try to suspend the device
535 * It only works if the user is the QWS Server and the apm application 535 * It only works if the user is the QWS Server and the apm application
536 * is installed. 536 * is installed.
537 * It tries to suspend and then waits some time cause some distributions 537 * It tries to suspend and then waits some time cause some distributions
538 * do have asynchronus apm implementations. 538 * do have asynchronus apm implementations.
539 * This method will either fail and return false or it'll suspend the 539 * This method will either fail and return false or it'll suspend the
540 * device and return once the device got woken up 540 * device and return once the device got woken up
541 * 541 *
542 * @return if the device got suspended 542 * @return if the device got suspended
543 */ 543 */
544bool ODevice::suspend ( ) 544bool ODevice::suspend ( )
545{ 545{
546 qDebug("ODevice::suspend"); 546 qDebug("ODevice::suspend");
547 if ( !isQWS( ) ) // only qwsserver is allowed to suspend 547 if ( !isQWS( ) ) // only qwsserver is allowed to suspend
548 return false; 548 return false;
549 549
550 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices 550 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices
551 return false; 551 return false;
552 552
553 bool res = false; 553 bool res = false;
554 554
555 struct timeval tvs, tvn; 555 struct timeval tvs, tvn;
556 ::gettimeofday ( &tvs, 0 ); 556 ::gettimeofday ( &tvs, 0 );
557 557
558 ::sync ( ); // flush fs caches 558 ::sync ( ); // flush fs caches
559 res = ( ::system ( "apm --suspend" ) == 0 ); 559 res = ( ::system ( "apm --suspend" ) == 0 );
560 560
561 // This is needed because the iPAQ apm implementation is asynchronous and we 561 // This is needed because the iPAQ apm implementation is asynchronous and we
562 // can not be sure when exactly the device is really suspended 562 // can not be sure when exactly the device is really suspended
563 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. 563 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists.
564 564
565 if ( res ) { 565 if ( res ) {
566 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed 566 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
567 ::usleep ( 200 * 1000 ); 567 ::usleep ( 200 * 1000 );
568 ::gettimeofday ( &tvn, 0 ); 568 ::gettimeofday ( &tvn, 0 );
569 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); 569 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
570 } 570 }
571 571
572 return res; 572 return res;
573} 573}
574 574
575//#include <linux/fb.h> better not rely on kernel headers in userspace ... 575//#include <linux/fb.h> better not rely on kernel headers in userspace ...
576 576
577#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 577#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611
578 578
579/* VESA Blanking Levels */ 579/* VESA Blanking Levels */
580#define VESA_NO_BLANKING 0 580#define VESA_NO_BLANKING 0
581#define VESA_VSYNC_SUSPEND 1 581#define VESA_VSYNC_SUSPEND 1
582#define VESA_HSYNC_SUSPEND 2 582#define VESA_HSYNC_SUSPEND 2
583#define VESA_POWERDOWN 3 583#define VESA_POWERDOWN 3
584 584
585/** 585/**
586 * This sets the display on or off 586 * This sets the display on or off
587 */ 587 */
588bool ODevice::setDisplayStatus ( bool on ) 588bool ODevice::setDisplayStatus ( bool on )
589{ 589{
590 qDebug("ODevice::setDisplayStatus(%d)", on); 590 qDebug("ODevice::setDisplayStatus(%d)", on);
591 591
592 if ( d-> m_model == Model_Unknown ) 592 if ( d-> m_model == Model_Unknown )
593 return false; 593 return false;
594 594
595 bool res = false; 595 bool res = false;
596 int fd; 596 int fd;
597 597
598#ifdef QT_QWS_DEVFS
599 if (( fd = ::open ( "/dev/fb/0", O_RDWR )) >= 0 ) {
600#else
598 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { 601 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) {
602#endif
599 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); 603 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 );
600 ::close ( fd ); 604 ::close ( fd );
601 } 605 }
602 return res; 606 return res;
603} 607}
604 608
605/** 609/**
606 * This sets the display brightness 610 * This sets the display brightness
607 * 611 *
608 * @param p The brightness to be set on a scale from 0 to 255 612 * @param p The brightness to be set on a scale from 0 to 255
609 * @return success or failure 613 * @return success or failure
610 */ 614 */
611bool ODevice::setDisplayBrightness ( int p) 615bool ODevice::setDisplayBrightness ( int p)
612{ 616{
613 Q_UNUSED( p ) 617 Q_UNUSED( p )
614 return false; 618 return false;
615} 619}
616 620
617/** 621/**
618 * @return returns the number of steppings on the brightness slider 622 * @return returns the number of steppings on the brightness slider
619 * in the Light-'n-Power settings. 623 * in the Light-'n-Power settings.
620 */ 624 */
621int ODevice::displayBrightnessResolution ( ) const 625int ODevice::displayBrightnessResolution ( ) const
622{ 626{
623 return 16; 627 return 16;
624} 628}
625 629
626/** 630/**
627 * This sets the display contrast 631 * This sets the display contrast
628 * @param p The contrast to be set on a scale from 0 to 255 632 * @param p The contrast to be set on a scale from 0 to 255
629 * @return success or failure 633 * @return success or failure
630 */ 634 */
631bool ODevice::setDisplayContrast ( int p) 635bool ODevice::setDisplayContrast ( int p)
632{ 636{
633 Q_UNUSED( p ) 637 Q_UNUSED( p )
634 return false; 638 return false;
635} 639}
636 640
637/** 641/**
638 * @return return the max value for the brightness settings slider 642 * @return return the max value for the brightness settings slider
639 * or 0 if the device doesn't support setting of a contrast 643 * or 0 if the device doesn't support setting of a contrast
640 */ 644 */
641int ODevice::displayContrastResolution ( ) const 645int ODevice::displayContrastResolution ( ) const
642{ 646{
643 return 0; 647 return 0;
644} 648}
645 649
646/** 650/**
647 * This returns the vendor as string 651 * This returns the vendor as string
648 * @return Vendor as QString 652 * @return Vendor as QString
649 */ 653 */
650QString ODevice::vendorString ( ) const 654QString ODevice::vendorString ( ) const
651{ 655{
652 return d-> m_vendorstr; 656 return d-> m_vendorstr;
653} 657}
654 658
655/** 659/**
656 * This returns the vendor as one of the values of OVendor 660 * This returns the vendor as one of the values of OVendor
657 * @return OVendor 661 * @return OVendor
658 */ 662 */
659OVendor ODevice::vendor ( ) const 663OVendor ODevice::vendor ( ) const
660{ 664{
661 return d-> m_vendor; 665 return d-> m_vendor;
662} 666}
663 667
664/** 668/**
665 * This returns the model as a string 669 * This returns the model as a string
666 * @return A string representing the model 670 * @return A string representing the model
667 */ 671 */
668QString ODevice::modelString ( ) const 672QString ODevice::modelString ( ) const
669{ 673{
670 return d-> m_modelstr; 674 return d-> m_modelstr;
671} 675}
672 676
673/** 677/**
674 * This does return the OModel used 678 * This does return the OModel used
675 */ 679 */
676OModel ODevice::model ( ) const 680OModel ODevice::model ( ) const
677{ 681{
678 return d-> m_model; 682 return d-> m_model;
679} 683}
680 684
681/** 685/**
682 * This does return the systen name 686 * This does return the systen name
683 */ 687 */
684QString ODevice::systemString ( ) const 688QString ODevice::systemString ( ) const
685{ 689{
686 return d-> m_systemstr; 690 return d-> m_systemstr;
687} 691}
688 692
689/** 693/**
690 * Return System as OSystem value 694 * Return System as OSystem value
691 */ 695 */
692OSystem ODevice::system ( ) const 696OSystem ODevice::system ( ) const
693{ 697{
694 return d-> m_system; 698 return d-> m_system;
695} 699}
696 700
697/** 701/**
698 * @return the version string of the base system 702 * @return the version string of the base system
699 */ 703 */
700QString ODevice::systemVersionString ( ) const 704QString ODevice::systemVersionString ( ) const
701{ 705{
702 return d-> m_sysverstr; 706 return d-> m_sysverstr;
703} 707}
704 708
705/** 709/**
706 * @return the current Transformation 710 * @return the current Transformation
707 */ 711 */
708Transformation ODevice::rotation ( ) const 712Transformation ODevice::rotation ( ) const
709{ 713{
710 VirtRotation rot; 714 VirtRotation rot;
711 ODevice* that =(ODevice* )this; 715 ODevice* that =(ODevice* )this;
712 that->virtual_hook( VIRTUAL_ROTATION, &rot ); 716 that->virtual_hook( VIRTUAL_ROTATION, &rot );
713 return rot.trans; 717 return rot.trans;
714} 718}
715 719
716/** 720/**
717 * @return the current rotation direction 721 * @return the current rotation direction
718 */ 722 */
719ODirection ODevice::direction ( ) const 723ODirection ODevice::direction ( ) const
720{ 724{
721 VirtDirection dir; 725 VirtDirection dir;
722 ODevice* that =(ODevice* )this; 726 ODevice* that =(ODevice* )this;
723 that->virtual_hook( VIRTUAL_DIRECTION, &dir ); 727 that->virtual_hook( VIRTUAL_DIRECTION, &dir );
724 return dir.direct; 728 return dir.direct;
725} 729}
726 730
727/** 731/**
728 * This plays an alarmSound 732 * This plays an alarmSound
729 */ 733 */
730void ODevice::alarmSound ( ) 734void ODevice::alarmSound ( )
731{ 735{
732#ifndef QT_NO_SOUND 736#ifndef QT_NO_SOUND
733 static Sound snd ( "alarm" ); 737 static Sound snd ( "alarm" );
734 738
735 if ( snd. isFinished ( )) 739 if ( snd. isFinished ( ))
736 snd. play ( ); 740 snd. play ( );
737#endif 741#endif
738} 742}
739 743
740/** 744/**
741 * This plays a key sound 745 * This plays a key sound
742 */ 746 */
743void ODevice::keySound ( ) 747void ODevice::keySound ( )
744{ 748{
745#ifndef QT_NO_SOUND 749#ifndef QT_NO_SOUND
746 static Sound snd ( "keysound" ); 750 static Sound snd ( "keysound" );
747 751
748 if ( snd. isFinished ( )) 752 if ( snd. isFinished ( ))
749 snd. play ( ); 753 snd. play ( );
750#endif 754#endif
751} 755}
752 756
753/** 757/**
754 * This plays a touch sound 758 * This plays a touch sound
755 */ 759 */
756void ODevice::touchSound ( ) 760void ODevice::touchSound ( )
757{ 761{
758#ifndef QT_NO_SOUND 762#ifndef QT_NO_SOUND
759 static Sound snd ( "touchsound" ); 763 static Sound snd ( "touchsound" );
760 764
761 if ( snd. isFinished ( )) 765 if ( snd. isFinished ( ))
762 snd. play ( ); 766 snd. play ( );
763#endif 767#endif
764} 768}
765 769
766/** 770/**
767 * This method will return a list of leds 771 * This method will return a list of leds
768 * available on this device 772 * available on this device
769 * @return a list of LEDs. 773 * @return a list of LEDs.
770 */ 774 */
771QValueList <OLed> ODevice::ledList ( ) const 775QValueList <OLed> ODevice::ledList ( ) const
772{ 776{
773 return QValueList <OLed> ( ); 777 return QValueList <OLed> ( );
774} 778}
775 779
776/** 780/**
777 * This does return the state of the LEDs 781 * This does return the state of the LEDs
778 */ 782 */
779QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const 783QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const
780{ 784{
781 return QValueList <OLedState> ( ); 785 return QValueList <OLedState> ( );
782} 786}
783 787
784/** 788/**
785 * @return the state for a given OLed 789 * @return the state for a given OLed
786 */ 790 */
787OLedState ODevice::ledState ( OLed /*which*/ ) const 791OLedState ODevice::ledState ( OLed /*which*/ ) const
788{ 792{
789 return Led_Off; 793 return Led_Off;
790} 794}