-rw-r--r-- | libopie/odevice.cpp | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index aadd0bf..8624016 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp | |||
@@ -61,96 +61,108 @@ public: | |||
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 | class iPAQ : public ODevice, public QWSServer::KeyboardFilter { | 78 | class iPAQ : public ODevice, public QWSServer::KeyboardFilter { |
79 | protected: | 79 | protected: |
80 | virtual void init ( ); | 80 | virtual void init ( ); |
81 | virtual void initButtons ( ); | 81 | virtual void initButtons ( ); |
82 | 82 | ||
83 | public: | 83 | public: |
84 | virtual bool setSoftSuspend ( bool soft ); | 84 | virtual bool setSoftSuspend ( bool soft ); |
85 | 85 | ||
86 | virtual bool setDisplayBrightness ( int b ); | 86 | virtual bool setDisplayBrightness ( int b ); |
87 | virtual int displayBrightnessResolution ( ) const; | 87 | virtual int displayBrightnessResolution ( ) const; |
88 | 88 | ||
89 | virtual void alarmSound ( ); | 89 | virtual void alarmSound ( ); |
90 | 90 | ||
91 | virtual QValueList <OLed> ledList ( ) const; | 91 | virtual QValueList <OLed> ledList ( ) const; |
92 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; | 92 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; |
93 | virtual OLedState ledState ( OLed led ) const; | 93 | virtual OLedState ledState ( OLed led ) const; |
94 | virtual bool setLedState ( OLed led, OLedState st ); | 94 | virtual bool setLedState ( OLed led, OLedState st ); |
95 | 95 | ||
96 | virtual bool hasLightSensor ( ) const; | 96 | virtual bool hasLightSensor ( ) const; |
97 | virtual int readLightSensor ( ); | 97 | virtual int readLightSensor ( ); |
98 | virtual int lightSensorResolution ( ) const; | 98 | virtual int lightSensorResolution ( ) const; |
99 | 99 | ||
100 | protected: | 100 | protected: |
101 | 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 ); |
102 | virtual void timerEvent ( QTimerEvent *te ); | 102 | virtual void timerEvent ( QTimerEvent *te ); |
103 | 103 | ||
104 | int m_power_timer; | 104 | int m_power_timer; |
105 | 105 | ||
106 | OLedState m_leds [2]; | 106 | OLedState m_leds [2]; |
107 | }; | 107 | }; |
108 | 108 | ||
109 | class Jornada : public ODevice { | ||
110 | protected: | ||
111 | virtual void init ( ); | ||
112 | virtual void initButtons ( ); | ||
113 | public: | ||
114 | virtual bool setSoftSuspend ( bool soft ); | ||
115 | virtual bool setDisplayBrightness ( int b ); | ||
116 | virtual int displayBrightnessResolution ( ) const; | ||
117 | static bool isJornada(); | ||
118 | |||
119 | }; | ||
120 | |||
109 | class Zaurus : public ODevice { | 121 | class Zaurus : public ODevice { |
110 | protected: | 122 | protected: |
111 | virtual void init ( ); | 123 | virtual void init ( ); |
112 | virtual void initButtons ( ); | 124 | virtual void initButtons ( ); |
113 | 125 | ||
114 | public: | 126 | public: |
115 | virtual bool setSoftSuspend ( bool soft ); | 127 | virtual bool setSoftSuspend ( bool soft ); |
116 | 128 | ||
117 | virtual bool setDisplayBrightness ( int b ); | 129 | virtual bool setDisplayBrightness ( int b ); |
118 | virtual int displayBrightnessResolution ( ) const; | 130 | virtual int displayBrightnessResolution ( ) const; |
119 | 131 | ||
120 | virtual void alarmSound ( ); | 132 | virtual void alarmSound ( ); |
121 | virtual void keySound ( ); | 133 | virtual void keySound ( ); |
122 | virtual void touchSound ( ); | 134 | virtual void touchSound ( ); |
123 | 135 | ||
124 | virtual QValueList <OLed> ledList ( ) const; | 136 | virtual QValueList <OLed> ledList ( ) const; |
125 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; | 137 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; |
126 | virtual OLedState ledState ( OLed led ) const; | 138 | virtual OLedState ledState ( OLed led ) const; |
127 | virtual bool setLedState ( OLed led, OLedState st ); | 139 | virtual bool setLedState ( OLed led, OLedState st ); |
128 | 140 | ||
129 | static bool isZaurus(); | 141 | static bool isZaurus(); |
130 | 142 | ||
131 | protected: | 143 | protected: |
132 | virtual void buzzer ( int snd ); | 144 | virtual void buzzer ( int snd ); |
133 | 145 | ||
134 | OLedState m_leds [1]; | 146 | OLedState m_leds [1]; |
135 | bool m_embedix; | 147 | bool m_embedix; |
136 | }; | 148 | }; |
137 | 149 | ||
138 | class SIMpad : public ODevice, public QWSServer::KeyboardFilter { | 150 | class SIMpad : public ODevice, public QWSServer::KeyboardFilter { |
139 | protected: | 151 | protected: |
140 | virtual void init ( ); | 152 | virtual void init ( ); |
141 | virtual void initButtons ( ); | 153 | virtual void initButtons ( ); |
142 | 154 | ||
143 | public: | 155 | public: |
144 | virtual bool setSoftSuspend ( bool soft ); | 156 | virtual bool setSoftSuspend ( bool soft ); |
145 | virtual bool suspend(); | 157 | virtual bool suspend(); |
146 | 158 | ||
147 | virtual bool setDisplayStatus( bool on ); | 159 | virtual bool setDisplayStatus( bool on ); |
148 | virtual bool setDisplayBrightness ( int b ); | 160 | virtual bool setDisplayBrightness ( int b ); |
149 | virtual int displayBrightnessResolution ( ) const; | 161 | virtual int displayBrightnessResolution ( ) const; |
150 | 162 | ||
151 | virtual void alarmSound ( ); | 163 | virtual void alarmSound ( ); |
152 | 164 | ||
153 | virtual QValueList <OLed> ledList ( ) const; | 165 | virtual QValueList <OLed> ledList ( ) const; |
154 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; | 166 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; |
155 | virtual OLedState ledState ( OLed led ) const; | 167 | virtual OLedState ledState ( OLed led ) const; |
156 | virtual bool setLedState ( OLed led, OLedState st ); | 168 | virtual bool setLedState ( OLed led, OLedState st ); |
@@ -388,96 +400,98 @@ struct yopy_button { | |||
388 | char *pix; | 400 | char *pix; |
389 | char *fpressedservice; | 401 | char *fpressedservice; |
390 | char *fpressedaction; | 402 | char *fpressedaction; |
391 | char *fheldservice; | 403 | char *fheldservice; |
392 | char *fheldaction; | 404 | char *fheldaction; |
393 | } yopy_buttons [] = { | 405 | } yopy_buttons [] = { |
394 | { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Action Button"), | 406 | { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Action Button"), |
395 | "devicebuttons/yopy_action", | 407 | "devicebuttons/yopy_action", |
396 | "datebook", "nextView()", | 408 | "datebook", "nextView()", |
397 | "today", "raise()" }, | 409 | "today", "raise()" }, |
398 | { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "OK Button"), | 410 | { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "OK Button"), |
399 | "devicebuttons/yopy_ok", | 411 | "devicebuttons/yopy_ok", |
400 | "addressbook", "raise()", | 412 | "addressbook", "raise()", |
401 | "addressbook", "beamBusinessCard()" }, | 413 | "addressbook", "beamBusinessCard()" }, |
402 | { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "End Button"), | 414 | { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "End Button"), |
403 | "devicebuttons/yopy_end", | 415 | "devicebuttons/yopy_end", |
404 | "QPE/Launcher", "home()", | 416 | "QPE/Launcher", "home()", |
405 | "buttonsettings", "raise()" }, | 417 | "buttonsettings", "raise()" }, |
406 | }; | 418 | }; |
407 | 419 | ||
408 | static QCString makeChannel ( const char *str ) | 420 | static QCString makeChannel ( const char *str ) |
409 | { | 421 | { |
410 | if ( str && !::strchr ( str, '/' )) | 422 | if ( str && !::strchr ( str, '/' )) |
411 | return QCString ( "QPE/Application/" ) + str; | 423 | return QCString ( "QPE/Application/" ) + str; |
412 | else | 424 | else |
413 | return str; | 425 | return str; |
414 | } | 426 | } |
415 | 427 | ||
416 | static inline bool isQWS() | 428 | static inline bool isQWS() |
417 | { | 429 | { |
418 | return qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; | 430 | return qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; |
419 | } | 431 | } |
420 | 432 | ||
421 | ODevice *ODevice::inst ( ) | 433 | ODevice *ODevice::inst ( ) |
422 | { | 434 | { |
423 | static ODevice *dev = 0; | 435 | static ODevice *dev = 0; |
424 | 436 | ||
425 | if ( !dev ) { | 437 | if ( !dev ) { |
426 | if ( QFile::exists ( "/proc/hal/model" )) | 438 | if ( QFile::exists ( "/proc/hal/model" )) |
427 | dev = new iPAQ ( ); | 439 | dev = new iPAQ ( ); |
428 | else if ( Zaurus::isZaurus() ) | 440 | else if ( Zaurus::isZaurus() ) |
429 | dev = new Zaurus ( ); | 441 | dev = new Zaurus ( ); |
430 | else if ( QFile::exists ( "/proc/ucb1x00" ) && QFile::exists ( "/proc/cs3" )) | 442 | else if ( QFile::exists ( "/proc/ucb1x00" ) && QFile::exists ( "/proc/cs3" )) |
431 | dev = new SIMpad ( ); | 443 | dev = new SIMpad ( ); |
432 | else if ( QFile::exists ( "/proc/sys/board/name" )) | 444 | else if ( QFile::exists ( "/proc/sys/board/name" )) |
433 | dev = new Ramses ( ); | 445 | dev = new Ramses ( ); |
434 | else if ( Yopy::isYopy() ) | 446 | else if ( Yopy::isYopy() ) |
435 | dev = new Yopy ( ); | 447 | dev = new Yopy ( ); |
448 | else if ( Jornada::isJornada() ) | ||
449 | dev = new Jornada ( ); | ||
436 | else | 450 | else |
437 | dev = new ODevice ( ); | 451 | dev = new ODevice ( ); |
438 | dev-> init ( ); | 452 | dev-> init ( ); |
439 | } | 453 | } |
440 | return dev; | 454 | return dev; |
441 | } | 455 | } |
442 | 456 | ||
443 | 457 | ||
444 | /************************************************** | 458 | /************************************************** |
445 | * | 459 | * |
446 | * common | 460 | * common |
447 | * | 461 | * |
448 | **************************************************/ | 462 | **************************************************/ |
449 | 463 | ||
450 | 464 | ||
451 | ODevice::ODevice ( ) | 465 | ODevice::ODevice ( ) |
452 | { | 466 | { |
453 | d = new ODeviceData; | 467 | d = new ODeviceData; |
454 | 468 | ||
455 | d-> m_modelstr = "Unknown"; | 469 | d-> m_modelstr = "Unknown"; |
456 | d-> m_model = Model_Unknown; | 470 | d-> m_model = Model_Unknown; |
457 | d-> m_vendorstr = "Unknown"; | 471 | d-> m_vendorstr = "Unknown"; |
458 | d-> m_vendor = Vendor_Unknown; | 472 | d-> m_vendor = Vendor_Unknown; |
459 | d-> m_systemstr = "Unknown"; | 473 | d-> m_systemstr = "Unknown"; |
460 | d-> m_system = System_Unknown; | 474 | d-> m_system = System_Unknown; |
461 | d-> m_sysverstr = "0.0"; | 475 | d-> m_sysverstr = "0.0"; |
462 | d-> m_rotation = Rot0; | 476 | d-> m_rotation = Rot0; |
463 | d-> m_direction = CW; | 477 | d-> m_direction = CW; |
464 | 478 | ||
465 | d-> m_holdtime = 1000; // 1000ms | 479 | d-> m_holdtime = 1000; // 1000ms |
466 | d-> m_buttons = 0; | 480 | d-> m_buttons = 0; |
467 | d-> m_cpu_frequencies = new QStrList; | 481 | d-> m_cpu_frequencies = new QStrList; |
468 | } | 482 | } |
469 | 483 | ||
470 | void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) | 484 | void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) |
471 | { | 485 | { |
472 | if ( msg == "deviceButtonMappingChanged()" ) { | 486 | if ( msg == "deviceButtonMappingChanged()" ) { |
473 | reloadButtonMapping ( ); | 487 | reloadButtonMapping ( ); |
474 | } | 488 | } |
475 | } | 489 | } |
476 | 490 | ||
477 | void ODevice::init ( ) | 491 | void ODevice::init ( ) |
478 | { | 492 | { |
479 | } | 493 | } |
480 | 494 | ||
481 | /** | 495 | /** |
482 | * This method initialises the button mapping | 496 | * This method initialises the button mapping |
483 | */ | 497 | */ |
@@ -2407,48 +2421,160 @@ bool Ramses::setDisplayBrightness(int bright) | |||
2407 | // scale backlight brightness to hardware | 2421 | // scale backlight brightness to hardware |
2408 | bright = 500-(bright * 500 / 255); | 2422 | bright = 500-(bright * 500 / 255); |
2409 | if ((fd = ::open("/proc/sys/board/pwm1", O_WRONLY)) >= 0) { | 2423 | if ((fd = ::open("/proc/sys/board/pwm1", O_WRONLY)) >= 0) { |
2410 | qDebug(" %d -> pwm1", bright); | 2424 | qDebug(" %d -> pwm1", bright); |
2411 | char writeCommand[100]; | 2425 | char writeCommand[100]; |
2412 | const int count = sprintf(writeCommand, "%d\n", bright); | 2426 | const int count = sprintf(writeCommand, "%d\n", bright); |
2413 | res = (::write(fd, writeCommand, count) != -1); | 2427 | res = (::write(fd, writeCommand, count) != -1); |
2414 | ::close(fd); | 2428 | ::close(fd); |
2415 | } | 2429 | } |
2416 | return res; | 2430 | return res; |
2417 | } | 2431 | } |
2418 | 2432 | ||
2419 | 2433 | ||
2420 | int Ramses::displayBrightnessResolution() const | 2434 | int Ramses::displayBrightnessResolution() const |
2421 | { | 2435 | { |
2422 | return 32; | 2436 | return 32; |
2423 | } | 2437 | } |
2424 | 2438 | ||
2425 | bool Ramses::setDisplayContrast(int contr) | 2439 | bool Ramses::setDisplayContrast(int contr) |
2426 | { | 2440 | { |
2427 | qDebug("Ramses::setDisplayContrast(%d)", contr); | 2441 | qDebug("Ramses::setDisplayContrast(%d)", contr); |
2428 | bool res = false; | 2442 | bool res = false; |
2429 | int fd; | 2443 | int fd; |
2430 | 2444 | ||
2431 | // pwm0 contrast: 20 steps 79..90 (dunkel->hell) | 2445 | // pwm0 contrast: 20 steps 79..90 (dunkel->hell) |
2432 | 2446 | ||
2433 | if (contr > 255 ) | 2447 | if (contr > 255 ) |
2434 | contr = 255; | 2448 | contr = 255; |
2435 | if (contr < 0) | 2449 | if (contr < 0) |
2436 | contr = 0; | 2450 | contr = 0; |
2437 | contr = 90 - (contr * 20 / 255); | 2451 | contr = 90 - (contr * 20 / 255); |
2438 | 2452 | ||
2439 | if ((fd = ::open("/proc/sys/board/pwm0", O_WRONLY)) >= 0) { | 2453 | if ((fd = ::open("/proc/sys/board/pwm0", O_WRONLY)) >= 0) { |
2440 | qDebug(" %d -> pwm0", contr); | 2454 | qDebug(" %d -> pwm0", contr); |
2441 | char writeCommand[100]; | 2455 | char writeCommand[100]; |
2442 | const int count = sprintf(writeCommand, "%d\n", contr); | 2456 | const int count = sprintf(writeCommand, "%d\n", contr); |
2443 | res = (::write(fd, writeCommand, count) != -1); | 2457 | res = (::write(fd, writeCommand, count) != -1); |
2444 | res = true; | 2458 | res = true; |
2445 | ::close(fd); | 2459 | ::close(fd); |
2446 | } | 2460 | } |
2447 | return res; | 2461 | return res; |
2448 | } | 2462 | } |
2449 | 2463 | ||
2450 | 2464 | ||
2451 | int Ramses::displayContrastResolution() const | 2465 | int Ramses::displayContrastResolution() const |
2452 | { | 2466 | { |
2453 | return 20; | 2467 | return 20; |
2454 | } | 2468 | } |
2469 | |||
2470 | |||
2471 | /************************************************** | ||
2472 | * * | ||
2473 | * Jornada * | ||
2474 | * * | ||
2475 | **************************************************/ | ||
2476 | |||
2477 | |||
2478 | bool Jornada::isJornada ( ) | ||
2479 | { | ||
2480 | QFile f( "/proc/cpuinfo" ); | ||
2481 | if ( f. open ( IO_ReadOnly ) ) { | ||
2482 | QTextStream ts ( &f ); | ||
2483 | QString line; | ||
2484 | while( line = ts. readLine ( ) ) { | ||
2485 | if ( line. left ( 8 ) == "Hardware" ) { | ||
2486 | int loc = line. find ( ":" ); | ||
2487 | if ( loc != -1 ) { | ||
2488 | QString model = | ||
2489 | line. mid ( loc + 2 ). simplifyWhiteSpace( ); | ||
2490 | return ( model == "HP Jornada 56x" ); | ||
2491 | } | ||
2492 | } | ||
2493 | } | ||
2494 | } | ||
2495 | return false; | ||
2496 | } | ||
2497 | |||
2498 | void Jornada::init ( ) | ||
2499 | { | ||
2500 | d-> m_vendorstr = "HP"; | ||
2501 | d-> m_vendor = Vendor_HP; | ||
2502 | d-> m_modelstr = "Jornada 56x"; | ||
2503 | d-> m_model = Model_Jornada_56x; | ||
2504 | d-> m_systemstr = "Familiar"; | ||
2505 | d-> m_system = System_Familiar; | ||
2506 | d-> m_rotation = Rot0; | ||
2507 | } | ||
2508 | |||
2509 | void Jornada::initButtons ( ) | ||
2510 | { | ||
2511 | if ( d-> m_buttons ) | ||
2512 | return; | ||
2513 | |||
2514 | // Simulation uses iPAQ 3660 device buttons | ||
2515 | |||
2516 | qDebug ( "init Buttons" ); | ||
2517 | d-> m_buttons = new QValueList <ODeviceButton>; | ||
2518 | |||
2519 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { | ||
2520 | i_button *ib = ipaq_buttons + i; | ||
2521 | ODeviceButton b; | ||
2522 | |||
2523 | if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { | ||
2524 | b. setKeycode ( ib-> code ); | ||
2525 | b. setUserText ( QObject::tr ( "Button", ib-> utext )); | ||
2526 | b. setPixmap ( Resource::loadPixmap ( ib-> pix )); | ||
2527 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); | ||
2528 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); | ||
2529 | d-> m_buttons-> append ( b ); | ||
2530 | } | ||
2531 | } | ||
2532 | reloadButtonMapping ( ); | ||
2533 | |||
2534 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | ||
2535 | connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); | ||
2536 | } | ||
2537 | |||
2538 | int Jornada::displayBrightnessResolution ( ) const | ||
2539 | { | ||
2540 | } | ||
2541 | |||
2542 | bool Jornada::setDisplayBrightness ( int bright ) | ||
2543 | { | ||
2544 | bool res = false; | ||
2545 | int fd; | ||
2546 | |||
2547 | if ( bright > 255 ) | ||
2548 | bright = 255; | ||
2549 | if ( bright < 0 ) | ||
2550 | bright = 0; | ||
2551 | |||
2552 | if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { | ||
2553 | FLITE_IN bl; | ||
2554 | bl. mode = 1; | ||
2555 | bl. pwr = bright ? 1 : 0; | ||
2556 | bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255; | ||
2557 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); | ||
2558 | ::close ( fd ); | ||
2559 | } | ||
2560 | return res; | ||
2561 | } | ||
2562 | |||
2563 | bool Jornada::setSoftSuspend ( bool soft ) | ||
2564 | { | ||
2565 | bool res = false; | ||
2566 | int fd; | ||
2567 | |||
2568 | if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { | ||
2569 | if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) | ||
2570 | res = true; | ||
2571 | else | ||
2572 | ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); | ||
2573 | |||
2574 | ::close ( fd ); | ||
2575 | } | ||
2576 | else | ||
2577 | ::perror ( "/proc/sys/ts/suspend_button_mode" ); | ||
2578 | |||
2579 | return res; | ||
2580 | } | ||