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
@@ -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
31class ODeviceData { 41class ODeviceData {
32public: 42public:
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
47class ODeviceIPAQ : public ODevice { 57class ODeviceIPAQ : public ODevice {
48protected: 58protected:
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 {
65protected: 70protected:
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
77protected: 82protected:
78 virtual void buzzer ( int snd ); 83 virtual void buzzer ( int snd );
79}; 84};
80 85
81 86
82 87
83 88
84ODevice *ODevice::inst ( ) 89ODevice *ODevice::inst ( )
85{ 90{
@@ -99,58 +104,96 @@ ODevice *ODevice::inst ( )
99} 104}
100 105
101ODevice::ODevice ( ) 106ODevice::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
114void ODevice::init ( ) 119void ODevice::init ( )
115{ 120{
116} 121}
117 122
118ODevice::~ODevice ( ) 123ODevice::~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
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;
136} 179}
137 180
138OVendor ODevice::vendor ( ) 181OVendor ODevice::vendor ( )
139{ 182{
140 return d-> m_vendor; 183 return d-> m_vendor;
141} 184}
142 185
143QString ODevice::modelString ( ) 186QString ODevice::modelString ( )
144{ 187{
145 return d-> m_modelstr; 188 return d-> m_modelstr;
146} 189}
147 190
148OModel ODevice::model ( ) 191OModel ODevice::model ( )
149{ 192{
150 return d-> m_model; 193 return d-> m_model;
151} 194}
152 195
153QString ODevice::systemString ( ) 196QString 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
279typedef struct h3600_ts_led { 313typedef 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
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
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
97protected: 97protected:
98 ODevice ( ); 98 ODevice ( );
99 virtual void init ( ); 99 virtual void init ( );
100 100
101 ODeviceData *d; 101 ODeviceData *d;
102 102
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
109 110
110 111