-rw-r--r-- | libopie/odevice.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index 6e3f114..9871e80 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp @@ -17,52 +17,54 @@ Boston, MA 02111-1307, USA. */ #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/ioctl.h> #include <signal.h> #include <sys/time.h> #include <linux/soundcard.h> #include <math.h> #include <qapplication.h> #include <qfile.h> #include <qtextstream.h> #include <qpe/sound.h> #include <qpe/resource.h> #include <qpe/config.h> #include "odevice.h" // _IO and friends are only defined in kernel headers ... -#define OD_IO(type,area,number,args) (( type << 30 ) | ( area << 8 ) | ( number ) | ( sizeof( args ) << 16 )) -#define OD_IOW(area,number,args) OD_IO(1,area,number,args) -#define OD_IOR(area,number,args) OD_IO(2,area,number,args) -#define OD_IORW(area,number,args) OD_IO(3,area,number,args) +#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)) class ODeviceData { public: QString m_vendorstr; OVendor m_vendor; QString m_modelstr; OModel m_model; QString m_systemstr; OSystem m_system; QString m_sysverstr; OLedState m_leds [4]; // just for convenience ... }; class ODeviceIPAQ : public ODevice { protected: virtual void init ( ); public: virtual bool setPowerButtonHandler ( PowerButtonHandler h ); @@ -135,91 +137,91 @@ ODevice::ODevice ( ) d-> m_model = OMODEL_Unknown; d-> m_vendorstr = "Unkown"; d-> m_vendor = OVENDOR_Unknown; d-> m_systemstr = "Unkown"; d-> m_system = OSYSTEM_Unknown; d-> m_sysverstr = "0.0"; } void ODevice::init ( ) { } ODevice::~ODevice ( ) { delete d; } bool ODevice::setPowerButtonHandler ( ODevice::PowerButtonHandler ) { return false; } //#include <linux/apm_bios.h> -#define APM_IOC_SUSPEND OD_IO( 0, 'A', 2, 0 ) +#define APM_IOC_SUSPEND OD_IO( 'A', 2 ) bool ODevice::suspend ( ) { if ( d-> m_model == OMODEL_Unknown ) // better don't suspend in qvfb / on unkown devices return false; int fd; bool res = false; if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { struct timeval tvs, tvn; ::signal ( SIGTSTP, SIG_IGN ); // we don't want to be stopped ::gettimeofday ( &tvs, 0 ); ::sync ( ); // flush fs caches res = ( ::ioctl ( fd, APM_IOC_SUSPEND, 0 ) == 0 ); // tell the kernel to "start" suspending if ( res ) { ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in our process group do { // wait at most 1.5 sec: either suspend didn't work or the device resumed ::usleep ( 200 * 1000 ); ::gettimeofday ( &tvn, 0 ); } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group } ::close ( fd ); ::signal ( SIGTSTP, SIG_DFL ); } return res; } //#include <linux/fb.h> better not rely on kernel headers in userspace ... -#define FBIOBLANK OD_IO( 0, 'F', 0x11, 0 ) // 0x4611 +#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 /* VESA Blanking Levels */ #define VESA_NO_BLANKING 0 #define VESA_VSYNC_SUSPEND 1 #define VESA_HSYNC_SUSPEND 2 #define VESA_POWERDOWN 3 bool ODevice::setDisplayStatus ( bool on ) { if ( d-> m_model == OMODEL_Unknown ) return false; bool res = false; int fd; if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); ::close ( fd ); } return res; } bool ODevice::setDisplayBrightness ( int ) |