summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/device/odevice_yopy.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_yopy.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_yopy.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_yopy.cpp212
1 files changed, 212 insertions, 0 deletions
diff --git a/libopie2/opiecore/device/odevice_yopy.cpp b/libopie2/opiecore/device/odevice_yopy.cpp
new file mode 100644
index 0000000..9d0cdeb
--- a/dev/null
+++ b/libopie2/opiecore/device/odevice_yopy.cpp
@@ -0,0 +1,212 @@
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 Yopy : public ODevice
72{
73 protected:
74
75 virtual void init();
76 virtual void initButtons();
77
78 public:
79 virtual bool suspend();
80
81 virtual bool setDisplayBrightness ( int b );
82 virtual int displayBrightnessResolution() const;
83
84 static bool isYopy();
85};
86
87struct yopy_button {
88 Qt::Key code;
89 char *utext;
90 char *pix;
91 char *fpressedservice;
92 char *fpressedaction;
93 char *fheldservice;
94 char *fheldaction;
95} yopy_buttons [] = {
96{ Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Action Button"),
97 "devicebuttons/yopy_action",
98 "datebook", "nextView()",
99 "today", "raise()" },
100{ Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "OK Button"),
101 "devicebuttons/yopy_ok",
102 "addressbook", "raise()",
103 "addressbook", "beamBusinessCard()" },
104{ Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "End Button"),
105 "devicebuttons/yopy_end",
106 "QPE/Launcher", "home()",
107 "buttonsettings", "raise()" },
108};
109
110bool Yopy::isYopy()
111{
112QFile f( "/proc/cpuinfo" );
113if ( f. open ( IO_ReadOnly ) ) {
114 QTextStream ts ( &f );
115 QString line;
116 while( line = ts. readLine() ) {
117 if ( line. left ( 8 ) == "Hardware" ) {
118 int loc = line. find ( ":" );
119 if ( loc != -1 ) {
120 QString model =
121 line. mid ( loc + 2 ). simplifyWhiteSpace( );
122 return ( model == "Yopy" );
123 }
124 }
125 }
126}
127return false;
128}
129
130void Yopy::init()
131{
132d->m_vendorstr = "G.Mate";
133d->m_vendor = Vendor_GMate;
134d->m_modelstr = "Yopy3700";
135d->m_model = Model_Yopy_3700;
136d->m_rotation = Rot0;
137
138d->m_systemstr = "Linupy";
139d->m_system = System_Linupy;
140
141QFile f ( "/etc/issue" );
142if ( f. open ( IO_ReadOnly )) {
143 QTextStream ts ( &f );
144 ts.readLine();
145 d->m_sysverstr = ts. readLine();
146 f. close();
147}
148}
149
150void Yopy::initButtons()
151{
152if ( d->m_buttons )
153 return;
154
155d->m_buttons = new QValueList <ODeviceButton>;
156
157for (uint i = 0; i < ( sizeof( yopy_buttons ) / sizeof(yopy_button)); i++) {
158
159 yopy_button *ib = yopy_buttons + i;
160
161 ODeviceButton b;
162
163 b. setKeycode ( ib->code );
164 b. setUserText ( QObject::tr ( "Button", ib->utext ));
165 b. setPixmap ( Resource::loadPixmap ( ib->pix ));
166 b. setFactoryPresetPressedAction
167 (OQCopMessage(makeChannel(ib->fpressedservice), ib->fpressedaction));
168 b. setFactoryPresetHeldAction
169 (OQCopMessage(makeChannel(ib->fheldservice), ib->fheldaction));
170
171 d->m_buttons->append ( b );
172}
173reloadButtonMapping();
174
175QCopChannel *sysch = new QCopChannel("QPE/System", this);
176connect(sysch, SIGNAL(received(const QCString &, const QByteArray & )),
177 this, SLOT(systemMessage(const QCString &, const QByteArray & )));
178}
179
180bool Yopy::suspend()
181{
182/* Opie for Yopy does not implement its own power management at the
183 moment. The public version runs parallel to X, and relies on the
184 existing power management features. */
185return false;
186}
187
188bool Yopy::setDisplayBrightness(int bright)
189{
190/* The code here works, but is disabled as the current version runs
191 parallel to X, and relies on the existing backlight demon. */
192#if 0
193if ( QFile::exists("/proc/sys/pm/light") ) {
194 int fd = ::open("/proc/sys/pm/light", O_WRONLY);
195 if (fd >= 0 ) {
196 if (bright)
197 ::write(fd, "1\n", 2);
198 else
199 ::write(fd, "0\n", 2);
200 ::close(fd);
201 return true;
202 }
203}
204#endif
205return false;
206}
207
208int Yopy::displayBrightnessResolution() const
209{
210 return 2;
211}
212