summaryrefslogtreecommitdiff
authorsandman <sandman>2002-10-29 15:50:21 (UTC)
committer sandman <sandman>2002-10-29 15:50:21 (UTC)
commitbad66a2ea2aea8bec1c7895b0e1a461e2f4859c2 (patch) (unidiff)
tree6a39587f58ff01456fff0a6d17d5564d28bb4f4f
parent6224d462ef211b3b4cffa42d4a7f261caa92834b (diff)
downloadopie-bad66a2ea2aea8bec1c7895b0e1a461e2f4859c2.zip
opie-bad66a2ea2aea8bec1c7895b0e1a461e2f4859c2.tar.gz
opie-bad66a2ea2aea8bec1c7895b0e1a461e2f4859c2.tar.bz2
added lightSensorResolution() to get the hardware resolution of the light
sensor
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp12
-rw-r--r--libopie/odevice.h1
2 files changed, 11 insertions, 2 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 9f64fc0..4c49c4f 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -41,96 +41,97 @@
41 41
42// _IO and friends are only defined in kernel headers ... 42// _IO and friends are only defined in kernel headers ...
43 43
44#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) 44#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
45 45
46#define OD_IO(type,number) OD_IOC(0,type,number,0) 46#define OD_IO(type,number) OD_IOC(0,type,number,0)
47#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) 47#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size))
48#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) 48#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size))
49#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) 49#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size))
50 50
51using namespace Opie; 51using namespace Opie;
52 52
53class ODeviceData { 53class ODeviceData {
54public: 54public:
55 bool m_qwsserver; 55 bool m_qwsserver;
56 56
57 QString m_vendorstr; 57 QString m_vendorstr;
58 OVendor m_vendor; 58 OVendor m_vendor;
59 59
60 QString m_modelstr; 60 QString m_modelstr;
61 OModel m_model; 61 OModel m_model;
62 62
63 QString m_systemstr; 63 QString m_systemstr;
64 OSystem m_system; 64 OSystem m_system;
65 65
66 QString m_sysverstr; 66 QString m_sysverstr;
67}; 67};
68 68
69 69
70class iPAQ : public QObject, public ODevice, public QWSServer::KeyboardFilter { 70class iPAQ : public QObject, public ODevice, public QWSServer::KeyboardFilter {
71protected: 71protected:
72 virtual void init ( ); 72 virtual void init ( );
73 73
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 90
90 //virtual QValueList <int> keyList ( ) const; 91 //virtual QValueList <int> keyList ( ) const;
91 92
92protected: 93protected:
93 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 );
94 virtual void timerEvent ( QTimerEvent *te ); 95 virtual void timerEvent ( QTimerEvent *te );
95 96
96 int m_power_timer; 97 int m_power_timer;
97 98
98 OLedState m_leds [2]; 99 OLedState m_leds [2];
99}; 100};
100 101
101class Zaurus : public ODevice { 102class Zaurus : public ODevice {
102protected: 103protected:
103 virtual void init ( ); 104 virtual void init ( );
104 105
105 public: 106 public:
106 virtual bool setSoftSuspend ( bool soft ); 107 virtual bool setSoftSuspend ( bool soft );
107 108
108 virtual bool setDisplayBrightness ( int b ); 109 virtual bool setDisplayBrightness ( int b );
109 virtual int displayBrightnessResolution ( ) const; 110 virtual int displayBrightnessResolution ( ) const;
110 111
111 virtual void alarmSound ( ); 112 virtual void alarmSound ( );
112 virtual void keySound ( ); 113 virtual void keySound ( );
113 virtual void touchSound ( ); 114 virtual void touchSound ( );
114 115
115 virtual QValueList <OLed> ledList ( ) const; 116 virtual QValueList <OLed> ledList ( ) const;
116 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 117 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
117 virtual OLedState ledState ( OLed led ) const; 118 virtual OLedState ledState ( OLed led ) const;
118 virtual bool setLedState ( OLed led, OLedState st ); 119 virtual bool setLedState ( OLed led, OLedState st );
119 120
120 //virtual QValueList <int> keyList ( ) const; 121 //virtual QValueList <int> keyList ( ) const;
121 122
122protected: 123protected:
123 virtual void buzzer ( int snd ); 124 virtual void buzzer ( int snd );
124 125
125 OLedState m_leds [1]; 126 OLedState m_leds [1];
126}; 127};
127 128
128 129
129 130
130 131
131 132
132 133
133 134
134ODevice *ODevice::inst ( ) 135ODevice *ODevice::inst ( )
135{ 136{
136 static ODevice *dev = 0; 137 static ODevice *dev = 0;
@@ -324,96 +325,100 @@ void ODevice::keySound ( )
324#endif 325#endif
325#endif 326#endif
326} 327}
327 328
328void ODevice::touchSound ( ) 329void ODevice::touchSound ( )
329{ 330{
330 331
331#ifndef QT_QWS_EBX 332#ifndef QT_QWS_EBX
332#ifndef QT_NO_SOUND 333#ifndef QT_NO_SOUND
333 static Sound snd ( "touchsound" ); 334 static Sound snd ( "touchsound" );
334 335
335 if ( snd. isFinished ( )) 336 if ( snd. isFinished ( ))
336 snd. play ( ); 337 snd. play ( );
337#endif 338#endif
338#endif 339#endif
339} 340}
340 341
341 342
342QValueList <OLed> ODevice::ledList ( ) const 343QValueList <OLed> ODevice::ledList ( ) const
343{ 344{
344 return QValueList <OLed> ( ); 345 return QValueList <OLed> ( );
345} 346}
346 347
347QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const 348QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const
348{ 349{
349 return QValueList <OLedState> ( ); 350 return QValueList <OLedState> ( );
350} 351}
351 352
352OLedState ODevice::ledState ( OLed /*which*/ ) const 353OLedState ODevice::ledState ( OLed /*which*/ ) const
353{ 354{
354 return Led_Off; 355 return Led_Off;
355} 356}
356 357
357bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ ) 358bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ )
358{ 359{
359 return false; 360 return false;
360} 361}
361 362
362bool ODevice::hasLightSensor ( ) const 363bool ODevice::hasLightSensor ( ) const
363{ 364{
364 return false; 365 return false;
365} 366}
366 367
367int ODevice::readLightSensor ( ) 368int ODevice::readLightSensor ( )
368{ 369{
369 return -1; 370 return -1;
370} 371}
371 372
373int ODevice::lightSensorResolution ( ) const
374{
375 return 0;
376}
372 377
373//QValueList <int> ODevice::keyList ( ) const 378//QValueList <int> ODevice::keyList ( ) const
374//{ 379//{
375 //return QValueList <int> ( ); 380 //return QValueList <int> ( );
376//} 381//}
377 382
378 383
379 384
380/************************************************** 385/**************************************************
381 * 386 *
382 * iPAQ 387 * iPAQ
383 * 388 *
384 **************************************************/ 389 **************************************************/
385 390
386void iPAQ::init ( ) 391void iPAQ::init ( )
387{ 392{
388 d-> m_vendorstr = "HP"; 393 d-> m_vendorstr = "HP";
389 d-> m_vendor = Vendor_HP; 394 d-> m_vendor = Vendor_HP;
390 395
391 QFile f ( "/proc/hal/model" ); 396 QFile f ( "/proc/hal/model" );
392 397
393 if ( f. open ( IO_ReadOnly )) { 398 if ( f. open ( IO_ReadOnly )) {
394 QTextStream ts ( &f ); 399 QTextStream ts ( &f );
395 400
396 d-> m_modelstr = "H" + ts. readLine ( ); 401 d-> m_modelstr = "H" + ts. readLine ( );
397 402
398 if ( d-> m_modelstr == "H3100" ) 403 if ( d-> m_modelstr == "H3100" )
399 d-> m_model = Model_iPAQ_H31xx; 404 d-> m_model = Model_iPAQ_H31xx;
400 else if ( d-> m_modelstr == "H3600" ) 405 else if ( d-> m_modelstr == "H3600" )
401 d-> m_model = Model_iPAQ_H36xx; 406 d-> m_model = Model_iPAQ_H36xx;
402 else if ( d-> m_modelstr == "H3700" ) 407 else if ( d-> m_modelstr == "H3700" )
403 d-> m_model = Model_iPAQ_H37xx; 408 d-> m_model = Model_iPAQ_H37xx;
404 else if ( d-> m_modelstr == "H3800" ) 409 else if ( d-> m_modelstr == "H3800" )
405 d-> m_model = Model_iPAQ_H38xx; 410 d-> m_model = Model_iPAQ_H38xx;
406 else 411 else
407 d-> m_model = Model_Unknown; 412 d-> m_model = Model_Unknown;
408 413
409 f. close ( ); 414 f. close ( );
410 } 415 }
411 416
412 f. setName ( "/etc/familiar-version" ); 417 f. setName ( "/etc/familiar-version" );
413 if ( f. open ( IO_ReadOnly )) { 418 if ( f. open ( IO_ReadOnly )) {
414 d-> m_systemstr = "Familiar"; 419 d-> m_systemstr = "Familiar";
415 d-> m_system = System_Familiar; 420 d-> m_system = System_Familiar;
416 421
417 QTextStream ts ( &f ); 422 QTextStream ts ( &f );
418 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 423 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
419 424
@@ -637,121 +642,124 @@ bool iPAQ::setSoftSuspend ( bool soft )
637 ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); 642 ::perror ( "write to /proc/sys/ts/suspend_button_mode" );
638 643
639 ::close ( fd ); 644 ::close ( fd );
640 } 645 }
641 else 646 else
642 ::perror ( "/proc/sys/ts/suspend_button_mode" ); 647 ::perror ( "/proc/sys/ts/suspend_button_mode" );
643 648
644 return res; 649 return res;
645} 650}
646 651
647 652
648bool iPAQ::setDisplayBrightness ( int bright ) 653bool iPAQ::setDisplayBrightness ( int bright )
649{ 654{
650 bool res = false; 655 bool res = false;
651 int fd; 656 int fd;
652 657
653 if ( bright > 255 ) 658 if ( bright > 255 )
654 bright = 255; 659 bright = 255;
655 if ( bright < 0 ) 660 if ( bright < 0 )
656 bright = 0; 661 bright = 0;
657 662
658 // 128 is the maximum if you want a decent lifetime for the LCD 663 // 128 is the maximum if you want a decent lifetime for the LCD
659 664
660 if ( bright > 1 ) 665 if ( bright > 1 )
661 bright = (int) ( 0.5 + ( ::pow ( 2, double( bright ) / 255.0 ) - 1 ) * 128.0 ); // logarithmic 666 bright = (int) ( 0.5 + ( ::pow ( 2, double( bright ) / 255.0 ) - 1 ) * 128.0 ); // logarithmic
662 //bright = ( bright + 1 ) / 2; 667 //bright = ( bright + 1 ) / 2;
663 668
664 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { 669 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
665 FLITE_IN bl; 670 FLITE_IN bl;
666 bl. mode = 1; 671 bl. mode = 1;
667 bl. pwr = bright ? 1 : 0; 672 bl. pwr = bright ? 1 : 0;
668 bl. brightness = bright; 673 bl. brightness = bright;
669 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); 674 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 );
670 ::close ( fd ); 675 ::close ( fd );
671 } 676 }
672 return res; 677 return res;
673} 678}
674 679
675int iPAQ::displayBrightnessResolution ( ) const 680int iPAQ::displayBrightnessResolution ( ) const
676{ 681{
677 return 256; // really 128, but logarithmic control is smoother this way 682 return 256; // really 128, but logarithmic control is smoother this way
678} 683}
679 684
680 685
681bool iPAQ::hasLightSensor ( ) const 686bool iPAQ::hasLightSensor ( ) const
682{ 687{
683 return true; 688 return true;
684} 689}
685#include <errno.h> 690
686#include <string.h>
687int iPAQ::readLightSensor ( ) 691int iPAQ::readLightSensor ( )
688{ 692{
689 int fd; 693 int fd;
690 int val = -1; 694 int val = -1;
691 695
692 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { 696 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) {
693 char buffer [8]; 697 char buffer [8];
694 698
695 if ( ::read ( fd, buffer, 5 ) == 5 ) { 699 if ( ::read ( fd, buffer, 5 ) == 5 ) {
696 char *endptr; 700 char *endptr;
697 701
698 buffer [4] = 0; 702 buffer [4] = 0;
699 val = ::strtol ( buffer + 2, &endptr, 16 ); 703 val = ::strtol ( buffer + 2, &endptr, 16 );
700 704
701 if ( *endptr != 0 ) 705 if ( *endptr != 0 )
702 val = -1; 706 val = -1;
703 } 707 }
704 ::close ( fd ); 708 ::close ( fd );
705 } 709 }
706 710
707 return val; 711 return val;
708} 712}
709 713
714int iPAQ::lightSensorResolution ( ) const
715{
716 return 256;
717}
710 718
711/************************************************** 719/**************************************************
712 * 720 *
713 * Zaurus 721 * Zaurus
714 * 722 *
715 **************************************************/ 723 **************************************************/
716 724
717 725
718 726
719void Zaurus::init ( ) 727void Zaurus::init ( )
720{ 728{
721 d-> m_modelstr = "Zaurus SL5000"; 729 d-> m_modelstr = "Zaurus SL5000";
722 d-> m_model = Model_Zaurus_SL5000; 730 d-> m_model = Model_Zaurus_SL5000;
723 d-> m_vendorstr = "Sharp"; 731 d-> m_vendorstr = "Sharp";
724 d-> m_vendor = Vendor_Sharp; 732 d-> m_vendor = Vendor_Sharp;
725 733
726 QFile f ( "/proc/filesystems" ); 734 QFile f ( "/proc/filesystems" );
727 735
728 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { 736 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) {
729 d-> m_systemstr = "OpenZaurus"; 737 d-> m_systemstr = "OpenZaurus";
730 d-> m_system = System_OpenZaurus; 738 d-> m_system = System_OpenZaurus;
731 739
732 f. close ( ); 740 f. close ( );
733 741
734 f. setName ( "/etc/oz_version" ); 742 f. setName ( "/etc/oz_version" );
735 if ( f. open ( IO_ReadOnly )) { 743 if ( f. open ( IO_ReadOnly )) {
736 QTextStream ts ( &f ); 744 QTextStream ts ( &f );
737 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 745 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
738 f. close ( ); 746 f. close ( );
739 } 747 }
740 } 748 }
741 else { 749 else {
742 d-> m_systemstr = "Zaurus"; 750 d-> m_systemstr = "Zaurus";
743 d-> m_system = System_Zaurus; 751 d-> m_system = System_Zaurus;
744 } 752 }
745 753
746 754
747 m_leds [0] = Led_Off; 755 m_leds [0] = Led_Off;
748} 756}
749 757
750#include <unistd.h> 758#include <unistd.h>
751#include <fcntl.h> 759#include <fcntl.h>
752#include <sys/ioctl.h> 760#include <sys/ioctl.h>
753 761
754//#include <asm/sharp_char.h> // including kernel headers is evil ... 762//#include <asm/sharp_char.h> // including kernel headers is evil ...
755 763
756#define SHARP_DEV_IOCTL_COMMAND_START 0x5680 764#define SHARP_DEV_IOCTL_COMMAND_START 0x5680
757 765
diff --git a/libopie/odevice.h b/libopie/odevice.h
index be2a9c7..e07b91c 100644
--- a/libopie/odevice.h
+++ b/libopie/odevice.h
@@ -90,56 +90,57 @@ private:
90protected: 90protected:
91 ODevice ( ); 91 ODevice ( );
92 virtual void init ( ); 92 virtual void init ( );
93 93
94 ODeviceData *d; 94 ODeviceData *d;
95 95
96public: 96public:
97 virtual ~ODevice ( ); 97 virtual ~ODevice ( );
98 98
99 static ODevice *inst ( ); 99 static ODevice *inst ( );
100 100
101 101
102 102
103// information 103// information
104 104
105 QString modelString ( ) const; 105 QString modelString ( ) const;
106 OModel model ( ) const; 106 OModel model ( ) const;
107 107
108 QString vendorString ( ) const; 108 QString vendorString ( ) const;
109 OVendor vendor ( ) const; 109 OVendor vendor ( ) const;
110 110
111 QString systemString ( ) const; 111 QString systemString ( ) const;
112 OSystem system ( ) const; 112 OSystem system ( ) const;
113 113
114 QString systemVersionString ( ) const; 114 QString systemVersionString ( ) const;
115 115
116 // system 116 // system
117 117
118 virtual bool setSoftSuspend ( bool on ); 118 virtual bool setSoftSuspend ( bool on );
119 virtual bool suspend ( ); 119 virtual bool suspend ( );
120 120
121 virtual bool setDisplayStatus ( bool on ); 121 virtual bool setDisplayStatus ( bool on );
122 virtual bool setDisplayBrightness ( int brightness ); 122 virtual bool setDisplayBrightness ( int brightness );
123 virtual int displayBrightnessResolution ( ) const; 123 virtual int displayBrightnessResolution ( ) const;
124 124
125// input / output 125// input / output
126 126
127 virtual void alarmSound ( ); 127 virtual void alarmSound ( );
128 virtual void keySound ( ); 128 virtual void keySound ( );
129 virtual void touchSound ( ); 129 virtual void touchSound ( );
130 130
131 virtual QValueList <OLed> ledList ( ) const; 131 virtual QValueList <OLed> ledList ( ) const;
132 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 132 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
133 virtual OLedState ledState ( OLed led ) const; 133 virtual OLedState ledState ( OLed led ) const;
134 virtual bool setLedState ( OLed led, OLedState st ); 134 virtual bool setLedState ( OLed led, OLedState st );
135 135
136 virtual bool hasLightSensor ( ) const; 136 virtual bool hasLightSensor ( ) const;
137 virtual int readLightSensor ( ); 137 virtual int readLightSensor ( );
138 virtual int lightSensorResolution ( ) const;
138 139
139 //virtual QValueList <int> keyList ( ) const; 140 //virtual QValueList <int> keyList ( ) const;
140}; 141};
141 142
142} 143}
143 144
144#endif 145#endif
145 146