summaryrefslogtreecommitdiff
path: root/libopie/odevice.cpp
Unidiff
Diffstat (limited to 'libopie/odevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 1da8862..2f40731 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -1,354 +1,356 @@
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 27
28#include <qapplication.h> 28#include <qapplication.h>
29 29
30#include <qfile.h> 30#include <qfile.h>
31#include <qtextstream.h> 31#include <qtextstream.h>
32#include <qpe/sound.h> 32#include <qpe/sound.h>
33#include <qpe/resource.h> 33#include <qpe/resource.h>
34#include <qpe/config.h> 34#include <qpe/config.h>
35 35
36 36
37 37
38#include "odevice.h" 38#include "odevice.h"
39 39
40 40
41class ODeviceData { 41class ODeviceData {
42public: 42public:
43 QString m_vendorstr; 43 QString m_vendorstr;
44 OVendor m_vendor; 44 OVendor m_vendor;
45 45
46 QString m_modelstr; 46 QString m_modelstr;
47 OModel m_model; 47 OModel m_model;
48 48
49 QString m_systemstr; 49 QString m_systemstr;
50 OSystem m_system; 50 OSystem m_system;
51 51
52 QString m_sysverstr; 52 QString m_sysverstr;
53 53
54 OLedState m_leds [4]; // just for convenience ... 54 OLedState m_leds [4]; // just for convenience ...
55}; 55};
56 56
57class ODeviceIPAQ : public ODevice { 57class ODeviceIPAQ : public ODevice {
58protected: 58protected:
59 virtual void init ( ); 59 virtual void init ( );
60 60
61public: 61public:
62 virtual void alarmSound ( ); 62 virtual void alarmSound ( );
63 63
64 virtual uint hasLeds ( ) const; 64 virtual uint hasLeds ( ) const;
65 virtual OLedState led ( uint which ) const; 65 virtual OLedState led ( uint which ) const;
66 virtual bool setLed ( uint which, OLedState st ); 66 virtual bool setLed ( uint which, OLedState st );
67}; 67};
68 68
69class ODeviceZaurus : public ODevice { 69class ODeviceZaurus : public ODevice {
70protected: 70protected:
71 virtual void init ( ); 71 virtual void init ( );
72 72
73 public: 73 public:
74 virtual void alarmSound ( ); 74 virtual void alarmSound ( );
75 virtual void keySound ( ); 75 virtual void keySound ( );
76 virtual void touchSound ( ); 76 virtual void touchSound ( );
77 77
78 virtual uint hasLeds ( ) const; 78 virtual uint hasLeds ( ) const;
79 virtual OLedState led ( uint which ) const; 79 virtual OLedState led ( uint which ) const;
80 virtual bool setLed ( uint which, OLedState st ); 80 virtual bool setLed ( uint which, OLedState st );
81 81
82protected: 82protected:
83 virtual void buzzer ( int snd ); 83 virtual void buzzer ( int snd );
84}; 84};
85 85
86 86
87 87
88 88
89ODevice *ODevice::inst ( ) 89ODevice *ODevice::inst ( )
90{ 90{
91 static ODevice *dev = 0; 91 static ODevice *dev = 0;
92 92
93 if ( !dev ) { 93 if ( !dev ) {
94 if ( QFile::exists ( "/proc/hal/model" )) 94 if ( QFile::exists ( "/proc/hal/model" ))
95 dev = new ODeviceIPAQ ( ); 95 dev = new ODeviceIPAQ ( );
96 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) 96 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ))
97 dev = new ODeviceZaurus ( ); 97 dev = new ODeviceZaurus ( );
98 else 98 else
99 dev = new ODevice ( ); 99 dev = new ODevice ( );
100 100
101 dev-> init ( ); 101 dev-> init ( );
102 } 102 }
103 return dev; 103 return dev;
104} 104}
105 105
106ODevice::ODevice ( ) 106ODevice::ODevice ( )
107{ 107{
108 d = new ODeviceData; 108 d = new ODeviceData;
109 109
110 d-> m_modelstr = "Unknown"; 110 d-> m_modelstr = "Unknown";
111 d-> m_model = OMODEL_Unknown; 111 d-> m_model = OMODEL_Unknown;
112 d-> m_vendorstr = "Unkown"; 112 d-> m_vendorstr = "Unkown";
113 d-> m_vendor = OVENDOR_Unknown; 113 d-> m_vendor = OVENDOR_Unknown;
114 d-> m_systemstr = "Unkown"; 114 d-> m_systemstr = "Unkown";
115 d-> m_system = OSYSTEM_Unknown; 115 d-> m_system = OSYSTEM_Unknown;
116 d-> m_sysverstr = "0.0"; 116 d-> m_sysverstr = "0.0";
117} 117}
118 118
119void ODevice::init ( ) 119void ODevice::init ( )
120{ 120{
121} 121}
122 122
123ODevice::~ODevice ( ) 123ODevice::~ODevice ( )
124{ 124{
125 delete d; 125 delete d;
126} 126}
127 127
128//#include <linux/apm_bios.h> 128//#include <linux/apm_bios.h>
129 129
130//#define APM_IOC_SUSPEND _IO('A',2) 130//#define APM_IOC_SUSPEND _IO('A',2)
131 131
132#define APM_IOC_SUSPEND (( 0<<30 ) | ( 'A'<<8 ) | ( 2 ) | ( 0<<16 )) 132#define APM_IOC_SUSPEND (( 0<<30 ) | ( 'A'<<8 ) | ( 2 ) | ( 0<<16 ))
133 133
134bool ODevice::suspend ( ) 134bool ODevice::suspend ( )
135{ 135{
136 if ( d-> m_model == OMODEL_Unknown ) // better don't suspend in qvfb / on unkown devices 136 if ( d-> m_model == OMODEL_Unknown ) // better don't suspend in qvfb / on unkown devices
137 return false; 137 return false;
138 138
139 int fd; 139 int fd;
140 bool res = false; 140 bool res = false;
141 141
142 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || 142 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
143 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { 143 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
144 struct timeval tvs, tvn; 144 struct timeval tvs, tvn;
145 145
146 ::signal ( SIGTSTP, SIG_IGN );// we don't want to be stopped 146 ::signal ( SIGTSTP, SIG_IGN );// we don't want to be stopped
147 ::gettimeofday ( &tvs, 0 ); 147 ::gettimeofday ( &tvs, 0 );
148 148
149 ::sync ( ); // flush fs caches
150
149 res = ( ::ioctl ( fd, APM_IOC_SUSPEND ) == 0 ); // tell the kernel to "start" suspending 151 res = ( ::ioctl ( fd, APM_IOC_SUSPEND ) == 0 ); // tell the kernel to "start" suspending
150 ::close ( fd );
151 152
152 if ( res ) { 153 if ( res ) {
153 ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in out process group 154 ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in our process group
154 155
155 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed 156 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
156 ::usleep ( 200 * 1000 ); 157 ::usleep ( 200 * 1000 );
157 ::gettimeofday ( &tvn, 0 ); 158 ::gettimeofday ( &tvn, 0 );
158 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); 159 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
159 160
160 ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group 161 ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group
161 } 162 }
162 163
164 ::close ( fd );
163 ::signal ( SIGTSTP, SIG_DFL ); 165 ::signal ( SIGTSTP, SIG_DFL );
164 } 166 }
165 167
166 return res; 168 return res;
167} 169}
168 170
169 171
170QString ODevice::vendorString ( ) 172QString ODevice::vendorString ( )
171{ 173{
172 return d-> m_vendorstr; 174 return d-> m_vendorstr;
173} 175}
174 176
175OVendor ODevice::vendor ( ) 177OVendor ODevice::vendor ( )
176{ 178{
177 return d-> m_vendor; 179 return d-> m_vendor;
178} 180}
179 181
180QString ODevice::modelString ( ) 182QString ODevice::modelString ( )
181{ 183{
182 return d-> m_modelstr; 184 return d-> m_modelstr;
183} 185}
184 186
185OModel ODevice::model ( ) 187OModel ODevice::model ( )
186{ 188{
187 return d-> m_model; 189 return d-> m_model;
188} 190}
189 191
190QString ODevice::systemString ( ) 192QString ODevice::systemString ( )
191{ 193{
192 return d-> m_systemstr; 194 return d-> m_systemstr;
193} 195}
194 196
195OSystem ODevice::system ( ) 197OSystem ODevice::system ( )
196{ 198{
197 return d-> m_system; 199 return d-> m_system;
198} 200}
199 201
200QString ODevice::systemVersionString ( ) 202QString ODevice::systemVersionString ( )
201{ 203{
202 return d-> m_sysverstr; 204 return d-> m_sysverstr;
203} 205}
204 206
205void ODevice::alarmSound ( ) 207void ODevice::alarmSound ( )
206{ 208{
207#ifndef QT_QWS_EBX 209#ifndef QT_QWS_EBX
208#ifndef QT_NO_SOUND 210#ifndef QT_NO_SOUND
209 static Sound snd ( "alarm" ); 211 static Sound snd ( "alarm" );
210 212
211 if ( snd. isFinished ( )) 213 if ( snd. isFinished ( ))
212 snd. play ( ); 214 snd. play ( );
213#endif 215#endif
214#endif 216#endif
215} 217}
216 218
217void ODevice::keySound ( ) 219void ODevice::keySound ( )
218{ 220{
219#ifndef QT_QWS_EBX 221#ifndef QT_QWS_EBX
220#ifndef QT_NO_SOUND 222#ifndef QT_NO_SOUND
221 static Sound snd ( "keysound" ); 223 static Sound snd ( "keysound" );
222 224
223 if ( snd. isFinished ( )) 225 if ( snd. isFinished ( ))
224 snd. play ( ); 226 snd. play ( );
225#endif 227#endif
226#endif 228#endif
227} 229}
228 230
229void ODevice::touchSound ( ) 231void ODevice::touchSound ( )
230{ 232{
231 233
232#ifndef QT_QWS_EBX 234#ifndef QT_QWS_EBX
233#ifndef QT_NO_SOUND 235#ifndef QT_NO_SOUND
234 static Sound snd ( "touchsound" ); 236 static Sound snd ( "touchsound" );
235//qDebug("touchSound"); 237//qDebug("touchSound");
236 if ( snd. isFinished ( )) { 238 if ( snd. isFinished ( )) {
237 snd. play ( ); 239 snd. play ( );
238 // qDebug("sound should play"); 240 // qDebug("sound should play");
239 } 241 }
240#endif 242#endif
241#endif 243#endif
242} 244}
243 245
244uint ODevice::hasLeds ( ) const 246uint ODevice::hasLeds ( ) const
245{ 247{
246 return 0; 248 return 0;
247} 249}
248 250
249OLedState ODevice::led ( uint /*which*/ ) const 251OLedState ODevice::led ( uint /*which*/ ) const
250{ 252{
251 return OLED_Off; 253 return OLED_Off;
252} 254}
253 255
254bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ ) 256bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ )
255{ 257{
256 return false; 258 return false;
257} 259}
258 260
259 261
260 262
261 263
262//#if defined( QT_QWS_IPAQ ) // IPAQ 264//#if defined( QT_QWS_IPAQ ) // IPAQ
263 265
264 266
265void ODeviceIPAQ::init ( ) 267void ODeviceIPAQ::init ( )
266{ 268{
267 d-> m_vendorstr = "HP"; 269 d-> m_vendorstr = "HP";
268 d-> m_vendor = OVENDOR_HP; 270 d-> m_vendor = OVENDOR_HP;
269 271
270 QFile f ( "/proc/hal/model" ); 272 QFile f ( "/proc/hal/model" );
271 273
272 if ( f. open ( IO_ReadOnly )) { 274 if ( f. open ( IO_ReadOnly )) {
273 QTextStream ts ( &f ); 275 QTextStream ts ( &f );
274 276
275 d-> m_modelstr = "H" + ts. readLine ( ); 277 d-> m_modelstr = "H" + ts. readLine ( );
276 278
277 if ( d-> m_modelstr == "H3100" ) 279 if ( d-> m_modelstr == "H3100" )
278 d-> m_model = OMODEL_iPAQ_H31xx; 280 d-> m_model = OMODEL_iPAQ_H31xx;
279 else if ( d-> m_modelstr == "H3600" ) 281 else if ( d-> m_modelstr == "H3600" )
280 d-> m_model = OMODEL_iPAQ_H36xx; 282 d-> m_model = OMODEL_iPAQ_H36xx;
281 else if ( d-> m_modelstr == "H3700" ) 283 else if ( d-> m_modelstr == "H3700" )
282 d-> m_model = OMODEL_iPAQ_H37xx; 284 d-> m_model = OMODEL_iPAQ_H37xx;
283 else if ( d-> m_modelstr == "H3800" ) 285 else if ( d-> m_modelstr == "H3800" )
284 d-> m_model = OMODEL_iPAQ_H38xx; 286 d-> m_model = OMODEL_iPAQ_H38xx;
285 else 287 else
286 d-> m_model = OMODEL_Unknown; 288 d-> m_model = OMODEL_Unknown;
287 289
288 f. close ( ); 290 f. close ( );
289 } 291 }
290 292
291 f. setName ( "/etc/familiar-version" ); 293 f. setName ( "/etc/familiar-version" );
292 if ( f. open ( IO_ReadOnly )) { 294 if ( f. open ( IO_ReadOnly )) {
293 d-> m_systemstr = "Familiar"; 295 d-> m_systemstr = "Familiar";
294 d-> m_system = OSYSTEM_Familiar; 296 d-> m_system = OSYSTEM_Familiar;
295 297
296 QTextStream ts ( &f ); 298 QTextStream ts ( &f );
297 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 299 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
298 300
299 f. close ( ); 301 f. close ( );
300 } 302 }
301 303
302 d-> m_leds [0] = OLED_Off; 304 d-> m_leds [0] = OLED_Off;
303} 305}
304 306
305//#include <linux/h3600_ts.h> // including kernel headers is evil ... 307//#include <linux/h3600_ts.h> // including kernel headers is evil ...
306 308
307typedef struct h3600_ts_led { 309typedef struct h3600_ts_led {
308 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ 310 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */
309 unsigned char TotalTime; /* Units of 5 seconds */ 311 unsigned char TotalTime; /* Units of 5 seconds */
310 unsigned char OnTime; /* units of 100m/s */ 312 unsigned char OnTime; /* units of 100m/s */
311 unsigned char OffTime; /* units of 100m/s */ 313 unsigned char OffTime; /* units of 100m/s */
312} LED_IN; 314} LED_IN;
313 315
314 316
315// #define IOC_H3600_TS_MAGIC 'f' 317// #define IOC_H3600_TS_MAGIC 'f'
316// #define LED_ON _IOW(IOC_H3600_TS_MAGIC, 5, struct h3600_ts_led) 318// #define LED_ON _IOW(IOC_H3600_TS_MAGIC, 5, struct h3600_ts_led)
317#define LED_ON (( 1<<30 ) | ( 'f'<<8 ) | ( 5 ) | ( sizeof(struct h3600_ts_led)<<16 )) // _IOW only defined in kernel headers :( 319#define LED_ON (( 1<<30 ) | ( 'f'<<8 ) | ( 5 ) | ( sizeof(struct h3600_ts_led)<<16 )) // _IOW only defined in kernel headers :(
318 320
319 321
320void ODeviceIPAQ::alarmSound ( ) 322void ODeviceIPAQ::alarmSound ( )
321{ 323{
322#if defined( QT_QWS_IPAQ ) // IPAQ 324#if defined( QT_QWS_IPAQ ) // IPAQ
323#ifndef QT_NO_SOUND 325#ifndef QT_NO_SOUND
324 static Sound snd ( "alarm" ); 326 static Sound snd ( "alarm" );
325 int fd; 327 int fd;
326 int vol; 328 int vol;
327 bool vol_reset = false; 329 bool vol_reset = false;
328 330
329 if ((( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) || 331 if ((( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) ||
330 (( fd = ::open ( "/dev/mixer", O_RDWR )) >= 0 )) { 332 (( fd = ::open ( "/dev/mixer", O_RDWR )) >= 0 )) {
331 333
332 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { 334 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
333 Config cfg ( "qpe" ); 335 Config cfg ( "qpe" );
334 cfg. setGroup ( "Volume" ); 336 cfg. setGroup ( "Volume" );
335 337
336 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); 338 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
337 if ( volalarm < 0 ) 339 if ( volalarm < 0 )
338 volalarm = 0; 340 volalarm = 0;
339 else if ( volalarm > 100 ) 341 else if ( volalarm > 100 )
340 volalarm = 100; 342 volalarm = 100;
341 volalarm |= ( volalarm << 8 ); 343 volalarm |= ( volalarm << 8 );
342 344
343 if (( volalarm & 0xff ) > ( vol & 0xff )) { 345 if (( volalarm & 0xff ) > ( vol & 0xff )) {
344 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) 346 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
345 vol_reset = true; 347 vol_reset = true;
346 } 348 }
347 } 349 }
348 } 350 }
349 351
350 snd. play ( ); 352 snd. play ( );
351 while ( !snd. isFinished ( )) 353 while ( !snd. isFinished ( ))
352 qApp-> processEvents ( ); 354 qApp-> processEvents ( );
353 355
354 if ( fd >= 0 ) { 356 if ( fd >= 0 ) {