author | sandman <sandman> | 2002-08-28 23:11:30 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-08-28 23:11:30 (UTC) |
commit | 186bdeb08c0d9ccd78177310cf9f69ea80b76a96 (patch) (unidiff) | |
tree | 981a01a9dfa52423f6330586bfa7ca752dd97523 /libopie | |
parent | 42e4592219600d6919c93dec82635e2b64382b37 (diff) | |
download | opie-186bdeb08c0d9ccd78177310cf9f69ea80b76a96.zip opie-186bdeb08c0d9ccd78177310cf9f69ea80b76a96.tar.gz opie-186bdeb08c0d9ccd78177310cf9f69ea80b76a96.tar.bz2 |
Use the new iPAQ suspend code for all supported platforms (that is OZ
right now ;) )
-rw-r--r-- | libopie/odevice.cpp | 119 | ||||
-rw-r--r-- | libopie/odevice.h | 1 |
2 files changed, 55 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,85 +1,90 @@ | |||
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 | { |
@@ -99,58 +104,96 @@ ODevice *ODevice::inst ( ) | |||
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 | } |
@@ -244,117 +287,63 @@ void ODeviceIPAQ::init ( ) | |||
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 )) { |
diff --git a/libopie/odevice.h b/libopie/odevice.h index eeae357..cda504a 100644 --- a/libopie/odevice.h +++ b/libopie/odevice.h | |||
@@ -82,29 +82,30 @@ public: | |||
82 | 82 | ||
83 | QString systemVersionString ( ); | 83 | QString systemVersionString ( ); |
84 | 84 | ||
85 | // input / output | 85 | // input / output |
86 | 86 | ||
87 | virtual void alarmSound ( ); | 87 | virtual void alarmSound ( ); |
88 | virtual void keySound ( ); | 88 | virtual void keySound ( ); |
89 | virtual void touchSound ( ); | 89 | virtual void touchSound ( ); |
90 | 90 | ||
91 | virtual uint hasLeds ( ) const; | 91 | virtual uint hasLeds ( ) const; |
92 | virtual OLedState led ( uint which ) const; | 92 | virtual OLedState led ( uint which ) const; |
93 | virtual bool setLed ( uint which, OLedState st ); | 93 | virtual bool setLed ( uint which, OLedState st ); |
94 | 94 | ||
95 | virtual ~ODevice ( ); | 95 | virtual ~ODevice ( ); |
96 | 96 | ||
97 | protected: | 97 | protected: |
98 | ODevice ( ); | 98 | ODevice ( ); |
99 | virtual void init ( ); | 99 | virtual void init ( ); |
100 | 100 | ||
101 | ODeviceData *d; | 101 | ODeviceData *d; |
102 | 102 | ||
103 | private: | 103 | private: |
104 | ODevice ( const ODevice & ); | 104 | ODevice ( const ODevice & ); |
105 | 105 | ||
106 | static void tstp_sighandler ( int ); | ||
106 | }; | 107 | }; |
107 | 108 | ||
108 | #endif | 109 | #endif |
109 | 110 | ||
110 | 111 | ||