summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp149
1 files changed, 147 insertions, 2 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 3ff029e..aadd0bf 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -46,65 +46,64 @@
46// _IO and friends are only defined in kernel headers ... 46// _IO and friends are only defined in kernel headers ...
47 47
48#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) 48#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
49 49
50#define OD_IO(type,number) OD_IOC(0,type,number,0) 50#define OD_IO(type,number) OD_IOC(0,type,number,0)
51#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) 51#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size))
52#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) 52#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size))
53#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) 53#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size))
54 54
55using namespace Opie; 55using namespace Opie;
56 56
57class ODeviceData { 57class ODeviceData {
58public: 58public:
59 QString m_vendorstr; 59 QString m_vendorstr;
60 OVendor m_vendor; 60 OVendor m_vendor;
61 61
62 QString m_modelstr; 62 QString m_modelstr;
63 OModel m_model; 63 OModel m_model;
64 64
65 QString m_systemstr; 65 QString m_systemstr;
66 OSystem m_system; 66 OSystem m_system;
67 67
68 QString m_sysverstr; 68 QString m_sysverstr;
69 69
70 Transformation m_rotation; 70 Transformation m_rotation;
71 ODirection m_direction; 71 ODirection m_direction;
72 72
73 QValueList <ODeviceButton> *m_buttons; 73 QValueList <ODeviceButton> *m_buttons;
74 uint m_holdtime; 74 uint m_holdtime;
75 QStrList *m_cpu_frequencies; 75 QStrList *m_cpu_frequencies;
76}; 76};
77 77
78
79class iPAQ : public ODevice, public QWSServer::KeyboardFilter { 78class iPAQ : public ODevice, public QWSServer::KeyboardFilter {
80protected: 79protected:
81 virtual void init ( ); 80 virtual void init ( );
82 virtual void initButtons ( ); 81 virtual void initButtons ( );
83 82
84public: 83public:
85 virtual bool setSoftSuspend ( bool soft ); 84 virtual bool setSoftSuspend ( bool soft );
86 85
87 virtual bool setDisplayBrightness ( int b ); 86 virtual bool setDisplayBrightness ( int b );
88 virtual int displayBrightnessResolution ( ) const; 87 virtual int displayBrightnessResolution ( ) const;
89 88
90 virtual void alarmSound ( ); 89 virtual void alarmSound ( );
91 90
92 virtual QValueList <OLed> ledList ( ) const; 91 virtual QValueList <OLed> ledList ( ) const;
93 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 92 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
94 virtual OLedState ledState ( OLed led ) const; 93 virtual OLedState ledState ( OLed led ) const;
95 virtual bool setLedState ( OLed led, OLedState st ); 94 virtual bool setLedState ( OLed led, OLedState st );
96 95
97 virtual bool hasLightSensor ( ) const; 96 virtual bool hasLightSensor ( ) const;
98 virtual int readLightSensor ( ); 97 virtual int readLightSensor ( );
99 virtual int lightSensorResolution ( ) const; 98 virtual int lightSensorResolution ( ) const;
100 99
101protected: 100protected:
102 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); 101 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
103 virtual void timerEvent ( QTimerEvent *te ); 102 virtual void timerEvent ( QTimerEvent *te );
104 103
105 int m_power_timer; 104 int m_power_timer;
106 105
107 OLedState m_leds [2]; 106 OLedState m_leds [2];
108}; 107};
109 108
110class Zaurus : public ODevice { 109class Zaurus : public ODevice {
@@ -340,93 +339,131 @@ struct s_button {
340 "QPE/Launcher", "home()", 339 "QPE/Launcher", "home()",
341 "buttonsettings", "raise()" }, 340 "buttonsettings", "raise()" },
342 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 341 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
343 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), 342 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"),
344 "devicebuttons/simpad_upper_lower", 343 "devicebuttons/simpad_upper_lower",
345 "QPE/Launcher", "home()", 344 "QPE/Launcher", "home()",
346 "buttonsettings", "raise()" }, 345 "buttonsettings", "raise()" },
347 */ 346 */
348}; 347};
349 348
350struct r_button { 349struct r_button {
351 uint model; 350 uint model;
352 Qt::Key code; 351 Qt::Key code;
353 char *utext; 352 char *utext;
354 char *pix; 353 char *pix;
355 char *fpressedservice; 354 char *fpressedservice;
356 char *fpressedaction; 355 char *fpressedaction;
357 char *fheldservice; 356 char *fheldservice;
358 char *fheldaction; 357 char *fheldaction;
359} ramses_buttons [] = { 358} ramses_buttons [] = {
360 { Model_Ramses_MNCI, 359 { Model_Ramses_MNCI,
361 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 360 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
362 "devicebuttons/z_menu", 361 "devicebuttons/z_menu",
363 "QPE/TaskBar", "toggleMenu()", 362 "QPE/TaskBar", "toggleMenu()",
364 "QPE/TaskBar", "toggleStartMenu()" }, 363 "QPE/TaskBar", "toggleStartMenu()" },
365 { Model_Ramses_MNCI, 364 { Model_Ramses_MNCI,
366 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 365 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
367 "devicebuttons/ipaq_home", 366 "devicebuttons/ipaq_home",
368 "QPE/Launcher", "home()", 367 "QPE/Launcher", "home()",
369 "buttonsettings", "raise()" }, 368 "buttonsettings", "raise()" },
370}; 369};
371 370
371class Yopy : public ODevice {
372protected:
373 virtual void init ( );
374 virtual void initButtons ( );
375
376public:
377 virtual bool suspend ( );
378
379 virtual bool setDisplayBrightness ( int b );
380 virtual int displayBrightnessResolution ( ) const;
381
382 static bool isYopy ( );
383};
384
385struct yopy_button {
386 Qt::Key code;
387 char *utext;
388 char *pix;
389 char *fpressedservice;
390 char *fpressedaction;
391 char *fheldservice;
392 char *fheldaction;
393} yopy_buttons [] = {
394 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Action Button"),
395 "devicebuttons/yopy_action",
396 "datebook", "nextView()",
397 "today", "raise()" },
398 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "OK Button"),
399 "devicebuttons/yopy_ok",
400 "addressbook", "raise()",
401 "addressbook", "beamBusinessCard()" },
402 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "End Button"),
403 "devicebuttons/yopy_end",
404 "QPE/Launcher", "home()",
405 "buttonsettings", "raise()" },
406};
407
372static QCString makeChannel ( const char *str ) 408static QCString makeChannel ( const char *str )
373{ 409{
374 if ( str && !::strchr ( str, '/' )) 410 if ( str && !::strchr ( str, '/' ))
375 return QCString ( "QPE/Application/" ) + str; 411 return QCString ( "QPE/Application/" ) + str;
376 else 412 else
377 return str; 413 return str;
378} 414}
379 415
380static inline bool isQWS() 416static inline bool isQWS()
381{ 417{
382 return qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; 418 return qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
383} 419}
384 420
385ODevice *ODevice::inst ( ) 421ODevice *ODevice::inst ( )
386{ 422{
387 static ODevice *dev = 0; 423 static ODevice *dev = 0;
388 424
389 if ( !dev ) { 425 if ( !dev ) {
390 if ( QFile::exists ( "/proc/hal/model" )) 426 if ( QFile::exists ( "/proc/hal/model" ))
391 dev = new iPAQ ( ); 427 dev = new iPAQ ( );
392 else if ( Zaurus::isZaurus() ) 428 else if ( Zaurus::isZaurus() )
393 dev = new Zaurus ( ); 429 dev = new Zaurus ( );
394 else if ( QFile::exists ( "/proc/ucb1x00" ) && QFile::exists ( "/proc/cs3" )) 430 else if ( QFile::exists ( "/proc/ucb1x00" ) && QFile::exists ( "/proc/cs3" ))
395 dev = new SIMpad ( ); 431 dev = new SIMpad ( );
396 else if ( QFile::exists ( "/proc/sys/board/name" )) 432 else if ( QFile::exists ( "/proc/sys/board/name" ))
397 dev = new Ramses ( ); 433 dev = new Ramses ( );
434 else if ( Yopy::isYopy() )
435 dev = new Yopy ( );
398 else 436 else
399 dev = new ODevice ( ); 437 dev = new ODevice ( );
400
401 dev-> init ( ); 438 dev-> init ( );
402 } 439 }
403 return dev; 440 return dev;
404} 441}
405 442
406 443
407/************************************************** 444/**************************************************
408 * 445 *
409 * common 446 * common
410 * 447 *
411 **************************************************/ 448 **************************************************/
412 449
413 450
414ODevice::ODevice ( ) 451ODevice::ODevice ( )
415{ 452{
416 d = new ODeviceData; 453 d = new ODeviceData;
417 454
418 d-> m_modelstr = "Unknown"; 455 d-> m_modelstr = "Unknown";
419 d-> m_model = Model_Unknown; 456 d-> m_model = Model_Unknown;
420 d-> m_vendorstr = "Unknown"; 457 d-> m_vendorstr = "Unknown";
421 d-> m_vendor = Vendor_Unknown; 458 d-> m_vendor = Vendor_Unknown;
422 d-> m_systemstr = "Unknown"; 459 d-> m_systemstr = "Unknown";
423 d-> m_system = System_Unknown; 460 d-> m_system = System_Unknown;
424 d-> m_sysverstr = "0.0"; 461 d-> m_sysverstr = "0.0";
425 d-> m_rotation = Rot0; 462 d-> m_rotation = Rot0;
426 d-> m_direction = CW; 463 d-> m_direction = CW;
427 464
428 d-> m_holdtime = 1000; // 1000ms 465 d-> m_holdtime = 1000; // 1000ms
429 d-> m_buttons = 0; 466 d-> m_buttons = 0;
430 d-> m_cpu_frequencies = new QStrList; 467 d-> m_cpu_frequencies = new QStrList;
431} 468}
432 469
@@ -901,64 +938,172 @@ void ODevice::remapPressedAction ( int button, const OQCopMessage &action )
901 buttonFile. setGroup ( "Button" + QString::number ( button )); 938 buttonFile. setGroup ( "Button" + QString::number ( button ));
902 buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); 939 buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan);
903 buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( )); 940 buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( ));
904 941
905 //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( ))); 942 //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( )));
906 943
907 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 944 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
908} 945}
909 946
910void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) 947void ODevice::remapHeldAction ( int button, const OQCopMessage &action )
911{ 948{
912 initButtons ( ); 949 initButtons ( );
913 950
914 if ( button >= (int) d-> m_buttons-> count ( )) 951 if ( button >= (int) d-> m_buttons-> count ( ))
915 return; 952 return;
916 953
917 ODeviceButton &b = ( *d-> m_buttons ) [button]; 954 ODeviceButton &b = ( *d-> m_buttons ) [button];
918 b. setHeldAction ( action ); 955 b. setHeldAction ( action );
919 956
920 Config buttonFile ( "ButtonSettings" ); 957 Config buttonFile ( "ButtonSettings" );
921 buttonFile. setGroup ( "Button" + QString::number ( button )); 958 buttonFile. setGroup ( "Button" + QString::number ( button ));
922 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( )); 959 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( ));
923 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( )); 960 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( ));
924 961
925 //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( ))); 962 //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( )));
926 963
927 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 964 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
928} 965}
929void ODevice::virtual_hook(int, void* ){ 966void ODevice::virtual_hook(int, void* ){
930 967
931} 968}
932 969
970/**************************************************
971 *
972 * Yopy 3500/3700
973 *
974 **************************************************/
975
976bool Yopy::isYopy ( )
977{
978 QFile f( "/proc/cpuinfo" );
979 if ( f. open ( IO_ReadOnly ) ) {
980 QTextStream ts ( &f );
981 QString line;
982 while( line = ts. readLine ( ) ) {
983 if ( line. left ( 8 ) == "Hardware" ) {
984 int loc = line. find ( ":" );
985 if ( loc != -1 ) {
986 QString model =
987 line. mid ( loc + 2 ). simplifyWhiteSpace( );
988 return ( model == "Yopy" );
989 }
990 }
991 }
992 }
993 return false;
994}
995
996void Yopy::init ( )
997{
998 d-> m_vendorstr = "G.Mate";
999 d-> m_vendor = Vendor_GMate;
1000 d-> m_modelstr = "Yopy3700";
1001 d-> m_model = Model_Yopy_3700;
1002 d-> m_rotation = Rot0;
1003
1004 d-> m_systemstr = "Linupy";
1005 d-> m_system = System_Linupy;
1006
1007 QFile f ( "/etc/issue" );
1008 if ( f. open ( IO_ReadOnly )) {
1009 QTextStream ts ( &f );
1010 ts.readLine();
1011 d-> m_sysverstr = ts. readLine ( );
1012 f. close ( );
1013 }
1014}
1015
1016void Yopy::initButtons ( )
1017{
1018 if ( d-> m_buttons )
1019 return;
1020
1021 d-> m_buttons = new QValueList <ODeviceButton>;
1022
1023 for (uint i = 0; i < ( sizeof( yopy_buttons ) / sizeof(yopy_button)); i++) {
1024
1025 yopy_button *ib = yopy_buttons + i;
1026
1027 ODeviceButton b;
1028
1029 b. setKeycode ( ib-> code );
1030 b. setUserText ( QObject::tr ( "Button", ib-> utext ));
1031 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
1032 b. setFactoryPresetPressedAction
1033 (OQCopMessage(makeChannel(ib->fpressedservice), ib->fpressedaction));
1034 b. setFactoryPresetHeldAction
1035 (OQCopMessage(makeChannel(ib->fheldservice), ib->fheldaction));
1036
1037 d-> m_buttons-> append ( b );
1038 }
1039 reloadButtonMapping ( );
1040
1041 QCopChannel *sysch = new QCopChannel("QPE/System", this);
1042 connect(sysch, SIGNAL(received(const QCString &, const QByteArray & )),
1043 this, SLOT(systemMessage(const QCString &, const QByteArray & )));
1044}
1045
1046bool Yopy::suspend()
1047{
1048 /* Opie for Yopy does not implement its own power management at the
1049 moment. The public version runs parallel to X, and relies on the
1050 existing power management features. */
1051 return false;
1052}
1053
1054bool Yopy::setDisplayBrightness(int bright)
1055{
1056 /* The code here works, but is disabled as the current version runs
1057 parallel to X, and relies on the existing backlight demon. */
1058#if 0
1059 if ( QFile::exists("/proc/sys/pm/light") ) {
1060 int fd = ::open("/proc/sys/pm/light", O_WRONLY);
1061 if (fd >= 0 ) {
1062 if (bright)
1063 ::write(fd, "1\n", 2);
1064 else
1065 ::write(fd, "0\n", 2);
1066 ::close(fd);
1067 return true;
1068 }
1069 }
1070#endif
1071 return false;
1072}
1073
1074int Yopy::displayBrightnessResolution() const
1075{
1076 return 2;
1077}
933 1078
934/************************************************** 1079/**************************************************
935 * 1080 *
936 * iPAQ 1081 * iPAQ
937 * 1082 *
938 **************************************************/ 1083 **************************************************/
939 1084
940void iPAQ::init ( ) 1085void iPAQ::init ( )
941{ 1086{
942 d-> m_vendorstr = "HP"; 1087 d-> m_vendorstr = "HP";
943 d-> m_vendor = Vendor_HP; 1088 d-> m_vendor = Vendor_HP;
944 1089
945 QFile f ( "/proc/hal/model" ); 1090 QFile f ( "/proc/hal/model" );
946 1091
947 if ( f. open ( IO_ReadOnly )) { 1092 if ( f. open ( IO_ReadOnly )) {
948 QTextStream ts ( &f ); 1093 QTextStream ts ( &f );
949 1094
950 d-> m_modelstr = "H" + ts. readLine ( ); 1095 d-> m_modelstr = "H" + ts. readLine ( );
951 1096
952 if ( d-> m_modelstr == "H3100" ) 1097 if ( d-> m_modelstr == "H3100" )
953 d-> m_model = Model_iPAQ_H31xx; 1098 d-> m_model = Model_iPAQ_H31xx;
954 else if ( d-> m_modelstr == "H3600" ) 1099 else if ( d-> m_modelstr == "H3600" )
955 d-> m_model = Model_iPAQ_H36xx; 1100 d-> m_model = Model_iPAQ_H36xx;
956 else if ( d-> m_modelstr == "H3700" ) 1101 else if ( d-> m_modelstr == "H3700" )
957 d-> m_model = Model_iPAQ_H37xx; 1102 d-> m_model = Model_iPAQ_H37xx;
958 else if ( d-> m_modelstr == "H3800" ) 1103 else if ( d-> m_modelstr == "H3800" )
959 d-> m_model = Model_iPAQ_H38xx; 1104 d-> m_model = Model_iPAQ_H38xx;
960 else if ( d-> m_modelstr == "H3900" ) 1105 else if ( d-> m_modelstr == "H3900" )
961 d-> m_model = Model_iPAQ_H39xx; 1106 d-> m_model = Model_iPAQ_H39xx;
962 else 1107 else
963 d-> m_model = Model_Unknown; 1108 d-> m_model = Model_Unknown;
964 1109