Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

odevice_mypal.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003              =.              (C) 2002-2005 The Opie Team <opie-devel@handhelds.org>
00004             .=l.
00005            .>+-=
00006  _;:,     .>    :=|.         This program is free software; you can
00007 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00008 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00009 .="- .-=="i,     .._         License as published by the Free Software
00010  - .   .-<_>     .<>         Foundation; version 2 of the License.
00011      ._= =}       :
00012     .%`+i>       _;_.
00013     .i_,=:_.      -<s.       This program is distributed in the hope that
00014      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00015     : ..    .:,     . . .    without even the implied warranty of
00016     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00017   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00018 ..}^=.=       =       ;      Library General Public License for more
00019 ++=   -.     .`     .:       details.
00020  :     =  ...= . :.=-
00021  -.   .:....=;==+<;          You should have received a copy of the GNU
00022   -_. . .   )=.  =           Library General Public License along with
00023     --        :-=`           this library; see the file COPYING.LIB.
00024                              If not, write to the Free Software Foundation,
00025                              Inc., 59 Temple Place - Suite 330,
00026                              Boston, MA 02111-1307, USA.
00027 
00028 */
00029 
00030 #include "odevice_mypal.h"
00031 
00032 /* QT */
00033 #include <qapplication.h>
00034 #include <qfile.h>
00035 #include <qtextstream.h>
00036 #include <qwindowsystem_qws.h>
00037 
00038 /* OPIE */
00039 #include <qpe/config.h>
00040 #include <qpe/sound.h>
00041 #include <qpe/qcopenvelope_qws.h>
00042 
00043 #include <opie2/okeyfilter.h>
00044 #include <opie2/oresource.h>
00045 
00046 /* STD */
00047 #include <fcntl.h>
00048 #include <math.h>
00049 #include <stdlib.h>
00050 #include <signal.h>
00051 #include <sys/ioctl.h>
00052 #include <sys/time.h>
00053 #include <unistd.h>
00054 #ifndef QT_NO_SOUND
00055 #include <linux/soundcard.h>
00056 #endif
00057 
00058 
00059 using namespace Opie::Core;
00060 using namespace Opie::Core::Internal;
00061 
00062 struct m_button mypal_buttons [] = {
00063     { Model_MyPal_716,
00064     Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
00065     "devicebuttons/ipaq_calendar",
00066     "datebook", "nextView()",
00067     "today", "raise()" },
00068     { Model_MyPal_716,
00069     Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
00070     "devicebuttons/ipaq_contact",
00071     "addressbook", "raise()",
00072     "addressbook", "beamBusinessCard()" },
00073     { Model_MyPal_716,
00074     Qt::Key_F8, QT_TRANSLATE_NOOP("Button", "Mail Button"),
00075     "devicebuttons/ipaq_mail",
00076     "opiemail", "raise()",
00077     "opiemail", "newMail()" },
00078     { Model_MyPal_716,
00079     Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
00080     "devicebuttons/ipaq_home",
00081     "QPE/Launcher", "home()",
00082     "buttonsettings", "raise()" },
00083     { Model_MyPal_716,
00084     Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Record Button"),
00085     "devicebuttons/ipaq_record",
00086     "QPE/VMemo", "toggleRecord()",
00087     "sound", "raise()" },
00088 };
00089 
00090 void MyPal::init(const QString& model)
00091 {
00092     d->m_vendorstr = "Asus";
00093     d->m_vendor = Vendor_Asus;
00094 
00095     d->m_modelstr = model.mid(model.findRev('A'));
00096     if ( d->m_modelstr == "A716" )
00097         d->m_model = Model_MyPal_716;
00098     else
00099         d->m_model = Model_Unknown;
00100 
00101     d->m_rotation = Rot0;
00102 
00103     m_power_timer = 0;
00104 }
00105 
00106 void MyPal::initButtons()
00107 {
00108     if ( d->m_buttons )
00109         return;
00110 
00111     if ( isQWS( ) ) {
00112         addPreHandler(this);
00113     }
00114 
00115     d->m_buttons = new QValueList <ODeviceButton>;
00116 
00117     for ( uint i = 0; i < ( sizeof( mypal_buttons ) / sizeof( m_button )); i++ ) {
00118         m_button *mb = mypal_buttons + i;
00119         ODeviceButton b;
00120 
00121         if (( mb->model & d->m_model ) == d->m_model ) {
00122             b. setKeycode ( mb->code );
00123             b. setUserText ( QObject::tr ( "Button", mb->utext ));
00124             b. setPixmap ( OResource::loadPixmap ( mb->pix ));
00125             b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( mb->fpressedservice ), mb->fpressedaction ));
00126             b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( mb->fheldservice ), mb->fheldaction ));
00127 
00128             d->m_buttons->append ( b );
00129         }
00130     }
00131     reloadButtonMapping();
00132 }
00133 
00134 bool MyPal::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
00135 {
00136     int newkeycode = keycode;
00137 
00138     switch ( keycode ) {
00139         case Key_Left :
00140         case Key_Right:
00141         case Key_Up   :
00142         case Key_Down : {
00143             // Rotate the cursor keys by 270
00144             // keycode - Key_Left = position of the button starting from left clockwise
00145             // add the rotation to it and modolo. No we've the original offset
00146             // add the offset to the Key_Left key
00147             if ( d->m_model == Model_MyPal_716 )
00148                 newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4;
00149             break;
00150         }
00151 
00152         // map Power Button short/long press to F34/F35
00153         case Key_SysReq: {
00154             if ( isPress ) {
00155                 if ( m_power_timer )
00156                     killTimer ( m_power_timer );
00157                 m_power_timer = startTimer ( 500 );
00158             }
00159             else if ( m_power_timer ) {
00160                 killTimer ( m_power_timer );
00161                 m_power_timer = 0;
00162                 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false );
00163                 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false );
00164             }
00165             newkeycode = Key_unknown;
00166             break;
00167         }
00168     }
00169 
00170     if ( newkeycode != keycode ) {
00171         if ( newkeycode != Key_unknown )
00172             QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
00173         return true;
00174     }
00175     else
00176         return false;
00177 }
00178 
00179 void MyPal::timerEvent ( QTimerEvent * )
00180 {
00181     killTimer ( m_power_timer );
00182     m_power_timer = 0;
00183     QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false );
00184     QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false );
00185 }
00186 
00187 
00188 void MyPal::playAlarmSound()
00189 {
00190 #ifndef QT_NO_SOUND
00191     static Sound snd ( "alarm" );
00192     if(!snd.isFinished())
00193         return;
00194 
00195     changeMixerForAlarm(0, "/dev/sound/mixer", &snd );
00196     snd. play();
00197 #endif
00198 }
00199 
00200 bool MyPal::setDisplayBrightness ( int bright )
00201 {
00202     bool res = false;
00203 
00204     if ( bright > 255 )
00205         bright = 255;
00206     if ( bright < 0 )
00207         bright = 0;
00208 
00209     QString cmdline;
00210 
00211     switch ( model()) {
00212     case Model_MyPal_716:
00213         if ( !bright )
00214             cmdline = QString::fromLatin1( "echo 4 > /sys/class/backlight/pxafb/power");
00215         else
00216             cmdline = QString::fromLatin1( "echo 0 > /sys/class/backlight/pxafb/power; echo %1 > /sys/class/backlight/pxafb/brightness" ).arg( bright );
00217         // No Global::shellQuote as we gurantee it to be sane
00218         res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
00219         break; 
00220     default:
00221         res = OAbstractMobileDevice::setDisplayBrightness(bright);
00222     }
00223 
00224     return res;
00225 }
00226 
00227 int MyPal::displayBrightnessResolution() const
00228 {
00229     switch ( model()) {
00230         case Model_MyPal_716:
00231             return 7;
00232         default:
00233             return OAbstractMobileDevice::displayBrightnessResolution();
00234     }
00235 }
00236 
00237 bool MyPal::setDisplayStatus ( bool on )
00238 {
00239     bool res = false;
00240 
00241     QString cmdline;
00242 
00243     if ( model() == Model_MyPal_716 ) {
00244         cmdline = QString::fromLatin1( "echo %1 > /sys/class/lcd/pxafb/power; echo %2 > /sys/class/backlight/pxafb/power").arg( on ? "0" : "4" ).arg( on ? "0" : "4" );
00245     } else {
00246         return OAbstractMobileDevice::setDisplayStatus(on);
00247     }
00248 
00249     res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
00250 
00251     return res;
00252 }

Generated on Sat Nov 5 16:16:06 2005 for OPIE by  doxygen 1.4.2