summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/device
Side-by-side diff
Diffstat (limited to 'libopie2/opiecore/device') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_zaurus.cpp73
-rw-r--r--libopie2/opiecore/device/odevice_zaurus.h6
2 files changed, 71 insertions, 8 deletions
diff --git a/libopie2/opiecore/device/odevice_zaurus.cpp b/libopie2/opiecore/device/odevice_zaurus.cpp
index 33d5cd6..a75f566 100644
--- a/libopie2/opiecore/device/odevice_zaurus.cpp
+++ b/libopie2/opiecore/device/odevice_zaurus.cpp
@@ -35,24 +35,26 @@
#include <qpe/config.h>
#include <qpe/sound.h>
/* QT */
#include <qapplication.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qwindowsystem_qws.h>
#include <qcopchannel_qws.h>
/* STD */
+#include <string.h>
+#include <errno.h>
#include <fcntl.h>
#include <math.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <unistd.h>
#ifndef QT_NO_SOUND
#include <linux/soundcard.h>
#endif
using namespace Opie::Core;
@@ -295,26 +297,28 @@ void Zaurus::initButtons()
struct z_button * pz_buttons;
int buttoncount;
switch ( d->m_model )
{
case Model_Zaurus_SL6000:
pz_buttons = z_buttons_6000;
buttoncount = ARRAY_SIZE(z_buttons_6000);
break;
case Model_Zaurus_SLC3100: // fallthrough
case Model_Zaurus_SLC3000: // fallthrough
case Model_Zaurus_SLC1000: // fallthrough
case Model_Zaurus_SLC7x0:
- if ( isQWS( ) ) {
- addPreHandler(this); // hinge-sensor-handler
+ if ( isQWS( ) )
+ { // setup hinge sensor stuff
+ addPreHandler(this);
+ initHingeSensor();
}
pz_buttons = z_buttons_c700;
buttoncount = ARRAY_SIZE(z_buttons_c700);
break;
default:
pz_buttons = z_buttons;
buttoncount = ARRAY_SIZE(z_buttons);
break;
}
for ( int i = 0; i < buttoncount; i++ ) {
struct z_button *zb = pz_buttons + i;
@@ -653,31 +657,84 @@ OHingeStatus Zaurus::readHingeSensor() const
qDebug( "Zaurus::readHingeSensor() - result = %d", retval );
return static_cast<OHingeStatus>( retval );
}
else
{
qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" );
return CASE_UNKNOWN;
}
}
}
else
{
- // corgi keyboard is event source 0 in OZ kernel 2.6
+ /*
+ * The corgi keyboard is event source 0 in OZ kernel 2.6.
+ * Hinge status is reported via Input System Switchs 0 and 1 like that:
+ *
+ * -------------------------
+ * | SW0 | SW1 | CASE |
+ * |-----|-----|-----------|
+ * | 0 0 Landscape |
+ * | 0 1 Portrait |
+ * | 1 0 Unknown |
+ * | 1 1 Closed |
+ * -------------------------
+ */
OInputDevice* keyboard = OInputSystem::instance()->device( "event0" );
- if ( keyboard && keyboard->isHeld( OInputDevice::Key_KP0 ) ) return CASE_LANDSCAPE;
- else if ( keyboard && keyboard->isHeld( OInputDevice::Key_KP1 ) ) return CASE_PORTRAIT;
- else if ( keyboard && keyboard->isHeld( OInputDevice::Key_KP2 ) ) return CASE_CLOSED;
- qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" );
- return CASE_UNKNOWN;
+ bool switch0 = true;
+ bool switch1 = false;
+ if ( keyboard )
+ {
+ switch0 = keyboard->isHeld( OInputDevice::Switch0 );
+ switch1 = keyboard->isHeld( OInputDevice::Switch1 );
+ }
+ if ( switch0 )
+ {
+ return switch1 ? CASE_CLOSED : CASE_UNKNOWN;
+ }
+ else
+ {
+ return switch1 ? CASE_PORTRAIT : CASE_LANDSCAPE;
+ }
+ }
+}
+
+void Zaurus::initHingeSensor()
+{
+ if ( m_embedix ) return;
+
+ m_hinge.setName( "/dev/input/event0" );
+ if ( !m_hinge.open( IO_ReadOnly ) )
+ {
+ qDebug( "Zaurus::init() - Couldn't open /dev/input/event0 for read (%s)", strerror( errno ) );
+ return;
+ }
+
+ QSocketNotifier* sn = new QSocketNotifier( m_hinge.handle(), QSocketNotifier::Read, this );
+ QObject::connect( sn, SIGNAL(activated(int)), this, SLOT(hingeSensorTriggered()) );
+}
+
+void Zaurus::hingeSensorTriggered()
+{
+ qDebug( "Zaurus::hingeSensorTriggered() - got event" );
+ struct input_event e;
+ if ( ::read( m_hinge.handle(), &e, sizeof e ) > 0 )
+ {
+ qDebug( "Zaurus::hingeSensorTriggered() - event has type %d, code %d, value %d", e.type, e.code, e.value );
+ if ( e.type != EV_SW ) return;
+ if ( readHingeSensor() != CASE_UNKNOWN )
+ {
+ qDebug( "Zaurus::hingeSensorTriggered() - got valid switch event, calling rotateDefault()" );
+ QCopChannel::send( "QPE/Rotation", "rotateDefault()" );
+ }
}
}
/*
* Take code from iPAQ device.
* That way we switch the cursor directions depending on status of hinge sensor, eg. hardware direction.
* I hope that is ok - Alwin
*/
bool Zaurus::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
{
int newkeycode = keycode;
diff --git a/libopie2/opiecore/device/odevice_zaurus.h b/libopie2/opiecore/device/odevice_zaurus.h
index 677e29f..bf30bc6 100644
--- a/libopie2/opiecore/device/odevice_zaurus.h
+++ b/libopie2/opiecore/device/odevice_zaurus.h
@@ -24,24 +24,25 @@
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef ODEVICE_ZAURUS
#define ODEVICE_ZAURUS
#include "odevice_abstractmobiledevice.h"
/* QT */
+#include <qfile.h>
#include <qwindowsystem_qws.h>
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif
// _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))
@@ -90,24 +91,28 @@
#define FB_BLANK_UNBLANK 0
#define FB_BLANK_POWERDOWN 4
namespace Opie {
namespace Core {
namespace Internal {
class Zaurus : public OAbstractMobileDevice, public QWSServer::KeyboardFilter
{
protected:
virtual void init(const QString&);
virtual void initButtons();
+ void initHingeSensor();
+
+ protected slots:
+ void hingeSensorTriggered();
public:
virtual bool setDisplayBrightness( int b );
virtual bool setDisplayStatus( bool on );
virtual int displayBrightnessResolution() const;
virtual void playAlarmSound();
virtual void playKeySound();
virtual void playTouchSound();
virtual QValueList <OLed> ledList() const;
virtual QValueList <OLedState> ledStateList ( OLed led ) const;
@@ -119,24 +124,25 @@ class Zaurus : public OAbstractMobileDevice, public QWSServer::KeyboardFilter
virtual Transformation rotation() const;
virtual ODirection direction() const;
virtual bool suspend();
protected:
virtual void buzzer( int snd );
virtual bool filter( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
QString m_backlightdev;
OLedState m_leds[1];
bool m_embedix;
+ QFile m_hinge;
};
struct z_button {
Qt::Key code;
char *utext;
char *pix;
char *fpressedservice;
char *fpressedaction;
char *fheldservice;
char *fheldaction;
};
}