summaryrefslogtreecommitdiff
path: root/libopie/odevice.cpp
authorkergoth <kergoth>2003-01-26 20:27:10 (UTC)
committer kergoth <kergoth>2003-01-26 20:27:10 (UTC)
commit4ce67fbdfb5e82bbde3a8963d3e956567438689d (patch) (unidiff)
treee35167d7c0d16aa462b336cd4aa4cba64c292892 /libopie/odevice.cpp
parent06d7d61516ee27b60c39453ef61215708aa3468a (diff)
downloadopie-4ce67fbdfb5e82bbde3a8963d3e956567438689d.zip
opie-4ce67fbdfb5e82bbde3a8963d3e956567438689d.tar.gz
opie-4ce67fbdfb5e82bbde3a8963d3e956567438689d.tar.bz2
None->Rot0 name for transformation enum, as it stomped on someone elses None ;)
Diffstat (limited to 'libopie/odevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 78eb416..9e97c56 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -1,1211 +1,1211 @@
1/* This file is part of the OPIE libraries 1/* This file is part of the OPIE libraries
2 Copyright (C) 2002 Robert Griebl (sandman@handhelds.org) 2 Copyright (C) 2002 Robert Griebl (sandman@handhelds.org)
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either 6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version. 7 version 2 of the License, or (at your option) any later version.
8 8
9 This library is distributed in the hope that it will be useful, 9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <stdlib.h> 20#include <stdlib.h>
21#include <unistd.h> 21#include <unistd.h>
22#include <fcntl.h> 22#include <fcntl.h>
23#include <sys/ioctl.h> 23#include <sys/ioctl.h>
24#include <signal.h> 24#include <signal.h>
25#include <sys/time.h> 25#include <sys/time.h>
26#include <linux/soundcard.h> 26#include <linux/soundcard.h>
27#include <math.h> 27#include <math.h>
28 28
29#include <qapplication.h> 29#include <qapplication.h>
30 30
31#include <qfile.h> 31#include <qfile.h>
32#include <qtextstream.h> 32#include <qtextstream.h>
33#include <qpe/sound.h> 33#include <qpe/sound.h>
34#include <qpe/resource.h> 34#include <qpe/resource.h>
35#include <qpe/config.h> 35#include <qpe/config.h>
36#include <qpe/qcopenvelope_qws.h> 36#include <qpe/qcopenvelope_qws.h>
37 37
38#include "odevice.h" 38#include "odevice.h"
39 39
40#include <qwindowsystem_qws.h> 40#include <qwindowsystem_qws.h>
41 41
42 42
43// _IO and friends are only defined in kernel headers ... 43// _IO and friends are only defined in kernel headers ...
44 44
45#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) 45#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
46 46
47#define OD_IO(type,number) OD_IOC(0,type,number,0) 47#define OD_IO(type,number) OD_IOC(0,type,number,0)
48#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) 48#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size))
49#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) 49#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size))
50#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) 50#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size))
51 51
52using namespace Opie; 52using namespace Opie;
53 53
54class ODeviceData { 54class ODeviceData {
55public: 55public:
56 bool m_qwsserver; 56 bool m_qwsserver;
57 57
58 QString m_vendorstr; 58 QString m_vendorstr;
59 OVendor m_vendor; 59 OVendor m_vendor;
60 60
61 QString m_modelstr; 61 QString m_modelstr;
62 OModel m_model; 62 OModel m_model;
63 63
64 QString m_systemstr; 64 QString m_systemstr;
65 OSystem m_system; 65 OSystem m_system;
66 66
67 QString m_sysverstr; 67 QString m_sysverstr;
68 68
69 Transformation m_rotation; 69 Transformation m_rotation;
70 70
71 QValueList <ODeviceButton> m_buttons; 71 QValueList <ODeviceButton> m_buttons;
72 uint m_holdtime; 72 uint m_holdtime;
73}; 73};
74 74
75 75
76class iPAQ : public ODevice, public QWSServer::KeyboardFilter { 76class iPAQ : public ODevice, public QWSServer::KeyboardFilter {
77protected: 77protected:
78 virtual void init ( ); 78 virtual void init ( );
79 79
80public: 80public:
81 virtual bool setSoftSuspend ( bool soft ); 81 virtual bool setSoftSuspend ( bool soft );
82 82
83 virtual bool setDisplayBrightness ( int b ); 83 virtual bool setDisplayBrightness ( int b );
84 virtual int displayBrightnessResolution ( ) const; 84 virtual int displayBrightnessResolution ( ) const;
85 85
86 virtual void alarmSound ( ); 86 virtual void alarmSound ( );
87 87
88 virtual QValueList <OLed> ledList ( ) const; 88 virtual QValueList <OLed> ledList ( ) const;
89 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 89 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
90 virtual OLedState ledState ( OLed led ) const; 90 virtual OLedState ledState ( OLed led ) const;
91 virtual bool setLedState ( OLed led, OLedState st ); 91 virtual bool setLedState ( OLed led, OLedState st );
92 92
93 virtual bool hasLightSensor ( ) const; 93 virtual bool hasLightSensor ( ) const;
94 virtual int readLightSensor ( ); 94 virtual int readLightSensor ( );
95 virtual int lightSensorResolution ( ) const; 95 virtual int lightSensorResolution ( ) const;
96 96
97protected: 97protected:
98 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); 98 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
99 virtual void timerEvent ( QTimerEvent *te ); 99 virtual void timerEvent ( QTimerEvent *te );
100 100
101 int m_power_timer; 101 int m_power_timer;
102 102
103 OLedState m_leds [2]; 103 OLedState m_leds [2];
104}; 104};
105 105
106class Zaurus : public ODevice { 106class Zaurus : public ODevice {
107protected: 107protected:
108 virtual void init ( ); 108 virtual void init ( );
109 109
110 public: 110 public:
111 virtual bool setSoftSuspend ( bool soft ); 111 virtual bool setSoftSuspend ( bool soft );
112 112
113 virtual bool setDisplayBrightness ( int b ); 113 virtual bool setDisplayBrightness ( int b );
114 virtual int displayBrightnessResolution ( ) const; 114 virtual int displayBrightnessResolution ( ) const;
115 115
116 virtual void alarmSound ( ); 116 virtual void alarmSound ( );
117 virtual void keySound ( ); 117 virtual void keySound ( );
118 virtual void touchSound ( ); 118 virtual void touchSound ( );
119 119
120 virtual QValueList <OLed> ledList ( ) const; 120 virtual QValueList <OLed> ledList ( ) const;
121 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 121 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
122 virtual OLedState ledState ( OLed led ) const; 122 virtual OLedState ledState ( OLed led ) const;
123 virtual bool setLedState ( OLed led, OLedState st ); 123 virtual bool setLedState ( OLed led, OLedState st );
124 124
125protected: 125protected:
126 virtual void buzzer ( int snd ); 126 virtual void buzzer ( int snd );
127 127
128 OLedState m_leds [1]; 128 OLedState m_leds [1];
129}; 129};
130 130
131 131
132struct i_button { 132struct i_button {
133 uint model; 133 uint model;
134 Qt::Key code; 134 Qt::Key code;
135 char *utext; 135 char *utext;
136 char *pix; 136 char *pix;
137 char *fpressedservice; 137 char *fpressedservice;
138 char *fpressedaction; 138 char *fpressedaction;
139 char *fheldservice; 139 char *fheldservice;
140 char *fheldaction; 140 char *fheldaction;
141} ipaq_buttons [] = { 141} ipaq_buttons [] = {
142 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, 142 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx,
143 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 143 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
144 "devicebuttons/ipaq_calendar", 144 "devicebuttons/ipaq_calendar",
145 "datebook", "nextView()", 145 "datebook", "nextView()",
146 "today", "raise()" }, 146 "today", "raise()" },
147 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, 147 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx,
148 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 148 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
149 "devicebuttons/ipaq_contact", 149 "devicebuttons/ipaq_contact",
150 "addressbook", "raise()", 150 "addressbook", "raise()",
151 "addressbook", "beamBusinessCard()" }, 151 "addressbook", "beamBusinessCard()" },
152 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, 152 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx,
153 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 153 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
154 "devicebuttons/ipaq_menu", 154 "devicebuttons/ipaq_menu",
155 "QPE/TaskBar", "toggleMenu()", 155 "QPE/TaskBar", "toggleMenu()",
156 "QPE/TaskBar", "toggleStartMenu()" }, 156 "QPE/TaskBar", "toggleStartMenu()" },
157 { Model_iPAQ_H38xx | Model_iPAQ_H39xx, 157 { Model_iPAQ_H38xx | Model_iPAQ_H39xx,
158 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), 158 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"),
159 "devicebuttons/ipaq_mail", 159 "devicebuttons/ipaq_mail",
160 "mail", "raise()", 160 "mail", "raise()",
161 "mail", "newMail()" }, 161 "mail", "newMail()" },
162 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, 162 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx,
163 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 163 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
164 "devicebuttons/ipaq_home", 164 "devicebuttons/ipaq_home",
165 "QPE/Launcher", "home()", 165 "QPE/Launcher", "home()",
166 "buttonsettings", "raise()" }, 166 "buttonsettings", "raise()" },
167 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, 167 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx,
168 Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), 168 Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"),
169 "devicebuttons/ipaq_record", 169 "devicebuttons/ipaq_record",
170 "QPE/VMemo", "toggleRecord()", 170 "QPE/VMemo", "toggleRecord()",
171 "sound", "raise()" }, 171 "sound", "raise()" },
172}; 172};
173 173
174struct z_button { 174struct z_button {
175 Qt::Key code; 175 Qt::Key code;
176 char *utext; 176 char *utext;
177 char *pix; 177 char *pix;
178 char *fpressedservice; 178 char *fpressedservice;
179 char *fpressedaction; 179 char *fpressedaction;
180 char *fheldservice; 180 char *fheldservice;
181 char *fheldaction; 181 char *fheldaction;
182} z_buttons [] = { 182} z_buttons [] = {
183 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 183 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
184 "devicebuttons/z_calendar", 184 "devicebuttons/z_calendar",
185 "datebook", "nextView()", 185 "datebook", "nextView()",
186 "today", "raise()" }, 186 "today", "raise()" },
187 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 187 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
188 "devicebuttons/z_contact", 188 "devicebuttons/z_contact",
189 "addressbook", "raise()", 189 "addressbook", "raise()",
190 "addressbook", "beamBusinessCard()" }, 190 "addressbook", "beamBusinessCard()" },
191 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 191 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
192 "devicebuttons/z_home", 192 "devicebuttons/z_home",
193 "QPE/Launcher", "home()", 193 "QPE/Launcher", "home()",
194 "buttonsettings", "raise()" }, 194 "buttonsettings", "raise()" },
195 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 195 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
196 "devicebuttons/z_menu", 196 "devicebuttons/z_menu",
197 "QPE/TaskBar", "toggleMenu()", 197 "QPE/TaskBar", "toggleMenu()",
198 "QPE/TaskBar", "toggleStartMenu()" }, 198 "QPE/TaskBar", "toggleStartMenu()" },
199 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), 199 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"),
200 "devicebuttons/z_mail", 200 "devicebuttons/z_mail",
201 "mail", "raise()", 201 "mail", "raise()",
202 "mail", "newMail()" }, 202 "mail", "newMail()" },
203}; 203};
204 204
205static QCString makeChannel ( const char *str ) 205static QCString makeChannel ( const char *str )
206{ 206{
207 if ( str && !::strchr ( str, '/' )) 207 if ( str && !::strchr ( str, '/' ))
208 return QCString ( "QPE/Application/" ) + str; 208 return QCString ( "QPE/Application/" ) + str;
209 else 209 else
210 return str; 210 return str;
211} 211}
212 212
213 213
214 214
215 215
216ODevice *ODevice::inst ( ) 216ODevice *ODevice::inst ( )
217{ 217{
218 static ODevice *dev = 0; 218 static ODevice *dev = 0;
219 219
220 if ( !dev ) { 220 if ( !dev ) {
221 if ( QFile::exists ( "/proc/hal/model" )) 221 if ( QFile::exists ( "/proc/hal/model" ))
222 dev = new iPAQ ( ); 222 dev = new iPAQ ( );
223 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) 223 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ))
224 dev = new Zaurus ( ); 224 dev = new Zaurus ( );
225 else 225 else
226 dev = new ODevice ( ); 226 dev = new ODevice ( );
227 227
228 dev-> init ( ); 228 dev-> init ( );
229 } 229 }
230 return dev; 230 return dev;
231} 231}
232 232
233 233
234/************************************************** 234/**************************************************
235 * 235 *
236 * common 236 * common
237 * 237 *
238 **************************************************/ 238 **************************************************/
239 239
240 240
241ODevice::ODevice ( ) 241ODevice::ODevice ( )
242{ 242{
243 d = new ODeviceData; 243 d = new ODeviceData;
244 244
245 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; 245 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
246 246
247 d-> m_modelstr = "Unknown"; 247 d-> m_modelstr = "Unknown";
248 d-> m_model = Model_Unknown; 248 d-> m_model = Model_Unknown;
249 d-> m_vendorstr = "Unknown"; 249 d-> m_vendorstr = "Unknown";
250 d-> m_vendor = Vendor_Unknown; 250 d-> m_vendor = Vendor_Unknown;
251 d-> m_systemstr = "Unknown"; 251 d-> m_systemstr = "Unknown";
252 d-> m_system = System_Unknown; 252 d-> m_system = System_Unknown;
253 d-> m_sysverstr = "0.0"; 253 d-> m_sysverstr = "0.0";
254 d-> m_rotation = None; 254 d-> m_rotation = Rot0;
255 255
256 d-> m_holdtime = 1000; // 1000ms 256 d-> m_holdtime = 1000; // 1000ms
257 257
258 QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); 258 QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
259 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); 259 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & )));
260} 260}
261 261
262void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) 262void ODevice::systemMessage ( const QCString &msg, const QByteArray & )
263{ 263{
264 if ( msg == "deviceButtonMappingChanged()" ) { 264 if ( msg == "deviceButtonMappingChanged()" ) {
265 reloadButtonMapping ( ); 265 reloadButtonMapping ( );
266 } 266 }
267} 267}
268 268
269void ODevice::init ( ) 269void ODevice::init ( )
270{ 270{
271 // Simulation uses iPAQ 3660 device buttons 271 // Simulation uses iPAQ 3660 device buttons
272 272
273 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 273 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
274 i_button *ib = ipaq_buttons + i; 274 i_button *ib = ipaq_buttons + i;
275 ODeviceButton b; 275 ODeviceButton b;
276 276
277 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { 277 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) {
278 b. setKeycode ( ib-> code ); 278 b. setKeycode ( ib-> code );
279 b. setUserText ( qApp-> translate ( "Button", ib-> utext )); 279 b. setUserText ( qApp-> translate ( "Button", ib-> utext ));
280 b. setPixmap ( Resource::loadPixmap ( ib-> pix )); 280 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
281 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); 281 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction ));
282 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); 282 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction ));
283 283
284 d-> m_buttons. append ( b ); 284 d-> m_buttons. append ( b );
285 } 285 }
286 } 286 }
287 reloadButtonMapping ( ); 287 reloadButtonMapping ( );
288} 288}
289 289
290ODevice::~ODevice ( ) 290ODevice::~ODevice ( )
291{ 291{
292 delete d; 292 delete d;
293} 293}
294 294
295bool ODevice::setSoftSuspend ( bool /*soft*/ ) 295bool ODevice::setSoftSuspend ( bool /*soft*/ )
296{ 296{
297 return false; 297 return false;
298} 298}
299 299
300//#include <linux/apm_bios.h> 300//#include <linux/apm_bios.h>
301 301
302#define APM_IOC_SUSPEND OD_IO( 'A', 2 ) 302#define APM_IOC_SUSPEND OD_IO( 'A', 2 )
303 303
304 304
305bool ODevice::suspend ( ) 305bool ODevice::suspend ( )
306{ 306{
307 if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend 307 if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend
308 return false; 308 return false;
309 309
310 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices 310 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices
311 return false; 311 return false;
312 312
313 bool res = false; 313 bool res = false;
314 314
315 struct timeval tvs, tvn; 315 struct timeval tvs, tvn;
316 ::gettimeofday ( &tvs, 0 ); 316 ::gettimeofday ( &tvs, 0 );
317 317
318 ::sync ( ); // flush fs caches 318 ::sync ( ); // flush fs caches
319 res = ( ::system ( "apm --suspend" ) == 0 ); 319 res = ( ::system ( "apm --suspend" ) == 0 );
320 320
321 // This is needed because the iPAQ apm implementation is asynchronous and we 321 // This is needed because the iPAQ apm implementation is asynchronous and we
322 // can not be sure when exactly the device is really suspended 322 // can not be sure when exactly the device is really suspended
323 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. 323 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists.
324 324
325 if ( res ) { 325 if ( res ) {
326 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed 326 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
327 ::usleep ( 200 * 1000 ); 327 ::usleep ( 200 * 1000 );
328 ::gettimeofday ( &tvn, 0 ); 328 ::gettimeofday ( &tvn, 0 );
329 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); 329 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
330 } 330 }
331 331
332 return res; 332 return res;
333} 333}
334 334
335//#include <linux/fb.h> better not rely on kernel headers in userspace ... 335//#include <linux/fb.h> better not rely on kernel headers in userspace ...
336 336
337#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 337#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611
338 338
339/* VESA Blanking Levels */ 339/* VESA Blanking Levels */
340#define VESA_NO_BLANKING 0 340#define VESA_NO_BLANKING 0
341#define VESA_VSYNC_SUSPEND 1 341#define VESA_VSYNC_SUSPEND 1
342#define VESA_HSYNC_SUSPEND 2 342#define VESA_HSYNC_SUSPEND 2
343#define VESA_POWERDOWN 3 343#define VESA_POWERDOWN 3
344 344
345 345
346bool ODevice::setDisplayStatus ( bool on ) 346bool ODevice::setDisplayStatus ( bool on )
347{ 347{
348 if ( d-> m_model == Model_Unknown ) 348 if ( d-> m_model == Model_Unknown )
349 return false; 349 return false;
350 350
351 bool res = false; 351 bool res = false;
352 int fd; 352 int fd;
353 353
354 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { 354 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) {
355 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); 355 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 );
356 ::close ( fd ); 356 ::close ( fd );
357 } 357 }
358 return res; 358 return res;
359} 359}
360 360
361bool ODevice::setDisplayBrightness ( int ) 361bool ODevice::setDisplayBrightness ( int )
362{ 362{
363 return false; 363 return false;
364} 364}
365 365
366int ODevice::displayBrightnessResolution ( ) const 366int ODevice::displayBrightnessResolution ( ) const
367{ 367{
368 return 16; 368 return 16;
369} 369}
370 370
371QString ODevice::vendorString ( ) const 371QString ODevice::vendorString ( ) const
372{ 372{
373 return d-> m_vendorstr; 373 return d-> m_vendorstr;
374} 374}
375 375
376OVendor ODevice::vendor ( ) const 376OVendor ODevice::vendor ( ) const
377{ 377{
378 return d-> m_vendor; 378 return d-> m_vendor;
379} 379}
380 380
381QString ODevice::modelString ( ) const 381QString ODevice::modelString ( ) const
382{ 382{
383 return d-> m_modelstr; 383 return d-> m_modelstr;
384} 384}
385 385
386OModel ODevice::model ( ) const 386OModel ODevice::model ( ) const
387{ 387{
388 return d-> m_model; 388 return d-> m_model;
389} 389}
390 390
391QString ODevice::systemString ( ) const 391QString ODevice::systemString ( ) const
392{ 392{
393 return d-> m_systemstr; 393 return d-> m_systemstr;
394} 394}
395 395
396OSystem ODevice::system ( ) const 396OSystem ODevice::system ( ) const
397{ 397{
398 return d-> m_system; 398 return d-> m_system;
399} 399}
400 400
401QString ODevice::systemVersionString ( ) const 401QString ODevice::systemVersionString ( ) const
402{ 402{
403 return d-> m_sysverstr; 403 return d-> m_sysverstr;
404} 404}
405 405
406Transformation ODevice::rotation ( ) const 406Transformation ODevice::rotation ( ) const
407{ 407{
408 return d-> m_rotation; 408 return d-> m_rotation;
409} 409}
410 410
411void ODevice::alarmSound ( ) 411void ODevice::alarmSound ( )
412{ 412{
413#ifndef QT_NO_SOUND 413#ifndef QT_NO_SOUND
414 static Sound snd ( "alarm" ); 414 static Sound snd ( "alarm" );
415 415
416 if ( snd. isFinished ( )) 416 if ( snd. isFinished ( ))
417 snd. play ( ); 417 snd. play ( );
418#endif 418#endif
419} 419}
420 420
421void ODevice::keySound ( ) 421void ODevice::keySound ( )
422{ 422{
423#ifndef QT_NO_SOUND 423#ifndef QT_NO_SOUND
424 static Sound snd ( "keysound" ); 424 static Sound snd ( "keysound" );
425 425
426 if ( snd. isFinished ( )) 426 if ( snd. isFinished ( ))
427 snd. play ( ); 427 snd. play ( );
428#endif 428#endif
429} 429}
430 430
431void ODevice::touchSound ( ) 431void ODevice::touchSound ( )
432{ 432{
433 433
434#ifndef QT_NO_SOUND 434#ifndef QT_NO_SOUND
435 static Sound snd ( "touchsound" ); 435 static Sound snd ( "touchsound" );
436 436
437 if ( snd. isFinished ( )) 437 if ( snd. isFinished ( ))
438 snd. play ( ); 438 snd. play ( );
439#endif 439#endif
440} 440}
441 441
442 442
443QValueList <OLed> ODevice::ledList ( ) const 443QValueList <OLed> ODevice::ledList ( ) const
444{ 444{
445 return QValueList <OLed> ( ); 445 return QValueList <OLed> ( );
446} 446}
447 447
448QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const 448QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const
449{ 449{
450 return QValueList <OLedState> ( ); 450 return QValueList <OLedState> ( );
451} 451}
452 452
453OLedState ODevice::ledState ( OLed /*which*/ ) const 453OLedState ODevice::ledState ( OLed /*which*/ ) const
454{ 454{
455 return Led_Off; 455 return Led_Off;
456} 456}
457 457
458bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ ) 458bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ )
459{ 459{
460 return false; 460 return false;
461} 461}
462 462
463bool ODevice::hasLightSensor ( ) const 463bool ODevice::hasLightSensor ( ) const
464{ 464{
465 return false; 465 return false;
466} 466}
467 467
468int ODevice::readLightSensor ( ) 468int ODevice::readLightSensor ( )
469{ 469{
470 return -1; 470 return -1;
471} 471}
472 472
473int ODevice::lightSensorResolution ( ) const 473int ODevice::lightSensorResolution ( ) const
474{ 474{
475 return 0; 475 return 0;
476} 476}
477 477
478const QValueList <ODeviceButton> &ODevice::buttons ( ) const 478const QValueList <ODeviceButton> &ODevice::buttons ( ) const
479{ 479{
480 return d-> m_buttons; 480 return d-> m_buttons;
481} 481}
482 482
483uint ODevice::buttonHoldTime ( ) const 483uint ODevice::buttonHoldTime ( ) const
484{ 484{
485 return d-> m_holdtime; 485 return d-> m_holdtime;
486} 486}
487 487
488const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) 488const ODeviceButton *ODevice::buttonForKeycode ( ushort code )
489{ 489{
490 for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons. begin ( ); it != d-> m_buttons. end ( ); ++it ) { 490 for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons. begin ( ); it != d-> m_buttons. end ( ); ++it ) {
491 if ( (*it). keycode ( ) == code ) 491 if ( (*it). keycode ( ) == code )
492 return &(*it); 492 return &(*it);
493 } 493 }
494 return 0; 494 return 0;
495} 495}
496 496
497void ODevice::reloadButtonMapping ( ) 497void ODevice::reloadButtonMapping ( )
498{ 498{
499 Config cfg ( "ButtonSettings" ); 499 Config cfg ( "ButtonSettings" );
500 500
501 for ( uint i = 0; i < d-> m_buttons. count ( ); i++ ) { 501 for ( uint i = 0; i < d-> m_buttons. count ( ); i++ ) {
502 ODeviceButton &b = d-> m_buttons [i]; 502 ODeviceButton &b = d-> m_buttons [i];
503 QString group = "Button" + QString::number ( i ); 503 QString group = "Button" + QString::number ( i );
504 504
505 QCString pch, hch; 505 QCString pch, hch;
506 QCString pm, hm; 506 QCString pm, hm;
507 QByteArray pdata, hdata; 507 QByteArray pdata, hdata;
508 508
509 if ( cfg. hasGroup ( group )) { 509 if ( cfg. hasGroup ( group )) {
510 cfg. setGroup ( group ); 510 cfg. setGroup ( group );
511 pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( ); 511 pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( );
512 pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( ); 512 pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( );
513 // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); 513 // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" ));
514 514
515 hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( ); 515 hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( );
516 hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( ); 516 hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( );
517 // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); 517 // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" ));
518 } 518 }
519 519
520 b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); 520 b. setPressedAction ( OQCopMessage ( pch, pm, pdata ));
521 b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); 521 b. setHeldAction ( OQCopMessage ( hch, hm, hdata ));
522 } 522 }
523} 523}
524 524
525void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) 525void ODevice::remapPressedAction ( int button, const OQCopMessage &action )
526{ 526{
527 if ( button >= (int) d-> m_buttons. count ( )) 527 if ( button >= (int) d-> m_buttons. count ( ))
528 return; 528 return;
529 529
530 ODeviceButton &b = d-> m_buttons [button]; 530 ODeviceButton &b = d-> m_buttons [button];
531 b. setPressedAction ( action ); 531 b. setPressedAction ( action );
532 532
533 Config buttonFile ( "ButtonSettings" ); 533 Config buttonFile ( "ButtonSettings" );
534 buttonFile. setGroup ( "Button" + QString::number ( button )); 534 buttonFile. setGroup ( "Button" + QString::number ( button ));
535 buttonFile. writeEntry ( "PressedActionChannel", (const char*) b. pressedAction ( ). channel ( )); 535 buttonFile. writeEntry ( "PressedActionChannel", (const char*) b. pressedAction ( ). channel ( ));
536 buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( )); 536 buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( ));
537 537
538 //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( ))); 538 //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( )));
539 539
540 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 540 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
541} 541}
542 542
543void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) 543void ODevice::remapHeldAction ( int button, const OQCopMessage &action )
544{ 544{
545 if ( button >= (int) d-> m_buttons. count ( )) 545 if ( button >= (int) d-> m_buttons. count ( ))
546 return; 546 return;
547 547
548 ODeviceButton &b = d-> m_buttons [button]; 548 ODeviceButton &b = d-> m_buttons [button];
549 b. setHeldAction ( action ); 549 b. setHeldAction ( action );
550 550
551 Config buttonFile ( "ButtonSettings" ); 551 Config buttonFile ( "ButtonSettings" );
552 buttonFile. setGroup ( "Button" + QString::number ( button )); 552 buttonFile. setGroup ( "Button" + QString::number ( button ));
553 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( )); 553 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( ));
554 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( )); 554 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( ));
555 555
556 //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( ))); 556 //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( )));
557 557
558 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 558 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
559} 559}
560 560
561 561
562 562
563 563
564/************************************************** 564/**************************************************
565 * 565 *
566 * iPAQ 566 * iPAQ
567 * 567 *
568 **************************************************/ 568 **************************************************/
569 569
570void iPAQ::init ( ) 570void iPAQ::init ( )
571{ 571{
572 d-> m_vendorstr = "HP"; 572 d-> m_vendorstr = "HP";
573 d-> m_vendor = Vendor_HP; 573 d-> m_vendor = Vendor_HP;
574 574
575 QFile f ( "/proc/hal/model" ); 575 QFile f ( "/proc/hal/model" );
576 576
577 if ( f. open ( IO_ReadOnly )) { 577 if ( f. open ( IO_ReadOnly )) {
578 QTextStream ts ( &f ); 578 QTextStream ts ( &f );
579 579
580 d-> m_modelstr = "H" + ts. readLine ( ); 580 d-> m_modelstr = "H" + ts. readLine ( );
581 581
582 if ( d-> m_modelstr == "H3100" ) 582 if ( d-> m_modelstr == "H3100" )
583 d-> m_model = Model_iPAQ_H31xx; 583 d-> m_model = Model_iPAQ_H31xx;
584 else if ( d-> m_modelstr == "H3600" ) 584 else if ( d-> m_modelstr == "H3600" )
585 d-> m_model = Model_iPAQ_H36xx; 585 d-> m_model = Model_iPAQ_H36xx;
586 else if ( d-> m_modelstr == "H3700" ) 586 else if ( d-> m_modelstr == "H3700" )
587 d-> m_model = Model_iPAQ_H37xx; 587 d-> m_model = Model_iPAQ_H37xx;
588 else if ( d-> m_modelstr == "H3800" ) 588 else if ( d-> m_modelstr == "H3800" )
589 d-> m_model = Model_iPAQ_H38xx; 589 d-> m_model = Model_iPAQ_H38xx;
590 else if ( d-> m_modelstr == "H3900" ) 590 else if ( d-> m_modelstr == "H3900" )
591 d-> m_model = Model_iPAQ_H39xx; 591 d-> m_model = Model_iPAQ_H39xx;
592 else 592 else
593 d-> m_model = Model_Unknown; 593 d-> m_model = Model_Unknown;
594 594
595 f. close ( ); 595 f. close ( );
596 } 596 }
597 597
598 switch ( d-> m_model ) { 598 switch ( d-> m_model ) {
599 case Model_iPAQ_H31xx: 599 case Model_iPAQ_H31xx:
600 case Model_iPAQ_H38xx: 600 case Model_iPAQ_H38xx:
601 d-> m_rotation = Rot90; 601 d-> m_rotation = Rot90;
602 break; 602 break;
603 case Model_iPAQ_H36xx: 603 case Model_iPAQ_H36xx:
604 case Model_iPAQ_H37xx: 604 case Model_iPAQ_H37xx:
605 case Model_iPAQ_H39xx: 605 case Model_iPAQ_H39xx:
606 default: 606 default:
607 d-> m_rotation = Rot270; 607 d-> m_rotation = Rot270;
608 break; 608 break;
609 } 609 }
610 610
611 f. setName ( "/etc/familiar-version" ); 611 f. setName ( "/etc/familiar-version" );
612 if ( f. open ( IO_ReadOnly )) { 612 if ( f. open ( IO_ReadOnly )) {
613 d-> m_systemstr = "Familiar"; 613 d-> m_systemstr = "Familiar";
614 d-> m_system = System_Familiar; 614 d-> m_system = System_Familiar;
615 615
616 QTextStream ts ( &f ); 616 QTextStream ts ( &f );
617 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 617 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
618 618
619 f. close ( ); 619 f. close ( );
620 } 620 }
621 621
622 m_leds [0] = m_leds [1] = Led_Off; 622 m_leds [0] = m_leds [1] = Led_Off;
623 623
624 m_power_timer = 0; 624 m_power_timer = 0;
625 625
626 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 626 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
627 i_button *ib = ipaq_buttons + i; 627 i_button *ib = ipaq_buttons + i;
628 ODeviceButton b; 628 ODeviceButton b;
629 629
630 if (( ib-> model & d-> m_model ) == d-> m_model ) { 630 if (( ib-> model & d-> m_model ) == d-> m_model ) {
631 b. setKeycode ( ib-> code ); 631 b. setKeycode ( ib-> code );
632 b. setUserText ( qApp-> translate ( "Button", ib-> utext )); 632 b. setUserText ( qApp-> translate ( "Button", ib-> utext ));
633 b. setPixmap ( Resource::loadPixmap ( ib-> pix )); 633 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
634 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); 634 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction ));
635 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); 635 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction ));
636 636
637 d-> m_buttons. append ( b ); 637 d-> m_buttons. append ( b );
638 } 638 }
639 } 639 }
640 reloadButtonMapping ( ); 640 reloadButtonMapping ( );
641 641
642 if ( d-> m_qwsserver ) 642 if ( d-> m_qwsserver )
643 QWSServer::setKeyboardFilter ( this ); 643 QWSServer::setKeyboardFilter ( this );
644} 644}
645 645
646//#include <linux/h3600_ts.h> // including kernel headers is evil ... 646//#include <linux/h3600_ts.h> // including kernel headers is evil ...
647 647
648typedef struct { 648typedef struct {
649 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ 649 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */
650 unsigned char TotalTime; /* Units of 5 seconds */ 650 unsigned char TotalTime; /* Units of 5 seconds */
651 unsigned char OnTime; /* units of 100m/s */ 651 unsigned char OnTime; /* units of 100m/s */
652 unsigned char OffTime; /* units of 100m/s */ 652 unsigned char OffTime; /* units of 100m/s */
653} LED_IN; 653} LED_IN;
654 654
655typedef struct { 655typedef struct {
656 unsigned char mode; 656 unsigned char mode;
657 unsigned char pwr; 657 unsigned char pwr;
658 unsigned char brightness; 658 unsigned char brightness;
659} FLITE_IN; 659} FLITE_IN;
660 660
661#define LED_ON OD_IOW( 'f', 5, LED_IN ) 661#define LED_ON OD_IOW( 'f', 5, LED_IN )
662#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) 662#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN )
663 663
664 664
665QValueList <OLed> iPAQ::ledList ( ) const 665QValueList <OLed> iPAQ::ledList ( ) const
666{ 666{
667 QValueList <OLed> vl; 667 QValueList <OLed> vl;
668 vl << Led_Power; 668 vl << Led_Power;
669 669
670 if ( d-> m_model == Model_iPAQ_H38xx ) 670 if ( d-> m_model == Model_iPAQ_H38xx )
671 vl << Led_BlueTooth; 671 vl << Led_BlueTooth;
672 return vl; 672 return vl;
673} 673}
674 674
675QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const 675QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const
676{ 676{
677 QValueList <OLedState> vl; 677 QValueList <OLedState> vl;
678 678
679 if ( l == Led_Power ) 679 if ( l == Led_Power )
680 vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; 680 vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast;
681 else if ( l == Led_BlueTooth && d-> m_model == Model_iPAQ_H38xx ) 681 else if ( l == Led_BlueTooth && d-> m_model == Model_iPAQ_H38xx )
682 vl << Led_Off; // << Led_On << ??? 682 vl << Led_Off; // << Led_On << ???
683 683
684 return vl; 684 return vl;
685} 685}
686 686
687OLedState iPAQ::ledState ( OLed l ) const 687OLedState iPAQ::ledState ( OLed l ) const
688 { 688 {
689 switch ( l ) { 689 switch ( l ) {
690 case Led_Power: 690 case Led_Power:
691 return m_leds [0]; 691 return m_leds [0];
692 case Led_BlueTooth: 692 case Led_BlueTooth:
693 return m_leds [1]; 693 return m_leds [1];
694 default: 694 default:
695 return Led_Off; 695 return Led_Off;
696 } 696 }
697} 697}
698 698
699bool iPAQ::setLedState ( OLed l, OLedState st ) 699bool iPAQ::setLedState ( OLed l, OLedState st )
700{ 700{
701 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK ); 701 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK );
702 702
703 if ( l == Led_Power ) { 703 if ( l == Led_Power ) {
704 if ( fd >= 0 ) { 704 if ( fd >= 0 ) {
705 LED_IN leds; 705 LED_IN leds;
706 ::memset ( &leds, 0, sizeof( leds )); 706 ::memset ( &leds, 0, sizeof( leds ));
707 leds. TotalTime = 0; 707 leds. TotalTime = 0;
708 leds. OnTime = 0; 708 leds. OnTime = 0;
709 leds. OffTime = 1; 709 leds. OffTime = 1;
710 leds. OffOnBlink = 2; 710 leds. OffOnBlink = 2;
711 711
712 switch ( st ) { 712 switch ( st ) {
713 case Led_Off : leds. OffOnBlink = 0; break; 713 case Led_Off : leds. OffOnBlink = 0; break;
714 case Led_On : leds. OffOnBlink = 1; break; 714 case Led_On : leds. OffOnBlink = 1; break;
715 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; 715 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break;
716 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; 716 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break;
717 } 717 }
718 718
719 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { 719 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) {
720 m_leds [0] = st; 720 m_leds [0] = st;
721 return true; 721 return true;
722 } 722 }
723 } 723 }
724 } 724 }
725 return false; 725 return false;
726} 726}
727 727
728 728
729bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) 729bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
730{ 730{
731 int newkeycode = keycode; 731 int newkeycode = keycode;
732 732
733 switch ( keycode ) { 733 switch ( keycode ) {
734 // H38xx/H39xx have no "Q" key anymore - this is now the Mail key 734 // H38xx/H39xx have no "Q" key anymore - this is now the Mail key
735 case HardKey_Menu: { 735 case HardKey_Menu: {
736 if (( d-> m_model == Model_iPAQ_H38xx ) || 736 if (( d-> m_model == Model_iPAQ_H38xx ) ||
737 ( d-> m_model == Model_iPAQ_H39xx )) { 737 ( d-> m_model == Model_iPAQ_H39xx )) {
738 newkeycode = HardKey_Mail; 738 newkeycode = HardKey_Mail;
739 } 739 }
740 break; 740 break;
741 } 741 }
742 742
743 // Rotate cursor keys 180° 743 // Rotate cursor keys 180°
744 case Key_Left : 744 case Key_Left :
745 case Key_Right: 745 case Key_Right:
746 case Key_Up : 746 case Key_Up :
747 case Key_Down : { 747 case Key_Down : {
748 if (( d-> m_model == Model_iPAQ_H31xx ) || 748 if (( d-> m_model == Model_iPAQ_H31xx ) ||
749 ( d-> m_model == Model_iPAQ_H38xx )) { 749 ( d-> m_model == Model_iPAQ_H38xx )) {
750 newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4; 750 newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4;
751 } 751 }
752 break; 752 break;
753 } 753 }
754 754
755 // map Power Button short/long press to F34/F35 755 // map Power Button short/long press to F34/F35
756 case Key_SysReq: { 756 case Key_SysReq: {
757 if ( isPress ) { 757 if ( isPress ) {
758 if ( m_power_timer ) 758 if ( m_power_timer )
759 killTimer ( m_power_timer ); 759 killTimer ( m_power_timer );
760 m_power_timer = startTimer ( 500 ); 760 m_power_timer = startTimer ( 500 );
761 } 761 }
762 else if ( m_power_timer ) { 762 else if ( m_power_timer ) {
763 killTimer ( m_power_timer ); 763 killTimer ( m_power_timer );
764 m_power_timer = 0; 764 m_power_timer = 0;
765 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); 765 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false );
766 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); 766 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false );
767 } 767 }
768 newkeycode = Key_unknown; 768 newkeycode = Key_unknown;
769 break; 769 break;
770 } 770 }
771 } 771 }
772 772
773 if ( newkeycode != keycode ) { 773 if ( newkeycode != keycode ) {
774 if ( newkeycode != Key_unknown ) 774 if ( newkeycode != Key_unknown )
775 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); 775 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
776 return true; 776 return true;
777 } 777 }
778 else 778 else
779 return false; 779 return false;
780} 780}
781 781
782void iPAQ::timerEvent ( QTimerEvent * ) 782void iPAQ::timerEvent ( QTimerEvent * )
783{ 783{
784 killTimer ( m_power_timer ); 784 killTimer ( m_power_timer );
785 m_power_timer = 0; 785 m_power_timer = 0;
786 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); 786 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false );
787 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); 787 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false );
788} 788}
789 789
790 790
791void iPAQ::alarmSound ( ) 791void iPAQ::alarmSound ( )
792{ 792{
793#ifndef QT_NO_SOUND 793#ifndef QT_NO_SOUND
794 static Sound snd ( "alarm" ); 794 static Sound snd ( "alarm" );
795 int fd; 795 int fd;
796 int vol; 796 int vol;
797 bool vol_reset = false; 797 bool vol_reset = false;
798 798
799 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { 799 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) {
800 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { 800 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
801 Config cfg ( "qpe" ); 801 Config cfg ( "qpe" );
802 cfg. setGroup ( "Volume" ); 802 cfg. setGroup ( "Volume" );
803 803
804 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); 804 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
805 if ( volalarm < 0 ) 805 if ( volalarm < 0 )
806 volalarm = 0; 806 volalarm = 0;
807 else if ( volalarm > 100 ) 807 else if ( volalarm > 100 )
808 volalarm = 100; 808 volalarm = 100;
809 volalarm |= ( volalarm << 8 ); 809 volalarm |= ( volalarm << 8 );
810 810
811 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) 811 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
812 vol_reset = true; 812 vol_reset = true;
813 } 813 }
814 } 814 }
815 815
816 snd. play ( ); 816 snd. play ( );
817 while ( !snd. isFinished ( )) 817 while ( !snd. isFinished ( ))
818 qApp-> processEvents ( ); 818 qApp-> processEvents ( );
819 819
820 if ( fd >= 0 ) { 820 if ( fd >= 0 ) {
821 if ( vol_reset ) 821 if ( vol_reset )
822 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); 822 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
823 ::close ( fd ); 823 ::close ( fd );
824 } 824 }
825#endif 825#endif
826} 826}
827 827
828 828
829bool iPAQ::setSoftSuspend ( bool soft ) 829bool iPAQ::setSoftSuspend ( bool soft )
830{ 830{
831 bool res = false; 831 bool res = false;
832 int fd; 832 int fd;
833 833
834 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { 834 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) {
835 if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) 835 if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 )
836 res = true; 836 res = true;
837 else 837 else
838 ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); 838 ::perror ( "write to /proc/sys/ts/suspend_button_mode" );
839 839
840 ::close ( fd ); 840 ::close ( fd );
841 } 841 }
842 else 842 else
843 ::perror ( "/proc/sys/ts/suspend_button_mode" ); 843 ::perror ( "/proc/sys/ts/suspend_button_mode" );
844 844
845 return res; 845 return res;
846} 846}
847 847
848 848
849bool iPAQ::setDisplayBrightness ( int bright ) 849bool iPAQ::setDisplayBrightness ( int bright )
850{ 850{
851 bool res = false; 851 bool res = false;
852 int fd; 852 int fd;
853 853
854 if ( bright > 255 ) 854 if ( bright > 255 )
855 bright = 255; 855 bright = 255;
856 if ( bright < 0 ) 856 if ( bright < 0 )
857 bright = 0; 857 bright = 0;
858 858
859 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { 859 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
860 FLITE_IN bl; 860 FLITE_IN bl;
861 bl. mode = 1; 861 bl. mode = 1;
862 bl. pwr = bright ? 1 : 0; 862 bl. pwr = bright ? 1 : 0;
863 bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255; 863 bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255;
864 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); 864 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 );
865 ::close ( fd ); 865 ::close ( fd );
866 } 866 }
867 return res; 867 return res;
868} 868}
869 869
870int iPAQ::displayBrightnessResolution ( ) const 870int iPAQ::displayBrightnessResolution ( ) const
871{ 871{
872 switch ( model ( )) { 872 switch ( model ( )) {
873 case Model_iPAQ_H31xx: 873 case Model_iPAQ_H31xx:
874 case Model_iPAQ_H36xx: 874 case Model_iPAQ_H36xx:
875 case Model_iPAQ_H37xx: 875 case Model_iPAQ_H37xx:
876 return 128; // really 256, but >128 could damage the LCD 876 return 128; // really 256, but >128 could damage the LCD
877 877
878 case Model_iPAQ_H38xx: 878 case Model_iPAQ_H38xx:
879 case Model_iPAQ_H39xx: 879 case Model_iPAQ_H39xx:
880 return 64; 880 return 64;
881 881
882 default: 882 default:
883 return 2; 883 return 2;
884 } 884 }
885} 885}
886 886
887 887
888bool iPAQ::hasLightSensor ( ) const 888bool iPAQ::hasLightSensor ( ) const
889{ 889{
890 return true; 890 return true;
891} 891}
892 892
893int iPAQ::readLightSensor ( ) 893int iPAQ::readLightSensor ( )
894{ 894{
895 int fd; 895 int fd;
896 int val = -1; 896 int val = -1;
897 897
898 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { 898 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) {
899 char buffer [8]; 899 char buffer [8];
900 900
901 if ( ::read ( fd, buffer, 5 ) == 5 ) { 901 if ( ::read ( fd, buffer, 5 ) == 5 ) {
902 char *endptr; 902 char *endptr;
903 903
904 buffer [4] = 0; 904 buffer [4] = 0;
905 val = ::strtol ( buffer + 2, &endptr, 16 ); 905 val = ::strtol ( buffer + 2, &endptr, 16 );
906 906
907 if ( *endptr != 0 ) 907 if ( *endptr != 0 )
908 val = -1; 908 val = -1;
909 } 909 }
910 ::close ( fd ); 910 ::close ( fd );
911 } 911 }
912 912
913 return val; 913 return val;
914} 914}
915 915
916int iPAQ::lightSensorResolution ( ) const 916int iPAQ::lightSensorResolution ( ) const
917{ 917{
918 return 256; 918 return 256;
919} 919}
920 920
921/************************************************** 921/**************************************************
922 * 922 *
923 * Zaurus 923 * Zaurus
924 * 924 *
925 **************************************************/ 925 **************************************************/
926 926
927 927
928 928
929void Zaurus::init ( ) 929void Zaurus::init ( )
930{ 930{
931 d-> m_vendorstr = "Sharp"; 931 d-> m_vendorstr = "Sharp";
932 d-> m_vendor = Vendor_Sharp; 932 d-> m_vendor = Vendor_Sharp;
933 933
934 QFile f ( "/proc/filesystems" ); 934 QFile f ( "/proc/filesystems" );
935 935
936 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { 936 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) {
937 d-> m_vendorstr = "OpenZaurus Team"; 937 d-> m_vendorstr = "OpenZaurus Team";
938 d-> m_systemstr = "OpenZaurus"; 938 d-> m_systemstr = "OpenZaurus";
939 d-> m_system = System_OpenZaurus; 939 d-> m_system = System_OpenZaurus;
940 940
941 f. close ( ); 941 f. close ( );
942 942
943 f. setName ( "/etc/oz_version" ); 943 f. setName ( "/etc/oz_version" );
944 if ( f. open ( IO_ReadOnly )) { 944 if ( f. open ( IO_ReadOnly )) {
945 QTextStream ts ( &f ); 945 QTextStream ts ( &f );
946 d-> m_sysverstr = ts. readLine ( );//. mid ( 10 ); 946 d-> m_sysverstr = ts. readLine ( );//. mid ( 10 );
947 f. close ( ); 947 f. close ( );
948 } 948 }
949 } 949 }
950 else { 950 else {
951 d-> m_systemstr = "Zaurus"; 951 d-> m_systemstr = "Zaurus";
952 d-> m_system = System_Zaurus; 952 d-> m_system = System_Zaurus;
953 } 953 }
954 954
955 f. setName ( "/proc/deviceinfo/product" ); 955 f. setName ( "/proc/deviceinfo/product" );
956 if ( f. open ( IO_ReadOnly ) ) { 956 if ( f. open ( IO_ReadOnly ) ) {
957 QTextStream ts ( &f ); 957 QTextStream ts ( &f );
958 QString model = ts. readLine ( ); 958 QString model = ts. readLine ( );
959 f. close ( ); 959 f. close ( );
960 960
961 d-> m_modelstr = QString("Zaurus ") + model; 961 d-> m_modelstr = QString("Zaurus ") + model;
962 if ( model == "SL-5500" ) 962 if ( model == "SL-5500" )
963 d-> m_model = Model_Zaurus_SL5500; 963 d-> m_model = Model_Zaurus_SL5500;
964 else if ( model == "SL-C700" ) 964 else if ( model == "SL-C700" )
965 d-> m_model = Model_Zaurus_SLC700; 965 d-> m_model = Model_Zaurus_SLC700;
966 else if ( model == "SL-A300" ) 966 else if ( model == "SL-A300" )
967 d-> m_model = Model_Zaurus_SLA300; 967 d-> m_model = Model_Zaurus_SLA300;
968 else if ( model == "SL-B600" || model == "SL-5600" ) 968 else if ( model == "SL-B600" || model == "SL-5600" )
969 d-> m_model = Model_Zaurus_SLB600; 969 d-> m_model = Model_Zaurus_SLB600;
970 else 970 else
971 d-> m_model = Model_Zaurus_SL5000; 971 d-> m_model = Model_Zaurus_SL5000;
972 } 972 }
973 else { 973 else {
974 d-> m_model = Model_Zaurus_SL5000; 974 d-> m_model = Model_Zaurus_SL5000;
975 d-> m_modelstr = "Zaurus (model unknown)"; 975 d-> m_modelstr = "Zaurus (model unknown)";
976 } 976 }
977 977
978 switch ( d-> m_model ) { 978 switch ( d-> m_model ) {
979 case Model_Zaurus_SLC700: 979 case Model_Zaurus_SLC700:
980 /* note for C700, we must check the display rotation 980 /* note for C700, we must check the display rotation
981 * sensor to set an appropriate value 981 * sensor to set an appropriate value
982 */ 982 */
983 case Model_Zaurus_SLA300: 983 case Model_Zaurus_SLA300:
984 case Model_Zaurus_SLB600: 984 case Model_Zaurus_SLB600:
985 case Model_Zaurus_SL5500: 985 case Model_Zaurus_SL5500:
986 case Model_Zaurus_SL5000: 986 case Model_Zaurus_SL5000:
987 default: 987 default:
988 d-> m_rotation = Rot270; 988 d-> m_rotation = Rot270;
989 break; 989 break;
990 } 990 }
991 991
992 for ( uint i = 0; i < ( sizeof( z_buttons ) / sizeof( z_button )); i++ ) { 992 for ( uint i = 0; i < ( sizeof( z_buttons ) / sizeof( z_button )); i++ ) {
993 z_button *zb = z_buttons + i; 993 z_button *zb = z_buttons + i;
994 ODeviceButton b; 994 ODeviceButton b;
995 995
996 b. setKeycode ( zb-> code ); 996 b. setKeycode ( zb-> code );
997 b. setUserText ( qApp-> translate ( "Button", zb-> utext )); 997 b. setUserText ( qApp-> translate ( "Button", zb-> utext ));
998 b. setPixmap ( Resource::loadPixmap ( zb-> pix )); 998 b. setPixmap ( Resource::loadPixmap ( zb-> pix ));
999 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb-> fpressedservice ), zb-> fpressedaction )); 999 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb-> fpressedservice ), zb-> fpressedaction ));
1000 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb-> fheldservice ), zb-> fheldaction )); 1000 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb-> fheldservice ), zb-> fheldaction ));
1001 1001
1002 d-> m_buttons. append ( b ); 1002 d-> m_buttons. append ( b );
1003 } 1003 }
1004 reloadButtonMapping ( ); 1004 reloadButtonMapping ( );
1005 1005
1006 m_leds [0] = Led_Off; 1006 m_leds [0] = Led_Off;
1007} 1007}
1008 1008
1009#include <unistd.h> 1009#include <unistd.h>
1010#include <fcntl.h> 1010#include <fcntl.h>
1011#include <sys/ioctl.h> 1011#include <sys/ioctl.h>
1012 1012
1013//#include <asm/sharp_char.h> // including kernel headers is evil ... 1013//#include <asm/sharp_char.h> // including kernel headers is evil ...
1014 1014
1015#define SHARP_DEV_IOCTL_COMMAND_START 0x5680 1015#define SHARP_DEV_IOCTL_COMMAND_START 0x5680
1016 1016
1017 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 1017 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
1018#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 1018#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
1019 1019
1020#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 1020#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
1021#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 1021#define SHARP_BUZ_KEYSOUND 2 /* key sound */
1022#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 1022#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
1023 1023
1024/* --- for SHARP_BUZZER device --- */ 1024/* --- for SHARP_BUZZER device --- */
1025 1025
1026 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 1026 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
1027//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 1027//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
1028 1028
1029#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) 1029#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1)
1030#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2) 1030#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2)
1031#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3) 1031#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3)
1032#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4) 1032#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4)
1033#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5) 1033#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5)
1034 1034
1035//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 1035//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
1036//#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 1036//#define SHARP_BUZ_KEYSOUND 2 /* key sound */
1037 1037
1038//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */ 1038//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */
1039//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */ 1039//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */
1040//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */ 1040//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */
1041//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */ 1041//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */
1042//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */ 1042//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */
1043//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */ 1043//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */
1044//#define SHARP_PDA_APPSTART 9 /* application start */ 1044//#define SHARP_PDA_APPSTART 9 /* application start */
1045//#define SHARP_PDA_APPQUIT 10 /* application ends */ 1045//#define SHARP_PDA_APPQUIT 10 /* application ends */
1046 1046
1047//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 1047//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
1048//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */ 1048//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */
1049//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */ 1049//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */
1050//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */ 1050//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */
1051// 1051//
1052 1052
1053 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 1053 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
1054#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1) 1054#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1)
1055 1055
1056typedef struct sharp_led_status { 1056typedef struct sharp_led_status {
1057 int which; /* select which LED status is wanted. */ 1057 int which; /* select which LED status is wanted. */
1058 int status; /* set new led status if you call SHARP_LED_SETSTATUS */ 1058 int status; /* set new led status if you call SHARP_LED_SETSTATUS */
1059} sharp_led_status; 1059} sharp_led_status;
1060 1060
1061#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */ 1061#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */
1062 1062
1063#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */ 1063#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */
1064#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */ 1064#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */
1065#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */ 1065#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */
1066 1066
1067// #include <asm/sharp_apm.h> // including kernel headers is evil ... 1067// #include <asm/sharp_apm.h> // including kernel headers is evil ...
1068 1068
1069#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int ) 1069#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int )
1070#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int ) 1070#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int )
1071#define APM_EVT_POWER_BUTTON (1 << 0) 1071#define APM_EVT_POWER_BUTTON (1 << 0)
1072 1072
1073#define FL_IOCTL_STEP_CONTRAST 100 1073#define FL_IOCTL_STEP_CONTRAST 100
1074 1074
1075 1075
1076void Zaurus::buzzer ( int sound ) 1076void Zaurus::buzzer ( int sound )
1077{ 1077{
1078 static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK ); 1078 static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK );
1079 1079
1080 if ( fd >= 0 ) 1080 if ( fd >= 0 )
1081 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); 1081 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound );
1082} 1082}
1083 1083
1084 1084
1085void Zaurus::alarmSound ( ) 1085void Zaurus::alarmSound ( )
1086{ 1086{
1087 buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); 1087 buzzer ( SHARP_BUZ_SCHEDULE_ALARM );
1088} 1088}
1089 1089
1090void Zaurus::touchSound ( ) 1090void Zaurus::touchSound ( )
1091{ 1091{
1092 buzzer ( SHARP_BUZ_TOUCHSOUND ); 1092 buzzer ( SHARP_BUZ_TOUCHSOUND );
1093} 1093}
1094 1094
1095void Zaurus::keySound ( ) 1095void Zaurus::keySound ( )
1096{ 1096{
1097 buzzer ( SHARP_BUZ_KEYSOUND ); 1097 buzzer ( SHARP_BUZ_KEYSOUND );
1098} 1098}
1099 1099
1100 1100
1101QValueList <OLed> Zaurus::ledList ( ) const 1101QValueList <OLed> Zaurus::ledList ( ) const
1102{ 1102{
1103 QValueList <OLed> vl; 1103 QValueList <OLed> vl;
1104 vl << Led_Mail; 1104 vl << Led_Mail;
1105 return vl; 1105 return vl;
1106} 1106}
1107 1107
1108QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const 1108QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const
1109{ 1109{
1110 QValueList <OLedState> vl; 1110 QValueList <OLedState> vl;
1111 1111
1112 if ( l == Led_Mail ) 1112 if ( l == Led_Mail )
1113 vl << Led_Off << Led_On << Led_BlinkSlow; 1113 vl << Led_Off << Led_On << Led_BlinkSlow;
1114 return vl; 1114 return vl;
1115} 1115}
1116 1116
1117OLedState Zaurus::ledState ( OLed which ) const 1117OLedState Zaurus::ledState ( OLed which ) const
1118{ 1118{
1119 if ( which == Led_Mail ) 1119 if ( which == Led_Mail )
1120 return m_leds [0]; 1120 return m_leds [0];
1121 else 1121 else
1122 return Led_Off; 1122 return Led_Off;
1123} 1123}
1124 1124
1125bool Zaurus::setLedState ( OLed which, OLedState st ) 1125bool Zaurus::setLedState ( OLed which, OLedState st )
1126{ 1126{
1127 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); 1127 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK );
1128 1128
1129 if ( which == Led_Mail ) { 1129 if ( which == Led_Mail ) {
1130 if ( fd >= 0 ) { 1130 if ( fd >= 0 ) {
1131 struct sharp_led_status leds; 1131 struct sharp_led_status leds;
1132 ::memset ( &leds, 0, sizeof( leds )); 1132 ::memset ( &leds, 0, sizeof( leds ));
1133 leds. which = SHARP_LED_MAIL_EXISTS; 1133 leds. which = SHARP_LED_MAIL_EXISTS;
1134 bool ok = true; 1134 bool ok = true;
1135 1135
1136 switch ( st ) { 1136 switch ( st ) {
1137 case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; 1137 case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break;
1138 case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; 1138 case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break;
1139 case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break; 1139 case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break;
1140 default : ok = false; 1140 default : ok = false;
1141 } 1141 }
1142 1142
1143 if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) { 1143 if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) {
1144 m_leds [0] = st; 1144 m_leds [0] = st;
1145 return true; 1145 return true;
1146 } 1146 }
1147 } 1147 }
1148 } 1148 }
1149 return false; 1149 return false;
1150} 1150}
1151 1151
1152bool Zaurus::setSoftSuspend ( bool soft ) 1152bool Zaurus::setSoftSuspend ( bool soft )
1153{ 1153{
1154 bool res = false; 1154 bool res = false;
1155 int fd; 1155 int fd;
1156 1156
1157 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || 1157 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
1158 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { 1158 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
1159 1159
1160 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources 1160 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources
1161 1161
1162 if ( sources >= 0 ) { 1162 if ( sources >= 0 ) {
1163 if ( soft ) 1163 if ( soft )
1164 sources &= ~APM_EVT_POWER_BUTTON; 1164 sources &= ~APM_EVT_POWER_BUTTON;
1165 else 1165 else
1166 sources |= APM_EVT_POWER_BUTTON; 1166 sources |= APM_EVT_POWER_BUTTON;
1167 1167
1168 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources 1168 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources
1169 res = true; 1169 res = true;
1170 else 1170 else
1171 perror ( "APM_IOCGEVTSRC" ); 1171 perror ( "APM_IOCGEVTSRC" );
1172 } 1172 }
1173 else 1173 else
1174 perror ( "APM_IOCGEVTSRC" ); 1174 perror ( "APM_IOCGEVTSRC" );
1175 1175
1176 ::close ( fd ); 1176 ::close ( fd );
1177 } 1177 }
1178 else 1178 else
1179 perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); 1179 perror ( "/dev/apm_bios or /dev/misc/apm_bios" );
1180 1180
1181 return res; 1181 return res;
1182} 1182}
1183 1183
1184 1184
1185bool Zaurus::setDisplayBrightness ( int bright ) 1185bool Zaurus::setDisplayBrightness ( int bright )
1186{ 1186{
1187 bool res = false; 1187 bool res = false;
1188 int fd; 1188 int fd;
1189 1189
1190 if ( bright > 255 ) 1190 if ( bright > 255 )
1191 bright = 255; 1191 bright = 255;
1192 if ( bright < 0 ) 1192 if ( bright < 0 )
1193 bright = 0; 1193 bright = 0;
1194 1194
1195 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) { 1195 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) {
1196 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus 1196 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus
1197 if ( bright && !bl ) 1197 if ( bright && !bl )
1198 bl = 1; 1198 bl = 1;
1199 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 ); 1199 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 );
1200 ::close ( fd ); 1200 ::close ( fd );
1201 } 1201 }
1202 return res; 1202 return res;
1203} 1203}
1204 1204
1205 1205
1206int Zaurus::displayBrightnessResolution ( ) const 1206int Zaurus::displayBrightnessResolution ( ) const
1207{ 1207{
1208 return 5; 1208 return 5;
1209} 1209}
1210 1210
1211 1211