summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/device/odevice_ramses.cpp
authormickeyl <mickeyl>2004-01-13 15:21:40 (UTC)
committer mickeyl <mickeyl>2004-01-13 15:21:40 (UTC)
commitaf79bda4c7e51f46abe67124f9c06126eaebb59d (patch) (unidiff)
tree4e9ad77ec4b2bb3d66ac6553d0a225b0b18f2140 /libopie2/opiecore/device/odevice_ramses.cpp
parent24eb97ec5cda3d72c3541fd120568b8d937025f8 (diff)
downloadopie-af79bda4c7e51f46abe67124f9c06126eaebb59d.zip
opie-af79bda4c7e51f46abe67124f9c06126eaebb59d.tar.gz
opie-af79bda4c7e51f46abe67124f9c06126eaebb59d.tar.bz2
- split odevice into dedicated files and classes, it has getting much too large
- merge odevice into libopie2 - merge oprocctrl and oprocess into libopie2
Diffstat (limited to 'libopie2/opiecore/device/odevice_ramses.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_ramses.cpp317
1 files changed, 317 insertions, 0 deletions
diff --git a/libopie2/opiecore/device/odevice_ramses.cpp b/libopie2/opiecore/device/odevice_ramses.cpp
new file mode 100644
index 0000000..a90c3a0
--- a/dev/null
+++ b/libopie2/opiecore/device/odevice_ramses.cpp
@@ -0,0 +1,317 @@
1/*
2                 This file is part of the Opie Project
3              Copyright (C) The Opie Team <opie-devel@handhelds.org>
4 =.
5 .=l.
6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details.
21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include "odevice.h"
31
32/* QT */
33#include <qapplication.h>
34#include <qfile.h>
35#include <qtextstream.h>
36#include <qwindowsystem_qws.h>
37
38/* OPIE */
39#include <qpe/config.h>
40#include <qpe/resource.h>
41#include <qpe/sound.h>
42#include <qpe/qcopenvelope_qws.h>
43
44/* STD */
45#include <fcntl.h>
46#include <math.h>
47#include <stdlib.h>
48#include <signal.h>
49#include <sys/ioctl.h>
50#include <sys/time.h>
51#include <unistd.h>
52#ifndef QT_NO_SOUND
53#include <linux/soundcard.h>
54#endif
55
56#ifndef ARRAY_SIZE
57#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
58#endif
59
60// _IO and friends are only defined in kernel headers ...
61
62#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
63
64#define OD_IO(type,number) OD_IOC(0,type,number,0)
65#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size))
66#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size))
67#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size))
68
69using namespace Opie;
70
71class Ramses : public ODevice, public QWSServer::KeyboardFilter
72{
73 protected:
74 virtual void init();
75
76 public:
77 virtual bool setSoftSuspend( bool soft );
78 virtual bool suspend();
79
80 virtual bool setDisplayStatus( bool on );
81 virtual bool setDisplayBrightness( int b );
82 virtual int displayBrightnessResolution() const;
83 virtual bool setDisplayContrast( int b );
84 virtual int displayContrastResolution() const;
85
86 protected:
87 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
88 virtual void timerEvent ( QTimerEvent *te );
89
90 int m_power_timer;
91};
92
93struct r_button {
94 uint model;
95 Qt::Key code;
96 char *utext;
97 char *pix;
98 char *fpressedservice;
99 char *fpressedaction;
100 char *fheldservice;
101 char *fheldaction;
102} ramses_buttons [] = {
103 { Model_Ramses_MNCI,
104 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
105 "devicebuttons/z_menu",
106 "QPE/TaskBar", "toggleMenu()",
107 "QPE/TaskBar", "toggleStartMenu()" },
108 { Model_Ramses_MNCI,
109 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
110 "devicebuttons/ipaq_home",
111 "QPE/Launcher", "home()",
112 "buttonsettings", "raise()" },
113};
114
115void Ramses::init()
116{
117 d->m_vendorstr = "M und N";
118 d->m_vendor = Vendor_MundN;
119
120 QFile f("/proc/sys/board/ramses");
121
122 d->m_modelstr = "Ramses";
123 d->m_model = Model_Ramses_MNCI;
124
125 d->m_rotation = Rot0;
126 d->m_holdtime = 1000;
127
128 f.setName("/etc/oz_version");
129
130 if (f.open(IO_ReadOnly)) {
131 d->m_systemstr = "OpenEmbedded/Ramses";
132 d->m_system = System_OpenZaurus;
133
134 QTextStream ts(&f);
135 ts.setDevice(&f);
136 d->m_sysverstr = ts.readLine();
137 f.close();
138 }
139
140 m_power_timer = 0;
141
142#ifdef QT_QWS_ALLOW_OVERCLOCK
143#warning *** Overclocking enabled - this may fry your hardware - you have been warned ***
144#define OC(x...) x
145#else
146#define OC(x...)
147#endif
148
149 // This table is true for a Intel XScale PXA 255
150
151 d->m_cpu_frequencies->append("99000"); // mem= 99, run= 99, turbo= 99, PXbus= 50
152OC(d->m_cpu_frequencies->append("118000"); ) // mem=118, run=118, turbo=118, PXbus= 59 OC'd mem
153 d->m_cpu_frequencies->append("199100"); // mem= 99, run=199, turbo=199, PXbus= 99
154OC(d->m_cpu_frequencies->append("236000"); ) // mem=118, run=236, turbo=236, PXbus=118 OC'd mem
155 d->m_cpu_frequencies->append("298600"); // mem= 99, run=199, turbo=298, PXbus= 99
156OC(d->m_cpu_frequencies->append("354000"); ) // mem=118, run=236, turbo=354, PXbus=118 OC'd mem
157 d->m_cpu_frequencies->append("398099"); // mem= 99, run=199, turbo=398, PXbus= 99
158 d->m_cpu_frequencies->append("398100"); // mem= 99, run=398, turbo=398, PXbus=196
159OC(d->m_cpu_frequencies->append("471000"); ) // mem=118, run=471, turbo=471, PXbus=236 OC'd mem/core/bus
160
161}
162
163bool Ramses::filter(int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat)
164{
165 Q_UNUSED( keycode );
166 Q_UNUSED( modifiers );
167 Q_UNUSED( isPress );
168 Q_UNUSED( autoRepeat );
169 return false;
170}
171
172void Ramses::timerEvent(QTimerEvent *)
173{
174 killTimer(m_power_timer);
175 m_power_timer = 0;
176 QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, true, false);
177 QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, false, false);
178}
179
180
181bool Ramses::setSoftSuspend(bool soft)
182{
183 qDebug("Ramses::setSoftSuspend(%d)", soft);
184#if 0
185 bool res = false;
186 int fd;
187
188 if (((fd = ::open("/dev/apm_bios", O_RDWR)) >= 0) ||
189 ((fd = ::open("/dev/misc/apm_bios",O_RDWR)) >= 0)) {
190
191 int sources = ::ioctl(fd, APM_IOCGEVTSRC, 0); // get current event sources
192
193 if (sources >= 0) {
194 if (soft)
195 sources &= ~APM_EVT_POWER_BUTTON;
196 else
197 sources |= APM_EVT_POWER_BUTTON;
198
199 if (::ioctl(fd, APM_IOCSEVTSRC, sources) >= 0) // set new event sources
200 res = true;
201 else
202 perror("APM_IOCGEVTSRC");
203 }
204 else
205 perror("APM_IOCGEVTSRC");
206
207 ::close(fd);
208 }
209 else
210 perror("/dev/apm_bios or /dev/misc/apm_bios");
211
212 return res;
213#else
214 return true;
215#endif
216}
217
218bool Ramses::suspend()
219{
220 qDebug("Ramses::suspend");
221 return false;
222}
223
224/**
225* This sets the display on or off
226*/
227bool Ramses::setDisplayStatus(bool on)
228{
229 qDebug("Ramses::setDisplayStatus(%d)", on);
230#if 0
231 bool res = false;
232 int fd;
233
234 if ((fd = ::open ("/dev/fb/0", O_RDWR)) >= 0) {
235 res = (::ioctl(fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN) == 0);
236 ::close(fd);
237 }
238 return res;
239#else
240 return true;
241#endif
242}
243
244
245/*
246* We get something between 0..255 into us
247*/
248bool Ramses::setDisplayBrightness(int bright)
249{
250 qDebug("Ramses::setDisplayBrightness(%d)", bright);
251 bool res = false;
252 int fd;
253
254 // pwm1 brighness: 20 steps 500..0 (dunkel->hell)
255
256 if (bright > 255 )
257 bright = 255;
258 if (bright < 0)
259 bright = 0;
260
261 // Turn backlight completely off
262 if ((fd = ::open("/proc/sys/board/lcd_backlight", O_WRONLY)) >= 0) {
263 char writeCommand[10];
264 const int count = sprintf(writeCommand, "%d\n", bright ? 1 : 0);
265 res = (::write(fd, writeCommand, count) != -1);
266 ::close(fd);
267 }
268
269 // scale backlight brightness to hardware
270 bright = 500-(bright * 500 / 255);
271 if ((fd = ::open("/proc/sys/board/pwm1", O_WRONLY)) >= 0) {
272 qDebug(" %d ->pwm1", bright);
273 char writeCommand[100];
274 const int count = sprintf(writeCommand, "%d\n", bright);
275 res = (::write(fd, writeCommand, count) != -1);
276 ::close(fd);
277 }
278 return res;
279}
280
281
282int Ramses::displayBrightnessResolution() const
283{
284 return 32;
285}
286
287bool Ramses::setDisplayContrast(int contr)
288{
289 qDebug("Ramses::setDisplayContrast(%d)", contr);
290 bool res = false;
291 int fd;
292
293 // pwm0 contrast: 20 steps 79..90 (dunkel->hell)
294
295 if (contr > 255 )
296 contr = 255;
297 if (contr < 0)
298 contr = 0;
299 contr = 90 - (contr * 20 / 255);
300
301 if ((fd = ::open("/proc/sys/board/pwm0", O_WRONLY)) >= 0) {
302 qDebug(" %d ->pwm0", contr);
303 char writeCommand[100];
304 const int count = sprintf(writeCommand, "%d\n", contr);
305 res = (::write(fd, writeCommand, count) != -1);
306 res = true;
307 ::close(fd);
308 }
309 return res;
310}
311
312
313int Ramses::displayContrastResolution() const
314{
315 return 20;
316}
317