-rw-r--r-- | libopie/odevice.cpp | 119 |
1 files changed, 54 insertions, 65 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index bf64676..6572fb6 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp | |||
@@ -1,578 +1,567 @@ | |||
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> | ||
22 | #include <fcntl.h> | ||
23 | #include <sys/ioctl.h> | ||
24 | #include <signal.h> | ||
25 | #include <sys/time.h> | ||
26 | #include <linux/soundcard.h> | ||
27 | |||
28 | #include <qapplication.h> | ||
21 | 29 | ||
22 | #include <qfile.h> | 30 | #include <qfile.h> |
23 | #include <qtextstream.h> | 31 | #include <qtextstream.h> |
24 | #include <qpe/sound.h> | 32 | #include <qpe/sound.h> |
25 | #include <qpe/resource.h> | 33 | #include <qpe/resource.h> |
34 | #include <qpe/config.h> | ||
35 | |||
26 | 36 | ||
27 | 37 | ||
28 | #include "odevice.h" | 38 | #include "odevice.h" |
29 | 39 | ||
30 | 40 | ||
31 | class ODeviceData { | 41 | class ODeviceData { |
32 | public: | 42 | public: |
33 | QString m_vendorstr; | 43 | QString m_vendorstr; |
34 | OVendor m_vendor; | 44 | OVendor m_vendor; |
35 | 45 | ||
36 | QString m_modelstr; | 46 | QString m_modelstr; |
37 | OModel m_model; | 47 | OModel m_model; |
38 | 48 | ||
39 | QString m_systemstr; | 49 | QString m_systemstr; |
40 | OSystem m_system; | 50 | OSystem m_system; |
41 | 51 | ||
42 | QString m_sysverstr; | 52 | QString m_sysverstr; |
43 | 53 | ||
44 | OLedState m_leds [4]; // just for convenience ... | 54 | OLedState m_leds [4]; // just for convenience ... |
45 | }; | 55 | }; |
46 | 56 | ||
47 | class ODeviceIPAQ : public ODevice { | 57 | class ODeviceIPAQ : public ODevice { |
48 | protected: | 58 | protected: |
49 | virtual void init ( ); | 59 | virtual void init ( ); |
50 | 60 | ||
51 | public: | 61 | public: |
52 | virtual bool suspend ( ); | ||
53 | |||
54 | virtual void alarmSound ( ); | 62 | virtual void alarmSound ( ); |
55 | 63 | ||
56 | virtual uint hasLeds ( ) const; | 64 | virtual uint hasLeds ( ) const; |
57 | virtual OLedState led ( uint which ) const; | 65 | virtual OLedState led ( uint which ) const; |
58 | virtual bool setLed ( uint which, OLedState st ); | 66 | virtual bool setLed ( uint which, OLedState st ); |
59 | |||
60 | private: | ||
61 | static void tstp_sighandler ( int ); | ||
62 | }; | 67 | }; |
63 | 68 | ||
64 | class ODeviceZaurus : public ODevice { | 69 | class ODeviceZaurus : public ODevice { |
65 | protected: | 70 | protected: |
66 | virtual void init ( ); | 71 | virtual void init ( ); |
67 | 72 | ||
68 | public: | 73 | public: |
69 | virtual void alarmSound ( ); | 74 | virtual void alarmSound ( ); |
70 | virtual void keySound ( ); | 75 | virtual void keySound ( ); |
71 | virtual void touchSound ( ); | 76 | virtual void touchSound ( ); |
72 | 77 | ||
73 | virtual uint hasLeds ( ) const; | 78 | virtual uint hasLeds ( ) const; |
74 | virtual OLedState led ( uint which ) const; | 79 | virtual OLedState led ( uint which ) const; |
75 | virtual bool setLed ( uint which, OLedState st ); | 80 | virtual bool setLed ( uint which, OLedState st ); |
76 | 81 | ||
77 | protected: | 82 | protected: |
78 | virtual void buzzer ( int snd ); | 83 | virtual void buzzer ( int snd ); |
79 | }; | 84 | }; |
80 | 85 | ||
81 | 86 | ||
82 | 87 | ||
83 | 88 | ||
84 | ODevice *ODevice::inst ( ) | 89 | ODevice *ODevice::inst ( ) |
85 | { | 90 | { |
86 | static ODevice *dev = 0; | 91 | static ODevice *dev = 0; |
87 | 92 | ||
88 | if ( !dev ) { | 93 | if ( !dev ) { |
89 | if ( QFile::exists ( "/proc/hal/model" )) | 94 | if ( QFile::exists ( "/proc/hal/model" )) |
90 | dev = new ODeviceIPAQ ( ); | 95 | dev = new ODeviceIPAQ ( ); |
91 | 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" )) |
92 | dev = new ODeviceZaurus ( ); | 97 | dev = new ODeviceZaurus ( ); |
93 | else | 98 | else |
94 | dev = new ODevice ( ); | 99 | dev = new ODevice ( ); |
95 | 100 | ||
96 | dev-> init ( ); | 101 | dev-> init ( ); |
97 | } | 102 | } |
98 | return dev; | 103 | return dev; |
99 | } | 104 | } |
100 | 105 | ||
101 | ODevice::ODevice ( ) | 106 | ODevice::ODevice ( ) |
102 | { | 107 | { |
103 | d = new ODeviceData; | 108 | d = new ODeviceData; |
104 | 109 | ||
105 | d-> m_modelstr = "Unknown"; | 110 | d-> m_modelstr = "Unknown"; |
106 | d-> m_model = OMODEL_Unknown; | 111 | d-> m_model = OMODEL_Unknown; |
107 | d-> m_vendorstr = "Unkown"; | 112 | d-> m_vendorstr = "Unkown"; |
108 | d-> m_vendor = OVENDOR_Unknown; | 113 | d-> m_vendor = OVENDOR_Unknown; |
109 | d-> m_systemstr = "Unkown"; | 114 | d-> m_systemstr = "Unkown"; |
110 | d-> m_system = OSYSTEM_Unknown; | 115 | d-> m_system = OSYSTEM_Unknown; |
111 | d-> m_sysverstr = "0.0"; | 116 | d-> m_sysverstr = "0.0"; |
112 | } | 117 | } |
113 | 118 | ||
114 | void ODevice::init ( ) | 119 | void ODevice::init ( ) |
115 | { | 120 | { |
116 | } | 121 | } |
117 | 122 | ||
118 | ODevice::~ODevice ( ) | 123 | ODevice::~ODevice ( ) |
119 | { | 124 | { |
120 | delete d; | 125 | delete d; |
121 | } | 126 | } |
122 | 127 | ||
128 | //#include <linux/apm_bios.h> | ||
129 | |||
130 | //#define APM_IOC_SUSPEND _IO('A',2) | ||
131 | |||
132 | #define APM_IOC_SUSPEND (( 0<<30 ) | ( 'A'<<8 ) | ( 2 ) | ( 0<<16 )) | ||
133 | |||
134 | |||
135 | void ODevice::tstp_sighandler ( int ) | ||
136 | { | ||
137 | } | ||
138 | |||
139 | |||
123 | bool ODevice::suspend ( ) | 140 | bool ODevice::suspend ( ) |
124 | { | 141 | { |
125 | int rc = ::system ( "apm --suspend" ); | 142 | if ( d-> m_model == OMODEL_Unknown ) // better don't suspend in qvfb / on unkown devices |
126 | |||
127 | if (( rc == 127 ) || ( rc == -1 )) | ||
128 | return false; | 143 | return false; |
129 | else | 144 | |
130 | return true; | 145 | int fd; |
146 | bool res = false; | ||
147 | |||
148 | if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || | ||
149 | (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { | ||
150 | struct timeval tvs, tvn; | ||
151 | |||
152 | ::signal ( SIGTSTP, tstp_sighandler );// we don't want to be stopped | ||
153 | ::gettimeofday ( &tvs, 0 ); | ||
154 | |||
155 | res = ( ::ioctl ( fd, APM_IOC_SUSPEND ) == 0 ); // tell the kernel to "start" suspending | ||
156 | ::close ( fd ); | ||
157 | |||
158 | if ( res ) { | ||
159 | ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in out process group | ||
160 | |||
161 | do { // wait at most 1.5 sec: either suspend didn't work or the device resumed | ||
162 | ::usleep ( 200 * 1000 ); | ||
163 | ::gettimeofday ( &tvn, 0 ); | ||
164 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); | ||
165 | |||
166 | ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group | ||
167 | } | ||
168 | |||
169 | ::signal ( SIGTSTP, SIG_DFL ); | ||
170 | } | ||
171 | |||
172 | return res; | ||
131 | } | 173 | } |
132 | 174 | ||
175 | |||
133 | QString ODevice::vendorString ( ) | 176 | QString ODevice::vendorString ( ) |
134 | { | 177 | { |
135 | return d-> m_vendorstr; | 178 | return d-> m_vendorstr; |
136 | } | 179 | } |
137 | 180 | ||
138 | OVendor ODevice::vendor ( ) | 181 | OVendor ODevice::vendor ( ) |
139 | { | 182 | { |
140 | return d-> m_vendor; | 183 | return d-> m_vendor; |
141 | } | 184 | } |
142 | 185 | ||
143 | QString ODevice::modelString ( ) | 186 | QString ODevice::modelString ( ) |
144 | { | 187 | { |
145 | return d-> m_modelstr; | 188 | return d-> m_modelstr; |
146 | } | 189 | } |
147 | 190 | ||
148 | OModel ODevice::model ( ) | 191 | OModel ODevice::model ( ) |
149 | { | 192 | { |
150 | return d-> m_model; | 193 | return d-> m_model; |
151 | } | 194 | } |
152 | 195 | ||
153 | QString ODevice::systemString ( ) | 196 | QString ODevice::systemString ( ) |
154 | { | 197 | { |
155 | return d-> m_systemstr; | 198 | return d-> m_systemstr; |
156 | } | 199 | } |
157 | 200 | ||
158 | OSystem ODevice::system ( ) | 201 | OSystem ODevice::system ( ) |
159 | { | 202 | { |
160 | return d-> m_system; | 203 | return d-> m_system; |
161 | } | 204 | } |
162 | 205 | ||
163 | QString ODevice::systemVersionString ( ) | 206 | QString ODevice::systemVersionString ( ) |
164 | { | 207 | { |
165 | return d-> m_sysverstr; | 208 | return d-> m_sysverstr; |
166 | } | 209 | } |
167 | 210 | ||
168 | void ODevice::alarmSound ( ) | 211 | void ODevice::alarmSound ( ) |
169 | { | 212 | { |
170 | #ifndef QT_QWS_EBX | 213 | #ifndef QT_QWS_EBX |
171 | #ifndef QT_NO_SOUND | 214 | #ifndef QT_NO_SOUND |
172 | static Sound snd ( "alarm" ); | 215 | static Sound snd ( "alarm" ); |
173 | 216 | ||
174 | if ( snd. isFinished ( )) | 217 | if ( snd. isFinished ( )) |
175 | snd. play ( ); | 218 | snd. play ( ); |
176 | #endif | 219 | #endif |
177 | #endif | 220 | #endif |
178 | } | 221 | } |
179 | 222 | ||
180 | void ODevice::keySound ( ) | 223 | void ODevice::keySound ( ) |
181 | { | 224 | { |
182 | #ifndef QT_QWS_EBX | 225 | #ifndef QT_QWS_EBX |
183 | #ifndef QT_NO_SOUND | 226 | #ifndef QT_NO_SOUND |
184 | static Sound snd ( "keysound" ); | 227 | static Sound snd ( "keysound" ); |
185 | 228 | ||
186 | if ( snd. isFinished ( )) | 229 | if ( snd. isFinished ( )) |
187 | snd. play ( ); | 230 | snd. play ( ); |
188 | #endif | 231 | #endif |
189 | #endif | 232 | #endif |
190 | } | 233 | } |
191 | 234 | ||
192 | void ODevice::touchSound ( ) | 235 | void ODevice::touchSound ( ) |
193 | { | 236 | { |
194 | 237 | ||
195 | #ifndef QT_QWS_EBX | 238 | #ifndef QT_QWS_EBX |
196 | #ifndef QT_NO_SOUND | 239 | #ifndef QT_NO_SOUND |
197 | static Sound snd ( "touchsound" ); | 240 | static Sound snd ( "touchsound" ); |
198 | //qDebug("touchSound"); | 241 | //qDebug("touchSound"); |
199 | if ( snd. isFinished ( )) { | 242 | if ( snd. isFinished ( )) { |
200 | snd. play ( ); | 243 | snd. play ( ); |
201 | // qDebug("sound should play"); | 244 | // qDebug("sound should play"); |
202 | } | 245 | } |
203 | #endif | 246 | #endif |
204 | #endif | 247 | #endif |
205 | } | 248 | } |
206 | 249 | ||
207 | uint ODevice::hasLeds ( ) const | 250 | uint ODevice::hasLeds ( ) const |
208 | { | 251 | { |
209 | return 0; | 252 | return 0; |
210 | } | 253 | } |
211 | 254 | ||
212 | OLedState ODevice::led ( uint /*which*/ ) const | 255 | OLedState ODevice::led ( uint /*which*/ ) const |
213 | { | 256 | { |
214 | return OLED_Off; | 257 | return OLED_Off; |
215 | } | 258 | } |
216 | 259 | ||
217 | bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ ) | 260 | bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ ) |
218 | { | 261 | { |
219 | return false; | 262 | return false; |
220 | } | 263 | } |
221 | 264 | ||
222 | 265 | ||
223 | 266 | ||
224 | 267 | ||
225 | //#if defined( QT_QWS_IPAQ ) // IPAQ | 268 | //#if defined( QT_QWS_IPAQ ) // IPAQ |
226 | 269 | ||
227 | 270 | ||
228 | void ODeviceIPAQ::init ( ) | 271 | void ODeviceIPAQ::init ( ) |
229 | { | 272 | { |
230 | d-> m_vendorstr = "HP"; | 273 | d-> m_vendorstr = "HP"; |
231 | d-> m_vendor = OVENDOR_HP; | 274 | d-> m_vendor = OVENDOR_HP; |
232 | 275 | ||
233 | QFile f ( "/proc/hal/model" ); | 276 | QFile f ( "/proc/hal/model" ); |
234 | 277 | ||
235 | if ( f. open ( IO_ReadOnly )) { | 278 | if ( f. open ( IO_ReadOnly )) { |
236 | QTextStream ts ( &f ); | 279 | QTextStream ts ( &f ); |
237 | 280 | ||
238 | d-> m_modelstr = "H" + ts. readLine ( ); | 281 | d-> m_modelstr = "H" + ts. readLine ( ); |
239 | 282 | ||
240 | if ( d-> m_modelstr == "H3100" ) | 283 | if ( d-> m_modelstr == "H3100" ) |
241 | d-> m_model = OMODEL_iPAQ_H31xx; | 284 | d-> m_model = OMODEL_iPAQ_H31xx; |
242 | else if ( d-> m_modelstr == "H3600" ) | 285 | else if ( d-> m_modelstr == "H3600" ) |
243 | d-> m_model = OMODEL_iPAQ_H36xx; | 286 | d-> m_model = OMODEL_iPAQ_H36xx; |
244 | else if ( d-> m_modelstr == "H3700" ) | 287 | else if ( d-> m_modelstr == "H3700" ) |
245 | d-> m_model = OMODEL_iPAQ_H37xx; | 288 | d-> m_model = OMODEL_iPAQ_H37xx; |
246 | else if ( d-> m_modelstr == "H3800" ) | 289 | else if ( d-> m_modelstr == "H3800" ) |
247 | d-> m_model = OMODEL_iPAQ_H38xx; | 290 | d-> m_model = OMODEL_iPAQ_H38xx; |
248 | else | 291 | else |
249 | d-> m_model = OMODEL_Unknown; | 292 | d-> m_model = OMODEL_Unknown; |
250 | 293 | ||
251 | f. close ( ); | 294 | f. close ( ); |
252 | } | 295 | } |
253 | 296 | ||
254 | f. setName ( "/etc/familiar-version" ); | 297 | f. setName ( "/etc/familiar-version" ); |
255 | if ( f. open ( IO_ReadOnly )) { | 298 | if ( f. open ( IO_ReadOnly )) { |
256 | d-> m_systemstr = "Familiar"; | 299 | d-> m_systemstr = "Familiar"; |
257 | d-> m_system = OSYSTEM_Familiar; | 300 | d-> m_system = OSYSTEM_Familiar; |
258 | 301 | ||
259 | QTextStream ts ( &f ); | 302 | QTextStream ts ( &f ); |
260 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); | 303 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); |
261 | 304 | ||
262 | f. close ( ); | 305 | f. close ( ); |
263 | } | 306 | } |
264 | 307 | ||
265 | d-> m_leds [0] = OLED_Off; | 308 | d-> m_leds [0] = OLED_Off; |
266 | } | 309 | } |
267 | 310 | ||
268 | #include <unistd.h> | ||
269 | #include <fcntl.h> | ||
270 | #include <sys/ioctl.h> | ||
271 | #include <signal.h> | ||
272 | #include <sys/time.h> | ||
273 | #include <linux/soundcard.h> | ||
274 | #include <qapplication.h> | ||
275 | #include <qpe/config.h> | ||
276 | |||
277 | //#include <linux/h3600_ts.h> // including kernel headers is evil ... | 311 | //#include <linux/h3600_ts.h> // including kernel headers is evil ... |
278 | 312 | ||
279 | typedef struct h3600_ts_led { | 313 | typedef struct h3600_ts_led { |
280 | unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ | 314 | unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ |
281 | unsigned char TotalTime; /* Units of 5 seconds */ | 315 | unsigned char TotalTime; /* Units of 5 seconds */ |
282 | unsigned char OnTime; /* units of 100m/s */ | 316 | unsigned char OnTime; /* units of 100m/s */ |
283 | unsigned char OffTime; /* units of 100m/s */ | 317 | unsigned char OffTime; /* units of 100m/s */ |
284 | } LED_IN; | 318 | } LED_IN; |
285 | 319 | ||
286 | 320 | ||
287 | // #define IOC_H3600_TS_MAGIC 'f' | 321 | // #define IOC_H3600_TS_MAGIC 'f' |
288 | // #define LED_ON _IOW(IOC_H3600_TS_MAGIC, 5, struct h3600_ts_led) | 322 | // #define LED_ON _IOW(IOC_H3600_TS_MAGIC, 5, struct h3600_ts_led) |
289 | #define LED_ON (( 1<<30 ) | ( 'f'<<8 ) | ( 5 ) | ( sizeof(struct h3600_ts_led)<<16 )) // _IOW only defined in kernel headers :( | 323 | #define LED_ON (( 1<<30 ) | ( 'f'<<8 ) | ( 5 ) | ( sizeof(struct h3600_ts_led)<<16 )) // _IOW only defined in kernel headers :( |
290 | 324 | ||
291 | 325 | ||
292 | //#include <linux/apm_bios.h> | ||
293 | |||
294 | //#define APM_IOC_SUSPEND _IO('A',2) | ||
295 | |||
296 | #define APM_IOC_SUSPEND (( 0<<30 ) | ( 'A'<<8 ) | ( 2 ) | ( 0<<16 )) | ||
297 | |||
298 | |||
299 | void ODeviceIPAQ::tstp_sighandler ( int ) | ||
300 | { | ||
301 | } | ||
302 | |||
303 | |||
304 | bool ODeviceIPAQ::suspend ( ) | ||
305 | { | ||
306 | int fd; | ||
307 | bool res = false; | ||
308 | |||
309 | if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || | ||
310 | (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { | ||
311 | struct timeval tvs, tvn; | ||
312 | |||
313 | ::signal ( SIGTSTP, tstp_sighandler ); | ||
314 | ::gettimeofday ( &tvs, 0 ); | ||
315 | |||
316 | res = ( ::ioctl ( fd, APM_IOC_SUSPEND ) == 0 ); | ||
317 | ::close ( fd ); | ||
318 | |||
319 | if ( res ) { | ||
320 | ::kill ( -::getpid ( ), SIGTSTP ); | ||
321 | |||
322 | do { | ||
323 | ::usleep ( 200 * 1000 ); | ||
324 | ::gettimeofday ( &tvn, 0 ); | ||
325 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); | ||
326 | |||
327 | ::kill ( -::getpid ( ), SIGCONT ); | ||
328 | } | ||
329 | |||
330 | ::signal ( SIGTSTP, SIG_DFL ); | ||
331 | } | ||
332 | |||
333 | return res; | ||
334 | } | ||
335 | |||
336 | |||
337 | void ODeviceIPAQ::alarmSound ( ) | 326 | void ODeviceIPAQ::alarmSound ( ) |
338 | { | 327 | { |
339 | #if defined( QT_QWS_IPAQ ) // IPAQ | 328 | #if defined( QT_QWS_IPAQ ) // IPAQ |
340 | #ifndef QT_NO_SOUND | 329 | #ifndef QT_NO_SOUND |
341 | static Sound snd ( "alarm" ); | 330 | static Sound snd ( "alarm" ); |
342 | int fd; | 331 | int fd; |
343 | int vol; | 332 | int vol; |
344 | bool vol_reset = false; | 333 | bool vol_reset = false; |
345 | 334 | ||
346 | if ((( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) || | 335 | if ((( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) || |
347 | (( fd = ::open ( "/dev/mixer", O_RDWR )) >= 0 )) { | 336 | (( fd = ::open ( "/dev/mixer", O_RDWR )) >= 0 )) { |
348 | 337 | ||
349 | if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { | 338 | if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { |
350 | Config cfg ( "qpe" ); | 339 | Config cfg ( "qpe" ); |
351 | cfg. setGroup ( "Volume" ); | 340 | cfg. setGroup ( "Volume" ); |
352 | 341 | ||
353 | int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); | 342 | int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); |
354 | if ( volalarm < 0 ) | 343 | if ( volalarm < 0 ) |
355 | volalarm = 0; | 344 | volalarm = 0; |
356 | else if ( volalarm > 100 ) | 345 | else if ( volalarm > 100 ) |
357 | volalarm = 100; | 346 | volalarm = 100; |
358 | volalarm |= ( volalarm << 8 ); | 347 | volalarm |= ( volalarm << 8 ); |
359 | 348 | ||
360 | if (( volalarm & 0xff ) > ( vol & 0xff )) { | 349 | if (( volalarm & 0xff ) > ( vol & 0xff )) { |
361 | if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) | 350 | if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) |
362 | vol_reset = true; | 351 | vol_reset = true; |
363 | } | 352 | } |
364 | } | 353 | } |
365 | } | 354 | } |
366 | 355 | ||
367 | snd. play ( ); | 356 | snd. play ( ); |
368 | while ( !snd. isFinished ( )) | 357 | while ( !snd. isFinished ( )) |
369 | qApp-> processEvents ( ); | 358 | qApp-> processEvents ( ); |
370 | 359 | ||
371 | if ( fd >= 0 ) { | 360 | if ( fd >= 0 ) { |
372 | if ( vol_reset ) | 361 | if ( vol_reset ) |
373 | ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); | 362 | ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); |
374 | ::close ( fd ); | 363 | ::close ( fd ); |
375 | } | 364 | } |
376 | #endif | 365 | #endif |
377 | #endif | 366 | #endif |
378 | } | 367 | } |
379 | 368 | ||
380 | uint ODeviceIPAQ::hasLeds ( ) const | 369 | uint ODeviceIPAQ::hasLeds ( ) const |
381 | { | 370 | { |
382 | return 1; | 371 | return 1; |
383 | } | 372 | } |
384 | 373 | ||
385 | OLedState ODeviceIPAQ::led ( uint which ) const | 374 | OLedState ODeviceIPAQ::led ( uint which ) const |
386 | { | 375 | { |
387 | if ( which == 0 ) | 376 | if ( which == 0 ) |
388 | return d-> m_leds [0]; | 377 | return d-> m_leds [0]; |
389 | else | 378 | else |
390 | return OLED_Off; | 379 | return OLED_Off; |
391 | } | 380 | } |
392 | 381 | ||
393 | bool ODeviceIPAQ::setLed ( uint which, OLedState st ) | 382 | bool ODeviceIPAQ::setLed ( uint which, OLedState st ) |
394 | { | 383 | { |
395 | static int fd = ::open ( "/dev/touchscreen/0", O_RDWR|O_NONBLOCK ); | 384 | static int fd = ::open ( "/dev/touchscreen/0", O_RDWR|O_NONBLOCK ); |
396 | 385 | ||
397 | if ( which == 0 ) { | 386 | if ( which == 0 ) { |
398 | if ( fd >= 0 ) { | 387 | if ( fd >= 0 ) { |
399 | struct h3600_ts_led leds; | 388 | struct h3600_ts_led leds; |
400 | ::memset ( &leds, 0, sizeof( leds )); | 389 | ::memset ( &leds, 0, sizeof( leds )); |
401 | leds. TotalTime = 0; | 390 | leds. TotalTime = 0; |
402 | leds. OnTime = 0; | 391 | leds. OnTime = 0; |
403 | leds. OffTime = 1; | 392 | leds. OffTime = 1; |
404 | leds. OffOnBlink = 2; | 393 | leds. OffOnBlink = 2; |
405 | 394 | ||
406 | switch ( st ) { | 395 | switch ( st ) { |
407 | case OLED_Off : leds. OffOnBlink = 0; break; | 396 | case OLED_Off : leds. OffOnBlink = 0; break; |
408 | case OLED_On : leds. OffOnBlink = 1; break; | 397 | case OLED_On : leds. OffOnBlink = 1; break; |
409 | case OLED_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; | 398 | case OLED_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; |
410 | case OLED_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; | 399 | case OLED_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; |
411 | } | 400 | } |
412 | 401 | ||
413 | if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { | 402 | if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { |
414 | d-> m_leds [0] = st; | 403 | d-> m_leds [0] = st; |
415 | return true; | 404 | return true; |
416 | } | 405 | } |
417 | } | 406 | } |
418 | } | 407 | } |
419 | return false; | 408 | return false; |
420 | } | 409 | } |
421 | 410 | ||
422 | 411 | ||
423 | //#endif | 412 | //#endif |
424 | 413 | ||
425 | 414 | ||
426 | 415 | ||
427 | 416 | ||
428 | 417 | ||
429 | //#if defined( QT_QWS_EBX ) // Zaurus | 418 | //#if defined( QT_QWS_EBX ) // Zaurus |
430 | 419 | ||
431 | void ODeviceZaurus::init ( ) | 420 | void ODeviceZaurus::init ( ) |
432 | { | 421 | { |
433 | d-> m_modelstr = "Zaurus SL5000"; | 422 | d-> m_modelstr = "Zaurus SL5000"; |
434 | d-> m_model = OMODEL_Zaurus_SL5000; | 423 | d-> m_model = OMODEL_Zaurus_SL5000; |
435 | d-> m_vendorstr = "Sharp"; | 424 | d-> m_vendorstr = "Sharp"; |
436 | d-> m_vendor = OVENDOR_Sharp; | 425 | d-> m_vendor = OVENDOR_Sharp; |
437 | 426 | ||
438 | QFile f ( "/proc/filesystems" ); | 427 | QFile f ( "/proc/filesystems" ); |
439 | 428 | ||
440 | if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { | 429 | if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { |
441 | d-> m_systemstr = "OpenZaurus"; | 430 | d-> m_systemstr = "OpenZaurus"; |
442 | d-> m_system = OSYSTEM_OpenZaurus; | 431 | d-> m_system = OSYSTEM_OpenZaurus; |
443 | 432 | ||
444 | f. close ( ); | 433 | f. close ( ); |
445 | } | 434 | } |
446 | else { | 435 | else { |
447 | d-> m_systemstr = "Zaurus"; | 436 | d-> m_systemstr = "Zaurus"; |
448 | d-> m_system = OSYSTEM_Zaurus; | 437 | d-> m_system = OSYSTEM_Zaurus; |
449 | } | 438 | } |
450 | 439 | ||
451 | d-> m_leds [0] = OLED_Off; | 440 | d-> m_leds [0] = OLED_Off; |
452 | } | 441 | } |
453 | 442 | ||
454 | #include <unistd.h> | 443 | #include <unistd.h> |
455 | #include <fcntl.h> | 444 | #include <fcntl.h> |
456 | #include <sys/ioctl.h> | 445 | #include <sys/ioctl.h> |
457 | 446 | ||
458 | //#include <asm/sharp_char.h> // including kernel headers is evil ... | 447 | //#include <asm/sharp_char.h> // including kernel headers is evil ... |
459 | 448 | ||
460 | #define SHARP_DEV_IOCTL_COMMAND_START 0x5680 | 449 | #define SHARP_DEV_IOCTL_COMMAND_START 0x5680 |
461 | 450 | ||
462 | #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) | 451 | #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) |
463 | #define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) | 452 | #define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) |
464 | 453 | ||
465 | #define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ | 454 | #define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ |
466 | #define SHARP_BUZ_KEYSOUND 2 /* key sound */ | 455 | #define SHARP_BUZ_KEYSOUND 2 /* key sound */ |
467 | #define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ | 456 | #define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ |
468 | 457 | ||
469 | /* --- for SHARP_BUZZER device --- */ | 458 | /* --- for SHARP_BUZZER device --- */ |
470 | 459 | ||
471 | //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) | 460 | //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) |
472 | //#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) | 461 | //#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) |
473 | 462 | ||
474 | #define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) | 463 | #define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) |
475 | #define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2) | 464 | #define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2) |
476 | #define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3) | 465 | #define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3) |
477 | #define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4) | 466 | #define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4) |
478 | #define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5) | 467 | #define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5) |
479 | 468 | ||
480 | //#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ | 469 | //#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ |
481 | //#define SHARP_BUZ_KEYSOUND 2 /* key sound */ | 470 | //#define SHARP_BUZ_KEYSOUND 2 /* key sound */ |
482 | 471 | ||
483 | //#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */ | 472 | //#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */ |
484 | //#define SHARP_PDA_WARNSOUND 4 /* warning occurred */ | 473 | //#define SHARP_PDA_WARNSOUND 4 /* warning occurred */ |
485 | //#define SHARP_PDA_ERRORSOUND 5 /* error occurred */ | 474 | //#define SHARP_PDA_ERRORSOUND 5 /* error occurred */ |
486 | //#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */ | 475 | //#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */ |
487 | //#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */ | 476 | //#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */ |
488 | //#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */ | 477 | //#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */ |
489 | //#define SHARP_PDA_APPSTART 9 /* application start */ | 478 | //#define SHARP_PDA_APPSTART 9 /* application start */ |
490 | //#define SHARP_PDA_APPQUIT 10 /* application ends */ | 479 | //#define SHARP_PDA_APPQUIT 10 /* application ends */ |
491 | 480 | ||
492 | //#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ | 481 | //#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ |
493 | //#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */ | 482 | //#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */ |
494 | //#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */ | 483 | //#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */ |
495 | //#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */ | 484 | //#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */ |
496 | // | 485 | // |
497 | 486 | ||
498 | #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) | 487 | #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) |
499 | #define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1) | 488 | #define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1) |
500 | 489 | ||
501 | typedef struct sharp_led_status { | 490 | typedef struct sharp_led_status { |
502 | int which; /* select which LED status is wanted. */ | 491 | int which; /* select which LED status is wanted. */ |
503 | int status; /* set new led status if you call SHARP_LED_SETSTATUS */ | 492 | int status; /* set new led status if you call SHARP_LED_SETSTATUS */ |
504 | } sharp_led_status; | 493 | } sharp_led_status; |
505 | 494 | ||
506 | #define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */ | 495 | #define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */ |
507 | 496 | ||
508 | #define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */ | 497 | #define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */ |
509 | #define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */ | 498 | #define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */ |
510 | #define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */ | 499 | #define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */ |
511 | 500 | ||
512 | 501 | ||
513 | 502 | ||
514 | void ODeviceZaurus::buzzer ( int sound ) | 503 | void ODeviceZaurus::buzzer ( int sound ) |
515 | { | 504 | { |
516 | static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK ); | 505 | static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK ); |
517 | 506 | ||
518 | if ( fd >= 0 ) | 507 | if ( fd >= 0 ) |
519 | ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); | 508 | ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); |
520 | } | 509 | } |
521 | 510 | ||
522 | 511 | ||
523 | void ODeviceZaurus::alarmSound ( ) | 512 | void ODeviceZaurus::alarmSound ( ) |
524 | { | 513 | { |
525 | buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); | 514 | buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); |
526 | } | 515 | } |
527 | 516 | ||
528 | void ODeviceZaurus::touchSound ( ) | 517 | void ODeviceZaurus::touchSound ( ) |
529 | { | 518 | { |
530 | buzzer ( SHARP_BUZ_TOUCHSOUND ); | 519 | buzzer ( SHARP_BUZ_TOUCHSOUND ); |
531 | } | 520 | } |
532 | 521 | ||
533 | void ODeviceZaurus::keySound ( ) | 522 | void ODeviceZaurus::keySound ( ) |
534 | { | 523 | { |
535 | buzzer ( SHARP_BUZ_KEYSOUND ); | 524 | buzzer ( SHARP_BUZ_KEYSOUND ); |
536 | } | 525 | } |
537 | 526 | ||
538 | 527 | ||
539 | uint ODeviceZaurus::hasLeds ( ) const | 528 | uint ODeviceZaurus::hasLeds ( ) const |
540 | { | 529 | { |
541 | return 1; | 530 | return 1; |
542 | } | 531 | } |
543 | 532 | ||
544 | OLedState ODeviceZaurus::led ( uint which ) const | 533 | OLedState ODeviceZaurus::led ( uint which ) const |
545 | { | 534 | { |
546 | if ( which == 0 ) | 535 | if ( which == 0 ) |
547 | return d-> m_leds [0]; | 536 | return d-> m_leds [0]; |
548 | else | 537 | else |
549 | return OLED_Off; | 538 | return OLED_Off; |
550 | } | 539 | } |
551 | 540 | ||
552 | bool ODeviceZaurus::setLed ( uint which, OLedState st ) | 541 | bool ODeviceZaurus::setLed ( uint which, OLedState st ) |
553 | { | 542 | { |
554 | static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); | 543 | static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); |
555 | 544 | ||
556 | if ( which == 0 ) { | 545 | if ( which == 0 ) { |
557 | if ( fd >= 0 ) { | 546 | if ( fd >= 0 ) { |
558 | struct sharp_led_status leds; | 547 | struct sharp_led_status leds; |
559 | ::memset ( &leds, 0, sizeof( leds )); | 548 | ::memset ( &leds, 0, sizeof( leds )); |
560 | leds. which = SHARP_LED_MAIL_EXISTS; | 549 | leds. which = SHARP_LED_MAIL_EXISTS; |
561 | 550 | ||
562 | switch ( st ) { | 551 | switch ( st ) { |
563 | case OLED_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; | 552 | case OLED_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; |
564 | case OLED_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; | 553 | case OLED_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; |
565 | case OLED_BlinkSlow: | 554 | case OLED_BlinkSlow: |
566 | case OLED_BlinkFast: leds. status = LED_MAIL_UNREAD_MAIL_EX; break; | 555 | case OLED_BlinkFast: leds. status = LED_MAIL_UNREAD_MAIL_EX; break; |
567 | } | 556 | } |
568 | 557 | ||
569 | if ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 ) { | 558 | if ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 ) { |
570 | d-> m_leds [0] = st; | 559 | d-> m_leds [0] = st; |
571 | return true; | 560 | return true; |
572 | } | 561 | } |
573 | } | 562 | } |
574 | } | 563 | } |
575 | return false; | 564 | return false; |
576 | } | 565 | } |
577 | 566 | ||
578 | //#endif | 567 | //#endif |