summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp136
-rw-r--r--libopie/odevice.h14
2 files changed, 113 insertions, 37 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index e24e043..bc09e92 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -142,5 +142,8 @@ public:
+ virtual bool hasHingeSensor() const;
+ virtual OHingeStatus readHingeSensor();
+
static bool isZaurus();
-
- // Does this break BC?
+
+ // Does this break BC?
virtual bool suspend ( );
@@ -535,3 +538,3 @@ 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
@@ -825,3 +828,3 @@ bool ODevice::hasLightSensor ( ) const
/**
- * @return a value from the light senso
+ * @return a value from the light sensor
*/
@@ -833,3 +836,3 @@ int ODevice::readLightSensor ( )
/**
- * @return the light sensor resolution whatever that is ;)
+ * @return the light sensor resolution
*/
@@ -841,2 +844,18 @@ int ODevice::lightSensorResolution ( ) const
/**
+ * @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
@@ -851,3 +870,3 @@ const QStrList &ODevice::allowedCpuFrequencies ( ) const
* Set desired CPU frequency
- *
+ *
* @param index index into d->m_cpu_frequencies of the frequency to be set
@@ -1784,3 +1803,3 @@ void Zaurus::buzzer ( int sound )
soundname = "alarm";
-
+
}
@@ -1947,29 +1966,45 @@ 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;
}
@@ -2075,3 +2110,3 @@ int Zaurus::displayBrightnessResolution ( ) const
if (m_embedix)
- return 5;
+ return d->m_model == Model_Zaurus_SLC7x0 ? 18 : 5;
else
@@ -2080,2 +2115,33 @@ int Zaurus::displayBrightnessResolution ( ) const
+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;
+ }
+ }
+}
+
+
/**************************************************
diff --git a/libopie/odevice.h b/libopie/odevice.h
index 8273761..ee0b0ec 100644
--- a/libopie/odevice.h
+++ b/libopie/odevice.h
@@ -145,2 +145,9 @@ enum ODirection {
+enum OHingeStatus {
+ CASE_CLOSED = 3,
+ CASE_PORTRAIT = 2,
+ CASE_LANDSCAPE = 0,
+ CASE_UNKNOWN = 1,
+};
+
/**
@@ -209,4 +216,4 @@ public:
-// input / output
- //FIXME playAlarmSound and al might be better -zecke
+ // input / output
+ //FIXME playAlarmSound and al might be better -zecke
virtual void alarmSound ( );
@@ -224,2 +231,5 @@ public:
+ virtual bool hasHingeSensor ( ) const;
+ virtual OHingeStatus readHingeSensor ( );
+
const QStrList &allowedCpuFrequencies() const;