summaryrefslogtreecommitdiff
path: root/libopie/odevice.cpp
Unidiff
Diffstat (limited to 'libopie/odevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp14
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
@@ -9,68 +9,70 @@
9 This library is distributed in the hope that it will be useful, 9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <stdlib.h> 20#include <stdlib.h>
21#include <unistd.h> 21#include <unistd.h>
22#include <fcntl.h> 22#include <fcntl.h>
23#include <sys/ioctl.h> 23#include <sys/ioctl.h>
24#include <signal.h> 24#include <signal.h>
25#include <sys/time.h> 25#include <sys/time.h>
26#include <linux/soundcard.h> 26#include <linux/soundcard.h>
27#include <math.h> 27#include <math.h>
28 28
29#include <qapplication.h> 29#include <qapplication.h>
30 30
31#include <qfile.h> 31#include <qfile.h>
32#include <qtextstream.h> 32#include <qtextstream.h>
33#include <qpe/sound.h> 33#include <qpe/sound.h>
34#include <qpe/resource.h> 34#include <qpe/resource.h>
35#include <qpe/config.h> 35#include <qpe/config.h>
36 36
37#include "odevice.h" 37#include "odevice.h"
38 38
39// _IO and friends are only defined in kernel headers ... 39// _IO and friends are only defined in kernel headers ...
40 40
41#define OD_IO(type,area,number,args) (( type << 30 ) | ( area << 8 ) | ( number ) | ( sizeof( args ) << 16 )) 41#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
42#define OD_IOW(area,number,args) OD_IO(1,area,number,args) 42
43#define OD_IOR(area,number,args) OD_IO(2,area,number,args) 43#define OD_IO(type,number) OD_IOC(0,type,number,0)
44#define OD_IORW(area,number,args) OD_IO(3,area,number,args) 44#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size))
45#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size))
46#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size))
45 47
46 48
47class ODeviceData { 49class ODeviceData {
48public: 50public:
49 QString m_vendorstr; 51 QString m_vendorstr;
50 OVendor m_vendor; 52 OVendor m_vendor;
51 53
52 QString m_modelstr; 54 QString m_modelstr;
53 OModel m_model; 55 OModel m_model;
54 56
55 QString m_systemstr; 57 QString m_systemstr;
56 OSystem m_system; 58 OSystem m_system;
57 59
58 QString m_sysverstr; 60 QString m_sysverstr;
59 61
60 OLedState m_leds [4]; // just for convenience ... 62 OLedState m_leds [4]; // just for convenience ...
61}; 63};
62 64
63class ODeviceIPAQ : public ODevice { 65class ODeviceIPAQ : public ODevice {
64protected: 66protected:
65 virtual void init ( ); 67 virtual void init ( );
66 68
67public: 69public:
68 virtual bool setPowerButtonHandler ( PowerButtonHandler h ); 70 virtual bool setPowerButtonHandler ( PowerButtonHandler h );
69 71
70 virtual bool setDisplayBrightness ( int b ); 72 virtual bool setDisplayBrightness ( int b );
71 virtual int displayBrightnessResolution ( ) const; 73 virtual int displayBrightnessResolution ( ) const;
72 74
73 virtual void alarmSound ( ); 75 virtual void alarmSound ( );
74 76
75 virtual uint hasLeds ( ) const; 77 virtual uint hasLeds ( ) const;
76 virtual OLedState led ( uint which ) const; 78 virtual OLedState led ( uint which ) const;
@@ -127,107 +129,107 @@ ODevice *ODevice::inst ( )
127 **************************************************/ 129 **************************************************/
128 130
129 131
130ODevice::ODevice ( ) 132ODevice::ODevice ( )
131{ 133{
132 d = new ODeviceData; 134 d = new ODeviceData;
133 135
134 d-> m_modelstr = "Unknown"; 136 d-> m_modelstr = "Unknown";
135 d-> m_model = OMODEL_Unknown; 137 d-> m_model = OMODEL_Unknown;
136 d-> m_vendorstr = "Unkown"; 138 d-> m_vendorstr = "Unkown";
137 d-> m_vendor = OVENDOR_Unknown; 139 d-> m_vendor = OVENDOR_Unknown;
138 d-> m_systemstr = "Unkown"; 140 d-> m_systemstr = "Unkown";
139 d-> m_system = OSYSTEM_Unknown; 141 d-> m_system = OSYSTEM_Unknown;
140 d-> m_sysverstr = "0.0"; 142 d-> m_sysverstr = "0.0";
141} 143}
142 144
143void ODevice::init ( ) 145void ODevice::init ( )
144{ 146{
145} 147}
146 148
147ODevice::~ODevice ( ) 149ODevice::~ODevice ( )
148{ 150{
149 delete d; 151 delete d;
150} 152}
151 153
152bool ODevice::setPowerButtonHandler ( ODevice::PowerButtonHandler ) 154bool ODevice::setPowerButtonHandler ( ODevice::PowerButtonHandler )
153{ 155{
154 return false; 156 return false;
155} 157}
156 158
157//#include <linux/apm_bios.h> 159//#include <linux/apm_bios.h>
158 160
159#define APM_IOC_SUSPEND OD_IO( 0, 'A', 2, 0 ) 161#define APM_IOC_SUSPEND OD_IO( 'A', 2 )
160 162
161 163
162bool ODevice::suspend ( ) 164bool ODevice::suspend ( )
163{ 165{
164 if ( d-> m_model == OMODEL_Unknown ) // better don't suspend in qvfb / on unkown devices 166 if ( d-> m_model == OMODEL_Unknown ) // better don't suspend in qvfb / on unkown devices
165 return false; 167 return false;
166 168
167 int fd; 169 int fd;
168 bool res = false; 170 bool res = false;
169 171
170 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || 172 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
171 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { 173 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
172 struct timeval tvs, tvn; 174 struct timeval tvs, tvn;
173 175
174 ::signal ( SIGTSTP, SIG_IGN );// we don't want to be stopped 176 ::signal ( SIGTSTP, SIG_IGN );// we don't want to be stopped
175 ::gettimeofday ( &tvs, 0 ); 177 ::gettimeofday ( &tvs, 0 );
176 178
177 ::sync ( ); // flush fs caches 179 ::sync ( ); // flush fs caches
178 180
179 res = ( ::ioctl ( fd, APM_IOC_SUSPEND, 0 ) == 0 ); // tell the kernel to "start" suspending 181 res = ( ::ioctl ( fd, APM_IOC_SUSPEND, 0 ) == 0 ); // tell the kernel to "start" suspending
180 182
181 if ( res ) { 183 if ( res ) {
182 ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in our process group 184 ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in our process group
183 185
184 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed 186 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
185 ::usleep ( 200 * 1000 ); 187 ::usleep ( 200 * 1000 );
186 ::gettimeofday ( &tvn, 0 ); 188 ::gettimeofday ( &tvn, 0 );
187 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); 189 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
188 190
189 ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group 191 ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group
190 } 192 }
191 193
192 ::close ( fd ); 194 ::close ( fd );
193 ::signal ( SIGTSTP, SIG_DFL ); 195 ::signal ( SIGTSTP, SIG_DFL );
194 } 196 }
195 197
196 return res; 198 return res;
197} 199}
198 200
199//#include <linux/fb.h> better not rely on kernel headers in userspace ... 201//#include <linux/fb.h> better not rely on kernel headers in userspace ...
200 202
201#define FBIOBLANK OD_IO( 0, 'F', 0x11, 0 ) // 0x4611 203#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611
202 204
203/* VESA Blanking Levels */ 205/* VESA Blanking Levels */
204#define VESA_NO_BLANKING 0 206#define VESA_NO_BLANKING 0
205#define VESA_VSYNC_SUSPEND 1 207#define VESA_VSYNC_SUSPEND 1
206#define VESA_HSYNC_SUSPEND 2 208#define VESA_HSYNC_SUSPEND 2
207#define VESA_POWERDOWN 3 209#define VESA_POWERDOWN 3
208 210
209 211
210bool ODevice::setDisplayStatus ( bool on ) 212bool ODevice::setDisplayStatus ( bool on )
211{ 213{
212 if ( d-> m_model == OMODEL_Unknown ) 214 if ( d-> m_model == OMODEL_Unknown )
213 return false; 215 return false;
214 216
215 bool res = false; 217 bool res = false;
216 int fd; 218 int fd;
217 219
218 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { 220 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) {
219 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); 221 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 );
220 ::close ( fd ); 222 ::close ( fd );
221 } 223 }
222 return res; 224 return res;
223} 225}
224 226
225bool ODevice::setDisplayBrightness ( int ) 227bool ODevice::setDisplayBrightness ( int )
226{ 228{
227 return false; 229 return false;
228} 230}
229 231
230int ODevice::displayBrightnessResolution ( ) const 232int ODevice::displayBrightnessResolution ( ) const
231{ 233{
232 return 16; 234 return 16;
233} 235}