summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-01-01 19:59:53 (UTC)
committer mickeyl <mickeyl>2005-01-01 19:59:53 (UTC)
commitd4b1226ed820ec06ba07361f31dbb35ce559a4cc (patch) (unidiff)
treed86de5da06a19d5d2a9efd8f1cbc5c90657b0406
parent5f310dcd91f574c1b34ca99c157c0b93e6ae1e16 (diff)
downloadopie-d4b1226ed820ec06ba07361f31dbb35ce559a4cc.zip
opie-d4b1226ed820ec06ba07361f31dbb35ce559a4cc.tar.gz
opie-d4b1226ed820ec06ba07361f31dbb35ce559a4cc.tar.bz2
slightly more correct way to calculate the brightness
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_zaurus.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/libopie2/opiecore/device/odevice_zaurus.cpp b/libopie2/opiecore/device/odevice_zaurus.cpp
index e75e777..fb23e1d 100644
--- a/libopie2/opiecore/device/odevice_zaurus.cpp
+++ b/libopie2/opiecore/device/odevice_zaurus.cpp
@@ -1,590 +1,590 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) The Opie Team <opie-devel@handhelds.org> 3              Copyright (C) The Opie Team <opie-devel@handhelds.org>
4 =. Copyright (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de> 4 =. Copyright (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "odevice_zaurus.h" 30#include "odevice_zaurus.h"
31 31
32/* QT */ 32/* QT */
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qfile.h> 34#include <qfile.h>
35#include <qtextstream.h> 35#include <qtextstream.h>
36#include <qwindowsystem_qws.h> 36#include <qwindowsystem_qws.h>
37 37
38/* OPIE */ 38/* OPIE */
39#include <qpe/config.h> 39#include <qpe/config.h>
40#include <qpe/resource.h> 40#include <qpe/resource.h>
41#include <qpe/sound.h> 41#include <qpe/sound.h>
42#include <qpe/qcopenvelope_qws.h> 42#include <qpe/qcopenvelope_qws.h>
43 43
44/* STD */ 44/* STD */
45#include <fcntl.h> 45#include <fcntl.h>
46#include <math.h> 46#include <math.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <signal.h> 48#include <signal.h>
49#include <sys/ioctl.h> 49#include <sys/ioctl.h>
50#include <sys/time.h> 50#include <sys/time.h>
51#include <unistd.h> 51#include <unistd.h>
52#ifndef QT_NO_SOUND 52#ifndef QT_NO_SOUND
53#include <linux/soundcard.h> 53#include <linux/soundcard.h>
54#endif 54#endif
55 55
56using namespace Opie::Core; 56using namespace Opie::Core;
57using namespace Opie::Core::Internal; 57using namespace Opie::Core::Internal;
58 58
59struct z_button z_buttons [] = { 59struct z_button z_buttons [] = {
60 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 60 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
61 "devicebuttons/z_calendar", 61 "devicebuttons/z_calendar",
62 "datebook", "nextView()", 62 "datebook", "nextView()",
63 "today", "raise()" }, 63 "today", "raise()" },
64 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 64 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
65 "devicebuttons/z_contact", 65 "devicebuttons/z_contact",
66 "addressbook", "raise()", 66 "addressbook", "raise()",
67 "addressbook", "beamBusinessCard()" }, 67 "addressbook", "beamBusinessCard()" },
68 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 68 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
69 "devicebuttons/z_home", 69 "devicebuttons/z_home",
70 "QPE/Launcher", "home()", 70 "QPE/Launcher", "home()",
71 "buttonsettings", "raise()" }, 71 "buttonsettings", "raise()" },
72 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 72 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
73 "devicebuttons/z_menu", 73 "devicebuttons/z_menu",
74 "QPE/TaskBar", "toggleMenu()", 74 "QPE/TaskBar", "toggleMenu()",
75 "QPE/TaskBar", "toggleStartMenu()" }, 75 "QPE/TaskBar", "toggleStartMenu()" },
76 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), 76 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"),
77 "devicebuttons/z_mail", 77 "devicebuttons/z_mail",
78 "opiemail", "raise()", 78 "opiemail", "raise()",
79 "opiemail", "newMail()" }, 79 "opiemail", "newMail()" },
80}; 80};
81 81
82struct z_button z_buttons_c700 [] = { 82struct z_button z_buttons_c700 [] = {
83 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 83 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
84 "devicebuttons/z_calendar", 84 "devicebuttons/z_calendar",
85 "datebook", "nextView()", 85 "datebook", "nextView()",
86 "today", "raise()" }, 86 "today", "raise()" },
87 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 87 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
88 "devicebuttons/z_contact", 88 "devicebuttons/z_contact",
89 "addressbook", "raise()", 89 "addressbook", "raise()",
90 "addressbook", "beamBusinessCard()" }, 90 "addressbook", "beamBusinessCard()" },
91 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 91 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
92 "devicebuttons/z_home", 92 "devicebuttons/z_home",
93 "QPE/Launcher", "home()", 93 "QPE/Launcher", "home()",
94 "buttonsettings", "raise()" }, 94 "buttonsettings", "raise()" },
95 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 95 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
96 "devicebuttons/z_menu", 96 "devicebuttons/z_menu",
97 "QPE/TaskBar", "toggleMenu()", 97 "QPE/TaskBar", "toggleMenu()",
98 "QPE/TaskBar", "toggleStartMenu()" }, 98 "QPE/TaskBar", "toggleStartMenu()" },
99 { Qt::Key_F14, QT_TRANSLATE_NOOP("Button", "Display Rotate"), 99 { Qt::Key_F14, QT_TRANSLATE_NOOP("Button", "Display Rotate"),
100 "devicebuttons/z_hinge", 100 "devicebuttons/z_hinge",
101 "QPE/Rotation", "rotateDefault()", 101 "QPE/Rotation", "rotateDefault()",
102 "QPE/Dummy", "doNothing()" }, 102 "QPE/Dummy", "doNothing()" },
103}; 103};
104 104
105// FIXME This gets unnecessary complicated. We should think about splitting the Zaurus 105// FIXME This gets unnecessary complicated. We should think about splitting the Zaurus
106// class up into individual classes. We need three classes 106// class up into individual classes. We need three classes
107// 107//
108// Zaurus-Collie (SA-model w/ 320x240 lcd, for SL5500 and SL5000) 108// Zaurus-Collie (SA-model w/ 320x240 lcd, for SL5500 and SL5000)
109// Zaurus-Poodle (PXA-model w/ 320x240 lcd, for SL5600) 109// Zaurus-Poodle (PXA-model w/ 320x240 lcd, for SL5600)
110// Zaurus-Corgi (PXA-model w/ 640x480 lcd, for C700, C750, C760, C860, C3000) 110// Zaurus-Corgi (PXA-model w/ 640x480 lcd, for C700, C750, C760, C860, C3000)
111// Zaurus-Tosa (PXA-model w/ 480x640 lcd, for SL6000) 111// Zaurus-Tosa (PXA-model w/ 480x640 lcd, for SL6000)
112// 112//
113// Only question right now is: Do we really need to do it? Because as soon 113// Only question right now is: Do we really need to do it? Because as soon
114// as the OpenZaurus kernel is ready, there will be a unified interface for all 114// as the OpenZaurus kernel is ready, there will be a unified interface for all
115// Zaurus models (concerning apm, backlight, buttons, etc.) 115// Zaurus models (concerning apm, backlight, buttons, etc.)
116// 116//
117// Comments? - mickeyl. 117// Comments? - mickeyl.
118 118
119void Zaurus::init(const QString& cpu_info) 119void Zaurus::init(const QString& cpu_info)
120{ 120{
121 // generic distribution code already scanned /etc/issue at that point - 121 // generic distribution code already scanned /etc/issue at that point -
122 // embedix releases contain "Embedix <version> | Linux for Embedded Devices" 122 // embedix releases contain "Embedix <version> | Linux for Embedded Devices"
123 if ( d->m_sysverstr.contains( "embedix", false ) ) 123 if ( d->m_sysverstr.contains( "embedix", false ) )
124 { 124 {
125 d->m_vendorstr = "Sharp"; 125 d->m_vendorstr = "Sharp";
126 d->m_vendor = Vendor_Sharp; 126 d->m_vendor = Vendor_Sharp;
127 d->m_systemstr = "Zaurus"; 127 d->m_systemstr = "Zaurus";
128 d->m_system = System_Zaurus; 128 d->m_system = System_Zaurus;
129 m_embedix = true; 129 m_embedix = true;
130 } 130 }
131 else 131 else
132 { 132 {
133 d->m_vendorstr = "OpenZaurus Team"; 133 d->m_vendorstr = "OpenZaurus Team";
134 d->m_systemstr = "OpenZaurus"; 134 d->m_systemstr = "OpenZaurus";
135 d->m_system = System_OpenZaurus; 135 d->m_system = System_OpenZaurus;
136 // sysver already gathered 136 // sysver already gathered
137 137
138 // OpenZaurus sometimes uses the embedix kernel, check if this is one 138 // OpenZaurus sometimes uses the embedix kernel, check if this is one
139 FILE *uname = popen("uname -r", "r"); 139 FILE *uname = popen("uname -r", "r");
140 QFile f; 140 QFile f;
141 QString line; 141 QString line;
142 if ( f.open(IO_ReadOnly, uname) ) { 142 if ( f.open(IO_ReadOnly, uname) ) {
143 QTextStream ts ( &f ); 143 QTextStream ts ( &f );
144 line = ts. readLine(); 144 line = ts. readLine();
145 int loc = line. find ( "embedix" ); 145 int loc = line. find ( "embedix" );
146 if ( loc != -1 ) 146 if ( loc != -1 )
147 m_embedix = true; 147 m_embedix = true;
148 else 148 else
149 m_embedix = false; 149 m_embedix = false;
150 f.close(); 150 f.close();
151 } 151 }
152 pclose(uname); 152 pclose(uname);
153 } 153 }
154 154
155 // check the Zaurus model 155 // check the Zaurus model
156 QString model; 156 QString model;
157 int loc = cpu_info.find( ":" ); 157 int loc = cpu_info.find( ":" );
158 if ( loc != -1 ) 158 if ( loc != -1 )
159 model = cpu_info.mid( loc+2 ).simplifyWhiteSpace(); 159 model = cpu_info.mid( loc+2 ).simplifyWhiteSpace();
160 else 160 else
161 model = cpu_info; 161 model = cpu_info;
162 162
163 if ( model == "SHARP Corgi" ) { 163 if ( model == "SHARP Corgi" ) {
164 d->m_model = Model_Zaurus_SLC7x0; 164 d->m_model = Model_Zaurus_SLC7x0;
165 d->m_modelstr = "Zaurus SL-C700"; 165 d->m_modelstr = "Zaurus SL-C700";
166 } else if ( model == "SHARP Shepherd" ) { 166 } else if ( model == "SHARP Shepherd" ) {
167 d->m_model = Model_Zaurus_SLC7x0; 167 d->m_model = Model_Zaurus_SLC7x0;
168 d->m_modelstr = "Zaurus SL-C750"; 168 d->m_modelstr = "Zaurus SL-C750";
169 } else if ( model == "SHARP Husky" ) { 169 } else if ( model == "SHARP Husky" ) {
170 d->m_model = Model_Zaurus_SLC7x0; 170 d->m_model = Model_Zaurus_SLC7x0;
171 d->m_modelstr = "Zaurus SL-C760 or SL-C860"; 171 d->m_modelstr = "Zaurus SL-C760 or SL-C860";
172 } else if ( model == "SHARP Poodle" ) { 172 } else if ( model == "SHARP Poodle" ) {
173 d->m_model = Model_Zaurus_SLB600; 173 d->m_model = Model_Zaurus_SLB600;
174 d->m_modelstr = "Zaurus SL-B500 or SL-5600"; 174 d->m_modelstr = "Zaurus SL-B500 or SL-5600";
175 } else if ( model == "Sharp-Collie" || model == "Collie" ) { 175 } else if ( model == "Sharp-Collie" || model == "Collie" ) {
176 d->m_model = Model_Zaurus_SL5500; 176 d->m_model = Model_Zaurus_SL5500;
177 d->m_modelstr = "Zaurus SL-5500 or SL-5000d"; 177 d->m_modelstr = "Zaurus SL-5500 or SL-5000d";
178 } else if ( model == "SHARP Tosa" ) { 178 } else if ( model == "SHARP Tosa" ) {
179 d->m_model = Model_Zaurus_SL6000; 179 d->m_model = Model_Zaurus_SL6000;
180 d->m_modelstr = "Zaurus SL-6000"; 180 d->m_modelstr = "Zaurus SL-6000";
181 } else { 181 } else {
182 d->m_model = Model_Zaurus_SL5500; 182 d->m_model = Model_Zaurus_SL5500;
183 d->m_modelstr = "Unkown Zaurus"; 183 d->m_modelstr = "Unkown Zaurus";
184 } 184 }
185 185
186 // set initial rotation 186 // set initial rotation
187 switch( d->m_model ) { 187 switch( d->m_model ) {
188 case Model_Zaurus_SL6000: // fallthrough 188 case Model_Zaurus_SL6000: // fallthrough
189 case Model_Zaurus_SLA300: 189 case Model_Zaurus_SLA300:
190 d->m_rotation = Rot0; 190 d->m_rotation = Rot0;
191 break; 191 break;
192 case Model_Zaurus_SLC7x0: 192 case Model_Zaurus_SLC7x0:
193 d->m_rotation = rotation(); 193 d->m_rotation = rotation();
194 d->m_direction = direction(); 194 d->m_direction = direction();
195 break; 195 break;
196 case Model_Zaurus_SLB600: // fallthrough 196 case Model_Zaurus_SLB600: // fallthrough
197 case Model_Zaurus_SL5500: // fallthrough 197 case Model_Zaurus_SL5500: // fallthrough
198 case Model_Zaurus_SL5000: 198 case Model_Zaurus_SL5000:
199 default: 199 default:
200 d->m_rotation = Rot270; 200 d->m_rotation = Rot270;
201 break; 201 break;
202 } 202 }
203 m_leds [0] = Led_Off; 203 m_leds [0] = Led_Off;
204} 204}
205 205
206void Zaurus::initButtons() 206void Zaurus::initButtons()
207{ 207{
208 if ( d->m_buttons ) 208 if ( d->m_buttons )
209 return; 209 return;
210 210
211 d->m_buttons = new QValueList <ODeviceButton>; 211 d->m_buttons = new QValueList <ODeviceButton>;
212 212
213 struct z_button * pz_buttons; 213 struct z_button * pz_buttons;
214 int buttoncount; 214 int buttoncount;
215 switch ( d->m_model ) { 215 switch ( d->m_model ) {
216 case Model_Zaurus_SLC7x0: 216 case Model_Zaurus_SLC7x0:
217 pz_buttons = z_buttons_c700; 217 pz_buttons = z_buttons_c700;
218 buttoncount = ARRAY_SIZE(z_buttons_c700); 218 buttoncount = ARRAY_SIZE(z_buttons_c700);
219 break; 219 break;
220 default: 220 default:
221 pz_buttons = z_buttons; 221 pz_buttons = z_buttons;
222 buttoncount = ARRAY_SIZE(z_buttons); 222 buttoncount = ARRAY_SIZE(z_buttons);
223 break; 223 break;
224 } 224 }
225 225
226 for ( int i = 0; i < buttoncount; i++ ) { 226 for ( int i = 0; i < buttoncount; i++ ) {
227 struct z_button *zb = pz_buttons + i; 227 struct z_button *zb = pz_buttons + i;
228 ODeviceButton b; 228 ODeviceButton b;
229 229
230 b. setKeycode ( zb->code ); 230 b. setKeycode ( zb->code );
231 b. setUserText ( QObject::tr ( "Button", zb->utext )); 231 b. setUserText ( QObject::tr ( "Button", zb->utext ));
232 b. setPixmap ( Resource::loadPixmap ( zb->pix )); 232 b. setPixmap ( Resource::loadPixmap ( zb->pix ));
233 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb->fpressedservice ), 233 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb->fpressedservice ),
234 zb->fpressedaction )); 234 zb->fpressedaction ));
235 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb->fheldservice ), 235 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb->fheldservice ),
236 zb->fheldaction )); 236 zb->fheldaction ));
237 237
238 d->m_buttons->append ( b ); 238 d->m_buttons->append ( b );
239 } 239 }
240 240
241 reloadButtonMapping(); 241 reloadButtonMapping();
242} 242}
243 243
244 244
245 245
246typedef struct sharp_led_status { 246typedef struct sharp_led_status {
247 int which; /* select which LED status is wanted. */ 247 int which; /* select which LED status is wanted. */
248 int status; /* set new led status if you call SHARP_LED_SETSTATUS */ 248 int status; /* set new led status if you call SHARP_LED_SETSTATUS */
249} sharp_led_status; 249} sharp_led_status;
250 250
251void Zaurus::buzzer( int sound ) 251void Zaurus::buzzer( int sound )
252{ 252{
253#ifndef QT_NO_SOUND 253#ifndef QT_NO_SOUND
254 Sound *snd = 0; 254 Sound *snd = 0;
255 255
256 // Not all devices have real sound 256 // Not all devices have real sound
257 if ( d->m_model == Model_Zaurus_SLC7x0 257 if ( d->m_model == Model_Zaurus_SLC7x0
258 || d->m_model == Model_Zaurus_SLB600 258 || d->m_model == Model_Zaurus_SLB600
259 || d->m_model == Model_Zaurus_SL6000 ) { 259 || d->m_model == Model_Zaurus_SL6000 ) {
260 260
261 switch ( sound ){ 261 switch ( sound ){
262 case SHARP_BUZ_TOUCHSOUND: { 262 case SHARP_BUZ_TOUCHSOUND: {
263 static Sound touch_sound("touchsound"); 263 static Sound touch_sound("touchsound");
264 snd = &touch_sound; 264 snd = &touch_sound;
265 } 265 }
266 break; 266 break;
267 case SHARP_BUZ_KEYSOUND: { 267 case SHARP_BUZ_KEYSOUND: {
268 static Sound key_sound( "keysound" ); 268 static Sound key_sound( "keysound" );
269 snd = &key_sound; 269 snd = &key_sound;
270 } 270 }
271 break; 271 break;
272 case SHARP_BUZ_SCHEDULE_ALARM: 272 case SHARP_BUZ_SCHEDULE_ALARM:
273 default: { 273 default: {
274 static Sound alarm_sound("alarm"); 274 static Sound alarm_sound("alarm");
275 snd = &alarm_sound; 275 snd = &alarm_sound;
276 } 276 }
277 break; 277 break;
278 } 278 }
279 } 279 }
280 280
281 // If a soundname is defined, we expect that this device has 281 // If a soundname is defined, we expect that this device has
282 // sound capabilities.. Otherwise we expect to have the buzzer 282 // sound capabilities.. Otherwise we expect to have the buzzer
283 // device.. 283 // device..
284 if ( snd && snd->isFinished() ){ 284 if ( snd && snd->isFinished() ){
285 changeMixerForAlarm( 0, "/dev/sound/mixer", snd ); 285 changeMixerForAlarm( 0, "/dev/sound/mixer", snd );
286 snd->play(); 286 snd->play();
287 } else if( !snd ) { 287 } else if( !snd ) {
288 int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK ); 288 int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK );
289 289
290 if ( fd >= 0 ) { 290 if ( fd >= 0 ) {
291 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); 291 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound );
292 ::close ( fd ); 292 ::close ( fd );
293 } 293 }
294 294
295 } 295 }
296#endif 296#endif
297} 297}
298 298
299 299
300void Zaurus::playAlarmSound() 300void Zaurus::playAlarmSound()
301{ 301{
302 buzzer( SHARP_BUZ_SCHEDULE_ALARM ); 302 buzzer( SHARP_BUZ_SCHEDULE_ALARM );
303} 303}
304 304
305void Zaurus::playTouchSound() 305void Zaurus::playTouchSound()
306{ 306{
307 buzzer( SHARP_BUZ_TOUCHSOUND ); 307 buzzer( SHARP_BUZ_TOUCHSOUND );
308} 308}
309 309
310void Zaurus::playKeySound() 310void Zaurus::playKeySound()
311{ 311{
312 buzzer( SHARP_BUZ_KEYSOUND ); 312 buzzer( SHARP_BUZ_KEYSOUND );
313} 313}
314 314
315 315
316QValueList <OLed> Zaurus::ledList() const 316QValueList <OLed> Zaurus::ledList() const
317{ 317{
318 QValueList <OLed> vl; 318 QValueList <OLed> vl;
319 vl << Led_Mail; 319 vl << Led_Mail;
320 return vl; 320 return vl;
321} 321}
322 322
323QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const 323QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const
324{ 324{
325 QValueList <OLedState> vl; 325 QValueList <OLedState> vl;
326 326
327 if ( l == Led_Mail ) 327 if ( l == Led_Mail )
328 vl << Led_Off << Led_On << Led_BlinkSlow; 328 vl << Led_Off << Led_On << Led_BlinkSlow;
329 return vl; 329 return vl;
330} 330}
331 331
332OLedState Zaurus::ledState ( OLed which ) const 332OLedState Zaurus::ledState ( OLed which ) const
333{ 333{
334 if ( which == Led_Mail ) 334 if ( which == Led_Mail )
335 return m_leds [0]; 335 return m_leds [0];
336 else 336 else
337 return Led_Off; 337 return Led_Off;
338} 338}
339 339
340bool Zaurus::setLedState ( OLed which, OLedState st ) 340bool Zaurus::setLedState ( OLed which, OLedState st )
341{ 341{
342 if (!m_embedix) // Currently not supported on non_embedix kernels 342 if (!m_embedix) // Currently not supported on non_embedix kernels
343 return false; 343 return false;
344 344
345 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); 345 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK );
346 346
347 if ( which == Led_Mail ) { 347 if ( which == Led_Mail ) {
348 if ( fd >= 0 ) { 348 if ( fd >= 0 ) {
349 struct sharp_led_status leds; 349 struct sharp_led_status leds;
350 ::memset ( &leds, 0, sizeof( leds )); 350 ::memset ( &leds, 0, sizeof( leds ));
351 leds. which = SHARP_LED_MAIL_EXISTS; 351 leds. which = SHARP_LED_MAIL_EXISTS;
352 bool ok = true; 352 bool ok = true;
353 353
354 switch ( st ) { 354 switch ( st ) {
355 case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; 355 case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break;
356 case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; 356 case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break;
357 case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break; 357 case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break;
358 default : ok = false; 358 default : ok = false;
359 } 359 }
360 360
361 if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) { 361 if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) {
362 m_leds [0] = st; 362 m_leds [0] = st;
363 return true; 363 return true;
364 } 364 }
365 } 365 }
366 } 366 }
367 return false; 367 return false;
368} 368}
369 369
370bool Zaurus::setSoftSuspend ( bool soft ) 370bool Zaurus::setSoftSuspend ( bool soft )
371{ 371{
372 if (!m_embedix) { 372 if (!m_embedix) {
373 /* non-Embedix kernels dont have kernel autosuspend */ 373 /* non-Embedix kernels dont have kernel autosuspend */
374 return ODevice::setSoftSuspend( soft ); 374 return ODevice::setSoftSuspend( soft );
375 } 375 }
376 376
377 bool res = false; 377 bool res = false;
378 int fd; 378 int fd;
379 379
380 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || 380 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
381 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { 381 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
382 382
383 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources 383 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources
384 384
385 if ( sources >= 0 ) { 385 if ( sources >= 0 ) {
386 if ( soft ) 386 if ( soft )
387 sources &= ~APM_EVT_POWER_BUTTON; 387 sources &= ~APM_EVT_POWER_BUTTON;
388 else 388 else
389 sources |= APM_EVT_POWER_BUTTON; 389 sources |= APM_EVT_POWER_BUTTON;
390 390
391 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources 391 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources
392 res = true; 392 res = true;
393 else 393 else
394 perror ( "APM_IOCGEVTSRC" ); 394 perror ( "APM_IOCGEVTSRC" );
395 } 395 }
396 else 396 else
397 perror ( "APM_IOCGEVTSRC" ); 397 perror ( "APM_IOCGEVTSRC" );
398 398
399 ::close ( fd ); 399 ::close ( fd );
400 } 400 }
401 else 401 else
402 perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); 402 perror ( "/dev/apm_bios or /dev/misc/apm_bios" );
403 403
404 return res; 404 return res;
405} 405}
406 406
407bool Zaurus::setDisplayBrightness( int bright ) 407bool Zaurus::setDisplayBrightness( int bright )
408{ 408{
409 //qDebug( "Zaurus::setDisplayBrightness( %d )", bright ); 409 //qDebug( "Zaurus::setDisplayBrightness( %d )", bright );
410 bool res = false; 410 bool res = false;
411 411
412 if ( bright > 255 ) bright = 255; 412 if ( bright > 255 ) bright = 255;
413 if ( bright < 0 ) bright = 0; 413 if ( bright < 0 ) bright = 0;
414 414
415 if ( m_embedix ) 415 if ( m_embedix )
416 { 416 {
417 int numberOfSteps = displayBrightnessResolution(); 417 int numberOfSteps = displayBrightnessResolution();
418 int fd = ::open( SHARP_FL_IOCTL_DEVICE, O_WRONLY|O_NONBLOCK ); 418 int fd = ::open( SHARP_FL_IOCTL_DEVICE, O_WRONLY|O_NONBLOCK );
419 if ( fd ) 419 if ( fd )
420 { 420 {
421 int val = ( numberOfSteps * 255 ) / 255; 421 int val = ( bright * numberOfSteps ) / 255;
422 res = ( ::ioctl ( fd, SHARP_FL_IOCTL_STEP_CONTRAST, val ) == 0 ); 422 res = ( ::ioctl ( fd, SHARP_FL_IOCTL_STEP_CONTRAST, val ) == 0 );
423 ::close ( fd ); 423 ::close ( fd );
424 } 424 }
425 } 425 }
426 else 426 else
427 { 427 {
428 qDebug( "ODevice handling for non-embedix kernels not yet implemented" ); 428 qDebug( "ODevice handling for non-embedix kernels not yet implemented" );
429 } 429 }
430 return res; 430 return res;
431} 431}
432 432
433bool Zaurus::setDisplayStatus( bool on ) 433bool Zaurus::setDisplayStatus( bool on )
434{ 434{
435 bool res = false; 435 bool res = false;
436 if ( m_embedix ) 436 if ( m_embedix )
437 { 437 {
438 int fd = ::open( SHARP_FL_IOCTL_DEVICE, O_WRONLY|O_NONBLOCK ); 438 int fd = ::open( SHARP_FL_IOCTL_DEVICE, O_WRONLY|O_NONBLOCK );
439 if ( fd ) 439 if ( fd )
440 { 440 {
441 int ioctlnum = on ? SHARP_FL_IOCTL_ON : SHARP_FL_IOCTL_OFF; 441 int ioctlnum = on ? SHARP_FL_IOCTL_ON : SHARP_FL_IOCTL_OFF;
442 res = ( ::ioctl ( fd, ioctlnum, 0 ) == 0 ); 442 res = ( ::ioctl ( fd, ioctlnum, 0 ) == 0 );
443 ::close ( fd ); 443 ::close ( fd );
444 } 444 }
445 } 445 }
446 else 446 else
447 { 447 {
448 qDebug( "ODevice handling for non-embedix kernels not yet implemented" ); 448 qDebug( "ODevice handling for non-embedix kernels not yet implemented" );
449 } 449 }
450 return res; 450 return res;
451} 451}
452 452
453bool Zaurus::suspend() 453bool Zaurus::suspend()
454{ 454{
455 qDebug("ODevice::suspend"); 455 qDebug("ODevice::suspend");
456 if ( !isQWS( ) ) // only qwsserver is allowed to suspend 456 if ( !isQWS( ) ) // only qwsserver is allowed to suspend
457 return false; 457 return false;
458 458
459 if ( d->m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices 459 if ( d->m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices
460 return false; 460 return false;
461 461
462 bool res = false; 462 bool res = false;
463 ODevice::sendSuspendmsg(); 463 ODevice::sendSuspendmsg();
464 464
465 struct timeval tvs, tvn; 465 struct timeval tvs, tvn;
466 ::gettimeofday ( &tvs, 0 ); 466 ::gettimeofday ( &tvs, 0 );
467 467
468 ::sync(); // flush fs caches 468 ::sync(); // flush fs caches
469 res = ( ::system ( "apm --suspend" ) == 0 ); 469 res = ( ::system ( "apm --suspend" ) == 0 );
470 470
471 // This is needed because the apm implementation is asynchronous and we 471 // This is needed because the apm implementation is asynchronous and we
472 // can not be sure when exactly the device is really suspended 472 // can not be sure when exactly the device is really suspended
473 if ( res ) { 473 if ( res ) {
474 do { // Yes, wait 15 seconds. This APM sucks big time. 474 do { // Yes, wait 15 seconds. This APM sucks big time.
475 ::usleep ( 200 * 1000 ); 475 ::usleep ( 200 * 1000 );
476 ::gettimeofday ( &tvn, 0 ); 476 ::gettimeofday ( &tvn, 0 );
477 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 15000 ); 477 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 15000 );
478 } 478 }
479 479
480 QCopEnvelope ( "QPE/Rotation", "rotateDefault()" ); 480 QCopEnvelope ( "QPE/Rotation", "rotateDefault()" );
481 return res; 481 return res;
482} 482}
483 483
484 484
485Transformation Zaurus::rotation() const 485Transformation Zaurus::rotation() const
486{ 486{
487 Transformation rot; 487 Transformation rot;
488 int handle = 0; 488 int handle = 0;
489 int retval = 0; 489 int retval = 0;
490 490
491 switch ( d->m_model ) { 491 switch ( d->m_model ) {
492 case Model_Zaurus_SLC7x0: 492 case Model_Zaurus_SLC7x0:
493 handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); 493 handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK);
494 if (handle == -1) { 494 if (handle == -1) {
495 return Rot270; 495 return Rot270;
496 } else { 496 } else {
497 retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); 497 retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION);
498 ::close (handle); 498 ::close (handle);
499 499
500 if (retval == 2 ) 500 if (retval == 2 )
501 rot = Rot0; 501 rot = Rot0;
502 else 502 else
503 rot = Rot270; 503 rot = Rot270;
504 } 504 }
505 break; 505 break;
506 case Model_Zaurus_SLA300: 506 case Model_Zaurus_SLA300:
507 case Model_Zaurus_SLB600: 507 case Model_Zaurus_SLB600:
508 case Model_Zaurus_SL5500: 508 case Model_Zaurus_SL5500:
509 case Model_Zaurus_SL5000: 509 case Model_Zaurus_SL5000:
510 default: 510 default:
511 rot = d->m_rotation; 511 rot = d->m_rotation;
512 break; 512 break;
513 } 513 }
514 514
515 return rot; 515 return rot;
516} 516}
517ODirection Zaurus::direction() const 517ODirection Zaurus::direction() const
518{ 518{
519 ODirection dir; 519 ODirection dir;
520 int handle = 0; 520 int handle = 0;
521 int retval = 0; 521 int retval = 0;
522 switch ( d->m_model ) { 522 switch ( d->m_model ) {
523 case Model_Zaurus_SLC7x0: 523 case Model_Zaurus_SLC7x0:
524 handle = ::open( "/dev/apm_bios", O_RDWR|O_NONBLOCK ); 524 handle = ::open( "/dev/apm_bios", O_RDWR|O_NONBLOCK );
525 if (handle == -1) { 525 if (handle == -1) {
526 dir = CW; 526 dir = CW;
527 } else { 527 } else {
528 retval = ::ioctl( handle, SHARP_IOCTL_GET_ROTATION ); 528 retval = ::ioctl( handle, SHARP_IOCTL_GET_ROTATION );
529 ::close (handle); 529 ::close (handle);
530 if (retval == 2 ) 530 if (retval == 2 )
531 dir = CCW; 531 dir = CCW;
532 else 532 else
533 dir = CW; 533 dir = CW;
534 } 534 }
535 break; 535 break;
536 case Model_Zaurus_SLA300: 536 case Model_Zaurus_SLA300:
537 case Model_Zaurus_SLB600: 537 case Model_Zaurus_SLB600:
538 case Model_Zaurus_SL5500: 538 case Model_Zaurus_SL5500:
539 case Model_Zaurus_SL5000: 539 case Model_Zaurus_SL5000:
540 default: dir = d->m_direction; 540 default: dir = d->m_direction;
541 break; 541 break;
542 } 542 }
543 return dir; 543 return dir;
544 544
545} 545}
546 546
547int Zaurus::displayBrightnessResolution() const 547int Zaurus::displayBrightnessResolution() const
548{ 548{
549 if (m_embedix) 549 if (m_embedix)
550 { 550 {
551 int handle = ::open( SHARP_FL_IOCTL_DEVICE, O_RDWR|O_NONBLOCK ); 551 int handle = ::open( SHARP_FL_IOCTL_DEVICE, O_RDWR|O_NONBLOCK );
552 if ( handle != -1 ) return ::ioctl( handle, SHARP_FL_IOCTL_GET_STEP, 0 ); 552 if ( handle != -1 ) return ::ioctl( handle, SHARP_FL_IOCTL_GET_STEP, 0 );
553 else return 1; 553 else return 1;
554 } 554 }
555 else 555 else
556 { 556 {
557 qDebug( "ODevice handling for non-embedix kernels not yet implemented" ); 557 qDebug( "ODevice handling for non-embedix kernels not yet implemented" );
558 return 1; 558 return 1;
559 } 559 }
560} 560}
561 561
562bool Zaurus::hasHingeSensor() const 562bool Zaurus::hasHingeSensor() const
563{ 563{
564 return d->m_model == Model_Zaurus_SLC7x0; 564 return d->m_model == Model_Zaurus_SLC7x0;
565} 565}
566 566
567OHingeStatus Zaurus::readHingeSensor() 567OHingeStatus Zaurus::readHingeSensor()
568{ 568{
569 int handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); 569 int handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK);
570 if (handle == -1) 570 if (handle == -1)
571 { 571 {
572 qWarning("Zaurus::readHingeSensor() - failed (%s)", "unknown reason" ); //FIXME: use strerror 572 qWarning("Zaurus::readHingeSensor() - failed (%s)", "unknown reason" ); //FIXME: use strerror
573 return CASE_UNKNOWN; 573 return CASE_UNKNOWN;
574 } 574 }
575 else 575 else
576 { 576 {
577 int retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); 577 int retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION);
578 ::close (handle); 578 ::close (handle);
579 if ( retval == CASE_CLOSED || retval == CASE_PORTRAIT || retval == CASE_LANDSCAPE ) 579 if ( retval == CASE_CLOSED || retval == CASE_PORTRAIT || retval == CASE_LANDSCAPE )
580 { 580 {
581 qDebug( "Zaurus::readHingeSensor() - result = %d", retval ); 581 qDebug( "Zaurus::readHingeSensor() - result = %d", retval );
582 return static_cast<OHingeStatus>( retval ); 582 return static_cast<OHingeStatus>( retval );
583 } 583 }
584 else 584 else
585 { 585 {
586 qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" ); 586 qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" );
587 return CASE_UNKNOWN; 587 return CASE_UNKNOWN;
588 } 588 }
589 } 589 }
590} 590}