summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/device/odevice_zaurus.cpp
Side-by-side diff
Diffstat (limited to 'libopie2/opiecore/device/odevice_zaurus.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_zaurus.cpp99
1 files changed, 34 insertions, 65 deletions
diff --git a/libopie2/opiecore/device/odevice_zaurus.cpp b/libopie2/opiecore/device/odevice_zaurus.cpp
index 47682bb..127fee9 100644
--- a/libopie2/opiecore/device/odevice_zaurus.cpp
+++ b/libopie2/opiecore/device/odevice_zaurus.cpp
@@ -1,72 +1,72 @@
/*
- This file is part of the Opie Project
- Copyright (C) The Opie Team <opie-devel@handhelds.org>
+                 This file is part of the Opie Project
+              Copyright (C) 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; either version 2 of the License,
- ._= =} : or (at your option) any later version.
- .%`+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.
+           .>+-=
+ _;:,     .>    :=|. 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; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+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_zaurus.h"
/* QT */
#include <qapplication.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qwindowsystem_qws.h>
/* OPIE */
#include <qpe/config.h>
#include <qpe/resource.h>
#include <qpe/sound.h>
#include <qpe/qcopenvelope_qws.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 z_button 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"),
@@ -138,98 +138,96 @@ void Zaurus::init(const QString& cpu_info)
FILE *uname = popen("uname -r", "r");
QFile f;
QString line;
if ( f.open(IO_ReadOnly, uname) ) {
QTextStream ts ( &f );
line = ts. readLine();
int loc = line. find ( "embedix" );
if ( loc != -1 )
m_embedix = true;
else
m_embedix = false;
f.close();
}
pclose(uname);
}
// check the Zaurus model
QString model;
int loc = cpu_info.find( ":" );
if ( loc != -1 )
model = cpu_info.mid( loc+2 ).simplifyWhiteSpace();
else
model = cpu_info;
if ( model == "SHARP Corgi" ) {
d->m_model = Model_Zaurus_SLC7x0;
d->m_modelstr = "Zaurus SL-C700";
} else if ( model == "SHARP Shepherd" ) {
d->m_model = Model_Zaurus_SLC7x0;
d->m_modelstr = "Zaurus SL-C750";
} else if ( model == "SHARP Husky" ) {
d->m_model = Model_Zaurus_SLC7x0;
d->m_modelstr = "Zaurus SL-C760";
} else if ( model == "SHARP Poodle" ) {
d->m_model = Model_Zaurus_SLB600;
d->m_modelstr = "Zaurus SL-B500 or SL-5600";
} else if ( model == "Sharp-Collie" || model == "Collie" ) {
d->m_model = Model_Zaurus_SL5500;
d->m_modelstr = "Zaurus SL-5500 or SL-5000d";
} else if ( model == "SHARP Tosa" ) {
d->m_model = Model_Zaurus_SL6000;
d->m_modelstr = "Zaurus SL-6000";
} else {
d->m_model = Model_Zaurus_SL5500;
d->m_modelstr = "Unkown Zaurus";
}
// set initial rotation
-
- bool flipstate = false;
switch ( d->m_model ) {
case Model_Zaurus_SL6000:
case Model_Zaurus_SLA300:
d->m_rotation = Rot0;
break;
case Model_Zaurus_SLC7x0:
d->m_rotation = rotation();
d->m_direction = direction();
break;
case Model_Zaurus_SLB600:
case Model_Zaurus_SL5500:
case Model_Zaurus_SL5000:
default:
d->m_rotation = Rot270;
break;
}
m_leds [0] = Led_Off;
}
void Zaurus::initButtons()
{
if ( d->m_buttons )
return;
d->m_buttons = new QValueList <ODeviceButton>;
struct z_button * pz_buttons;
int buttoncount;
switch ( d->m_model ) {
case Model_Zaurus_SLC7x0:
pz_buttons = z_buttons_c700;
buttoncount = ARRAY_SIZE(z_buttons_c700);
break;
default:
pz_buttons = z_buttons;
buttoncount = ARRAY_SIZE(z_buttons);
break;
}
for ( int i = 0; i < buttoncount; i++ ) {
struct z_button *zb = pz_buttons + i;
ODeviceButton b;
b. setKeycode ( zb->code );
b. setUserText ( QObject::tr ( "Button", zb->utext ));
b. setPixmap ( Resource::loadPixmap ( zb->pix ));
b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb->fpressedservice ),
zb->fpressedaction ));
@@ -273,154 +271,125 @@ void Zaurus::initButtons()
#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5)
//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
//#define SHARP_BUZ_KEYSOUND 2 /* key sound */
//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */
//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */
//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */
//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */
//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */
//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */
//#define SHARP_PDA_APPSTART 9 /* application start */
//#define SHARP_PDA_APPQUIT 10 /* application ends */
//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */
//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */
//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */
//
#define SHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1)
#define SHARP_IOCTL_GET_ROTATION 0x413c
typedef struct sharp_led_status {
int which; /* select which LED status is wanted. */
int status; /* set new led status if you call SHARP_LED_SETSTATUS */
} sharp_led_status;
#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */
#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */
#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */
#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */
// #include <asm/sharp_apm.h> // including kernel headers is evil ...
#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int )
#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int )
#define APM_EVT_POWER_BUTTON (1 << 0)
#define FL_IOCTL_STEP_CONTRAST 100
void Zaurus::buzzer ( int sound )
{
#ifndef QT_NO_SOUND
- QString soundname;
+ Sound *snd = 0;
// Not all devices have real sound
if ( d->m_model == Model_Zaurus_SLC7x0
|| d->m_model == Model_Zaurus_SLB600 ){
switch ( sound ){
- case SHARP_BUZ_SCHEDULE_ALARM:
- soundname = "alarm";
- break;
case SHARP_BUZ_TOUCHSOUND:
- soundname = "touchsound";
+ static Sound touch_sound("touchsound");
+ snd = &touch_sound;
break;
case SHARP_BUZ_KEYSOUND:
- soundname = "keysound";
+ static Sound key_sound( "keysound" );
+ snd = &key_sound;
break;
+ case SHARP_BUZ_SCHEDULE_ALARM:
default:
- soundname = "alarm";
-
+ static Sound alarm_sound("alarm");
+ snd = &alarm_sound;
+ break;
}
}
// If a soundname is defined, we expect that this device has
// sound capabilities.. Otherwise we expect to have the buzzer
// device..
- if ( !soundname.isEmpty() ){
- int fd;
- int vol;
- bool vol_reset = false;
-
- Sound snd ( soundname );
-
- if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) {
- if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
- Config cfg ( "qpe" );
- cfg. setGroup ( "Volume" );
-
- int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
- if ( volalarm < 0 )
- volalarm = 0;
- else if ( volalarm > 100 )
- volalarm = 100;
- volalarm |= ( volalarm << 8 );
-
- if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
- vol_reset = true;
- }
- }
-
- snd. play();
- while ( !snd. isFinished())
- qApp->processEvents();
-
- if ( fd >= 0 ) {
- if ( vol_reset )
- ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
- ::close ( fd );
- }
+ if ( snd ){
+ changeMixerForAlarm( 0, "/dev/sound/mixer", snd );
+ snd-> play();
} else {
int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK );
if ( fd >= 0 ) {
::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound );
::close ( fd );
}
}
#endif
}
void Zaurus::playAlarmSound()
{
buzzer ( SHARP_BUZ_SCHEDULE_ALARM );
}
void Zaurus::playTouchSound()
{
buzzer ( SHARP_BUZ_TOUCHSOUND );
}
void Zaurus::playKeySound()
{
buzzer ( SHARP_BUZ_KEYSOUND );
}
QValueList <OLed> Zaurus::ledList() const
{
QValueList <OLed> vl;
vl << Led_Mail;
return vl;
}
QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const
{
QValueList <OLedState> vl;
if ( l == Led_Mail )
vl << Led_Off << Led_On << Led_BlinkSlow;
return vl;
}
OLedState Zaurus::ledState ( OLed which ) const
{
if ( which == Led_Mail )
@@ -469,97 +438,97 @@ bool Zaurus::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;
}
bool Zaurus::setDisplayBrightness ( int bright )
{
//qDebug( "Zaurus::setDisplayBrightness( %d )", bright );
bool res = false;
int fd;
if ( bright > 255 ) bright = 255;
if ( bright < 0 ) bright = 0;
if ( m_embedix )
{
if ( d->m_model == Model_Zaurus_SLC7x0 )
{
//qDebug( "using special treatment for devices with the corgi backlight interface" );
// special treatment for devices with the corgi backlight interface
if (( fd = ::open ( "/proc/driver/fl/corgi-bl", O_WRONLY )) >= 0 )
{
- int value = ( bright == 1 ) ? 1 : bright * ( 17.0 / 255.0 );
+ int value = ( bright == 1 ) ? 1 : static_cast<int>( bright * ( 17.0 / 255.0 ) );
char writeCommand[100];
const int count = sprintf( writeCommand, "0x%x\n", value );
res = ( ::write ( fd, writeCommand, count ) != -1 );
::close ( fd );
}
return res;
}
else
{
// standard treatment for devices with the dumb embedix frontlight interface
if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) {
int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus
if ( bright && !bl )
bl = 1;
res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 );
::close ( fd );
}
}
}
else
{
// special treatment for the OpenZaurus unified interface
#define FB_BACKLIGHT_SET_BRIGHTNESS _IOW('F', 1, u_int) /* set brightness */
if (( fd = ::open ( "/dev/fb0", O_WRONLY )) >= 0 ) {
res = ( ::ioctl ( fd , FB_BACKLIGHT_SET_BRIGHTNESS, bright ) == 0 );
::close ( fd );
}
}
return res;
}
bool Zaurus::suspend()
{
qDebug("ODevice::suspend");
if ( !isQWS( ) ) // only qwsserver is allowed to suspend
return false;
if ( d->m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices
return false;
bool res = false;
ODevice::sendSuspendmsg();
struct timeval tvs, tvn;
::gettimeofday ( &tvs, 0 );
::sync(); // flush fs caches
res = ( ::system ( "apm --suspend" ) == 0 );