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