author | schurig <schurig> | 2003-06-02 11:12:03 (UTC) |
---|---|---|
committer | schurig <schurig> | 2003-06-02 11:12:03 (UTC) |
commit | 2d6bec942d8b9b8b50639cb4ffe58cf24d5a255b (patch) (side-by-side diff) | |
tree | 5b917d74d600715ad1223f174a9b672d822caf47 /libopie/odevice.cpp | |
parent | 68a88060627137e8cb424c758c1339f1ed5c6eac (diff) | |
download | opie-2d6bec942d8b9b8b50639cb4ffe58cf24d5a255b.zip opie-2d6bec942d8b9b8b50639cb4ffe58cf24d5a255b.tar.gz opie-2d6bec942d8b9b8b50639cb4ffe58cf24d5a255b.tar.bz2 |
new Ramses target
-rw-r--r-- | libopie/odevice.cpp | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index f0429d4..d86654e 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp @@ -68,377 +68,420 @@ public: QString m_sysverstr; Transformation m_rotation; ODirection m_direction; QValueList <ODeviceButton> *m_buttons; uint m_holdtime; }; class iPAQ : public ODevice, public QWSServer::KeyboardFilter { protected: virtual void init ( ); virtual void initButtons ( ); public: virtual bool setSoftSuspend ( bool soft ); virtual bool setDisplayBrightness ( int b ); virtual int displayBrightnessResolution ( ) const; virtual void alarmSound ( ); virtual QValueList <OLed> ledList ( ) const; virtual QValueList <OLedState> ledStateList ( OLed led ) const; virtual OLedState ledState ( OLed led ) const; virtual bool setLedState ( OLed led, OLedState st ); virtual bool hasLightSensor ( ) const; virtual int readLightSensor ( ); virtual int lightSensorResolution ( ) const; protected: virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); virtual void timerEvent ( QTimerEvent *te ); int m_power_timer; OLedState m_leds [2]; }; class Zaurus : public ODevice { protected: virtual void init ( ); virtual void initButtons ( ); public: virtual bool setSoftSuspend ( bool soft ); virtual bool setDisplayBrightness ( int b ); virtual int displayBrightnessResolution ( ) const; virtual void alarmSound ( ); virtual void keySound ( ); virtual void touchSound ( ); virtual QValueList <OLed> ledList ( ) const; virtual QValueList <OLedState> ledStateList ( OLed led ) const; virtual OLedState ledState ( OLed led ) const; virtual bool setLedState ( OLed led, OLedState st ); protected: virtual void buzzer ( int snd ); OLedState m_leds [1]; }; class SIMpad : public ODevice, public QWSServer::KeyboardFilter { protected: virtual void init ( ); virtual void initButtons ( ); public: virtual bool setSoftSuspend ( bool soft ); virtual bool suspend(); virtual bool setDisplayStatus( bool on ); virtual bool setDisplayBrightness ( int b ); virtual int displayBrightnessResolution ( ) const; virtual void alarmSound ( ); virtual QValueList <OLed> ledList ( ) const; virtual QValueList <OLedState> ledStateList ( OLed led ) const; virtual OLedState ledState ( OLed led ) const; virtual bool setLedState ( OLed led, OLedState st ); protected: virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); virtual void timerEvent ( QTimerEvent *te ); int m_power_timer; OLedState m_leds [1]; //FIXME check if really only one }; +class Ramses : public ODevice, public QWSServer::KeyboardFilter { +protected: + virtual void init ( ); + virtual void initButtons ( ); + +public: + virtual bool setSoftSuspend ( bool soft ); + + virtual bool setDisplayStatus( bool on ); + virtual bool setDisplayBrightness ( int b ); + virtual int displayBrightnessResolution ( ) const; + +protected: + virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); + virtual void timerEvent ( QTimerEvent *te ); + + int m_power_timer; +}; + struct i_button { uint model; Qt::Key code; char *utext; char *pix; char *fpressedservice; char *fpressedaction; char *fheldservice; char *fheldaction; } ipaq_buttons [] = { { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), "devicebuttons/ipaq_calendar", "datebook", "nextView()", "today", "raise()" }, { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), "devicebuttons/ipaq_contact", "addressbook", "raise()", "addressbook", "beamBusinessCard()" }, { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), "devicebuttons/ipaq_menu", "QPE/TaskBar", "toggleMenu()", "QPE/TaskBar", "toggleStartMenu()" }, { Model_iPAQ_H38xx | Model_iPAQ_H39xx, Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), "devicebuttons/ipaq_mail", "mail", "raise()", "mail", "newMail()" }, { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), "devicebuttons/ipaq_home", "QPE/Launcher", "home()", "buttonsettings", "raise()" }, { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), "devicebuttons/ipaq_record", "QPE/VMemo", "toggleRecord()", "sound", "raise()" }, }; struct z_button { Qt::Key code; char *utext; char *pix; char *fpressedservice; char *fpressedaction; char *fheldservice; char *fheldaction; } z_buttons [] = { { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), "devicebuttons/z_calendar", "datebook", "nextView()", "today", "raise()" }, { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), "devicebuttons/z_contact", "addressbook", "raise()", "addressbook", "beamBusinessCard()" }, { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), "devicebuttons/z_home", "QPE/Launcher", "home()", "buttonsettings", "raise()" }, { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), "devicebuttons/z_menu", "QPE/TaskBar", "toggleMenu()", "QPE/TaskBar", "toggleStartMenu()" }, { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), "devicebuttons/z_mail", "mail", "raise()", "mail", "newMail()" }, }; struct z_button z_buttons_c700 [] = { { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), "devicebuttons/z_calendar", "datebook", "nextView()", "today", "raise()" }, { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), "devicebuttons/z_contact", "addressbook", "raise()", "addressbook", "beamBusinessCard()" }, { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), "devicebuttons/z_home", "QPE/Launcher", "home()", "buttonsettings", "raise()" }, { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), "devicebuttons/z_menu", "QPE/TaskBar", "toggleMenu()", "QPE/TaskBar", "toggleStartMenu()" }, { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Display Rotate"), "", "QPE/Rotation", "flip()", "QPE/Rotation", "flip()" }, }; struct s_button { uint model; Qt::Key code; char *utext; char *pix; char *fpressedservice; char *fpressedaction; char *fheldservice; char *fheldaction; } simpad_buttons [] = { { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Lower+Up"), "devicebuttons/simpad_lower_up", "datebook", "nextView()", "today", "raise()" }, { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Lower+Down"), "devicebuttons/simpad_lower_down", "addressbook", "raise()", "addressbook", "beamBusinessCard()" }, { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Lower+Right"), "devicebuttons/simpad_lower_right", "QPE/TaskBar", "toggleMenu()", "QPE/TaskBar", "toggleStartMenu()" }, { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Lower+Left"), "devicebuttons/simpad_lower_left", "mail", "raise()", "mail", "newMail()" }, { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, Qt::Key_F5, QT_TRANSLATE_NOOP("Button", "Upper+Up"), "devicebuttons/simpad_upper_up", "QPE/Launcher", "home()", "buttonsettings", "raise()" }, { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, Qt::Key_F6, QT_TRANSLATE_NOOP("Button", "Upper+Down"), "devicebuttons/simpad_upper_down", "addressbook", "raise()", "addressbook", "beamBusinessCard()" }, { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Upper+Right"), "devicebuttons/simpad_upper_right", "QPE/TaskBar", "toggleMenu()", "QPE/TaskBar", "toggleStartMenu()" }, { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Upper+Left"), "devicebuttons/simpad_upper_left", "QPE/Rotation", "flip()", "QPE/Rotation", "flip()" }, /* { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), "devicebuttons/simpad_lower_upper", "QPE/Launcher", "home()", "buttonsettings", "raise()" }, { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), "devicebuttons/simpad_upper_lower", "QPE/Launcher", "home()", "buttonsettings", "raise()" }, */ }; +struct r_button { + uint model; + Qt::Key code; + char *utext; + char *pix; + char *fpressedservice; + char *fpressedaction; + char *fheldservice; + char *fheldaction; +} ramses_buttons [] = { + { Model_Ramses_MNCI, + Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), + "devicebuttons/simpad_menu", + "QPE/TaskBar", "toggleMenu()", + "QPE/TaskBar", "toggleStartMenu()" }, + { Model_Ramses_MNCI, + Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), + "devicebuttons/ipaq_home", + "QPE/Launcher", "home()", + "buttonsettings", "raise()" }, +}; + static QCString makeChannel ( const char *str ) { if ( str && !::strchr ( str, '/' )) return QCString ( "QPE/Application/" ) + str; else return str; } static inline bool isQWS() { return qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; } ODevice *ODevice::inst ( ) { static ODevice *dev = 0; if ( !dev ) { if ( QFile::exists ( "/proc/hal/model" )) dev = new iPAQ ( ); else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) dev = new Zaurus ( ); else if ( QFile::exists ( "/proc/ucb1x00" ) && QFile::exists ( "/proc/cs3" )) dev = new SIMpad ( ); + else if ( QFile::exists ( "/proc/sys/board/name" )) + dev = new Ramses ( ); else dev = new ODevice ( ); dev-> init ( ); } return dev; } /************************************************** * * common * **************************************************/ ODevice::ODevice ( ) { d = new ODeviceData; d-> m_modelstr = "Unknown"; d-> m_model = Model_Unknown; d-> m_vendorstr = "Unknown"; d-> m_vendor = Vendor_Unknown; d-> m_systemstr = "Unknown"; d-> m_system = System_Unknown; d-> m_sysverstr = "0.0"; d-> m_rotation = Rot0; d-> m_direction = CW; d-> m_holdtime = 1000; // 1000ms d-> m_buttons = 0; } void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) { if ( msg == "deviceButtonMappingChanged()" ) { reloadButtonMapping ( ); } } void ODevice::init ( ) { } /** * This method initialises the button mapping */ void ODevice::initButtons ( ) { if ( d-> m_buttons ) return; // Simulation uses iPAQ 3660 device buttons qDebug ( "init Buttons" ); d-> m_buttons = new QValueList <ODeviceButton>; for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { i_button *ib = ipaq_buttons + i; ODeviceButton b; if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { b. setKeycode ( ib-> code ); b. setUserText ( QObject::tr ( "Button", ib-> utext )); b. setPixmap ( Resource::loadPixmap ( ib-> pix )); b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); d-> m_buttons-> append ( b ); } } reloadButtonMapping ( ); QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); } ODevice::~ODevice ( ) { delete d; } bool ODevice::setSoftSuspend ( bool /*soft*/ ) { return false; } //#include <linux/apm_bios.h> #define APM_IOC_SUSPEND OD_IO( 'A', 2 ) /** * This method will try to suspend the device * It only works if the user is the QWS Server and the apm application * is installed. * It tries to suspend and then waits some time cause some distributions @@ -1751,96 +1794,250 @@ void SIMpad::alarmSound ( ) } snd. play ( ); while ( !snd. isFinished ( )) qApp-> processEvents ( ); if ( fd >= 0 ) { if ( vol_reset ) ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); ::close ( fd ); } #endif } bool SIMpad::suspend ( ) // Must override because SIMpad does NOT have apm { qDebug( "ODevice for SIMpad: suspend()" ); if ( !isQWS( ) ) // only qwsserver is allowed to suspend return false; bool res = false; struct timeval tvs, tvn; ::gettimeofday ( &tvs, 0 ); ::sync ( ); // flush fs caches res = ( ::system ( "echo > /proc/sys/pm/suspend" ) == 0 ); //TODO make better :) return res; } bool SIMpad::setSoftSuspend ( bool soft ) { qDebug( "ODevice for SIMpad: UNHANDLED setSoftSuspend(%s)", soft? "on" : "off" ); return false; } bool SIMpad::setDisplayStatus ( bool on ) { qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" ); bool res = false; int fd; QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :) if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { res = ( ::system( (const char*) cmdline ) == 0 ); ::close ( fd ); } return res; } bool SIMpad::setDisplayBrightness ( int bright ) { qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright ); bool res = false; int fd; if ( bright > 255 ) bright = 255; if ( bright < 0 ) bright = 0; if (( fd = ::open ( SIMPAD_BACKLIGHT_CONTROL, O_WRONLY )) >= 0 ) { int value = 255 - bright; const int mask = SIMPAD_BACKLIGHT_MASK; value = value << 8; value += mask; char writeCommand[100]; const int count = sprintf( writeCommand, "0x%x\n", value ); res = ( ::write ( fd, writeCommand, count ) != -1 ); ::close ( fd ); } return res; } int SIMpad::displayBrightnessResolution ( ) const { switch ( model ( )) { case Model_SIMpad_CL4: case Model_SIMpad_SL4: case Model_SIMpad_SLC: case Model_SIMpad_TSinus: return 255; //TODO find out if this is save default: return 2; } } +/************************************************** + * + * Ramses + * + **************************************************/ + +void Ramses::init ( ) +{ + d->m_vendorstr = "M und N"; + d->m_vendor = Vendor_MundN; + + QFile f( "/proc/sys/board/ramses" ); + + d->m_modelstr = "Ramses"; + d->m_model = Model_Ramses_MNCI; + + d->m_rotation = Rot180; + d->m_direction = CCW; + d->m_holdtime = 1000; + + f.setName( "/etc/oz_version" ); + + if ( f.open( IO_ReadOnly )) { + d->m_systemstr = "OpenEmbedded/Ramses"; + d->m_system = System_OpenZaurus; + + QTextStream ts ( &f ); + ts.setDevice ( &f ); + d->m_sysverstr = ts.readLine ( ); + f.close ( ); + } + + m_power_timer = 0; + +} + +void Ramses::initButtons ( ) +{ + if ( d->m_buttons ) + return; + + if ( isQWS( ) ) + QWSServer::setKeyboardFilter ( this ); + + d->m_buttons = new QValueList <ODeviceButton>; + + for ( uint i = 0; i < ( sizeof( ramses_buttons ) / sizeof( s_button )); i++ ) { + r_button *rb = ramses_buttons + i; + ODeviceButton b; + + if (( rb->model & d->m_model ) == d->m_model ) { + b.setKeycode( rb->code ); + b.setUserText( QObject::tr ( "Button", rb->utext )); + b.setPixmap( Resource::loadPixmap ( rb->pix )); + b.setFactoryPresetPressedAction( OQCopMessage ( makeChannel ( rb->fpressedservice ), rb->fpressedaction )); + b.setFactoryPresetHeldAction( OQCopMessage ( makeChannel ( rb->fheldservice ), rb->fheldaction )); + + d->m_buttons->append( b ); + } + } + reloadButtonMapping(); + + QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); + connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); +} + +bool Ramses::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) +{ + //TODO + return false; +} + +void Ramses::timerEvent ( QTimerEvent * ) +{ + killTimer ( m_power_timer ); + m_power_timer = 0; + QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); + QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); +} + + +bool Ramses::setSoftSuspend ( bool soft ) +{ + bool res = false; + int fd; + + if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || + (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { + + int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources + + if ( sources >= 0 ) { + if ( soft ) + sources &= ~APM_EVT_POWER_BUTTON; + else + sources |= APM_EVT_POWER_BUTTON; + + if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources + res = true; + else + perror ( "APM_IOCGEVTSRC" ); + } + else + perror ( "APM_IOCGEVTSRC" ); + + ::close ( fd ); + } + else + perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); + + return res; +} + +/** + * This sets the display on or off + */ +bool Ramses::setDisplayStatus ( bool on ) +{ + bool res = false; + int fd; + + if (( fd = ::open ( "/dev/fb/0", O_RDWR )) >= 0 ) { + res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); + ::close ( fd ); + } + return res; +} + + +bool Ramses::setDisplayBrightness ( int bright ) +{ + qDebug( "ODevice for Ramses: setDisplayBrightness( %d )", bright ); + bool res = false; + int fd; + + if ( bright > 255 ) + bright = 100; + if ( bright < 0 ) + bright = 0; + + if (( fd = ::open ( "/proc/sys/board/pwm0", O_WRONLY )) >= 0 ) { + char writeCommand[100]; + const int count = sprintf( writeCommand, "%d\n", bright); + res = ( ::write ( fd, writeCommand, count ) != -1 ); + ::close ( fd ); + } + return res; +} + + +int Ramses::displayBrightnessResolution ( ) const +{ + return 100; +} |