summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp8
1 files changed, 0 insertions, 8 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 25c9826..2d2f7db 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -1,968 +1,960 @@
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 36
37#include "odevice.h" 37#include "odevice.h"
38 38
39#include <qwindowsystem_qws.h> 39#include <qwindowsystem_qws.h>
40 40
41 41
42// _IO and friends are only defined in kernel headers ... 42// _IO and friends are only defined in kernel headers ...
43 43
44#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) 44#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
45 45
46#define OD_IO(type,number) OD_IOC(0,type,number,0) 46#define OD_IO(type,number) OD_IOC(0,type,number,0)
47#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) 47#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size))
48#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) 48#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size))
49#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) 49#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size))
50 50
51using namespace Opie; 51using namespace Opie;
52 52
53class ODeviceData { 53class ODeviceData {
54public: 54public:
55 bool m_qwsserver; 55 bool m_qwsserver;
56 56
57 QString m_vendorstr; 57 QString m_vendorstr;
58 OVendor m_vendor; 58 OVendor m_vendor;
59 59
60 QString m_modelstr; 60 QString m_modelstr;
61 OModel m_model; 61 OModel m_model;
62 62
63 QString m_systemstr; 63 QString m_systemstr;
64 OSystem m_system; 64 OSystem m_system;
65 65
66 QString m_sysverstr; 66 QString m_sysverstr;
67}; 67};
68 68
69 69
70class iPAQ : public QObject, public ODevice, public QWSServer::KeyboardFilter { 70class iPAQ : public QObject, public ODevice, public QWSServer::KeyboardFilter {
71protected: 71protected:
72 virtual void init ( ); 72 virtual void init ( );
73 73
74public: 74public:
75 virtual bool setSoftSuspend ( bool soft ); 75 virtual bool setSoftSuspend ( bool soft );
76 76
77 virtual bool setDisplayBrightness ( int b ); 77 virtual bool setDisplayBrightness ( int b );
78 virtual int displayBrightnessResolution ( ) const; 78 virtual int displayBrightnessResolution ( ) const;
79 79
80 virtual void alarmSound ( ); 80 virtual void alarmSound ( );
81 81
82 virtual QValueList <OLed> ledList ( ) const; 82 virtual QValueList <OLed> ledList ( ) const;
83 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 83 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
84 virtual OLedState ledState ( OLed led ) const; 84 virtual OLedState ledState ( OLed led ) const;
85 virtual bool setLedState ( OLed led, OLedState st ); 85 virtual bool setLedState ( OLed led, OLedState st );
86 86
87 virtual bool hasLightSensor ( ) const; 87 virtual bool hasLightSensor ( ) const;
88 virtual int readLightSensor ( ); 88 virtual int readLightSensor ( );
89 virtual int lightSensorResolution ( ) const; 89 virtual int lightSensorResolution ( ) const;
90 90
91 //virtual QValueList <int> keyList ( ) const; 91 //virtual QValueList <int> keyList ( ) const;
92 92
93protected: 93protected:
94 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); 94 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
95 virtual void timerEvent ( QTimerEvent *te ); 95 virtual void timerEvent ( QTimerEvent *te );
96 96
97 int m_power_timer; 97 int m_power_timer;
98 98
99 OLedState m_leds [2]; 99 OLedState m_leds [2];
100}; 100};
101 101
102class Zaurus : public ODevice { 102class Zaurus : public ODevice {
103protected: 103protected:
104 virtual void init ( ); 104 virtual void init ( );
105 105
106 public: 106 public:
107 virtual bool setSoftSuspend ( bool soft ); 107 virtual bool setSoftSuspend ( bool soft );
108 108
109 virtual bool setDisplayBrightness ( int b ); 109 virtual bool setDisplayBrightness ( int b );
110 virtual int displayBrightnessResolution ( ) const; 110 virtual int displayBrightnessResolution ( ) const;
111 111
112 virtual void alarmSound ( ); 112 virtual void alarmSound ( );
113 virtual void keySound ( ); 113 virtual void keySound ( );
114 virtual void touchSound ( ); 114 virtual void touchSound ( );
115 115
116 virtual QValueList <OLed> ledList ( ) const; 116 virtual QValueList <OLed> ledList ( ) const;
117 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 117 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
118 virtual OLedState ledState ( OLed led ) const; 118 virtual OLedState ledState ( OLed led ) const;
119 virtual bool setLedState ( OLed led, OLedState st ); 119 virtual bool setLedState ( OLed led, OLedState st );
120 120
121 //virtual QValueList <int> keyList ( ) const; 121 //virtual QValueList <int> keyList ( ) const;
122 122
123protected: 123protected:
124 virtual void buzzer ( int snd ); 124 virtual void buzzer ( int snd );
125 125
126 OLedState m_leds [1]; 126 OLedState m_leds [1];
127}; 127};
128 128
129 129
130 130
131 131
132 132
133 133
134 134
135ODevice *ODevice::inst ( ) 135ODevice *ODevice::inst ( )
136{ 136{
137 static ODevice *dev = 0; 137 static ODevice *dev = 0;
138 138
139 if ( !dev ) { 139 if ( !dev ) {
140 if ( QFile::exists ( "/proc/hal/model" )) 140 if ( QFile::exists ( "/proc/hal/model" ))
141 dev = new iPAQ ( ); 141 dev = new iPAQ ( );
142 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) 142 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ))
143 dev = new Zaurus ( ); 143 dev = new Zaurus ( );
144 else 144 else
145 dev = new ODevice ( ); 145 dev = new ODevice ( );
146 146
147 dev-> init ( ); 147 dev-> init ( );
148 } 148 }
149 return dev; 149 return dev;
150} 150}
151 151
152 152
153/************************************************** 153/**************************************************
154 * 154 *
155 * common 155 * common
156 * 156 *
157 **************************************************/ 157 **************************************************/
158 158
159 159
160ODevice::ODevice ( ) 160ODevice::ODevice ( )
161{ 161{
162 d = new ODeviceData; 162 d = new ODeviceData;
163 163
164 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; 164 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
165 165
166 d-> m_modelstr = "Unknown"; 166 d-> m_modelstr = "Unknown";
167 d-> m_model = Model_Unknown; 167 d-> m_model = Model_Unknown;
168 d-> m_vendorstr = "Unkown"; 168 d-> m_vendorstr = "Unkown";
169 d-> m_vendor = Vendor_Unknown; 169 d-> m_vendor = Vendor_Unknown;
170 d-> m_systemstr = "Unkown"; 170 d-> m_systemstr = "Unkown";
171 d-> m_system = System_Unknown; 171 d-> m_system = System_Unknown;
172 d-> m_sysverstr = "0.0"; 172 d-> m_sysverstr = "0.0";
173} 173}
174 174
175void ODevice::init ( ) 175void ODevice::init ( )
176{ 176{
177} 177}
178 178
179ODevice::~ODevice ( ) 179ODevice::~ODevice ( )
180{ 180{
181 delete d; 181 delete d;
182} 182}
183 183
184bool ODevice::setSoftSuspend ( bool /*soft*/ ) 184bool ODevice::setSoftSuspend ( bool /*soft*/ )
185{ 185{
186 return false; 186 return false;
187} 187}
188 188
189//#include <linux/apm_bios.h> 189//#include <linux/apm_bios.h>
190 190
191#define APM_IOC_SUSPEND OD_IO( 'A', 2 ) 191#define APM_IOC_SUSPEND OD_IO( 'A', 2 )
192 192
193 193
194bool ODevice::suspend ( ) 194bool ODevice::suspend ( )
195{ 195{
196 if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend 196 if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend
197 return false; 197 return false;
198 198
199 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices 199 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices
200 return false; 200 return false;
201 201
202 int fd; 202 int fd;
203 bool res = false; 203 bool res = false;
204 204
205 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || 205 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
206 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { 206 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
207 struct timeval tvs, tvn; 207 struct timeval tvs, tvn;
208 208
209 // ::signal ( SIGTSTP, SIG_IGN );// we don't want to be stopped 209 // ::signal ( SIGTSTP, SIG_IGN );// we don't want to be stopped
210 ::gettimeofday ( &tvs, 0 ); 210 ::gettimeofday ( &tvs, 0 );
211 211
212 ::sync ( ); // flush fs caches 212 ::sync ( ); // flush fs caches
213 213
214 res = ( ::ioctl ( fd, APM_IOC_SUSPEND, 0 ) == 0 ); // tell the kernel to "start" suspending 214 res = ( ::ioctl ( fd, APM_IOC_SUSPEND, 0 ) == 0 ); // tell the kernel to "start" suspending
215 ::close ( fd ); 215 ::close ( fd );
216 216
217 if ( res ) { 217 if ( res ) {
218 // ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in our process group 218 // ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in our process group
219 219
220 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed 220 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
221 ::usleep ( 200 * 1000 ); 221 ::usleep ( 200 * 1000 );
222 ::gettimeofday ( &tvn, 0 ); 222 ::gettimeofday ( &tvn, 0 );
223 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); 223 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
224 224
225 // ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group 225 // ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group
226 } 226 }
227 227
228 // ::signal ( SIGTSTP, SIG_DFL ); 228 // ::signal ( SIGTSTP, SIG_DFL );
229 } 229 }
230 230
231 return res; 231 return res;
232} 232}
233 233
234//#include <linux/fb.h> better not rely on kernel headers in userspace ... 234//#include <linux/fb.h> better not rely on kernel headers in userspace ...
235 235
236#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 236#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611
237 237
238/* VESA Blanking Levels */ 238/* VESA Blanking Levels */
239#define VESA_NO_BLANKING 0 239#define VESA_NO_BLANKING 0
240#define VESA_VSYNC_SUSPEND 1 240#define VESA_VSYNC_SUSPEND 1
241#define VESA_HSYNC_SUSPEND 2 241#define VESA_HSYNC_SUSPEND 2
242#define VESA_POWERDOWN 3 242#define VESA_POWERDOWN 3
243 243
244 244
245bool ODevice::setDisplayStatus ( bool on ) 245bool ODevice::setDisplayStatus ( bool on )
246{ 246{
247 if ( d-> m_model == Model_Unknown ) 247 if ( d-> m_model == Model_Unknown )
248 return false; 248 return false;
249 249
250 bool res = false; 250 bool res = false;
251 int fd; 251 int fd;
252 252
253 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { 253 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) {
254 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); 254 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 );
255 ::close ( fd ); 255 ::close ( fd );
256 } 256 }
257 return res; 257 return res;
258} 258}
259 259
260bool ODevice::setDisplayBrightness ( int ) 260bool ODevice::setDisplayBrightness ( int )
261{ 261{
262 return false; 262 return false;
263} 263}
264 264
265int ODevice::displayBrightnessResolution ( ) const 265int ODevice::displayBrightnessResolution ( ) const
266{ 266{
267 return 16; 267 return 16;
268} 268}
269 269
270QString ODevice::vendorString ( ) const 270QString ODevice::vendorString ( ) const
271{ 271{
272 return d-> m_vendorstr; 272 return d-> m_vendorstr;
273} 273}
274 274
275OVendor ODevice::vendor ( ) const 275OVendor ODevice::vendor ( ) const
276{ 276{
277 return d-> m_vendor; 277 return d-> m_vendor;
278} 278}
279 279
280QString ODevice::modelString ( ) const 280QString ODevice::modelString ( ) const
281{ 281{
282 return d-> m_modelstr; 282 return d-> m_modelstr;
283} 283}
284 284
285OModel ODevice::model ( ) const 285OModel ODevice::model ( ) const
286{ 286{
287 return d-> m_model; 287 return d-> m_model;
288} 288}
289 289
290QString ODevice::systemString ( ) const 290QString ODevice::systemString ( ) const
291{ 291{
292 return d-> m_systemstr; 292 return d-> m_systemstr;
293} 293}
294 294
295OSystem ODevice::system ( ) const 295OSystem ODevice::system ( ) const
296{ 296{
297 return d-> m_system; 297 return d-> m_system;
298} 298}
299 299
300QString ODevice::systemVersionString ( ) const 300QString ODevice::systemVersionString ( ) const
301{ 301{
302 return d-> m_sysverstr; 302 return d-> m_sysverstr;
303} 303}
304 304
305void ODevice::alarmSound ( ) 305void ODevice::alarmSound ( )
306{ 306{
307#ifndef QT_QWS_EBX
308#ifndef QT_NO_SOUND 307#ifndef QT_NO_SOUND
309 static Sound snd ( "alarm" ); 308 static Sound snd ( "alarm" );
310 309
311 if ( snd. isFinished ( )) 310 if ( snd. isFinished ( ))
312 snd. play ( ); 311 snd. play ( );
313#endif 312#endif
314#endif
315} 313}
316 314
317void ODevice::keySound ( ) 315void ODevice::keySound ( )
318{ 316{
319#ifndef QT_QWS_EBX
320#ifndef QT_NO_SOUND 317#ifndef QT_NO_SOUND
321 static Sound snd ( "keysound" ); 318 static Sound snd ( "keysound" );
322 319
323 if ( snd. isFinished ( )) 320 if ( snd. isFinished ( ))
324 snd. play ( ); 321 snd. play ( );
325#endif 322#endif
326#endif
327} 323}
328 324
329void ODevice::touchSound ( ) 325void ODevice::touchSound ( )
330{ 326{
331 327
332#ifndef QT_QWS_EBX
333#ifndef QT_NO_SOUND 328#ifndef QT_NO_SOUND
334 static Sound snd ( "touchsound" ); 329 static Sound snd ( "touchsound" );
335 330
336 if ( snd. isFinished ( )) 331 if ( snd. isFinished ( ))
337 snd. play ( ); 332 snd. play ( );
338#endif 333#endif
339#endif
340} 334}
341 335
342 336
343QValueList <OLed> ODevice::ledList ( ) const 337QValueList <OLed> ODevice::ledList ( ) const
344{ 338{
345 return QValueList <OLed> ( ); 339 return QValueList <OLed> ( );
346} 340}
347 341
348QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const 342QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const
349{ 343{
350 return QValueList <OLedState> ( ); 344 return QValueList <OLedState> ( );
351} 345}
352 346
353OLedState ODevice::ledState ( OLed /*which*/ ) const 347OLedState ODevice::ledState ( OLed /*which*/ ) const
354{ 348{
355 return Led_Off; 349 return Led_Off;
356} 350}
357 351
358bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ ) 352bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ )
359{ 353{
360 return false; 354 return false;
361} 355}
362 356
363bool ODevice::hasLightSensor ( ) const 357bool ODevice::hasLightSensor ( ) const
364{ 358{
365 return false; 359 return false;
366} 360}
367 361
368int ODevice::readLightSensor ( ) 362int ODevice::readLightSensor ( )
369{ 363{
370 return -1; 364 return -1;
371} 365}
372 366
373int ODevice::lightSensorResolution ( ) const 367int ODevice::lightSensorResolution ( ) const
374{ 368{
375 return 0; 369 return 0;
376} 370}
377 371
378//QValueList <int> ODevice::keyList ( ) const 372//QValueList <int> ODevice::keyList ( ) const
379//{ 373//{
380 //return QValueList <int> ( ); 374 //return QValueList <int> ( );
381//} 375//}
382 376
383 377
384 378
385/************************************************** 379/**************************************************
386 * 380 *
387 * iPAQ 381 * iPAQ
388 * 382 *
389 **************************************************/ 383 **************************************************/
390 384
391void iPAQ::init ( ) 385void iPAQ::init ( )
392{ 386{
393 d-> m_vendorstr = "HP"; 387 d-> m_vendorstr = "HP";
394 d-> m_vendor = Vendor_HP; 388 d-> m_vendor = Vendor_HP;
395 389
396 QFile f ( "/proc/hal/model" ); 390 QFile f ( "/proc/hal/model" );
397 391
398 if ( f. open ( IO_ReadOnly )) { 392 if ( f. open ( IO_ReadOnly )) {
399 QTextStream ts ( &f ); 393 QTextStream ts ( &f );
400 394
401 d-> m_modelstr = "H" + ts. readLine ( ); 395 d-> m_modelstr = "H" + ts. readLine ( );
402 396
403 if ( d-> m_modelstr == "H3100" ) 397 if ( d-> m_modelstr == "H3100" )
404 d-> m_model = Model_iPAQ_H31xx; 398 d-> m_model = Model_iPAQ_H31xx;
405 else if ( d-> m_modelstr == "H3600" ) 399 else if ( d-> m_modelstr == "H3600" )
406 d-> m_model = Model_iPAQ_H36xx; 400 d-> m_model = Model_iPAQ_H36xx;
407 else if ( d-> m_modelstr == "H3700" ) 401 else if ( d-> m_modelstr == "H3700" )
408 d-> m_model = Model_iPAQ_H37xx; 402 d-> m_model = Model_iPAQ_H37xx;
409 else if ( d-> m_modelstr == "H3800" ) 403 else if ( d-> m_modelstr == "H3800" )
410 d-> m_model = Model_iPAQ_H38xx; 404 d-> m_model = Model_iPAQ_H38xx;
411 else if ( d-> m_modelstr == "H3900" ) 405 else if ( d-> m_modelstr == "H3900" )
412 d-> m_model = Model_iPAQ_H39xx; 406 d-> m_model = Model_iPAQ_H39xx;
413 else 407 else
414 d-> m_model = Model_Unknown; 408 d-> m_model = Model_Unknown;
415 409
416 f. close ( ); 410 f. close ( );
417 } 411 }
418 412
419 f. setName ( "/etc/familiar-version" ); 413 f. setName ( "/etc/familiar-version" );
420 if ( f. open ( IO_ReadOnly )) { 414 if ( f. open ( IO_ReadOnly )) {
421 d-> m_systemstr = "Familiar"; 415 d-> m_systemstr = "Familiar";
422 d-> m_system = System_Familiar; 416 d-> m_system = System_Familiar;
423 417
424 QTextStream ts ( &f ); 418 QTextStream ts ( &f );
425 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 419 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
426 420
427 f. close ( ); 421 f. close ( );
428 } 422 }
429 423
430 m_leds [0] = m_leds [1] = Led_Off; 424 m_leds [0] = m_leds [1] = Led_Off;
431 425
432 m_power_timer = 0; 426 m_power_timer = 0;
433 427
434 if ( d-> m_qwsserver ) 428 if ( d-> m_qwsserver )
435 QWSServer::setKeyboardFilter ( this ); 429 QWSServer::setKeyboardFilter ( this );
436} 430}
437 431
438//#include <linux/h3600_ts.h> // including kernel headers is evil ... 432//#include <linux/h3600_ts.h> // including kernel headers is evil ...
439 433
440typedef struct { 434typedef struct {
441 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ 435 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */
442 unsigned char TotalTime; /* Units of 5 seconds */ 436 unsigned char TotalTime; /* Units of 5 seconds */
443 unsigned char OnTime; /* units of 100m/s */ 437 unsigned char OnTime; /* units of 100m/s */
444 unsigned char OffTime; /* units of 100m/s */ 438 unsigned char OffTime; /* units of 100m/s */
445} LED_IN; 439} LED_IN;
446 440
447typedef struct { 441typedef struct {
448 unsigned char mode; 442 unsigned char mode;
449 unsigned char pwr; 443 unsigned char pwr;
450 unsigned char brightness; 444 unsigned char brightness;
451} FLITE_IN; 445} FLITE_IN;
452 446
453#define LED_ON OD_IOW( 'f', 5, LED_IN ) 447#define LED_ON OD_IOW( 'f', 5, LED_IN )
454#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) 448#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN )
455 449
456 450
457 451
458QValueList <OLed> iPAQ::ledList ( ) const 452QValueList <OLed> iPAQ::ledList ( ) const
459{ 453{
460 QValueList <OLed> vl; 454 QValueList <OLed> vl;
461 vl << Led_Power; 455 vl << Led_Power;
462 456
463 if ( d-> m_model == Model_iPAQ_H38xx ) 457 if ( d-> m_model == Model_iPAQ_H38xx )
464 vl << Led_BlueTooth; 458 vl << Led_BlueTooth;
465 return vl; 459 return vl;
466} 460}
467 461
468QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const 462QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const
469{ 463{
470 QValueList <OLedState> vl; 464 QValueList <OLedState> vl;
471 465
472 if ( l == Led_Power ) 466 if ( l == Led_Power )
473 vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; 467 vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast;
474 else if ( l == Led_BlueTooth && d-> m_model == Model_iPAQ_H38xx ) 468 else if ( l == Led_BlueTooth && d-> m_model == Model_iPAQ_H38xx )
475 vl << Led_Off; // << Led_On << ??? 469 vl << Led_Off; // << Led_On << ???
476 470
477 return vl; 471 return vl;
478} 472}
479 473
480OLedState iPAQ::ledState ( OLed l ) const 474OLedState iPAQ::ledState ( OLed l ) const
481 { 475 {
482 switch ( l ) { 476 switch ( l ) {
483 case Led_Power: 477 case Led_Power:
484 return m_leds [0]; 478 return m_leds [0];
485 case Led_BlueTooth: 479 case Led_BlueTooth:
486 return m_leds [1]; 480 return m_leds [1];
487 default: 481 default:
488 return Led_Off; 482 return Led_Off;
489 } 483 }
490} 484}
491 485
492bool iPAQ::setLedState ( OLed l, OLedState st ) 486bool iPAQ::setLedState ( OLed l, OLedState st )
493{ 487{
494 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK ); 488 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK );
495 489
496 if ( l == Led_Power ) { 490 if ( l == Led_Power ) {
497 if ( fd >= 0 ) { 491 if ( fd >= 0 ) {
498 LED_IN leds; 492 LED_IN leds;
499 ::memset ( &leds, 0, sizeof( leds )); 493 ::memset ( &leds, 0, sizeof( leds ));
500 leds. TotalTime = 0; 494 leds. TotalTime = 0;
501 leds. OnTime = 0; 495 leds. OnTime = 0;
502 leds. OffTime = 1; 496 leds. OffTime = 1;
503 leds. OffOnBlink = 2; 497 leds. OffOnBlink = 2;
504 498
505 switch ( st ) { 499 switch ( st ) {
506 case Led_Off : leds. OffOnBlink = 0; break; 500 case Led_Off : leds. OffOnBlink = 0; break;
507 case Led_On : leds. OffOnBlink = 1; break; 501 case Led_On : leds. OffOnBlink = 1; break;
508 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; 502 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break;
509 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; 503 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break;
510 } 504 }
511 505
512 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { 506 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) {
513 m_leds [0] = st; 507 m_leds [0] = st;
514 return true; 508 return true;
515 } 509 }
516 } 510 }
517 } 511 }
518 return false; 512 return false;
519} 513}
520 514
521 515
522//QValueList <int> iPAQ::keyList ( ) const 516//QValueList <int> iPAQ::keyList ( ) const
523//{ 517//{
524 //QValueList <int> vl; 518 //QValueList <int> vl;
525 //vl << HardKey_Datebook << HardKey_Contacts << ( model ( ) == Model_iPAQ_H38xx ? HardKey_Mail : HardKey_Menu ) << HardKey_Home << HardKey_Record << HardKey_Suspend << HardKey_Backlight; 519 //vl << HardKey_Datebook << HardKey_Contacts << ( model ( ) == Model_iPAQ_H38xx ? HardKey_Mail : HardKey_Menu ) << HardKey_Home << HardKey_Record << HardKey_Suspend << HardKey_Backlight;
526 //return vl; 520 //return vl;
527//} 521//}
528 522
529bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) 523bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
530{ 524{
531 int newkeycode = keycode; 525 int newkeycode = keycode;
532 526
533 527
534 // simple susbstitutions 528 // simple susbstitutions
535 switch ( d-> m_model ) { 529 switch ( d-> m_model ) {
536 case Model_iPAQ_H38xx: 530 case Model_iPAQ_H38xx:
537 // H38xx has no "Q" key anymore - this is now the Mail key 531 // H38xx has no "Q" key anymore - this is now the Mail key
538 if ( keycode == HardKey_Menu ) 532 if ( keycode == HardKey_Menu )
539 newkeycode = HardKey_Mail; 533 newkeycode = HardKey_Mail;
540 //nobreak 534 //nobreak
541 535
542 case Model_iPAQ_H31xx: 536 case Model_iPAQ_H31xx:
543 // Rotate cursor keys 180° 537 // Rotate cursor keys 180°
544 switch ( keycode ) { 538 switch ( keycode ) {
545 case Key_Left : newkeycode = Key_Right; break; 539 case Key_Left : newkeycode = Key_Right; break;
546 case Key_Right: newkeycode = Key_Left; break; 540 case Key_Right: newkeycode = Key_Left; break;
547 case Key_Up : newkeycode = Key_Down; break; 541 case Key_Up : newkeycode = Key_Down; break;
548 case Key_Down : newkeycode = Key_Up; break; 542 case Key_Down : newkeycode = Key_Up; break;
549 } 543 }
550 //nobreak; 544 //nobreak;
551 545
552 case Model_iPAQ_H36xx: 546 case Model_iPAQ_H36xx:
553 case Model_iPAQ_H37xx: 547 case Model_iPAQ_H37xx:
554 // map Power Button short/long press to F34/F35 548 // map Power Button short/long press to F34/F35
555 if ( keycode == Key_SysReq ) { 549 if ( keycode == Key_SysReq ) {
556 if ( isPress ) { 550 if ( isPress ) {
557 if ( m_power_timer ) 551 if ( m_power_timer )
558 killTimer ( m_power_timer ); 552 killTimer ( m_power_timer );
559 m_power_timer = startTimer ( 500 ); 553 m_power_timer = startTimer ( 500 );
560 } 554 }
561 else if ( m_power_timer ) { 555 else if ( m_power_timer ) {
562 killTimer ( m_power_timer ); 556 killTimer ( m_power_timer );
563 m_power_timer = 0; 557 m_power_timer = 0;
564 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); 558 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false );
565 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); 559 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false );
566 } 560 }
567 newkeycode = Key_unknown; 561 newkeycode = Key_unknown;
568 } 562 }
569 //nobreak; 563 //nobreak;
570 564
571 default: 565 default:
572 break; 566 break;
573 } 567 }
574 568
575 if ( newkeycode != keycode ) { 569 if ( newkeycode != keycode ) {
576 if ( newkeycode != Key_unknown ) 570 if ( newkeycode != Key_unknown )
577 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); 571 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
578 return true; 572 return true;
579 } 573 }
580 else 574 else
581 return false; 575 return false;
582} 576}
583 577
584void iPAQ::timerEvent ( QTimerEvent * ) 578void iPAQ::timerEvent ( QTimerEvent * )
585{ 579{
586 killTimer ( m_power_timer ); 580 killTimer ( m_power_timer );
587 m_power_timer = 0; 581 m_power_timer = 0;
588 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); 582 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false );
589 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); 583 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false );
590} 584}
591 585
592 586
593void iPAQ::alarmSound ( ) 587void iPAQ::alarmSound ( )
594{ 588{
595#if defined( QT_QWS_IPAQ ) // IPAQ
596#ifndef QT_NO_SOUND 589#ifndef QT_NO_SOUND
597 static Sound snd ( "alarm" ); 590 static Sound snd ( "alarm" );
598 int fd; 591 int fd;
599 int vol; 592 int vol;
600 bool vol_reset = false; 593 bool vol_reset = false;
601 594
602 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { 595 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) {
603 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { 596 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
604 Config cfg ( "qpe" ); 597 Config cfg ( "qpe" );
605 cfg. setGroup ( "Volume" ); 598 cfg. setGroup ( "Volume" );
606 599
607 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); 600 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
608 if ( volalarm < 0 ) 601 if ( volalarm < 0 )
609 volalarm = 0; 602 volalarm = 0;
610 else if ( volalarm > 100 ) 603 else if ( volalarm > 100 )
611 volalarm = 100; 604 volalarm = 100;
612 volalarm |= ( volalarm << 8 ); 605 volalarm |= ( volalarm << 8 );
613 606
614 if (( volalarm & 0xff ) > ( vol & 0xff )) { 607 if (( volalarm & 0xff ) > ( vol & 0xff )) {
615 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) 608 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
616 vol_reset = true; 609 vol_reset = true;
617 } 610 }
618 } 611 }
619 } 612 }
620 613
621 snd. play ( ); 614 snd. play ( );
622 while ( !snd. isFinished ( )) 615 while ( !snd. isFinished ( ))
623 qApp-> processEvents ( ); 616 qApp-> processEvents ( );
624 617
625 if ( fd >= 0 ) { 618 if ( fd >= 0 ) {
626 if ( vol_reset ) 619 if ( vol_reset )
627 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); 620 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
628 ::close ( fd ); 621 ::close ( fd );
629 } 622 }
630#endif 623#endif
631#endif
632} 624}
633 625
634 626
635bool iPAQ::setSoftSuspend ( bool soft ) 627bool iPAQ::setSoftSuspend ( bool soft )
636{ 628{
637 bool res = false; 629 bool res = false;
638 int fd; 630 int fd;
639 631
640 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { 632 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) {
641 if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) 633 if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 )
642 res = true; 634 res = true;
643 else 635 else
644 ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); 636 ::perror ( "write to /proc/sys/ts/suspend_button_mode" );
645 637
646 ::close ( fd ); 638 ::close ( fd );
647 } 639 }
648 else 640 else
649 ::perror ( "/proc/sys/ts/suspend_button_mode" ); 641 ::perror ( "/proc/sys/ts/suspend_button_mode" );
650 642
651 return res; 643 return res;
652} 644}
653 645
654 646
655bool iPAQ::setDisplayBrightness ( int bright ) 647bool iPAQ::setDisplayBrightness ( int bright )
656{ 648{
657 bool res = false; 649 bool res = false;
658 int fd; 650 int fd;
659 651
660 if ( bright > 255 ) 652 if ( bright > 255 )
661 bright = 255; 653 bright = 255;
662 if ( bright < 0 ) 654 if ( bright < 0 )
663 bright = 0; 655 bright = 0;
664 656
665 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { 657 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
666 FLITE_IN bl; 658 FLITE_IN bl;
667 bl. mode = 1; 659 bl. mode = 1;
668 bl. pwr = bright ? 1 : 0; 660 bl. pwr = bright ? 1 : 0;
669 bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255; 661 bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255;
670 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); 662 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 );
671 ::close ( fd ); 663 ::close ( fd );
672 } 664 }
673 return res; 665 return res;
674} 666}
675 667
676int iPAQ::displayBrightnessResolution ( ) const 668int iPAQ::displayBrightnessResolution ( ) const
677{ 669{
678 switch ( model ( )) { 670 switch ( model ( )) {
679 case Model_iPAQ_H31xx: 671 case Model_iPAQ_H31xx:
680 case Model_iPAQ_H36xx: 672 case Model_iPAQ_H36xx:
681 case Model_iPAQ_H37xx: 673 case Model_iPAQ_H37xx:
682 return 128; // really 256, but >128 could damage the LCD 674 return 128; // really 256, but >128 could damage the LCD
683 675
684 case Model_iPAQ_H38xx: 676 case Model_iPAQ_H38xx:
685 case Model_iPAQ_H39xx: 677 case Model_iPAQ_H39xx:
686 return 64; 678 return 64;
687 679
688 default: 680 default:
689 return 2; 681 return 2;
690 } 682 }
691} 683}
692 684
693 685
694bool iPAQ::hasLightSensor ( ) const 686bool iPAQ::hasLightSensor ( ) const
695{ 687{
696 return true; 688 return true;
697} 689}
698 690
699int iPAQ::readLightSensor ( ) 691int iPAQ::readLightSensor ( )
700{ 692{
701 int fd; 693 int fd;
702 int val = -1; 694 int val = -1;
703 695
704 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { 696 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) {
705 char buffer [8]; 697 char buffer [8];
706 698
707 if ( ::read ( fd, buffer, 5 ) == 5 ) { 699 if ( ::read ( fd, buffer, 5 ) == 5 ) {
708 char *endptr; 700 char *endptr;
709 701
710 buffer [4] = 0; 702 buffer [4] = 0;
711 val = ::strtol ( buffer + 2, &endptr, 16 ); 703 val = ::strtol ( buffer + 2, &endptr, 16 );
712 704
713 if ( *endptr != 0 ) 705 if ( *endptr != 0 )
714 val = -1; 706 val = -1;
715 } 707 }
716 ::close ( fd ); 708 ::close ( fd );
717 } 709 }
718 710
719 return val; 711 return val;
720} 712}
721 713
722int iPAQ::lightSensorResolution ( ) const 714int iPAQ::lightSensorResolution ( ) const
723{ 715{
724 return 256; 716 return 256;
725} 717}
726 718
727/************************************************** 719/**************************************************
728 * 720 *
729 * Zaurus 721 * Zaurus
730 * 722 *
731 **************************************************/ 723 **************************************************/
732 724
733 725
734 726
735void Zaurus::init ( ) 727void Zaurus::init ( )
736{ 728{
737 d-> m_modelstr = "Zaurus SL5000"; 729 d-> m_modelstr = "Zaurus SL5000";
738 d-> m_model = Model_Zaurus_SL5000; 730 d-> m_model = Model_Zaurus_SL5000;
739 d-> m_vendorstr = "Sharp"; 731 d-> m_vendorstr = "Sharp";
740 d-> m_vendor = Vendor_Sharp; 732 d-> m_vendor = Vendor_Sharp;
741 733
742 QFile f ( "/proc/filesystems" ); 734 QFile f ( "/proc/filesystems" );
743 735
744 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { 736 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) {
745 d-> m_systemstr = "OpenZaurus"; 737 d-> m_systemstr = "OpenZaurus";
746 d-> m_system = System_OpenZaurus; 738 d-> m_system = System_OpenZaurus;
747 739
748 f. close ( ); 740 f. close ( );
749 741
750 f. setName ( "/etc/oz_version" ); 742 f. setName ( "/etc/oz_version" );
751 if ( f. open ( IO_ReadOnly )) { 743 if ( f. open ( IO_ReadOnly )) {
752 QTextStream ts ( &f ); 744 QTextStream ts ( &f );
753 d-> m_sysverstr = ts. readLine ( );//. mid ( 10 ); 745 d-> m_sysverstr = ts. readLine ( );//. mid ( 10 );
754 f. close ( ); 746 f. close ( );
755 } 747 }
756 } 748 }
757 else { 749 else {
758 d-> m_systemstr = "Zaurus"; 750 d-> m_systemstr = "Zaurus";
759 d-> m_system = System_Zaurus; 751 d-> m_system = System_Zaurus;
760 } 752 }
761 753
762 754
763 m_leds [0] = Led_Off; 755 m_leds [0] = Led_Off;
764} 756}
765 757
766#include <unistd.h> 758#include <unistd.h>
767#include <fcntl.h> 759#include <fcntl.h>
768#include <sys/ioctl.h> 760#include <sys/ioctl.h>
769 761
770//#include <asm/sharp_char.h> // including kernel headers is evil ... 762//#include <asm/sharp_char.h> // including kernel headers is evil ...
771 763
772#define SHARP_DEV_IOCTL_COMMAND_START 0x5680 764#define SHARP_DEV_IOCTL_COMMAND_START 0x5680
773 765
774 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 766 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
775#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 767#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
776 768
777#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 769#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
778#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 770#define SHARP_BUZ_KEYSOUND 2 /* key sound */
779#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 771#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
780 772
781/* --- for SHARP_BUZZER device --- */ 773/* --- for SHARP_BUZZER device --- */
782 774
783 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 775 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
784//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 776//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
785 777
786#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) 778#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1)
787#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2) 779#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2)
788#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3) 780#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3)
789#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4) 781#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4)
790#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5) 782#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5)
791 783
792//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 784//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
793//#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 785//#define SHARP_BUZ_KEYSOUND 2 /* key sound */
794 786
795//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */ 787//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */
796//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */ 788//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */
797//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */ 789//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */
798//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */ 790//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */
799//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */ 791//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */
800//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */ 792//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */
801//#define SHARP_PDA_APPSTART 9 /* application start */ 793//#define SHARP_PDA_APPSTART 9 /* application start */
802//#define SHARP_PDA_APPQUIT 10 /* application ends */ 794//#define SHARP_PDA_APPQUIT 10 /* application ends */
803 795
804//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 796//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
805//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */ 797//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */
806//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */ 798//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */
807//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */ 799//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */
808// 800//
809 801
810 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 802 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
811#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1) 803#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1)
812 804
813typedef struct sharp_led_status { 805typedef struct sharp_led_status {
814 int which; /* select which LED status is wanted. */ 806 int which; /* select which LED status is wanted. */
815 int status; /* set new led status if you call SHARP_LED_SETSTATUS */ 807 int status; /* set new led status if you call SHARP_LED_SETSTATUS */
816} sharp_led_status; 808} sharp_led_status;
817 809
818#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */ 810#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */
819 811
820#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */ 812#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */
821#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */ 813#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */
822#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */ 814#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */
823 815
824// #include <asm/sharp_apm.h> // including kernel headers is evil ... 816// #include <asm/sharp_apm.h> // including kernel headers is evil ...
825 817
826#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int ) 818#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int )
827#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int ) 819#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int )
828#define APM_EVT_POWER_BUTTON (1 << 0) 820#define APM_EVT_POWER_BUTTON (1 << 0)
829 821
830#define FL_IOCTL_STEP_CONTRAST 100 822#define FL_IOCTL_STEP_CONTRAST 100
831 823
832 824
833void Zaurus::buzzer ( int sound ) 825void Zaurus::buzzer ( int sound )
834{ 826{
835 static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK ); 827 static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK );
836 828
837 if ( fd >= 0 ) 829 if ( fd >= 0 )
838 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); 830 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound );
839} 831}
840 832
841 833
842void Zaurus::alarmSound ( ) 834void Zaurus::alarmSound ( )
843{ 835{
844 buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); 836 buzzer ( SHARP_BUZ_SCHEDULE_ALARM );
845} 837}
846 838
847void Zaurus::touchSound ( ) 839void Zaurus::touchSound ( )
848{ 840{
849 buzzer ( SHARP_BUZ_TOUCHSOUND ); 841 buzzer ( SHARP_BUZ_TOUCHSOUND );
850} 842}
851 843
852void Zaurus::keySound ( ) 844void Zaurus::keySound ( )
853{ 845{
854 buzzer ( SHARP_BUZ_KEYSOUND ); 846 buzzer ( SHARP_BUZ_KEYSOUND );
855} 847}
856 848
857 849
858QValueList <OLed> Zaurus::ledList ( ) const 850QValueList <OLed> Zaurus::ledList ( ) const
859{ 851{
860 QValueList <OLed> vl; 852 QValueList <OLed> vl;
861 vl << Led_Mail; 853 vl << Led_Mail;
862 return vl; 854 return vl;
863} 855}
864 856
865QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const 857QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const
866{ 858{
867 QValueList <OLedState> vl; 859 QValueList <OLedState> vl;
868 860
869 if ( l == Led_Mail ) 861 if ( l == Led_Mail )
870 vl << Led_Off << Led_On << Led_BlinkSlow; 862 vl << Led_Off << Led_On << Led_BlinkSlow;
871 return vl; 863 return vl;
872} 864}
873 865
874OLedState Zaurus::ledState ( OLed which ) const 866OLedState Zaurus::ledState ( OLed which ) const
875{ 867{
876 if ( which == Led_Mail ) 868 if ( which == Led_Mail )
877 return m_leds [0]; 869 return m_leds [0];
878 else 870 else
879 return Led_Off; 871 return Led_Off;
880} 872}
881 873
882bool Zaurus::setLedState ( OLed which, OLedState st ) 874bool Zaurus::setLedState ( OLed which, OLedState st )
883{ 875{
884 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); 876 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK );
885 877
886 if ( which == Led_Mail ) { 878 if ( which == Led_Mail ) {
887 if ( fd >= 0 ) { 879 if ( fd >= 0 ) {
888 struct sharp_led_status leds; 880 struct sharp_led_status leds;
889 ::memset ( &leds, 0, sizeof( leds )); 881 ::memset ( &leds, 0, sizeof( leds ));
890 leds. which = SHARP_LED_MAIL_EXISTS; 882 leds. which = SHARP_LED_MAIL_EXISTS;
891 bool ok = true; 883 bool ok = true;
892 884
893 switch ( st ) { 885 switch ( st ) {
894 case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; 886 case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break;
895 case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; 887 case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break;
896 case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break; 888 case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break;
897 default : ok = false; 889 default : ok = false;
898 } 890 }
899 891
900 if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) { 892 if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) {
901 m_leds [0] = st; 893 m_leds [0] = st;
902 return true; 894 return true;
903 } 895 }
904 } 896 }
905 } 897 }
906 return false; 898 return false;
907} 899}
908 900
909bool Zaurus::setSoftSuspend ( bool soft ) 901bool Zaurus::setSoftSuspend ( bool soft )
910{ 902{
911 bool res = false; 903 bool res = false;
912 int fd; 904 int fd;
913 905
914 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || 906 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
915 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { 907 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
916 908
917 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources 909 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources
918 910
919 if ( sources >= 0 ) { 911 if ( sources >= 0 ) {
920 if ( soft ) 912 if ( soft )
921 sources &= ~APM_EVT_POWER_BUTTON; 913 sources &= ~APM_EVT_POWER_BUTTON;
922 else 914 else
923 sources |= APM_EVT_POWER_BUTTON; 915 sources |= APM_EVT_POWER_BUTTON;
924 916
925 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources 917 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources
926 res = true; 918 res = true;
927 else 919 else
928 perror ( "APM_IOCGEVTSRC" ); 920 perror ( "APM_IOCGEVTSRC" );
929 } 921 }
930 else 922 else
931 perror ( "APM_IOCGEVTSRC" ); 923 perror ( "APM_IOCGEVTSRC" );
932 924
933 ::close ( fd ); 925 ::close ( fd );
934 } 926 }
935 else 927 else
936 perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); 928 perror ( "/dev/apm_bios or /dev/misc/apm_bios" );
937 929
938 return res; 930 return res;
939} 931}
940 932
941 933
942bool Zaurus::setDisplayBrightness ( int bright ) 934bool Zaurus::setDisplayBrightness ( int bright )
943{ 935{
944 bool res = false; 936 bool res = false;
945 int fd; 937 int fd;
946 938
947 if ( bright > 255 ) 939 if ( bright > 255 )
948 bright = 255; 940 bright = 255;
949 if ( bright < 0 ) 941 if ( bright < 0 )
950 bright = 0; 942 bright = 0;
951 943
952 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) { 944 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) {
953 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus 945 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus
954 if ( bright && !bl ) 946 if ( bright && !bl )
955 bl = 1; 947 bl = 1;
956 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 ); 948 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 );
957 ::close ( fd ); 949 ::close ( fd );
958 } 950 }
959 return res; 951 return res;
960} 952}
961 953
962 954
963int Zaurus::displayBrightnessResolution ( ) const 955int Zaurus::displayBrightnessResolution ( ) const
964{ 956{
965 return 5; 957 return 5;
966} 958}
967 959
968 960