summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 9871e80..3bc1e0c 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -168,582 +168,590 @@ bool ODevice::suspend ( )
168 168
169 int fd; 169 int fd;
170 bool res = false; 170 bool res = false;
171 171
172 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || 172 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
173 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { 173 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
174 struct timeval tvs, tvn; 174 struct timeval tvs, tvn;
175 175
176 ::signal ( SIGTSTP, SIG_IGN );// we don't want to be stopped 176 ::signal ( SIGTSTP, SIG_IGN );// we don't want to be stopped
177 ::gettimeofday ( &tvs, 0 ); 177 ::gettimeofday ( &tvs, 0 );
178 178
179 ::sync ( ); // flush fs caches 179 ::sync ( ); // flush fs caches
180 180
181 res = ( ::ioctl ( fd, APM_IOC_SUSPEND, 0 ) == 0 ); // tell the kernel to "start" suspending 181 res = ( ::ioctl ( fd, APM_IOC_SUSPEND, 0 ) == 0 ); // tell the kernel to "start" suspending
182 182
183 if ( res ) { 183 if ( res ) {
184 ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in our process group 184 ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in our process group
185 185
186 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed 186 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
187 ::usleep ( 200 * 1000 ); 187 ::usleep ( 200 * 1000 );
188 ::gettimeofday ( &tvn, 0 ); 188 ::gettimeofday ( &tvn, 0 );
189 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); 189 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
190 190
191 ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group 191 ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group
192 } 192 }
193 193
194 ::close ( fd ); 194 ::close ( fd );
195 ::signal ( SIGTSTP, SIG_DFL ); 195 ::signal ( SIGTSTP, SIG_DFL );
196 } 196 }
197 197
198 return res; 198 return res;
199} 199}
200 200
201//#include <linux/fb.h> better not rely on kernel headers in userspace ... 201//#include <linux/fb.h> better not rely on kernel headers in userspace ...
202 202
203#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 203#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611
204 204
205/* VESA Blanking Levels */ 205/* VESA Blanking Levels */
206#define VESA_NO_BLANKING 0 206#define VESA_NO_BLANKING 0
207#define VESA_VSYNC_SUSPEND 1 207#define VESA_VSYNC_SUSPEND 1
208#define VESA_HSYNC_SUSPEND 2 208#define VESA_HSYNC_SUSPEND 2
209#define VESA_POWERDOWN 3 209#define VESA_POWERDOWN 3
210 210
211 211
212bool ODevice::setDisplayStatus ( bool on ) 212bool ODevice::setDisplayStatus ( bool on )
213{ 213{
214 if ( d-> m_model == OMODEL_Unknown ) 214 if ( d-> m_model == OMODEL_Unknown )
215 return false; 215 return false;
216 216
217 bool res = false; 217 bool res = false;
218 int fd; 218 int fd;
219 219
220 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { 220 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) {
221 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); 221 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 );
222 ::close ( fd ); 222 ::close ( fd );
223 } 223 }
224 return res; 224 return res;
225} 225}
226 226
227bool ODevice::setDisplayBrightness ( int ) 227bool ODevice::setDisplayBrightness ( int )
228{ 228{
229 return false; 229 return false;
230} 230}
231 231
232int ODevice::displayBrightnessResolution ( ) const 232int ODevice::displayBrightnessResolution ( ) const
233{ 233{
234 return 16; 234 return 16;
235} 235}
236 236
237QString ODevice::vendorString ( ) 237QString ODevice::vendorString ( )
238{ 238{
239 return d-> m_vendorstr; 239 return d-> m_vendorstr;
240} 240}
241 241
242OVendor ODevice::vendor ( ) 242OVendor ODevice::vendor ( )
243{ 243{
244 return d-> m_vendor; 244 return d-> m_vendor;
245} 245}
246 246
247QString ODevice::modelString ( ) 247QString ODevice::modelString ( )
248{ 248{
249 return d-> m_modelstr; 249 return d-> m_modelstr;
250} 250}
251 251
252OModel ODevice::model ( ) 252OModel ODevice::model ( )
253{ 253{
254 return d-> m_model; 254 return d-> m_model;
255} 255}
256 256
257QString ODevice::systemString ( ) 257QString ODevice::systemString ( )
258{ 258{
259 return d-> m_systemstr; 259 return d-> m_systemstr;
260} 260}
261 261
262OSystem ODevice::system ( ) 262OSystem ODevice::system ( )
263{ 263{
264 return d-> m_system; 264 return d-> m_system;
265} 265}
266 266
267QString ODevice::systemVersionString ( ) 267QString ODevice::systemVersionString ( )
268{ 268{
269 return d-> m_sysverstr; 269 return d-> m_sysverstr;
270} 270}
271 271
272void ODevice::alarmSound ( ) 272void ODevice::alarmSound ( )
273{ 273{
274#ifndef QT_QWS_EBX 274#ifndef QT_QWS_EBX
275#ifndef QT_NO_SOUND 275#ifndef QT_NO_SOUND
276 static Sound snd ( "alarm" ); 276 static Sound snd ( "alarm" );
277 277
278 if ( snd. isFinished ( )) 278 if ( snd. isFinished ( ))
279 snd. play ( ); 279 snd. play ( );
280#endif 280#endif
281#endif 281#endif
282} 282}
283 283
284void ODevice::keySound ( ) 284void ODevice::keySound ( )
285{ 285{
286#ifndef QT_QWS_EBX 286#ifndef QT_QWS_EBX
287#ifndef QT_NO_SOUND 287#ifndef QT_NO_SOUND
288 static Sound snd ( "keysound" ); 288 static Sound snd ( "keysound" );
289 289
290 if ( snd. isFinished ( )) 290 if ( snd. isFinished ( ))
291 snd. play ( ); 291 snd. play ( );
292#endif 292#endif
293#endif 293#endif
294} 294}
295 295
296void ODevice::touchSound ( ) 296void ODevice::touchSound ( )
297{ 297{
298 298
299#ifndef QT_QWS_EBX 299#ifndef QT_QWS_EBX
300#ifndef QT_NO_SOUND 300#ifndef QT_NO_SOUND
301 static Sound snd ( "touchsound" ); 301 static Sound snd ( "touchsound" );
302 302
303 if ( snd. isFinished ( )) 303 if ( snd. isFinished ( ))
304 snd. play ( ); 304 snd. play ( );
305#endif 305#endif
306#endif 306#endif
307} 307}
308 308
309uint ODevice::hasLeds ( ) const 309uint ODevice::hasLeds ( ) const
310{ 310{
311 return 0; 311 return 0;
312} 312}
313 313
314OLedState ODevice::led ( uint /*which*/ ) const 314OLedState ODevice::led ( uint /*which*/ ) const
315{ 315{
316 return OLED_Off; 316 return OLED_Off;
317} 317}
318 318
319bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ ) 319bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ )
320{ 320{
321 return false; 321 return false;
322} 322}
323 323
324 324
325 325
326 326
327/************************************************** 327/**************************************************
328 * 328 *
329 * iPAQ 329 * iPAQ
330 * 330 *
331 **************************************************/ 331 **************************************************/
332 332
333void ODeviceIPAQ::init ( ) 333void ODeviceIPAQ::init ( )
334{ 334{
335 d-> m_vendorstr = "HP"; 335 d-> m_vendorstr = "HP";
336 d-> m_vendor = OVENDOR_HP; 336 d-> m_vendor = OVENDOR_HP;
337 337
338 QFile f ( "/proc/hal/model" ); 338 QFile f ( "/proc/hal/model" );
339 339
340 if ( f. open ( IO_ReadOnly )) { 340 if ( f. open ( IO_ReadOnly )) {
341 QTextStream ts ( &f ); 341 QTextStream ts ( &f );
342 342
343 d-> m_modelstr = "H" + ts. readLine ( ); 343 d-> m_modelstr = "H" + ts. readLine ( );
344 344
345 if ( d-> m_modelstr == "H3100" ) 345 if ( d-> m_modelstr == "H3100" )
346 d-> m_model = OMODEL_iPAQ_H31xx; 346 d-> m_model = OMODEL_iPAQ_H31xx;
347 else if ( d-> m_modelstr == "H3600" ) 347 else if ( d-> m_modelstr == "H3600" )
348 d-> m_model = OMODEL_iPAQ_H36xx; 348 d-> m_model = OMODEL_iPAQ_H36xx;
349 else if ( d-> m_modelstr == "H3700" ) 349 else if ( d-> m_modelstr == "H3700" )
350 d-> m_model = OMODEL_iPAQ_H37xx; 350 d-> m_model = OMODEL_iPAQ_H37xx;
351 else if ( d-> m_modelstr == "H3800" ) 351 else if ( d-> m_modelstr == "H3800" )
352 d-> m_model = OMODEL_iPAQ_H38xx; 352 d-> m_model = OMODEL_iPAQ_H38xx;
353 else 353 else
354 d-> m_model = OMODEL_Unknown; 354 d-> m_model = OMODEL_Unknown;
355 355
356 f. close ( ); 356 f. close ( );
357 } 357 }
358 358
359 f. setName ( "/etc/familiar-version" ); 359 f. setName ( "/etc/familiar-version" );
360 if ( f. open ( IO_ReadOnly )) { 360 if ( f. open ( IO_ReadOnly )) {
361 d-> m_systemstr = "Familiar"; 361 d-> m_systemstr = "Familiar";
362 d-> m_system = OSYSTEM_Familiar; 362 d-> m_system = OSYSTEM_Familiar;
363 363
364 QTextStream ts ( &f ); 364 QTextStream ts ( &f );
365 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 365 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
366 366
367 f. close ( ); 367 f. close ( );
368 } 368 }
369 369
370 d-> m_leds [0] = OLED_Off; 370 d-> m_leds [0] = OLED_Off;
371} 371}
372 372
373//#include <linux/h3600_ts.h> // including kernel headers is evil ... 373//#include <linux/h3600_ts.h> // including kernel headers is evil ...
374 374
375typedef struct { 375typedef struct {
376 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ 376 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */
377 unsigned char TotalTime; /* Units of 5 seconds */ 377 unsigned char TotalTime; /* Units of 5 seconds */
378 unsigned char OnTime; /* units of 100m/s */ 378 unsigned char OnTime; /* units of 100m/s */
379 unsigned char OffTime; /* units of 100m/s */ 379 unsigned char OffTime; /* units of 100m/s */
380} LED_IN; 380} LED_IN;
381 381
382typedef struct { 382typedef struct {
383 unsigned char mode; 383 unsigned char mode;
384 unsigned char pwr; 384 unsigned char pwr;
385 unsigned char brightness; 385 unsigned char brightness;
386} FLITE_IN; 386} FLITE_IN;
387 387
388#define LED_ON OD_IOW( 'f', 5, LED_IN ) 388#define LED_ON OD_IOW( 'f', 5, LED_IN )
389#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) 389#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN )
390 390
391 391
392void ODeviceIPAQ::alarmSound ( ) 392void ODeviceIPAQ::alarmSound ( )
393{ 393{
394#if defined( QT_QWS_IPAQ ) // IPAQ 394#if defined( QT_QWS_IPAQ ) // IPAQ
395#ifndef QT_NO_SOUND 395#ifndef QT_NO_SOUND
396 static Sound snd ( "alarm" ); 396 static Sound snd ( "alarm" );
397 int fd; 397 int fd;
398 int vol; 398 int vol;
399 bool vol_reset = false; 399 bool vol_reset = false;
400 400
401 if ((( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) || 401 if ((( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) ||
402 (( fd = ::open ( "/dev/mixer", O_RDWR )) >= 0 )) { 402 (( fd = ::open ( "/dev/mixer", O_RDWR )) >= 0 )) {
403 403
404 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { 404 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
405 Config cfg ( "qpe" ); 405 Config cfg ( "qpe" );
406 cfg. setGroup ( "Volume" ); 406 cfg. setGroup ( "Volume" );
407 407
408 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); 408 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
409 if ( volalarm < 0 ) 409 if ( volalarm < 0 )
410 volalarm = 0; 410 volalarm = 0;
411 else if ( volalarm > 100 ) 411 else if ( volalarm > 100 )
412 volalarm = 100; 412 volalarm = 100;
413 volalarm |= ( volalarm << 8 ); 413 volalarm |= ( volalarm << 8 );
414 414
415 if (( volalarm & 0xff ) > ( vol & 0xff )) { 415 if (( volalarm & 0xff ) > ( vol & 0xff )) {
416 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) 416 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
417 vol_reset = true; 417 vol_reset = true;
418 } 418 }
419 } 419 }
420 } 420 }
421 421
422 snd. play ( ); 422 snd. play ( );
423 while ( !snd. isFinished ( )) 423 while ( !snd. isFinished ( ))
424 qApp-> processEvents ( ); 424 qApp-> processEvents ( );
425 425
426 if ( fd >= 0 ) { 426 if ( fd >= 0 ) {
427 if ( vol_reset ) 427 if ( vol_reset )
428 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); 428 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
429 ::close ( fd ); 429 ::close ( fd );
430 } 430 }
431#endif 431#endif
432#endif 432#endif
433} 433}
434 434
435uint ODeviceIPAQ::hasLeds ( ) const 435uint ODeviceIPAQ::hasLeds ( ) const
436{ 436{
437 return 1; 437 return 1;
438} 438}
439 439
440OLedState ODeviceIPAQ::led ( uint which ) const 440OLedState ODeviceIPAQ::led ( uint which ) const
441{ 441{
442 if ( which == 0 ) 442 if ( which == 0 )
443 return d-> m_leds [0]; 443 return d-> m_leds [0];
444 else 444 else
445 return OLED_Off; 445 return OLED_Off;
446} 446}
447 447
448bool ODeviceIPAQ::setLed ( uint which, OLedState st ) 448bool ODeviceIPAQ::setLed ( uint which, OLedState st )
449{ 449{
450 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR|O_NONBLOCK ); 450 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR|O_NONBLOCK );
451 451
452 if ( which == 0 ) { 452 if ( which == 0 ) {
453 if ( fd >= 0 ) { 453 if ( fd >= 0 ) {
454 LED_IN leds; 454 LED_IN leds;
455 ::memset ( &leds, 0, sizeof( leds )); 455 ::memset ( &leds, 0, sizeof( leds ));
456 leds. TotalTime = 0; 456 leds. TotalTime = 0;
457 leds. OnTime = 0; 457 leds. OnTime = 0;
458 leds. OffTime = 1; 458 leds. OffTime = 1;
459 leds. OffOnBlink = 2; 459 leds. OffOnBlink = 2;
460 460
461 switch ( st ) { 461 switch ( st ) {
462 case OLED_Off : leds. OffOnBlink = 0; break; 462 case OLED_Off : leds. OffOnBlink = 0; break;
463 case OLED_On : leds. OffOnBlink = 1; break; 463 case OLED_On : leds. OffOnBlink = 1; break;
464 case OLED_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; 464 case OLED_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break;
465 case OLED_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; 465 case OLED_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break;
466 } 466 }
467 467
468 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { 468 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) {
469 d-> m_leds [0] = st; 469 d-> m_leds [0] = st;
470 return true; 470 return true;
471 } 471 }
472 } 472 }
473 } 473 }
474 return false; 474 return false;
475} 475}
476 476
477bool ODeviceIPAQ::setPowerButtonHandler ( ODevice::PowerButtonHandler p ) 477bool ODeviceIPAQ::setPowerButtonHandler ( ODevice::PowerButtonHandler p )
478{ 478{
479 bool res = false; 479 bool res = false;
480 int fd; 480 int fd;
481 481
482 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { 482 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) {
483 if ( ::write ( fd, p == KERNEL ? "0" : "1", 1 ) == 1 ) 483 if ( ::write ( fd, p == KERNEL ? "0" : "1", 1 ) == 1 )
484 res = true; 484 res = true;
485 else 485 else
486 ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); 486 ::perror ( "write to /proc/sys/ts/suspend_button_mode" );
487 487
488 ::close ( fd ); 488 ::close ( fd );
489 } 489 }
490 else 490 else
491 ::perror ( "/proc/sys/ts/suspend_button_mode" ); 491 ::perror ( "/proc/sys/ts/suspend_button_mode" );
492 492
493 return res; 493 return res;
494} 494}
495 495
496 496
497bool ODeviceIPAQ::setDisplayBrightness ( int bright ) 497bool ODeviceIPAQ::setDisplayBrightness ( int bright )
498{ 498{
499 bool res = false; 499 bool res = false;
500 int fd; 500 int fd;
501 501
502 if ( bright > 255 ) 502 if ( bright > 255 )
503 bright = 255; 503 bright = 255;
504 if ( bright < 0 ) 504 if ( bright < 0 )
505 bright = 0; 505 bright = 0;
506 506
507 // 128 is the maximum if you want a decent lifetime for the LCD 507 // 128 is the maximum if you want a decent lifetime for the LCD
508 508
509 bright = (int) (( ::pow ( 2, double( bright ) / 255.0 ) - 1 ) * 128.0 ); // logarithmic 509 bright = (int) (( ::pow ( 2, double( bright ) / 255.0 ) - 1 ) * 128.0 ); // logarithmic
510 //bright = ( bright + 1 ) / 2; 510 //bright = ( bright + 1 ) / 2;
511 511
512 if ((( fd = ::open ( "/dev/ts", O_WRONLY )) >= 0 ) || 512 if ((( fd = ::open ( "/dev/ts", O_WRONLY )) >= 0 ) ||
513 (( fd = ::open ( "/dev/h3600_ts", O_WRONLY )) >= 0 )) { 513 (( fd = ::open ( "/dev/h3600_ts", O_WRONLY )) >= 0 )) {
514 FLITE_IN bl; 514 FLITE_IN bl;
515 bl. mode = 1; 515 bl. mode = 1;
516 bl. pwr = bright ? 1 : 0; 516 bl. pwr = bright ? 1 : 0;
517 bl. brightness = bright; 517 bl. brightness = bright;
518 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); 518 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 );
519 ::close ( fd ); 519 ::close ( fd );
520 } 520 }
521 return res; 521 return res;
522} 522}
523 523
524int ODeviceIPAQ::displayBrightnessResolution ( ) const 524int ODeviceIPAQ::displayBrightnessResolution ( ) const
525{ 525{
526 return 255; // really 128, but logarithmic control is smoother this way 526 return 255; // really 128, but logarithmic control is smoother this way
527} 527}
528 528
529 529
530/************************************************** 530/**************************************************
531 * 531 *
532 * Zaurus 532 * Zaurus
533 * 533 *
534 **************************************************/ 534 **************************************************/
535 535
536 536
537 537
538void ODeviceZaurus::init ( ) 538void ODeviceZaurus::init ( )
539{ 539{
540 d-> m_modelstr = "Zaurus SL5000"; 540 d-> m_modelstr = "Zaurus SL5000";
541 d-> m_model = OMODEL_Zaurus_SL5000; 541 d-> m_model = OMODEL_Zaurus_SL5000;
542 d-> m_vendorstr = "Sharp"; 542 d-> m_vendorstr = "Sharp";
543 d-> m_vendor = OVENDOR_Sharp; 543 d-> m_vendor = OVENDOR_Sharp;
544 544
545 QFile f ( "/proc/filesystems" ); 545 QFile f ( "/proc/filesystems" );
546 546
547 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { 547 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) {
548 d-> m_systemstr = "OpenZaurus"; 548 d-> m_systemstr = "OpenZaurus";
549 d-> m_system = OSYSTEM_OpenZaurus; 549 d-> m_system = OSYSTEM_OpenZaurus;
550 550
551 f. close ( ); 551 f. close ( );
552
553 f. setName ( "/etc/oz_version" );
554 if ( f. open ( IO_ReadOnly )) {
555 QTextStream ts ( &f );
556 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
557 f. close ( );
558 }
552 } 559 }
553 else { 560 else {
554 d-> m_systemstr = "Zaurus"; 561 d-> m_systemstr = "Zaurus";
555 d-> m_system = OSYSTEM_Zaurus; 562 d-> m_system = OSYSTEM_Zaurus;
556 } 563 }
557 564
565
558 d-> m_leds [0] = OLED_Off; 566 d-> m_leds [0] = OLED_Off;
559} 567}
560 568
561#include <unistd.h> 569#include <unistd.h>
562#include <fcntl.h> 570#include <fcntl.h>
563#include <sys/ioctl.h> 571#include <sys/ioctl.h>
564 572
565//#include <asm/sharp_char.h> // including kernel headers is evil ... 573//#include <asm/sharp_char.h> // including kernel headers is evil ...
566 574
567#define SHARP_DEV_IOCTL_COMMAND_START 0x5680 575#define SHARP_DEV_IOCTL_COMMAND_START 0x5680
568 576
569 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 577 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
570#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 578#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
571 579
572#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 580#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
573#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 581#define SHARP_BUZ_KEYSOUND 2 /* key sound */
574#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 582#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
575 583
576/* --- for SHARP_BUZZER device --- */ 584/* --- for SHARP_BUZZER device --- */
577 585
578 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 586 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
579//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 587//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
580 588
581#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) 589#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1)
582#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2) 590#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2)
583#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3) 591#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3)
584#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4) 592#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4)
585#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5) 593#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5)
586 594
587//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 595//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
588//#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 596//#define SHARP_BUZ_KEYSOUND 2 /* key sound */
589 597
590//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */ 598//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */
591//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */ 599//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */
592//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */ 600//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */
593//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */ 601//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */
594//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */ 602//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */
595//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */ 603//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */
596//#define SHARP_PDA_APPSTART 9 /* application start */ 604//#define SHARP_PDA_APPSTART 9 /* application start */
597//#define SHARP_PDA_APPQUIT 10 /* application ends */ 605//#define SHARP_PDA_APPQUIT 10 /* application ends */
598 606
599//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 607//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
600//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */ 608//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */
601//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */ 609//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */
602//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */ 610//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */
603// 611//
604 612
605 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 613 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
606#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1) 614#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1)
607 615
608typedef struct sharp_led_status { 616typedef struct sharp_led_status {
609 int which; /* select which LED status is wanted. */ 617 int which; /* select which LED status is wanted. */
610 int status; /* set new led status if you call SHARP_LED_SETSTATUS */ 618 int status; /* set new led status if you call SHARP_LED_SETSTATUS */
611} sharp_led_status; 619} sharp_led_status;
612 620
613#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */ 621#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */
614 622
615#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */ 623#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */
616#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */ 624#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */
617#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */ 625#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */
618 626
619// #include <asm/sharp_apm.h> // including kernel headers is evil ... 627// #include <asm/sharp_apm.h> // including kernel headers is evil ...
620 628
621#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int ) 629#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int )
622#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int ) 630#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int )
623#define APM_EVT_POWER_BUTTON (1 << 0) 631#define APM_EVT_POWER_BUTTON (1 << 0)
624 632
625#define FL_IOCTL_STEP_CONTRAST 100 633#define FL_IOCTL_STEP_CONTRAST 100
626 634
627 635
628void ODeviceZaurus::buzzer ( int sound ) 636void ODeviceZaurus::buzzer ( int sound )
629{ 637{
630 static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK ); 638 static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK );
631 639
632 if ( fd >= 0 ) 640 if ( fd >= 0 )
633 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); 641 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound );
634} 642}
635 643
636 644
637void ODeviceZaurus::alarmSound ( ) 645void ODeviceZaurus::alarmSound ( )
638{ 646{
639 buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); 647 buzzer ( SHARP_BUZ_SCHEDULE_ALARM );
640} 648}
641 649
642void ODeviceZaurus::touchSound ( ) 650void ODeviceZaurus::touchSound ( )
643{ 651{
644 buzzer ( SHARP_BUZ_TOUCHSOUND ); 652 buzzer ( SHARP_BUZ_TOUCHSOUND );
645} 653}
646 654
647void ODeviceZaurus::keySound ( ) 655void ODeviceZaurus::keySound ( )
648{ 656{
649 buzzer ( SHARP_BUZ_KEYSOUND ); 657 buzzer ( SHARP_BUZ_KEYSOUND );
650} 658}
651 659
652 660
653uint ODeviceZaurus::hasLeds ( ) const 661uint ODeviceZaurus::hasLeds ( ) const
654{ 662{
655 return 1; 663 return 1;
656} 664}
657 665
658OLedState ODeviceZaurus::led ( uint which ) const 666OLedState ODeviceZaurus::led ( uint which ) const
659{ 667{
660 if ( which == 0 ) 668 if ( which == 0 )
661 return d-> m_leds [0]; 669 return d-> m_leds [0];
662 else 670 else
663 return OLED_Off; 671 return OLED_Off;
664} 672}
665 673
666bool ODeviceZaurus::setLed ( uint which, OLedState st ) 674bool ODeviceZaurus::setLed ( uint which, OLedState st )
667{ 675{
668 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); 676 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK );
669 677
670 if ( which == 0 ) { 678 if ( which == 0 ) {
671 if ( fd >= 0 ) { 679 if ( fd >= 0 ) {
672 struct sharp_led_status leds; 680 struct sharp_led_status leds;
673 ::memset ( &leds, 0, sizeof( leds )); 681 ::memset ( &leds, 0, sizeof( leds ));
674 leds. which = SHARP_LED_MAIL_EXISTS; 682 leds. which = SHARP_LED_MAIL_EXISTS;
675 683
676 switch ( st ) { 684 switch ( st ) {
677 case OLED_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; 685 case OLED_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break;
678 case OLED_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; 686 case OLED_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break;
679 case OLED_BlinkSlow: 687 case OLED_BlinkSlow:
680 case OLED_BlinkFast: leds. status = LED_MAIL_UNREAD_MAIL_EX; break; 688 case OLED_BlinkFast: leds. status = LED_MAIL_UNREAD_MAIL_EX; break;
681 } 689 }
682 690
683 if ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 ) { 691 if ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 ) {
684 d-> m_leds [0] = st; 692 d-> m_leds [0] = st;
685 return true; 693 return true;
686 } 694 }
687 } 695 }
688 } 696 }
689 return false; 697 return false;
690} 698}
691 699
692bool ODeviceZaurus::setPowerButtonHandler ( ODevice::PowerButtonHandler p ) 700bool ODeviceZaurus::setPowerButtonHandler ( ODevice::PowerButtonHandler p )
693{ 701{
694 bool res = false; 702 bool res = false;
695 int fd; 703 int fd;
696 704
697 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || 705 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
698 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { 706 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
699 707
700 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources 708 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources
701 709
702 if ( sources >= 0 ) { 710 if ( sources >= 0 ) {
703 if ( p == KERNEL ) 711 if ( p == KERNEL )
704 sources |= APM_EVT_POWER_BUTTON; 712 sources |= APM_EVT_POWER_BUTTON;
705 else 713 else
706 sources &= ~APM_EVT_POWER_BUTTON; 714 sources &= ~APM_EVT_POWER_BUTTON;
707 715
708 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources & ~APM_EVT_POWER_BUTTON ) >= 0 ) // set new event sources 716 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources & ~APM_EVT_POWER_BUTTON ) >= 0 ) // set new event sources
709 res = true; 717 res = true;
710 else 718 else
711 perror ( "APM_IOCGEVTSRC" ); 719 perror ( "APM_IOCGEVTSRC" );
712 } 720 }
713 else 721 else
714 perror ( "APM_IOCGEVTSRC" ); 722 perror ( "APM_IOCGEVTSRC" );
715 723
716 ::close ( fd ); 724 ::close ( fd );
717 } 725 }
718 else 726 else
719 perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); 727 perror ( "/dev/apm_bios or /dev/misc/apm_bios" );
720 728
721 return res; 729 return res;
722} 730}
723 731
724 732
725bool ODeviceZaurus::setDisplayBrightness ( int bright ) 733bool ODeviceZaurus::setDisplayBrightness ( int bright )
726{ 734{
727 bool res = false; 735 bool res = false;
728 int fd; 736 int fd;
729 737
730 if ( bright > 255 ) 738 if ( bright > 255 )
731 bright = 255; 739 bright = 255;
732 if ( bright < 0 ) 740 if ( bright < 0 )
733 bright = 0; 741 bright = 0;
734 742
735 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) { 743 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) {
736 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus 744 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus
737 if ( bright && !bl ) 745 if ( bright && !bl )
738 bl = 1; 746 bl = 1;
739 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 ); 747 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 );
740 ::close ( fd ); 748 ::close ( fd );
741 } 749 }
742 return res; 750 return res;
743} 751}
744 752
745 753
746int ODeviceZaurus::displayBrightnessResolution ( ) const 754int ODeviceZaurus::displayBrightnessResolution ( ) const
747{ 755{
748 return 4; 756 return 4;
749} 757}