summaryrefslogtreecommitdiff
authorsandman <sandman>2002-10-27 15:52:44 (UTC)
committer sandman <sandman>2002-10-27 15:52:44 (UTC)
commitbf21c882b82bfcdbcdce6b2dc5d863a2a2fb37c7 (patch) (unidiff)
tree6f104afe571f394bea83b94cb0de9242ee742b88
parent4ad1fa6d01c9de96d309cd662e658bcb1bb899a5 (diff)
downloadopie-bf21c882b82bfcdbcdce6b2dc5d863a2a2fb37c7.zip
opie-bf21c882b82bfcdbcdce6b2dc5d863a2a2fb37c7.tar.gz
opie-bf21c882b82bfcdbcdce6b2dc5d863a2a2fb37c7.tar.bz2
- new function to check for and read the light sensor
- redone the Model enum, to make it easier to check for "any iPAQ" !! This means every application using this enum has to be recompiled !!
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp42
-rw-r--r--libopie/odevice.h17
2 files changed, 54 insertions, 5 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 58bd663..44fe35f 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -54,64 +54,67 @@ class 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
87 virtual bool hasLightSensor ( ) const;
88 virtual int readLightSensor ( );
86 89
87 //virtual QValueList <int> keyList ( ) const; 90 //virtual QValueList <int> keyList ( ) const;
88 91
89protected: 92protected:
90 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); 93 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
91 virtual void timerEvent ( QTimerEvent *te ); 94 virtual void timerEvent ( QTimerEvent *te );
92 95
93 int m_power_timer; 96 int m_power_timer;
94 97
95 OLedState m_leds [2]; 98 OLedState m_leds [2];
96}; 99};
97 100
98class Zaurus : public ODevice { 101class Zaurus : public ODevice {
99protected: 102protected:
100 virtual void init ( ); 103 virtual void init ( );
101 104
102 public: 105 public:
103 virtual bool setSoftSuspend ( bool soft ); 106 virtual bool setSoftSuspend ( bool soft );
104 107
105 virtual bool setDisplayBrightness ( int b ); 108 virtual bool setDisplayBrightness ( int b );
106 virtual int displayBrightnessResolution ( ) const; 109 virtual int displayBrightnessResolution ( ) const;
107 110
108 virtual void alarmSound ( ); 111 virtual void alarmSound ( );
109 virtual void keySound ( ); 112 virtual void keySound ( );
110 virtual void touchSound ( ); 113 virtual void touchSound ( );
111 114
112 virtual QValueList <OLed> ledList ( ) const; 115 virtual QValueList <OLed> ledList ( ) const;
113 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 116 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
114 virtual OLedState ledState ( OLed led ) const; 117 virtual OLedState ledState ( OLed led ) const;
115 virtual bool setLedState ( OLed led, OLedState st ); 118 virtual bool setLedState ( OLed led, OLedState st );
116 119
117 //virtual QValueList <int> keyList ( ) const; 120 //virtual QValueList <int> keyList ( ) const;
@@ -327,64 +330,73 @@ void ODevice::touchSound ( )
327 330
328#ifndef QT_QWS_EBX 331#ifndef QT_QWS_EBX
329#ifndef QT_NO_SOUND 332#ifndef QT_NO_SOUND
330 static Sound snd ( "touchsound" ); 333 static Sound snd ( "touchsound" );
331 334
332 if ( snd. isFinished ( )) 335 if ( snd. isFinished ( ))
333 snd. play ( ); 336 snd. play ( );
334#endif 337#endif
335#endif 338#endif
336} 339}
337 340
338 341
339QValueList <OLed> ODevice::ledList ( ) const 342QValueList <OLed> ODevice::ledList ( ) const
340{ 343{
341 return QValueList <OLed> ( ); 344 return QValueList <OLed> ( );
342} 345}
343 346
344QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const 347QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const
345{ 348{
346 return QValueList <OLedState> ( ); 349 return QValueList <OLedState> ( );
347} 350}
348 351
349OLedState ODevice::ledState ( OLed /*which*/ ) const 352OLedState ODevice::ledState ( OLed /*which*/ ) const
350{ 353{
351 return Led_Off; 354 return Led_Off;
352} 355}
353 356
354bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ ) 357bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ )
355{ 358{
356 return false; 359 return false;
357} 360}
358 361
362bool ODevice::hasLightSensor ( ) const
363{
364 return false;
365}
366
367int ODevice::readLightSensor ( )
368{
369 return -1;
370}
359 371
360 372
361//QValueList <int> ODevice::keyList ( ) const 373//QValueList <int> ODevice::keyList ( ) const
362//{ 374//{
363 //return QValueList <int> ( ); 375 //return QValueList <int> ( );
364//} 376//}
365 377
366 378
367 379
368/************************************************** 380/**************************************************
369 * 381 *
370 * iPAQ 382 * iPAQ
371 * 383 *
372 **************************************************/ 384 **************************************************/
373 385
374void iPAQ::init ( ) 386void iPAQ::init ( )
375{ 387{
376 d-> m_vendorstr = "HP"; 388 d-> m_vendorstr = "HP";
377 d-> m_vendor = Vendor_HP; 389 d-> m_vendor = Vendor_HP;
378 390
379 QFile f ( "/proc/hal/model" ); 391 QFile f ( "/proc/hal/model" );
380 392
381 if ( f. open ( IO_ReadOnly )) { 393 if ( f. open ( IO_ReadOnly )) {
382 QTextStream ts ( &f ); 394 QTextStream ts ( &f );
383 395
384 d-> m_modelstr = "H" + ts. readLine ( ); 396 d-> m_modelstr = "H" + ts. readLine ( );
385 397
386 if ( d-> m_modelstr == "H3100" ) 398 if ( d-> m_modelstr == "H3100" )
387 d-> m_model = Model_iPAQ_H31xx; 399 d-> m_model = Model_iPAQ_H31xx;
388 else if ( d-> m_modelstr == "H3600" ) 400 else if ( d-> m_modelstr == "H3600" )
389 d-> m_model = Model_iPAQ_H36xx; 401 d-> m_model = Model_iPAQ_H36xx;
390 else if ( d-> m_modelstr == "H3700" ) 402 else if ( d-> m_modelstr == "H3700" )
@@ -637,64 +649,94 @@ bool iPAQ::setDisplayBrightness ( int bright )
637{ 649{
638 bool res = false; 650 bool res = false;
639 int fd; 651 int fd;
640 652
641 if ( bright > 255 ) 653 if ( bright > 255 )
642 bright = 255; 654 bright = 255;
643 if ( bright < 0 ) 655 if ( bright < 0 )
644 bright = 0; 656 bright = 0;
645 657
646 // 128 is the maximum if you want a decent lifetime for the LCD 658 // 128 is the maximum if you want a decent lifetime for the LCD
647 659
648 if ( bright > 1 ) 660 if ( bright > 1 )
649 bright = (int) ( 0.5 + ( ::pow ( 2, double( bright ) / 255.0 ) - 1 ) * 128.0 ); // logarithmic 661 bright = (int) ( 0.5 + ( ::pow ( 2, double( bright ) / 255.0 ) - 1 ) * 128.0 ); // logarithmic
650 //bright = ( bright + 1 ) / 2; 662 //bright = ( bright + 1 ) / 2;
651 663
652 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { 664 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
653 FLITE_IN bl; 665 FLITE_IN bl;
654 bl. mode = 1; 666 bl. mode = 1;
655 bl. pwr = bright ? 1 : 0; 667 bl. pwr = bright ? 1 : 0;
656 bl. brightness = bright; 668 bl. brightness = bright;
657 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); 669 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 );
658 ::close ( fd ); 670 ::close ( fd );
659 } 671 }
660 return res; 672 return res;
661} 673}
662 674
663int iPAQ::displayBrightnessResolution ( ) const 675int iPAQ::displayBrightnessResolution ( ) const
664{ 676{
665 return 255; // really 128, but logarithmic control is smoother this way 677 return 255; // really 128, but logarithmic control is smoother this way
666} 678}
667 679
668 680
681bool iPAQ::hasLightSensor ( ) const
682{
683 return true;
684}
685
686int iPAQ::readLightSensor ( )
687{
688 int fd;
689 int val = -1;
690
691 if (( fd = ::open ( "/proc/hal/lightsensor", O_RDONLY )) >= 0 ) {
692 char buffer [5];
693
694 if ( ::read ( fd, buffer, 4 ) == 4 ) {
695 char *endptr;
696
697 buffer [4] = 0;
698 val = ::strtol ( buffer + 2, &endptr, 16 );
699
700 if ( *endptr != 0 )
701 val = -1;
702 }
703
704 ::close ( fd );
705 }
706
707 return val;
708}
709
710
669/************************************************** 711/**************************************************
670 * 712 *
671 * Zaurus 713 * Zaurus
672 * 714 *
673 **************************************************/ 715 **************************************************/
674 716
675 717
676 718
677void Zaurus::init ( ) 719void Zaurus::init ( )
678{ 720{
679 d-> m_modelstr = "Zaurus SL5000"; 721 d-> m_modelstr = "Zaurus SL5000";
680 d-> m_model = Model_Zaurus_SL5000; 722 d-> m_model = Model_Zaurus_SL5000;
681 d-> m_vendorstr = "Sharp"; 723 d-> m_vendorstr = "Sharp";
682 d-> m_vendor = Vendor_Sharp; 724 d-> m_vendor = Vendor_Sharp;
683 725
684 QFile f ( "/proc/filesystems" ); 726 QFile f ( "/proc/filesystems" );
685 727
686 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { 728 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) {
687 d-> m_systemstr = "OpenZaurus"; 729 d-> m_systemstr = "OpenZaurus";
688 d-> m_system = System_OpenZaurus; 730 d-> m_system = System_OpenZaurus;
689 731
690 f. close ( ); 732 f. close ( );
691 733
692 f. setName ( "/etc/oz_version" ); 734 f. setName ( "/etc/oz_version" );
693 if ( f. open ( IO_ReadOnly )) { 735 if ( f. open ( IO_ReadOnly )) {
694 QTextStream ts ( &f ); 736 QTextStream ts ( &f );
695 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 737 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
696 f. close ( ); 738 f. close ( );
697 } 739 }
698 } 740 }
699 else { 741 else {
700 d-> m_systemstr = "Zaurus"; 742 d-> m_systemstr = "Zaurus";
diff --git a/libopie/odevice.h b/libopie/odevice.h
index 38f3787..be2a9c7 100644
--- a/libopie/odevice.h
+++ b/libopie/odevice.h
@@ -1,70 +1,74 @@
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#ifndef _LIBOPIE_ODEVICE_H_ 20#ifndef _LIBOPIE_ODEVICE_H_
21#define _LIBOPIE_ODEVICE_H_ 21#define _LIBOPIE_ODEVICE_H_
22 22
23#include <qstring.h> 23#include <qstring.h>
24#include <qnamespace.h> 24#include <qnamespace.h>
25 25
26class ODeviceData; 26class ODeviceData;
27 27
28namespace Opie { 28namespace Opie {
29 29
30enum OModel { 30enum OModel {
31 Model_Unknown, 31 Model_Unknown,
32 32
33 Model_iPAQ_H31xx, 33 Model_iPAQ = ( 1 << 16 ),
34 Model_iPAQ_H36xx,
35 Model_iPAQ_H37xx,
36 Model_iPAQ_H38xx,
37 34
38 Model_Zaurus_SL5000 35 Model_iPAQ_H31xx = ( Model_iPAQ | 1 ),
36 Model_iPAQ_H36xx = ( Model_iPAQ | 2 ),
37 Model_iPAQ_H37xx = ( Model_iPAQ | 3 ),
38 Model_iPAQ_H38xx = ( Model_iPAQ | 4 ),
39
40 Model_Zaurus = ( 2 << 16 ),
41
42 Model_Zaurus_SL5000 = ( Model_Zaurus | 1 ),
39}; 43};
40 44
41 enum OVendor { 45 enum OVendor {
42 Vendor_Unknown, 46 Vendor_Unknown,
43 47
44 Vendor_HP, 48 Vendor_HP,
45 Vendor_Sharp 49 Vendor_Sharp
46 }; 50 };
47 51
48enum OSystem { 52enum OSystem {
49 System_Unknown, 53 System_Unknown,
50 54
51 System_Familiar, 55 System_Familiar,
52 System_Zaurus, 56 System_Zaurus,
53 System_OpenZaurus 57 System_OpenZaurus
54}; 58};
55 59
56enum OLedState { 60enum OLedState {
57 Led_Off, 61 Led_Off,
58 Led_On, 62 Led_On,
59 Led_BlinkSlow, 63 Led_BlinkSlow,
60 Led_BlinkFast 64 Led_BlinkFast
61}; 65};
62 66
63enum OLed { 67enum OLed {
64 Led_Mail, 68 Led_Mail,
65 Led_Power, 69 Led_Power,
66 Led_BlueTooth 70 Led_BlueTooth
67}; 71};
68 72
69enum OHardKey { 73enum OHardKey {
70 HardKey_Datebook = Qt::Key_F9, 74 HardKey_Datebook = Qt::Key_F9,
@@ -100,39 +104,42 @@ public:
100 104
101 QString modelString ( ) const; 105 QString modelString ( ) const;
102 OModel model ( ) const; 106 OModel model ( ) const;
103 107
104 QString vendorString ( ) const; 108 QString vendorString ( ) const;
105 OVendor vendor ( ) const; 109 OVendor vendor ( ) const;
106 110
107 QString systemString ( ) const; 111 QString systemString ( ) const;
108 OSystem system ( ) const; 112 OSystem system ( ) const;
109 113
110 QString systemVersionString ( ) const; 114 QString systemVersionString ( ) const;
111 115
112 // system 116 // system
113 117
114 virtual bool setSoftSuspend ( bool on ); 118 virtual bool setSoftSuspend ( bool on );
115 virtual bool suspend ( ); 119 virtual bool suspend ( );
116 120
117 virtual bool setDisplayStatus ( bool on ); 121 virtual bool setDisplayStatus ( bool on );
118 virtual bool setDisplayBrightness ( int brightness ); 122 virtual bool setDisplayBrightness ( int brightness );
119 virtual int displayBrightnessResolution ( ) const; 123 virtual int displayBrightnessResolution ( ) const;
120 124
121// input / output 125// input / output
122 126
123 virtual void alarmSound ( ); 127 virtual void alarmSound ( );
124 virtual void keySound ( ); 128 virtual void keySound ( );
125 virtual void touchSound ( ); 129 virtual void touchSound ( );
126 130
127 virtual QValueList <OLed> ledList ( ) const; 131 virtual QValueList <OLed> ledList ( ) const;
128 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 132 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
129 virtual OLedState ledState ( OLed led ) const; 133 virtual OLedState ledState ( OLed led ) const;
130 virtual bool setLedState ( OLed led, OLedState st ); 134 virtual bool setLedState ( OLed led, OLedState st );
131 135
136 virtual bool hasLightSensor ( ) const;
137 virtual int readLightSensor ( );
138
132 //virtual QValueList <int> keyList ( ) const; 139 //virtual QValueList <int> keyList ( ) const;
133}; 140};
134 141
135} 142}
136 143
137#endif 144#endif
138 145