summaryrefslogtreecommitdiff
authorsandman <sandman>2002-11-01 19:03:41 (UTC)
committer sandman <sandman>2002-11-01 19:03:41 (UTC)
commit0380a66a6edc8692668a24a49082881b13a4c5fc (patch) (unidiff)
tree6e1fbfe4133d493c6380da26e38d29678b8c3622
parent6860113387bbc86ee33e86327941cafc986e6481 (diff)
downloadopie-0380a66a6edc8692668a24a49082881b13a4c5fc.zip
opie-0380a66a6edc8692668a24a49082881b13a4c5fc.tar.gz
opie-0380a66a6edc8692668a24a49082881b13a4c5fc.tar.bz2
setDisplayBrightness calculated the wrong backlight level for iPAQs
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 8f4e296..7d8cdbf 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -1,970 +1,968 @@
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 307#ifndef QT_QWS_EBX
308#ifndef QT_NO_SOUND 308#ifndef QT_NO_SOUND
309 static Sound snd ( "alarm" ); 309 static Sound snd ( "alarm" );
310 310
311 if ( snd. isFinished ( )) 311 if ( snd. isFinished ( ))
312 snd. play ( ); 312 snd. play ( );
313#endif 313#endif
314#endif 314#endif
315} 315}
316 316
317void ODevice::keySound ( ) 317void ODevice::keySound ( )
318{ 318{
319#ifndef QT_QWS_EBX 319#ifndef QT_QWS_EBX
320#ifndef QT_NO_SOUND 320#ifndef QT_NO_SOUND
321 static Sound snd ( "keysound" ); 321 static Sound snd ( "keysound" );
322 322
323 if ( snd. isFinished ( )) 323 if ( snd. isFinished ( ))
324 snd. play ( ); 324 snd. play ( );
325#endif 325#endif
326#endif 326#endif
327} 327}
328 328
329void ODevice::touchSound ( ) 329void ODevice::touchSound ( )
330{ 330{
331 331
332#ifndef QT_QWS_EBX 332#ifndef QT_QWS_EBX
333#ifndef QT_NO_SOUND 333#ifndef QT_NO_SOUND
334 static Sound snd ( "touchsound" ); 334 static Sound snd ( "touchsound" );
335 335
336 if ( snd. isFinished ( )) 336 if ( snd. isFinished ( ))
337 snd. play ( ); 337 snd. play ( );
338#endif 338#endif
339#endif 339#endif
340} 340}
341 341
342 342
343QValueList <OLed> ODevice::ledList ( ) const 343QValueList <OLed> ODevice::ledList ( ) const
344{ 344{
345 return QValueList <OLed> ( ); 345 return QValueList <OLed> ( );
346} 346}
347 347
348QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const 348QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const
349{ 349{
350 return QValueList <OLedState> ( ); 350 return QValueList <OLedState> ( );
351} 351}
352 352
353OLedState ODevice::ledState ( OLed /*which*/ ) const 353OLedState ODevice::ledState ( OLed /*which*/ ) const
354{ 354{
355 return Led_Off; 355 return Led_Off;
356} 356}
357 357
358bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ ) 358bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ )
359{ 359{
360 return false; 360 return false;
361} 361}
362 362
363bool ODevice::hasLightSensor ( ) const 363bool ODevice::hasLightSensor ( ) const
364{ 364{
365 return false; 365 return false;
366} 366}
367 367
368int ODevice::readLightSensor ( ) 368int ODevice::readLightSensor ( )
369{ 369{
370 return -1; 370 return -1;
371} 371}
372 372
373int ODevice::lightSensorResolution ( ) const 373int ODevice::lightSensorResolution ( ) const
374{ 374{
375 return 0; 375 return 0;
376} 376}
377 377
378//QValueList <int> ODevice::keyList ( ) const 378//QValueList <int> ODevice::keyList ( ) const
379//{ 379//{
380 //return QValueList <int> ( ); 380 //return QValueList <int> ( );
381//} 381//}
382 382
383 383
384 384
385/************************************************** 385/**************************************************
386 * 386 *
387 * iPAQ 387 * iPAQ
388 * 388 *
389 **************************************************/ 389 **************************************************/
390 390
391void iPAQ::init ( ) 391void iPAQ::init ( )
392{ 392{
393 d-> m_vendorstr = "HP"; 393 d-> m_vendorstr = "HP";
394 d-> m_vendor = Vendor_HP; 394 d-> m_vendor = Vendor_HP;
395 395
396 QFile f ( "/proc/hal/model" ); 396 QFile f ( "/proc/hal/model" );
397 397
398 if ( f. open ( IO_ReadOnly )) { 398 if ( f. open ( IO_ReadOnly )) {
399 QTextStream ts ( &f ); 399 QTextStream ts ( &f );
400 400
401 d-> m_modelstr = "H" + ts. readLine ( ); 401 d-> m_modelstr = "H" + ts. readLine ( );
402 402
403 if ( d-> m_modelstr == "H3100" ) 403 if ( d-> m_modelstr == "H3100" )
404 d-> m_model = Model_iPAQ_H31xx; 404 d-> m_model = Model_iPAQ_H31xx;
405 else if ( d-> m_modelstr == "H3600" ) 405 else if ( d-> m_modelstr == "H3600" )
406 d-> m_model = Model_iPAQ_H36xx; 406 d-> m_model = Model_iPAQ_H36xx;
407 else if ( d-> m_modelstr == "H3700" ) 407 else if ( d-> m_modelstr == "H3700" )
408 d-> m_model = Model_iPAQ_H37xx; 408 d-> m_model = Model_iPAQ_H37xx;
409 else if ( d-> m_modelstr == "H3800" ) 409 else if ( d-> m_modelstr == "H3800" )
410 d-> m_model = Model_iPAQ_H38xx; 410 d-> m_model = Model_iPAQ_H38xx;
411 else if ( d-> m_modelstr == "H3900" ) 411 else if ( d-> m_modelstr == "H3900" )
412 d-> m_model = Model_iPAQ_H39xx; 412 d-> m_model = Model_iPAQ_H39xx;
413 else 413 else
414 d-> m_model = Model_Unknown; 414 d-> m_model = Model_Unknown;
415 415
416 f. close ( ); 416 f. close ( );
417 } 417 }
418 418
419 f. setName ( "/etc/familiar-version" ); 419 f. setName ( "/etc/familiar-version" );
420 if ( f. open ( IO_ReadOnly )) { 420 if ( f. open ( IO_ReadOnly )) {
421 d-> m_systemstr = "Familiar"; 421 d-> m_systemstr = "Familiar";
422 d-> m_system = System_Familiar; 422 d-> m_system = System_Familiar;
423 423
424 QTextStream ts ( &f ); 424 QTextStream ts ( &f );
425 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 425 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
426 426
427 f. close ( ); 427 f. close ( );
428 } 428 }
429 429
430 m_leds [0] = m_leds [1] = Led_Off; 430 m_leds [0] = m_leds [1] = Led_Off;
431 431
432 m_power_timer = 0; 432 m_power_timer = 0;
433 433
434 if ( d-> m_qwsserver ) 434 if ( d-> m_qwsserver )
435 QWSServer::setKeyboardFilter ( this ); 435 QWSServer::setKeyboardFilter ( this );
436} 436}
437 437
438//#include <linux/h3600_ts.h> // including kernel headers is evil ... 438//#include <linux/h3600_ts.h> // including kernel headers is evil ...
439 439
440typedef struct { 440typedef struct {
441 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ 441 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */
442 unsigned char TotalTime; /* Units of 5 seconds */ 442 unsigned char TotalTime; /* Units of 5 seconds */
443 unsigned char OnTime; /* units of 100m/s */ 443 unsigned char OnTime; /* units of 100m/s */
444 unsigned char OffTime; /* units of 100m/s */ 444 unsigned char OffTime; /* units of 100m/s */
445} LED_IN; 445} LED_IN;
446 446
447typedef struct { 447typedef struct {
448 unsigned char mode; 448 unsigned char mode;
449 unsigned char pwr; 449 unsigned char pwr;
450 unsigned char brightness; 450 unsigned char brightness;
451} FLITE_IN; 451} FLITE_IN;
452 452
453#define LED_ON OD_IOW( 'f', 5, LED_IN ) 453#define LED_ON OD_IOW( 'f', 5, LED_IN )
454#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) 454#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN )
455 455
456 456
457 457
458QValueList <OLed> iPAQ::ledList ( ) const 458QValueList <OLed> iPAQ::ledList ( ) const
459{ 459{
460 QValueList <OLed> vl; 460 QValueList <OLed> vl;
461 vl << Led_Power; 461 vl << Led_Power;
462 462
463 if ( d-> m_model == Model_iPAQ_H38xx ) 463 if ( d-> m_model == Model_iPAQ_H38xx )
464 vl << Led_BlueTooth; 464 vl << Led_BlueTooth;
465 return vl; 465 return vl;
466} 466}
467 467
468QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const 468QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const
469{ 469{
470 QValueList <OLedState> vl; 470 QValueList <OLedState> vl;
471 471
472 if ( l == Led_Power ) 472 if ( l == Led_Power )
473 vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; 473 vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast;
474 else if ( l == Led_BlueTooth && d-> m_model == Model_iPAQ_H38xx ) 474 else if ( l == Led_BlueTooth && d-> m_model == Model_iPAQ_H38xx )
475 vl << Led_Off; // << Led_On << ??? 475 vl << Led_Off; // << Led_On << ???
476 476
477 return vl; 477 return vl;
478} 478}
479 479
480OLedState iPAQ::ledState ( OLed l ) const 480OLedState iPAQ::ledState ( OLed l ) const
481 { 481 {
482 switch ( l ) { 482 switch ( l ) {
483 case Led_Power: 483 case Led_Power:
484 return m_leds [0]; 484 return m_leds [0];
485 case Led_BlueTooth: 485 case Led_BlueTooth:
486 return m_leds [1]; 486 return m_leds [1];
487 default: 487 default:
488 return Led_Off; 488 return Led_Off;
489 } 489 }
490} 490}
491 491
492bool iPAQ::setLedState ( OLed l, OLedState st ) 492bool iPAQ::setLedState ( OLed l, OLedState st )
493{ 493{
494 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK ); 494 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK );
495 495
496 if ( l == Led_Power ) { 496 if ( l == Led_Power ) {
497 if ( fd >= 0 ) { 497 if ( fd >= 0 ) {
498 LED_IN leds; 498 LED_IN leds;
499 ::memset ( &leds, 0, sizeof( leds )); 499 ::memset ( &leds, 0, sizeof( leds ));
500 leds. TotalTime = 0; 500 leds. TotalTime = 0;
501 leds. OnTime = 0; 501 leds. OnTime = 0;
502 leds. OffTime = 1; 502 leds. OffTime = 1;
503 leds. OffOnBlink = 2; 503 leds. OffOnBlink = 2;
504 504
505 switch ( st ) { 505 switch ( st ) {
506 case Led_Off : leds. OffOnBlink = 0; break; 506 case Led_Off : leds. OffOnBlink = 0; break;
507 case Led_On : leds. OffOnBlink = 1; break; 507 case Led_On : leds. OffOnBlink = 1; break;
508 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; 508 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break;
509 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; 509 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break;
510 } 510 }
511 511
512 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { 512 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) {
513 m_leds [0] = st; 513 m_leds [0] = st;
514 return true; 514 return true;
515 } 515 }
516 } 516 }
517 } 517 }
518 return false; 518 return false;
519} 519}
520 520
521 521
522//QValueList <int> iPAQ::keyList ( ) const 522//QValueList <int> iPAQ::keyList ( ) const
523//{ 523//{
524 //QValueList <int> vl; 524 //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; 525 //vl << HardKey_Datebook << HardKey_Contacts << ( model ( ) == Model_iPAQ_H38xx ? HardKey_Mail : HardKey_Menu ) << HardKey_Home << HardKey_Record << HardKey_Suspend << HardKey_Backlight;
526 //return vl; 526 //return vl;
527//} 527//}
528 528
529bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) 529bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
530{ 530{
531 int newkeycode = keycode; 531 int newkeycode = keycode;
532 532
533 533
534 // simple susbstitutions 534 // simple susbstitutions
535 switch ( d-> m_model ) { 535 switch ( d-> m_model ) {
536 case Model_iPAQ_H38xx: 536 case Model_iPAQ_H38xx:
537 // H38xx has no "Q" key anymore - this is now the Mail key 537 // H38xx has no "Q" key anymore - this is now the Mail key
538 if ( keycode == HardKey_Menu ) 538 if ( keycode == HardKey_Menu )
539 newkeycode = HardKey_Mail; 539 newkeycode = HardKey_Mail;
540 //nobreak 540 //nobreak
541 541
542 case Model_iPAQ_H31xx: 542 case Model_iPAQ_H31xx:
543 // Rotate cursor keys 180° 543 // Rotate cursor keys 180°
544 switch ( keycode ) { 544 switch ( keycode ) {
545 case Key_Left : newkeycode = Key_Right; break; 545 case Key_Left : newkeycode = Key_Right; break;
546 case Key_Right: newkeycode = Key_Left; break; 546 case Key_Right: newkeycode = Key_Left; break;
547 case Key_Up : newkeycode = Key_Down; break; 547 case Key_Up : newkeycode = Key_Down; break;
548 case Key_Down : newkeycode = Key_Up; break; 548 case Key_Down : newkeycode = Key_Up; break;
549 } 549 }
550 //nobreak; 550 //nobreak;
551 551
552 case Model_iPAQ_H36xx: 552 case Model_iPAQ_H36xx:
553 case Model_iPAQ_H37xx: 553 case Model_iPAQ_H37xx:
554 // map Power Button short/long press to F34/F35 554 // map Power Button short/long press to F34/F35
555 if ( keycode == Key_SysReq ) { 555 if ( keycode == Key_SysReq ) {
556 if ( isPress ) { 556 if ( isPress ) {
557 if ( m_power_timer ) 557 if ( m_power_timer )
558 killTimer ( m_power_timer ); 558 killTimer ( m_power_timer );
559 m_power_timer = startTimer ( 500 ); 559 m_power_timer = startTimer ( 500 );
560 } 560 }
561 else if ( m_power_timer ) { 561 else if ( m_power_timer ) {
562 killTimer ( m_power_timer ); 562 killTimer ( m_power_timer );
563 m_power_timer = 0; 563 m_power_timer = 0;
564 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); 564 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false );
565 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); 565 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false );
566 } 566 }
567 newkeycode = Key_unknown; 567 newkeycode = Key_unknown;
568 } 568 }
569 //nobreak; 569 //nobreak;
570 570
571 default: 571 default:
572 break; 572 break;
573 } 573 }
574 574
575 if ( newkeycode != keycode ) { 575 if ( newkeycode != keycode ) {
576 if ( newkeycode != Key_unknown ) 576 if ( newkeycode != Key_unknown )
577 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); 577 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
578 return true; 578 return true;
579 } 579 }
580 else 580 else
581 return false; 581 return false;
582} 582}
583 583
584void iPAQ::timerEvent ( QTimerEvent * ) 584void iPAQ::timerEvent ( QTimerEvent * )
585{ 585{
586 killTimer ( m_power_timer ); 586 killTimer ( m_power_timer );
587 m_power_timer = 0; 587 m_power_timer = 0;
588 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); 588 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false );
589 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); 589 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false );
590} 590}
591 591
592 592
593void iPAQ::alarmSound ( ) 593void iPAQ::alarmSound ( )
594{ 594{
595#if defined( QT_QWS_IPAQ ) // IPAQ 595#if defined( QT_QWS_IPAQ ) // IPAQ
596#ifndef QT_NO_SOUND 596#ifndef QT_NO_SOUND
597 static Sound snd ( "alarm" ); 597 static Sound snd ( "alarm" );
598 int fd; 598 int fd;
599 int vol; 599 int vol;
600 bool vol_reset = false; 600 bool vol_reset = false;
601 601
602 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { 602 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) {
603 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { 603 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
604 Config cfg ( "qpe" ); 604 Config cfg ( "qpe" );
605 cfg. setGroup ( "Volume" ); 605 cfg. setGroup ( "Volume" );
606 606
607 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); 607 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
608 if ( volalarm < 0 ) 608 if ( volalarm < 0 )
609 volalarm = 0; 609 volalarm = 0;
610 else if ( volalarm > 100 ) 610 else if ( volalarm > 100 )
611 volalarm = 100; 611 volalarm = 100;
612 volalarm |= ( volalarm << 8 ); 612 volalarm |= ( volalarm << 8 );
613 613
614 if (( volalarm & 0xff ) > ( vol & 0xff )) { 614 if (( volalarm & 0xff ) > ( vol & 0xff )) {
615 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) 615 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
616 vol_reset = true; 616 vol_reset = true;
617 } 617 }
618 } 618 }
619 } 619 }
620 620
621 snd. play ( ); 621 snd. play ( );
622 while ( !snd. isFinished ( )) 622 while ( !snd. isFinished ( ))
623 qApp-> processEvents ( ); 623 qApp-> processEvents ( );
624 624
625 if ( fd >= 0 ) { 625 if ( fd >= 0 ) {
626 if ( vol_reset ) 626 if ( vol_reset )
627 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); 627 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
628 ::close ( fd ); 628 ::close ( fd );
629 } 629 }
630#endif 630#endif
631#endif 631#endif
632} 632}
633 633
634 634
635bool iPAQ::setSoftSuspend ( bool soft ) 635bool iPAQ::setSoftSuspend ( bool soft )
636{ 636{
637 bool res = false; 637 bool res = false;
638 int fd; 638 int fd;
639 639
640 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { 640 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) {
641 if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) 641 if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 )
642 res = true; 642 res = true;
643 else 643 else
644 ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); 644 ::perror ( "write to /proc/sys/ts/suspend_button_mode" );
645 645
646 ::close ( fd ); 646 ::close ( fd );
647 } 647 }
648 else 648 else
649 ::perror ( "/proc/sys/ts/suspend_button_mode" ); 649 ::perror ( "/proc/sys/ts/suspend_button_mode" );
650 650
651 return res; 651 return res;
652} 652}
653 653
654 654
655bool iPAQ::setDisplayBrightness ( int bright ) 655bool iPAQ::setDisplayBrightness ( int bright )
656{ 656{
657 bool res = false; 657 bool res = false;
658 int fd; 658 int fd;
659 659
660 int maxbright = displayBrightnessResolution ( ); 660 if ( bright > 255 )
661 661 bright = 255;
662 if ( bright > maxbright )
663 bright = maxbright;
664 if ( bright < 0 ) 662 if ( bright < 0 )
665 bright = 0; 663 bright = 0;
666 664
667 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { 665 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
668 FLITE_IN bl; 666 FLITE_IN bl;
669 bl. mode = 1; 667 bl. mode = 1;
670 bl. pwr = bright ? 1 : 0; 668 bl. pwr = bright ? 1 : 0;
671 bl. brightness = bright; 669 bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255;
672 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); 670 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 );
673 ::close ( fd ); 671 ::close ( fd );
674 } 672 }
675 return res; 673 return res;
676} 674}
677 675
678int iPAQ::displayBrightnessResolution ( ) const 676int iPAQ::displayBrightnessResolution ( ) const
679{ 677{
680 switch ( model ( )) { 678 switch ( model ( )) {
681 case Model_iPAQ_H31xx: 679 case Model_iPAQ_H31xx:
682 case Model_iPAQ_H36xx: 680 case Model_iPAQ_H36xx:
683 case Model_iPAQ_H37xx: 681 case Model_iPAQ_H37xx:
684 return 128; // really 256, but >128 could damage the LCD 682 return 128; // really 256, but >128 could damage the LCD
685 683
686 case Model_iPAQ_H38xx: 684 case Model_iPAQ_H38xx:
687 case Model_iPAQ_H39xx: 685 case Model_iPAQ_H39xx:
688 return 64; 686 return 64;
689 687
690 default: 688 default:
691 return 2; 689 return 2;
692 } 690 }
693} 691}
694 692
695 693
696bool iPAQ::hasLightSensor ( ) const 694bool iPAQ::hasLightSensor ( ) const
697{ 695{
698 return true; 696 return true;
699} 697}
700 698
701int iPAQ::readLightSensor ( ) 699int iPAQ::readLightSensor ( )
702{ 700{
703 int fd; 701 int fd;
704 int val = -1; 702 int val = -1;
705 703
706 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { 704 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) {
707 char buffer [8]; 705 char buffer [8];
708 706
709 if ( ::read ( fd, buffer, 5 ) == 5 ) { 707 if ( ::read ( fd, buffer, 5 ) == 5 ) {
710 char *endptr; 708 char *endptr;
711 709
712 buffer [4] = 0; 710 buffer [4] = 0;
713 val = ::strtol ( buffer + 2, &endptr, 16 ); 711 val = ::strtol ( buffer + 2, &endptr, 16 );
714 712
715 if ( *endptr != 0 ) 713 if ( *endptr != 0 )
716 val = -1; 714 val = -1;
717 } 715 }
718 ::close ( fd ); 716 ::close ( fd );
719 } 717 }
720 718
721 return val; 719 return val;
722} 720}
723 721
724int iPAQ::lightSensorResolution ( ) const 722int iPAQ::lightSensorResolution ( ) const
725{ 723{
726 return 256; 724 return 256;
727} 725}
728 726
729/************************************************** 727/**************************************************
730 * 728 *
731 * Zaurus 729 * Zaurus
732 * 730 *
733 **************************************************/ 731 **************************************************/
734 732
735 733
736 734
737void Zaurus::init ( ) 735void Zaurus::init ( )
738{ 736{
739 d-> m_modelstr = "Zaurus SL5000"; 737 d-> m_modelstr = "Zaurus SL5000";
740 d-> m_model = Model_Zaurus_SL5000; 738 d-> m_model = Model_Zaurus_SL5000;
741 d-> m_vendorstr = "Sharp"; 739 d-> m_vendorstr = "Sharp";
742 d-> m_vendor = Vendor_Sharp; 740 d-> m_vendor = Vendor_Sharp;
743 741
744 QFile f ( "/proc/filesystems" ); 742 QFile f ( "/proc/filesystems" );
745 743
746 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { 744 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) {
747 d-> m_systemstr = "OpenZaurus"; 745 d-> m_systemstr = "OpenZaurus";
748 d-> m_system = System_OpenZaurus; 746 d-> m_system = System_OpenZaurus;
749 747
750 f. close ( ); 748 f. close ( );
751 749
752 f. setName ( "/etc/oz_version" ); 750 f. setName ( "/etc/oz_version" );
753 if ( f. open ( IO_ReadOnly )) { 751 if ( f. open ( IO_ReadOnly )) {
754 QTextStream ts ( &f ); 752 QTextStream ts ( &f );
755 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 753 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
756 f. close ( ); 754 f. close ( );
757 } 755 }
758 } 756 }
759 else { 757 else {
760 d-> m_systemstr = "Zaurus"; 758 d-> m_systemstr = "Zaurus";
761 d-> m_system = System_Zaurus; 759 d-> m_system = System_Zaurus;
762 } 760 }
763 761
764 762
765 m_leds [0] = Led_Off; 763 m_leds [0] = Led_Off;
766} 764}
767 765
768#include <unistd.h> 766#include <unistd.h>
769#include <fcntl.h> 767#include <fcntl.h>
770#include <sys/ioctl.h> 768#include <sys/ioctl.h>
771 769
772//#include <asm/sharp_char.h> // including kernel headers is evil ... 770//#include <asm/sharp_char.h> // including kernel headers is evil ...
773 771
774#define SHARP_DEV_IOCTL_COMMAND_START 0x5680 772#define SHARP_DEV_IOCTL_COMMAND_START 0x5680
775 773
776 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 774 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
777#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 775#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
778 776
779#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 777#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
780#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 778#define SHARP_BUZ_KEYSOUND 2 /* key sound */
781#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 779#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
782 780
783/* --- for SHARP_BUZZER device --- */ 781/* --- for SHARP_BUZZER device --- */
784 782
785 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 783 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
786//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 784//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
787 785
788#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) 786#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1)
789#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2) 787#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2)
790#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3) 788#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3)
791#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4) 789#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4)
792#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5) 790#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5)
793 791
794//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 792//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
795//#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 793//#define SHARP_BUZ_KEYSOUND 2 /* key sound */
796 794
797//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */ 795//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */
798//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */ 796//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */
799//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */ 797//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */
800//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */ 798//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */
801//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */ 799//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */
802//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */ 800//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */
803//#define SHARP_PDA_APPSTART 9 /* application start */ 801//#define SHARP_PDA_APPSTART 9 /* application start */
804//#define SHARP_PDA_APPQUIT 10 /* application ends */ 802//#define SHARP_PDA_APPQUIT 10 /* application ends */
805 803
806//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 804//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
807//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */ 805//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */
808//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */ 806//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */
809//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */ 807//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */
810// 808//
811 809
812 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 810 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
813#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1) 811#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1)
814 812
815typedef struct sharp_led_status { 813typedef struct sharp_led_status {
816 int which; /* select which LED status is wanted. */ 814 int which; /* select which LED status is wanted. */
817 int status; /* set new led status if you call SHARP_LED_SETSTATUS */ 815 int status; /* set new led status if you call SHARP_LED_SETSTATUS */
818} sharp_led_status; 816} sharp_led_status;
819 817
820#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */ 818#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */
821 819
822#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */ 820#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */
823#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */ 821#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */
824#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */ 822#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */
825 823
826// #include <asm/sharp_apm.h> // including kernel headers is evil ... 824// #include <asm/sharp_apm.h> // including kernel headers is evil ...
827 825
828#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int ) 826#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int )
829#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int ) 827#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int )
830#define APM_EVT_POWER_BUTTON (1 << 0) 828#define APM_EVT_POWER_BUTTON (1 << 0)
831 829
832#define FL_IOCTL_STEP_CONTRAST 100 830#define FL_IOCTL_STEP_CONTRAST 100
833 831
834 832
835void Zaurus::buzzer ( int sound ) 833void Zaurus::buzzer ( int sound )
836{ 834{
837 static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK ); 835 static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK );
838 836
839 if ( fd >= 0 ) 837 if ( fd >= 0 )
840 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); 838 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound );
841} 839}
842 840
843 841
844void Zaurus::alarmSound ( ) 842void Zaurus::alarmSound ( )
845{ 843{
846 buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); 844 buzzer ( SHARP_BUZ_SCHEDULE_ALARM );
847} 845}
848 846
849void Zaurus::touchSound ( ) 847void Zaurus::touchSound ( )
850{ 848{
851 buzzer ( SHARP_BUZ_TOUCHSOUND ); 849 buzzer ( SHARP_BUZ_TOUCHSOUND );
852} 850}
853 851
854void Zaurus::keySound ( ) 852void Zaurus::keySound ( )
855{ 853{
856 buzzer ( SHARP_BUZ_KEYSOUND ); 854 buzzer ( SHARP_BUZ_KEYSOUND );
857} 855}
858 856
859 857
860QValueList <OLed> Zaurus::ledList ( ) const 858QValueList <OLed> Zaurus::ledList ( ) const
861{ 859{
862 QValueList <OLed> vl; 860 QValueList <OLed> vl;
863 vl << Led_Mail; 861 vl << Led_Mail;
864 return vl; 862 return vl;
865} 863}
866 864
867QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const 865QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const
868{ 866{
869 QValueList <OLedState> vl; 867 QValueList <OLedState> vl;
870 868
871 if ( l == Led_Mail ) 869 if ( l == Led_Mail )
872 vl << Led_Off << Led_On << Led_BlinkSlow; 870 vl << Led_Off << Led_On << Led_BlinkSlow;
873 return vl; 871 return vl;
874} 872}
875 873
876OLedState Zaurus::ledState ( OLed which ) const 874OLedState Zaurus::ledState ( OLed which ) const
877{ 875{
878 if ( which == Led_Mail ) 876 if ( which == Led_Mail )
879 return m_leds [0]; 877 return m_leds [0];
880 else 878 else
881 return Led_Off; 879 return Led_Off;
882} 880}
883 881
884bool Zaurus::setLedState ( OLed which, OLedState st ) 882bool Zaurus::setLedState ( OLed which, OLedState st )
885{ 883{
886 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); 884 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK );
887 885
888 if ( which == Led_Mail ) { 886 if ( which == Led_Mail ) {
889 if ( fd >= 0 ) { 887 if ( fd >= 0 ) {
890 struct sharp_led_status leds; 888 struct sharp_led_status leds;
891 ::memset ( &leds, 0, sizeof( leds )); 889 ::memset ( &leds, 0, sizeof( leds ));
892 leds. which = SHARP_LED_MAIL_EXISTS; 890 leds. which = SHARP_LED_MAIL_EXISTS;
893 bool ok = true; 891 bool ok = true;
894 892
895 switch ( st ) { 893 switch ( st ) {
896 case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; 894 case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break;
897 case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; 895 case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break;
898 case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break; 896 case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break;
899 default : ok = false; 897 default : ok = false;
900 } 898 }
901 899
902 if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) { 900 if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) {
903 m_leds [0] = st; 901 m_leds [0] = st;
904 return true; 902 return true;
905 } 903 }
906 } 904 }
907 } 905 }
908 return false; 906 return false;
909} 907}
910 908
911bool Zaurus::setSoftSuspend ( bool soft ) 909bool Zaurus::setSoftSuspend ( bool soft )
912{ 910{
913 bool res = false; 911 bool res = false;
914 int fd; 912 int fd;
915 913
916 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || 914 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
917 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { 915 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
918 916
919 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources 917 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources
920 918
921 if ( sources >= 0 ) { 919 if ( sources >= 0 ) {
922 if ( soft ) 920 if ( soft )
923 sources &= ~APM_EVT_POWER_BUTTON; 921 sources &= ~APM_EVT_POWER_BUTTON;
924 else 922 else
925 sources |= APM_EVT_POWER_BUTTON; 923 sources |= APM_EVT_POWER_BUTTON;
926 924
927 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources 925 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources
928 res = true; 926 res = true;
929 else 927 else
930 perror ( "APM_IOCGEVTSRC" ); 928 perror ( "APM_IOCGEVTSRC" );
931 } 929 }
932 else 930 else
933 perror ( "APM_IOCGEVTSRC" ); 931 perror ( "APM_IOCGEVTSRC" );
934 932
935 ::close ( fd ); 933 ::close ( fd );
936 } 934 }
937 else 935 else
938 perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); 936 perror ( "/dev/apm_bios or /dev/misc/apm_bios" );
939 937
940 return res; 938 return res;
941} 939}
942 940
943 941
944bool Zaurus::setDisplayBrightness ( int bright ) 942bool Zaurus::setDisplayBrightness ( int bright )
945{ 943{
946 bool res = false; 944 bool res = false;
947 int fd; 945 int fd;
948 946
949 if ( bright > 255 ) 947 if ( bright > 255 )
950 bright = 255; 948 bright = 255;
951 if ( bright < 0 ) 949 if ( bright < 0 )
952 bright = 0; 950 bright = 0;
953 951
954 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) { 952 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) {
955 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus 953 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus
956 if ( bright && !bl ) 954 if ( bright && !bl )
957 bl = 1; 955 bl = 1;
958 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 ); 956 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 );
959 ::close ( fd ); 957 ::close ( fd );
960 } 958 }
961 return res; 959 return res;
962} 960}
963 961
964 962
965int Zaurus::displayBrightnessResolution ( ) const 963int Zaurus::displayBrightnessResolution ( ) const
966{ 964{
967 return 5; 965 return 5;
968} 966}
969 967
970 968