summaryrefslogtreecommitdiff
authorsandman <sandman>2002-10-29 15:50:21 (UTC)
committer sandman <sandman>2002-10-29 15:50:21 (UTC)
commitbad66a2ea2aea8bec1c7895b0e1a461e2f4859c2 (patch) (side-by-side diff)
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 @@
// _IO and friends are only defined in kernel headers ...
#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
#define OD_IO(type,number) OD_IOC(0,type,number,0)
#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size))
#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size))
#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size))
using namespace Opie;
class ODeviceData {
public:
bool m_qwsserver;
QString m_vendorstr;
OVendor m_vendor;
QString m_modelstr;
OModel m_model;
QString m_systemstr;
OSystem m_system;
QString m_sysverstr;
};
class iPAQ : public QObject, public ODevice, public QWSServer::KeyboardFilter {
protected:
virtual void init ( );
public:
virtual bool setSoftSuspend ( bool soft );
virtual bool setDisplayBrightness ( int b );
virtual int displayBrightnessResolution ( ) const;
virtual void alarmSound ( );
virtual QValueList <OLed> ledList ( ) const;
virtual QValueList <OLedState> ledStateList ( OLed led ) const;
virtual OLedState ledState ( OLed led ) const;
virtual bool setLedState ( OLed led, OLedState st );
virtual bool hasLightSensor ( ) const;
virtual int readLightSensor ( );
+ virtual int lightSensorResolution ( ) const;
//virtual QValueList <int> keyList ( ) const;
protected:
virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
virtual void timerEvent ( QTimerEvent *te );
int m_power_timer;
OLedState m_leds [2];
};
class Zaurus : public ODevice {
protected:
virtual void init ( );
public:
virtual bool setSoftSuspend ( bool soft );
virtual bool setDisplayBrightness ( int b );
virtual int displayBrightnessResolution ( ) const;
virtual void alarmSound ( );
virtual void keySound ( );
virtual void touchSound ( );
virtual QValueList <OLed> ledList ( ) const;
virtual QValueList <OLedState> ledStateList ( OLed led ) const;
virtual OLedState ledState ( OLed led ) const;
virtual bool setLedState ( OLed led, OLedState st );
//virtual QValueList <int> keyList ( ) const;
protected:
virtual void buzzer ( int snd );
OLedState m_leds [1];
};
ODevice *ODevice::inst ( )
{
static ODevice *dev = 0;
@@ -324,96 +325,100 @@ void ODevice::keySound ( )
#endif
#endif
}
void ODevice::touchSound ( )
{
#ifndef QT_QWS_EBX
#ifndef QT_NO_SOUND
static Sound snd ( "touchsound" );
if ( snd. isFinished ( ))
snd. play ( );
#endif
#endif
}
QValueList <OLed> ODevice::ledList ( ) const
{
return QValueList <OLed> ( );
}
QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const
{
return QValueList <OLedState> ( );
}
OLedState ODevice::ledState ( OLed /*which*/ ) const
{
return Led_Off;
}
bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ )
{
return false;
}
bool ODevice::hasLightSensor ( ) const
{
return false;
}
int ODevice::readLightSensor ( )
{
return -1;
}
+int ODevice::lightSensorResolution ( ) const
+{
+ return 0;
+}
//QValueList <int> ODevice::keyList ( ) const
//{
// return QValueList <int> ( );
//}
/**************************************************
*
* iPAQ
*
**************************************************/
void iPAQ::init ( )
{
d-> m_vendorstr = "HP";
d-> m_vendor = Vendor_HP;
QFile f ( "/proc/hal/model" );
if ( f. open ( IO_ReadOnly )) {
QTextStream ts ( &f );
d-> m_modelstr = "H" + ts. readLine ( );
if ( d-> m_modelstr == "H3100" )
d-> m_model = Model_iPAQ_H31xx;
else if ( d-> m_modelstr == "H3600" )
d-> m_model = Model_iPAQ_H36xx;
else if ( d-> m_modelstr == "H3700" )
d-> m_model = Model_iPAQ_H37xx;
else if ( d-> m_modelstr == "H3800" )
d-> m_model = Model_iPAQ_H38xx;
else
d-> m_model = Model_Unknown;
f. close ( );
}
f. setName ( "/etc/familiar-version" );
if ( f. open ( IO_ReadOnly )) {
d-> m_systemstr = "Familiar";
d-> m_system = System_Familiar;
QTextStream ts ( &f );
d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
@@ -637,121 +642,124 @@ bool iPAQ::setSoftSuspend ( bool soft )
::perror ( "write to /proc/sys/ts/suspend_button_mode" );
::close ( fd );
}
else
::perror ( "/proc/sys/ts/suspend_button_mode" );
return res;
}
bool iPAQ::setDisplayBrightness ( int bright )
{
bool res = false;
int fd;
if ( bright > 255 )
bright = 255;
if ( bright < 0 )
bright = 0;
// 128 is the maximum if you want a decent lifetime for the LCD
if ( bright > 1 )
bright = (int) ( 0.5 + ( ::pow ( 2, double( bright ) / 255.0 ) - 1 ) * 128.0 ); // logarithmic
// bright = ( bright + 1 ) / 2;
if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
FLITE_IN bl;
bl. mode = 1;
bl. pwr = bright ? 1 : 0;
bl. brightness = bright;
res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 );
::close ( fd );
}
return res;
}
int iPAQ::displayBrightnessResolution ( ) const
{
return 256; // really 128, but logarithmic control is smoother this way
}
bool iPAQ::hasLightSensor ( ) const
{
return true;
}
-#include <errno.h>
-#include <string.h>
+
int iPAQ::readLightSensor ( )
{
int fd;
int val = -1;
if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) {
char buffer [8];
if ( ::read ( fd, buffer, 5 ) == 5 ) {
char *endptr;
buffer [4] = 0;
val = ::strtol ( buffer + 2, &endptr, 16 );
if ( *endptr != 0 )
val = -1;
}
::close ( fd );
}
return val;
}
+int iPAQ::lightSensorResolution ( ) const
+{
+ return 256;
+}
/**************************************************
*
* Zaurus
*
**************************************************/
void Zaurus::init ( )
{
d-> m_modelstr = "Zaurus SL5000";
d-> m_model = Model_Zaurus_SL5000;
d-> m_vendorstr = "Sharp";
d-> m_vendor = Vendor_Sharp;
QFile f ( "/proc/filesystems" );
if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) {
d-> m_systemstr = "OpenZaurus";
d-> m_system = System_OpenZaurus;
f. close ( );
f. setName ( "/etc/oz_version" );
if ( f. open ( IO_ReadOnly )) {
QTextStream ts ( &f );
d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
f. close ( );
}
}
else {
d-> m_systemstr = "Zaurus";
d-> m_system = System_Zaurus;
}
m_leds [0] = Led_Off;
}
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
//#include <asm/sharp_char.h> // including kernel headers is evil ...
#define SHARP_DEV_IOCTL_COMMAND_START 0x5680
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:
protected:
ODevice ( );
virtual void init ( );
ODeviceData *d;
public:
virtual ~ODevice ( );
static ODevice *inst ( );
// information
QString modelString ( ) const;
OModel model ( ) const;
QString vendorString ( ) const;
OVendor vendor ( ) const;
QString systemString ( ) const;
OSystem system ( ) const;
QString systemVersionString ( ) const;
// system
virtual bool setSoftSuspend ( bool on );
virtual bool suspend ( );
virtual bool setDisplayStatus ( bool on );
virtual bool setDisplayBrightness ( int brightness );
virtual int displayBrightnessResolution ( ) const;
// input / output
virtual void alarmSound ( );
virtual void keySound ( );
virtual void touchSound ( );
virtual QValueList <OLed> ledList ( ) const;
virtual QValueList <OLedState> ledStateList ( OLed led ) const;
virtual OLedState ledState ( OLed led ) const;
virtual bool setLedState ( OLed led, OLedState st );
virtual bool hasLightSensor ( ) const;
virtual int readLightSensor ( );
+ virtual int lightSensorResolution ( ) const;
//virtual QValueList <int> keyList ( ) const;
};
}
#endif