summaryrefslogtreecommitdiff
path: root/libopie/odevice.cpp
authoreilers <eilers>2003-08-08 15:09:29 (UTC)
committer eilers <eilers>2003-08-08 15:09:29 (UTC)
commitb87b33dc1f6e8e1276a7035ab7a3e53b8ed4bd16 (patch) (unidiff)
treeb0f96db67cfb1b9d2476530ecec9a2ba6eacbab1 /libopie/odevice.cpp
parent14d394e6c107b037a09a31a92605034fe50f7813 (diff)
downloadopie-b87b33dc1f6e8e1276a7035ab7a3e53b8ed4bd16.zip
opie-b87b33dc1f6e8e1276a7035ab7a3e53b8ed4bd16.tar.gz
opie-b87b33dc1f6e8e1276a7035ab7a3e53b8ed4bd16.tar.bz2
Merging all changes from BRANCH_1_0.
Diffstat (limited to 'libopie/odevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp111
1 files changed, 63 insertions, 48 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 62dc9d4..17ae389 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -411,128 +411,131 @@ ODevice *ODevice::inst ( )
411ODevice::ODevice ( ) 411ODevice::ODevice ( )
412{ 412{
413 d = new ODeviceData; 413 d = new ODeviceData;
414 414
415 d-> m_modelstr = "Unknown"; 415 d-> m_modelstr = "Unknown";
416 d-> m_model = Model_Unknown; 416 d-> m_model = Model_Unknown;
417 d-> m_vendorstr = "Unknown"; 417 d-> m_vendorstr = "Unknown";
418 d-> m_vendor = Vendor_Unknown; 418 d-> m_vendor = Vendor_Unknown;
419 d-> m_systemstr = "Unknown"; 419 d-> m_systemstr = "Unknown";
420 d-> m_system = System_Unknown; 420 d-> m_system = System_Unknown;
421 d-> m_sysverstr = "0.0"; 421 d-> m_sysverstr = "0.0";
422 d-> m_rotation = Rot0; 422 d-> m_rotation = Rot0;
423 d-> m_direction = CW; 423 d-> m_direction = CW;
424 424
425 d-> m_holdtime = 1000; // 1000ms 425 d-> m_holdtime = 1000; // 1000ms
426 d-> m_buttons = 0; 426 d-> m_buttons = 0;
427 d-> m_cpu_frequencies = new QStrList; 427 d-> m_cpu_frequencies = new QStrList;
428} 428}
429 429
430void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) 430void ODevice::systemMessage ( const QCString &msg, const QByteArray & )
431{ 431{
432 if ( msg == "deviceButtonMappingChanged()" ) { 432 if ( msg == "deviceButtonMappingChanged()" ) {
433 reloadButtonMapping ( ); 433 reloadButtonMapping ( );
434 } 434 }
435} 435}
436 436
437void ODevice::init ( ) 437void ODevice::init ( )
438{ 438{
439} 439}
440 440
441/** 441/**
442 * This method initialises the button mapping 442 * This method initialises the button mapping
443 */ 443 */
444void ODevice::initButtons ( ) 444void ODevice::initButtons ( )
445{ 445{
446 if ( d-> m_buttons ) 446 if ( d-> m_buttons )
447 return; 447 return;
448 448
449 // Simulation uses iPAQ 3660 device buttons 449 // Simulation uses iPAQ 3660 device buttons
450 450
451 qDebug ( "init Buttons" ); 451 qDebug ( "init Buttons" );
452 d-> m_buttons = new QValueList <ODeviceButton>; 452 d-> m_buttons = new QValueList <ODeviceButton>;
453 453
454 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 454 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
455 i_button *ib = ipaq_buttons + i; 455 i_button *ib = ipaq_buttons + i;
456 ODeviceButton b; 456 ODeviceButton b;
457 457
458 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { 458 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) {
459 b. setKeycode ( ib-> code ); 459 b. setKeycode ( ib-> code );
460 b. setUserText ( QObject::tr ( "Button", ib-> utext )); 460 b. setUserText ( QObject::tr ( "Button", ib-> utext ));
461 b. setPixmap ( Resource::loadPixmap ( ib-> pix )); 461 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
462 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); 462 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction ));
463 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); 463 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction ));
464 d-> m_buttons-> append ( b ); 464 d-> m_buttons-> append ( b );
465 } 465 }
466 } 466 }
467 reloadButtonMapping ( ); 467 reloadButtonMapping ( );
468 468
469 QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); 469 QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
470 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); 470 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & )));
471} 471}
472 472
473ODevice::~ODevice ( ) 473ODevice::~ODevice ( )
474{ 474{
475// we leak m_devicebuttons and m_cpu_frequency
476// but it's a singleton and it is not so importantant
477// -zecke
475 delete d; 478 delete d;
476} 479}
477 480
478bool ODevice::setSoftSuspend ( bool /*soft*/ ) 481bool ODevice::setSoftSuspend ( bool /*soft*/ )
479{ 482{
480 return false; 483 return false;
481} 484}
482 485
483//#include <linux/apm_bios.h> 486//#include <linux/apm_bios.h>
484 487
485#define APM_IOC_SUSPEND OD_IO( 'A', 2 ) 488#define APM_IOC_SUSPEND OD_IO( 'A', 2 )
486 489
487/** 490/**
488 * This method will try to suspend the device 491 * This method will try to suspend the device
489 * It only works if the user is the QWS Server and the apm application 492 * It only works if the user is the QWS Server and the apm application
490 * is installed. 493 * is installed.
491 * It tries to suspend and then waits some time cause some distributions 494 * It tries to suspend and then waits some time cause some distributions
492 * do have asynchronus apm implementations. 495 * do have asynchronus apm implementations.
493 * This method will either fail and return false or it'll suspend the 496 * This method will either fail and return false or it'll suspend the
494 * device and return once the device got woken up 497 * device and return once the device got woken up
495 * 498 *
496 * @return if the device got suspended 499 * @return if the device got suspended
497 */ 500 */
498bool ODevice::suspend ( ) 501bool ODevice::suspend ( )
499{ 502{
500 qDebug("ODevice::suspend"); 503 qDebug("ODevice::suspend");
501 if ( !isQWS( ) ) // only qwsserver is allowed to suspend 504 if ( !isQWS( ) ) // only qwsserver is allowed to suspend
502 return false; 505 return false;
503 506
504 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices 507 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices
505 return false; 508 return false;
506 509
507 bool res = false; 510 bool res = false;
508 511
509 struct timeval tvs, tvn; 512 struct timeval tvs, tvn;
510 ::gettimeofday ( &tvs, 0 ); 513 ::gettimeofday ( &tvs, 0 );
511 514
512 ::sync ( ); // flush fs caches 515 ::sync ( ); // flush fs caches
513 res = ( ::system ( "apm --suspend" ) == 0 ); 516 res = ( ::system ( "apm --suspend" ) == 0 );
514 517
515 // This is needed because the iPAQ apm implementation is asynchronous and we 518 // This is needed because the iPAQ apm implementation is asynchronous and we
516 // can not be sure when exactly the device is really suspended 519 // can not be sure when exactly the device is really suspended
517 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. 520 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists.
518 521
519 if ( res ) { 522 if ( res ) {
520 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed 523 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
521 ::usleep ( 200 * 1000 ); 524 ::usleep ( 200 * 1000 );
522 ::gettimeofday ( &tvn, 0 ); 525 ::gettimeofday ( &tvn, 0 );
523 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); 526 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
524 } 527 }
525 528
526 return res; 529 return res;
527} 530}
528 531
529//#include <linux/fb.h> better not rely on kernel headers in userspace ... 532//#include <linux/fb.h> better not rely on kernel headers in userspace ...
530 533
531#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 534#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611
532 535
533/* VESA Blanking Levels */ 536/* VESA Blanking Levels */
534#define VESA_NO_BLANKING 0 537#define VESA_NO_BLANKING 0
535#define VESA_VSYNC_SUSPEND 1 538#define VESA_VSYNC_SUSPEND 1
536#define VESA_HSYNC_SUSPEND 2 539#define VESA_HSYNC_SUSPEND 2
537#define VESA_POWERDOWN 3 540#define VESA_POWERDOWN 3
538 541
@@ -724,129 +727,129 @@ QValueList <OLed> ODevice::ledList ( ) const
724/** 727/**
725 * This does return the state of the LEDs 728 * This does return the state of the LEDs
726 */ 729 */
727QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const 730QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const
728{ 731{
729 return QValueList <OLedState> ( ); 732 return QValueList <OLedState> ( );
730} 733}
731 734
732/** 735/**
733 * @return the state for a given OLed 736 * @return the state for a given OLed
734 */ 737 */
735OLedState ODevice::ledState ( OLed /*which*/ ) const 738OLedState ODevice::ledState ( OLed /*which*/ ) const
736{ 739{
737 return Led_Off; 740 return Led_Off;
738} 741}
739 742
740/** 743/**
741 * Set the state for a LED 744 * Set the state for a LED
742 * @param which Which OLed to use 745 * @param which Which OLed to use
743 * @param st The state to set 746 * @param st The state to set
744 * @return success or failure 747 * @return success or failure
745 */ 748 */
746bool ODevice::setLedState ( OLed which, OLedState st ) 749bool ODevice::setLedState ( OLed which, OLedState st )
747{ 750{
748 Q_UNUSED( which ) 751 Q_UNUSED( which )
749 Q_UNUSED( st ) 752 Q_UNUSED( st )
750 return false; 753 return false;
751} 754}
752 755
753/** 756/**
754 * @return if the device has a light sensor 757 * @return if the device has a light sensor
755 */ 758 */
756bool ODevice::hasLightSensor ( ) const 759bool ODevice::hasLightSensor ( ) const
757{ 760{
758 return false; 761 return false;
759} 762}
760 763
761/** 764/**
762 * @return a value from the light senso 765 * @return a value from the light senso
763 */ 766 */
764int ODevice::readLightSensor ( ) 767int ODevice::readLightSensor ( )
765{ 768{
766 return -1; 769 return -1;
767} 770}
768 771
769/** 772/**
770 * @return the light sensor resolution whatever that is ;) 773 * @return the light sensor resolution whatever that is ;)
771 */ 774 */
772int ODevice::lightSensorResolution ( ) const 775int ODevice::lightSensorResolution ( ) const
773{ 776{
774 return 0; 777 return 0;
775} 778}
776 779
777/** 780/**
778 * @return a list with CPU frequencies supported by the hardware 781 * @return a list with CPU frequencies supported by the hardware
779 */ 782 */
780const QStrList &ODevice::allowedCpuFrequencies ( ) const 783const QStrList &ODevice::allowedCpuFrequencies ( ) const
781{ 784{
782 return *d->m_cpu_frequencies; 785 return *d->m_cpu_frequencies;
783} 786}
784 787
785 788
786/** 789/**
787 * Set desired CPU frequency 790 * Set desired CPU frequency
788 * 791 *
789 * @param index index into d->m_cpu_frequencies of the frequency to be set 792 * @param index index into d->m_cpu_frequencies of the frequency to be set
790 */ 793 */
791bool ODevice::setCurrentCpuFrequency(uint index) 794bool ODevice::setCurrentCpuFrequency(uint index)
792{ 795{
793 if (index >= d->m_cpu_frequencies->count()) 796 if (index >= d->m_cpu_frequencies->count())
794 return false; 797 return false;
795 798
796 char *freq = d->m_cpu_frequencies->at(index); 799 char *freq = d->m_cpu_frequencies->at(index);
797 qWarning("set freq to %s", freq); 800 qWarning("set freq to %s", freq);
798 801
799 int fd; 802 int fd;
800 803
801 if ((fd = ::open("/proc/sys/cpu/0/speed", O_WRONLY)) >= 0) { 804 if ((fd = ::open("/proc/sys/cpu/0/speed", O_WRONLY)) >= 0) {
802 char writeCommand[50]; 805 char writeCommand[50];
803 const int count = sprintf(writeCommand, "%s\n", freq); 806 const int count = sprintf(writeCommand, "%s\n", freq);
804 int res = (::write(fd, writeCommand, count) != -1); 807 int res = (::write(fd, writeCommand, count) != -1);
805 ::close(fd); 808 ::close(fd);
806 return res; 809 return res;
807 } 810 }
808 811
809 return false; 812 return false;
810} 813}
811 814
812 815
813/** 816/**
814 * @return a list of hardware buttons 817 * @return a list of hardware buttons
815 */ 818 */
816const QValueList <ODeviceButton> &ODevice::buttons ( ) 819const QValueList <ODeviceButton> &ODevice::buttons ( )
817{ 820{
818 initButtons ( ); 821 initButtons ( );
819 822
820 return *d-> m_buttons; 823 return *d-> m_buttons;
821} 824}
822 825
823/** 826/**
824 * @return The amount of time that would count as a hold 827 * @return The amount of time that would count as a hold
825 */ 828 */
826uint ODevice::buttonHoldTime ( ) const 829uint ODevice::buttonHoldTime ( ) const
827{ 830{
828 return d-> m_holdtime; 831 return d-> m_holdtime;
829} 832}
830 833
831/** 834/**
832 * This method return a ODeviceButton for a key code 835 * This method return a ODeviceButton for a key code
833 * or 0 if no special hardware button is available for the device 836 * or 0 if no special hardware button is available for the device
834 * 837 *
835 * @return The devicebutton or 0l 838 * @return The devicebutton or 0l
836 * @see ODeviceButton 839 * @see ODeviceButton
837 */ 840 */
838const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) 841const ODeviceButton *ODevice::buttonForKeycode ( ushort code )
839{ 842{
840 initButtons ( ); 843 initButtons ( );
841 844
842 for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) { 845 for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) {
843 if ( (*it). keycode ( ) == code ) 846 if ( (*it). keycode ( ) == code )
844 return &(*it); 847 return &(*it);
845 } 848 }
846 return 0; 849 return 0;
847} 850}
848 851
849void ODevice::reloadButtonMapping ( ) 852void ODevice::reloadButtonMapping ( )
850{ 853{
851 initButtons ( ); 854 initButtons ( );
852 855
@@ -859,133 +862,131 @@ void ODevice::reloadButtonMapping ( )
859 QCString pch, hch; 862 QCString pch, hch;
860 QCString pm, hm; 863 QCString pm, hm;
861 QByteArray pdata, hdata; 864 QByteArray pdata, hdata;
862 865
863 if ( cfg. hasGroup ( group )) { 866 if ( cfg. hasGroup ( group )) {
864 cfg. setGroup ( group ); 867 cfg. setGroup ( group );
865 pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( ); 868 pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( );
866 pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( ); 869 pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( );
867 // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); 870 // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" ));
868 871
869 hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( ); 872 hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( );
870 hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( ); 873 hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( );
871 // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); 874 // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" ));
872 } 875 }
873 876
874 b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); 877 b. setPressedAction ( OQCopMessage ( pch, pm, pdata ));
875 878
876 b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); 879 b. setHeldAction ( OQCopMessage ( hch, hm, hdata ));
877 } 880 }
878} 881}
879 882
880void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) 883void ODevice::remapPressedAction ( int button, const OQCopMessage &action )
881{ 884{
882 initButtons ( ); 885 initButtons ( );
883 886
884 QString mb_chan; 887 QString mb_chan;
885 888
886 if ( button >= (int) d-> m_buttons-> count ( )) 889 if ( button >= (int) d-> m_buttons-> count ( ))
887 return; 890 return;
888 891
889 ODeviceButton &b = ( *d-> m_buttons ) [button]; 892 ODeviceButton &b = ( *d-> m_buttons ) [button];
890 b. setPressedAction ( action ); 893 b. setPressedAction ( action );
891 894
892 mb_chan=b. pressedAction ( ). channel ( ); 895 mb_chan=b. pressedAction ( ). channel ( );
893 896
894 Config buttonFile ( "ButtonSettings" ); 897 Config buttonFile ( "ButtonSettings" );
895 buttonFile. setGroup ( "Button" + QString::number ( button )); 898 buttonFile. setGroup ( "Button" + QString::number ( button ));
896 buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); 899 buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan);
897 buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( )); 900 buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( ));
898 901
899 //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( ))); 902 //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( )));
900 903
901 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 904 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
902} 905}
903 906
904void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) 907void ODevice::remapHeldAction ( int button, const OQCopMessage &action )
905{ 908{
906 initButtons ( ); 909 initButtons ( );
907 910
908 if ( button >= (int) d-> m_buttons-> count ( )) 911 if ( button >= (int) d-> m_buttons-> count ( ))
909 return; 912 return;
910 913
911 ODeviceButton &b = ( *d-> m_buttons ) [button]; 914 ODeviceButton &b = ( *d-> m_buttons ) [button];
912 b. setHeldAction ( action ); 915 b. setHeldAction ( action );
913 916
914 Config buttonFile ( "ButtonSettings" ); 917 Config buttonFile ( "ButtonSettings" );
915 buttonFile. setGroup ( "Button" + QString::number ( button )); 918 buttonFile. setGroup ( "Button" + QString::number ( button ));
916 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( )); 919 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( ));
917 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( )); 920 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( ));
918 921
919 //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( ))); 922 //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( )));
920 923
921 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 924 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
922} 925}
923void ODevice::virtual_hook( int id, void* data ) { 926void ODevice::virtual_hook(int, void* ){
924 Q_UNUSED(id);
925 Q_UNUSED(data);
926}
927 927
928}
928 929
929 930
930/************************************************** 931/**************************************************
931 * 932 *
932 * iPAQ 933 * iPAQ
933 * 934 *
934 **************************************************/ 935 **************************************************/
935 936
936void iPAQ::init ( ) 937void iPAQ::init ( )
937{ 938{
938 d-> m_vendorstr = "HP"; 939 d-> m_vendorstr = "HP";
939 d-> m_vendor = Vendor_HP; 940 d-> m_vendor = Vendor_HP;
940 941
941 QFile f ( "/proc/hal/model" ); 942 QFile f ( "/proc/hal/model" );
942 943
943 if ( f. open ( IO_ReadOnly )) { 944 if ( f. open ( IO_ReadOnly )) {
944 QTextStream ts ( &f ); 945 QTextStream ts ( &f );
945 946
946 d-> m_modelstr = "H" + ts. readLine ( ); 947 d-> m_modelstr = "H" + ts. readLine ( );
947 948
948 if ( d-> m_modelstr == "H3100" ) 949 if ( d-> m_modelstr == "H3100" )
949 d-> m_model = Model_iPAQ_H31xx; 950 d-> m_model = Model_iPAQ_H31xx;
950 else if ( d-> m_modelstr == "H3600" ) 951 else if ( d-> m_modelstr == "H3600" )
951 d-> m_model = Model_iPAQ_H36xx; 952 d-> m_model = Model_iPAQ_H36xx;
952 else if ( d-> m_modelstr == "H3700" ) 953 else if ( d-> m_modelstr == "H3700" )
953 d-> m_model = Model_iPAQ_H37xx; 954 d-> m_model = Model_iPAQ_H37xx;
954 else if ( d-> m_modelstr == "H3800" ) 955 else if ( d-> m_modelstr == "H3800" )
955 d-> m_model = Model_iPAQ_H38xx; 956 d-> m_model = Model_iPAQ_H38xx;
956 else if ( d-> m_modelstr == "H3900" ) 957 else if ( d-> m_modelstr == "H3900" )
957 d-> m_model = Model_iPAQ_H39xx; 958 d-> m_model = Model_iPAQ_H39xx;
958 else 959 else
959 d-> m_model = Model_Unknown; 960 d-> m_model = Model_Unknown;
960 961
961 f. close ( ); 962 f. close ( );
962 } 963 }
963 964
964 switch ( d-> m_model ) { 965 switch ( d-> m_model ) {
965 case Model_iPAQ_H31xx: 966 case Model_iPAQ_H31xx:
966 case Model_iPAQ_H38xx: 967 case Model_iPAQ_H38xx:
967 d-> m_rotation = Rot90; 968 d-> m_rotation = Rot90;
968 break; 969 break;
969 case Model_iPAQ_H36xx: 970 case Model_iPAQ_H36xx:
970 case Model_iPAQ_H37xx: 971 case Model_iPAQ_H37xx:
971 case Model_iPAQ_H39xx: 972 case Model_iPAQ_H39xx:
972 default: 973 default:
973 d-> m_rotation = Rot270; 974 d-> m_rotation = Rot270;
974 break; 975 break;
975 } 976 }
976 977
977 f. setName ( "/etc/familiar-version" ); 978 f. setName ( "/etc/familiar-version" );
978 if ( f. open ( IO_ReadOnly )) { 979 if ( f. open ( IO_ReadOnly )) {
979 d-> m_systemstr = "Familiar"; 980 d-> m_systemstr = "Familiar";
980 d-> m_system = System_Familiar; 981 d-> m_system = System_Familiar;
981 982
982 QTextStream ts ( &f ); 983 QTextStream ts ( &f );
983 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 984 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
984 985
985 f. close ( ); 986 f. close ( );
986 } else { 987 } else {
987 f. setName ( "/etc/oz_version" ); 988 f. setName ( "/etc/oz_version" );
988 989
989 if ( f. open ( IO_ReadOnly )) { 990 if ( f. open ( IO_ReadOnly )) {
990 d-> m_systemstr = "OpenEmbedded/iPaq"; 991 d-> m_systemstr = "OpenEmbedded/iPaq";
991 d-> m_system = System_Familiar; 992 d-> m_system = System_Familiar;
@@ -1587,129 +1588,128 @@ bool Zaurus::setLedState ( OLed which, OLedState st )
1587 } 1588 }
1588 } 1589 }
1589 return false; 1590 return false;
1590} 1591}
1591 1592
1592bool Zaurus::setSoftSuspend ( bool soft ) 1593bool Zaurus::setSoftSuspend ( bool soft )
1593{ 1594{
1594 bool res = false; 1595 bool res = false;
1595 int fd; 1596 int fd;
1596 1597
1597 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || 1598 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
1598 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { 1599 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
1599 1600
1600 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources 1601 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources
1601 1602
1602 if ( sources >= 0 ) { 1603 if ( sources >= 0 ) {
1603 if ( soft ) 1604 if ( soft )
1604 sources &= ~APM_EVT_POWER_BUTTON; 1605 sources &= ~APM_EVT_POWER_BUTTON;
1605 else 1606 else
1606 sources |= APM_EVT_POWER_BUTTON; 1607 sources |= APM_EVT_POWER_BUTTON;
1607 1608
1608 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources 1609 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources
1609 res = true; 1610 res = true;
1610 else 1611 else
1611 perror ( "APM_IOCGEVTSRC" ); 1612 perror ( "APM_IOCGEVTSRC" );
1612 } 1613 }
1613 else 1614 else
1614 perror ( "APM_IOCGEVTSRC" ); 1615 perror ( "APM_IOCGEVTSRC" );
1615 1616
1616 ::close ( fd ); 1617 ::close ( fd );
1617 } 1618 }
1618 else 1619 else
1619 perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); 1620 perror ( "/dev/apm_bios or /dev/misc/apm_bios" );
1620 1621
1621 return res; 1622 return res;
1622} 1623}
1623 1624
1624 1625
1625bool Zaurus::setDisplayBrightness ( int bright ) 1626bool Zaurus::setDisplayBrightness ( int bright )
1626{ 1627{
1627 bool res = false; 1628 bool res = false;
1628 int fd; 1629 int fd;
1629 1630
1630 if ( bright > 255 ) 1631 if ( bright > 255 )
1631 bright = 255; 1632 bright = 255;
1632 if ( bright < 0 ) 1633 if ( bright < 0 )
1633 bright = 0; 1634 bright = 0;
1634 1635
1635 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) { 1636 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) {
1636 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus 1637 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus
1637 if ( bright && !bl ) 1638 if ( bright && !bl )
1638 bl = 1; 1639 bl = 1;
1639 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 ); 1640 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 );
1640 ::close ( fd ); 1641 ::close ( fd );
1641 } 1642 }
1642 return res; 1643 return res;
1643} 1644}
1644 1645
1645 1646
1646int Zaurus::displayBrightnessResolution ( ) const 1647int Zaurus::displayBrightnessResolution ( ) const
1647{ 1648{
1648 return 5; 1649 return 5;
1649} 1650}
1650 1651
1651
1652/************************************************** 1652/**************************************************
1653 * 1653 *
1654 * SIMpad 1654 * SIMpad
1655 * 1655 *
1656 **************************************************/ 1656 **************************************************/
1657 1657
1658void SIMpad::init ( ) 1658void SIMpad::init ( )
1659{ 1659{
1660 d-> m_vendorstr = "SIEMENS"; 1660 d-> m_vendorstr = "SIEMENS";
1661 d-> m_vendor = Vendor_SIEMENS; 1661 d-> m_vendor = Vendor_SIEMENS;
1662 1662
1663 QFile f ( "/proc/hal/model" ); 1663 QFile f ( "/proc/hal/model" );
1664 1664
1665 //TODO Implement model checking 1665 //TODO Implement model checking
1666 //FIXME For now we assume an SL4 1666 //FIXME For now we assume an SL4
1667 1667
1668 d-> m_modelstr = "SL4"; 1668 d-> m_modelstr = "SL4";
1669 d-> m_model = Model_SIMpad_SL4; 1669 d-> m_model = Model_SIMpad_SL4;
1670 1670
1671 switch ( d-> m_model ) { 1671 switch ( d-> m_model ) {
1672 default: 1672 default:
1673 d-> m_rotation = Rot0; 1673 d-> m_rotation = Rot0;
1674 d-> m_direction = CCW; 1674 d-> m_direction = CCW;
1675 d-> m_holdtime = 1000; // 1000ms 1675 d-> m_holdtime = 1000; // 1000ms
1676 1676
1677 break; 1677 break;
1678 } 1678 }
1679 1679
1680 f. setName ( "/etc/familiar-version" ); 1680 f. setName ( "/etc/familiar-version" );
1681 if ( f. open ( IO_ReadOnly )) { 1681 if ( f. open ( IO_ReadOnly )) {
1682 d-> m_systemstr = "Familiar"; 1682 d-> m_systemstr = "Familiar";
1683 d-> m_system = System_Familiar; 1683 d-> m_system = System_Familiar;
1684 1684
1685 QTextStream ts ( &f ); 1685 QTextStream ts ( &f );
1686 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 1686 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
1687 1687
1688 f. close ( ); 1688 f. close ( );
1689 } else { 1689 } else {
1690 f. setName ( "/etc/oz_version" ); 1690 f. setName ( "/etc/oz_version" );
1691 1691
1692 if ( f. open ( IO_ReadOnly )) { 1692 if ( f. open ( IO_ReadOnly )) {
1693 d-> m_systemstr = "OpenEmbedded/SIMpad"; 1693 d-> m_systemstr = "OpenEmbedded/SIMpad";
1694 d-> m_system = System_OpenZaurus; 1694 d-> m_system = System_OpenZaurus;
1695 1695
1696 QTextStream ts ( &f ); 1696 QTextStream ts ( &f );
1697 ts.setDevice ( &f ); 1697 ts.setDevice ( &f );
1698 d-> m_sysverstr = ts. readLine ( ); 1698 d-> m_sysverstr = ts. readLine ( );
1699 f. close ( ); 1699 f. close ( );
1700 } 1700 }
1701 } 1701 }
1702 1702
1703 m_leds [0] = m_leds [1] = Led_Off; 1703 m_leds [0] = m_leds [1] = Led_Off;
1704 1704
1705 m_power_timer = 0; 1705 m_power_timer = 0;
1706 1706
1707} 1707}
1708 1708
1709void SIMpad::initButtons ( ) 1709void SIMpad::initButtons ( )
1710{ 1710{
1711 if ( d-> m_buttons ) 1711 if ( d-> m_buttons )
1712 return; 1712 return;
1713 1713
1714 if ( isQWS( ) ) 1714 if ( isQWS( ) )
1715 QWSServer::setKeyboardFilter ( this ); 1715 QWSServer::setKeyboardFilter ( this );
@@ -1828,316 +1828,331 @@ bool SIMpad::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress,
1828{ 1828{
1829 //TODO 1829 //TODO
1830 return false; 1830 return false;
1831} 1831}
1832 1832
1833void SIMpad::timerEvent ( QTimerEvent * ) 1833void SIMpad::timerEvent ( QTimerEvent * )
1834{ 1834{
1835 killTimer ( m_power_timer ); 1835 killTimer ( m_power_timer );
1836 m_power_timer = 0; 1836 m_power_timer = 0;
1837 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); 1837 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false );
1838 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); 1838 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false );
1839} 1839}
1840 1840
1841 1841
1842void SIMpad::alarmSound ( ) 1842void SIMpad::alarmSound ( )
1843{ 1843{
1844#ifndef QT_NO_SOUND 1844#ifndef QT_NO_SOUND
1845 static Sound snd ( "alarm" ); 1845 static Sound snd ( "alarm" );
1846 int fd; 1846 int fd;
1847 int vol; 1847 int vol;
1848 bool vol_reset = false; 1848 bool vol_reset = false;
1849 1849
1850 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { 1850 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) {
1851 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { 1851 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
1852 Config cfg ( "qpe" ); 1852 Config cfg ( "qpe" );
1853 cfg. setGroup ( "Volume" ); 1853 cfg. setGroup ( "Volume" );
1854 1854
1855 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); 1855 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
1856 if ( volalarm < 0 ) 1856 if ( volalarm < 0 )
1857 volalarm = 0; 1857 volalarm = 0;
1858 else if ( volalarm > 100 ) 1858 else if ( volalarm > 100 )
1859 volalarm = 100; 1859 volalarm = 100;
1860 volalarm |= ( volalarm << 8 ); 1860 volalarm |= ( volalarm << 8 );
1861 1861
1862 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) 1862 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
1863 vol_reset = true; 1863 vol_reset = true;
1864 } 1864 }
1865 } 1865 }
1866 1866
1867 snd. play ( ); 1867 snd. play ( );
1868 while ( !snd. isFinished ( )) 1868 while ( !snd. isFinished ( ))
1869 qApp-> processEvents ( ); 1869 qApp-> processEvents ( );
1870 1870
1871 if ( fd >= 0 ) { 1871 if ( fd >= 0 ) {
1872 if ( vol_reset ) 1872 if ( vol_reset )
1873 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); 1873 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
1874 ::close ( fd ); 1874 ::close ( fd );
1875 } 1875 }
1876#endif 1876#endif
1877} 1877}
1878 1878
1879 1879
1880bool SIMpad::suspend ( ) // Must override because SIMpad does NOT have apm 1880bool SIMpad::suspend ( ) // Must override because SIMpad does NOT have apm
1881{ 1881{
1882 qDebug( "ODevice for SIMpad: suspend()" ); 1882 qDebug( "ODevice for SIMpad: suspend()" );
1883 if ( !isQWS( ) ) // only qwsserver is allowed to suspend 1883 if ( !isQWS( ) ) // only qwsserver is allowed to suspend
1884 return false; 1884 return false;
1885 1885
1886 bool res = false; 1886 bool res = false;
1887 1887
1888 struct timeval tvs, tvn; 1888 struct timeval tvs, tvn;
1889 ::gettimeofday ( &tvs, 0 ); 1889 ::gettimeofday ( &tvs, 0 );
1890 1890
1891 ::sync ( ); // flush fs caches 1891 ::sync ( ); // flush fs caches
1892 res = ( ::system ( "echo > /proc/sys/pm/suspend" ) == 0 ); //TODO make better :) 1892 res = ( ::system ( "cat /dev/fb/0 >/tmp/.buffer; echo > /proc/sys/pm/suspend; cat /tmp/.buffer >/dev/fb/0" ) == 0 ); //TODO make better :)
1893 1893
1894 return res; 1894 return res;
1895} 1895}
1896 1896
1897 1897
1898bool SIMpad::setSoftSuspend ( bool soft ) 1898bool SIMpad::setSoftSuspend ( bool soft )
1899{ 1899{
1900 qDebug( "ODevice for SIMpad: UNHANDLED setSoftSuspend(%s)", soft? "on" : "off" ); 1900 qDebug( "ODevice for SIMpad: UNHANDLED setSoftSuspend(%s)", soft? "on" : "off" );
1901 return false; 1901 return false;
1902} 1902}
1903 1903
1904 1904
1905bool SIMpad::setDisplayStatus ( bool on ) 1905bool SIMpad::setDisplayStatus ( bool on )
1906{ 1906{
1907 qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" ); 1907 qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" );
1908 1908
1909 bool res = false; 1909 bool res = false;
1910 int fd; 1910 int fd;
1911 1911
1912 QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :) 1912 QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :)
1913 1913
1914 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { 1914 res = ( ::system( (const char*) cmdline ) == 0 );
1915 res = ( ::system( (const char*) cmdline ) == 0 ); 1915
1916 ::close ( fd );
1917 }
1918 return res; 1916 return res;
1919} 1917}
1920 1918
1921 1919
1922bool SIMpad::setDisplayBrightness ( int bright ) 1920bool SIMpad::setDisplayBrightness ( int bright )
1923{ 1921{
1924 qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright ); 1922 qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright );
1925 bool res = false; 1923 bool res = false;
1926 int fd; 1924 int fd;
1927 1925
1928 if ( bright > 255 ) 1926 if ( bright > 255 )
1929 bright = 255; 1927 bright = 255;
1930 if ( bright < 0 ) 1928 if ( bright < 1 )
1931 bright = 0; 1929 bright = 0;
1932 1930
1933 if (( fd = ::open ( SIMPAD_BACKLIGHT_CONTROL, O_WRONLY )) >= 0 ) { 1931 if (( fd = ::open ( SIMPAD_BACKLIGHT_CONTROL, O_WRONLY )) >= 0 ) {
1934 int value = 255 - bright; 1932 int value = 255 - bright;
1935 const int mask = SIMPAD_BACKLIGHT_MASK; 1933 const int mask = SIMPAD_BACKLIGHT_MASK;
1936 value = value << 8; 1934 value = value << 8;
1937 value += mask; 1935 value += mask;
1938 char writeCommand[100]; 1936 char writeCommand[100];
1939 const int count = sprintf( writeCommand, "0x%x\n", value ); 1937 const int count = sprintf( writeCommand, "0x%x\n", value );
1940 res = ( ::write ( fd, writeCommand, count ) != -1 ); 1938 res = ( ::write ( fd, writeCommand, count ) != -1 );
1941 ::close ( fd ); 1939 ::close ( fd );
1942 } 1940 }
1943 return res; 1941 return res;
1944} 1942}
1945 1943
1946 1944
1947int SIMpad::displayBrightnessResolution ( ) const 1945int SIMpad::displayBrightnessResolution ( ) const
1948{ 1946{
1949 switch ( model ( )) { 1947 return 255; // All SIMpad models share the same display
1950 case Model_SIMpad_CL4:
1951 case Model_SIMpad_SL4:
1952 case Model_SIMpad_SLC:
1953 case Model_SIMpad_TSinus:
1954 return 255; //TODO find out if this is save
1955
1956 default:
1957 return 2;
1958 }
1959} 1948}
1960 1949
1961/************************************************** 1950/**************************************************
1962 * 1951 *
1963 * Ramses 1952 * Ramses
1964 * 1953 *
1965 **************************************************/ 1954 **************************************************/
1966 1955
1967void Ramses::init() 1956void Ramses::init()
1968{ 1957{
1969 d->m_vendorstr = "M und N"; 1958 d->m_vendorstr = "M und N";
1970 d->m_vendor = Vendor_MundN; 1959 d->m_vendor = Vendor_MundN;
1971 1960
1972 QFile f("/proc/sys/board/ramses"); 1961 QFile f("/proc/sys/board/ramses");
1973 1962
1974 d->m_modelstr = "Ramses"; 1963 d->m_modelstr = "Ramses";
1975 d->m_model = Model_Ramses_MNCI; 1964 d->m_model = Model_Ramses_MNCI;
1976 1965
1977 d->m_rotation = Rot180; 1966 d->m_rotation = Rot0;
1978 d->m_direction = CW; 1967 d->m_holdtime = 1000;
1979 d->m_holdtime = 1000;
1980 1968
1981 f.setName("/etc/oz_version"); 1969 f.setName("/etc/oz_version");
1982 1970
1983 if (f.open(IO_ReadOnly)) { 1971 if (f.open(IO_ReadOnly)) {
1984 d->m_systemstr = "OpenEmbedded/Ramses"; 1972 d->m_systemstr = "OpenEmbedded/Ramses";
1985 d->m_system = System_OpenZaurus; 1973 d->m_system = System_OpenZaurus;
1986 1974
1987 QTextStream ts(&f); 1975 QTextStream ts(&f);
1988 ts.setDevice(&f); 1976 ts.setDevice(&f);
1989 d->m_sysverstr = ts.readLine(); 1977 d->m_sysverstr = ts.readLine();
1990 f.close(); 1978 f.close();
1991 } 1979 }
1992 1980
1993 m_power_timer = 0; 1981 m_power_timer = 0;
1994 1982
1995#ifdef QT_QWS_ALLOW_OVERCLOCK 1983#ifdef QT_QWS_ALLOW_OVERCLOCK
1996#warning *** Overclocking enabled - this may fry your hardware - you have been warned *** 1984#warning *** Overclocking enabled - this may fry your hardware - you have been warned ***
1997#define OC(x...) x 1985#define OC(x...) x
1998#else 1986#else
1999#define OC(x...) 1987#define OC(x...)
2000#endif 1988#endif
2001 1989
2002 1990
2003 // This table is true for a Intel XScale PXA 255 1991 // This table is true for a Intel XScale PXA 255
2004 1992
2005 d->m_cpu_frequencies->append("99000"); // mem= 99, run= 99, turbo= 99, PXbus= 50 1993 d->m_cpu_frequencies->append("99000"); // mem= 99, run= 99, turbo= 99, PXbus= 50
2006 OC(d->m_cpu_frequencies->append("118000"); ) // mem=118, run=118, turbo=118, PXbus= 59 OC'd mem 1994 OC(d->m_cpu_frequencies->append("118000"); ) // mem=118, run=118, turbo=118, PXbus= 59 OC'd mem
2007 d->m_cpu_frequencies->append("199100"); // mem= 99, run=199, turbo=199, PXbus= 99 1995 d->m_cpu_frequencies->append("199100"); // mem= 99, run=199, turbo=199, PXbus= 99
2008 OC(d->m_cpu_frequencies->append("236000"); ) // mem=118, run=236, turbo=236, PXbus=118 OC'd mem 1996 OC(d->m_cpu_frequencies->append("236000"); ) // mem=118, run=236, turbo=236, PXbus=118 OC'd mem
2009 d->m_cpu_frequencies->append("298600"); // mem= 99, run=199, turbo=298, PXbus= 99 1997 d->m_cpu_frequencies->append("298600"); // mem= 99, run=199, turbo=298, PXbus= 99
2010 OC(d->m_cpu_frequencies->append("354000"); ) // mem=118, run=236, turbo=354, PXbus=118 OC'd mem 1998 OC(d->m_cpu_frequencies->append("354000"); ) // mem=118, run=236, turbo=354, PXbus=118 OC'd mem
2011 d->m_cpu_frequencies->append("398099"); // mem= 99, run=199, turbo=398, PXbus= 99 1999 d->m_cpu_frequencies->append("398099"); // mem= 99, run=199, turbo=398, PXbus= 99
2012 d->m_cpu_frequencies->append("398100"); // mem= 99, run=398, turbo=398, PXbus=196 2000 d->m_cpu_frequencies->append("398100"); // mem= 99, run=398, turbo=398, PXbus=196
2013 OC(d->m_cpu_frequencies->append("471000"); ) // mem=118, run=471, turbo=471, PXbus=236 OC'd mem/core/bus 2001 OC(d->m_cpu_frequencies->append("471000"); ) // mem=118, run=471, turbo=471, PXbus=236 OC'd mem/core/bus
2014 2002
2015} 2003}
2016 2004
2017bool Ramses::filter(int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat) 2005bool Ramses::filter(int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat)
2018{ 2006{
2019 Q_UNUSED( keycode ); 2007 Q_UNUSED( keycode );
2020 Q_UNUSED( modifiers ); 2008 Q_UNUSED( modifiers );
2021 Q_UNUSED( isPress ); 2009 Q_UNUSED( isPress );
2022 Q_UNUSED( autoRepeat ); 2010 Q_UNUSED( autoRepeat );
2023 return false; 2011 return false;
2024} 2012}
2025 2013
2026void Ramses::timerEvent(QTimerEvent *) 2014void Ramses::timerEvent(QTimerEvent *)
2027{ 2015{
2028 killTimer(m_power_timer); 2016 killTimer(m_power_timer);
2029 m_power_timer = 0; 2017 m_power_timer = 0;
2030 QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, true, false); 2018 QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, true, false);
2031 QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, false, false); 2019 QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, false, false);
2032} 2020}
2033 2021
2034 2022
2035bool Ramses::setSoftSuspend(bool soft) 2023bool Ramses::setSoftSuspend(bool soft)
2036{ 2024{
2037 Q_UNUSED(soft); 2025 qDebug("Ramses::setSoftSuspend(%d)", soft);
2038 return true; 2026#if 0
2039}
2040
2041bool Ramses::suspend()
2042{
2043 //qDebug("Ramses::suspend()");
2044 if ( !isQWS() ) // only qwsserver is allowed to suspend
2045 return false;
2046
2047 bool res = false; 2027 bool res = false;
2048 int fd; 2028 int fd;
2049 2029
2050 if ((fd = ::open("/proc/sys/pm/suspend", O_WRONLY)) >= 0) { 2030 if (((fd = ::open("/dev/apm_bios", O_RDWR)) >= 0) ||
2051 res = ( ::write ( fd, "1", 1 ) != -1 ); 2031 ((fd = ::open("/dev/misc/apm_bios",O_RDWR)) >= 0)) {
2032
2033 int sources = ::ioctl(fd, APM_IOCGEVTSRC, 0); // get current event sources
2034
2035 if (sources >= 0) {
2036 if (soft)
2037 sources &= ~APM_EVT_POWER_BUTTON;
2038 else
2039 sources |= APM_EVT_POWER_BUTTON;
2040
2041 if (::ioctl(fd, APM_IOCSEVTSRC, sources) >= 0) // set new event sources
2042 res = true;
2043 else
2044 perror("APM_IOCGEVTSRC");
2045 }
2046 else
2047 perror("APM_IOCGEVTSRC");
2048
2052 ::close(fd); 2049 ::close(fd);
2053 } 2050 }
2054 return res; 2051 else
2052 perror("/dev/apm_bios or /dev/misc/apm_bios");
2053
2054 return res;
2055#else
2056 return true;
2057#endif
2058}
2059
2060bool Ramses::suspend ( )
2061{
2062 qDebug("Ramses::suspend");
2063 return false;
2055} 2064}
2056 2065
2057/** 2066/**
2058 * This sets the display on or off 2067 * This sets the display on or off
2059 */ 2068 */
2060bool Ramses::setDisplayStatus(bool on) 2069bool Ramses::setDisplayStatus(bool on)
2061{ 2070{
2062 //qDebug("Ramses::setDisplayStatus(%d)", on); 2071 qDebug("Ramses::setDisplayStatus(%d)", on);
2072#if 0
2063 bool res = false; 2073 bool res = false;
2064 int fd; 2074 int fd;
2065 2075
2066 if ((fd = ::open ("/dev/fb/1", O_RDWR)) >= 0) { 2076 if ((fd = ::open ("/dev/fb/0", O_RDWR)) >= 0) {
2067 res = (::ioctl(fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN) == 0); 2077 res = (::ioctl(fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN) == 0);
2068 ::close(fd); 2078 ::close(fd);
2069 } 2079 }
2070 return res; 2080 return res;
2081#else
2082 return true;
2083#endif
2071} 2084}
2072 2085
2073 2086
2074/* 2087/*
2075 * We get something between 0..255 into us 2088 * We get something between 0..255 into us
2076*/ 2089*/
2077bool Ramses::setDisplayBrightness(int bright) 2090bool Ramses::setDisplayBrightness(int bright)
2078{ 2091{
2079 //qDebug("Ramses::setDisplayBrightness(%d)", bright); 2092 qDebug("Ramses::setDisplayBrightness(%d)", bright);
2080 bool res = false; 2093 bool res = false;
2081 int fd; 2094 int fd;
2082 2095
2083 // pwm1 brighness: 20 steps 500..0 (dunkel->hell) 2096 // pwm1 brighness: 20 steps 500..0 (dunkel->hell)
2084 2097
2085 if (bright > 255 ) 2098 if (bright > 255 )
2086 bright = 255; 2099 bright = 255;
2087 if (bright < 0) 2100 if (bright < 0)
2088 bright = 0; 2101 bright = 0;
2089 2102
2090 // Turn backlight completely off 2103 // Turn backlight completely off
2091 if ((fd = ::open("/proc/sys/board/lcd_backlight", O_WRONLY)) >= 0) { 2104 if ((fd = ::open("/proc/sys/board/lcd_backlight", O_WRONLY)) >= 0) {
2092 char writeCommand[10]; 2105 char writeCommand[10];
2093 const int count = sprintf(writeCommand, "%d\n", bright ? 1 : 0); 2106 const int count = sprintf(writeCommand, "%d\n", bright ? 1 : 0);
2094 res = (::write(fd, writeCommand, count) != -1); 2107 res = (::write(fd, writeCommand, count) != -1);
2095 ::close(fd); 2108 ::close(fd);
2096 } 2109 }
2097 2110
2098 // scale backlight brightness to hardware 2111 // scale backlight brightness to hardware
2099 if ((fd = ::open("/proc/sys/board/lcd_brightness", O_WRONLY)) >= 0) { 2112 bright = 500-(bright * 500 / 255);
2100 //qDebug(" %d -> pwm1", bright); 2113 if ((fd = ::open("/proc/sys/board/pwm1", O_WRONLY)) >= 0) {
2114 qDebug(" %d -> pwm1", bright);
2101 char writeCommand[100]; 2115 char writeCommand[100];
2102 const int count = sprintf(writeCommand, "%d\n", bright); 2116 const int count = sprintf(writeCommand, "%d\n", bright);
2103 res = (::write(fd, writeCommand, count) != -1); 2117 res = (::write(fd, writeCommand, count) != -1);
2104 ::close(fd); 2118 ::close(fd);
2105 } 2119 }
2106 return res; 2120 return res;
2107} 2121}
2108 2122
2109 2123
2110int Ramses::displayBrightnessResolution() const 2124int Ramses::displayBrightnessResolution() const
2111{ 2125{
2112 return 256; 2126 return 32;
2113} 2127}
2114 2128
2115bool Ramses::setDisplayContrast(int contr) 2129bool Ramses::setDisplayContrast(int contr)
2116{ 2130{
2117 //qDebug("Ramses::setDisplayContrast(%d)", contr); 2131 qDebug("Ramses::setDisplayContrast(%d)", contr);
2118 bool res = false; 2132 bool res = false;
2119 int fd; 2133 int fd;
2120 2134
2121 // pwm0 contrast: 20 steps 79..90 (dunkel->hell) 2135 // pwm0 contrast: 20 steps 79..90 (dunkel->hell)
2122 2136
2123 if (contr > 255 ) 2137 if (contr > 255 )
2124 contr = 255; 2138 contr = 255;
2125 if (contr < 0) 2139 if (contr < 0)
2126 contr = 0; 2140 contr = 0;
2141 contr = 90 - (contr * 20 / 255);
2127 2142
2128 if ((fd = ::open("/proc/sys/board/lcd_contrast", O_WRONLY)) >= 0) { 2143 if ((fd = ::open("/proc/sys/board/pwm0", O_WRONLY)) >= 0) {
2129 //qDebug(" %d -> pwm0", contr); 2144 qDebug(" %d -> pwm0", contr);
2130 char writeCommand[100]; 2145 char writeCommand[100];
2131 const int count = sprintf(writeCommand, "%d\n", contr); 2146 const int count = sprintf(writeCommand, "%d\n", contr);
2132 res = (::write(fd, writeCommand, count) != -1); 2147 res = (::write(fd, writeCommand, count) != -1);
2133 res = true; 2148 res = true;
2134 ::close(fd); 2149 ::close(fd);
2135 } 2150 }
2136 return res; 2151 return res;
2137} 2152}
2138 2153
2139 2154
2140int Ramses::displayContrastResolution() const 2155int Ramses::displayContrastResolution() const
2141{ 2156{
2142 return 256; 2157 return 20;
2143} 2158}