00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "odevice_abstractmobiledevice.h"
00031
00032
00033 #include <qcopchannel_qws.h>
00034
00035
00036 #include <sys/time.h>
00037 #include <sys/ioctl.h>
00038 #include <time.h>
00039 #include <fcntl.h>
00040 #include <unistd.h>
00041 #include <stdlib.h>
00042
00043 namespace Opie {
00044 namespace Core {
00045 OAbstractMobileDevice::OAbstractMobileDevice()
00046 : m_timeOut( 1500 )
00047 {}
00048
00056 void OAbstractMobileDevice::setAPMTimeOut( int time ) {
00057 m_timeOut = time;
00058 }
00059
00060
00061 bool OAbstractMobileDevice::suspend() {
00062 if ( !isQWS( ) )
00063 return false;
00064
00065 bool res = false;
00066 QCopChannel::send( "QPE/System", "aboutToSuspend()" );
00067
00068 struct timeval tvs, tvn;
00069 ::gettimeofday ( &tvs, 0 );
00070
00071 ::sync();
00072 res = ( ::system ( "apm --suspend" ) == 0 );
00073
00074
00075
00076
00077
00078 if ( res ) {
00079 do {
00080 ::usleep ( 200 * 1000 );
00081 ::gettimeofday ( &tvn, 0 );
00082 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < m_timeOut );
00083 }
00084
00085 QCopChannel::send( "QPE/System", "returnFromSuspend()" );
00086
00087 return res;
00088 }
00089
00090
00091
00092
00093 #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
00094 #define OD_IO(type,number) OD_IOC(0,type,number,0)
00095
00096 #define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611
00097
00098
00099 #define VESA_NO_BLANKING 0
00100 #define VESA_VSYNC_SUSPEND 1
00101 #define VESA_HSYNC_SUSPEND 2
00102 #define VESA_POWERDOWN 3
00103
00104 bool OAbstractMobileDevice::setDisplayStatus ( bool on ) {
00105 bool res = false;
00106 int fd;
00107
00108 #ifdef QT_QWS_DEVFS
00109 if (( fd = ::open ( "/dev/fb/0", O_RDWR )) >= 0 ) {
00110 #else
00111 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) {
00112 #endif
00113 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 );
00114 ::close ( fd );
00115 }
00116
00117 return res;
00118 }
00119 }
00120 }