summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_ipaq.cpp53
-rw-r--r--libopie2/opiecore/device/odevice_mypal.cpp55
2 files changed, 79 insertions, 29 deletions
diff --git a/libopie2/opiecore/device/odevice_ipaq.cpp b/libopie2/opiecore/device/odevice_ipaq.cpp
index e6e3145..63b60a7 100644
--- a/libopie2/opiecore/device/odevice_ipaq.cpp
+++ b/libopie2/opiecore/device/odevice_ipaq.cpp
@@ -1,81 +1,82 @@
/*
                This file is part of the Opie Project
=. (C) 2002-2005 The Opie Team <opie-devel@handhelds.org>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; version 2 of the License.
     ._= =}       :
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "odevice_ipaq.h"
/* QT */
#include <qapplication.h>
+#include <qdir.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qwindowsystem_qws.h>
/* OPIE */
#include <qpe/config.h>
#include <qpe/sound.h>
#include <qpe/qcopenvelope_qws.h>
#include <opie2/okeyfilter.h>
#include <opie2/oresource.h>
/* STD */
#include <fcntl.h>
#include <math.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <unistd.h>
#ifndef QT_NO_SOUND
#include <linux/soundcard.h>
#endif
using namespace Opie::Core;
using namespace Opie::Core::Internal;
/* KERNEL */
#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
#define OD_IO(type,number) OD_IOC(0,type,number,0)
#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size))
#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size))
#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size))
typedef struct {
unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */
unsigned char TotalTime; /* Units of 5 seconds */
unsigned char OnTime; /* units of 100m/s */
unsigned char OffTime; /* units of 100m/s */
} LED_IN;
typedef struct {
unsigned char mode;
unsigned char pwr;
unsigned char brightness;
} FLITE_IN;
@@ -334,148 +335,184 @@ bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, b
break;
}
}
if ( newkeycode != keycode ) {
if ( newkeycode != Key_unknown )
QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
return true;
}
else
return false;
}
void iPAQ::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 );
}
void iPAQ::playAlarmSound()
{
#ifndef QT_NO_SOUND
static Sound snd ( "alarm" );
if(!snd.isFinished())
return;
changeMixerForAlarm(0, "/dev/sound/mixer", &snd );
snd. play();
#endif
}
bool iPAQ::setDisplayBrightness ( int bright )
{
bool res = false;
int fd;
if ( bright > 255 )
bright = 255;
if ( bright < 0 )
bright = 0;
QString cmdline;
switch ( model()) {
case Model_iPAQ_H191x:
- if ( !bright )
- cmdline = QString::fromLatin1( "echo 4 > /sys/class/backlight/pxafb/power");
- else
- cmdline = QString::fromLatin1( "echo 0 > /sys/class/backlight/pxafb/power; echo %1 > /sys/class/backlight/pxafb/brightness" ).arg( bright );
- // No Global::shellQuote as we gurantee it to be sane
- res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
+ {
+ QDir sysClass( "/sys/class/backlight/pxafb/" );
+ sysClass.setFilter(QDir::Dirs);
+ int fd;
+ if ( sysClass.exists() ) {
+ QString sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/power" );
+ fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
+ if ( fd ) {
+ char buf[10];
+ buf[0] = bright ? 0 : 4;
+ buf[1] = '\0';
+ res = ( ::write( fd, &buf[0], 2 ) == 0 );
+ ::close( fd );
+ }
+ sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/brightness" );
+ fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
+ if ( fd ) {
+ char buf[100];
+ int len = ::snprintf( &buf[0], sizeof buf, "%d", bright );
+ res = ( ::write( fd, &buf[0], len ) == 0 );
+ ::close( fd );
+ }
+ }
+ }
break;
case Model_iPAQ_HX4700:
cmdline = QString::fromLatin1( "echo %1 > /sys/class/backlight/w100fb/brightness" ).arg( bright );
// No Global::shellQuote as we gurantee it to be sane
res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
break;
default:
if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
FLITE_IN bl;
bl. mode = 1;
bl. pwr = bright ? 1 : 0;
bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255;
res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 );
::close ( fd );
}
}
return res;
}
int iPAQ::displayBrightnessResolution() const
{
switch ( model()) {
case Model_iPAQ_H31xx:
case Model_iPAQ_H36xx:
case Model_iPAQ_H37xx:
return 128; // really 256, but >128 could damage the LCD
case Model_iPAQ_H38xx:
case Model_iPAQ_H39xx:
return 64;
case Model_iPAQ_H5xxx:
case Model_iPAQ_HX4700:
return 255;
case Model_iPAQ_H191x:
return 7;
case Model_iPAQ_H1940:
return 44;
default:
return 2;
}
}
bool iPAQ::setDisplayStatus ( bool on )
{
bool res = false;
QString cmdline;
if ( model() == Model_iPAQ_H191x ) {
- 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" );
+ QDir sysClass( "/sys/class/lcd/pxafb/" );
+ sysClass.setFilter(QDir::Dirs);
+ if ( sysClass.exists() ) {
+ QString sysClassPath = sysClass.absFilePath( "/sys/class/lcd/pxafb/power" );
+ int fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
+ if ( fd ) {
+ char buf[10];
+ buf[0] = on ? 0 : 4;
+ buf[1] = '\0';
+ res = ( ::write( fd, &buf[0], 2 ) == 0 );
+ ::close( fd );
+ }
+ }
+ return res;
} else {
return OAbstractMobileDevice::setDisplayStatus(on);
}
res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
return res;
}
bool iPAQ::hasLightSensor() const
{
- return true;
+ switch (model()) {
+ case Model_iPAQ_H191x:
+ return false;
+ default:
+ return true;
+ }
}
int iPAQ::readLightSensor()
{
int fd;
int val = -1;
if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) {
char buffer [8];
if ( ::read ( fd, buffer, 5 ) == 5 ) {
char *endptr;
buffer [4] = 0;
val = ::strtol ( buffer + 2, &endptr, 16 );
if ( *endptr != 0 )
val = -1;
}
::close ( fd );
}
return val;
}
int iPAQ::lightSensorResolution() const
{
return 256;
}
diff --git a/libopie2/opiecore/device/odevice_mypal.cpp b/libopie2/opiecore/device/odevice_mypal.cpp
index 7e1245a..7eb8d1d 100644
--- a/libopie2/opiecore/device/odevice_mypal.cpp
+++ b/libopie2/opiecore/device/odevice_mypal.cpp
@@ -1,81 +1,82 @@
/*
                This file is part of the Opie Project
=. (C) 2002-2005 The Opie Team <opie-devel@handhelds.org>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; version 2 of the License.
     ._= =}       :
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "odevice_mypal.h"
/* QT */
#include <qapplication.h>
+#include <qdir.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qwindowsystem_qws.h>
/* OPIE */
#include <qpe/config.h>
#include <qpe/sound.h>
#include <qpe/qcopenvelope_qws.h>
#include <opie2/okeyfilter.h>
#include <opie2/oresource.h>
/* STD */
#include <fcntl.h>
#include <math.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <unistd.h>
#ifndef QT_NO_SOUND
#include <linux/soundcard.h>
#endif
using namespace Opie::Core;
using namespace Opie::Core::Internal;
struct m_button mypal_buttons [] = {
{ Model_MyPal_716,
Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
"devicebuttons/ipaq_calendar",
"datebook", "nextView()",
"today", "raise()" },
{ Model_MyPal_716,
Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
"devicebuttons/ipaq_contact",
"addressbook", "raise()",
"addressbook", "beamBusinessCard()" },
{ Model_MyPal_716,
Qt::Key_F8, QT_TRANSLATE_NOOP("Button", "Mail Button"),
"devicebuttons/ipaq_mail",
"opiemail", "raise()",
"opiemail", "newMail()" },
{ Model_MyPal_716,
Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
"devicebuttons/ipaq_home",
"QPE/Launcher", "home()",
@@ -161,92 +162,104 @@ bool MyPal::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress,
m_power_timer = 0;
QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false );
QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false );
}
newkeycode = Key_unknown;
break;
}
}
if ( newkeycode != keycode ) {
if ( newkeycode != Key_unknown )
QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
return true;
}
else
return false;
}
void MyPal::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 );
}
void MyPal::playAlarmSound()
{
#ifndef QT_NO_SOUND
static Sound snd ( "alarm" );
if(!snd.isFinished())
return;
changeMixerForAlarm(0, "/dev/sound/mixer", &snd );
snd. play();
#endif
}
bool MyPal::setDisplayBrightness ( int bright )
{
bool res = false;
if ( bright > 255 )
bright = 255;
if ( bright < 0 )
bright = 0;
- QString cmdline;
-
- switch ( model()) {
- case Model_MyPal_716:
- if ( !bright )
- cmdline = QString::fromLatin1( "echo 4 > /sys/class/backlight/pxafb/power");
- else
- cmdline = QString::fromLatin1( "echo 0 > /sys/class/backlight/pxafb/power; echo %1 > /sys/class/backlight/pxafb/brightness" ).arg( bright );
- // No Global::shellQuote as we gurantee it to be sane
- res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
- break;
- default:
- res = OAbstractMobileDevice::setDisplayBrightness(bright);
+ QDir sysClass( "/sys/class/backlight/pxafb/" );
+ sysClass.setFilter(QDir::Dirs);
+ int fd;
+ if ( sysClass.exists() ) {
+ QString sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/power" );
+ fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
+ if ( fd ) {
+ char buf[10];
+ buf[0] = bright ? 0 : 4;
+ buf[1] = '\0';
+ res = ( ::write( fd, &buf[0], 2 ) == 0 );
+ ::close( fd );
+ }
+ sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/brightness" );
+ fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
+ if ( fd ) {
+ char buf[100];
+ int len = ::snprintf( &buf[0], sizeof buf, "%d", bright );
+ res = ( ::write( fd, &buf[0], len ) == 0 );
+ ::close( fd );
+ }
}
return res;
}
int MyPal::displayBrightnessResolution() const
{
switch ( model()) {
case Model_MyPal_716:
return 7;
default:
return OAbstractMobileDevice::displayBrightnessResolution();
}
}
bool MyPal::setDisplayStatus ( bool on )
{
bool res = false;
- QString cmdline;
-
- if ( model() == Model_MyPal_716 ) {
- 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" );
- } else {
- return OAbstractMobileDevice::setDisplayStatus(on);
+ QDir sysClass( "/sys/class/lcd/" );
+ sysClass.setFilter(QDir::Dirs);
+ if ( sysClass.exists() ) {
+ QString sysClassPath = sysClass.absFilePath( "/sys/class/lcd/pxafb/power" );
+ int fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
+ if ( fd ) {
+ char buf[10];
+ buf[0] = on ? 0 : 4;
+ buf[1] = '\0';
+ res = ( ::write( fd, &buf[0], 2 ) == 0 );
+ ::close( fd );
+ }
}
- res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
-
return res;
}