-rw-r--r-- | libopie/odevice.cpp | 2827 |
1 files changed, 0 insertions, 2827 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp deleted file mode 100644 index 9d0bbbf..0000000 --- a/libopie/odevice.cpp +++ b/dev/null | |||
@@ -1,2827 +0,0 @@ | |||
1 | /* This file is part of the OPIE libraries | ||
2 | Copyright (C) 2002 Robert Griebl (sandman@handhelds.org) | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | ||
13 | |||
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 | ||
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
17 | Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | |||
20 | #include <stdlib.h> | ||
21 | #include <unistd.h> | ||
22 | #include <fcntl.h> | ||
23 | #include <sys/ioctl.h> | ||
24 | #include <signal.h> | ||
25 | #include <sys/time.h> | ||
26 | #ifndef QT_NO_SOUND | ||
27 | #include <linux/soundcard.h> | ||
28 | #endif | ||
29 | #include <math.h> | ||
30 | |||
31 | |||
32 | #include <qfile.h> | ||
33 | #include <qtextstream.h> | ||
34 | #include <qpe/sound.h> | ||
35 | #include <qpe/resource.h> | ||
36 | #include <qpe/config.h> | ||
37 | #include <qpe/qcopenvelope_qws.h> | ||
38 | |||
39 | #include "odevice.h" | ||
40 | |||
41 | #include <qwindowsystem_qws.h> | ||
42 | |||
43 | #ifndef ARRAY_SIZE | ||
44 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) | ||
45 | #endif | ||
46 | |||
47 | // _IO and friends are only defined in kernel headers ... | ||
48 | |||
49 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) | ||
50 | |||
51 | #define OD_IO(type,number) OD_IOC(0,type,number,0) | ||
52 | #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) | ||
53 | #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) | ||
54 | #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) | ||
55 | |||
56 | using namespace Opie; | ||
57 | |||
58 | class ODeviceData { | ||
59 | public: | ||
60 | QString m_vendorstr; | ||
61 | OVendor m_vendor; | ||
62 | |||
63 | QString m_modelstr; | ||
64 | OModel m_model; | ||
65 | |||
66 | QString m_systemstr; | ||
67 | OSystem m_system; | ||
68 | |||
69 | QString m_sysverstr; | ||
70 | |||
71 | Transformation m_rotation; | ||
72 | ODirection m_direction; | ||
73 | |||
74 | QValueList <ODeviceButton> *m_buttons; | ||
75 | uint m_holdtime; | ||
76 | QStrList *m_cpu_frequencies; | ||
77 | |||
78 | }; | ||
79 | |||
80 | class iPAQ : public ODevice, public QWSServer::KeyboardFilter { | ||
81 | protected: | ||
82 | virtual void init ( ); | ||
83 | virtual void initButtons ( ); | ||
84 | |||
85 | public: | ||
86 | virtual bool setSoftSuspend ( bool soft ); | ||
87 | |||
88 | virtual bool setDisplayBrightness ( int b ); | ||
89 | virtual int displayBrightnessResolution ( ) const; | ||
90 | |||
91 | virtual void alarmSound ( ); | ||
92 | |||
93 | virtual QValueList <OLed> ledList ( ) const; | ||
94 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; | ||
95 | virtual OLedState ledState ( OLed led ) const; | ||
96 | virtual bool setLedState ( OLed led, OLedState st ); | ||
97 | |||
98 | virtual bool hasLightSensor ( ) const; | ||
99 | virtual int readLightSensor ( ); | ||
100 | virtual int lightSensorResolution ( ) const; | ||
101 | |||
102 | protected: | ||
103 | virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); | ||
104 | virtual void timerEvent ( QTimerEvent *te ); | ||
105 | |||
106 | int m_power_timer; | ||
107 | |||
108 | OLedState m_leds [2]; | ||
109 | }; | ||
110 | |||
111 | class Jornada : public ODevice { | ||
112 | protected: | ||
113 | virtual void init ( ); | ||
114 | //virtual void initButtons ( ); | ||
115 | public: | ||
116 | virtual bool setSoftSuspend ( bool soft ); | ||
117 | virtual bool setDisplayBrightness ( int b ); | ||
118 | virtual int displayBrightnessResolution ( ) const; | ||
119 | static bool isJornada(); | ||
120 | |||
121 | }; | ||
122 | |||
123 | class Zaurus : public ODevice { | ||
124 | protected: | ||
125 | virtual void init ( ); | ||
126 | virtual void initButtons ( ); | ||
127 | |||
128 | public: | ||
129 | virtual bool setSoftSuspend ( bool soft ); | ||
130 | |||
131 | virtual bool setDisplayBrightness ( int b ); | ||
132 | virtual int displayBrightnessResolution ( ) const; | ||
133 | |||
134 | virtual void alarmSound ( ); | ||
135 | virtual void keySound ( ); | ||
136 | virtual void touchSound ( ); | ||
137 | |||
138 | virtual QValueList <OLed> ledList ( ) const; | ||
139 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; | ||
140 | virtual OLedState ledState ( OLed led ) const; | ||
141 | virtual bool setLedState ( OLed led, OLedState st ); | ||
142 | |||
143 | bool hasHingeSensor() const; | ||
144 | OHingeStatus readHingeSensor(); | ||
145 | |||
146 | static bool isZaurus(); | ||
147 | |||
148 | // Does this break BC? | ||
149 | virtual bool suspend ( ); | ||
150 | Transformation rotation ( ) const; | ||
151 | ODirection direction ( ) const; | ||
152 | |||
153 | protected: | ||
154 | virtual void buzzer ( int snd ); | ||
155 | |||
156 | OLedState m_leds [1]; | ||
157 | bool m_embedix; | ||
158 | void virtual_hook( int id, void *data ); | ||
159 | }; | ||
160 | |||
161 | class SIMpad : public ODevice, public QWSServer::KeyboardFilter { | ||
162 | protected: | ||
163 | virtual void init ( ); | ||
164 | virtual void initButtons ( ); | ||
165 | |||
166 | public: | ||
167 | virtual bool setSoftSuspend ( bool soft ); | ||
168 | virtual bool suspend(); | ||
169 | |||
170 | virtual bool setDisplayStatus( bool on ); | ||
171 | virtual bool setDisplayBrightness ( int b ); | ||
172 | virtual int displayBrightnessResolution ( ) const; | ||
173 | |||
174 | virtual void alarmSound ( ); | ||
175 | |||
176 | virtual QValueList <OLed> ledList ( ) const; | ||
177 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; | ||
178 | virtual OLedState ledState ( OLed led ) const; | ||
179 | virtual bool setLedState ( OLed led, OLedState st ); | ||
180 | |||
181 | protected: | ||
182 | virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); | ||
183 | virtual void timerEvent ( QTimerEvent *te ); | ||
184 | |||
185 | int m_power_timer; | ||
186 | |||
187 | OLedState m_leds [1]; //FIXME check if really only one | ||
188 | }; | ||
189 | |||
190 | class Ramses : public ODevice, public QWSServer::KeyboardFilter { | ||
191 | protected: | ||
192 | virtual void init ( ); | ||
193 | |||
194 | public: | ||
195 | virtual bool setSoftSuspend ( bool soft ); | ||
196 | virtual bool suspend ( ); | ||
197 | |||
198 | virtual bool setDisplayStatus( bool on ); | ||
199 | virtual bool setDisplayBrightness ( int b ); | ||
200 | virtual int displayBrightnessResolution ( ) const; | ||
201 | virtual bool setDisplayContrast ( int b ); | ||
202 | virtual int displayContrastResolution ( ) const; | ||
203 | |||
204 | protected: | ||
205 | virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); | ||
206 | virtual void timerEvent ( QTimerEvent *te ); | ||
207 | |||
208 | int m_power_timer; | ||
209 | }; | ||
210 | |||
211 | struct i_button { | ||
212 | uint model; | ||
213 | Qt::Key code; | ||
214 | char *utext; | ||
215 | char *pix; | ||
216 | char *fpressedservice; | ||
217 | char *fpressedaction; | ||
218 | char *fheldservice; | ||
219 | char *fheldaction; | ||
220 | } ipaq_buttons [] = { | ||
221 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, | ||
222 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), | ||
223 | "devicebuttons/ipaq_calendar", | ||
224 | "datebook", "nextView()", | ||
225 | "today", "raise()" }, | ||
226 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, | ||
227 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), | ||
228 | "devicebuttons/ipaq_contact", | ||
229 | "addressbook", "raise()", | ||
230 | "addressbook", "beamBusinessCard()" }, | ||
231 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, | ||
232 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), | ||
233 | "devicebuttons/ipaq_menu", | ||
234 | "QPE/TaskBar", "toggleMenu()", | ||
235 | "QPE/TaskBar", "toggleStartMenu()" }, | ||
236 | { Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, | ||
237 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), | ||
238 | "devicebuttons/ipaq_mail", | ||
239 | "mail", "raise()", | ||
240 | "mail", "newMail()" }, | ||
241 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, | ||
242 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), | ||
243 | "devicebuttons/ipaq_home", | ||
244 | "QPE/Launcher", "home()", | ||
245 | "buttonsettings", "raise()" }, | ||
246 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, | ||
247 | Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), | ||
248 | "devicebuttons/ipaq_record", | ||
249 | "QPE/VMemo", "toggleRecord()", | ||
250 | "sound", "raise()" }, | ||
251 | }; | ||
252 | |||
253 | struct z_button { | ||
254 | Qt::Key code; | ||
255 | char *utext; | ||
256 | char *pix; | ||
257 | char *fpressedservice; | ||
258 | char *fpressedaction; | ||
259 | char *fheldservice; | ||
260 | char *fheldaction; | ||
261 | } z_buttons [] = { | ||
262 | { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), | ||
263 | "devicebuttons/z_calendar", | ||
264 | "datebook", "nextView()", | ||
265 | "today", "raise()" }, | ||
266 | { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), | ||
267 | "devicebuttons/z_contact", | ||
268 | "addressbook", "raise()", | ||
269 | "addressbook", "beamBusinessCard()" }, | ||
270 | { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), | ||
271 | "devicebuttons/z_home", | ||
272 | "QPE/Launcher", "home()", | ||
273 | "buttonsettings", "raise()" }, | ||
274 | { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), | ||
275 | "devicebuttons/z_menu", | ||
276 | "QPE/TaskBar", "toggleMenu()", | ||
277 | "QPE/TaskBar", "toggleStartMenu()" }, | ||
278 | { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), | ||
279 | "devicebuttons/z_mail", | ||
280 | "mail", "raise()", | ||
281 | "mail", "newMail()" }, | ||
282 | }; | ||
283 | |||
284 | struct z_button z_buttons_c700 [] = { | ||
285 | { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), | ||
286 | "devicebuttons/z_calendar", | ||
287 | "datebook", "nextView()", | ||
288 | "today", "raise()" }, | ||
289 | { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), | ||
290 | "devicebuttons/z_contact", | ||
291 | "addressbook", "raise()", | ||
292 | "addressbook", "beamBusinessCard()" }, | ||
293 | { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), | ||
294 | "devicebuttons/z_home", | ||
295 | "QPE/Launcher", "home()", | ||
296 | "buttonsettings", "raise()" }, | ||
297 | { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), | ||
298 | "devicebuttons/z_menu", | ||
299 | "QPE/TaskBar", "toggleMenu()", | ||
300 | "QPE/TaskBar", "toggleStartMenu()" }, | ||
301 | { Qt::Key_F14, QT_TRANSLATE_NOOP("Button", "Display Rotate"), | ||
302 | "devicebuttons/z_hinge", | ||
303 | "QPE/Rotation", "rotateDefault()", | ||
304 | "QPE/Dummy", "doNothing()" }, | ||
305 | }; | ||
306 | |||
307 | struct s_button { | ||
308 | uint model; | ||
309 | Qt::Key code; | ||
310 | char *utext; | ||
311 | char *pix; | ||
312 | char *fpressedservice; | ||
313 | char *fpressedaction; | ||
314 | char *fheldservice; | ||
315 | char *fheldaction; | ||
316 | } simpad_buttons [] = { | ||
317 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | ||
318 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Lower+Up"), | ||
319 | "devicebuttons/simpad_lower_up", | ||
320 | "datebook", "nextView()", | ||
321 | "today", "raise()" }, | ||
322 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | ||
323 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Lower+Down"), | ||
324 | "devicebuttons/simpad_lower_down", | ||
325 | "addressbook", "raise()", | ||
326 | "addressbook", "beamBusinessCard()" }, | ||
327 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | ||
328 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Lower+Right"), | ||
329 | "devicebuttons/simpad_lower_right", | ||
330 | "QPE/TaskBar", "toggleMenu()", | ||
331 | "QPE/TaskBar", "toggleStartMenu()" }, | ||
332 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | ||
333 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Lower+Left"), | ||
334 | "devicebuttons/simpad_lower_left", | ||
335 | "mail", "raise()", | ||
336 | "mail", "newMail()" }, | ||
337 | |||
338 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | ||
339 | Qt::Key_F5, QT_TRANSLATE_NOOP("Button", "Upper+Up"), | ||
340 | "devicebuttons/simpad_upper_up", | ||
341 | "QPE/Launcher", "home()", | ||
342 | "buttonsettings", "raise()" }, | ||
343 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | ||
344 | Qt::Key_F6, QT_TRANSLATE_NOOP("Button", "Upper+Down"), | ||
345 | "devicebuttons/simpad_upper_down", | ||
346 | "addressbook", "raise()", | ||
347 | "addressbook", "beamBusinessCard()" }, | ||
348 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | ||
349 | Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Upper+Right"), | ||
350 | "devicebuttons/simpad_upper_right", | ||
351 | "QPE/TaskBar", "toggleMenu()", | ||
352 | "QPE/TaskBar", "toggleStartMenu()" }, | ||
353 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | ||
354 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Upper+Left"), | ||
355 | "devicebuttons/simpad_upper_left", | ||
356 | "QPE/Rotation", "flip()", | ||
357 | "QPE/Rotation", "flip()" }, | ||
358 | /* | ||
359 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | ||
360 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), | ||
361 | "devicebuttons/simpad_lower_upper", | ||
362 | "QPE/Launcher", "home()", | ||
363 | "buttonsettings", "raise()" }, | ||
364 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | ||
365 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), | ||
366 | "devicebuttons/simpad_upper_lower", | ||
367 | "QPE/Launcher", "home()", | ||
368 | "buttonsettings", "raise()" }, | ||
369 | */ | ||
370 | }; | ||
371 | |||
372 | class Yopy : public ODevice { | ||
373 | protected: | ||
374 | virtual void init ( ); | ||
375 | virtual void initButtons ( ); | ||
376 | |||
377 | public: | ||
378 | virtual bool suspend ( ); | ||
379 | |||
380 | virtual bool setDisplayBrightness ( int b ); | ||
381 | virtual int displayBrightnessResolution ( ) const; | ||
382 | |||
383 | static bool isYopy ( ); | ||
384 | }; | ||
385 | |||
386 | struct yopy_button { | ||
387 | Qt::Key code; | ||
388 | char *utext; | ||
389 | char *pix; | ||
390 | char *fpressedservice; | ||
391 | char *fpressedaction; | ||
392 | char *fheldservice; | ||
393 | char *fheldaction; | ||
394 | } yopy_buttons [] = { | ||
395 | { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Action Button"), | ||
396 | "devicebuttons/yopy_action", | ||
397 | "datebook", "nextView()", | ||
398 | "today", "raise()" }, | ||
399 | { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "OK Button"), | ||
400 | "devicebuttons/yopy_ok", | ||
401 | "addressbook", "raise()", | ||
402 | "addressbook", "beamBusinessCard()" }, | ||
403 | { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "End Button"), | ||
404 | "devicebuttons/yopy_end", | ||
405 | "QPE/Launcher", "home()", | ||
406 | "buttonsettings", "raise()" }, | ||
407 | }; | ||
408 | |||
409 | static QCString makeChannel ( const char *str ) | ||
410 | { | ||
411 | if ( str && !::strchr ( str, '/' )) | ||
412 | return QCString ( "QPE/Application/" ) + str; | ||
413 | else | ||
414 | return str; | ||
415 | } | ||
416 | |||
417 | static inline bool isQWS() | ||
418 | { | ||
419 | return qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; | ||
420 | } | ||
421 | |||
422 | ODevice *ODevice::inst ( ) | ||
423 | { | ||
424 | static ODevice *dev = 0; | ||
425 | |||
426 | if ( !dev ) { | ||
427 | if ( QFile::exists ( "/proc/hal/model" )) | ||
428 | dev = new iPAQ ( ); | ||
429 | else if ( Zaurus::isZaurus() ) | ||
430 | dev = new Zaurus ( ); | ||
431 | else if ( QFile::exists ( "/proc/ucb1x00" ) && QFile::exists ( "/proc/cs3" )) | ||
432 | dev = new SIMpad ( ); | ||
433 | else if ( Yopy::isYopy() ) | ||
434 | dev = new Yopy ( ); | ||
435 | else if ( Jornada::isJornada() ) | ||
436 | dev = new Jornada ( ); | ||
437 | else if ( QFile::exists ( "/proc/sys/board/sys_name" )) | ||
438 | dev = new Ramses ( ); | ||
439 | else | ||
440 | dev = new ODevice ( ); | ||
441 | dev-> init ( ); | ||
442 | } | ||
443 | return dev; | ||
444 | } | ||
445 | |||
446 | |||
447 | /************************************************** | ||
448 | * | ||
449 | * common | ||
450 | * | ||
451 | **************************************************/ | ||
452 | |||
453 | |||
454 | ODevice::ODevice ( ) | ||
455 | { | ||
456 | d = new ODeviceData; | ||
457 | |||
458 | d-> m_modelstr = "Unknown"; | ||
459 | d-> m_model = Model_Unknown; | ||
460 | d-> m_vendorstr = "Unknown"; | ||
461 | d-> m_vendor = Vendor_Unknown; | ||
462 | d-> m_systemstr = "Unknown"; | ||
463 | d-> m_system = System_Unknown; | ||
464 | d-> m_sysverstr = "0.0"; | ||
465 | d-> m_rotation = Rot0; | ||
466 | d-> m_direction = CW; | ||
467 | |||
468 | d-> m_holdtime = 1000; // 1000ms | ||
469 | d-> m_buttons = 0; | ||
470 | d-> m_cpu_frequencies = new QStrList; | ||
471 | } | ||
472 | |||
473 | void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) | ||
474 | { | ||
475 | if ( msg == "deviceButtonMappingChanged()" ) { | ||
476 | reloadButtonMapping ( ); | ||
477 | } | ||
478 | } | ||
479 | |||
480 | void ODevice::init ( ) | ||
481 | { | ||
482 | } | ||
483 | |||
484 | /** | ||
485 | * This method initialises the button mapping | ||
486 | */ | ||
487 | void ODevice::initButtons ( ) | ||
488 | { | ||
489 | if ( d-> m_buttons ) | ||
490 | return; | ||
491 | |||
492 | // Simulation uses iPAQ 3660 device buttons | ||
493 | |||
494 | qDebug ( "init Buttons" ); | ||
495 | d-> m_buttons = new QValueList <ODeviceButton>; | ||
496 | |||
497 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { | ||
498 | i_button *ib = ipaq_buttons + i; | ||
499 | ODeviceButton b; | ||
500 | |||
501 | if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { | ||
502 | b. setKeycode ( ib-> code ); | ||
503 | b. setUserText ( QObject::tr ( "Button", ib-> utext )); | ||
504 | b. setPixmap ( Resource::loadPixmap ( ib-> pix )); | ||
505 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); | ||
506 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); | ||
507 | d-> m_buttons-> append ( b ); | ||
508 | } | ||
509 | } | ||
510 | reloadButtonMapping ( ); | ||
511 | |||
512 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | ||
513 | connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); | ||
514 | } | ||
515 | |||
516 | ODevice::~ODevice ( ) | ||
517 | { | ||
518 | // we leak m_devicebuttons and m_cpu_frequency | ||
519 | // but it's a singleton and it is not so importantant | ||
520 | // -zecke | ||
521 | delete d; | ||
522 | } | ||
523 | |||
524 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) | ||
525 | { | ||
526 | return false; | ||
527 | } | ||
528 | |||
529 | //#include <linux/apm_bios.h> | ||
530 | |||
531 | #define APM_IOC_SUSPEND OD_IO( 'A', 2 ) | ||
532 | |||
533 | /** | ||
534 | * This method will try to suspend the device | ||
535 | * It only works if the user is the QWS Server and the apm application | ||
536 | * is installed. | ||
537 | * It tries to suspend and then waits some time cause some distributions | ||
538 | * do have asynchronus apm implementations. | ||
539 | * This method will either fail and return false or it'll suspend the | ||
540 | * device and return once the device got woken up | ||
541 | * | ||
542 | * @return if the device got suspended | ||
543 | */ | ||
544 | bool ODevice::suspend ( ) | ||
545 | { | ||
546 | qDebug("ODevice::suspend"); | ||
547 | if ( !isQWS( ) ) // only qwsserver is allowed to suspend | ||
548 | return false; | ||
549 | |||
550 | if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices | ||
551 | return false; | ||
552 | |||
553 | bool res = false; | ||
554 | |||
555 | struct timeval tvs, tvn; | ||
556 | ::gettimeofday ( &tvs, 0 ); | ||
557 | |||
558 | ::sync ( ); // flush fs caches | ||
559 | res = ( ::system ( "apm --suspend" ) == 0 ); | ||
560 | |||
561 | // This is needed because the iPAQ apm implementation is asynchronous and we | ||
562 | // can not be sure when exactly the device is really suspended | ||
563 | // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. | ||
564 | |||
565 | if ( res ) { | ||
566 | do { // wait at most 1.5 sec: either suspend didn't work or the device resumed | ||
567 | ::usleep ( 200 * 1000 ); | ||
568 | ::gettimeofday ( &tvn, 0 ); | ||
569 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); | ||
570 | } | ||
571 | |||
572 | return res; | ||
573 | } | ||
574 | |||
575 | //#include <linux/fb.h> better not rely on kernel headers in userspace ... | ||
576 | |||
577 | #define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 | ||
578 | |||
579 | /* VESA Blanking Levels */ | ||
580 | #define VESA_NO_BLANKING 0 | ||
581 | #define VESA_VSYNC_SUSPEND 1 | ||
582 | #define VESA_HSYNC_SUSPEND 2 | ||
583 | #define VESA_POWERDOWN 3 | ||
584 | |||
585 | /** | ||
586 | * This sets the display on or off | ||
587 | */ | ||
588 | bool ODevice::setDisplayStatus ( bool on ) | ||
589 | { | ||
590 | qDebug("ODevice::setDisplayStatus(%d)", on); | ||
591 | |||
592 | if ( d-> m_model == Model_Unknown ) | ||
593 | return false; | ||
594 | |||
595 | bool res = false; | ||
596 | int fd; | ||
597 | |||
598 | #ifdef QT_QWS_DEVFS | ||
599 | if (( fd = ::open ( "/dev/fb/0", O_RDWR )) >= 0 ) { | ||
600 | #else | ||
601 | if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { | ||
602 | #endif | ||
603 | res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); | ||
604 | ::close ( fd ); | ||
605 | } | ||
606 | return res; | ||
607 | } | ||
608 | |||
609 | /** | ||
610 | * This sets the display brightness | ||
611 | * | ||
612 | * @param p The brightness to be set on a scale from 0 to 255 | ||
613 | * @return success or failure | ||
614 | */ | ||
615 | bool ODevice::setDisplayBrightness ( int p) | ||
616 | { | ||
617 | Q_UNUSED( p ) | ||
618 | return false; | ||
619 | } | ||
620 | |||
621 | /** | ||
622 | * @return returns the number of steppings on the brightness slider | ||
623 | * in the Light-'n-Power settings. | ||
624 | */ | ||
625 | int ODevice::displayBrightnessResolution ( ) const | ||
626 | { | ||
627 | return 16; | ||
628 | } | ||
629 | |||
630 | /** | ||
631 | * This sets the display contrast | ||
632 | * @param p The contrast to be set on a scale from 0 to 255 | ||
633 | * @return success or failure | ||
634 | */ | ||
635 | bool ODevice::setDisplayContrast ( int p) | ||
636 | { | ||
637 | Q_UNUSED( p ) | ||
638 | return false; | ||
639 | } | ||
640 | |||
641 | /** | ||
642 | * @return return the max value for the brightness settings slider | ||
643 | * or 0 if the device doesn't support setting of a contrast | ||
644 | */ | ||
645 | int ODevice::displayContrastResolution ( ) const | ||
646 | { | ||
647 | return 0; | ||
648 | } | ||
649 | |||
650 | /** | ||
651 | * This returns the vendor as string | ||
652 | * @return Vendor as QString | ||
653 | */ | ||
654 | QString ODevice::vendorString ( ) const | ||
655 | { | ||
656 | return d-> m_vendorstr; | ||
657 | } | ||
658 | |||
659 | /** | ||
660 | * This returns the vendor as one of the values of OVendor | ||
661 | * @return OVendor | ||
662 | */ | ||
663 | OVendor ODevice::vendor ( ) const | ||
664 | { | ||
665 | return d-> m_vendor; | ||
666 | } | ||
667 | |||
668 | /** | ||
669 | * This returns the model as a string | ||
670 | * @return A string representing the model | ||
671 | */ | ||
672 | QString ODevice::modelString ( ) const | ||
673 | { | ||
674 | return d-> m_modelstr; | ||
675 | } | ||
676 | |||
677 | /** | ||
678 | * This does return the OModel used | ||
679 | */ | ||
680 | OModel ODevice::model ( ) const | ||
681 | { | ||
682 | return d-> m_model; | ||
683 | } | ||
684 | |||
685 | /** | ||
686 | * This does return the systen name | ||
687 | */ | ||
688 | QString ODevice::systemString ( ) const | ||
689 | { | ||
690 | return d-> m_systemstr; | ||
691 | } | ||
692 | |||
693 | /** | ||
694 | * Return System as OSystem value | ||
695 | */ | ||
696 | OSystem ODevice::system ( ) const | ||
697 | { | ||
698 | return d-> m_system; | ||
699 | } | ||
700 | |||
701 | /** | ||
702 | * @return the version string of the base system | ||
703 | */ | ||
704 | QString ODevice::systemVersionString ( ) const | ||
705 | { | ||
706 | return d-> m_sysverstr; | ||
707 | } | ||
708 | |||
709 | /** | ||
710 | * @return the current Transformation | ||
711 | */ | ||
712 | Transformation ODevice::rotation ( ) const | ||
713 | { | ||
714 | VirtRotation rot; | ||
715 | ODevice* that =(ODevice* )this; | ||
716 | that->virtual_hook( VIRTUAL_ROTATION, &rot ); | ||
717 | return rot.trans; | ||
718 | } | ||
719 | |||
720 | /** | ||
721 | * @return the current rotation direction | ||
722 | */ | ||
723 | ODirection ODevice::direction ( ) const | ||
724 | { | ||
725 | VirtDirection dir; | ||
726 | ODevice* that =(ODevice* )this; | ||
727 | that->virtual_hook( VIRTUAL_DIRECTION, &dir ); | ||
728 | return dir.direct; | ||
729 | } | ||
730 | |||
731 | /** | ||
732 | * This plays an alarmSound | ||
733 | */ | ||
734 | void ODevice::alarmSound ( ) | ||
735 | { | ||
736 | #ifndef QT_NO_SOUND | ||
737 | static Sound snd ( "alarm" ); | ||
738 | |||
739 | if ( snd. isFinished ( )) | ||
740 | snd. play ( ); | ||
741 | #endif | ||
742 | } | ||
743 | |||
744 | /** | ||
745 | * This plays a key sound | ||
746 | */ | ||
747 | void ODevice::keySound ( ) | ||
748 | { | ||
749 | #ifndef QT_NO_SOUND | ||
750 | static Sound snd ( "keysound" ); | ||
751 | |||
752 | if ( snd. isFinished ( )) | ||
753 | snd. play ( ); | ||
754 | #endif | ||
755 | } | ||
756 | |||
757 | /** | ||
758 | * This plays a touch sound | ||
759 | */ | ||
760 | void ODevice::touchSound ( ) | ||
761 | { | ||
762 | #ifndef QT_NO_SOUND | ||
763 | static Sound snd ( "touchsound" ); | ||
764 | |||
765 | if ( snd. isFinished ( )) | ||
766 | snd. play ( ); | ||
767 | #endif | ||
768 | } | ||
769 | |||
770 | /** | ||
771 | * This method will return a list of leds | ||
772 | * available on this device | ||
773 | * @return a list of LEDs. | ||
774 | */ | ||
775 | QValueList <OLed> ODevice::ledList ( ) const | ||
776 | { | ||
777 | return QValueList <OLed> ( ); | ||
778 | } | ||
779 | |||
780 | /** | ||
781 | * This does return the state of the LEDs | ||
782 | */ | ||
783 | QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const | ||
784 | { | ||
785 | return QValueList <OLedState> ( ); | ||
786 | } | ||
787 | |||
788 | /** | ||
789 | * @return the state for a given OLed | ||
790 | */ | ||
791 | OLedState ODevice::ledState ( OLed /*which*/ ) const | ||
792 | { | ||
793 | return Led_Off; | ||
794 | } | ||
795 | |||
796 | /** | ||
797 | * Set the state for a LED | ||
798 | * @param which Which OLed to use | ||
799 | * @param st The state to set | ||
800 | * @return success or failure | ||
801 | */ | ||
802 | bool ODevice::setLedState ( OLed which, OLedState st ) | ||
803 | { | ||
804 | Q_UNUSED( which ) | ||
805 | Q_UNUSED( st ) | ||
806 | return false; | ||
807 | } | ||
808 | |||
809 | /** | ||
810 | * @return if the device has a light sensor | ||
811 | */ | ||
812 | bool ODevice::hasLightSensor ( ) const | ||
813 | { | ||
814 | return false; | ||
815 | } | ||
816 | |||
817 | /** | ||
818 | * @return a value from the light sensor | ||
819 | */ | ||
820 | int ODevice::readLightSensor ( ) | ||
821 | { | ||
822 | return -1; | ||
823 | } | ||
824 | |||
825 | /** | ||
826 | * @return the light sensor resolution | ||
827 | */ | ||
828 | int ODevice::lightSensorResolution ( ) const | ||
829 | { | ||
830 | return 0; | ||
831 | } | ||
832 | |||
833 | /** | ||
834 | * @return if the device has a hinge sensor | ||
835 | */ | ||
836 | bool ODevice::hasHingeSensor ( ) const | ||
837 | { | ||
838 | VirtHasHinge hing; | ||
839 | ODevice* that =(ODevice* )this; | ||
840 | that->virtual_hook( VIRTUAL_HAS_HINGE, &hing ); | ||
841 | return hing.hasHinge; | ||
842 | } | ||
843 | |||
844 | /** | ||
845 | * @return a value from the hinge sensor | ||
846 | */ | ||
847 | OHingeStatus ODevice::readHingeSensor ( ) | ||
848 | { | ||
849 | VirtHingeStatus hing; | ||
850 | virtual_hook( VIRTUAL_HINGE, &hing ); | ||
851 | return hing.hingeStat; | ||
852 | } | ||
853 | |||
854 | /** | ||
855 | * @return a list with CPU frequencies supported by the hardware | ||
856 | */ | ||
857 | const QStrList &ODevice::allowedCpuFrequencies ( ) const | ||
858 | { | ||
859 | return *d->m_cpu_frequencies; | ||
860 | } | ||
861 | |||
862 | |||
863 | /** | ||
864 | * Set desired CPU frequency | ||
865 | * | ||
866 | * @param index index into d->m_cpu_frequencies of the frequency to be set | ||
867 | */ | ||
868 | bool ODevice::setCurrentCpuFrequency(uint index) | ||
869 | { | ||
870 | if (index >= d->m_cpu_frequencies->count()) | ||
871 | return false; | ||
872 | |||
873 | char *freq = d->m_cpu_frequencies->at(index); | ||
874 | qWarning("set freq to %s", freq); | ||
875 | |||
876 | int fd; | ||
877 | |||
878 | if ((fd = ::open("/proc/sys/cpu/0/speed", O_WRONLY)) >= 0) { | ||
879 | char writeCommand[50]; | ||
880 | const int count = sprintf(writeCommand, "%s\n", freq); | ||
881 | int res = (::write(fd, writeCommand, count) != -1); | ||
882 | ::close(fd); | ||
883 | return res; | ||
884 | } | ||
885 | |||
886 | return false; | ||
887 | } | ||
888 | |||
889 | |||
890 | /** | ||
891 | * @return a list of hardware buttons | ||
892 | */ | ||
893 | const QValueList <ODeviceButton> &ODevice::buttons ( ) | ||
894 | { | ||
895 | initButtons ( ); | ||
896 | |||
897 | return *d-> m_buttons; | ||
898 | } | ||
899 | |||
900 | /** | ||
901 | * @return The amount of time that would count as a hold | ||
902 | */ | ||
903 | uint ODevice::buttonHoldTime ( ) const | ||
904 | { | ||
905 | return d-> m_holdtime; | ||
906 | } | ||
907 | |||
908 | /** | ||
909 | * This method return a ODeviceButton for a key code | ||
910 | * or 0 if no special hardware button is available for the device | ||
911 | * | ||
912 | * @return The devicebutton or 0l | ||
913 | * @see ODeviceButton | ||
914 | */ | ||
915 | const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) | ||
916 | { | ||
917 | initButtons ( ); | ||
918 | |||
919 | for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) { | ||
920 | if ( (*it). keycode ( ) == code ) | ||
921 | return &(*it); | ||
922 | } | ||
923 | return 0; | ||
924 | } | ||
925 | |||
926 | void ODevice::reloadButtonMapping ( ) | ||
927 | { | ||
928 | initButtons ( ); | ||
929 | |||
930 | Config cfg ( "ButtonSettings" ); | ||
931 | |||
932 | for ( uint i = 0; i < d-> m_buttons-> count ( ); i++ ) { | ||
933 | ODeviceButton &b = ( *d-> m_buttons ) [i]; | ||
934 | QString group = "Button" + QString::number ( i ); | ||
935 | |||
936 | QCString pch, hch; | ||
937 | QCString pm, hm; | ||
938 | QByteArray pdata, hdata; | ||
939 | |||
940 | if ( cfg. hasGroup ( group )) { | ||
941 | cfg. setGroup ( group ); | ||
942 | pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( ); | ||
943 | pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( ); | ||
944 | // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); | ||
945 | |||
946 | hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( ); | ||
947 | hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( ); | ||
948 | // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); | ||
949 | } | ||
950 | |||
951 | b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); | ||
952 | |||
953 | b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); | ||
954 | } | ||
955 | } | ||
956 | |||
957 | void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) | ||
958 | { | ||
959 | initButtons ( ); | ||
960 | |||
961 | QString mb_chan; | ||
962 | |||
963 | if ( button >= (int) d-> m_buttons-> count ( )) | ||
964 | return; | ||
965 | |||
966 | ODeviceButton &b = ( *d-> m_buttons ) [button]; | ||
967 | b. setPressedAction ( action ); | ||
968 | |||
969 | mb_chan=b. pressedAction ( ). channel ( ); | ||
970 | |||
971 | Config buttonFile ( "ButtonSettings" ); | ||
972 | buttonFile. setGroup ( "Button" + QString::number ( button )); | ||
973 | buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); | ||
974 | buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( )); | ||
975 | |||
976 | //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( ))); | ||
977 | |||
978 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); | ||
979 | } | ||
980 | |||
981 | void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) | ||
982 | { | ||
983 | initButtons ( ); | ||
984 | |||
985 | if ( button >= (int) d-> m_buttons-> count ( )) | ||
986 | return; | ||
987 | |||
988 | ODeviceButton &b = ( *d-> m_buttons ) [button]; | ||
989 | b. setHeldAction ( action ); | ||
990 | |||
991 | Config buttonFile ( "ButtonSettings" ); | ||
992 | buttonFile. setGroup ( "Button" + QString::number ( button )); | ||
993 | buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( )); | ||
994 | buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( )); | ||
995 | |||
996 | //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( ))); | ||
997 | |||
998 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); | ||
999 | } | ||
1000 | void ODevice::virtual_hook(int id, void* data){ | ||
1001 | switch( id ) { | ||
1002 | case VIRTUAL_ROTATION:{ | ||
1003 | VirtRotation* rot = reinterpret_cast<VirtRotation*>( data ); | ||
1004 | rot->trans = d->m_rotation; | ||
1005 | break; | ||
1006 | } | ||
1007 | case VIRTUAL_DIRECTION:{ | ||
1008 | VirtDirection *dir = reinterpret_cast<VirtDirection*>( data ); | ||
1009 | dir->direct = d->m_direction; | ||
1010 | break; | ||
1011 | } | ||
1012 | case VIRTUAL_HAS_HINGE:{ | ||
1013 | VirtHasHinge *hin = reinterpret_cast<VirtHasHinge*>( data ); | ||
1014 | hin->hasHinge = false; | ||
1015 | break; | ||
1016 | } | ||
1017 | case VIRTUAL_HINGE:{ | ||
1018 | VirtHingeStatus *hin = reinterpret_cast<VirtHingeStatus*>( data ); | ||
1019 | hin->hingeStat = CASE_UNKNOWN; | ||
1020 | break; | ||
1021 | } | ||
1022 | } | ||
1023 | } | ||
1024 | |||
1025 | /************************************************** | ||
1026 | * | ||
1027 | * Yopy 3500/3700 | ||
1028 | * | ||
1029 | **************************************************/ | ||
1030 | |||
1031 | bool Yopy::isYopy ( ) | ||
1032 | { | ||
1033 | QFile f( "/proc/cpuinfo" ); | ||
1034 | if ( f. open ( IO_ReadOnly ) ) { | ||
1035 | QTextStream ts ( &f ); | ||
1036 | QString line; | ||
1037 | while( line = ts. readLine ( ) ) { | ||
1038 | if ( line. left ( 8 ) == "Hardware" ) { | ||
1039 | int loc = line. find ( ":" ); | ||
1040 | if ( loc != -1 ) { | ||
1041 | QString model = | ||
1042 | line. mid ( loc + 2 ). simplifyWhiteSpace( ); | ||
1043 | return ( model == "Yopy" ); | ||
1044 | } | ||
1045 | } | ||
1046 | } | ||
1047 | } | ||
1048 | return false; | ||
1049 | } | ||
1050 | |||
1051 | void Yopy::init ( ) | ||
1052 | { | ||
1053 | d-> m_vendorstr = "G.Mate"; | ||
1054 | d-> m_vendor = Vendor_GMate; | ||
1055 | d-> m_modelstr = "Yopy3700"; | ||
1056 | d-> m_model = Model_Yopy_3700; | ||
1057 | d-> m_rotation = Rot0; | ||
1058 | |||
1059 | d-> m_systemstr = "Linupy"; | ||
1060 | d-> m_system = System_Linupy; | ||
1061 | |||
1062 | QFile f ( "/etc/issue" ); | ||
1063 | if ( f. open ( IO_ReadOnly )) { | ||
1064 | QTextStream ts ( &f ); | ||
1065 | ts.readLine(); | ||
1066 | d-> m_sysverstr = ts. readLine ( ); | ||
1067 | f. close ( ); | ||
1068 | } | ||
1069 | } | ||
1070 | |||
1071 | void Yopy::initButtons ( ) | ||
1072 | { | ||
1073 | if ( d-> m_buttons ) | ||
1074 | return; | ||
1075 | |||
1076 | d-> m_buttons = new QValueList <ODeviceButton>; | ||
1077 | |||
1078 | for (uint i = 0; i < ( sizeof( yopy_buttons ) / sizeof(yopy_button)); i++) { | ||
1079 | |||
1080 | yopy_button *ib = yopy_buttons + i; | ||
1081 | |||
1082 | ODeviceButton b; | ||
1083 | |||
1084 | b. setKeycode ( ib-> code ); | ||
1085 | b. setUserText ( QObject::tr ( "Button", ib-> utext )); | ||
1086 | b. setPixmap ( Resource::loadPixmap ( ib-> pix )); | ||
1087 | b. setFactoryPresetPressedAction | ||
1088 | (OQCopMessage(makeChannel(ib->fpressedservice), ib->fpressedaction)); | ||
1089 | b. setFactoryPresetHeldAction | ||
1090 | (OQCopMessage(makeChannel(ib->fheldservice), ib->fheldaction)); | ||
1091 | |||
1092 | d-> m_buttons-> append ( b ); | ||
1093 | } | ||
1094 | reloadButtonMapping ( ); | ||
1095 | |||
1096 | QCopChannel *sysch = new QCopChannel("QPE/System", this); | ||
1097 | connect(sysch, SIGNAL(received(const QCString&,const QByteArray&)), | ||
1098 | this, SLOT(systemMessage(const QCString&,const QByteArray&))); | ||
1099 | } | ||
1100 | |||
1101 | bool Yopy::suspend() | ||
1102 | { | ||
1103 | /* Opie for Yopy does not implement its own power management at the | ||
1104 | moment. The public version runs parallel to X, and relies on the | ||
1105 | existing power management features. */ | ||
1106 | return false; | ||
1107 | } | ||
1108 | |||
1109 | bool Yopy::setDisplayBrightness(int /*bright*/) | ||
1110 | { | ||
1111 | /* The code here works, but is disabled as the current version runs | ||
1112 | parallel to X, and relies on the existing backlight demon. */ | ||
1113 | #if 0 | ||
1114 | if ( QFile::exists("/proc/sys/pm/light") ) { | ||
1115 | int fd = ::open("/proc/sys/pm/light", O_WRONLY); | ||
1116 | if (fd >= 0 ) { | ||
1117 | if (bright) | ||
1118 | ::write(fd, "1\n", 2); | ||
1119 | else | ||
1120 | ::write(fd, "0\n", 2); | ||
1121 | ::close(fd); | ||
1122 | return true; | ||
1123 | } | ||
1124 | } | ||
1125 | #endif | ||
1126 | return false; | ||
1127 | } | ||
1128 | |||
1129 | int Yopy::displayBrightnessResolution() const | ||
1130 | { | ||
1131 | return 2; | ||
1132 | } | ||
1133 | |||
1134 | /************************************************** | ||
1135 | * | ||
1136 | * iPAQ | ||
1137 | * | ||
1138 | **************************************************/ | ||
1139 | |||
1140 | void iPAQ::init ( ) | ||
1141 | { | ||
1142 | d-> m_vendorstr = "HP"; | ||
1143 | d-> m_vendor = Vendor_HP; | ||
1144 | |||
1145 | QFile f ( "/proc/hal/model" ); | ||
1146 | |||
1147 | if ( f. open ( IO_ReadOnly )) { | ||
1148 | QTextStream ts ( &f ); | ||
1149 | |||
1150 | d-> m_modelstr = "H" + ts. readLine ( ); | ||
1151 | |||
1152 | if ( d-> m_modelstr == "H3100" ) | ||
1153 | d-> m_model = Model_iPAQ_H31xx; | ||
1154 | else if ( d-> m_modelstr == "H3600" ) | ||
1155 | d-> m_model = Model_iPAQ_H36xx; | ||
1156 | else if ( d-> m_modelstr == "H3700" ) | ||
1157 | d-> m_model = Model_iPAQ_H37xx; | ||
1158 | else if ( d-> m_modelstr == "H3800" ) | ||
1159 | d-> m_model = Model_iPAQ_H38xx; | ||
1160 | else if ( d-> m_modelstr == "H3900" ) | ||
1161 | d-> m_model = Model_iPAQ_H39xx; | ||
1162 | else if ( d-> m_modelstr == "H5400" ) | ||
1163 | d-> m_model = Model_iPAQ_H5xxx; | ||
1164 | else | ||
1165 | d-> m_model = Model_Unknown; | ||
1166 | |||
1167 | f. close ( ); | ||
1168 | } | ||
1169 | |||
1170 | switch ( d-> m_model ) { | ||
1171 | case Model_iPAQ_H31xx: | ||
1172 | case Model_iPAQ_H38xx: | ||
1173 | d-> m_rotation = Rot90; | ||
1174 | break; | ||
1175 | case Model_iPAQ_H36xx: | ||
1176 | case Model_iPAQ_H37xx: | ||
1177 | case Model_iPAQ_H39xx: | ||
1178 | |||
1179 | default: | ||
1180 | d-> m_rotation = Rot270; | ||
1181 | break; | ||
1182 | case Model_iPAQ_H5xxx: | ||
1183 | d-> m_rotation = Rot0; | ||
1184 | } | ||
1185 | |||
1186 | f. setName ( "/etc/familiar-version" ); | ||
1187 | if ( f. open ( IO_ReadOnly )) { | ||
1188 | d-> m_systemstr = "Familiar"; | ||
1189 | d-> m_system = System_Familiar; | ||
1190 | |||
1191 | QTextStream ts ( &f ); | ||
1192 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); | ||
1193 | |||
1194 | f. close ( ); | ||
1195 | } else { | ||
1196 | f. setName ( "/etc/oz_version" ); | ||
1197 | |||
1198 | if ( f. open ( IO_ReadOnly )) { | ||
1199 | d-> m_systemstr = "OpenEmbedded/iPaq"; | ||
1200 | d-> m_system = System_Familiar; | ||
1201 | |||
1202 | QTextStream ts ( &f ); | ||
1203 | ts.setDevice ( &f ); | ||
1204 | d-> m_sysverstr = ts. readLine ( ); | ||
1205 | f. close ( ); | ||
1206 | } | ||
1207 | } | ||
1208 | |||
1209 | |||
1210 | |||
1211 | |||
1212 | |||
1213 | m_leds [0] = m_leds [1] = Led_Off; | ||
1214 | |||
1215 | m_power_timer = 0; | ||
1216 | |||
1217 | } | ||
1218 | |||
1219 | void iPAQ::initButtons ( ) | ||
1220 | { | ||
1221 | if ( d-> m_buttons ) | ||
1222 | return; | ||
1223 | |||
1224 | if ( isQWS( ) ) | ||
1225 | QWSServer::setKeyboardFilter ( this ); | ||
1226 | |||
1227 | d-> m_buttons = new QValueList <ODeviceButton>; | ||
1228 | |||
1229 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { | ||
1230 | i_button *ib = ipaq_buttons + i; | ||
1231 | ODeviceButton b; | ||
1232 | |||
1233 | if (( ib-> model & d-> m_model ) == d-> m_model ) { | ||
1234 | b. setKeycode ( ib-> code ); | ||
1235 | b. setUserText ( QObject::tr ( "Button", ib-> utext )); | ||
1236 | b. setPixmap ( Resource::loadPixmap ( ib-> pix )); | ||
1237 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); | ||
1238 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); | ||
1239 | |||
1240 | d-> m_buttons-> append ( b ); | ||
1241 | } | ||
1242 | } | ||
1243 | reloadButtonMapping ( ); | ||
1244 | |||
1245 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | ||
1246 | connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); | ||
1247 | } | ||
1248 | |||
1249 | |||
1250 | //#include <linux/h3600_ts.h> // including kernel headers is evil ... | ||
1251 | |||
1252 | typedef struct { | ||
1253 | unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ | ||
1254 | unsigned char TotalTime; /* Units of 5 seconds */ | ||
1255 | unsigned char OnTime; /* units of 100m/s */ | ||
1256 | unsigned char OffTime; /* units of 100m/s */ | ||
1257 | } LED_IN; | ||
1258 | |||
1259 | typedef struct { | ||
1260 | unsigned char mode; | ||
1261 | unsigned char pwr; | ||
1262 | unsigned char brightness; | ||
1263 | } FLITE_IN; | ||
1264 | |||
1265 | #define LED_ON OD_IOW( 'f', 5, LED_IN ) | ||
1266 | #define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) | ||
1267 | |||
1268 | |||
1269 | QValueList <OLed> iPAQ::ledList ( ) const | ||
1270 | { | ||
1271 | QValueList <OLed> vl; | ||
1272 | vl << Led_Power; | ||
1273 | |||
1274 | if ( d-> m_model == Model_iPAQ_H38xx ) | ||
1275 | vl << Led_BlueTooth; | ||
1276 | return vl; | ||
1277 | } | ||
1278 | |||
1279 | QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const | ||
1280 | { | ||
1281 | QValueList <OLedState> vl; | ||
1282 | |||
1283 | if ( l == Led_Power ) | ||
1284 | vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; | ||
1285 | else if ( l == Led_BlueTooth && d-> m_model == Model_iPAQ_H38xx ) | ||
1286 | vl << Led_Off; // << Led_On << ??? | ||
1287 | |||
1288 | return vl; | ||
1289 | } | ||
1290 | |||
1291 | OLedState iPAQ::ledState ( OLed l ) const | ||
1292 | { | ||
1293 | switch ( l ) { | ||
1294 | case Led_Power: | ||
1295 | return m_leds [0]; | ||
1296 | case Led_BlueTooth: | ||
1297 | return m_leds [1]; | ||
1298 | default: | ||
1299 | return Led_Off; | ||
1300 | } | ||
1301 | } | ||
1302 | |||
1303 | bool iPAQ::setLedState ( OLed l, OLedState st ) | ||
1304 | { | ||
1305 | static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK ); | ||
1306 | |||
1307 | if ( l == Led_Power ) { | ||
1308 | if ( fd >= 0 ) { | ||
1309 | LED_IN leds; | ||
1310 | ::memset ( &leds, 0, sizeof( leds )); | ||
1311 | leds. TotalTime = 0; | ||
1312 | leds. OnTime = 0; | ||
1313 | leds. OffTime = 1; | ||
1314 | leds. OffOnBlink = 2; | ||
1315 | |||
1316 | switch ( st ) { | ||
1317 | case Led_Off : leds. OffOnBlink = 0; break; | ||
1318 | case Led_On : leds. OffOnBlink = 1; break; | ||
1319 | case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; | ||
1320 | case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; | ||
1321 | } | ||
1322 | |||
1323 | if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { | ||
1324 | m_leds [0] = st; | ||
1325 | return true; | ||
1326 | } | ||
1327 | } | ||
1328 | } | ||
1329 | return false; | ||
1330 | } | ||
1331 | |||
1332 | |||
1333 | bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) | ||
1334 | { | ||
1335 | int newkeycode = keycode; | ||
1336 | |||
1337 | switch ( keycode ) { | ||
1338 | // H38xx/H39xx have no "Q" key anymore - this is now the Mail key | ||
1339 | case HardKey_Menu: { | ||
1340 | if (( d-> m_model == Model_iPAQ_H38xx ) || | ||
1341 | ( d-> m_model == Model_iPAQ_H39xx ) || | ||
1342 | ( d-> m_model == Model_iPAQ_H5xxx)) { | ||
1343 | newkeycode = HardKey_Mail; | ||
1344 | } | ||
1345 | break; | ||
1346 | } | ||
1347 | |||
1348 | // Rotate cursor keys 180° or 270° | ||
1349 | case Key_Left : | ||
1350 | case Key_Right: | ||
1351 | case Key_Up : | ||
1352 | case Key_Down : { | ||
1353 | |||
1354 | if (( d-> m_model == Model_iPAQ_H31xx ) || | ||
1355 | ( d-> m_model == Model_iPAQ_H38xx )) { | ||
1356 | newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4; | ||
1357 | } | ||
1358 | // Rotate the cursor keys by 270° | ||
1359 | // keycode - Key_Left = position of the button starting from left clockwise | ||
1360 | // add the rotation to it and modolo. No we've the original offset | ||
1361 | // add the offset to the Key_Left key | ||
1362 | if ( d-> m_model == Model_iPAQ_H5xxx ) | ||
1363 | newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4; | ||
1364 | break; | ||
1365 | } | ||
1366 | |||
1367 | // map Power Button short/long press to F34/F35 | ||
1368 | case Key_SysReq: { | ||
1369 | if ( isPress ) { | ||
1370 | if ( m_power_timer ) | ||
1371 | killTimer ( m_power_timer ); | ||
1372 | m_power_timer = startTimer ( 500 ); | ||
1373 | } | ||
1374 | else if ( m_power_timer ) { | ||
1375 | killTimer ( m_power_timer ); | ||
1376 | m_power_timer = 0; | ||
1377 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); | ||
1378 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); | ||
1379 | } | ||
1380 | newkeycode = Key_unknown; | ||
1381 | break; | ||
1382 | } | ||
1383 | } | ||
1384 | |||
1385 | if ( newkeycode != keycode ) { | ||
1386 | if ( newkeycode != Key_unknown ) | ||
1387 | QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); | ||
1388 | return true; | ||
1389 | } | ||
1390 | else | ||
1391 | return false; | ||
1392 | } | ||
1393 | |||
1394 | void iPAQ::timerEvent ( QTimerEvent * ) | ||
1395 | { | ||
1396 | killTimer ( m_power_timer ); | ||
1397 | m_power_timer = 0; | ||
1398 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); | ||
1399 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); | ||
1400 | } | ||
1401 | |||
1402 | |||
1403 | void iPAQ::alarmSound ( ) | ||
1404 | { | ||
1405 | #ifndef QT_NO_SOUND | ||
1406 | static Sound snd ( "alarm" ); | ||
1407 | int fd; | ||
1408 | int vol; | ||
1409 | bool vol_reset = false; | ||
1410 | |||
1411 | if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { | ||
1412 | if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { | ||
1413 | Config cfg ( "qpe" ); | ||
1414 | cfg. setGroup ( "Volume" ); | ||
1415 | |||
1416 | int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); | ||
1417 | if ( volalarm < 0 ) | ||
1418 | volalarm = 0; | ||
1419 | else if ( volalarm > 100 ) | ||
1420 | volalarm = 100; | ||
1421 | volalarm |= ( volalarm << 8 ); | ||
1422 | |||
1423 | if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) | ||
1424 | vol_reset = true; | ||
1425 | } | ||
1426 | } | ||
1427 | |||
1428 | snd. play ( ); | ||
1429 | while ( !snd. isFinished ( )) | ||
1430 | qApp-> processEvents ( ); | ||
1431 | |||
1432 | if ( fd >= 0 ) { | ||
1433 | if ( vol_reset ) | ||
1434 | ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); | ||
1435 | ::close ( fd ); | ||
1436 | } | ||
1437 | #endif | ||
1438 | } | ||
1439 | |||
1440 | |||
1441 | bool iPAQ::setSoftSuspend ( bool soft ) | ||
1442 | { | ||
1443 | bool res = false; | ||
1444 | int fd; | ||
1445 | |||
1446 | if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { | ||
1447 | if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) | ||
1448 | res = true; | ||
1449 | else | ||
1450 | ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); | ||
1451 | |||
1452 | ::close ( fd ); | ||
1453 | } | ||
1454 | else | ||
1455 | ::perror ( "/proc/sys/ts/suspend_button_mode" ); | ||
1456 | |||
1457 | return res; | ||
1458 | } | ||
1459 | |||
1460 | |||
1461 | bool iPAQ::setDisplayBrightness ( int bright ) | ||
1462 | { | ||
1463 | bool res = false; | ||
1464 | int fd; | ||
1465 | |||
1466 | if ( bright > 255 ) | ||
1467 | bright = 255; | ||
1468 | if ( bright < 0 ) | ||
1469 | bright = 0; | ||
1470 | |||
1471 | if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { | ||
1472 | FLITE_IN bl; | ||
1473 | bl. mode = 1; | ||
1474 | bl. pwr = bright ? 1 : 0; | ||
1475 | bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255; | ||
1476 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); | ||
1477 | ::close ( fd ); | ||
1478 | } | ||
1479 | return res; | ||
1480 | } | ||
1481 | |||
1482 | int iPAQ::displayBrightnessResolution ( ) const | ||
1483 | { | ||
1484 | switch ( model ( )) { | ||
1485 | case Model_iPAQ_H31xx: | ||
1486 | case Model_iPAQ_H36xx: | ||
1487 | case Model_iPAQ_H37xx: | ||
1488 | return 128; // really 256, but >128 could damage the LCD | ||
1489 | |||
1490 | case Model_iPAQ_H38xx: | ||
1491 | case Model_iPAQ_H39xx: | ||
1492 | return 64; | ||
1493 | case Model_iPAQ_H5xxx: | ||
1494 | return 255; | ||
1495 | |||
1496 | default: | ||
1497 | return 2; | ||
1498 | } | ||
1499 | } | ||
1500 | |||
1501 | |||
1502 | bool iPAQ::hasLightSensor ( ) const | ||
1503 | { | ||
1504 | return true; | ||
1505 | } | ||
1506 | |||
1507 | int iPAQ::readLightSensor ( ) | ||
1508 | { | ||
1509 | int fd; | ||
1510 | int val = -1; | ||
1511 | |||
1512 | if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { | ||
1513 | char buffer [8]; | ||
1514 | |||
1515 | if ( ::read ( fd, buffer, 5 ) == 5 ) { | ||
1516 | char *endptr; | ||
1517 | |||
1518 | buffer [4] = 0; | ||
1519 | val = ::strtol ( buffer + 2, &endptr, 16 ); | ||
1520 | |||
1521 | if ( *endptr != 0 ) | ||
1522 | val = -1; | ||
1523 | } | ||
1524 | ::close ( fd ); | ||
1525 | } | ||
1526 | |||
1527 | return val; | ||
1528 | } | ||
1529 | |||
1530 | int iPAQ::lightSensorResolution ( ) const | ||
1531 | { | ||
1532 | return 256; | ||
1533 | } | ||
1534 | |||
1535 | /************************************************** | ||
1536 | * | ||
1537 | * Zaurus | ||
1538 | * | ||
1539 | **************************************************/ | ||
1540 | |||
1541 | // Check whether this device is the sharp zaurus.. | ||
1542 | // FIXME This gets unnecessary complicated. We should think about splitting the Zaurus | ||
1543 | // class up into individual classes. We need three classes | ||
1544 | // | ||
1545 | // Zaurus-Collie (SA-model w/ 320x240 lcd, for SL5500 and SL5000) | ||
1546 | // Zaurus-Poodle (PXA-model w/ 320x240 lcd, for SL5600) | ||
1547 | // Zaurus-Corgi (PXA-model w/ 640x480 lcd, for C700, C750, C760, and C860) | ||
1548 | // | ||
1549 | // Only question right now is: Do we really need to do it? Because as soon | ||
1550 | // as the OpenZaurus kernel is ready, there will be a unified interface for all | ||
1551 | // Zaurus models (concerning apm, backlight, buttons, etc.) | ||
1552 | // | ||
1553 | // Comments? - mickeyl. | ||
1554 | |||
1555 | bool Zaurus::isZaurus() | ||
1556 | { | ||
1557 | |||
1558 | // If the special devices by embedix exist, it is quite simple: it is a Zaurus ! | ||
1559 | if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ) ){ | ||
1560 | return true; | ||
1561 | } | ||
1562 | |||
1563 | // On non-embedix kernels, we have to look closer. | ||
1564 | bool is_zaurus = false; | ||
1565 | QFile f ( "/proc/cpuinfo" ); | ||
1566 | if ( f. open ( IO_ReadOnly ) ) { | ||
1567 | QString model; | ||
1568 | QFile f ( "/proc/cpuinfo" ); | ||
1569 | |||
1570 | QTextStream ts ( &f ); | ||
1571 | QString line; | ||
1572 | while( line = ts. readLine ( ) ) { | ||
1573 | if ( line. left ( 8 ) == "Hardware" ) | ||
1574 | break; | ||
1575 | } | ||
1576 | int loc = line. find ( ":" ); | ||
1577 | if ( loc != -1 ) | ||
1578 | model = line. mid ( loc + 2 ). simplifyWhiteSpace( ); | ||
1579 | |||
1580 | if ( model == "Sharp-Collie" | ||
1581 | || model == "Collie" | ||
1582 | || model == "SHARP Corgi" | ||
1583 | || model == "SHARP Shepherd" | ||
1584 | || model == "SHARP Poodle" | ||
1585 | || model == "SHARP Husky" | ||
1586 | ) | ||
1587 | is_zaurus = true; | ||
1588 | |||
1589 | } | ||
1590 | return is_zaurus; | ||
1591 | } | ||
1592 | |||
1593 | |||
1594 | void Zaurus::init ( ) | ||
1595 | { | ||
1596 | d-> m_vendorstr = "Sharp"; | ||
1597 | d-> m_vendor = Vendor_Sharp; | ||
1598 | m_embedix = true; // Not openzaurus means: It has an embedix kernel ! | ||
1599 | |||
1600 | // QFile f ( "/proc/filesystems" ); | ||
1601 | QString model; | ||
1602 | |||
1603 | // It isn't a good idea to check the system configuration to | ||
1604 | // detect the distribution ! | ||
1605 | // Otherwise it may happen that any other distribution is detected as openzaurus, just | ||
1606 | // because it uses a jffs2 filesystem.. | ||
1607 | // (eilers) | ||
1608 | // if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { | ||
1609 | QFile f ("/etc/oz_version"); | ||
1610 | if ( f.exists() ){ | ||
1611 | d-> m_vendorstr = "OpenZaurus Team"; | ||
1612 | d-> m_systemstr = "OpenZaurus"; | ||
1613 | d-> m_system = System_OpenZaurus; | ||
1614 | |||
1615 | if ( f. open ( IO_ReadOnly )) { | ||
1616 | QTextStream ts ( &f ); | ||
1617 | d-> m_sysverstr = ts. readLine ( );//. mid ( 10 ); | ||
1618 | f. close ( ); | ||
1619 | } | ||
1620 | |||
1621 | // Openzaurus sometimes uses the embedix kernel! | ||
1622 | // => Check whether this is an embedix kernel | ||
1623 | FILE *uname = popen("uname -r", "r"); | ||
1624 | QString line; | ||
1625 | if ( f.open(IO_ReadOnly, uname) ) { | ||
1626 | QTextStream ts ( &f ); | ||
1627 | line = ts. readLine ( ); | ||
1628 | int loc = line. find ( "embedix" ); | ||
1629 | if ( loc != -1 ) | ||
1630 | m_embedix = true; | ||
1631 | else | ||
1632 | m_embedix = false; | ||
1633 | f. close ( ); | ||
1634 | } | ||
1635 | pclose(uname); | ||
1636 | } | ||
1637 | else { | ||
1638 | d-> m_systemstr = "Zaurus"; | ||
1639 | d-> m_system = System_Zaurus; | ||
1640 | } | ||
1641 | |||
1642 | f. setName ( "/proc/cpuinfo" ); | ||
1643 | if ( f. open ( IO_ReadOnly ) ) { | ||
1644 | QTextStream ts ( &f ); | ||
1645 | QString line; | ||
1646 | while( line = ts. readLine ( ) ) { | ||
1647 | if ( line. left ( 8 ) == "Hardware" ) | ||
1648 | break; | ||
1649 | } | ||
1650 | int loc = line. find ( ":" ); | ||
1651 | if ( loc != -1 ) | ||
1652 | model = line. mid ( loc + 2 ). simplifyWhiteSpace( ); | ||
1653 | } | ||
1654 | |||
1655 | if ( model == "SHARP Corgi" ) { | ||
1656 | d-> m_model = Model_Zaurus_SLC7x0; | ||
1657 | d-> m_modelstr = "Zaurus SL-C700"; | ||
1658 | } else if ( model == "SHARP Shepherd" ) { | ||
1659 | d-> m_model = Model_Zaurus_SLC7x0; | ||
1660 | d-> m_modelstr = "Zaurus SL-C750"; | ||
1661 | } else if ( model == "SHARP Husky" ) { | ||
1662 | d-> m_model = Model_Zaurus_SLC7x0; | ||
1663 | d-> m_modelstr = "Zaurus SL-C760"; | ||
1664 | } else if ( model == "SHARP Poodle" ) { | ||
1665 | d-> m_model = Model_Zaurus_SLB600; | ||
1666 | d-> m_modelstr = "Zaurus SL-B500 or SL-5600"; | ||
1667 | } else if ( model == "Sharp-Collie" || model == "Collie" ) { | ||
1668 | d-> m_model = Model_Zaurus_SL5500; | ||
1669 | d-> m_modelstr = "Zaurus SL-5500 or SL-5000d"; | ||
1670 | } else { | ||
1671 | d-> m_model = Model_Zaurus_SL5500; | ||
1672 | d-> m_modelstr = "Zaurus (Model unknown)"; | ||
1673 | } | ||
1674 | |||
1675 | switch ( d-> m_model ) { | ||
1676 | case Model_Zaurus_SLA300: | ||
1677 | d-> m_rotation = Rot0; | ||
1678 | break; | ||
1679 | case Model_Zaurus_SLC7x0: | ||
1680 | d-> m_rotation = rotation(); | ||
1681 | d-> m_direction = direction(); | ||
1682 | break; | ||
1683 | case Model_Zaurus_SLB600: | ||
1684 | case Model_Zaurus_SL5500: | ||
1685 | case Model_Zaurus_SL5000: | ||
1686 | default: | ||
1687 | d-> m_rotation = Rot270; | ||
1688 | break; | ||
1689 | } | ||
1690 | m_leds [0] = Led_Off; | ||
1691 | } | ||
1692 | |||
1693 | void Zaurus::initButtons ( ) | ||
1694 | { | ||
1695 | if ( d-> m_buttons ) | ||
1696 | return; | ||
1697 | |||
1698 | d-> m_buttons = new QValueList <ODeviceButton>; | ||
1699 | |||
1700 | struct z_button * pz_buttons; | ||
1701 | int buttoncount; | ||
1702 | switch ( d-> m_model ) { | ||
1703 | case Model_Zaurus_SLC7x0: | ||
1704 | pz_buttons = z_buttons_c700; | ||
1705 | buttoncount = ARRAY_SIZE(z_buttons_c700); | ||
1706 | break; | ||
1707 | default: | ||
1708 | pz_buttons = z_buttons; | ||
1709 | buttoncount = ARRAY_SIZE(z_buttons); | ||
1710 | break; | ||
1711 | } | ||
1712 | |||
1713 | for ( int i = 0; i < buttoncount; i++ ) { | ||
1714 | struct z_button *zb = pz_buttons + i; | ||
1715 | ODeviceButton b; | ||
1716 | |||
1717 | b. setKeycode ( zb-> code ); | ||
1718 | b. setUserText ( QObject::tr ( "Button", zb-> utext )); | ||
1719 | b. setPixmap ( Resource::loadPixmap ( zb-> pix )); | ||
1720 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb-> fpressedservice ), | ||
1721 | zb-> fpressedaction )); | ||
1722 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb-> fheldservice ), | ||
1723 | zb-> fheldaction )); | ||
1724 | |||
1725 | d-> m_buttons-> append ( b ); | ||
1726 | } | ||
1727 | |||
1728 | reloadButtonMapping ( ); | ||
1729 | |||
1730 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | ||
1731 | connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), | ||
1732 | this, SLOT( systemMessage(const QCString&,const QByteArray&))); | ||
1733 | } | ||
1734 | |||
1735 | #include <unistd.h> | ||
1736 | #include <fcntl.h> | ||
1737 | #include <sys/ioctl.h> | ||
1738 | |||
1739 | //#include <asm/sharp_char.h> // including kernel headers is evil ... | ||
1740 | |||
1741 | #define SHARP_DEV_IOCTL_COMMAND_START 0x5680 | ||
1742 | |||
1743 | #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) | ||
1744 | #define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) | ||
1745 | |||
1746 | #define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ | ||
1747 | #define SHARP_BUZ_KEYSOUND 2 /* key sound */ | ||
1748 | #define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ | ||
1749 | |||
1750 | /* --- for SHARP_BUZZER device --- */ | ||
1751 | |||
1752 | //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) | ||
1753 | //#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) | ||
1754 | |||
1755 | #define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) | ||
1756 | #define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2) | ||
1757 | #define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3) | ||
1758 | #define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4) | ||
1759 | #define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5) | ||
1760 | |||
1761 | //#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ | ||
1762 | //#define SHARP_BUZ_KEYSOUND 2 /* key sound */ | ||
1763 | |||
1764 | //#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */ | ||
1765 | //#define SHARP_PDA_WARNSOUND 4 /* warning occurred */ | ||
1766 | //#define SHARP_PDA_ERRORSOUND 5 /* error occurred */ | ||
1767 | //#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */ | ||
1768 | //#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */ | ||
1769 | //#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */ | ||
1770 | //#define SHARP_PDA_APPSTART 9 /* application start */ | ||
1771 | //#define SHARP_PDA_APPQUIT 10 /* application ends */ | ||
1772 | |||
1773 | //#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ | ||
1774 | //#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */ | ||
1775 | //#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */ | ||
1776 | //#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */ | ||
1777 | // | ||
1778 | |||
1779 | #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) | ||
1780 | #define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1) | ||
1781 | |||
1782 | #define SHARP_IOCTL_GET_ROTATION 0x413c | ||
1783 | |||
1784 | typedef struct sharp_led_status { | ||
1785 | int which; /* select which LED status is wanted. */ | ||
1786 | int status; /* set new led status if you call SHARP_LED_SETSTATUS */ | ||
1787 | } sharp_led_status; | ||
1788 | |||
1789 | #define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */ | ||
1790 | |||
1791 | #define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */ | ||
1792 | #define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */ | ||
1793 | #define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */ | ||
1794 | |||
1795 | // #include <asm/sharp_apm.h> // including kernel headers is evil ... | ||
1796 | |||
1797 | #define APM_IOCGEVTSRC OD_IOR( 'A', 203, int ) | ||
1798 | #define APM_IOCSEVTSRC OD_IORW( 'A', 204, int ) | ||
1799 | #define APM_EVT_POWER_BUTTON (1 << 0) | ||
1800 | |||
1801 | #define FL_IOCTL_STEP_CONTRAST 100 | ||
1802 | |||
1803 | |||
1804 | void Zaurus::buzzer ( int sound ) | ||
1805 | { | ||
1806 | #ifndef QT_NO_SOUND | ||
1807 | QString soundname; | ||
1808 | |||
1809 | // Not all devices have real sound | ||
1810 | if ( d->m_model == Model_Zaurus_SLC7x0 | ||
1811 | || d->m_model == Model_Zaurus_SLB600 ){ | ||
1812 | |||
1813 | switch ( sound ){ | ||
1814 | case SHARP_BUZ_SCHEDULE_ALARM: | ||
1815 | soundname = "alarm"; | ||
1816 | break; | ||
1817 | case SHARP_BUZ_TOUCHSOUND: | ||
1818 | soundname = "touchsound"; | ||
1819 | break; | ||
1820 | case SHARP_BUZ_KEYSOUND: | ||
1821 | soundname = "keysound"; | ||
1822 | break; | ||
1823 | default: | ||
1824 | soundname = "alarm"; | ||
1825 | |||
1826 | } | ||
1827 | } | ||
1828 | |||
1829 | // If a soundname is defined, we expect that this device has | ||
1830 | // sound capabilities.. Otherwise we expect to have the buzzer | ||
1831 | // device.. | ||
1832 | if ( !soundname.isEmpty() ){ | ||
1833 | int fd; | ||
1834 | int vol; | ||
1835 | bool vol_reset = false; | ||
1836 | |||
1837 | Sound snd ( soundname ); | ||
1838 | |||
1839 | if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { | ||
1840 | if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { | ||
1841 | Config cfg ( "qpe" ); | ||
1842 | cfg. setGroup ( "Volume" ); | ||
1843 | |||
1844 | int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); | ||
1845 | if ( volalarm < 0 ) | ||
1846 | volalarm = 0; | ||
1847 | else if ( volalarm > 100 ) | ||
1848 | volalarm = 100; | ||
1849 | volalarm |= ( volalarm << 8 ); | ||
1850 | |||
1851 | if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) | ||
1852 | vol_reset = true; | ||
1853 | } | ||
1854 | } | ||
1855 | |||
1856 | snd. play ( ); | ||
1857 | while ( !snd. isFinished ( )) | ||
1858 | qApp-> processEvents ( ); | ||
1859 | |||
1860 | if ( fd >= 0 ) { | ||
1861 | if ( vol_reset ) | ||
1862 | ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); | ||
1863 | ::close ( fd ); | ||
1864 | } | ||
1865 | } else { | ||
1866 | int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK ); | ||
1867 | |||
1868 | if ( fd >= 0 ) { | ||
1869 | ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); | ||
1870 | ::close ( fd ); | ||
1871 | } | ||
1872 | |||
1873 | } | ||
1874 | #endif | ||
1875 | } | ||
1876 | |||
1877 | |||
1878 | void Zaurus::alarmSound ( ) | ||
1879 | { | ||
1880 | buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); | ||
1881 | } | ||
1882 | |||
1883 | void Zaurus::touchSound ( ) | ||
1884 | { | ||
1885 | buzzer ( SHARP_BUZ_TOUCHSOUND ); | ||
1886 | } | ||
1887 | |||
1888 | void Zaurus::keySound ( ) | ||
1889 | { | ||
1890 | buzzer ( SHARP_BUZ_KEYSOUND ); | ||
1891 | } | ||
1892 | |||
1893 | |||
1894 | QValueList <OLed> Zaurus::ledList ( ) const | ||
1895 | { | ||
1896 | QValueList <OLed> vl; | ||
1897 | vl << Led_Mail; | ||
1898 | return vl; | ||
1899 | } | ||
1900 | |||
1901 | QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const | ||
1902 | { | ||
1903 | QValueList <OLedState> vl; | ||
1904 | |||
1905 | if ( l == Led_Mail ) | ||
1906 | vl << Led_Off << Led_On << Led_BlinkSlow; | ||
1907 | return vl; | ||
1908 | } | ||
1909 | |||
1910 | OLedState Zaurus::ledState ( OLed which ) const | ||
1911 | { | ||
1912 | if ( which == Led_Mail ) | ||
1913 | return m_leds [0]; | ||
1914 | else | ||
1915 | return Led_Off; | ||
1916 | } | ||
1917 | |||
1918 | bool Zaurus::setLedState ( OLed which, OLedState st ) | ||
1919 | { | ||
1920 | if (!m_embedix) // Currently not supported on non_embedix kernels | ||
1921 | return false; | ||
1922 | |||
1923 | static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); | ||
1924 | |||
1925 | if ( which == Led_Mail ) { | ||
1926 | if ( fd >= 0 ) { | ||
1927 | struct sharp_led_status leds; | ||
1928 | ::memset ( &leds, 0, sizeof( leds )); | ||
1929 | leds. which = SHARP_LED_MAIL_EXISTS; | ||
1930 | bool ok = true; | ||
1931 | |||
1932 | switch ( st ) { | ||
1933 | case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; | ||
1934 | case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; | ||
1935 | case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break; | ||
1936 | default : ok = false; | ||
1937 | } | ||
1938 | |||
1939 | if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) { | ||
1940 | m_leds [0] = st; | ||
1941 | return true; | ||
1942 | } | ||
1943 | } | ||
1944 | } | ||
1945 | return false; | ||
1946 | } | ||
1947 | |||
1948 | bool Zaurus::setSoftSuspend ( bool soft ) | ||
1949 | { | ||
1950 | if (!m_embedix) { | ||
1951 | /* non-Embedix kernels dont have kernel autosuspend */ | ||
1952 | return ODevice::setSoftSuspend( soft ); | ||
1953 | } | ||
1954 | |||
1955 | bool res = false; | ||
1956 | int fd; | ||
1957 | |||
1958 | if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || | ||
1959 | (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { | ||
1960 | |||
1961 | int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources | ||
1962 | |||
1963 | if ( sources >= 0 ) { | ||
1964 | if ( soft ) | ||
1965 | sources &= ~APM_EVT_POWER_BUTTON; | ||
1966 | else | ||
1967 | sources |= APM_EVT_POWER_BUTTON; | ||
1968 | |||
1969 | if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources | ||
1970 | res = true; | ||
1971 | else | ||
1972 | perror ( "APM_IOCGEVTSRC" ); | ||
1973 | } | ||
1974 | else | ||
1975 | perror ( "APM_IOCGEVTSRC" ); | ||
1976 | |||
1977 | ::close ( fd ); | ||
1978 | } | ||
1979 | else | ||
1980 | perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); | ||
1981 | |||
1982 | return res; | ||
1983 | } | ||
1984 | |||
1985 | |||
1986 | bool Zaurus::setDisplayBrightness ( int bright ) | ||
1987 | { | ||
1988 | //qDebug( "Zaurus::setDisplayBrightness( %d )", bright ); | ||
1989 | bool res = false; | ||
1990 | int fd; | ||
1991 | |||
1992 | if ( bright > 255 ) bright = 255; | ||
1993 | if ( bright < 0 ) bright = 0; | ||
1994 | |||
1995 | if ( m_embedix ) | ||
1996 | { | ||
1997 | if ( d->m_model == Model_Zaurus_SLC7x0 ) | ||
1998 | { | ||
1999 | //qDebug( "using special treatment for devices with the corgi backlight interface" ); | ||
2000 | // special treatment for devices with the corgi backlight interface | ||
2001 | if (( fd = ::open ( "/proc/driver/fl/corgi-bl", O_WRONLY )) >= 0 ) | ||
2002 | { | ||
2003 | int value = ( bright == 1 ) ? 1 : bright * ( 17.0 / 255.0 ); | ||
2004 | char writeCommand[100]; | ||
2005 | const int count = sprintf( writeCommand, "0x%x\n", value ); | ||
2006 | res = ( ::write ( fd, writeCommand, count ) != -1 ); | ||
2007 | ::close ( fd ); | ||
2008 | } | ||
2009 | return res; | ||
2010 | } | ||
2011 | else | ||
2012 | { | ||
2013 | // standard treatment for devices with the dumb embedix frontlight interface | ||
2014 | if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) { | ||
2015 | int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus | ||
2016 | if ( bright && !bl ) | ||
2017 | bl = 1; | ||
2018 | res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 ); | ||
2019 | ::close ( fd ); | ||
2020 | } | ||
2021 | } | ||
2022 | } | ||
2023 | else | ||
2024 | { | ||
2025 | // special treatment for the OpenZaurus unified interface | ||
2026 | #define FB_BACKLIGHT_SET_BRIGHTNESS _IOW('F', 1, u_int) /* set brightness */ | ||
2027 | if (( fd = ::open ( "/dev/fb0", O_WRONLY )) >= 0 ) { | ||
2028 | res = ( ::ioctl ( fd , FB_BACKLIGHT_SET_BRIGHTNESS, bright ) == 0 ); | ||
2029 | ::close ( fd ); | ||
2030 | } | ||
2031 | } | ||
2032 | return res; | ||
2033 | } | ||
2034 | |||
2035 | bool Zaurus::suspend ( ) | ||
2036 | { | ||
2037 | qDebug("ODevice::suspend"); | ||
2038 | if ( !isQWS( ) ) // only qwsserver is allowed to suspend | ||
2039 | return false; | ||
2040 | |||
2041 | if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices | ||
2042 | return false; | ||
2043 | |||
2044 | bool res = false; | ||
2045 | |||
2046 | struct timeval tvs, tvn; | ||
2047 | ::gettimeofday ( &tvs, 0 ); | ||
2048 | |||
2049 | ::sync ( ); // flush fs caches | ||
2050 | res = ( ::system ( "apm --suspend" ) == 0 ); | ||
2051 | |||
2052 | // This is needed because the iPAQ apm implementation is asynchronous and we | ||
2053 | // can not be sure when exactly the device is really suspended | ||
2054 | // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. | ||
2055 | |||
2056 | if ( res ) { | ||
2057 | do { // Yes, wait 15 seconds. This APM bug sucks big time. | ||
2058 | ::usleep ( 200 * 1000 ); | ||
2059 | ::gettimeofday ( &tvn, 0 ); | ||
2060 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 15000 ); | ||
2061 | } | ||
2062 | |||
2063 | QCopEnvelope ( "QPE/Rotation", "rotateDefault()" ); | ||
2064 | return res; | ||
2065 | } | ||
2066 | |||
2067 | |||
2068 | Transformation Zaurus::rotation ( ) const | ||
2069 | { | ||
2070 | Transformation rot; | ||
2071 | int handle = 0; | ||
2072 | int retval = 0; | ||
2073 | |||
2074 | switch ( d-> m_model ) { | ||
2075 | case Model_Zaurus_SLC7x0: | ||
2076 | handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); | ||
2077 | if (handle == -1) { | ||
2078 | return Rot270; | ||
2079 | } else { | ||
2080 | retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); | ||
2081 | ::close (handle); | ||
2082 | |||
2083 | if (retval == 2 ) | ||
2084 | rot = Rot0; | ||
2085 | else | ||
2086 | rot = Rot270; | ||
2087 | } | ||
2088 | break; | ||
2089 | case Model_Zaurus_SLA300: | ||
2090 | case Model_Zaurus_SLB600: | ||
2091 | case Model_Zaurus_SL5500: | ||
2092 | case Model_Zaurus_SL5000: | ||
2093 | default: | ||
2094 | rot = d-> m_rotation; | ||
2095 | break; | ||
2096 | } | ||
2097 | |||
2098 | return rot; | ||
2099 | } | ||
2100 | ODirection Zaurus::direction ( ) const | ||
2101 | { | ||
2102 | ODirection dir; | ||
2103 | int handle = 0; | ||
2104 | int retval = 0; | ||
2105 | switch ( d-> m_model ) { | ||
2106 | case Model_Zaurus_SLC7x0: | ||
2107 | handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); | ||
2108 | if (handle == -1) { | ||
2109 | dir = CW; | ||
2110 | } else { | ||
2111 | retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); | ||
2112 | ::close (handle); | ||
2113 | if (retval == 2 ) | ||
2114 | dir = CCW; | ||
2115 | else | ||
2116 | dir = CW; | ||
2117 | } | ||
2118 | break; | ||
2119 | case Model_Zaurus_SLA300: | ||
2120 | case Model_Zaurus_SLB600: | ||
2121 | case Model_Zaurus_SL5500: | ||
2122 | case Model_Zaurus_SL5000: | ||
2123 | default: | ||
2124 | dir = d-> m_direction; | ||
2125 | break; | ||
2126 | } | ||
2127 | return dir; | ||
2128 | |||
2129 | } | ||
2130 | |||
2131 | int Zaurus::displayBrightnessResolution ( ) const | ||
2132 | { | ||
2133 | if (m_embedix) | ||
2134 | return d->m_model == Model_Zaurus_SLC7x0 ? 18 : 5; | ||
2135 | else | ||
2136 | return 256; | ||
2137 | } | ||
2138 | |||
2139 | bool Zaurus::hasHingeSensor() const | ||
2140 | { | ||
2141 | return d->m_model == Model_Zaurus_SLC7x0; | ||
2142 | } | ||
2143 | |||
2144 | OHingeStatus Zaurus::readHingeSensor() | ||
2145 | { | ||
2146 | int handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); | ||
2147 | if (handle == -1) | ||
2148 | { | ||
2149 | qWarning("Zaurus::readHingeSensor() - failed (%s)", "unknown reason" ); //FIXME: use strerror | ||
2150 | return CASE_UNKNOWN; | ||
2151 | } | ||
2152 | else | ||
2153 | { | ||
2154 | int retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); | ||
2155 | ::close (handle); | ||
2156 | if ( retval == CASE_CLOSED || retval == CASE_PORTRAIT || retval == CASE_LANDSCAPE ) | ||
2157 | { | ||
2158 | qDebug( "Zaurus::readHingeSensor() - result = %d", retval ); | ||
2159 | return static_cast<OHingeStatus>( retval ); | ||
2160 | } | ||
2161 | else | ||
2162 | { | ||
2163 | qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" ); | ||
2164 | return CASE_UNKNOWN; | ||
2165 | } | ||
2166 | } | ||
2167 | } | ||
2168 | |||
2169 | |||
2170 | void Zaurus::virtual_hook( int id, void *data ) { | ||
2171 | switch( id ) { | ||
2172 | case VIRTUAL_ROTATION:{ | ||
2173 | VirtRotation* rot = reinterpret_cast<VirtRotation*>( data ); | ||
2174 | rot->trans = rotation(); | ||
2175 | break; | ||
2176 | } | ||
2177 | case VIRTUAL_DIRECTION:{ | ||
2178 | VirtDirection *dir = reinterpret_cast<VirtDirection*>( data ); | ||
2179 | dir->direct = direction(); | ||
2180 | break; | ||
2181 | } | ||
2182 | case VIRTUAL_HAS_HINGE:{ | ||
2183 | VirtHasHinge *hin = reinterpret_cast<VirtHasHinge*>( data ); | ||
2184 | hin->hasHinge = hasHingeSensor(); | ||
2185 | break; | ||
2186 | } | ||
2187 | case VIRTUAL_HINGE:{ | ||
2188 | VirtHingeStatus *hin = reinterpret_cast<VirtHingeStatus*>( data ); | ||
2189 | hin->hingeStat = readHingeSensor(); | ||
2190 | break; | ||
2191 | } | ||
2192 | default: | ||
2193 | ODevice::virtual_hook( id, data ); | ||
2194 | break; | ||
2195 | } | ||
2196 | } | ||
2197 | |||
2198 | /************************************************** | ||
2199 | * | ||
2200 | * SIMpad | ||
2201 | * | ||
2202 | **************************************************/ | ||
2203 | |||
2204 | void SIMpad::init ( ) | ||
2205 | { | ||
2206 | d-> m_vendorstr = "SIEMENS"; | ||
2207 | d-> m_vendor = Vendor_SIEMENS; | ||
2208 | |||
2209 | QFile f ( "/proc/hal/model" ); | ||
2210 | |||
2211 | //TODO Implement model checking | ||
2212 | //FIXME For now we assume an SL4 | ||
2213 | |||
2214 | d-> m_modelstr = "SL4"; | ||
2215 | d-> m_model = Model_SIMpad_SL4; | ||
2216 | |||
2217 | switch ( d-> m_model ) { | ||
2218 | default: | ||
2219 | d-> m_rotation = Rot0; | ||
2220 | d-> m_direction = CCW; | ||
2221 | d-> m_holdtime = 1000; // 1000ms | ||
2222 | |||
2223 | break; | ||
2224 | } | ||
2225 | |||
2226 | f. setName ( "/etc/familiar-version" ); | ||
2227 | if ( f. open ( IO_ReadOnly )) { | ||
2228 | d-> m_systemstr = "Familiar"; | ||
2229 | d-> m_system = System_Familiar; | ||
2230 | |||
2231 | QTextStream ts ( &f ); | ||
2232 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); | ||
2233 | |||
2234 | f. close ( ); | ||
2235 | } else { | ||
2236 | f. setName ( "/etc/oz_version" ); | ||
2237 | |||
2238 | if ( f. open ( IO_ReadOnly )) { | ||
2239 | d-> m_systemstr = "OpenEmbedded/SIMpad"; | ||
2240 | d-> m_system = System_OpenZaurus; | ||
2241 | |||
2242 | QTextStream ts ( &f ); | ||
2243 | ts.setDevice ( &f ); | ||
2244 | d-> m_sysverstr = ts. readLine ( ); | ||
2245 | f. close ( ); | ||
2246 | } | ||
2247 | } | ||
2248 | |||
2249 | m_leds [0] = m_leds [1] = Led_Off; | ||
2250 | |||
2251 | m_power_timer = 0; | ||
2252 | |||
2253 | } | ||
2254 | |||
2255 | void SIMpad::initButtons ( ) | ||
2256 | { | ||
2257 | if ( d-> m_buttons ) | ||
2258 | return; | ||
2259 | |||
2260 | if ( isQWS( ) ) | ||
2261 | QWSServer::setKeyboardFilter ( this ); | ||
2262 | |||
2263 | d-> m_buttons = new QValueList <ODeviceButton>; | ||
2264 | |||
2265 | for ( uint i = 0; i < ( sizeof( simpad_buttons ) / sizeof( s_button )); i++ ) { | ||
2266 | s_button *sb = simpad_buttons + i; | ||
2267 | ODeviceButton b; | ||
2268 | |||
2269 | if (( sb-> model & d-> m_model ) == d-> m_model ) { | ||
2270 | b. setKeycode ( sb-> code ); | ||
2271 | b. setUserText ( QObject::tr ( "Button", sb-> utext )); | ||
2272 | b. setPixmap ( Resource::loadPixmap ( sb-> pix )); | ||
2273 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( sb-> fpressedservice ), sb-> fpressedaction )); | ||
2274 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( sb-> fheldservice ), sb-> fheldaction )); | ||
2275 | |||
2276 | d-> m_buttons-> append ( b ); | ||
2277 | } | ||
2278 | } | ||
2279 | reloadButtonMapping ( ); | ||
2280 | |||
2281 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | ||
2282 | connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); | ||
2283 | } | ||
2284 | |||
2285 | // SIMpad boardcontrol register CS3 | ||
2286 | #define SIMPAD_BOARDCONTROL "/proc/cs3" | ||
2287 | #define SIMPAD_VCC_5V_EN 0x0001 // For 5V PCMCIA | ||
2288 | #define SIMPAD_VCC_3V_EN 0x0002 // FOR 3.3V PCMCIA | ||
2289 | #define SIMPAD_EN1 0x0004 // This is only for EPROM's | ||
2290 | #define SIMPAD_EN0 0x0008 // Both should be enable for 3.3V or 5V | ||
2291 | #define SIMPAD_DISPLAY_ON 0x0010 | ||
2292 | #define SIMPAD_PCMCIA_BUFF_DIS 0x0020 | ||
2293 | #define SIMPAD_MQ_RESET 0x0040 | ||
2294 | #define SIMPAD_PCMCIA_RESET 0x0080 | ||
2295 | #define SIMPAD_DECT_POWER_ON 0x0100 | ||
2296 | #define SIMPAD_IRDA_SD 0x0200 // Shutdown for powersave | ||
2297 | #define SIMPAD_RS232_ON 0x0400 | ||
2298 | #define SIMPAD_SD_MEDIAQ 0x0800 // Shutdown for powersave | ||
2299 | #define SIMPAD_LED2_ON 0x1000 | ||
2300 | #define SIMPAD_IRDA_MODE 0x2000 // Fast/Slow IrDA mode | ||
2301 | #define SIMPAD_ENABLE_5V 0x4000 // Enable 5V circuit | ||
2302 | #define SIMPAD_RESET_SIMCARD 0x8000 | ||
2303 | |||
2304 | //SIMpad touchscreen backlight strength control | ||
2305 | #define SIMPAD_BACKLIGHT_CONTROL "/proc/driver/mq200/registers/PWM_CONTROL" | ||
2306 | #define SIMPAD_BACKLIGHT_MASK 0x00a10044 | ||
2307 | |||
2308 | QValueList <OLed> SIMpad::ledList ( ) const | ||
2309 | { | ||
2310 | QValueList <OLed> vl; | ||
2311 | vl << Led_Power; //FIXME which LED is LED2 ? The green one or the amber one? | ||
2312 | //vl << Led_Mail; //TODO find out if LED1 is accessible anyway | ||
2313 | return vl; | ||
2314 | } | ||
2315 | |||
2316 | QValueList <OLedState> SIMpad::ledStateList ( OLed l ) const | ||
2317 | { | ||
2318 | QValueList <OLedState> vl; | ||
2319 | |||
2320 | if ( l == Led_Power ) //FIXME which LED is LED2 ? The green one or the amber one? | ||
2321 | vl << Led_Off << Led_On; | ||
2322 | //else if ( l == Led_Mail ) //TODO find out if LED1 is accessible anyway | ||
2323 | //vl << Led_Off; | ||
2324 | return vl; | ||
2325 | } | ||
2326 | |||
2327 | OLedState SIMpad::ledState ( OLed l ) const | ||
2328 | { | ||
2329 | switch ( l ) { | ||
2330 | case Led_Power: | ||
2331 | return m_leds [0]; | ||
2332 | //case Led_Mail: | ||
2333 | //return m_leds [1]; | ||
2334 | default: | ||
2335 | return Led_Off; | ||
2336 | } | ||
2337 | } | ||
2338 | |||
2339 | bool SIMpad::setLedState ( OLed l, OLedState st ) | ||
2340 | { | ||
2341 | static int fd = ::open ( SIMPAD_BOARDCONTROL, O_RDWR | O_NONBLOCK ); | ||
2342 | |||
2343 | if ( l == Led_Power ) { | ||
2344 | if ( fd >= 0 ) { | ||
2345 | LED_IN leds; | ||
2346 | ::memset ( &leds, 0, sizeof( leds )); | ||
2347 | leds. TotalTime = 0; | ||
2348 | leds. OnTime = 0; | ||
2349 | leds. OffTime = 1; | ||
2350 | leds. OffOnBlink = 2; | ||
2351 | |||
2352 | switch ( st ) { | ||
2353 | case Led_Off : leds. OffOnBlink = 0; break; | ||
2354 | case Led_On : leds. OffOnBlink = 1; break; | ||
2355 | case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; | ||
2356 | case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; | ||
2357 | } | ||
2358 | |||
2359 | { | ||
2360 | /*TODO Implement this like that: | ||
2361 | read from cs3 | ||
2362 | && with SIMPAD_LED2_ON | ||
2363 | write to cs3 */ | ||
2364 | m_leds [0] = st; | ||
2365 | return true; | ||
2366 | } | ||
2367 | } | ||
2368 | } | ||
2369 | return false; | ||
2370 | } | ||
2371 | |||
2372 | |||
2373 | bool SIMpad::filter ( int /*unicode*/, int /*keycode*/, int /*modifiers*/, bool /*isPress*/, bool /*autoRepeat*/ ) | ||
2374 | { | ||
2375 | //TODO | ||
2376 | return false; | ||
2377 | } | ||
2378 | |||
2379 | void SIMpad::timerEvent ( QTimerEvent * ) | ||
2380 | { | ||
2381 | killTimer ( m_power_timer ); | ||
2382 | m_power_timer = 0; | ||
2383 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); | ||
2384 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); | ||
2385 | } | ||
2386 | |||
2387 | |||
2388 | void SIMpad::alarmSound ( ) | ||
2389 | { | ||
2390 | #ifndef QT_NO_SOUND | ||
2391 | static Sound snd ( "alarm" ); | ||
2392 | int fd; | ||
2393 | int vol; | ||
2394 | bool vol_reset = false; | ||
2395 | |||
2396 | if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { | ||
2397 | if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { | ||
2398 | Config cfg ( "qpe" ); | ||
2399 | cfg. setGroup ( "Volume" ); | ||
2400 | |||
2401 | int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); | ||
2402 | if ( volalarm < 0 ) | ||
2403 | volalarm = 0; | ||
2404 | else if ( volalarm > 100 ) | ||
2405 | volalarm = 100; | ||
2406 | volalarm |= ( volalarm << 8 ); | ||
2407 | |||
2408 | if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) | ||
2409 | vol_reset = true; | ||
2410 | } | ||
2411 | } | ||
2412 | |||
2413 | snd. play ( ); | ||
2414 | while ( !snd. isFinished ( )) | ||
2415 | qApp-> processEvents ( ); | ||
2416 | |||
2417 | if ( fd >= 0 ) { | ||
2418 | if ( vol_reset ) | ||
2419 | ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); | ||
2420 | ::close ( fd ); | ||
2421 | } | ||
2422 | #endif | ||
2423 | } | ||
2424 | |||
2425 | |||
2426 | bool SIMpad::suspend ( ) // Must override because SIMpad does NOT have apm | ||
2427 | { | ||
2428 | qDebug( "ODevice for SIMpad: suspend()" ); | ||
2429 | if ( !isQWS( ) ) // only qwsserver is allowed to suspend | ||
2430 | return false; | ||
2431 | |||
2432 | bool res = false; | ||
2433 | |||
2434 | struct timeval tvs; | ||
2435 | ::gettimeofday ( &tvs, 0 ); | ||
2436 | |||
2437 | ::sync ( ); // flush fs caches | ||
2438 | res = ( ::system ( "cat /dev/fb/0 >/tmp/.buffer; echo > /proc/sys/pm/suspend; cat /tmp/.buffer >/dev/fb/0" ) == 0 ); //TODO make better :) | ||
2439 | |||
2440 | return res; | ||
2441 | } | ||
2442 | |||
2443 | |||
2444 | bool SIMpad::setSoftSuspend ( bool soft ) | ||
2445 | { | ||
2446 | qDebug( "ODevice for SIMpad: UNHANDLED setSoftSuspend(%s)", soft? "on" : "off" ); | ||
2447 | return false; | ||
2448 | } | ||
2449 | |||
2450 | |||
2451 | bool SIMpad::setDisplayStatus ( bool on ) | ||
2452 | { | ||
2453 | qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" ); | ||
2454 | |||
2455 | bool res = false; | ||
2456 | |||
2457 | QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :) | ||
2458 | |||
2459 | res = ( ::system( (const char*) cmdline ) == 0 ); | ||
2460 | |||
2461 | return res; | ||
2462 | } | ||
2463 | |||
2464 | |||
2465 | bool SIMpad::setDisplayBrightness ( int bright ) | ||
2466 | { | ||
2467 | qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright ); | ||
2468 | bool res = false; | ||
2469 | int fd; | ||
2470 | |||
2471 | if ( bright > 255 ) | ||
2472 | bright = 255; | ||
2473 | if ( bright < 1 ) | ||
2474 | bright = 0; | ||
2475 | |||
2476 | if (( fd = ::open ( SIMPAD_BACKLIGHT_CONTROL, O_WRONLY )) >= 0 ) { | ||
2477 | int value = 255 - bright; | ||
2478 | const int mask = SIMPAD_BACKLIGHT_MASK; | ||
2479 | value = value << 8; | ||
2480 | value += mask; | ||
2481 | char writeCommand[100]; | ||
2482 | const int count = sprintf( writeCommand, "0x%x\n", value ); | ||
2483 | res = ( ::write ( fd, writeCommand, count ) != -1 ); | ||
2484 | ::close ( fd ); | ||
2485 | } | ||
2486 | return res; | ||
2487 | } | ||
2488 | |||
2489 | |||
2490 | int SIMpad::displayBrightnessResolution ( ) const | ||
2491 | { | ||
2492 | return 255; // All SIMpad models share the same display | ||
2493 | } | ||
2494 | |||
2495 | /************************************************** | ||
2496 | * | ||
2497 | * Ramses | ||
2498 | * | ||
2499 | **************************************************/ | ||
2500 | |||
2501 | void Ramses::init() | ||
2502 | { | ||
2503 | d->m_vendorstr = "M und N"; | ||
2504 | d->m_vendor = Vendor_MundN; | ||
2505 | |||
2506 | QFile f("/proc/sys/board/ramses"); | ||
2507 | |||
2508 | d->m_modelstr = "Ramses"; | ||
2509 | d->m_model = Model_Ramses_MNCI; | ||
2510 | |||
2511 | d->m_rotation = Rot90; | ||
2512 | d->m_holdtime = 1000; | ||
2513 | |||
2514 | f.setName("/etc/oz_version"); | ||
2515 | |||
2516 | if (f.open(IO_ReadOnly)) { | ||
2517 | d->m_systemstr = "OpenEmbedded/Ramses"; | ||
2518 | d->m_system = System_OpenZaurus; | ||
2519 | |||
2520 | QTextStream ts(&f); | ||
2521 | ts.setDevice(&f); | ||
2522 | d->m_sysverstr = ts.readLine(); | ||
2523 | f.close(); | ||
2524 | } | ||
2525 | |||
2526 | m_power_timer = 0; | ||
2527 | |||
2528 | #ifdef QT_QWS_ALLOW_OVERCLOCK | ||
2529 | #warning *** Overclocking enabled - this may fry your hardware - you have been warned *** | ||
2530 | #define OC(x...) x | ||
2531 | #else | ||
2532 | #define OC(x...) | ||
2533 | #endif | ||
2534 | |||
2535 | |||
2536 | // This table is true for a Intel XScale PXA 255 | ||
2537 | |||
2538 | d->m_cpu_frequencies->append("99000"); // mem= 99, run= 99, turbo= 99, PXbus= 50 | ||
2539 | OC(d->m_cpu_frequencies->append("118000"); ) // mem=118, run=118, turbo=118, PXbus= 59 OC'd mem | ||
2540 | d->m_cpu_frequencies->append("199100"); // mem= 99, run=199, turbo=199, PXbus= 99 | ||
2541 | OC(d->m_cpu_frequencies->append("236000"); ) // mem=118, run=236, turbo=236, PXbus=118 OC'd mem | ||
2542 | d->m_cpu_frequencies->append("298600"); // mem= 99, run=199, turbo=298, PXbus= 99 | ||
2543 | OC(d->m_cpu_frequencies->append("354000"); ) // mem=118, run=236, turbo=354, PXbus=118 OC'd mem | ||
2544 | d->m_cpu_frequencies->append("398099"); // mem= 99, run=199, turbo=398, PXbus= 99 | ||
2545 | d->m_cpu_frequencies->append("398100"); // mem= 99, run=398, turbo=398, PXbus=196 | ||
2546 | OC(d->m_cpu_frequencies->append("471000"); ) // mem=118, run=471, turbo=471, PXbus=236 OC'd mem/core/bus | ||
2547 | |||
2548 | } | ||
2549 | |||
2550 | bool Ramses::filter(int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat) | ||
2551 | { | ||
2552 | Q_UNUSED( keycode ); | ||
2553 | Q_UNUSED( modifiers ); | ||
2554 | Q_UNUSED( isPress ); | ||
2555 | Q_UNUSED( autoRepeat ); | ||
2556 | return false; | ||
2557 | } | ||
2558 | |||
2559 | void Ramses::timerEvent(QTimerEvent *) | ||
2560 | { | ||
2561 | killTimer(m_power_timer); | ||
2562 | m_power_timer = 0; | ||
2563 | QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, true, false); | ||
2564 | QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, false, false); | ||
2565 | } | ||
2566 | |||
2567 | |||
2568 | bool Ramses::setSoftSuspend(bool soft) | ||
2569 | { | ||
2570 | qDebug("Ramses::setSoftSuspend(%d)", soft); | ||
2571 | #if 0 | ||
2572 | bool res = false; | ||
2573 | int fd; | ||
2574 | |||
2575 | if (((fd = ::open("/dev/apm_bios", O_RDWR)) >= 0) || | ||
2576 | ((fd = ::open("/dev/misc/apm_bios",O_RDWR)) >= 0)) { | ||
2577 | |||
2578 | int sources = ::ioctl(fd, APM_IOCGEVTSRC, 0); // get current event sources | ||
2579 | |||
2580 | if (sources >= 0) { | ||
2581 | if (soft) | ||
2582 | sources &= ~APM_EVT_POWER_BUTTON; | ||
2583 | else | ||
2584 | sources |= APM_EVT_POWER_BUTTON; | ||
2585 | |||
2586 | if (::ioctl(fd, APM_IOCSEVTSRC, sources) >= 0) // set new event sources | ||
2587 | res = true; | ||
2588 | else | ||
2589 | perror("APM_IOCGEVTSRC"); | ||
2590 | } | ||
2591 | else | ||
2592 | perror("APM_IOCGEVTSRC"); | ||
2593 | |||
2594 | ::close(fd); | ||
2595 | } | ||
2596 | else | ||
2597 | perror("/dev/apm_bios or /dev/misc/apm_bios"); | ||
2598 | |||
2599 | return res; | ||
2600 | #else | ||
2601 | return true; | ||
2602 | #endif | ||
2603 | } | ||
2604 | |||
2605 | bool Ramses::suspend ( ) | ||
2606 | { | ||
2607 | qDebug("Ramses::suspend"); | ||
2608 | return false; | ||
2609 | } | ||
2610 | |||
2611 | /** | ||
2612 | * This sets the display on or off | ||
2613 | */ | ||
2614 | bool Ramses::setDisplayStatus(bool on) | ||
2615 | { | ||
2616 | qDebug("Ramses::setDisplayStatus(%d)", on); | ||
2617 | #if 0 | ||
2618 | bool res = false; | ||
2619 | int fd; | ||
2620 | |||
2621 | if ((fd = ::open ("/dev/fb/0", O_RDWR)) >= 0) { | ||
2622 | res = (::ioctl(fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN) == 0); | ||
2623 | ::close(fd); | ||
2624 | } | ||
2625 | return res; | ||
2626 | #else | ||
2627 | return true; | ||
2628 | #endif | ||
2629 | } | ||
2630 | |||
2631 | |||
2632 | /* | ||
2633 | * We get something between 0..255 into us | ||
2634 | */ | ||
2635 | bool Ramses::setDisplayBrightness(int bright) | ||
2636 | { | ||
2637 | qDebug("Ramses::setDisplayBrightness(%d)", bright); | ||
2638 | bool res = false; | ||
2639 | int fd; | ||
2640 | |||
2641 | // pwm1 brighness: 20 steps 500..0 (dunkel->hell) | ||
2642 | |||
2643 | if (bright > 255 ) | ||
2644 | bright = 255; | ||
2645 | if (bright < 0) | ||
2646 | bright = 0; | ||
2647 | |||
2648 | // Turn backlight completely off | ||
2649 | if ((fd = ::open("/proc/sys/board/lcd_backlight", O_WRONLY)) >= 0) { | ||
2650 | char writeCommand[10]; | ||
2651 | const int count = sprintf(writeCommand, "%d\n", bright ? 1 : 0); | ||
2652 | res = (::write(fd, writeCommand, count) != -1); | ||
2653 | ::close(fd); | ||
2654 | } | ||
2655 | |||
2656 | // scale backlight brightness to hardware | ||
2657 | bright = 500-(bright * 500 / 255); | ||
2658 | if ((fd = ::open("/proc/sys/board/pwm1", O_WRONLY)) >= 0) { | ||
2659 | qDebug(" %d -> pwm1", bright); | ||
2660 | char writeCommand[100]; | ||
2661 | const int count = sprintf(writeCommand, "%d\n", bright); | ||
2662 | res = (::write(fd, writeCommand, count) != -1); | ||
2663 | ::close(fd); | ||
2664 | } | ||
2665 | return res; | ||
2666 | } | ||
2667 | |||
2668 | |||
2669 | int Ramses::displayBrightnessResolution() const | ||
2670 | { | ||
2671 | return 32; | ||
2672 | } | ||
2673 | |||
2674 | bool Ramses::setDisplayContrast(int contr) | ||
2675 | { | ||
2676 | qDebug("Ramses::setDisplayContrast(%d)", contr); | ||
2677 | bool res = false; | ||
2678 | int fd; | ||
2679 | |||
2680 | // pwm0 contrast: 20 steps 79..90 (dunkel->hell) | ||
2681 | |||
2682 | if (contr > 255 ) | ||
2683 | contr = 255; | ||
2684 | if (contr < 0) | ||
2685 | contr = 0; | ||
2686 | contr = 90 - (contr * 20 / 255); | ||
2687 | |||
2688 | if ((fd = ::open("/proc/sys/board/pwm0", O_WRONLY)) >= 0) { | ||
2689 | qDebug(" %d -> pwm0", contr); | ||
2690 | char writeCommand[100]; | ||
2691 | const int count = sprintf(writeCommand, "%d\n", contr); | ||
2692 | res = (::write(fd, writeCommand, count) != -1); | ||
2693 | res = true; | ||
2694 | ::close(fd); | ||
2695 | } | ||
2696 | return res; | ||
2697 | } | ||
2698 | |||
2699 | |||
2700 | int Ramses::displayContrastResolution() const | ||
2701 | { | ||
2702 | return 20; | ||
2703 | } | ||
2704 | |||
2705 | |||
2706 | /************************************************** | ||
2707 | * * | ||
2708 | * Jornada * | ||
2709 | * * | ||
2710 | **************************************************/ | ||
2711 | |||
2712 | |||
2713 | bool Jornada::isJornada ( ) | ||
2714 | { | ||
2715 | QFile f( "/proc/cpuinfo" ); | ||
2716 | if ( f. open ( IO_ReadOnly ) ) { | ||
2717 | QTextStream ts ( &f ); | ||
2718 | QString line; | ||
2719 | while( line = ts. readLine ( ) ) { | ||
2720 | if ( line. left ( 8 ) == "Hardware" ) { | ||
2721 | int loc = line. find ( ":" ); | ||
2722 | if ( loc != -1 ) { | ||
2723 | QString model = | ||
2724 | line. mid ( loc + 2 ). simplifyWhiteSpace( ); | ||
2725 | return ( model == "HP Jornada 56x" ); | ||
2726 | } | ||
2727 | } | ||
2728 | } | ||
2729 | } | ||
2730 | return false; | ||
2731 | } | ||
2732 | |||
2733 | void Jornada::init ( ) | ||
2734 | { | ||
2735 | d-> m_vendorstr = "HP"; | ||
2736 | d-> m_vendor = Vendor_HP; | ||
2737 | d-> m_modelstr = "Jornada 56x"; | ||
2738 | d-> m_model = Model_Jornada_56x; | ||
2739 | d-> m_systemstr = "Familiar"; | ||
2740 | d-> m_system = System_Familiar; | ||
2741 | d-> m_rotation = Rot0; | ||
2742 | |||
2743 | QFile f ( "/etc/familiar-version" ); | ||
2744 | f. setName ( "/etc/familiar-version" ); | ||
2745 | if ( f. open ( IO_ReadOnly )) { | ||
2746 | |||
2747 | QTextStream ts ( &f ); | ||
2748 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); | ||
2749 | |||
2750 | f. close ( ); | ||
2751 | } | ||
2752 | } | ||
2753 | |||
2754 | #if 0 | ||
2755 | void Jornada::initButtons ( ) | ||
2756 | { | ||
2757 | if ( d-> m_buttons ) | ||
2758 | return; | ||
2759 | |||
2760 | // Simulation uses iPAQ 3660 device buttons | ||
2761 | |||
2762 | qDebug ( "init Buttons" ); | ||
2763 | d-> m_buttons = new QValueList <ODeviceButton>; | ||
2764 | |||
2765 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { | ||
2766 | i_button *ib = ipaq_buttons + i; | ||
2767 | ODeviceButton b; | ||
2768 | |||
2769 | if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { | ||
2770 | b. setKeycode ( ib-> code ); | ||
2771 | b. setUserText ( QObject::tr ( "Button", ib-> utext )); | ||
2772 | b. setPixmap ( Resource::loadPixmap ( ib-> pix )); | ||
2773 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); | ||
2774 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); | ||
2775 | d-> m_buttons-> append ( b ); | ||
2776 | } | ||
2777 | } | ||
2778 | reloadButtonMapping ( ); | ||
2779 | |||
2780 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | ||
2781 | connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); | ||
2782 | } | ||
2783 | #endif | ||
2784 | int Jornada::displayBrightnessResolution ( ) const | ||
2785 | { | ||
2786 | return 255; | ||
2787 | } | ||
2788 | |||
2789 | bool Jornada::setDisplayBrightness ( int bright ) | ||
2790 | { | ||
2791 | bool res = false; | ||
2792 | int fd; | ||
2793 | |||
2794 | if ( bright > 255 ) | ||
2795 | bright = 255; | ||
2796 | if ( bright < 0 ) | ||
2797 | bright = 0; | ||
2798 | |||
2799 | if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { | ||
2800 | FLITE_IN bl; | ||
2801 | bl. mode = 1; | ||
2802 | bl. pwr = bright ? 1 : 0; | ||
2803 | bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255; | ||
2804 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); | ||
2805 | ::close ( fd ); | ||
2806 | } | ||
2807 | return res; | ||
2808 | } | ||
2809 | |||
2810 | bool Jornada::setSoftSuspend ( bool soft ) | ||
2811 | { | ||
2812 | bool res = false; | ||
2813 | int fd; | ||
2814 | |||
2815 | if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { | ||
2816 | if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) | ||
2817 | res = true; | ||
2818 | else | ||
2819 | ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); | ||
2820 | |||
2821 | ::close ( fd ); | ||
2822 | } | ||
2823 | else | ||
2824 | ::perror ( "/proc/sys/ts/suspend_button_mode" ); | ||
2825 | |||
2826 | return res; | ||
2827 | } | ||