summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_ipaq.cpp53
-rw-r--r--libopie2/opiecore/device/odevice_mypal.cpp55
2 files changed, 79 insertions, 29 deletions
diff --git a/libopie2/opiecore/device/odevice_ipaq.cpp b/libopie2/opiecore/device/odevice_ipaq.cpp
index e6e3145..63b60a7 100644
--- a/libopie2/opiecore/device/odevice_ipaq.cpp
+++ b/libopie2/opiecore/device/odevice_ipaq.cpp
@@ -1,481 +1,518 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 =. (C) 2002-2005 The Opie Team <opie-devel@handhelds.org> 3 =. (C) 2002-2005 The Opie Team <opie-devel@handhelds.org>
4 .=l. 4 .=l.
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can 6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; version 2 of the License. 10 - .   .-<_>     .<> Foundation; version 2 of the License.
11     ._= =}       : 11     ._= =}       :
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that 13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more 18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details. 19++=   -.     .`     .: details.
20 :     =  ...= . :.=- 20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU 21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with 22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB. 23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation, 24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, 25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27 27
28*/ 28*/
29 29
30#include "odevice_ipaq.h" 30#include "odevice_ipaq.h"
31 31
32/* QT */ 32/* QT */
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qdir.h>
34#include <qfile.h> 35#include <qfile.h>
35#include <qtextstream.h> 36#include <qtextstream.h>
36#include <qwindowsystem_qws.h> 37#include <qwindowsystem_qws.h>
37 38
38/* OPIE */ 39/* OPIE */
39#include <qpe/config.h> 40#include <qpe/config.h>
40#include <qpe/sound.h> 41#include <qpe/sound.h>
41#include <qpe/qcopenvelope_qws.h> 42#include <qpe/qcopenvelope_qws.h>
42 43
43#include <opie2/okeyfilter.h> 44#include <opie2/okeyfilter.h>
44#include <opie2/oresource.h> 45#include <opie2/oresource.h>
45 46
46/* STD */ 47/* STD */
47#include <fcntl.h> 48#include <fcntl.h>
48#include <math.h> 49#include <math.h>
49#include <stdlib.h> 50#include <stdlib.h>
50#include <signal.h> 51#include <signal.h>
51#include <sys/ioctl.h> 52#include <sys/ioctl.h>
52#include <sys/time.h> 53#include <sys/time.h>
53#include <unistd.h> 54#include <unistd.h>
54#ifndef QT_NO_SOUND 55#ifndef QT_NO_SOUND
55#include <linux/soundcard.h> 56#include <linux/soundcard.h>
56#endif 57#endif
57 58
58 59
59using namespace Opie::Core; 60using namespace Opie::Core;
60using namespace Opie::Core::Internal; 61using namespace Opie::Core::Internal;
61 62
62/* KERNEL */ 63/* KERNEL */
63#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) 64#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
64 65
65#define OD_IO(type,number) OD_IOC(0,type,number,0) 66#define OD_IO(type,number) OD_IOC(0,type,number,0)
66#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) 67#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size))
67#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) 68#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size))
68#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) 69#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size))
69 70
70typedef struct { 71typedef struct {
71 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ 72 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */
72 unsigned char TotalTime; /* Units of 5 seconds */ 73 unsigned char TotalTime; /* Units of 5 seconds */
73 unsigned char OnTime; /* units of 100m/s */ 74 unsigned char OnTime; /* units of 100m/s */
74 unsigned char OffTime; /* units of 100m/s */ 75 unsigned char OffTime; /* units of 100m/s */
75} LED_IN; 76} LED_IN;
76 77
77typedef struct { 78typedef struct {
78 unsigned char mode; 79 unsigned char mode;
79 unsigned char pwr; 80 unsigned char pwr;
80 unsigned char brightness; 81 unsigned char brightness;
81} FLITE_IN; 82} FLITE_IN;
82 83
83#define LED_ON OD_IOW( 'f', 5, LED_IN ) 84#define LED_ON OD_IOW( 'f', 5, LED_IN )
84#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) 85#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN )
85 86
86struct i_button ipaq_buttons [] = { 87struct i_button ipaq_buttons [] = {
87 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx | Model_iPAQ_H191x, 88 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx | Model_iPAQ_H191x,
88 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 89 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
89 "devicebuttons/ipaq_calendar", 90 "devicebuttons/ipaq_calendar",
90 "datebook", "nextView()", 91 "datebook", "nextView()",
91 "today", "raise()" }, 92 "today", "raise()" },
92 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx | Model_iPAQ_H191x, 93 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx | Model_iPAQ_H191x,
93 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 94 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
94 "devicebuttons/ipaq_contact", 95 "devicebuttons/ipaq_contact",
95 "addressbook", "raise()", 96 "addressbook", "raise()",
96 "addressbook", "beamBusinessCard()" }, 97 "addressbook", "beamBusinessCard()" },
97 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, 98 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx,
98 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 99 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
99 "devicebuttons/ipaq_menu", 100 "devicebuttons/ipaq_menu",
100 "QPE/TaskBar", "toggleMenu()", 101 "QPE/TaskBar", "toggleMenu()",
101 "QPE/TaskBar", "toggleStartMenu()" }, 102 "QPE/TaskBar", "toggleStartMenu()" },
102 { Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, 103 { Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx,
103 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), 104 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"),
104 "devicebuttons/ipaq_mail", 105 "devicebuttons/ipaq_mail",
105 "opiemail", "raise()", 106 "opiemail", "raise()",
106 "opiemail", "newMail()" }, 107 "opiemail", "newMail()" },
107 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx | Model_iPAQ_H191x, 108 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx | Model_iPAQ_H191x,
108 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 109 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
109 "devicebuttons/ipaq_home", 110 "devicebuttons/ipaq_home",
110 "QPE/Launcher", "home()", 111 "QPE/Launcher", "home()",
111 "buttonsettings", "raise()" }, 112 "buttonsettings", "raise()" },
112 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, 113 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx,
113 Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), 114 Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"),
114 "devicebuttons/ipaq_record", 115 "devicebuttons/ipaq_record",
115 "QPE/VMemo", "toggleRecord()", 116 "QPE/VMemo", "toggleRecord()",
116 "sound", "raise()" }, 117 "sound", "raise()" },
117 118
118 { Model_iPAQ_H191x, 119 { Model_iPAQ_H191x,
119 Qt::Key_F8, QT_TRANSLATE_NOOP("Button", "Mail Button"), 120 Qt::Key_F8, QT_TRANSLATE_NOOP("Button", "Mail Button"),
120 "devicebuttons/ipaq_mail", 121 "devicebuttons/ipaq_mail",
121 "opiemail", "raise()", 122 "opiemail", "raise()",
122 "opiemail", "newMail()" }, 123 "opiemail", "newMail()" },
123 { Model_iPAQ_H191x, 124 { Model_iPAQ_H191x,
124 Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Record Button"), 125 Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Record Button"),
125 "devicebuttons/ipaq_record", 126 "devicebuttons/ipaq_record",
126 "QPE/VMemo", "toggleRecord()", 127 "QPE/VMemo", "toggleRecord()",
127 "sound", "raise()" }, 128 "sound", "raise()" },
128 129
129}; 130};
130 131
131void iPAQ::init(const QString& model) 132void iPAQ::init(const QString& model)
132{ 133{
133 d->m_vendorstr = "HP"; 134 d->m_vendorstr = "HP";
134 d->m_vendor = Vendor_HP; 135 d->m_vendor = Vendor_HP;
135 136
136 d->m_modelstr = model.mid(model.findRev('H')); 137 d->m_modelstr = model.mid(model.findRev('H'));
137 138
138 if ( d->m_modelstr == "H3100" ) 139 if ( d->m_modelstr == "H3100" )
139 d->m_model = Model_iPAQ_H31xx; 140 d->m_model = Model_iPAQ_H31xx;
140 else if ( d->m_modelstr == "H3600" ) 141 else if ( d->m_modelstr == "H3600" )
141 d->m_model = Model_iPAQ_H36xx; 142 d->m_model = Model_iPAQ_H36xx;
142 else if ( d->m_modelstr == "H3700" ) 143 else if ( d->m_modelstr == "H3700" )
143 d->m_model = Model_iPAQ_H37xx; 144 d->m_model = Model_iPAQ_H37xx;
144 else if ( d->m_modelstr == "H3800" ) 145 else if ( d->m_modelstr == "H3800" )
145 d->m_model = Model_iPAQ_H38xx; 146 d->m_model = Model_iPAQ_H38xx;
146 else if ( d->m_modelstr == "H3900" ) 147 else if ( d->m_modelstr == "H3900" )
147 d->m_model = Model_iPAQ_H39xx; 148 d->m_model = Model_iPAQ_H39xx;
148 else if ( d->m_modelstr == "H5400" ) 149 else if ( d->m_modelstr == "H5400" )
149 d->m_model = Model_iPAQ_H5xxx; 150 d->m_model = Model_iPAQ_H5xxx;
150 else if ( d->m_modelstr == "H2200" ) 151 else if ( d->m_modelstr == "H2200" )
151 d->m_model = Model_iPAQ_H22xx; 152 d->m_model = Model_iPAQ_H22xx;
152 else if ( d->m_modelstr == "H1910" ) 153 else if ( d->m_modelstr == "H1910" )
153 d->m_model = Model_iPAQ_H191x; 154 d->m_model = Model_iPAQ_H191x;
154 else if ( d->m_modelstr == "H1940" ) 155 else if ( d->m_modelstr == "H1940" )
155 d->m_model = Model_iPAQ_H1940; 156 d->m_model = Model_iPAQ_H1940;
156 else if ( d->m_modelstr == "HX4700" ) 157 else if ( d->m_modelstr == "HX4700" )
157 d->m_model = Model_iPAQ_HX4700; 158 d->m_model = Model_iPAQ_HX4700;
158 159
159 else 160 else
160 d->m_model = Model_Unknown; 161 d->m_model = Model_Unknown;
161 162
162 switch ( d->m_model ) { 163 switch ( d->m_model ) {
163 case Model_iPAQ_H31xx: 164 case Model_iPAQ_H31xx:
164 case Model_iPAQ_H38xx: 165 case Model_iPAQ_H38xx:
165 d->m_rotation = Rot90; 166 d->m_rotation = Rot90;
166 break; 167 break;
167 case Model_iPAQ_H5xxx: 168 case Model_iPAQ_H5xxx:
168 case Model_iPAQ_H22xx: 169 case Model_iPAQ_H22xx:
169 case Model_iPAQ_H191x: 170 case Model_iPAQ_H191x:
170 case Model_iPAQ_H1940: 171 case Model_iPAQ_H1940:
171 case Model_iPAQ_HX4700: 172 case Model_iPAQ_HX4700:
172 d->m_rotation = Rot0; 173 d->m_rotation = Rot0;
173 break; 174 break;
174 case Model_iPAQ_H36xx: 175 case Model_iPAQ_H36xx:
175 case Model_iPAQ_H37xx: 176 case Model_iPAQ_H37xx:
176 case Model_iPAQ_H39xx: 177 case Model_iPAQ_H39xx:
177 default: 178 default:
178 d->m_rotation = Rot270; 179 d->m_rotation = Rot270;
179 break; 180 break;
180 181
181 } 182 }
182 183
183 m_leds [0] = m_leds [1] = Led_Off; 184 m_leds [0] = m_leds [1] = Led_Off;
184 185
185 m_power_timer = 0; 186 m_power_timer = 0;
186 187
187} 188}
188 189
189void iPAQ::initButtons() 190void iPAQ::initButtons()
190{ 191{
191 if ( d->m_buttons ) 192 if ( d->m_buttons )
192 return; 193 return;
193 194
194 if ( isQWS( ) ) { 195 if ( isQWS( ) ) {
195 addPreHandler(this); 196 addPreHandler(this);
196 } 197 }
197 198
198 d->m_buttons = new QValueList <ODeviceButton>; 199 d->m_buttons = new QValueList <ODeviceButton>;
199 200
200 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 201 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
201 i_button *ib = ipaq_buttons + i; 202 i_button *ib = ipaq_buttons + i;
202 ODeviceButton b; 203 ODeviceButton b;
203 204
204 if (( ib->model & d->m_model ) == d->m_model ) { 205 if (( ib->model & d->m_model ) == d->m_model ) {
205 b. setKeycode ( ib->code ); 206 b. setKeycode ( ib->code );
206 b. setUserText ( QObject::tr ( "Button", ib->utext )); 207 b. setUserText ( QObject::tr ( "Button", ib->utext ));
207 b. setPixmap ( OResource::loadPixmap ( ib->pix )); 208 b. setPixmap ( OResource::loadPixmap ( ib->pix ));
208 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib->fpressedservice ), ib->fpressedaction )); 209 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib->fpressedservice ), ib->fpressedaction ));
209 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib->fheldservice ), ib->fheldaction )); 210 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib->fheldservice ), ib->fheldaction ));
210 211
211 d->m_buttons->append ( b ); 212 d->m_buttons->append ( b );
212 } 213 }
213 } 214 }
214 reloadButtonMapping(); 215 reloadButtonMapping();
215} 216}
216 217
217QValueList <OLed> iPAQ::ledList() const 218QValueList <OLed> iPAQ::ledList() const
218{ 219{
219 QValueList <OLed> vl; 220 QValueList <OLed> vl;
220 vl << Led_Power; 221 vl << Led_Power;
221 222
222 if ( d->m_model == Model_iPAQ_H38xx ) 223 if ( d->m_model == Model_iPAQ_H38xx )
223 vl << Led_BlueTooth; 224 vl << Led_BlueTooth;
224 return vl; 225 return vl;
225} 226}
226 227
227QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const 228QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const
228{ 229{
229 QValueList <OLedState> vl; 230 QValueList <OLedState> vl;
230 231
231 if ( l == Led_Power ) 232 if ( l == Led_Power )
232 vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; 233 vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast;
233 else if ( l == Led_BlueTooth && d->m_model == Model_iPAQ_H38xx ) 234 else if ( l == Led_BlueTooth && d->m_model == Model_iPAQ_H38xx )
234 vl << Led_Off; // << Led_On << ??? 235 vl << Led_Off; // << Led_On << ???
235 236
236 return vl; 237 return vl;
237} 238}
238 239
239OLedState iPAQ::ledState ( OLed l ) const 240OLedState iPAQ::ledState ( OLed l ) const
240{ 241{
241 switch ( l ) { 242 switch ( l ) {
242 case Led_Power: 243 case Led_Power:
243 return m_leds [0]; 244 return m_leds [0];
244 case Led_BlueTooth: 245 case Led_BlueTooth:
245 return m_leds [1]; 246 return m_leds [1];
246 default: 247 default:
247 return Led_Off; 248 return Led_Off;
248 } 249 }
249} 250}
250 251
251bool iPAQ::setLedState ( OLed l, OLedState st ) 252bool iPAQ::setLedState ( OLed l, OLedState st )
252{ 253{
253 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK ); 254 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK );
254 255
255 if ( l == Led_Power ) { 256 if ( l == Led_Power ) {
256 if ( fd >= 0 ) { 257 if ( fd >= 0 ) {
257 LED_IN leds; 258 LED_IN leds;
258 ::memset ( &leds, 0, sizeof( leds )); 259 ::memset ( &leds, 0, sizeof( leds ));
259 leds. TotalTime = 0; 260 leds. TotalTime = 0;
260 leds. OnTime = 0; 261 leds. OnTime = 0;
261 leds. OffTime = 1; 262 leds. OffTime = 1;
262 leds. OffOnBlink = 2; 263 leds. OffOnBlink = 2;
263 264
264 switch ( st ) { 265 switch ( st ) {
265 case Led_Off : leds. OffOnBlink = 0; break; 266 case Led_Off : leds. OffOnBlink = 0; break;
266 case Led_On : leds. OffOnBlink = 1; break; 267 case Led_On : leds. OffOnBlink = 1; break;
267 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; 268 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break;
268 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; 269 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break;
269 } 270 }
270 271
271 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { 272 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) {
272 m_leds [0] = st; 273 m_leds [0] = st;
273 return true; 274 return true;
274 } 275 }
275 } 276 }
276 } 277 }
277 return false; 278 return false;
278} 279}
279 280
280 281
281bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) 282bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
282{ 283{
283 int newkeycode = keycode; 284 int newkeycode = keycode;
284 285
285 switch ( keycode ) { 286 switch ( keycode ) {
286 // H38xx/H39xx have no "Q" key anymore - this is now the Mail key 287 // H38xx/H39xx have no "Q" key anymore - this is now the Mail key
287 case HardKey_Menu: { 288 case HardKey_Menu: {
288 if (( d->m_model == Model_iPAQ_H38xx ) || 289 if (( d->m_model == Model_iPAQ_H38xx ) ||
289 ( d->m_model == Model_iPAQ_H39xx ) || 290 ( d->m_model == Model_iPAQ_H39xx ) ||
290 ( d->m_model == Model_iPAQ_H5xxx)) { 291 ( d->m_model == Model_iPAQ_H5xxx)) {
291 newkeycode = HardKey_Mail; 292 newkeycode = HardKey_Mail;
292 } 293 }
293 break; 294 break;
294 } 295 }
295 296
296 // Rotate cursor keys 180 or 270 297 // Rotate cursor keys 180 or 270
297 case Key_Left : 298 case Key_Left :
298 case Key_Right: 299 case Key_Right:
299 case Key_Up : 300 case Key_Up :
300 case Key_Down : { 301 case Key_Down : {
301 if (( d->m_model == Model_iPAQ_H31xx ) || 302 if (( d->m_model == Model_iPAQ_H31xx ) ||
302 ( d->m_model == Model_iPAQ_H38xx )) { 303 ( d->m_model == Model_iPAQ_H38xx )) {
303 newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4; 304 newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4;
304 } 305 }
305 // Rotate the cursor keys by 270 306 // Rotate the cursor keys by 270
306 // keycode - Key_Left = position of the button starting from left clockwise 307 // keycode - Key_Left = position of the button starting from left clockwise
307 // add the rotation to it and modolo. No we've the original offset 308 // add the rotation to it and modolo. No we've the original offset
308 // add the offset to the Key_Left key 309 // add the offset to the Key_Left key
309 if (( d->m_model == Model_iPAQ_H5xxx ) || 310 if (( d->m_model == Model_iPAQ_H5xxx ) ||
310 ( d->m_model == Model_iPAQ_H191x ) || 311 ( d->m_model == Model_iPAQ_H191x ) ||
311 ( d->m_model == Model_iPAQ_H1940 )) 312 ( d->m_model == Model_iPAQ_H1940 ))
312 newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4; 313 newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4;
313 break; 314 break;
314 } 315 }
315 316
316 // map Power Button short/long press to F6 for h191x 317 // map Power Button short/long press to F6 for h191x
317 case Key_F6: 318 case Key_F6:
318 if ( d->m_model != Model_iPAQ_H191x ) 319 if ( d->m_model != Model_iPAQ_H191x )
319 break; 320 break;
320 // map Power Button short/long press to F34/F35 321 // map Power Button short/long press to F34/F35
321 case Key_SysReq: { 322 case Key_SysReq: {
322 if ( isPress ) { 323 if ( isPress ) {
323 if ( m_power_timer ) 324 if ( m_power_timer )
324 killTimer ( m_power_timer ); 325 killTimer ( m_power_timer );
325 m_power_timer = startTimer ( 500 ); 326 m_power_timer = startTimer ( 500 );
326 } 327 }
327 else if ( m_power_timer ) { 328 else if ( m_power_timer ) {
328 killTimer ( m_power_timer ); 329 killTimer ( m_power_timer );
329 m_power_timer = 0; 330 m_power_timer = 0;
330 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); 331 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false );
331 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); 332 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false );
332 } 333 }
333 newkeycode = Key_unknown; 334 newkeycode = Key_unknown;
334 break; 335 break;
335 } 336 }
336 } 337 }
337 338
338 if ( newkeycode != keycode ) { 339 if ( newkeycode != keycode ) {
339 if ( newkeycode != Key_unknown ) 340 if ( newkeycode != Key_unknown )
340 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); 341 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
341 return true; 342 return true;
342 } 343 }
343 else 344 else
344 return false; 345 return false;
345} 346}
346 347
347void iPAQ::timerEvent ( QTimerEvent * ) 348void iPAQ::timerEvent ( QTimerEvent * )
348{ 349{
349 killTimer ( m_power_timer ); 350 killTimer ( m_power_timer );
350 m_power_timer = 0; 351 m_power_timer = 0;
351 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); 352 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false );
352 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); 353 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false );
353} 354}
354 355
355 356
356void iPAQ::playAlarmSound() 357void iPAQ::playAlarmSound()
357{ 358{
358#ifndef QT_NO_SOUND 359#ifndef QT_NO_SOUND
359 static Sound snd ( "alarm" ); 360 static Sound snd ( "alarm" );
360 if(!snd.isFinished()) 361 if(!snd.isFinished())
361 return; 362 return;
362 363
363 changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); 364 changeMixerForAlarm(0, "/dev/sound/mixer", &snd );
364 snd. play(); 365 snd. play();
365#endif 366#endif
366} 367}
367 368
368bool iPAQ::setDisplayBrightness ( int bright ) 369bool iPAQ::setDisplayBrightness ( int bright )
369{ 370{
370 bool res = false; 371 bool res = false;
371 int fd; 372 int fd;
372 373
373 if ( bright > 255 ) 374 if ( bright > 255 )
374 bright = 255; 375 bright = 255;
375 if ( bright < 0 ) 376 if ( bright < 0 )
376 bright = 0; 377 bright = 0;
377 378
378 QString cmdline; 379 QString cmdline;
379 380
380 switch ( model()) { 381 switch ( model()) {
381 case Model_iPAQ_H191x: 382 case Model_iPAQ_H191x:
382 if ( !bright ) 383 {
383 cmdline = QString::fromLatin1( "echo 4 > /sys/class/backlight/pxafb/power"); 384 QDir sysClass( "/sys/class/backlight/pxafb/" );
384 else 385 sysClass.setFilter(QDir::Dirs);
385 cmdline = QString::fromLatin1( "echo 0 > /sys/class/backlight/pxafb/power; echo %1 > /sys/class/backlight/pxafb/brightness" ).arg( bright ); 386 int fd;
386 // No Global::shellQuote as we gurantee it to be sane 387 if ( sysClass.exists() ) {
387 res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); 388 QString sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/power" );
389 fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
390 if ( fd ) {
391 char buf[10];
392 buf[0] = bright ? 0 : 4;
393 buf[1] = '\0';
394 res = ( ::write( fd, &buf[0], 2 ) == 0 );
395 ::close( fd );
396 }
397 sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/brightness" );
398 fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
399 if ( fd ) {
400 char buf[100];
401 int len = ::snprintf( &buf[0], sizeof buf, "%d", bright );
402 res = ( ::write( fd, &buf[0], len ) == 0 );
403 ::close( fd );
404 }
405 }
406 }
388 break; 407 break;
389 408
390 case Model_iPAQ_HX4700: 409 case Model_iPAQ_HX4700:
391 cmdline = QString::fromLatin1( "echo %1 > /sys/class/backlight/w100fb/brightness" ).arg( bright ); 410 cmdline = QString::fromLatin1( "echo %1 > /sys/class/backlight/w100fb/brightness" ).arg( bright );
392 // No Global::shellQuote as we gurantee it to be sane 411 // No Global::shellQuote as we gurantee it to be sane
393 res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); 412 res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
394 break; 413 break;
395 414
396 415
397 default: 416 default:
398 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { 417 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
399 FLITE_IN bl; 418 FLITE_IN bl;
400 bl. mode = 1; 419 bl. mode = 1;
401 bl. pwr = bright ? 1 : 0; 420 bl. pwr = bright ? 1 : 0;
402 bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; 421 bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255;
403 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); 422 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 );
404 ::close ( fd ); 423 ::close ( fd );
405 } 424 }
406 } 425 }
407 return res; 426 return res;
408} 427}
409 428
410int iPAQ::displayBrightnessResolution() const 429int iPAQ::displayBrightnessResolution() const
411{ 430{
412 switch ( model()) { 431 switch ( model()) {
413 case Model_iPAQ_H31xx: 432 case Model_iPAQ_H31xx:
414 case Model_iPAQ_H36xx: 433 case Model_iPAQ_H36xx:
415 case Model_iPAQ_H37xx: 434 case Model_iPAQ_H37xx:
416 return 128; // really 256, but >128 could damage the LCD 435 return 128; // really 256, but >128 could damage the LCD
417 436
418 case Model_iPAQ_H38xx: 437 case Model_iPAQ_H38xx:
419 case Model_iPAQ_H39xx: 438 case Model_iPAQ_H39xx:
420 return 64; 439 return 64;
421 case Model_iPAQ_H5xxx: 440 case Model_iPAQ_H5xxx:
422 case Model_iPAQ_HX4700: 441 case Model_iPAQ_HX4700:
423 return 255; 442 return 255;
424 case Model_iPAQ_H191x: 443 case Model_iPAQ_H191x:
425 return 7; 444 return 7;
426 case Model_iPAQ_H1940: 445 case Model_iPAQ_H1940:
427 return 44; 446 return 44;
428 default: 447 default:
429 return 2; 448 return 2;
430 } 449 }
431} 450}
432 451
433bool iPAQ::setDisplayStatus ( bool on ) 452bool iPAQ::setDisplayStatus ( bool on )
434{ 453{
435 bool res = false; 454 bool res = false;
436 455
437 QString cmdline; 456 QString cmdline;
438 457
439 if ( model() == Model_iPAQ_H191x ) { 458 if ( model() == Model_iPAQ_H191x ) {
440 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" ); 459 QDir sysClass( "/sys/class/lcd/pxafb/" );
460 sysClass.setFilter(QDir::Dirs);
461 if ( sysClass.exists() ) {
462 QString sysClassPath = sysClass.absFilePath( "/sys/class/lcd/pxafb/power" );
463 int fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
464 if ( fd ) {
465 char buf[10];
466 buf[0] = on ? 0 : 4;
467 buf[1] = '\0';
468 res = ( ::write( fd, &buf[0], 2 ) == 0 );
469 ::close( fd );
470 }
471 }
472 return res;
441 } else { 473 } else {
442 return OAbstractMobileDevice::setDisplayStatus(on); 474 return OAbstractMobileDevice::setDisplayStatus(on);
443 } 475 }
444 476
445 res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); 477 res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
446 478
447 return res; 479 return res;
448} 480}
449 481
450bool iPAQ::hasLightSensor() const 482bool iPAQ::hasLightSensor() const
451{ 483{
452 return true; 484 switch (model()) {
485 case Model_iPAQ_H191x:
486 return false;
487 default:
488 return true;
489 }
453} 490}
454 491
455int iPAQ::readLightSensor() 492int iPAQ::readLightSensor()
456{ 493{
457 int fd; 494 int fd;
458 int val = -1; 495 int val = -1;
459 496
460 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { 497 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) {
461 char buffer [8]; 498 char buffer [8];
462 499
463 if ( ::read ( fd, buffer, 5 ) == 5 ) { 500 if ( ::read ( fd, buffer, 5 ) == 5 ) {
464 char *endptr; 501 char *endptr;
465 502
466 buffer [4] = 0; 503 buffer [4] = 0;
467 val = ::strtol ( buffer + 2, &endptr, 16 ); 504 val = ::strtol ( buffer + 2, &endptr, 16 );
468 505
469 if ( *endptr != 0 ) 506 if ( *endptr != 0 )
470 val = -1; 507 val = -1;
471 } 508 }
472 ::close ( fd ); 509 ::close ( fd );
473 } 510 }
474 511
475 return val; 512 return val;
476} 513}
477 514
478int iPAQ::lightSensorResolution() const 515int iPAQ::lightSensorResolution() const
479{ 516{
480 return 256; 517 return 256;
481} 518}
diff --git a/libopie2/opiecore/device/odevice_mypal.cpp b/libopie2/opiecore/device/odevice_mypal.cpp
index 7e1245a..7eb8d1d 100644
--- a/libopie2/opiecore/device/odevice_mypal.cpp
+++ b/libopie2/opiecore/device/odevice_mypal.cpp
@@ -1,252 +1,265 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 =. (C) 2002-2005 The Opie Team <opie-devel@handhelds.org> 3 =. (C) 2002-2005 The Opie Team <opie-devel@handhelds.org>
4 .=l. 4 .=l.
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can 6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; version 2 of the License. 10 - .   .-<_>     .<> Foundation; version 2 of the License.
11     ._= =}       : 11     ._= =}       :
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that 13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more 18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details. 19++=   -.     .`     .: details.
20 :     =  ...= . :.=- 20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU 21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with 22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB. 23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation, 24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, 25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27 27
28*/ 28*/
29 29
30#include "odevice_mypal.h" 30#include "odevice_mypal.h"
31 31
32/* QT */ 32/* QT */
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qdir.h>
34#include <qfile.h> 35#include <qfile.h>
35#include <qtextstream.h> 36#include <qtextstream.h>
36#include <qwindowsystem_qws.h> 37#include <qwindowsystem_qws.h>
37 38
38/* OPIE */ 39/* OPIE */
39#include <qpe/config.h> 40#include <qpe/config.h>
40#include <qpe/sound.h> 41#include <qpe/sound.h>
41#include <qpe/qcopenvelope_qws.h> 42#include <qpe/qcopenvelope_qws.h>
42 43
43#include <opie2/okeyfilter.h> 44#include <opie2/okeyfilter.h>
44#include <opie2/oresource.h> 45#include <opie2/oresource.h>
45 46
46/* STD */ 47/* STD */
47#include <fcntl.h> 48#include <fcntl.h>
48#include <math.h> 49#include <math.h>
49#include <stdlib.h> 50#include <stdlib.h>
50#include <signal.h> 51#include <signal.h>
51#include <sys/ioctl.h> 52#include <sys/ioctl.h>
52#include <sys/time.h> 53#include <sys/time.h>
53#include <unistd.h> 54#include <unistd.h>
54#ifndef QT_NO_SOUND 55#ifndef QT_NO_SOUND
55#include <linux/soundcard.h> 56#include <linux/soundcard.h>
56#endif 57#endif
57 58
58 59
59using namespace Opie::Core; 60using namespace Opie::Core;
60using namespace Opie::Core::Internal; 61using namespace Opie::Core::Internal;
61 62
62struct m_button mypal_buttons [] = { 63struct m_button mypal_buttons [] = {
63 { Model_MyPal_716, 64 { Model_MyPal_716,
64 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 65 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
65 "devicebuttons/ipaq_calendar", 66 "devicebuttons/ipaq_calendar",
66 "datebook", "nextView()", 67 "datebook", "nextView()",
67 "today", "raise()" }, 68 "today", "raise()" },
68 { Model_MyPal_716, 69 { Model_MyPal_716,
69 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 70 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
70 "devicebuttons/ipaq_contact", 71 "devicebuttons/ipaq_contact",
71 "addressbook", "raise()", 72 "addressbook", "raise()",
72 "addressbook", "beamBusinessCard()" }, 73 "addressbook", "beamBusinessCard()" },
73 { Model_MyPal_716, 74 { Model_MyPal_716,
74 Qt::Key_F8, QT_TRANSLATE_NOOP("Button", "Mail Button"), 75 Qt::Key_F8, QT_TRANSLATE_NOOP("Button", "Mail Button"),
75 "devicebuttons/ipaq_mail", 76 "devicebuttons/ipaq_mail",
76 "opiemail", "raise()", 77 "opiemail", "raise()",
77 "opiemail", "newMail()" }, 78 "opiemail", "newMail()" },
78 { Model_MyPal_716, 79 { Model_MyPal_716,
79 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 80 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
80 "devicebuttons/ipaq_home", 81 "devicebuttons/ipaq_home",
81 "QPE/Launcher", "home()", 82 "QPE/Launcher", "home()",
82 "buttonsettings", "raise()" }, 83 "buttonsettings", "raise()" },
83 { Model_MyPal_716, 84 { Model_MyPal_716,
84 Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Record Button"), 85 Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Record Button"),
85 "devicebuttons/ipaq_record", 86 "devicebuttons/ipaq_record",
86 "QPE/VMemo", "toggleRecord()", 87 "QPE/VMemo", "toggleRecord()",
87 "sound", "raise()" }, 88 "sound", "raise()" },
88}; 89};
89 90
90void MyPal::init(const QString& model) 91void MyPal::init(const QString& model)
91{ 92{
92 d->m_vendorstr = "Asus"; 93 d->m_vendorstr = "Asus";
93 d->m_vendor = Vendor_Asus; 94 d->m_vendor = Vendor_Asus;
94 95
95 d->m_modelstr = model.mid(model.findRev('A')); 96 d->m_modelstr = model.mid(model.findRev('A'));
96 if ( d->m_modelstr == "A716" ) 97 if ( d->m_modelstr == "A716" )
97 d->m_model = Model_MyPal_716; 98 d->m_model = Model_MyPal_716;
98 else 99 else
99 d->m_model = Model_Unknown; 100 d->m_model = Model_Unknown;
100 101
101 d->m_rotation = Rot0; 102 d->m_rotation = Rot0;
102 103
103 m_power_timer = 0; 104 m_power_timer = 0;
104} 105}
105 106
106void MyPal::initButtons() 107void MyPal::initButtons()
107{ 108{
108 if ( d->m_buttons ) 109 if ( d->m_buttons )
109 return; 110 return;
110 111
111 if ( isQWS( ) ) { 112 if ( isQWS( ) ) {
112 addPreHandler(this); 113 addPreHandler(this);
113 } 114 }
114 115
115 d->m_buttons = new QValueList <ODeviceButton>; 116 d->m_buttons = new QValueList <ODeviceButton>;
116 117
117 for ( uint i = 0; i < ( sizeof( mypal_buttons ) / sizeof( m_button )); i++ ) { 118 for ( uint i = 0; i < ( sizeof( mypal_buttons ) / sizeof( m_button )); i++ ) {
118 m_button *mb = mypal_buttons + i; 119 m_button *mb = mypal_buttons + i;
119 ODeviceButton b; 120 ODeviceButton b;
120 121
121 if (( mb->model & d->m_model ) == d->m_model ) { 122 if (( mb->model & d->m_model ) == d->m_model ) {
122 b. setKeycode ( mb->code ); 123 b. setKeycode ( mb->code );
123 b. setUserText ( QObject::tr ( "Button", mb->utext )); 124 b. setUserText ( QObject::tr ( "Button", mb->utext ));
124 b. setPixmap ( OResource::loadPixmap ( mb->pix )); 125 b. setPixmap ( OResource::loadPixmap ( mb->pix ));
125 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( mb->fpressedservice ), mb->fpressedaction )); 126 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( mb->fpressedservice ), mb->fpressedaction ));
126 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( mb->fheldservice ), mb->fheldaction )); 127 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( mb->fheldservice ), mb->fheldaction ));
127 128
128 d->m_buttons->append ( b ); 129 d->m_buttons->append ( b );
129 } 130 }
130 } 131 }
131 reloadButtonMapping(); 132 reloadButtonMapping();
132} 133}
133 134
134bool MyPal::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) 135bool MyPal::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
135{ 136{
136 int newkeycode = keycode; 137 int newkeycode = keycode;
137 138
138 switch ( keycode ) { 139 switch ( keycode ) {
139 case Key_Left : 140 case Key_Left :
140 case Key_Right: 141 case Key_Right:
141 case Key_Up : 142 case Key_Up :
142 case Key_Down : { 143 case Key_Down : {
143 // Rotate the cursor keys by 270 144 // Rotate the cursor keys by 270
144 // keycode - Key_Left = position of the button starting from left clockwise 145 // 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 rotation to it and modolo. No we've the original offset
146 // add the offset to the Key_Left key 147 // add the offset to the Key_Left key
147 if ( d->m_model == Model_MyPal_716 ) 148 if ( d->m_model == Model_MyPal_716 )
148 newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4; 149 newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4;
149 break; 150 break;
150 } 151 }
151 152
152 // map Power Button short/long press to F6 153 // map Power Button short/long press to F6
153 case Key_F6: { 154 case Key_F6: {
154 if ( isPress ) { 155 if ( isPress ) {
155 if ( m_power_timer ) 156 if ( m_power_timer )
156 killTimer ( m_power_timer ); 157 killTimer ( m_power_timer );
157 m_power_timer = startTimer ( 500 ); 158 m_power_timer = startTimer ( 500 );
158 } 159 }
159 else if ( m_power_timer ) { 160 else if ( m_power_timer ) {
160 killTimer ( m_power_timer ); 161 killTimer ( m_power_timer );
161 m_power_timer = 0; 162 m_power_timer = 0;
162 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); 163 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false );
163 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); 164 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false );
164 } 165 }
165 newkeycode = Key_unknown; 166 newkeycode = Key_unknown;
166 break; 167 break;
167 } 168 }
168 } 169 }
169 170
170 if ( newkeycode != keycode ) { 171 if ( newkeycode != keycode ) {
171 if ( newkeycode != Key_unknown ) 172 if ( newkeycode != Key_unknown )
172 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); 173 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
173 return true; 174 return true;
174 } 175 }
175 else 176 else
176 return false; 177 return false;
177} 178}
178 179
179void MyPal::timerEvent ( QTimerEvent * ) 180void MyPal::timerEvent ( QTimerEvent * )
180{ 181{
181 killTimer ( m_power_timer ); 182 killTimer ( m_power_timer );
182 m_power_timer = 0; 183 m_power_timer = 0;
183 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); 184 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false );
184 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); 185 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false );
185} 186}
186 187
187 188
188void MyPal::playAlarmSound() 189void MyPal::playAlarmSound()
189{ 190{
190#ifndef QT_NO_SOUND 191#ifndef QT_NO_SOUND
191 static Sound snd ( "alarm" ); 192 static Sound snd ( "alarm" );
192 if(!snd.isFinished()) 193 if(!snd.isFinished())
193 return; 194 return;
194 195
195 changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); 196 changeMixerForAlarm(0, "/dev/sound/mixer", &snd );
196 snd. play(); 197 snd. play();
197#endif 198#endif
198} 199}
199 200
200bool MyPal::setDisplayBrightness ( int bright ) 201bool MyPal::setDisplayBrightness ( int bright )
201{ 202{
202 bool res = false; 203 bool res = false;
203 204
204 if ( bright > 255 ) 205 if ( bright > 255 )
205 bright = 255; 206 bright = 255;
206 if ( bright < 0 ) 207 if ( bright < 0 )
207 bright = 0; 208 bright = 0;
208 209
209 QString cmdline; 210 QDir sysClass( "/sys/class/backlight/pxafb/" );
210 211 sysClass.setFilter(QDir::Dirs);
211 switch ( model()) { 212 int fd;
212 case Model_MyPal_716: 213 if ( sysClass.exists() ) {
213 if ( !bright ) 214 QString sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/power" );
214 cmdline = QString::fromLatin1( "echo 4 > /sys/class/backlight/pxafb/power"); 215 fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
215 else 216 if ( fd ) {
216 cmdline = QString::fromLatin1( "echo 0 > /sys/class/backlight/pxafb/power; echo %1 > /sys/class/backlight/pxafb/brightness" ).arg( bright ); 217 char buf[10];
217 // No Global::shellQuote as we gurantee it to be sane 218 buf[0] = bright ? 0 : 4;
218 res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); 219 buf[1] = '\0';
219 break; 220 res = ( ::write( fd, &buf[0], 2 ) == 0 );
220 default: 221 ::close( fd );
221 res = OAbstractMobileDevice::setDisplayBrightness(bright); 222 }
223 sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/brightness" );
224 fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
225 if ( fd ) {
226 char buf[100];
227 int len = ::snprintf( &buf[0], sizeof buf, "%d", bright );
228 res = ( ::write( fd, &buf[0], len ) == 0 );
229 ::close( fd );
230 }
222 } 231 }
223 232
224 return res; 233 return res;
225} 234}
226 235
227int MyPal::displayBrightnessResolution() const 236int MyPal::displayBrightnessResolution() const
228{ 237{
229 switch ( model()) { 238 switch ( model()) {
230 case Model_MyPal_716: 239 case Model_MyPal_716:
231 return 7; 240 return 7;
232 default: 241 default:
233 return OAbstractMobileDevice::displayBrightnessResolution(); 242 return OAbstractMobileDevice::displayBrightnessResolution();
234 } 243 }
235} 244}
236 245
237bool MyPal::setDisplayStatus ( bool on ) 246bool MyPal::setDisplayStatus ( bool on )
238{ 247{
239 bool res = false; 248 bool res = false;
240 249
241 QString cmdline; 250 QDir sysClass( "/sys/class/lcd/" );
242 251 sysClass.setFilter(QDir::Dirs);
243 if ( model() == Model_MyPal_716 ) { 252 if ( sysClass.exists() ) {
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" ); 253 QString sysClassPath = sysClass.absFilePath( "/sys/class/lcd/pxafb/power" );
245 } else { 254 int fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
246 return OAbstractMobileDevice::setDisplayStatus(on); 255 if ( fd ) {
256 char buf[10];
257 buf[0] = on ? 0 : 4;
258 buf[1] = '\0';
259 res = ( ::write( fd, &buf[0], 2 ) == 0 );
260 ::close( fd );
261 }
247 } 262 }
248 263
249 res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
250
251 return res; 264 return res;
252} 265}