summaryrefslogtreecommitdiff
path: root/libopie
authorsandman <sandman>2002-06-18 12:44:05 (UTC)
committer sandman <sandman>2002-06-18 12:44:05 (UTC)
commite21322ab34a8df36344eece685e604abe4f83fc6 (patch) (unidiff)
tree199bf3f1b70b7d364d5ad836e01789ab6ce87d70 /libopie
parent714133d7f0e2a0dafe55b280f93915765fc67fe3 (diff)
downloadopie-e21322ab34a8df36344eece685e604abe4f83fc6.zip
opie-e21322ab34a8df36344eece685e604abe4f83fc6.tar.gz
opie-e21322ab34a8df36344eece685e604abe4f83fc6.tar.bz2
Reimplemented OHwInfo as ODevice with enhanced capabilities
ODevice should replace custom-*.h in the future (iPAQ is finished)
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/libopie.pro4
-rw-r--r--libopie/odevice.cpp469
-rw-r--r--libopie/odevice.h107
-rw-r--r--libopie/ohwinfo.cpp84
-rw-r--r--libopie/ohwinfo.h48
5 files changed, 578 insertions, 134 deletions
diff --git a/libopie/libopie.pro b/libopie/libopie.pro
index 49a7f49..d1cbe3e 100644
--- a/libopie/libopie.pro
+++ b/libopie/libopie.pro
@@ -1,8 +1,8 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qte warn_on release 2CONFIG += qte warn_on release
3 HEADERS = ofontmenu.h ofileselector.h ofiledialog.h ofileview.h tododb.h todoevent.h todoresource.h todovcalresource.h xmltree.h colordialog.h colorpopupmenu.h oclickablelabel.h oprocctrl.h oprocess.h ohwinfo.h 3 HEADERS = ofontmenu.h ofileselector.h ofiledialog.h ofileview.h tododb.h todoevent.h todoresource.h todovcalresource.h xmltree.h colordialog.h colorpopupmenu.h oclickablelabel.h oprocctrl.h oprocess.h odevice.h
4 SOURCES = ofontmenu.cc ofileselector.cc ofiledialog.cc xmltree.cc tododb.cpp todoevent.cpp todovcalresource.cpp colordialog.cpp colorpopupmenu.cpp oclickablelabel.cpp oprocctrl.cpp oprocess.cpp ohwinfo.cpp 4 SOURCES = ofontmenu.cc ofileselector.cc ofiledialog.cc xmltree.cc tododb.cpp todoevent.cpp todovcalresource.cpp colordialog.cpp colorpopupmenu.cpp oclickablelabel.cpp oprocctrl.cpp oprocess.cpp odevice.cpp
5 TARGET = opie 5 TARGET = opie
6INCLUDEPATH += $(OPIEDIR)/include 6INCLUDEPATH += $(OPIEDIR)/include
7DESTDIR = $(QTDIR)/lib$(PROJMAK) 7DESTDIR = $(QTDIR)/lib$(PROJMAK)
8#VERSION = 1.0.0 8#VERSION = 1.0.0
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
diff --git a/libopie/odevice.h b/libopie/odevice.h
new file mode 100644
index 0000000..793becc
--- a/dev/null
+++ b/libopie/odevice.h
@@ -0,0 +1,107 @@
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#ifndef _LIBOPIE_ODEVICE_H_
21#define _LIBOPIE_ODEVICE_H_
22
23#include <qstring.h>
24
25
26class ODeviceData;
27
28enum OModel {
29 OMODEL_Unknown,
30
31 OMODEL_iPAQ_H31xx,
32 OMODEL_iPAQ_H36xx,
33 OMODEL_iPAQ_H37xx,
34 OMODEL_iPAQ_H38xx,
35
36 OMODEL_Zaurus_SL5000
37};
38
39 enum OVendor {
40 OVENDOR_Unknown,
41
42 OVENDOR_HP,
43 OVENDOR_Sharp,
44 };
45
46enum OSystem {
47 OSYSTEM_Unknown,
48
49 OSYSTEM_Familiar,
50 OSYSTEM_Zaurus,
51 OSYSTEM_OpenZaurus
52};
53
54enum OLedState {
55 OLED_Off,
56 OLED_On,
57 OLED_BlinkSlow,
58 OLED_BlinkFast
59};
60
61
62class ODevice
63{
64public:
65
66public:
67 static ODevice *inst ( );
68
69
70// information
71
72 QString modelString ( );
73 OModel model ( );
74
75 QString vendorString ( );
76 OVendor vendor ( );
77
78 QString systemString ( );
79 OSystem system ( );
80
81
82// input / output
83
84 virtual void alarmSound ( );
85 virtual void keySound ( );
86 virtual void touchSound ( );
87
88 virtual uint hasLeds ( ) const;
89 virtual OLedState led ( uint which ) const;
90 virtual bool setLed ( uint which, OLedState st );
91
92 virtual ~ODevice ( );
93
94protected:
95 ODevice ( );
96 virtual void init ( );
97
98 ODeviceData *d;
99
100private:
101 ODevice ( const ODevice & );
102
103};
104
105#endif
106
107
diff --git a/libopie/ohwinfo.cpp b/libopie/ohwinfo.cpp
deleted file mode 100644
index 30c47c8..0000000
--- a/libopie/ohwinfo.cpp
+++ b/dev/null
@@ -1,84 +0,0 @@
1#include <qfile.h>
2#include <qtextstream.h>
3
4#include "ohwinfo.h"
5
6
7struct OHwInfoData {
8 QString m_vendorstr;
9 OHwVendor m_vendor;
10
11 QString m_modelstr;
12 OHwModel m_model;
13};
14
15
16OHwInfo *OHwInfo::inst ( )
17{
18 static OHwInfo *inf = 0;
19
20 if ( !inf ) {
21 inf = new OHwInfo ( );
22 }
23 return inf;
24}
25
26OHwInfo::OHwInfo ( )
27{
28 m_data = new OHwInfoData ( );
29
30 QFile f ( "/proc/hal/model" );
31
32 if ( f. open ( IO_ReadOnly )) {
33 QTextStream ts ( &f );
34 m_data-> m_modelstr = "H" + ts. readLine ( );
35
36 if ( m_data-> m_modelstr == "H3100" )
37 m_data-> m_model = OMODEL_iPAQ_H31xx;
38 else if ( m_data-> m_modelstr == "H3600" )
39 m_data-> m_model = OMODEL_iPAQ_H36xx;
40 else if ( m_data-> m_modelstr == "H3700" )
41 m_data-> m_model = OMODEL_iPAQ_H37xx;
42 else if ( m_data-> m_modelstr == "H3800" )
43 m_data-> m_model = OMODEL_iPAQ_H38xx;
44 else
45 m_data-> m_model = OMODEL_Unknown;
46
47 m_data-> m_vendorstr = "HP";
48 m_data-> m_vendor = OVENDOR_HP;
49
50 f. close ( );
51 }
52 else {
53 m_data-> m_modelstr = "Unknown";
54 m_data-> m_model = OMODEL_Unknown;
55 m_data-> m_vendorstr = "Unkown";
56 m_data-> m_vendor = OVENDOR_Unknown;
57 }
58}
59
60OHwInfo::~OHwInfo ( )
61{
62 delete m_data;
63}
64
65QString OHwInfo::vendorString ( )
66{
67 return m_data-> m_vendorstr;
68}
69
70OHwVendor OHwInfo::vendor ( )
71{
72 return m_data-> m_vendor;
73}
74
75QString OHwInfo::modelString ( )
76{
77 return m_data-> m_modelstr;
78}
79
80OHwModel OHwInfo::model ( )
81{
82 return m_data-> m_model;
83}
84
diff --git a/libopie/ohwinfo.h b/libopie/ohwinfo.h
deleted file mode 100644
index e2106f3..0000000
--- a/libopie/ohwinfo.h
+++ b/dev/null
@@ -1,48 +0,0 @@
1#ifndef _LIBOPIE_OHWINFO_H_
2#define _LIBOPIE_OHWINFO_H_
3
4#include <qstring.h>
5
6enum OHwModel {
7 OMODEL_Unknown,
8
9 OMODEL_iPAQ_H31xx,
10 OMODEL_iPAQ_H36xx,
11 OMODEL_iPAQ_H37xx,
12 OMODEL_iPAQ_H38xx,
13
14 OMODEL_Zaurus_SL5000
15};
16
17 enum OHwVendor {
18 OVENDOR_Unknown,
19
20 OVENDOR_HP,
21 OVENDOR_Sharp,
22};
23
24class OHwInfoData;
25
26
27class OHwInfo
28{
29public:
30 static OHwInfo *inst ( );
31
32 QString modelString ( );
33 OHwModel model ( );
34
35 QString vendorString ( );
36 OHwVendor vendor ( );
37
38 virtual ~OHwInfo ( );
39
40private:
41 OHwInfo ( );
42 OHwInfo ( const OHwInfo & );
43
44 OHwInfoData *m_data;
45};
46
47#endif
48