summaryrefslogtreecommitdiff
path: root/libopie
Unidiff
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp62
-rw-r--r--libopie/odevice.h4
2 files changed, 65 insertions, 1 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index bc8014a..057c344 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -12,16 +12,18 @@
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>
21
20#include <qfile.h> 22#include <qfile.h>
21#include <qtextstream.h> 23#include <qtextstream.h>
22#include <qpe/sound.h> 24#include <qpe/sound.h>
23#include <qpe/resource.h> 25#include <qpe/resource.h>
24 26
25 27
26#include "odevice.h" 28#include "odevice.h"
27 29
@@ -42,21 +44,26 @@ public:
42 OLedState m_leds [4]; // just for convenience ... 44 OLedState m_leds [4]; // just for convenience ...
43}; 45};
44 46
45class ODeviceIPAQ : public ODevice { 47class ODeviceIPAQ : public ODevice {
46protected: 48protected:
47 virtual void init ( ); 49 virtual void init ( );
48 50
49public: 51public:
52 virtual bool suspend ( );
53
50 virtual void alarmSound ( ); 54 virtual void alarmSound ( );
51 55
52 virtual uint hasLeds ( ) const; 56 virtual uint hasLeds ( ) const;
53 virtual OLedState led ( uint which ) const; 57 virtual OLedState led ( uint which ) const;
54 virtual bool setLed ( uint which, OLedState st ); 58 virtual bool setLed ( uint which, OLedState st );
59
60private:
61 static void tstp_sighandler ( int );
55}; 62};
56 63
57class ODeviceZaurus : public ODevice { 64class ODeviceZaurus : public ODevice {
58protected: 65protected:
59 virtual void init ( ); 66 virtual void init ( );
60 67
61 public: 68 public:
62 virtual void alarmSound ( ); 69 virtual void alarmSound ( );
@@ -108,16 +115,26 @@ void ODevice::init ( )
108{ 115{
109} 116}
110 117
111ODevice::~ODevice ( ) 118ODevice::~ODevice ( )
112{ 119{
113 delete d; 120 delete d;
114} 121}
115 122
123bool ODevice::suspend ( )
124{
125 int rc = ::system ( "apm --suspend" );
126
127 if (( rc == 127 ) || ( rc == -1 ))
128 return false;
129 else
130 return true;
131}
132
116QString ODevice::vendorString ( ) 133QString ODevice::vendorString ( )
117{ 134{
118 return d-> m_vendorstr; 135 return d-> m_vendorstr;
119} 136}
120 137
121OVendor ODevice::vendor ( ) 138OVendor ODevice::vendor ( )
122{ 139{
123 return d-> m_vendor; 140 return d-> m_vendor;
@@ -246,16 +263,18 @@ void ODeviceIPAQ::init ( )
246 } 263 }
247 264
248 d-> m_leds [0] = OLED_Off; 265 d-> m_leds [0] = OLED_Off;
249} 266}
250 267
251#include <unistd.h> 268#include <unistd.h>
252#include <fcntl.h> 269#include <fcntl.h>
253#include <sys/ioctl.h> 270#include <sys/ioctl.h>
271#include <signal.h>
272#include <sys/time.h>
254#include <linux/soundcard.h> 273#include <linux/soundcard.h>
255#include <qapplication.h> 274#include <qapplication.h>
256#include <qpe/config.h> 275#include <qpe/config.h>
257 276
258//#include <linux/h3600_ts.h> // including kernel headers is evil ... 277//#include <linux/h3600_ts.h> // including kernel headers is evil ...
259 278
260typedef struct h3600_ts_led { 279typedef struct h3600_ts_led {
261 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ 280 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */
@@ -265,16 +284,59 @@ typedef struct h3600_ts_led {
265} LED_IN; 284} LED_IN;
266 285
267 286
268// #define IOC_H3600_TS_MAGIC 'f' 287// #define IOC_H3600_TS_MAGIC 'f'
269// #define LED_ON _IOW(IOC_H3600_TS_MAGIC, 5, struct h3600_ts_led) 288// #define LED_ON _IOW(IOC_H3600_TS_MAGIC, 5, struct h3600_ts_led)
270#define LED_ON (( 1<<30 ) | ( 'f'<<8 ) | ( 5 ) | ( sizeof(struct h3600_ts_led)<<16 )) // _IOW only defined in kernel headers :( 289#define LED_ON (( 1<<30 ) | ( 'f'<<8 ) | ( 5 ) | ( sizeof(struct h3600_ts_led)<<16 )) // _IOW only defined in kernel headers :(
271 290
272 291
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 struct timeval tvs, tvn;
311
312 ::signal ( SIGTSTP, tstp_sighandler );
313 ::gettimeofday ( &tvs, 0 );
314
315 res = ( ::ioctl ( fd, APM_IOC_SUSPEND ) == 0 );
316 ::close ( fd );
317
318 if ( res ) {
319 ::kill ( -::getpid ( ), SIGTSTP );
320
321 do {
322 ::usleep ( 200 * 1000 );
323 ::gettimeofday ( &tvn, 0 );
324 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
325
326 ::kill ( -::getpid ( ), SIGCONT );
327 }
328
329 ::signal ( SIGTSTP, SIG_DFL );
330 }
331 return res;
332}
333
334
273void ODeviceIPAQ::alarmSound ( ) 335void ODeviceIPAQ::alarmSound ( )
274{ 336{
275#if defined( QT_QWS_IPAQ ) // IPAQ 337#if defined( QT_QWS_IPAQ ) // IPAQ
276#ifndef QT_NO_SOUND 338#ifndef QT_NO_SOUND
277 static Sound snd ( "alarm" ); 339 static Sound snd ( "alarm" );
278 int fd; 340 int fd;
279 int vol; 341 int vol;
280 bool vol_reset = false; 342 bool vol_reset = false;
diff --git a/libopie/odevice.h b/libopie/odevice.h
index b54e576..eeae357 100644
--- a/libopie/odevice.h
+++ b/libopie/odevice.h
@@ -60,17 +60,19 @@ enum OLedState {
60 60
61 61
62class ODevice 62class ODevice
63{ 63{
64public: 64public:
65 65
66public: 66public:
67 static ODevice *inst ( ); 67 static ODevice *inst ( );
68 68
69 // system
70 virtual bool suspend ( );
69 71
70// information 72// information
71 73
72 QString modelString ( ); 74 QString modelString ( );
73 OModel model ( ); 75 OModel model ( );
74 76
75 QString vendorString ( ); 77 QString vendorString ( );
76 OVendor vendor ( ); 78 OVendor vendor ( );