summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp38
1 files changed, 14 insertions, 24 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 2d2f7db..d8415ad 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -74,283 +74,273 @@ protected:
74public: 74public:
75 virtual bool setSoftSuspend ( bool soft ); 75 virtual bool setSoftSuspend ( bool soft );
76 76
77 virtual bool setDisplayBrightness ( int b ); 77 virtual bool setDisplayBrightness ( int b );
78 virtual int displayBrightnessResolution ( ) const; 78 virtual int displayBrightnessResolution ( ) const;
79 79
80 virtual void alarmSound ( ); 80 virtual void alarmSound ( );
81 81
82 virtual QValueList <OLed> ledList ( ) const; 82 virtual QValueList <OLed> ledList ( ) const;
83 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 83 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
84 virtual OLedState ledState ( OLed led ) const; 84 virtual OLedState ledState ( OLed led ) const;
85 virtual bool setLedState ( OLed led, OLedState st ); 85 virtual bool setLedState ( OLed led, OLedState st );
86 86
87 virtual bool hasLightSensor ( ) const; 87 virtual bool hasLightSensor ( ) const;
88 virtual int readLightSensor ( ); 88 virtual int readLightSensor ( );
89 virtual int lightSensorResolution ( ) const; 89 virtual int lightSensorResolution ( ) const;
90 90
91 //virtual QValueList <int> keyList ( ) const; 91 //virtual QValueList <int> keyList ( ) const;
92 92
93protected: 93protected:
94 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); 94 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
95 virtual void timerEvent ( QTimerEvent *te ); 95 virtual void timerEvent ( QTimerEvent *te );
96 96
97 int m_power_timer; 97 int m_power_timer;
98 98
99 OLedState m_leds [2]; 99 OLedState m_leds [2];
100}; 100};
101 101
102class Zaurus : public ODevice { 102class Zaurus : public ODevice {
103protected: 103protected:
104 virtual void init ( ); 104 virtual void init ( );
105 105
106 public: 106 public:
107 virtual bool setSoftSuspend ( bool soft ); 107 virtual bool setSoftSuspend ( bool soft );
108 108
109 virtual bool setDisplayBrightness ( int b ); 109 virtual bool setDisplayBrightness ( int b );
110 virtual int displayBrightnessResolution ( ) const; 110 virtual int displayBrightnessResolution ( ) const;
111 111
112 virtual void alarmSound ( ); 112 virtual void alarmSound ( );
113 virtual void keySound ( ); 113 virtual void keySound ( );
114 virtual void touchSound ( ); 114 virtual void touchSound ( );
115 115
116 virtual QValueList <OLed> ledList ( ) const; 116 virtual QValueList <OLed> ledList ( ) const;
117 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 117 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
118 virtual OLedState ledState ( OLed led ) const; 118 virtual OLedState ledState ( OLed led ) const;
119 virtual bool setLedState ( OLed led, OLedState st ); 119 virtual bool setLedState ( OLed led, OLedState st );
120 120
121 //virtual QValueList <int> keyList ( ) const; 121 //virtual QValueList <int> keyList ( ) const;
122 122
123protected: 123protected:
124 virtual void buzzer ( int snd ); 124 virtual void buzzer ( int snd );
125 125
126 OLedState m_leds [1]; 126 OLedState m_leds [1];
127}; 127};
128 128
129 129
130 130
131 131
132 132
133 133
134 134
135ODevice *ODevice::inst ( ) 135ODevice *ODevice::inst ( )
136{ 136{
137 static ODevice *dev = 0; 137 static ODevice *dev = 0;
138 138
139 if ( !dev ) { 139 if ( !dev ) {
140 if ( QFile::exists ( "/proc/hal/model" )) 140 if ( QFile::exists ( "/proc/hal/model" ))
141 dev = new iPAQ ( ); 141 dev = new iPAQ ( );
142 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) 142 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ))
143 dev = new Zaurus ( ); 143 dev = new Zaurus ( );
144 else 144 else
145 dev = new ODevice ( ); 145 dev = new ODevice ( );
146 146
147 dev-> init ( ); 147 dev-> init ( );
148 } 148 }
149 return dev; 149 return dev;
150} 150}
151 151
152 152
153/************************************************** 153/**************************************************
154 * 154 *
155 * common 155 * common
156 * 156 *
157 **************************************************/ 157 **************************************************/
158 158
159 159
160ODevice::ODevice ( ) 160ODevice::ODevice ( )
161{ 161{
162 d = new ODeviceData; 162 d = new ODeviceData;
163 163
164 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; 164 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
165 165
166 d-> m_modelstr = "Unknown"; 166 d-> m_modelstr = "Unknown";
167 d-> m_model = Model_Unknown; 167 d-> m_model = Model_Unknown;
168 d-> m_vendorstr = "Unkown"; 168 d-> m_vendorstr = "Unkown";
169 d-> m_vendor = Vendor_Unknown; 169 d-> m_vendor = Vendor_Unknown;
170 d-> m_systemstr = "Unkown"; 170 d-> m_systemstr = "Unkown";
171 d-> m_system = System_Unknown; 171 d-> m_system = System_Unknown;
172 d-> m_sysverstr = "0.0"; 172 d-> m_sysverstr = "0.0";
173} 173}
174 174
175void ODevice::init ( ) 175void ODevice::init ( )
176{ 176{
177} 177}
178 178
179ODevice::~ODevice ( ) 179ODevice::~ODevice ( )
180{ 180{
181 delete d; 181 delete d;
182} 182}
183 183
184bool ODevice::setSoftSuspend ( bool /*soft*/ ) 184bool ODevice::setSoftSuspend ( bool /*soft*/ )
185{ 185{
186 return false; 186 return false;
187} 187}
188 188
189//#include <linux/apm_bios.h> 189//#include <linux/apm_bios.h>
190 190
191#define APM_IOC_SUSPEND OD_IO( 'A', 2 ) 191#define APM_IOC_SUSPEND OD_IO( 'A', 2 )
192 192
193 193
194bool ODevice::suspend ( ) 194bool ODevice::suspend ( )
195{ 195{
196 if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend 196 if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend
197 return false; 197 return false;
198 198
199 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices 199 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices
200 return false; 200 return false;
201 201
202 int fd;
203 bool res = false; 202 bool res = false;
204 203
205 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || 204 struct timeval tvs, tvn;
206 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { 205 ::gettimeofday ( &tvs, 0 );
207 struct timeval tvs, tvn;
208
209 // ::signal ( SIGTSTP, SIG_IGN );// we don't want to be stopped
210 ::gettimeofday ( &tvs, 0 );
211 206
212 ::sync ( ); // flush fs caches 207 ::sync ( ); // flush fs caches
213 208 res = ( ::system ( "apm --suspend" ) == 0 );
214 res = ( ::ioctl ( fd, APM_IOC_SUSPEND, 0 ) == 0 ); // tell the kernel to "start" suspending 209
215 ::close ( fd ); 210 // This is needed because the iPAQ apm implementation is asynchronous and we
216 211 // can not be sure when exactly the device is really suspended
217 if ( res ) { 212 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists.
218 // ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in our process group 213
219 214 if ( res ) {
220 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed 215 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
221 ::usleep ( 200 * 1000 ); 216 ::usleep ( 200 * 1000 );
222 ::gettimeofday ( &tvn, 0 ); 217 ::gettimeofday ( &tvn, 0 );
223 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); 218 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
224
225 // ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group
226 }
227
228 // ::signal ( SIGTSTP, SIG_DFL );
229 } 219 }
230 220
231 return res; 221 return res;
232} 222}
233 223
234//#include <linux/fb.h> better not rely on kernel headers in userspace ... 224//#include <linux/fb.h> better not rely on kernel headers in userspace ...
235 225
236#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 226#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611
237 227
238/* VESA Blanking Levels */ 228/* VESA Blanking Levels */
239#define VESA_NO_BLANKING 0 229#define VESA_NO_BLANKING 0
240#define VESA_VSYNC_SUSPEND 1 230#define VESA_VSYNC_SUSPEND 1
241#define VESA_HSYNC_SUSPEND 2 231#define VESA_HSYNC_SUSPEND 2
242#define VESA_POWERDOWN 3 232#define VESA_POWERDOWN 3
243 233
244 234
245bool ODevice::setDisplayStatus ( bool on ) 235bool ODevice::setDisplayStatus ( bool on )
246{ 236{
247 if ( d-> m_model == Model_Unknown ) 237 if ( d-> m_model == Model_Unknown )
248 return false; 238 return false;
249 239
250 bool res = false; 240 bool res = false;
251 int fd; 241 int fd;
252 242
253 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { 243 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) {
254 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); 244 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 );
255 ::close ( fd ); 245 ::close ( fd );
256 } 246 }
257 return res; 247 return res;
258} 248}
259 249
260bool ODevice::setDisplayBrightness ( int ) 250bool ODevice::setDisplayBrightness ( int )
261{ 251{
262 return false; 252 return false;
263} 253}
264 254
265int ODevice::displayBrightnessResolution ( ) const 255int ODevice::displayBrightnessResolution ( ) const
266{ 256{
267 return 16; 257 return 16;
268} 258}
269 259
270QString ODevice::vendorString ( ) const 260QString ODevice::vendorString ( ) const
271{ 261{
272 return d-> m_vendorstr; 262 return d-> m_vendorstr;
273} 263}
274 264
275OVendor ODevice::vendor ( ) const 265OVendor ODevice::vendor ( ) const
276{ 266{
277 return d-> m_vendor; 267 return d-> m_vendor;
278} 268}
279 269
280QString ODevice::modelString ( ) const 270QString ODevice::modelString ( ) const
281{ 271{
282 return d-> m_modelstr; 272 return d-> m_modelstr;
283} 273}
284 274
285OModel ODevice::model ( ) const 275OModel ODevice::model ( ) const
286{ 276{
287 return d-> m_model; 277 return d-> m_model;
288} 278}
289 279
290QString ODevice::systemString ( ) const 280QString ODevice::systemString ( ) const
291{ 281{
292 return d-> m_systemstr; 282 return d-> m_systemstr;
293} 283}
294 284
295OSystem ODevice::system ( ) const 285OSystem ODevice::system ( ) const
296{ 286{
297 return d-> m_system; 287 return d-> m_system;
298} 288}
299 289
300QString ODevice::systemVersionString ( ) const 290QString ODevice::systemVersionString ( ) const
301{ 291{
302 return d-> m_sysverstr; 292 return d-> m_sysverstr;
303} 293}
304 294
305void ODevice::alarmSound ( ) 295void ODevice::alarmSound ( )
306{ 296{
307#ifndef QT_NO_SOUND 297#ifndef QT_NO_SOUND
308 static Sound snd ( "alarm" ); 298 static Sound snd ( "alarm" );
309 299
310 if ( snd. isFinished ( )) 300 if ( snd. isFinished ( ))
311 snd. play ( ); 301 snd. play ( );
312#endif 302#endif
313} 303}
314 304
315void ODevice::keySound ( ) 305void ODevice::keySound ( )
316{ 306{
317#ifndef QT_NO_SOUND 307#ifndef QT_NO_SOUND
318 static Sound snd ( "keysound" ); 308 static Sound snd ( "keysound" );
319 309
320 if ( snd. isFinished ( )) 310 if ( snd. isFinished ( ))
321 snd. play ( ); 311 snd. play ( );
322#endif 312#endif
323} 313}
324 314
325void ODevice::touchSound ( ) 315void ODevice::touchSound ( )
326{ 316{
327 317
328#ifndef QT_NO_SOUND 318#ifndef QT_NO_SOUND
329 static Sound snd ( "touchsound" ); 319 static Sound snd ( "touchsound" );
330 320
331 if ( snd. isFinished ( )) 321 if ( snd. isFinished ( ))
332 snd. play ( ); 322 snd. play ( );
333#endif 323#endif
334} 324}
335 325
336 326
337QValueList <OLed> ODevice::ledList ( ) const 327QValueList <OLed> ODevice::ledList ( ) const
338{ 328{
339 return QValueList <OLed> ( ); 329 return QValueList <OLed> ( );
340} 330}
341 331
342QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const 332QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const
343{ 333{
344 return QValueList <OLedState> ( ); 334 return QValueList <OLedState> ( );
345} 335}
346 336
347OLedState ODevice::ledState ( OLed /*which*/ ) const 337OLedState ODevice::ledState ( OLed /*which*/ ) const
348{ 338{
349 return Led_Off; 339 return Led_Off;
350} 340}
351 341
352bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ ) 342bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ )
353{ 343{
354 return false; 344 return false;
355} 345}
356 346