summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/device/odevice_abstractmobiledevice.cpp
Unidiff
Diffstat (limited to 'libopie2/opiecore/device/odevice_abstractmobiledevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_abstractmobiledevice.cpp119
1 files changed, 119 insertions, 0 deletions
diff --git a/libopie2/opiecore/device/odevice_abstractmobiledevice.cpp b/libopie2/opiecore/device/odevice_abstractmobiledevice.cpp
new file mode 100644
index 0000000..f3f6af5
--- a/dev/null
+++ b/libopie2/opiecore/device/odevice_abstractmobiledevice.cpp
@@ -0,0 +1,119 @@
1/*
2                 This file is part of the Opie Project
3              Copyright (C) 2004, 2005 Holger Hans Peter Freyther <freyther@handhelds.org>
4 Copyright (C) 2004, 2005 Michael 'mickey' Lauer <mickeyl@handhelds.org>
5 Copyright (C) 2002, 2003 Robert Griebl <sandman@handhelds.org>
6
7
8 =.
9 .=l.
10           .>+-=
11 _;:,     .>    :=|. This program is free software; you can
12.> <`_,   >  .   <= redistribute it and/or modify it under
13:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
14.="- .-=="i,     .._ License as published by the Free Software
15 - .   .-<_>     .<> Foundation; either version 2 of the License,
16     ._= =}       : or (at your option) any later version.
17    .%`+i>       _;_.
18    .i_,=:_.      -<s. This program is distributed in the hope that
19     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
20    : ..    .:,     . . . without even the implied warranty of
21    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
22  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
23..}^=.=       =       ; Library General Public License for more
24++=   -.     .`     .: details.
25 :     =  ...= . :.=-
26 -.   .:....=;==+<; You should have received a copy of the GNU
27  -_. . .   )=.  = Library General Public License along with
28    --        :-=` this library; see the file COPYING.LIB.
29 If not, write to the Free Software Foundation,
30 Inc., 59 Temple Place - Suite 330,
31 Boston, MA 02111-1307, USA.
32*/
33
34#include "odevice_abstractmobiledevice.h"
35
36#include <sys/time.h>
37#include <sys/ioctl.h>
38
39#include <time.h>
40#include <fcntl.h>
41#include <unistd.h>
42#include <stdlib.h>
43
44namespace Opie {
45namespace Core {
46OAbstractMobileDevice::OAbstractMobileDevice()
47 : m_timeOut( 1500 )
48{}
49
50/**
51 * @short Time to wait for the asynchronos APM implementation to suspend
52 *
53 * Milli Seconds to wait before returning from the suspend method.
54 * This is needed due asynchrnonus implementations of the APM bios.
55 *
56 */
57void OAbstractMobileDevice::setAPMTimeOut( int time ) {
58 m_timeOut = time;
59}
60
61
62bool OAbstractMobileDevice::suspend() {
63 if ( !isQWS( ) ) // only qwsserver is allowed to suspend
64 return false;
65
66 bool res = false;
67 ODevice::sendSuspendmsg();
68
69 struct timeval tvs, tvn;
70 ::gettimeofday ( &tvs, 0 );
71
72 ::sync(); // flush fs caches
73 res = ( ::system ( "apm --suspend" ) == 0 );
74
75 // This is needed because some apm implementations are asynchronous and we
76 // can not be sure when exactly the device is really suspended
77 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists.
78
79 if ( res ) {
80 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
81 ::usleep ( 200 * 1000 );
82 ::gettimeofday ( &tvn, 0 );
83 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < m_timeOut );
84 }
85
86 return res;
87}
88
89//#include <linux/fb.h> better not rely on kernel headers in userspace ...
90
91// _IO and friends are only defined in kernel headers ...
92#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
93#define OD_IO(type,number) OD_IOC(0,type,number,0)
94
95#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611
96
97/* VESA Blanking Levels */
98#define VESA_NO_BLANKING 0
99#define VESA_VSYNC_SUSPEND 1
100#define VESA_HSYNC_SUSPEND 2
101#define VESA_POWERDOWN 3
102
103bool OAbstractMobileDevice::setDisplayStatus ( bool on ) {
104 bool res = false;
105 int fd;
106
107#ifdef QT_QWS_DEVFS
108 if (( fd = ::open ( "/dev/fb/0", O_RDWR )) >= 0 ) {
109#else
110 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) {
111#endif
112 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 );
113 ::close ( fd );
114 }
115
116 return res;
117}
118}
119}