summaryrefslogtreecommitdiff
path: root/libopie/odevice.cpp
Unidiff
Diffstat (limited to 'libopie/odevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp469
1 files changed, 469 insertions, 0 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
new file mode 100644
index 0000000..d952edf
--- a/dev/null
+++ b/libopie/odevice.cpp
@@ -0,0 +1,469 @@
1/* This file is part of the OPIE libraries
2 Copyright (C) 2002 Robert Griebl (sandman@handhelds.org)
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
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
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18*/
19
20#include <qfile.h>
21#include <qtextstream.h>
22
23
24#include "odevice.h"
25
26
27class ODeviceData {
28public:
29 QString m_vendorstr;
30 OVendor m_vendor;
31
32 QString m_modelstr;
33 OModel m_model;
34
35 QString m_systemstr;
36 OSystem m_system;
37
38 OLedState m_leds [4]; // just for convenience ...
39};
40
41class ODeviceIPAQ : public ODevice {
42protected:
43 virtual void init ( );
44
45public:
46 virtual void alarmSound ( );
47 virtual void keySound ( );
48 virtual void touchSound ( );
49
50 virtual uint hasLeds ( ) const;
51 virtual OLedState led ( uint which ) const;
52 virtual bool setLed ( uint which, OLedState st );
53};
54
55class ODeviceZaurus : public ODevice {
56protected:
57 virtual void init ( );
58
59 public:
60 virtual void alarmSound ( );
61 virtual void keySound ( );
62 virtual void touchSound ( );
63
64 virtual uint hasLeds ( ) const;
65 virtual OLedState led ( uint which ) const;
66 virtual bool setLed ( uint which, OLedState st );
67
68protected:
69 virtual void buzzer ( int snd );
70};
71
72
73
74
75
76
77
78ODevice *ODevice::inst ( )
79{
80 static ODevice *dev = 0;
81
82 if ( !dev ) {
83 if ( QFile::exists ( "/proc/hal/model" ))
84 dev = new ODeviceIPAQ ( );
85 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ))
86 dev = new ODeviceZaurus ( );
87 else
88 dev = new ODevice ( );
89
90 dev-> init ( );
91 }
92 return dev;
93}
94
95ODevice::ODevice ( )
96{
97 d = new ODeviceData;
98
99 d-> m_modelstr = "Unknown";
100 d-> m_model = OMODEL_Unknown;
101 d-> m_vendorstr = "Unkown";
102 d-> m_vendor = OVENDOR_Unknown;
103 d-> m_systemstr = "Unkown";
104 d-> m_system = OSYSTEM_Unknown;
105}
106
107void ODevice::init ( )
108{
109}
110
111ODevice::~ODevice ( )
112{
113 delete d;
114}
115
116QString ODevice::vendorString ( )
117{
118 return d-> m_vendorstr;
119}
120
121OVendor ODevice::vendor ( )
122{
123 return d-> m_vendor;
124}
125
126QString ODevice::modelString ( )
127{
128 return d-> m_modelstr;
129}
130
131OModel ODevice::model ( )
132{
133 return d-> m_model;
134}
135
136QString ODevice::systemString ( )
137{
138 return d-> m_systemstr;
139}
140
141OSystem ODevice::system ( )
142{
143 return d-> m_system;
144}
145
146void ODevice::alarmSound ( )
147{
148}
149
150void ODevice::keySound ( )
151{
152}
153
154void ODevice::touchSound ( )
155{
156}
157
158uint ODevice::hasLeds ( ) const
159{
160 return 0;
161}
162
163OLedState ODevice::led ( uint /*which*/ ) const
164{
165 return OLED_Off;
166}
167
168bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ )
169{
170 return false;
171}
172
173
174
175
176//#if defined( QT_QWS_IPAQ ) // IPAQ
177
178
179void ODeviceIPAQ::init ( )
180{
181 d-> m_vendorstr = "HP";
182 d-> m_vendor = OVENDOR_HP;
183
184 QFile f ( "/proc/hal/model" );
185
186 if ( f. open ( IO_ReadOnly )) {
187 QTextStream ts ( &f );
188
189 d-> m_modelstr = "H" + ts. readLine ( );
190
191 if ( d-> m_modelstr == "H3100" )
192 d-> m_model = OMODEL_iPAQ_H31xx;
193 else if ( d-> m_modelstr == "H3600" )
194 d-> m_model = OMODEL_iPAQ_H36xx;
195 else if ( d-> m_modelstr == "H3700" )
196 d-> m_model = OMODEL_iPAQ_H37xx;
197 else if ( d-> m_modelstr == "H3800" )
198 d-> m_model = OMODEL_iPAQ_H38xx;
199 else
200 d-> m_model = OMODEL_Unknown;
201
202 f. close ( );
203 }
204
205 if ( QFile::exists ( "/etc/familiar-version" )) {
206 d-> m_systemstr = "Familiar";
207 d-> m_system = OSYSTEM_Familiar;
208 }
209
210 d-> m_leds [0] = OLED_Off;
211}
212
213#include <unistd.h>
214#include <fcntl.h>
215#include <sys/ioctl.h>
216#include <linux/soundcard.h>
217#include <qapplication.h>
218#include <qpe/resource.h>
219#include <qpe/config.h>
220#include <qpe/sound.h>
221
222//#include <linux/h3600_ts.h> // including kernel headers is evil ...
223
224typedef struct h3600_ts_led {
225 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */
226 unsigned char TotalTime; /* Units of 5 seconds */
227 unsigned char OnTime; /* units of 100m/s */
228 unsigned char OffTime; /* units of 100m/s */
229} LED_IN;
230
231
232// #define IOC_H3600_TS_MAGIC 'f'
233// #define LED_ON _IOW(IOC_H3600_TS_MAGIC, 5, struct h3600_ts_led)
234#define LED_ON (( 1<<30 ) | ( 'f'<<8 ) | ( 5 ) | ( sizeof(struct h3600_ts_led)<<16 )) // _IOW only defined in kernel headers :(
235
236
237void ODeviceIPAQ::alarmSound ( )
238{
239#ifndef QT_NO_SOUND
240 static Sound snd ( "alarm" );
241 int fd;
242 int vol;
243 bool vol_reset = false;
244
245 if ((( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) ||
246 (( fd = ::open ( "/dev/mixer", O_RDWR )) >= 0 )) {
247
248 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
249 Config cfg ( "qpe" );
250 cfg. setGroup ( "Volume" );
251
252 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
253 if ( volalarm < 0 )
254 volalarm = 0;
255 else if ( volalarm > 100 )
256 volalarm = 100;
257 volalarm |= ( volalarm << 8 );
258
259 if (( volalarm & 0xff ) > ( vol & 0xff )) {
260 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
261 vol_reset = true;
262 }
263 }
264 }
265
266 snd. play ( );
267 while ( !snd. isFinished ( ))
268 qApp-> processEvents ( );
269
270 if ( fd >= 0 ) {
271 if ( vol_reset )
272 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
273 ::close ( fd );
274 }
275#endif
276}
277
278void ODeviceIPAQ::touchSound ( )
279{
280#ifndef QT_NO_SOUND
281 static Sound snd ( "touchsound" );
282
283 if ( snd. isFinished ( ))
284 snd. play ( );
285#endif
286}
287
288void ODeviceIPAQ::keySound ( )
289{
290#ifndef QT_NO_SOUND
291 static Sound snd ( "keysound" );
292
293 if ( snd. isFinished ( ))
294 snd. play ( );
295#endif
296}
297
298
299uint ODeviceIPAQ::hasLeds ( ) const
300{
301 return 1;
302}
303
304OLedState ODeviceIPAQ::led ( uint which ) const
305{
306 if ( which == 0 )
307 return d-> m_leds [0];
308 else
309 return OLED_Off;
310}
311
312bool ODeviceIPAQ::setLed ( uint which, OLedState st )
313{
314 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR|O_NONBLOCK );
315
316 if ( which == 0 ) {
317 if ( fd >= 0 ) {
318 struct h3600_ts_led leds;
319 ::memset ( &leds, 0, sizeof( leds ));
320 leds. TotalTime = 0;
321 leds. OnTime = 0;
322 leds. OffTime = 1;
323 leds. OffOnBlink = 2;
324
325 switch ( st ) {
326 case OLED_Off : leds. OffOnBlink = 0; break;
327 case OLED_On : leds. OffOnBlink = 1; break;
328 case OLED_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break;
329 case OLED_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break;
330 }
331
332 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) {
333 d-> m_leds [0] = st;
334 return true;
335 }
336 }
337 }
338 return false;
339}
340
341
342//#endif
343
344
345
346
347
348//#if defined( QT_QWS_CUSTOM ) // Zaurus
349
350void ODeviceZaurus::init ( )
351 {
352 d-> m_modelstr = "Zaurus SL5000";
353 d-> m_model = OMODEL_Zaurus_SL5000;
354 d-> m_vendorstr = "Sharp";
355 d-> m_vendor = OVENDOR_Sharp;
356
357 QFile f ( "/proc/filesystems" );
358
359 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) {
360 d-> m_systemstr = "OpenZaurus";
361 d-> m_system = OSYSTEM_OpenZaurus;
362
363 f. close ( );
364 }
365 else {
366 d-> m_systemstr = "Zaurus";
367 d-> m_system = OSYSTEM_Zaurus;
368 }
369
370 d-> m_leds [0] = OLED_Off;
371}
372
373#include <unistd.h>
374#include <fcntl.h>
375#include <sys/ioctl.h>
376
377//#include <asm/sharp_char.h> // including kernel headers is evil ...
378
379#define SHARP_DEV_IOCTL_COMMAND_START 0x5680
380
381 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
382#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
383
384#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
385#define SHARP_BUZ_KEYSOUND 2 /* key sound */
386#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
387
388
389 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
390#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1)
391
392typedef struct sharp_led_status {
393 int which; /* select which LED status is wanted. */
394 int status; /* set new led status if you call SHARP_LED_SETSTATUS */
395} sharp_led_status;
396
397#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */
398
399#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */
400#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */
401#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */
402
403
404
405void ODeviceZaurus::buzzer ( int sound )
406{
407 static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK );
408
409 if ( fd >= 0 )
410 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound );
411}
412
413
414void ODeviceZaurus::alarmSound ( )
415{
416 buzzer ( SHARP_BUZ_SCHEDULE_ALARM );
417}
418
419void ODeviceZaurus::touchSound ( )
420{
421 buzzer ( SHARP_BUZ_TOUCHSOUND );
422}
423
424void ODeviceZaurus::keySound ( )
425{
426 buzzer ( SHARP_BUZ_KEYSOUND );
427}
428
429
430uint ODeviceZaurus::hasLeds ( ) const
431{
432 return 1;
433}
434
435OLedState ODeviceZaurus::led ( uint which ) const
436{
437 if ( which == 0 )
438 return d-> m_leds [0];
439 else
440 return OLED_Off;
441}
442
443bool ODeviceZaurus::setLed ( uint which, OLedState st )
444{
445 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK );
446
447 if ( which == 0 ) {
448 if ( fd >= 0 ) {
449 struct sharp_led_status leds;
450 ::memset ( &leds, 0, sizeof( leds ));
451 leds. which = SHARP_LED_MAIL_EXISTS;
452
453 switch ( st ) {
454 case OLED_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break;
455 case OLED_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break;
456 case OLED_BlinkSlow:
457 case OLED_BlinkFast: leds. status = LED_MAIL_UNREAD_MAIL_EX; break;
458 }
459
460 if ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 ) {
461 d-> m_leds [0] = st;
462 return true;
463 }
464 }
465 }
466 return false;
467}
468
469//#endif