summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/device/odevice_ipaq.cpp
Unidiff
Diffstat (limited to 'libopie2/opiecore/device/odevice_ipaq.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_ipaq.cpp53
1 files changed, 45 insertions, 8 deletions
diff --git a/libopie2/opiecore/device/odevice_ipaq.cpp b/libopie2/opiecore/device/odevice_ipaq.cpp
index e6e3145..63b60a7 100644
--- a/libopie2/opiecore/device/odevice_ipaq.cpp
+++ b/libopie2/opiecore/device/odevice_ipaq.cpp
@@ -1,81 +1,82 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 =. (C) 2002-2005 The Opie Team <opie-devel@handhelds.org> 3 =. (C) 2002-2005 The Opie Team <opie-devel@handhelds.org>
4 .=l. 4 .=l.
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can 6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; version 2 of the License. 10 - .   .-<_>     .<> Foundation; version 2 of the License.
11     ._= =}       : 11     ._= =}       :
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that 13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more 18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details. 19++=   -.     .`     .: details.
20 :     =  ...= . :.=- 20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU 21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with 22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB. 23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation, 24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, 25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27 27
28*/ 28*/
29 29
30#include "odevice_ipaq.h" 30#include "odevice_ipaq.h"
31 31
32/* QT */ 32/* QT */
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qdir.h>
34#include <qfile.h> 35#include <qfile.h>
35#include <qtextstream.h> 36#include <qtextstream.h>
36#include <qwindowsystem_qws.h> 37#include <qwindowsystem_qws.h>
37 38
38/* OPIE */ 39/* OPIE */
39#include <qpe/config.h> 40#include <qpe/config.h>
40#include <qpe/sound.h> 41#include <qpe/sound.h>
41#include <qpe/qcopenvelope_qws.h> 42#include <qpe/qcopenvelope_qws.h>
42 43
43#include <opie2/okeyfilter.h> 44#include <opie2/okeyfilter.h>
44#include <opie2/oresource.h> 45#include <opie2/oresource.h>
45 46
46/* STD */ 47/* STD */
47#include <fcntl.h> 48#include <fcntl.h>
48#include <math.h> 49#include <math.h>
49#include <stdlib.h> 50#include <stdlib.h>
50#include <signal.h> 51#include <signal.h>
51#include <sys/ioctl.h> 52#include <sys/ioctl.h>
52#include <sys/time.h> 53#include <sys/time.h>
53#include <unistd.h> 54#include <unistd.h>
54#ifndef QT_NO_SOUND 55#ifndef QT_NO_SOUND
55#include <linux/soundcard.h> 56#include <linux/soundcard.h>
56#endif 57#endif
57 58
58 59
59using namespace Opie::Core; 60using namespace Opie::Core;
60using namespace Opie::Core::Internal; 61using namespace Opie::Core::Internal;
61 62
62/* KERNEL */ 63/* KERNEL */
63#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) 64#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
64 65
65#define OD_IO(type,number) OD_IOC(0,type,number,0) 66#define OD_IO(type,number) OD_IOC(0,type,number,0)
66#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) 67#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size))
67#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) 68#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size))
68#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) 69#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size))
69 70
70typedef struct { 71typedef struct {
71 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ 72 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */
72 unsigned char TotalTime; /* Units of 5 seconds */ 73 unsigned char TotalTime; /* Units of 5 seconds */
73 unsigned char OnTime; /* units of 100m/s */ 74 unsigned char OnTime; /* units of 100m/s */
74 unsigned char OffTime; /* units of 100m/s */ 75 unsigned char OffTime; /* units of 100m/s */
75} LED_IN; 76} LED_IN;
76 77
77typedef struct { 78typedef struct {
78 unsigned char mode; 79 unsigned char mode;
79 unsigned char pwr; 80 unsigned char pwr;
80 unsigned char brightness; 81 unsigned char brightness;
81} FLITE_IN; 82} FLITE_IN;
@@ -334,148 +335,184 @@ bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, b
334 break; 335 break;
335 } 336 }
336 } 337 }
337 338
338 if ( newkeycode != keycode ) { 339 if ( newkeycode != keycode ) {
339 if ( newkeycode != Key_unknown ) 340 if ( newkeycode != Key_unknown )
340 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); 341 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
341 return true; 342 return true;
342 } 343 }
343 else 344 else
344 return false; 345 return false;
345} 346}
346 347
347void iPAQ::timerEvent ( QTimerEvent * ) 348void iPAQ::timerEvent ( QTimerEvent * )
348{ 349{
349 killTimer ( m_power_timer ); 350 killTimer ( m_power_timer );
350 m_power_timer = 0; 351 m_power_timer = 0;
351 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); 352 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false );
352 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); 353 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false );
353} 354}
354 355
355 356
356void iPAQ::playAlarmSound() 357void iPAQ::playAlarmSound()
357{ 358{
358#ifndef QT_NO_SOUND 359#ifndef QT_NO_SOUND
359 static Sound snd ( "alarm" ); 360 static Sound snd ( "alarm" );
360 if(!snd.isFinished()) 361 if(!snd.isFinished())
361 return; 362 return;
362 363
363 changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); 364 changeMixerForAlarm(0, "/dev/sound/mixer", &snd );
364 snd. play(); 365 snd. play();
365#endif 366#endif
366} 367}
367 368
368bool iPAQ::setDisplayBrightness ( int bright ) 369bool iPAQ::setDisplayBrightness ( int bright )
369{ 370{
370 bool res = false; 371 bool res = false;
371 int fd; 372 int fd;
372 373
373 if ( bright > 255 ) 374 if ( bright > 255 )
374 bright = 255; 375 bright = 255;
375 if ( bright < 0 ) 376 if ( bright < 0 )
376 bright = 0; 377 bright = 0;
377 378
378 QString cmdline; 379 QString cmdline;
379 380
380 switch ( model()) { 381 switch ( model()) {
381 case Model_iPAQ_H191x: 382 case Model_iPAQ_H191x:
382 if ( !bright ) 383 {
383 cmdline = QString::fromLatin1( "echo 4 > /sys/class/backlight/pxafb/power"); 384 QDir sysClass( "/sys/class/backlight/pxafb/" );
384 else 385 sysClass.setFilter(QDir::Dirs);
385 cmdline = QString::fromLatin1( "echo 0 > /sys/class/backlight/pxafb/power; echo %1 > /sys/class/backlight/pxafb/brightness" ).arg( bright ); 386 int fd;
386 // No Global::shellQuote as we gurantee it to be sane 387 if ( sysClass.exists() ) {
387 res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); 388 QString sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/power" );
389 fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
390 if ( fd ) {
391 char buf[10];
392 buf[0] = bright ? 0 : 4;
393 buf[1] = '\0';
394 res = ( ::write( fd, &buf[0], 2 ) == 0 );
395 ::close( fd );
396 }
397 sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/brightness" );
398 fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
399 if ( fd ) {
400 char buf[100];
401 int len = ::snprintf( &buf[0], sizeof buf, "%d", bright );
402 res = ( ::write( fd, &buf[0], len ) == 0 );
403 ::close( fd );
404 }
405 }
406 }
388 break; 407 break;
389 408
390 case Model_iPAQ_HX4700: 409 case Model_iPAQ_HX4700:
391 cmdline = QString::fromLatin1( "echo %1 > /sys/class/backlight/w100fb/brightness" ).arg( bright ); 410 cmdline = QString::fromLatin1( "echo %1 > /sys/class/backlight/w100fb/brightness" ).arg( bright );
392 // No Global::shellQuote as we gurantee it to be sane 411 // No Global::shellQuote as we gurantee it to be sane
393 res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); 412 res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
394 break; 413 break;
395 414
396 415
397 default: 416 default:
398 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { 417 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
399 FLITE_IN bl; 418 FLITE_IN bl;
400 bl. mode = 1; 419 bl. mode = 1;
401 bl. pwr = bright ? 1 : 0; 420 bl. pwr = bright ? 1 : 0;
402 bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; 421 bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255;
403 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); 422 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 );
404 ::close ( fd ); 423 ::close ( fd );
405 } 424 }
406 } 425 }
407 return res; 426 return res;
408} 427}
409 428
410int iPAQ::displayBrightnessResolution() const 429int iPAQ::displayBrightnessResolution() const
411{ 430{
412 switch ( model()) { 431 switch ( model()) {
413 case Model_iPAQ_H31xx: 432 case Model_iPAQ_H31xx:
414 case Model_iPAQ_H36xx: 433 case Model_iPAQ_H36xx:
415 case Model_iPAQ_H37xx: 434 case Model_iPAQ_H37xx:
416 return 128; // really 256, but >128 could damage the LCD 435 return 128; // really 256, but >128 could damage the LCD
417 436
418 case Model_iPAQ_H38xx: 437 case Model_iPAQ_H38xx:
419 case Model_iPAQ_H39xx: 438 case Model_iPAQ_H39xx:
420 return 64; 439 return 64;
421 case Model_iPAQ_H5xxx: 440 case Model_iPAQ_H5xxx:
422 case Model_iPAQ_HX4700: 441 case Model_iPAQ_HX4700:
423 return 255; 442 return 255;
424 case Model_iPAQ_H191x: 443 case Model_iPAQ_H191x:
425 return 7; 444 return 7;
426 case Model_iPAQ_H1940: 445 case Model_iPAQ_H1940:
427 return 44; 446 return 44;
428 default: 447 default:
429 return 2; 448 return 2;
430 } 449 }
431} 450}
432 451
433bool iPAQ::setDisplayStatus ( bool on ) 452bool iPAQ::setDisplayStatus ( bool on )
434{ 453{
435 bool res = false; 454 bool res = false;
436 455
437 QString cmdline; 456 QString cmdline;
438 457
439 if ( model() == Model_iPAQ_H191x ) { 458 if ( model() == Model_iPAQ_H191x ) {
440 cmdline = QString::fromLatin1( "echo %1 > /sys/class/lcd/pxafb/power; echo %2 > /sys/class/backlight/pxafb/power").arg( on ? "0" : "4" ).arg( on ? "0" : "4" ); 459 QDir sysClass( "/sys/class/lcd/pxafb/" );
460 sysClass.setFilter(QDir::Dirs);
461 if ( sysClass.exists() ) {
462 QString sysClassPath = sysClass.absFilePath( "/sys/class/lcd/pxafb/power" );
463 int fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
464 if ( fd ) {
465 char buf[10];
466 buf[0] = on ? 0 : 4;
467 buf[1] = '\0';
468 res = ( ::write( fd, &buf[0], 2 ) == 0 );
469 ::close( fd );
470 }
471 }
472 return res;
441 } else { 473 } else {
442 return OAbstractMobileDevice::setDisplayStatus(on); 474 return OAbstractMobileDevice::setDisplayStatus(on);
443 } 475 }
444 476
445 res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); 477 res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
446 478
447 return res; 479 return res;
448} 480}
449 481
450bool iPAQ::hasLightSensor() const 482bool iPAQ::hasLightSensor() const
451{ 483{
452 return true; 484 switch (model()) {
485 case Model_iPAQ_H191x:
486 return false;
487 default:
488 return true;
489 }
453} 490}
454 491
455int iPAQ::readLightSensor() 492int iPAQ::readLightSensor()
456{ 493{
457 int fd; 494 int fd;
458 int val = -1; 495 int val = -1;
459 496
460 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { 497 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) {
461 char buffer [8]; 498 char buffer [8];
462 499
463 if ( ::read ( fd, buffer, 5 ) == 5 ) { 500 if ( ::read ( fd, buffer, 5 ) == 5 ) {
464 char *endptr; 501 char *endptr;
465 502
466 buffer [4] = 0; 503 buffer [4] = 0;
467 val = ::strtol ( buffer + 2, &endptr, 16 ); 504 val = ::strtol ( buffer + 2, &endptr, 16 );
468 505
469 if ( *endptr != 0 ) 506 if ( *endptr != 0 )
470 val = -1; 507 val = -1;
471 } 508 }
472 ::close ( fd ); 509 ::close ( fd );
473 } 510 }
474 511
475 return val; 512 return val;
476} 513}
477 514
478int iPAQ::lightSensorResolution() const 515int iPAQ::lightSensorResolution() const
479{ 516{
480 return 256; 517 return 256;
481} 518}