-rw-r--r-- | libopie2/opiecore/device/odevice_mypal.cpp | 252 | ||||
-rw-r--r-- | libopie2/opiecore/device/odevice_mypal.h | 78 |
2 files changed, 330 insertions, 0 deletions
diff --git a/libopie2/opiecore/device/odevice_mypal.cpp b/libopie2/opiecore/device/odevice_mypal.cpp new file mode 100644 index 0000000..45c70ae --- a/dev/null +++ b/libopie2/opiecore/device/odevice_mypal.cpp | |||
@@ -0,0 +1,252 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | =. (C) 2002-2005 The Opie Team <opie-devel@handhelds.org> | ||
4 | .=l. | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This program is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; version 2 of the License. | ||
11 | ._= =} : | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This program is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
18 | ..}^=.= = ; Library General Public License for more | ||
19 | ++= -. .` .: details. | ||
20 | : = ...= . :.=- | ||
21 | -. .:....=;==+<; You should have received a copy of the GNU | ||
22 | -_. . . )=. = Library General Public License along with | ||
23 | -- :-=` this library; see the file COPYING.LIB. | ||
24 | If not, write to the Free Software Foundation, | ||
25 | Inc., 59 Temple Place - Suite 330, | ||
26 | Boston, MA 02111-1307, USA. | ||
27 | |||
28 | */ | ||
29 | |||
30 | #include "odevice_mypal.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/sound.h> | ||
41 | #include <qpe/qcopenvelope_qws.h> | ||
42 | |||
43 | #include <opie2/okeyfilter.h> | ||
44 | #include <opie2/oresource.h> | ||
45 | |||
46 | /* STD */ | ||
47 | #include <fcntl.h> | ||
48 | #include <math.h> | ||
49 | #include <stdlib.h> | ||
50 | #include <signal.h> | ||
51 | #include <sys/ioctl.h> | ||
52 | #include <sys/time.h> | ||
53 | #include <unistd.h> | ||
54 | #ifndef QT_NO_SOUND | ||
55 | #include <linux/soundcard.h> | ||
56 | #endif | ||
57 | |||
58 | |||
59 | using namespace Opie::Core; | ||
60 | using namespace Opie::Core::Internal; | ||
61 | |||
62 | struct m_button mypal_buttons [] = { | ||
63 | { Model_MyPal_716, | ||
64 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), | ||
65 | "devicebuttons/ipaq_calendar", | ||
66 | "datebook", "nextView()", | ||
67 | "today", "raise()" }, | ||
68 | { Model_MyPal_716, | ||
69 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), | ||
70 | "devicebuttons/ipaq_contact", | ||
71 | "addressbook", "raise()", | ||
72 | "addressbook", "beamBusinessCard()" }, | ||
73 | { Model_MyPal_716, | ||
74 | Qt::Key_F8, QT_TRANSLATE_NOOP("Button", "Mail Button"), | ||
75 | "devicebuttons/ipaq_mail", | ||
76 | "opiemail", "raise()", | ||
77 | "opiemail", "newMail()" }, | ||
78 | { Model_MyPal_716, | ||
79 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), | ||
80 | "devicebuttons/ipaq_home", | ||
81 | "QPE/Launcher", "home()", | ||
82 | "buttonsettings", "raise()" }, | ||
83 | { Model_MyPal_716, | ||
84 | Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Record Button"), | ||
85 | "devicebuttons/ipaq_record", | ||
86 | "QPE/VMemo", "toggleRecord()", | ||
87 | "sound", "raise()" }, | ||
88 | }; | ||
89 | |||
90 | void MyPal::init(const QString& model) | ||
91 | { | ||
92 | d->m_vendorstr = "Asus"; | ||
93 | d->m_vendor = Vendor_Asus; | ||
94 | |||
95 | d->m_modelstr = model.mid(model.findRev('A')); | ||
96 | if ( d->m_modelstr == "A716" ) | ||
97 | d->m_model = Model_MyPal_716; | ||
98 | else | ||
99 | d->m_model = Model_Unknown; | ||
100 | |||
101 | d->m_rotation = Rot0; | ||
102 | |||
103 | m_power_timer = 0; | ||
104 | } | ||
105 | |||
106 | void MyPal::initButtons() | ||
107 | { | ||
108 | if ( d->m_buttons ) | ||
109 | return; | ||
110 | |||
111 | if ( isQWS( ) ) { | ||
112 | addPreHandler(this); | ||
113 | } | ||
114 | |||
115 | d->m_buttons = new QValueList <ODeviceButton>; | ||
116 | |||
117 | for ( uint i = 0; i < ( sizeof( mypal_buttons ) / sizeof( m_button )); i++ ) { | ||
118 | m_button *mb = mypal_buttons + i; | ||
119 | ODeviceButton b; | ||
120 | |||
121 | if (( mb->model & d->m_model ) == d->m_model ) { | ||
122 | b. setKeycode ( mb->code ); | ||
123 | b. setUserText ( QObject::tr ( "Button", mb->utext )); | ||
124 | b. setPixmap ( OResource::loadPixmap ( mb->pix )); | ||
125 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( mb->fpressedservice ), mb->fpressedaction )); | ||
126 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( mb->fheldservice ), mb->fheldaction )); | ||
127 | |||
128 | d->m_buttons->append ( b ); | ||
129 | } | ||
130 | } | ||
131 | reloadButtonMapping(); | ||
132 | } | ||
133 | |||
134 | bool MyPal::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) | ||
135 | { | ||
136 | int newkeycode = keycode; | ||
137 | |||
138 | switch ( keycode ) { | ||
139 | case Key_Left : | ||
140 | case Key_Right: | ||
141 | case Key_Up : | ||
142 | case Key_Down : { | ||
143 | // Rotate the cursor keys by 270 | ||
144 | // keycode - Key_Left = position of the button starting from left clockwise | ||
145 | // add the rotation to it and modolo. No we've the original offset | ||
146 | // add the offset to the Key_Left key | ||
147 | if ( d->m_model == Model_MyPal_716 ) | ||
148 | newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4; | ||
149 | break; | ||
150 | } | ||
151 | |||
152 | // map Power Button short/long press to F34/F35 | ||
153 | case Key_SysReq: { | ||
154 | if ( isPress ) { | ||
155 | if ( m_power_timer ) | ||
156 | killTimer ( m_power_timer ); | ||
157 | m_power_timer = startTimer ( 500 ); | ||
158 | } | ||
159 | else if ( m_power_timer ) { | ||
160 | killTimer ( m_power_timer ); | ||
161 | m_power_timer = 0; | ||
162 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); | ||
163 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); | ||
164 | } | ||
165 | newkeycode = Key_unknown; | ||
166 | break; | ||
167 | } | ||
168 | } | ||
169 | |||
170 | if ( newkeycode != keycode ) { | ||
171 | if ( newkeycode != Key_unknown ) | ||
172 | QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); | ||
173 | return true; | ||
174 | } | ||
175 | else | ||
176 | return false; | ||
177 | } | ||
178 | |||
179 | void MyPal::timerEvent ( QTimerEvent * ) | ||
180 | { | ||
181 | killTimer ( m_power_timer ); | ||
182 | m_power_timer = 0; | ||
183 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); | ||
184 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); | ||
185 | } | ||
186 | |||
187 | |||
188 | void MyPal::playAlarmSound() | ||
189 | { | ||
190 | #ifndef QT_NO_SOUND | ||
191 | static Sound snd ( "alarm" ); | ||
192 | if(!snd.isFinished()) | ||
193 | return; | ||
194 | |||
195 | changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); | ||
196 | snd. play(); | ||
197 | #endif | ||
198 | } | ||
199 | |||
200 | bool MyPal::setDisplayBrightness ( int bright ) | ||
201 | { | ||
202 | bool res = false; | ||
203 | |||
204 | if ( bright > 220 ) | ||
205 | bright = 220; | ||
206 | if ( bright < 0 ) | ||
207 | bright = 0; | ||
208 | |||
209 | QString cmdline; | ||
210 | |||
211 | switch ( model()) { | ||
212 | case Model_MyPal_716: | ||
213 | if ( !bright ) | ||
214 | cmdline = QString::fromLatin1( "echo 4 > /sys/class/backlight/pxafb/power"); | ||
215 | else | ||
216 | cmdline = QString::fromLatin1( "echo 0 > /sys/class/backlight/pxafb/power; echo %1 > /sys/class/backlight/pxafb/brightness" ).arg( bright ); | ||
217 | // No Global::shellQuote as we gurantee it to be sane | ||
218 | res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); | ||
219 | break; | ||
220 | default: | ||
221 | res = OAbstractMobileDevice::setDisplayBrightness(bright); | ||
222 | } | ||
223 | |||
224 | return res; | ||
225 | } | ||
226 | |||
227 | int MyPal::displayBrightnessResolution() const | ||
228 | { | ||
229 | switch ( model()) { | ||
230 | case Model_MyPal_716: | ||
231 | return 220; | ||
232 | default: | ||
233 | return OAbstractMobileDevice::displayBrightnessResolution(); | ||
234 | } | ||
235 | } | ||
236 | |||
237 | bool MyPal::setDisplayStatus ( bool on ) | ||
238 | { | ||
239 | bool res = false; | ||
240 | |||
241 | QString cmdline; | ||
242 | |||
243 | if ( model() == Model_MyPal_716 ) { | ||
244 | cmdline = QString::fromLatin1( "echo %1 > /sys/class/lcd/pxafb/power; echo %2 > /sys/class/backlight/pxafb/power").arg( on ? "0" : "4" ).arg( on ? "0" : "4" ); | ||
245 | } else { | ||
246 | return OAbstractMobileDevice::setDisplayStatus(on); | ||
247 | } | ||
248 | |||
249 | res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); | ||
250 | |||
251 | return res; | ||
252 | } | ||
diff --git a/libopie2/opiecore/device/odevice_mypal.h b/libopie2/opiecore/device/odevice_mypal.h new file mode 100644 index 0000000..7827c78 --- a/dev/null +++ b/libopie2/opiecore/device/odevice_mypal.h | |||
@@ -0,0 +1,78 @@ | |||
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 | #ifndef ODEVICE_MYPAL | ||
31 | #define ODEVICE_MYPAL | ||
32 | |||
33 | #include "odevice_abstractmobiledevice.h" | ||
34 | |||
35 | /* QT */ | ||
36 | #include <qwindowsystem_qws.h> | ||
37 | |||
38 | namespace Opie { | ||
39 | namespace Core { | ||
40 | namespace Internal { | ||
41 | |||
42 | class MyPal : public OAbstractMobileDevice, public QWSServer::KeyboardFilter | ||
43 | { | ||
44 | |||
45 | protected: | ||
46 | virtual void init(const QString&); | ||
47 | virtual void initButtons(); | ||
48 | |||
49 | public: | ||
50 | virtual bool setDisplayStatus ( bool on ); | ||
51 | virtual bool setDisplayBrightness( int b ); | ||
52 | virtual int displayBrightnessResolution() const; | ||
53 | |||
54 | virtual void playAlarmSound(); | ||
55 | |||
56 | protected: | ||
57 | virtual bool filter( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); | ||
58 | virtual void timerEvent( QTimerEvent *te ); | ||
59 | |||
60 | int m_power_timer; | ||
61 | }; | ||
62 | |||
63 | struct m_button { | ||
64 | uint model; | ||
65 | Qt::Key code; | ||
66 | char *utext; | ||
67 | char *pix; | ||
68 | char *fpressedservice; | ||
69 | char *fpressedaction; | ||
70 | char *fheldservice; | ||
71 | char *fheldaction; | ||
72 | }; | ||
73 | |||
74 | } | ||
75 | } | ||
76 | } | ||
77 | |||
78 | #endif | ||