summaryrefslogtreecommitdiff
path: root/libopie
authorsandman <sandman>2002-08-28 23:11:30 (UTC)
committer sandman <sandman>2002-08-28 23:11:30 (UTC)
commit186bdeb08c0d9ccd78177310cf9f69ea80b76a96 (patch) (unidiff)
tree981a01a9dfa52423f6330586bfa7ca752dd97523 /libopie
parent42e4592219600d6919c93dec82635e2b64382b37 (diff)
downloadopie-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 ;) )
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp119
-rw-r--r--libopie/odevice.h1
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
@@ -18,11 +18,21 @@
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"
@@ -49,16 +59,11 @@ protected:
49 virtual void init ( ); 59 virtual void init ( );
50 60
51public: 61public:
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
60private:
61 static void tstp_sighandler ( int );
62}; 67};
63 68
64class ODeviceZaurus : public ODevice { 69class ODeviceZaurus : public ODevice {
@@ -120,16 +125,54 @@ ODevice::~ODevice ( )
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
135void ODevice::tstp_sighandler ( int )
136{
137}
138
139
123bool ODevice::suspend ( ) 140bool 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
133QString ODevice::vendorString ( ) 176QString ODevice::vendorString ( )
134{ 177{
135 return d-> m_vendorstr; 178 return d-> m_vendorstr;
@@ -265,15 +308,6 @@ void ODeviceIPAQ::init ( )
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
279typedef struct h3600_ts_led { 313typedef struct h3600_ts_led {
@@ -289,51 +323,6 @@ typedef 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
299void ODeviceIPAQ::tstp_sighandler ( int )
300{
301}
302
303
304bool 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
337void ODeviceIPAQ::alarmSound ( ) 326void ODeviceIPAQ::alarmSound ( )
338{ 327{
339#if defined( QT_QWS_IPAQ ) // IPAQ 328#if defined( QT_QWS_IPAQ ) // IPAQ
diff --git a/libopie/odevice.h b/libopie/odevice.h
index eeae357..cda504a 100644
--- a/libopie/odevice.h
+++ b/libopie/odevice.h
@@ -103,6 +103,7 @@ protected:
103private: 103private:
104 ODevice ( const ODevice & ); 104 ODevice ( const ODevice & );
105 105
106 static void tstp_sighandler ( int );
106}; 107};
107 108
108#endif 109#endif