summaryrefslogtreecommitdiff
path: root/libopie/odevice.cpp
Side-by-side diff
Diffstat (limited to 'libopie/odevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp136
1 files changed, 101 insertions, 35 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index e24e043..bc09e92 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -119,51 +119,54 @@ public:
static bool isJornada();
};
class Zaurus : public ODevice {
protected:
virtual void init ( );
virtual void initButtons ( );
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 bool hasHingeSensor() const;
+ virtual OHingeStatus readHingeSensor();
+
static bool isZaurus();
-
- // Does this break BC?
+
+ // Does this break BC?
virtual bool suspend ( );
virtual Transformation rotation ( ) const;
virtual ODirection direction ( ) const;
protected:
virtual void buzzer ( int snd );
OLedState m_leds [1];
bool m_embedix;
};
class SIMpad : public ODevice, public QWSServer::KeyboardFilter {
protected:
virtual void init ( );
virtual void initButtons ( );
public:
virtual bool setSoftSuspend ( bool soft );
virtual bool suspend();
virtual bool setDisplayStatus( bool on );
virtual bool setDisplayBrightness ( int b );
virtual int displayBrightnessResolution ( ) const;
@@ -512,49 +515,49 @@ void ODevice::initButtons ( )
qDebug ( "init Buttons" );
d-> m_buttons = new QValueList <ODeviceButton>;
for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
i_button *ib = ipaq_buttons + i;
ODeviceButton b;
if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) {
b. setKeycode ( ib-> code );
b. setUserText ( QObject::tr ( "Button", ib-> utext ));
b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction ));
b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction ));
d-> m_buttons-> append ( b );
}
}
reloadButtonMapping ( );
QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & )));
}
ODevice::~ODevice ( )
{
-// we leak m_devicebuttons and m_cpu_frequency
+// we leak m_devicebuttons and m_cpu_frequency
// but it's a singleton and it is not so importantant
// -zecke
delete d;
}
bool ODevice::setSoftSuspend ( bool /*soft*/ )
{
return false;
}
//#include <linux/apm_bios.h>
#define APM_IOC_SUSPEND OD_IO( 'A', 2 )
/**
* This method will try to suspend the device
* It only works if the user is the QWS Server and the apm application
* is installed.
* It tries to suspend and then waits some time cause some distributions
* do have asynchronus apm implementations.
* This method will either fail and return false or it'll suspend the
* device and return once the device got woken up
*
* @return if the device got suspended
@@ -802,75 +805,91 @@ OLedState ODevice::ledState ( OLed /*which*/ ) const
}
/**
* Set the state for a LED
* @param which Which OLed to use
* @param st The state to set
* @return success or failure
*/
bool ODevice::setLedState ( OLed which, OLedState st )
{
Q_UNUSED( which )
Q_UNUSED( st )
return false;
}
/**
* @return if the device has a light sensor
*/
bool ODevice::hasLightSensor ( ) const
{
return false;
}
/**
- * @return a value from the light senso
+ * @return a value from the light sensor
*/
int ODevice::readLightSensor ( )
{
return -1;
}
/**
- * @return the light sensor resolution whatever that is ;)
+ * @return the light sensor resolution
*/
int ODevice::lightSensorResolution ( ) const
{
return 0;
}
/**
+ * @return if the device has a hinge sensor
+ */
+bool ODevice::hasHingeSensor ( ) const
+{
+ return false;
+}
+
+/**
+ * @return a value from the hinge sensor
+ */
+OHingeStatus ODevice::readHingeSensor ( )
+{
+ return CASE_UNKNOWN;
+}
+
+/**
* @return a list with CPU frequencies supported by the hardware
*/
const QStrList &ODevice::allowedCpuFrequencies ( ) const
{
return *d->m_cpu_frequencies;
}
/**
* Set desired CPU frequency
- *
+ *
* @param index index into d->m_cpu_frequencies of the frequency to be set
*/
bool ODevice::setCurrentCpuFrequency(uint index)
{
if (index >= d->m_cpu_frequencies->count())
return false;
char *freq = d->m_cpu_frequencies->at(index);
qWarning("set freq to %s", freq);
int fd;
if ((fd = ::open("/proc/sys/cpu/0/speed", O_WRONLY)) >= 0) {
char writeCommand[50];
const int count = sprintf(writeCommand, "%s\n", freq);
int res = (::write(fd, writeCommand, count) != -1);
::close(fd);
return res;
}
return false;
}
@@ -1761,49 +1780,49 @@ typedef struct sharp_led_status {
#define FL_IOCTL_STEP_CONTRAST 100
void Zaurus::buzzer ( int sound )
{
#ifndef QT_NO_SOUND
QString soundname;
// Not all devices have real sound
if ( d->m_model == Model_Zaurus_SLC7x0
|| d->m_model == Model_Zaurus_SLB600 ){
switch ( sound ){
case SHARP_BUZ_SCHEDULE_ALARM:
soundname = "alarm";
break;
case SHARP_BUZ_TOUCHSOUND:
soundname = "touchsound";
break;
case SHARP_BUZ_KEYSOUND:
soundname = "keysound";
break;
default:
soundname = "alarm";
-
+
}
}
// If a soundname is defined, we expect that this device has
// sound capabilities.. Otherwise we expect to have the buzzer
// device..
if ( !soundname.isEmpty() ){
int fd;
int vol;
bool vol_reset = false;
Sound snd ( soundname );
if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) {
if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
Config cfg ( "qpe" );
cfg. setGroup ( "Volume" );
int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
if ( volalarm < 0 )
volalarm = 0;
else if ( volalarm > 100 )
volalarm = 100;
volalarm |= ( volalarm << 8 );
@@ -1924,75 +1943,91 @@ bool Zaurus::setSoftSuspend ( bool soft )
if ( soft )
sources &= ~APM_EVT_POWER_BUTTON;
else
sources |= APM_EVT_POWER_BUTTON;
if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources
res = true;
else
perror ( "APM_IOCGEVTSRC" );
}
else
perror ( "APM_IOCGEVTSRC" );
::close ( fd );
}
else
perror ( "/dev/apm_bios or /dev/misc/apm_bios" );
return res;
}
bool Zaurus::setDisplayBrightness ( int bright )
{
-// FIXME The C7x0 have a proc-interface (/proc/drivers/corgi-bl) which
-// is nice to use. Currently it exposes 16+1 levels. Implement this!
-// (or wait for kergoth unifying the interfaces in the OpenZaurus kernel.)
- bool res = false;
- int fd;
-
- if ( bright > 255 )
- bright = 255;
- if ( bright < 0 )
- bright = 0;
-
- if (m_embedix) {
- if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) {
- int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus
- if ( bright && !bl )
- bl = 1;
- res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 );
- ::close ( fd );
- }
- } else {
-#define FB_BACKLIGHT_SET_BRIGHTNESS _IOW('F', 1, u_int) /* set brightness */
- if (( fd = ::open ( "/dev/fb0", O_WRONLY )) >= 0 ) {
- res = ( ::ioctl ( fd , FB_BACKLIGHT_SET_BRIGHTNESS, bright ) == 0 );
- ::close ( fd );
- }
- }
- return res;
+ bool res = false;
+ int fd;
+
+ if ( bright > 255 ) bright = 255;
+ if ( bright < 0 ) bright = 0;
+
+ if ( m_embedix )
+ {
+ if ( d->m_model == Model_Zaurus_SLC7x0 )
+ {
+ // special treatment for devices with the corgi backlight interface
+ if (( fd = ::open ( "/proc/driver/fl/corgi-bl", O_WRONLY )) >= 0 )
+ {
+ if ( bright > 0x11 ) bright = 0x11;
+ char writeCommand[100];
+ const int count = sprintf( writeCommand, "0x%x\n", bright );
+ res = ( ::write ( fd, writeCommand, count ) != -1 );
+ ::close ( fd );
+ }
+ return res;
+ }
+ else
+ {
+ // standard treatment for devices with the dumb embedix frontlight interface
+ if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) {
+ int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus
+ if ( bright && !bl )
+ bl = 1;
+ res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 );
+ ::close ( fd );
+ }
+ }
+ }
+ else
+ {
+ // special treatment for the OpenZaurus unified interface
+ #define FB_BACKLIGHT_SET_BRIGHTNESS _IOW('F', 1, u_int) /* set brightness */
+ if (( fd = ::open ( "/dev/fb0", O_WRONLY )) >= 0 ) {
+ res = ( ::ioctl ( fd , FB_BACKLIGHT_SET_BRIGHTNESS, bright ) == 0 );
+ ::close ( fd );
+ }
+ }
+ return res;
}
bool Zaurus::suspend ( )
{
qDebug("ODevice::suspend");
if ( !isQWS( ) ) // only qwsserver is allowed to suspend
return false;
if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices
return false;
bool res = false;
struct timeval tvs, tvn;
::gettimeofday ( &tvs, 0 );
::sync ( ); // flush fs caches
res = ( ::system ( "apm --suspend" ) == 0 );
// This is needed because the iPAQ apm implementation is asynchronous and we
// can not be sure when exactly the device is really suspended
// This can be deleted as soon as a stable familiar with a synchronous apm implementation exists.
if ( res ) {
@@ -2052,53 +2087,84 @@ ODirection Zaurus::direction ( ) const
} else {
retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION);
::close (handle);
if (retval == 2 )
dir = CCW;
else
dir = CW;
}
break;
case Model_Zaurus_SLA300:
case Model_Zaurus_SLB600:
case Model_Zaurus_SL5500:
case Model_Zaurus_SL5000:
default:
dir = d-> m_direction;
break;
}
return dir;
}
int Zaurus::displayBrightnessResolution ( ) const
{
if (m_embedix)
- return 5;
+ return d->m_model == Model_Zaurus_SLC7x0 ? 18 : 5;
else
return 256;
}
+bool Zaurus::hasHingeSensor() const
+{
+ return d->m_model == Model_Zaurus_SLC7x0;
+}
+
+OHingeStatus Zaurus::readHingeSensor()
+{
+ int handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK);
+ if (handle == -1)
+ {
+ qWarning("Zaurus::readHingeSensor() - failed (%s)", "unknown reason" ); //FIXME: use strerror
+ return CASE_UNKNOWN;
+ }
+ else
+ {
+ int retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION);
+ ::close (handle);
+ if ( retval == CASE_CLOSED || retval == CASE_PORTRAIT || retval == CASE_LANDSCAPE )
+ {
+ qDebug( "Zaurus::readHingeSensor() - result = %d", retval );
+ return static_cast<OHingeStatus>( retval );
+ }
+ else
+ {
+ qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" );
+ return CASE_UNKNOWN;
+ }
+ }
+}
+
+
/**************************************************
*
* SIMpad
*
**************************************************/
void SIMpad::init ( )
{
d-> m_vendorstr = "SIEMENS";
d-> m_vendor = Vendor_SIEMENS;
QFile f ( "/proc/hal/model" );
//TODO Implement model checking
//FIXME For now we assume an SL4
d-> m_modelstr = "SL4";
d-> m_model = Model_SIMpad_SL4;
switch ( d-> m_model ) {
default:
d-> m_rotation = Rot0;
d-> m_direction = CCW;
d-> m_holdtime = 1000; // 1000ms