summaryrefslogtreecommitdiff
path: root/libopie2
authorzecke <zecke>2004-08-25 21:51:13 (UTC)
committer zecke <zecke>2004-08-25 21:51:13 (UTC)
commitdf3e4c8b13c16aeb96e70dbaa2d409f83eed988e (patch) (unidiff)
tree59b12028c6e8a53b99f1686278b6e9fdc57ab18e /libopie2
parente4811064703ad34f42f15c3044cd8f63c0e7583c (diff)
downloadopie-df3e4c8b13c16aeb96e70dbaa2d409f83eed988e.zip
opie-df3e4c8b13c16aeb96e70dbaa2d409f83eed988e.tar.gz
opie-df3e4c8b13c16aeb96e70dbaa2d409f83eed988e.tar.bz2
-Have a common implementation for reading the config value
and setting the Mixer. The mixer, sound and path is configurable -Restore the Opie HEADER (who is guilty? probably me) -Fix warnings -Port Zaurus,Simpad,Ipaq to configure the mixer
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice.cpp57
-rw-r--r--libopie2/opiecore/device/odevice.h55
-rw-r--r--libopie2/opiecore/device/odevice_ipaq.cpp71
-rw-r--r--libopie2/opiecore/device/odevice_simpad.cpp47
-rw-r--r--libopie2/opiecore/device/odevice_simpad.h2
-rw-r--r--libopie2/opiecore/device/odevice_yopy.cpp2
-rw-r--r--libopie2/opiecore/device/odevice_zaurus.cpp99
7 files changed, 158 insertions, 175 deletions
diff --git a/libopie2/opiecore/device/odevice.cpp b/libopie2/opiecore/device/odevice.cpp
index b58f9eb..26c6dca 100644
--- a/libopie2/opiecore/device/odevice.cpp
+++ b/libopie2/opiecore/device/odevice.cpp
@@ -24,48 +24,49 @@
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "odevice_ipaq.h" 30#include "odevice_ipaq.h"
31#include "odevice_jornada.h" 31#include "odevice_jornada.h"
32#include "odevice_ramses.h" 32#include "odevice_ramses.h"
33#include "odevice_simpad.h" 33#include "odevice_simpad.h"
34#include "odevice_yopy.h" 34#include "odevice_yopy.h"
35#include "odevice_zaurus.h" 35#include "odevice_zaurus.h"
36 36
37/* QT */ 37/* QT */
38#include <qapplication.h> 38#include <qapplication.h>
39#include <qfile.h> 39#include <qfile.h>
40#include <qtextstream.h> 40#include <qtextstream.h>
41#include <qwindowsystem_qws.h> 41#include <qwindowsystem_qws.h>
42 42
43/* OPIE */ 43/* OPIE */
44#include <qpe/config.h> 44#include <qpe/config.h>
45#include <qpe/resource.h> 45#include <qpe/resource.h>
46#include <qpe/sound.h> 46#include <qpe/sound.h>
47#include <qpe/qcopenvelope_qws.h> 47#include <qpe/qcopenvelope_qws.h>
48#include <qpe/sound.h>
48#include <opie2/okeyfilter.h> 49#include <opie2/okeyfilter.h>
49 50
50/* STD */ 51/* STD */
51#include <fcntl.h> 52#include <fcntl.h>
52#include <math.h> 53#include <math.h>
53#include <stdlib.h> 54#include <stdlib.h>
54#include <signal.h> 55#include <signal.h>
55#include <sys/ioctl.h> 56#include <sys/ioctl.h>
56#include <sys/time.h> 57#include <sys/time.h>
57#include <unistd.h> 58#include <unistd.h>
58#ifndef QT_NO_SOUND 59#ifndef QT_NO_SOUND
59#include <linux/soundcard.h> 60#include <linux/soundcard.h>
60#endif 61#endif
61 62
62namespace Opie { 63namespace Opie {
63namespace Core { 64namespace Core {
64 65
65static const char* PATH_PROC_CPUINFO = "/proc/cpuinfo"; 66static const char* PATH_PROC_CPUINFO = "/proc/cpuinfo";
66 67
67 68
68/* STATIC and common implementation */ 69/* STATIC and common implementation */
69/* EXPORT */ ODistribution distributions[] = { 70/* EXPORT */ ODistribution distributions[] = {
70 { System_Familiar, "FamiliarLinux", "/etc/familiar-version" }, 71 { System_Familiar, "FamiliarLinux", "/etc/familiar-version" },
71 { System_OpenZaurus, "OpenZaurus", "/etc/oz_version" }, 72 { System_OpenZaurus, "OpenZaurus", "/etc/oz_version" },
@@ -150,48 +151,52 @@ ODevice *ODevice::inst()
150 if ( !dev ) dev = new ODevice(); 151 if ( !dev ) dev = new ODevice();
151 dev->init(cpu_info); 152 dev->init(cpu_info);
152 } 153 }
153 return dev; 154 return dev;
154} 155}
155 156
156ODevice::ODevice() 157ODevice::ODevice()
157{ 158{
158 d = new ODeviceData; 159 d = new ODeviceData;
159 160
160 d->m_modelstr = "Unknown"; 161 d->m_modelstr = "Unknown";
161 d->m_model = Model_Unknown; 162 d->m_model = Model_Unknown;
162 d->m_vendorstr = "Unknown"; 163 d->m_vendorstr = "Unknown";
163 d->m_vendor = Vendor_Unknown; 164 d->m_vendor = Vendor_Unknown;
164 d->m_systemstr = "Unknown"; 165 d->m_systemstr = "Unknown";
165 d->m_system = System_Unknown; 166 d->m_system = System_Unknown;
166 d->m_sysverstr = "0.0"; 167 d->m_sysverstr = "0.0";
167 d->m_rotation = Rot0; 168 d->m_rotation = Rot0;
168 d->m_direction = CW; 169 d->m_direction = CW;
169 170
170 d->m_holdtime = 1000; // 1000ms 171 d->m_holdtime = 1000; // 1000ms
171 d->m_buttons = 0; 172 d->m_buttons = 0;
172 d->m_cpu_frequencies = new QStrList; 173 d->m_cpu_frequencies = new QStrList;
173 174
175
176 /* mixer */
177 d->m_sound = d->m_vol = d->m_mixer = -1;
178
174 // New distribution detection code first checks for legacy distributions, 179 // New distribution detection code first checks for legacy distributions,
175 // identified by /etc/familiar-version or /etc/oz_version. 180 // identified by /etc/familiar-version or /etc/oz_version.
176 // Then check for OpenEmbedded and lastly, read /etc/issue 181 // Then check for OpenEmbedded and lastly, read /etc/issue
177 182
178 for ( unsigned int i = 0; i < sizeof distributions; ++i ) 183 for ( unsigned int i = 0; i < sizeof distributions; ++i )
179 { 184 {
180 if ( QFile::exists( distributions[i].sysvfile ) ) 185 if ( QFile::exists( distributions[i].sysvfile ) )
181 { 186 {
182 d->m_systemstr = distributions[i].sysstr; 187 d->m_systemstr = distributions[i].sysstr;
183 d->m_system = distributions[i].system; 188 d->m_system = distributions[i].system;
184 d->m_sysverstr = "<Unknown>"; 189 d->m_sysverstr = "<Unknown>";
185 QFile f( distributions[i].sysvfile ); 190 QFile f( distributions[i].sysvfile );
186 if ( f.open( IO_ReadOnly ) ) 191 if ( f.open( IO_ReadOnly ) )
187 { 192 {
188 QTextStream ts( &f ); 193 QTextStream ts( &f );
189 d->m_sysverstr = ts.readLine(); 194 d->m_sysverstr = ts.readLine();
190 } 195 }
191 break; 196 break;
192 } 197 }
193 } 198 }
194} 199}
195 200
196void ODevice::systemMessage( const QCString &msg, const QByteArray & ) 201void ODevice::systemMessage( const QCString &msg, const QByteArray & )
197{ 202{
@@ -684,45 +689,97 @@ void ODevice::remapPressedAction ( int button, const OQCopMessage &action )
684 689
685void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) 690void ODevice::remapHeldAction ( int button, const OQCopMessage &action )
686{ 691{
687 initButtons(); 692 initButtons();
688 693
689 if ( button >= (int) d->m_buttons->count()) 694 if ( button >= (int) d->m_buttons->count())
690 return; 695 return;
691 696
692 ODeviceButton &b = ( *d->m_buttons ) [button]; 697 ODeviceButton &b = ( *d->m_buttons ) [button];
693 b. setHeldAction ( action ); 698 b. setHeldAction ( action );
694 699
695 Config buttonFile ( "ButtonSettings" ); 700 Config buttonFile ( "ButtonSettings" );
696 buttonFile. setGroup ( "Button" + QString::number ( button )); 701 buttonFile. setGroup ( "Button" + QString::number ( button ));
697 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction(). channel()); 702 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction(). channel());
698 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction(). message()); 703 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction(). message());
699 704
700// buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction(). data())); 705// buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction(). data()));
701 706
702 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 707 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
703} 708}
704void ODevice::virtual_hook(int, void* ){ 709void ODevice::virtual_hook(int, void* ){
705 710
706} 711}
707 712
713/**
714 * Sends a QCOP message to channel QPE/System
715 * with the message "aboutToSuspend()" if this
716 * is the windowing server
717 */
708void ODevice::sendSuspendmsg() 718void ODevice::sendSuspendmsg()
709{ 719{
710 if ( isQWS() ) 720 if ( isQWS() )
711 return; 721 return;
712 722
713 QCopEnvelope ( "QPE/System", "aboutToSuspend()" ); 723 QCopEnvelope ( "QPE/System", "aboutToSuspend()" );
714} 724}
715 725
726/**
727 * \brief Prepend the QWSServer::KeyboardFilter to the list of installed KeyFilters
728 *
729 * Prepend a QWSServer::KeyboardFilter to the List of Keyboard
730 * Filters. This function is the only way to prepend a KeyFilter.
731 *
732 * @param aFilter The KeyFilter to be prepended to the list of filters
733 *
734 * @see Opie::Core::OKeyFilter
735 * @see Opie::Core::OKeyFilter::inst()
736 */
716void ODevice::addPreHandler(QWSServer::KeyboardFilter*aFilter) 737void ODevice::addPreHandler(QWSServer::KeyboardFilter*aFilter)
717{ 738{
718 Opie::Core::OKeyFilter::inst()->addPreHandler(aFilter); 739 Opie::Core::OKeyFilter::inst()->addPreHandler(aFilter);
719} 740}
720 741
742/**
743 * \brief Remove the QWSServer::KeyboardFilter in the param from the list
744 *
745 * Remove the QWSServer::KeyboardFilter \par aFilter from the List
746 * of Keyfilters. Call this when you delete the KeyFilter!
747 *
748 * @param aFilter The filter to be removed from the Opie::Core::OKeyFilter
749 * @see Opie::Core::ODevice::addPreHandler
750 */
721void ODevice::remPreHandler(QWSServer::KeyboardFilter*aFilter) 751void ODevice::remPreHandler(QWSServer::KeyboardFilter*aFilter)
722{ 752{
723 Opie::Core::OKeyFilter::inst()->remPreHandler(aFilter); 753 Opie::Core::OKeyFilter::inst()->remPreHandler(aFilter);
724} 754}
725 755
756void ODevice::playingStopped() {
757 const_cast<QObject*>(sender())->disconnect( this );
758 if ( d->m_sound >= 0 ) {
759 ::ioctl ( d->m_sound, MIXER_WRITE( d->m_mixer ), &d->m_vol );
760 ::close ( d->m_sound );
761 }
762}
763
764void ODevice::changeMixerForAlarm( int mixer, const char* file, Sound *snd ) {
765 if (( d->m_sound = ::open ( file, O_RDWR )) >= 0 ) {
766 if ( ::ioctl ( d->m_sound, MIXER_READ( mixer ), &d->m_vol ) >= 0 ) {
767 Config cfg ( "qpe" );
768 cfg. setGroup ( "Volume" );
769
770 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
771 if ( volalarm < 0 )
772 volalarm = 0;
773 else if ( volalarm > 100 )
774 volalarm = 100;
775 volalarm |= ( volalarm << 8 );
776
777 if ( ::ioctl ( d->m_sound, MIXER_WRITE( mixer ), &volalarm ) >= 0 )
778 register_qpe_sound_finished(snd, this, SLOT(playingStopped()));
779 }
780 d->m_mixer = mixer;
781 }
782}
726 783
727} 784}
728} 785}
diff --git a/libopie2/opiecore/device/odevice.h b/libopie2/opiecore/device/odevice.h
index cb7a83f..f4b3e0e 100644
--- a/libopie2/opiecore/device/odevice.h
+++ b/libopie2/opiecore/device/odevice.h
@@ -1,71 +1,76 @@
1/* 1/*
2 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 Copyright (C) The Opie Team <opie-devel@handhelds.org> 3              Copyright (C) The Opie Team <opie-devel@handhelds.org>
4 =. 4 =.
5 .=l. 5 .=l.
6 .>+-= 6           .>+-=
7_;:, .> :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11- . .-<_> .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13 .%`+i> _;_. 13    .%`+i>       _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++= -. .` .: details. 20++=   -.     .`     .: details.
21: = ...= . :.=- 21 :     =  ...= . :.=-
22-. .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#ifndef ODEVICE_H_ 30#ifndef ODEVICE_H_
31#define ODEVICE_H_ 31#define ODEVICE_H_
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/odevicebutton.h> 34#include <opie2/odevicebutton.h>
35#include <qpe/qpeapplication.h> /* for Transformation enum.. */ 35#include <qpe/qpeapplication.h> /* for Transformation enum.. */
36 36
37/* QT */ 37/* QT */
38#include <qnamespace.h> 38#include <qnamespace.h>
39#include <qobject.h> 39#include <qobject.h>
40#include <qstring.h> 40#include <qstring.h>
41
42
41#include <qstrlist.h> 43#include <qstrlist.h>
42#include <qwindowsystem_qws.h> 44#include <qwindowsystem_qws.h>
43 45
46
47class Sound;
48
44namespace Opie{ 49namespace Opie{
45namespace Core{ 50namespace Core{
46 51
47 class ODeviceData; 52class ODeviceData;
48/** 53/**
49 * The available devices 54 * The available devices
50 */ 55 */
51enum OModel { 56enum OModel {
52 Model_Unknown, // = 0 57 Model_Unknown, // = 0
53 58
54 Model_Series_Mask = 0xff000000, 59 Model_Series_Mask = 0xff000000,
55 60
56 Model_iPAQ = ( 1 << 24 ), 61 Model_iPAQ = ( 1 << 24 ),
57 62
58 Model_iPAQ_All = ( Model_iPAQ | 0xffffff ), 63 Model_iPAQ_All = ( Model_iPAQ | 0xffffff ),
59 Model_iPAQ_H31xx = ( Model_iPAQ | 0x000001 ), 64 Model_iPAQ_H31xx = ( Model_iPAQ | 0x000001 ),
60 Model_iPAQ_H36xx = ( Model_iPAQ | 0x000002 ), 65 Model_iPAQ_H36xx = ( Model_iPAQ | 0x000002 ),
61 Model_iPAQ_H37xx = ( Model_iPAQ | 0x000004 ), 66 Model_iPAQ_H37xx = ( Model_iPAQ | 0x000004 ),
62 Model_iPAQ_H38xx = ( Model_iPAQ | 0x000008 ), 67 Model_iPAQ_H38xx = ( Model_iPAQ | 0x000008 ),
63 Model_iPAQ_H39xx = ( Model_iPAQ | 0x000010 ), 68 Model_iPAQ_H39xx = ( Model_iPAQ | 0x000010 ),
64 Model_iPAQ_H5xxx = ( Model_iPAQ | 0x000020 ), 69 Model_iPAQ_H5xxx = ( Model_iPAQ | 0x000020 ),
65 Model_iPAQ_H22xx = ( Model_iPAQ | 0x000040 ), 70 Model_iPAQ_H22xx = ( Model_iPAQ | 0x000040 ),
66 71
67 Model_Jornada = ( 6 << 24 ), 72 Model_Jornada = ( 6 << 24 ),
68 Model_Jornada_56x = ( Model_Jornada | 0x000001 ), 73 Model_Jornada_56x = ( Model_Jornada | 0x000001 ),
69 74
70 Model_Zaurus = ( 2 << 24 ), 75 Model_Zaurus = ( 2 << 24 ),
71 76
@@ -298,65 +303,71 @@ public:
298 const ODeviceButton *buttonForKeycode ( ushort keyCode ); 303 const ODeviceButton *buttonForKeycode ( ushort keyCode );
299 304
300 /** 305 /**
301 * Reassigns the pressed action for \a button. To return to the factory 306 * Reassigns the pressed action for \a button. To return to the factory
302 * default pass an empty string as \a qcopMessage. 307 * default pass an empty string as \a qcopMessage.
303 */ 308 */
304 void remapPressedAction ( int button, const OQCopMessage &qcopMessage ); 309 void remapPressedAction ( int button, const OQCopMessage &qcopMessage );
305 310
306 /** 311 /**
307 * Reassigns the held action for \a button. To return to the factory 312 * Reassigns the held action for \a button. To return to the factory
308 * default pass an empty string as \a qcopMessage. 313 * default pass an empty string as \a qcopMessage.
309 */ 314 */
310 void remapHeldAction ( int button, const OQCopMessage &qcopMessage ); 315 void remapHeldAction ( int button, const OQCopMessage &qcopMessage );
311 316
312 /** 317 /**
313 * How long (in ms) you have to press a button for a "hold" action 318 * How long (in ms) you have to press a button for a "hold" action
314 */ 319 */
315 uint buttonHoldTime() const; 320 uint buttonHoldTime() const;
316 321
317signals: 322signals:
318 void buttonMappingChanged(); 323 void buttonMappingChanged();
319 324
320private slots: 325private slots:
321 void systemMessage ( const QCString &, const QByteArray & ); 326 void systemMessage ( const QCString &, const QByteArray & );
327 void playingStopped();
322 328
323protected: 329protected:
324 void addPreHandler(QWSServer::KeyboardFilter*aFilter); 330 void addPreHandler(QWSServer::KeyboardFilter*aFilter);
325 void remPreHandler(QWSServer::KeyboardFilter*aFilter); 331 void remPreHandler(QWSServer::KeyboardFilter*aFilter);
326 void reloadButtonMapping(); 332 void reloadButtonMapping();
333 void changeMixerForAlarm( int mixer, const char* file, Sound *snd);
334
327 /* ugly virtual hook */ 335 /* ugly virtual hook */
328 virtual void virtual_hook( int id, void* data ); 336 virtual void virtual_hook( int id, void* data );
329}; 337};
330 338
331class ODeviceData { 339class ODeviceData {
332 340
333 public: 341 public:
334 QString m_vendorstr; 342 QString m_vendorstr;
335 OVendor m_vendor; 343 OVendor m_vendor;
336 344
337 QString m_modelstr; 345 QString m_modelstr;
338 OModel m_model; 346 OModel m_model;
339 347
340 QString m_systemstr; 348 QString m_systemstr;
341 OSystem m_system; 349 OSystem m_system;
342 350
343 QString m_sysverstr; 351 QString m_sysverstr;
344 352
345 Transformation m_rotation; 353 Transformation m_rotation;
346 ODirection m_direction; 354 ODirection m_direction;
347 355
348 QValueList <ODeviceButton> *m_buttons; 356 QValueList <ODeviceButton> *m_buttons;
349 uint m_holdtime; 357 uint m_holdtime;
350 QStrList *m_cpu_frequencies; 358 QStrList *m_cpu_frequencies;
359
360 /* values for changeMixerForAlarm */
361 int m_sound, m_vol, m_mixer;
351}; 362};
352 363
353extern bool isQWS(); 364extern bool isQWS();
354extern QCString makeChannel ( const char *str ); 365extern QCString makeChannel ( const char *str );
355} 366}
356} 367}
357 368
358 369
359 370
360 371
361#endif 372#endif
362 373
diff --git a/libopie2/opiecore/device/odevice_ipaq.cpp b/libopie2/opiecore/device/odevice_ipaq.cpp
index 21fed99..7f5aa7b 100644
--- a/libopie2/opiecore/device/odevice_ipaq.cpp
+++ b/libopie2/opiecore/device/odevice_ipaq.cpp
@@ -1,48 +1,48 @@
1/* 1/*
2 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 Copyright (C) The Opie Team <opie-devel@handhelds.org> 3              Copyright (C) 2002,2003,2004 The Opie Team <opie-devel@handhelds.org>
4 =. 4 =.
5 .=l. 5 .=l.
6 .>+-= 6           .>+-=
7_;:, .> :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11- . .-<_> .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13 .%`+i> _;_. 13    .%`+i>       _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++= -. .` .: details. 20++=   -.     .`     .: details.
21: = ...= . :.=- 21 :     =  ...= . :.=-
22-. .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "odevice_ipaq.h" 30#include "odevice_ipaq.h"
31 31
32/* QT */ 32/* QT */
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qfile.h> 34#include <qfile.h>
35#include <qtextstream.h> 35#include <qtextstream.h>
36#include <qwindowsystem_qws.h> 36#include <qwindowsystem_qws.h>
37 37
38/* OPIE */ 38/* OPIE */
39#include <qpe/config.h> 39#include <qpe/config.h>
40#include <qpe/resource.h> 40#include <qpe/resource.h>
41#include <qpe/sound.h> 41#include <qpe/sound.h>
42#include <qpe/qcopenvelope_qws.h> 42#include <qpe/qcopenvelope_qws.h>
43#include <opie2/okeyfilter.h> 43#include <opie2/okeyfilter.h>
44 44
45/* STD */ 45/* STD */
46#include <fcntl.h> 46#include <fcntl.h>
47#include <math.h> 47#include <math.h>
48#include <stdlib.h> 48#include <stdlib.h>
@@ -310,78 +310,51 @@ bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, b
310 } 310 }
311 311
312 if ( newkeycode != keycode ) { 312 if ( newkeycode != keycode ) {
313 if ( newkeycode != Key_unknown ) 313 if ( newkeycode != Key_unknown )
314 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); 314 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
315 return true; 315 return true;
316 } 316 }
317 else 317 else
318 return false; 318 return false;
319} 319}
320 320
321void iPAQ::timerEvent ( QTimerEvent * ) 321void iPAQ::timerEvent ( QTimerEvent * )
322{ 322{
323 killTimer ( m_power_timer ); 323 killTimer ( m_power_timer );
324 m_power_timer = 0; 324 m_power_timer = 0;
325 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); 325 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false );
326 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); 326 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false );
327} 327}
328 328
329 329
330void iPAQ::playAlarmSound() 330void iPAQ::playAlarmSound()
331{ 331{
332#ifndef QT_NO_SOUND 332#ifndef QT_NO_SOUND
333 static Sound snd ( "alarm" ); 333 static Sound snd ( "alarm" );
334 int fd;
335 int vol;
336 bool vol_reset = false;
337
338 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) {
339 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
340 Config cfg ( "qpe" );
341 cfg. setGroup ( "Volume" );
342
343 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
344 if ( volalarm < 0 )
345 volalarm = 0;
346 else if ( volalarm > 100 )
347 volalarm = 100;
348 volalarm |= ( volalarm << 8 );
349
350 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
351 vol_reset = true;
352 }
353 }
354 334
335 changeMixerForAlarm(0, "/dev/sound/mixer", &snd );
355 snd. play(); 336 snd. play();
356 while ( !snd. isFinished())
357 qApp->processEvents();
358
359 if ( fd >= 0 ) {
360 if ( vol_reset )
361 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
362 ::close ( fd );
363 }
364#endif 337#endif
365} 338}
366 339
367 340
368bool iPAQ::setSoftSuspend ( bool soft ) 341bool iPAQ::setSoftSuspend ( bool soft )
369{ 342{
370 bool res = false; 343 bool res = false;
371 int fd; 344 int fd;
372 345
373 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { 346 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) {
374 if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) 347 if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 )
375 res = true; 348 res = true;
376 else 349 else
377 ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); 350 ::perror ( "write to /proc/sys/ts/suspend_button_mode" );
378 351
379 ::close ( fd ); 352 ::close ( fd );
380 } 353 }
381 else 354 else
382 ::perror ( "/proc/sys/ts/suspend_button_mode" ); 355 ::perror ( "/proc/sys/ts/suspend_button_mode" );
383 356
384 return res; 357 return res;
385} 358}
386 359
387 360
diff --git a/libopie2/opiecore/device/odevice_simpad.cpp b/libopie2/opiecore/device/odevice_simpad.cpp
index c6de614..2d0160d 100644
--- a/libopie2/opiecore/device/odevice_simpad.cpp
+++ b/libopie2/opiecore/device/odevice_simpad.cpp
@@ -217,153 +217,124 @@ QValueList <OLedState> SIMpad::ledStateList ( OLed l ) const
217 217
218OLedState SIMpad::ledState ( OLed l ) const 218OLedState SIMpad::ledState ( OLed l ) const
219{ 219{
220 switch ( l ) { 220 switch ( l ) {
221 case Led_Power: 221 case Led_Power:
222 return m_leds [0]; 222 return m_leds [0];
223 //case Led_Mail: 223 //case Led_Mail:
224 // return m_leds [1]; 224 // return m_leds [1];
225 default: 225 default:
226 return Led_Off; 226 return Led_Off;
227 } 227 }
228} 228}
229 229
230bool SIMpad::setLedState ( OLed l, OLedState st ) 230bool SIMpad::setLedState ( OLed l, OLedState st )
231{ 231{
232#if 0 232#if 0
233 static int fd = ::open ( SIMPAD_BOARDCONTROL, O_RDWR | O_NONBLOCK ); 233 static int fd = ::open ( SIMPAD_BOARDCONTROL, O_RDWR | O_NONBLOCK );
234 234
235 /*TODO Implement this like that: 235 /*TODO Implement this like that:
236 read from cs3 236 read from cs3
237 && with SIMPAD_LED2_ON 237 && with SIMPAD_LED2_ON
238 write to cs3 */ 238 write to cs3 */
239 m_leds [0] = st; 239 m_leds [0] = st;
240 return true; 240 return true;
241 } 241 // }
242 } 242// }
243 } 243#else
244 244 Q_UNUSED( l )
245 Q_UNUSED( st )
245#endif 246#endif
246 return false; 247 return false;
247} 248}
248 249
249 250
250bool SIMpad::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) 251bool SIMpad::filter ( int /*unicode*/, int /*keycode*/, int /*modifiers*/, bool /*isPress*/, bool /*autoRepeat*/ )
251{ 252{
252 //TODO 253 //TODO
253 return false; 254 return false;
254} 255}
255 256
256void SIMpad::timerEvent ( QTimerEvent * ) 257void SIMpad::timerEvent ( QTimerEvent * )
257{ 258{
258 killTimer ( m_power_timer ); 259 killTimer ( m_power_timer );
259 m_power_timer = 0; 260 m_power_timer = 0;
260 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); 261 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false );
261 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); 262 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false );
262} 263}
263 264
264 265
265void SIMpad::playAlarmSound() 266void SIMpad::playAlarmSound()
266{ 267{
267#ifndef QT_NO_SOUND 268#ifndef QT_NO_SOUND
268 static Sound snd ( "alarm" ); 269 static Sound snd ( "alarm" );
269 int fd;
270 int vol;
271 bool vol_reset = false;
272
273 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) {
274 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
275 Config cfg ( "qpe" );
276 cfg. setGroup ( "Volume" );
277
278 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
279 if ( volalarm < 0 )
280 volalarm = 0;
281 else if ( volalarm > 100 )
282 volalarm = 100;
283 volalarm |= ( volalarm << 8 );
284
285 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
286 vol_reset = true;
287 }
288 }
289 270
271 /* save as the Sound is static! */
272 changeMixerForAlarm( 0, "/dev/sound/mixer" , &snd);
290 snd. play(); 273 snd. play();
291 while ( !snd. isFinished())
292 qApp->processEvents();
293
294 if ( fd >= 0 ) {
295 if ( vol_reset )
296 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
297 ::close ( fd );
298 }
299#endif 274#endif
300} 275}
301 276
302 277
303bool SIMpad::suspend() // Must override because SIMpad does NOT have apm 278bool SIMpad::suspend() // Must override because SIMpad does NOT have apm
304{ 279{
305 qDebug( "ODevice for SIMpad: suspend()" ); 280 qDebug( "ODevice for SIMpad: suspend()" );
306 if ( !isQWS( ) ) // only qwsserver is allowed to suspend 281 if ( !isQWS( ) ) // only qwsserver is allowed to suspend
307 return false; 282 return false;
308 283
309 /* 284 /*
310 * we need to save the screen content 285 * we need to save the screen content
311 * then go to suspend using ODevice::suspend 286 * then go to suspend using ODevice::suspend
312 * and finally restore the screen content 287 * and finally restore the screen content
313 */ 288 */
314 (void)::system( "cat /dev/fb/0 > /tmp/.buffer" ); 289 (void)::system( "cat /dev/fb/0 > /tmp/.buffer" );
315 bool res = ODevice::suspend(); 290 bool res = ODevice::suspend();
316 291
317 /* 292 /*
318 * restore 293 * restore
319 */ 294 */
320 if ( res ) 295 if ( res )
321 ::system( "cat /tmp/.buffer > /dev/fb/0" ); 296 ::system( "cat /tmp/.buffer > /dev/fb/0" );
322 297
323 return res; 298 return res;
324} 299}
325 300
326 301
327bool SIMpad::setSoftSuspend ( bool soft ) 302bool SIMpad::setSoftSuspend ( bool soft )
328{ 303{
329 qDebug( "ODevice for SIMpad: UNHANDLED setSoftSuspend(%s)", soft? "on" : "off" ); 304 qDebug( "ODevice for SIMpad: UNHANDLED setSoftSuspend(%s)", soft? "on" : "off" );
330 return false; 305 return false;
331} 306}
332 307
333 308
334bool SIMpad::setDisplayStatus ( bool on ) 309bool SIMpad::setDisplayStatus ( bool on )
335{ 310{
336 qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" ); 311 qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" );
337 312
338 bool res = false;
339 int fd;
340 313
341 QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :) 314 QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :)
342 315
343 res = ( ::system( (const char*) cmdline ) == 0 ); 316 return ( ::system( (const char*) cmdline ) == 0 );
344
345 return res;
346} 317}
347 318
348 319
349bool SIMpad::setDisplayBrightness ( int bright ) 320bool SIMpad::setDisplayBrightness ( int bright )
350{ 321{
351 qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright ); 322 qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright );
352 bool res = false; 323 bool res = false;
353 int fd; 324 int fd;
354 325
355 if ( bright > 255 ) 326 if ( bright > 255 )
356 bright = 255; 327 bright = 255;
357 if ( bright < 1 ) 328 if ( bright < 1 )
358 bright = 0; 329 bright = 0;
359 330
360 if (( fd = ::open ( SIMPAD_BACKLIGHT_CONTROL, O_WRONLY )) >= 0 ) { 331 if (( fd = ::open ( SIMPAD_BACKLIGHT_CONTROL, O_WRONLY )) >= 0 ) {
361 int value = 255 - bright; 332 int value = 255 - bright;
362 const int mask = SIMPAD_BACKLIGHT_MASK; 333 const int mask = SIMPAD_BACKLIGHT_MASK;
363 value = value << 8; 334 value = value << 8;
364 value += mask; 335 value += mask;
365 char writeCommand[100]; 336 char writeCommand[100];
366 const int count = snprintf( writeCommand, sizeof(writeCommand), "0x%x\n", value ); 337 const int count = snprintf( writeCommand, sizeof(writeCommand), "0x%x\n", value );
367 res = ( ::write ( fd, writeCommand, count ) != -1 ); 338 res = ( ::write ( fd, writeCommand, count ) != -1 );
368 ::close ( fd ); 339 ::close ( fd );
369 } 340 }
diff --git a/libopie2/opiecore/device/odevice_simpad.h b/libopie2/opiecore/device/odevice_simpad.h
index d9ae5a5..6c42be7 100644
--- a/libopie2/opiecore/device/odevice_simpad.h
+++ b/libopie2/opiecore/device/odevice_simpad.h
@@ -1,27 +1,27 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) The Opie Team <opie-devel@handhelds.org> 3              Copyright (C) 2003, 2004 The Opie Team <opie-devel@handhelds.org>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
diff --git a/libopie2/opiecore/device/odevice_yopy.cpp b/libopie2/opiecore/device/odevice_yopy.cpp
index 223aa76..a06d7ec 100644
--- a/libopie2/opiecore/device/odevice_yopy.cpp
+++ b/libopie2/opiecore/device/odevice_yopy.cpp
@@ -122,34 +122,36 @@ bool Yopy::suspend()
122 moment. The public version runs parallel to X, and relies on the 122 moment. The public version runs parallel to X, and relies on the
123 existing power management features. */ 123 existing power management features. */
124 return false; 124 return false;
125} 125}
126 126
127 127
128bool Yopy::setDisplayBrightness( int bright ) 128bool Yopy::setDisplayBrightness( int bright )
129{ 129{
130 /* The code here works, but is disabled as the current version runs 130 /* The code here works, but is disabled as the current version runs
131 parallel to X, and relies on the existing backlight demon. */ 131 parallel to X, and relies on the existing backlight demon. */
132#if 0 132#if 0
133 if ( QFile::exists( "/proc/sys/pm/light" ) ) 133 if ( QFile::exists( "/proc/sys/pm/light" ) )
134 { 134 {
135 int fd = ::open( "/proc/sys/pm/light", O_WRONLY ); 135 int fd = ::open( "/proc/sys/pm/light", O_WRONLY );
136 if ( fd >= 0 ) 136 if ( fd >= 0 )
137 { 137 {
138 if ( bright ) 138 if ( bright )
139 ::write( fd, "1\n", 2 ); 139 ::write( fd, "1\n", 2 );
140 else 140 else
141 ::write( fd, "0\n", 2 ); 141 ::write( fd, "0\n", 2 );
142 ::close( fd ); 142 ::close( fd );
143 return true; 143 return true;
144 } 144 }
145 } 145 }
146#else
147 Q_UNUSED( bright )
146#endif 148#endif
147 return false; 149 return false;
148} 150}
149 151
150 152
151int Yopy::displayBrightnessResolution() const 153int Yopy::displayBrightnessResolution() const
152{ 154{
153 return 2; 155 return 2;
154} 156}
155 157
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,48 +1,48 @@
1/* 1/*
2 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 Copyright (C) The Opie Team <opie-devel@handhelds.org> 3              Copyright (C) The Opie Team <opie-devel@handhelds.org>
4 =. 4 =.
5 .=l. 5 .=l.
6 .>+-= 6           .>+-=
7_;:, .> :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11- . .-<_> .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13 .%`+i> _;_. 13    .%`+i>       _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++= -. .` .: details. 20++=   -.     .`     .: details.
21: = ...= . :.=- 21 :     =  ...= . :.=-
22-. .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "odevice_zaurus.h" 30#include "odevice_zaurus.h"
31 31
32/* QT */ 32/* QT */
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qfile.h> 34#include <qfile.h>
35#include <qtextstream.h> 35#include <qtextstream.h>
36#include <qwindowsystem_qws.h> 36#include <qwindowsystem_qws.h>
37 37
38/* OPIE */ 38/* OPIE */
39#include <qpe/config.h> 39#include <qpe/config.h>
40#include <qpe/resource.h> 40#include <qpe/resource.h>
41#include <qpe/sound.h> 41#include <qpe/sound.h>
42#include <qpe/qcopenvelope_qws.h> 42#include <qpe/qcopenvelope_qws.h>
43 43
44/* STD */ 44/* STD */
45#include <fcntl.h> 45#include <fcntl.h>
46#include <math.h> 46#include <math.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <signal.h> 48#include <signal.h>
@@ -162,50 +162,48 @@ void Zaurus::init(const QString& cpu_info)
162 if ( model == "SHARP Corgi" ) { 162 if ( model == "SHARP Corgi" ) {
163 d->m_model = Model_Zaurus_SLC7x0; 163 d->m_model = Model_Zaurus_SLC7x0;
164 d->m_modelstr = "Zaurus SL-C700"; 164 d->m_modelstr = "Zaurus SL-C700";
165 } else if ( model == "SHARP Shepherd" ) { 165 } else if ( model == "SHARP Shepherd" ) {
166 d->m_model = Model_Zaurus_SLC7x0; 166 d->m_model = Model_Zaurus_SLC7x0;
167 d->m_modelstr = "Zaurus SL-C750"; 167 d->m_modelstr = "Zaurus SL-C750";
168 } else if ( model == "SHARP Husky" ) { 168 } else if ( model == "SHARP Husky" ) {
169 d->m_model = Model_Zaurus_SLC7x0; 169 d->m_model = Model_Zaurus_SLC7x0;
170 d->m_modelstr = "Zaurus SL-C760"; 170 d->m_modelstr = "Zaurus SL-C760";
171 } else if ( model == "SHARP Poodle" ) { 171 } else if ( model == "SHARP Poodle" ) {
172 d->m_model = Model_Zaurus_SLB600; 172 d->m_model = Model_Zaurus_SLB600;
173 d->m_modelstr = "Zaurus SL-B500 or SL-5600"; 173 d->m_modelstr = "Zaurus SL-B500 or SL-5600";
174 } else if ( model == "Sharp-Collie" || model == "Collie" ) { 174 } else if ( model == "Sharp-Collie" || model == "Collie" ) {
175 d->m_model = Model_Zaurus_SL5500; 175 d->m_model = Model_Zaurus_SL5500;
176 d->m_modelstr = "Zaurus SL-5500 or SL-5000d"; 176 d->m_modelstr = "Zaurus SL-5500 or SL-5000d";
177 } else if ( model == "SHARP Tosa" ) { 177 } else if ( model == "SHARP Tosa" ) {
178 d->m_model = Model_Zaurus_SL6000; 178 d->m_model = Model_Zaurus_SL6000;
179 d->m_modelstr = "Zaurus SL-6000"; 179 d->m_modelstr = "Zaurus SL-6000";
180 } else { 180 } else {
181 d->m_model = Model_Zaurus_SL5500; 181 d->m_model = Model_Zaurus_SL5500;
182 d->m_modelstr = "Unkown Zaurus"; 182 d->m_modelstr = "Unkown Zaurus";
183 } 183 }
184 184
185 // set initial rotation 185 // set initial rotation
186
187 bool flipstate = false;
188 switch ( d->m_model ) { 186 switch ( d->m_model ) {
189 case Model_Zaurus_SL6000: 187 case Model_Zaurus_SL6000:
190 case Model_Zaurus_SLA300: 188 case Model_Zaurus_SLA300:
191 d->m_rotation = Rot0; 189 d->m_rotation = Rot0;
192 break; 190 break;
193 case Model_Zaurus_SLC7x0: 191 case Model_Zaurus_SLC7x0:
194 d->m_rotation = rotation(); 192 d->m_rotation = rotation();
195 d->m_direction = direction(); 193 d->m_direction = direction();
196 break; 194 break;
197 case Model_Zaurus_SLB600: 195 case Model_Zaurus_SLB600:
198 case Model_Zaurus_SL5500: 196 case Model_Zaurus_SL5500:
199 case Model_Zaurus_SL5000: 197 case Model_Zaurus_SL5000:
200 default: 198 default:
201 d->m_rotation = Rot270; 199 d->m_rotation = Rot270;
202 break; 200 break;
203 } 201 }
204 m_leds [0] = Led_Off; 202 m_leds [0] = Led_Off;
205} 203}
206 204
207void Zaurus::initButtons() 205void Zaurus::initButtons()
208{ 206{
209 if ( d->m_buttons ) 207 if ( d->m_buttons )
210 return; 208 return;
211 209
@@ -297,106 +295,77 @@ void Zaurus::initButtons()
297 295
298typedef struct sharp_led_status { 296typedef struct sharp_led_status {
299int which; /* select which LED status is wanted. */ 297int which; /* select which LED status is wanted. */
300int status; /* set new led status if you call SHARP_LED_SETSTATUS */ 298int status; /* set new led status if you call SHARP_LED_SETSTATUS */
301} sharp_led_status; 299} sharp_led_status;
302 300
303#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */ 301#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */
304 302
305#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */ 303#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */
306#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */ 304#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */
307#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */ 305#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */
308 306
309// #include <asm/sharp_apm.h> // including kernel headers is evil ... 307// #include <asm/sharp_apm.h> // including kernel headers is evil ...
310 308
311#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int ) 309#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int )
312#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int ) 310#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int )
313#define APM_EVT_POWER_BUTTON (1 << 0) 311#define APM_EVT_POWER_BUTTON (1 << 0)
314 312
315#define FL_IOCTL_STEP_CONTRAST 100 313#define FL_IOCTL_STEP_CONTRAST 100
316 314
317 315
318void Zaurus::buzzer ( int sound ) 316void Zaurus::buzzer ( int sound )
319{ 317{
320#ifndef QT_NO_SOUND 318#ifndef QT_NO_SOUND
321 QString soundname; 319 Sound *snd = 0;
322 320
323 // Not all devices have real sound 321 // Not all devices have real sound
324 if ( d->m_model == Model_Zaurus_SLC7x0 322 if ( d->m_model == Model_Zaurus_SLC7x0
325 || d->m_model == Model_Zaurus_SLB600 ){ 323 || d->m_model == Model_Zaurus_SLB600 ){
326 324
327 switch ( sound ){ 325 switch ( sound ){
328 case SHARP_BUZ_SCHEDULE_ALARM:
329 soundname = "alarm";
330 break;
331 case SHARP_BUZ_TOUCHSOUND: 326 case SHARP_BUZ_TOUCHSOUND:
332 soundname = "touchsound"; 327 static Sound touch_sound("touchsound");
328 snd = &touch_sound;
333 break; 329 break;
334 case SHARP_BUZ_KEYSOUND: 330 case SHARP_BUZ_KEYSOUND:
335 soundname = "keysound"; 331 static Sound key_sound( "keysound" );
332 snd = &key_sound;
336 break; 333 break;
334 case SHARP_BUZ_SCHEDULE_ALARM:
337 default: 335 default:
338 soundname = "alarm"; 336 static Sound alarm_sound("alarm");
339 337 snd = &alarm_sound;
338 break;
340 } 339 }
341 } 340 }
342 341
343 // If a soundname is defined, we expect that this device has 342 // If a soundname is defined, we expect that this device has
344 // sound capabilities.. Otherwise we expect to have the buzzer 343 // sound capabilities.. Otherwise we expect to have the buzzer
345 // device.. 344 // device..
346 if ( !soundname.isEmpty() ){ 345 if ( snd ){
347 int fd; 346 changeMixerForAlarm( 0, "/dev/sound/mixer", snd );
348 int vol; 347 snd-> play();
349 bool vol_reset = false;
350
351 Sound snd ( soundname );
352
353 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) {
354 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
355 Config cfg ( "qpe" );
356 cfg. setGroup ( "Volume" );
357
358 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
359 if ( volalarm < 0 )
360 volalarm = 0;
361 else if ( volalarm > 100 )
362 volalarm = 100;
363 volalarm |= ( volalarm << 8 );
364
365 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
366 vol_reset = true;
367 }
368 }
369
370 snd. play();
371 while ( !snd. isFinished())
372 qApp->processEvents();
373
374 if ( fd >= 0 ) {
375 if ( vol_reset )
376 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
377 ::close ( fd );
378 }
379 } else { 348 } else {
380 int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK ); 349 int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK );
381 350
382 if ( fd >= 0 ) { 351 if ( fd >= 0 ) {
383 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); 352 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound );
384 ::close ( fd ); 353 ::close ( fd );
385 } 354 }
386 355
387 } 356 }
388#endif 357#endif
389} 358}
390 359
391 360
392void Zaurus::playAlarmSound() 361void Zaurus::playAlarmSound()
393{ 362{
394 buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); 363 buzzer ( SHARP_BUZ_SCHEDULE_ALARM );
395} 364}
396 365
397void Zaurus::playTouchSound() 366void Zaurus::playTouchSound()
398{ 367{
399 buzzer ( SHARP_BUZ_TOUCHSOUND ); 368 buzzer ( SHARP_BUZ_TOUCHSOUND );
400} 369}
401 370
402void Zaurus::playKeySound() 371void Zaurus::playKeySound()
@@ -493,49 +462,49 @@ bool Zaurus::setSoftSuspend ( bool soft )
493 else 462 else
494 perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); 463 perror ( "/dev/apm_bios or /dev/misc/apm_bios" );
495 464
496 return res; 465 return res;
497} 466}
498 467
499 468
500bool Zaurus::setDisplayBrightness ( int bright ) 469bool Zaurus::setDisplayBrightness ( int bright )
501{ 470{
502 //qDebug( "Zaurus::setDisplayBrightness( %d )", bright ); 471 //qDebug( "Zaurus::setDisplayBrightness( %d )", bright );
503 bool res = false; 472 bool res = false;
504 int fd; 473 int fd;
505 474
506 if ( bright > 255 ) bright = 255; 475 if ( bright > 255 ) bright = 255;
507 if ( bright < 0 ) bright = 0; 476 if ( bright < 0 ) bright = 0;
508 477
509 if ( m_embedix ) 478 if ( m_embedix )
510 { 479 {
511 if ( d->m_model == Model_Zaurus_SLC7x0 ) 480 if ( d->m_model == Model_Zaurus_SLC7x0 )
512 { 481 {
513 //qDebug( "using special treatment for devices with the corgi backlight interface" ); 482 //qDebug( "using special treatment for devices with the corgi backlight interface" );
514 // special treatment for devices with the corgi backlight interface 483 // special treatment for devices with the corgi backlight interface
515 if (( fd = ::open ( "/proc/driver/fl/corgi-bl", O_WRONLY )) >= 0 ) 484 if (( fd = ::open ( "/proc/driver/fl/corgi-bl", O_WRONLY )) >= 0 )
516 { 485 {
517 int value = ( bright == 1 ) ? 1 : bright * ( 17.0 / 255.0 ); 486 int value = ( bright == 1 ) ? 1 : static_cast<int>( bright * ( 17.0 / 255.0 ) );
518 char writeCommand[100]; 487 char writeCommand[100];
519 const int count = sprintf( writeCommand, "0x%x\n", value ); 488 const int count = sprintf( writeCommand, "0x%x\n", value );
520 res = ( ::write ( fd, writeCommand, count ) != -1 ); 489 res = ( ::write ( fd, writeCommand, count ) != -1 );
521 ::close ( fd ); 490 ::close ( fd );
522 } 491 }
523 return res; 492 return res;
524 } 493 }
525 else 494 else
526 { 495 {
527 // standard treatment for devices with the dumb embedix frontlight interface 496 // standard treatment for devices with the dumb embedix frontlight interface
528 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) { 497 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) {
529 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus 498 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus
530 if ( bright && !bl ) 499 if ( bright && !bl )
531 bl = 1; 500 bl = 1;
532 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 ); 501 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 );
533 ::close ( fd ); 502 ::close ( fd );
534 } 503 }
535 } 504 }
536 } 505 }
537 else 506 else
538 { 507 {
539 // special treatment for the OpenZaurus unified interface 508 // special treatment for the OpenZaurus unified interface
540 #define FB_BACKLIGHT_SET_BRIGHTNESS _IOW('F', 1, u_int) /* set brightness */ 509 #define FB_BACKLIGHT_SET_BRIGHTNESS _IOW('F', 1, u_int) /* set brightness */
541 if (( fd = ::open ( "/dev/fb0", O_WRONLY )) >= 0 ) { 510 if (( fd = ::open ( "/dev/fb0", O_WRONLY )) >= 0 ) {