summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_zaurus.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/libopie2/opiecore/device/odevice_zaurus.cpp b/libopie2/opiecore/device/odevice_zaurus.cpp
index 7302d2c..b7f3104 100644
--- a/libopie2/opiecore/device/odevice_zaurus.cpp
+++ b/libopie2/opiecore/device/odevice_zaurus.cpp
@@ -169,549 +169,560 @@ void Zaurus::init(const QString& cpu_info)
169 d->m_system = System_Zaurus; 169 d->m_system = System_Zaurus;
170 m_embedix = true; 170 m_embedix = true;
171 } 171 }
172 else 172 else
173 { 173 {
174 d->m_vendorstr = "OpenZaurus Team"; 174 d->m_vendorstr = "OpenZaurus Team";
175 d->m_systemstr = "OpenZaurus"; 175 d->m_systemstr = "OpenZaurus";
176 d->m_system = System_OpenZaurus; 176 d->m_system = System_OpenZaurus;
177 // sysver already gathered 177 // sysver already gathered
178 178
179 // OpenZaurus sometimes uses the 2.4 (embedix) kernel, check if this is one 179 // OpenZaurus sometimes uses the 2.4 (embedix) kernel, check if this is one
180 FILE *uname = popen("uname -r", "r"); 180 FILE *uname = popen("uname -r", "r");
181 QFile f; 181 QFile f;
182 QString line; 182 QString line;
183 if ( f.open(IO_ReadOnly, uname) ) { 183 if ( f.open(IO_ReadOnly, uname) ) {
184 QTextStream ts ( &f ); 184 QTextStream ts ( &f );
185 line = ts.readLine(); 185 line = ts.readLine();
186 m_embedix = line.startsWith( "2.4." ); 186 m_embedix = line.startsWith( "2.4." );
187 f.close(); 187 f.close();
188 } 188 }
189 pclose(uname); 189 pclose(uname);
190 } 190 }
191 191
192 // check the Zaurus model 192 // check the Zaurus model
193 QString model; 193 QString model;
194 int loc = cpu_info.find( ":" ); 194 int loc = cpu_info.find( ":" );
195 if ( loc != -1 ) 195 if ( loc != -1 )
196 model = cpu_info.mid( loc+2 ).simplifyWhiteSpace(); 196 model = cpu_info.mid( loc+2 ).simplifyWhiteSpace();
197 else 197 else
198 model = cpu_info; 198 model = cpu_info;
199 199
200 if ( model == "SHARP Corgi" ) { 200 if ( model == "SHARP Corgi" ) {
201 d->m_model = Model_Zaurus_SLC7x0; 201 d->m_model = Model_Zaurus_SLC7x0;
202 d->m_modelstr = "Zaurus SL-C700"; 202 d->m_modelstr = "Zaurus SL-C700";
203 } else if ( model == "SHARP Shepherd" ) { 203 } else if ( model == "SHARP Shepherd" ) {
204 d->m_model = Model_Zaurus_SLC7x0; 204 d->m_model = Model_Zaurus_SLC7x0;
205 d->m_modelstr = "Zaurus SL-C750"; 205 d->m_modelstr = "Zaurus SL-C750";
206 } else if ( model == "SHARP Husky" ) { 206 } else if ( model == "SHARP Husky" ) {
207 d->m_model = Model_Zaurus_SLC7x0; 207 d->m_model = Model_Zaurus_SLC7x0;
208 d->m_modelstr = "Zaurus SL-C760 or SL-C860"; 208 d->m_modelstr = "Zaurus SL-C760 or SL-C860";
209 } else if ( model == "SHARP Boxer" ) { 209 } else if ( model == "SHARP Boxer" ) {
210 d->m_model = Model_Zaurus_SLC7x0; 210 d->m_model = Model_Zaurus_SLC7x0;
211 d->m_modelstr = "Zaurus SL-C760 or SL-C860"; 211 d->m_modelstr = "Zaurus SL-C760 or SL-C860";
212 } else if ( model == "SHARP Poodle" ) { 212 } else if ( model == "SHARP Poodle" ) {
213 d->m_model = Model_Zaurus_SLB600; 213 d->m_model = Model_Zaurus_SLB600;
214 d->m_modelstr = "Zaurus SL-B500 or SL-5600"; 214 d->m_modelstr = "Zaurus SL-B500 or SL-5600";
215 } else if ( model == "Sharp-Collie" || model == "Collie" ) { 215 } else if ( model == "Sharp-Collie" || model == "Collie" ) {
216 d->m_model = Model_Zaurus_SL5500; 216 d->m_model = Model_Zaurus_SL5500;
217 d->m_modelstr = "Zaurus SL-5500 or SL-5000d"; 217 d->m_modelstr = "Zaurus SL-5500 or SL-5000d";
218 } else if ( model == "SHARP Tosa" ) { 218 } else if ( model == "SHARP Tosa" ) {
219 d->m_model = Model_Zaurus_SL6000; 219 d->m_model = Model_Zaurus_SL6000;
220 d->m_modelstr = "Zaurus SL-6000"; 220 d->m_modelstr = "Zaurus SL-6000";
221 } else if ( model == "SHARP Spitz" ) { 221 } else if ( model == "SHARP Spitz" ) {
222 d->m_model = Model_Zaurus_SLC3000; 222 d->m_model = Model_Zaurus_SLC3000;
223 d->m_modelstr = "Zaurus SL-C3000"; 223 d->m_modelstr = "Zaurus SL-C3000";
224 } else if ( model == "SHARP Akita" ) { 224 } else if ( model == "SHARP Akita" ) {
225 d->m_model = Model_Zaurus_SLC1000; 225 d->m_model = Model_Zaurus_SLC1000;
226 d->m_modelstr = "Zaurus SL-C1000"; 226 d->m_modelstr = "Zaurus SL-C1000";
227 } else { 227 } else {
228 d->m_model = Model_Zaurus_SL5500; 228 d->m_model = Model_Zaurus_SL5500;
229 d->m_modelstr = "Unknown Zaurus"; 229 d->m_modelstr = "Unknown Zaurus";
230 } 230 }
231 231
232 // set path to backlight device in kernel 2.6 232 // set path to backlight device in kernel 2.6
233 switch ( d->m_model ) 233 switch ( d->m_model )
234 { 234 {
235 case Model_Zaurus_SLB600: // fallthrough 235 case Model_Zaurus_SLB600: // fallthrough
236 case Model_Zaurus_SL5500: 236 case Model_Zaurus_SL5500:
237 m_backlightdev = "/sys/class/backlight/locomo-backlight/"; 237 m_backlightdev = "/sys/class/backlight/locomo-backlight/";
238 break; 238 break;
239 case Model_Zaurus_SL6000: 239 case Model_Zaurus_SL6000:
240 m_backlightdev = "/sys/class/backlight/tosa-bl/"; 240 m_backlightdev = "/sys/class/backlight/tosa-bl/";
241 break; 241 break;
242 default: 242 default:
243 m_backlightdev = "/sys/class/backlight/corgi-bl/"; 243 m_backlightdev = "/sys/class/backlight/corgi-bl/";
244 } 244 }
245 245
246 // set initial rotation 246 // set initial rotation
247 switch( d->m_model ) 247 switch( d->m_model )
248 { 248 {
249 case Model_Zaurus_SL6000: // fallthrough 249 case Model_Zaurus_SL6000: // fallthrough
250 case Model_Zaurus_SLA300: 250 case Model_Zaurus_SLA300:
251 d->m_rotation = Rot0; 251 d->m_rotation = Rot0;
252 break; 252 break;
253 case Model_Zaurus_SLC3000: // fallthrough 253 case Model_Zaurus_SLC3000: // fallthrough
254 case Model_Zaurus_SLC1000: // fallthrough 254 case Model_Zaurus_SLC1000: // fallthrough
255 case Model_Zaurus_SLC7x0: 255 case Model_Zaurus_SLC7x0:
256 d->m_rotation = rotation(); 256 d->m_rotation = rotation();
257 d->m_direction = direction(); 257 d->m_direction = direction();
258 break; 258 break;
259 case Model_Zaurus_SLB600: // fallthrough 259 case Model_Zaurus_SLB600: // fallthrough
260 case Model_Zaurus_SL5000: // fallthrough 260 case Model_Zaurus_SL5000: // fallthrough
261 case Model_Zaurus_SL5500: // fallthrough 261 case Model_Zaurus_SL5500: // fallthrough
262 default: 262 default:
263 d->m_rotation = Rot270; 263 d->m_rotation = Rot270;
264 } 264 }
265 265
266 // set default qte driver 266 // set default qte driver
267 switch( d->m_model ) 267 switch( d->m_model )
268 { 268 {
269 case Model_Zaurus_SLC7x0: 269 case Model_Zaurus_SLC7x0:
270 d->m_qteDriver = "W100"; 270 d->m_qteDriver = "W100";
271 break; 271 break;
272 default: 272 default:
273 d->m_qteDriver = "Transformed"; 273 d->m_qteDriver = "Transformed";
274 } 274 }
275 275
276 m_leds[0] = Led_Off; 276 m_leds[0] = Led_Off;
277 277
278 if ( m_embedix ) 278 if ( m_embedix )
279 qDebug( "Zaurus::init() - Using the 2.4 Embedix HAL on a %s", (const char*) d->m_modelstr ); 279 qDebug( "Zaurus::init() - Using the 2.4 Embedix HAL on a %s", (const char*) d->m_modelstr );
280 else 280 else
281 qDebug( "Zaurus::init() - Using the 2.6 OpenZaurus HAL on a %s", (const char*) d->m_modelstr ); 281 qDebug( "Zaurus::init() - Using the 2.6 OpenZaurus HAL on a %s", (const char*) d->m_modelstr );
282} 282}
283 283
284void Zaurus::initButtons() 284void Zaurus::initButtons()
285{ 285{
286 if ( d->m_buttons ) 286 if ( d->m_buttons )
287 return; 287 return;
288 288
289 d->m_buttons = new QValueList <ODeviceButton>; 289 d->m_buttons = new QValueList <ODeviceButton>;
290 290
291 struct z_button * pz_buttons; 291 struct z_button * pz_buttons;
292 int buttoncount; 292 int buttoncount;
293 switch ( d->m_model ) 293 switch ( d->m_model )
294 { 294 {
295 case Model_Zaurus_SL6000: 295 case Model_Zaurus_SL6000:
296 pz_buttons = z_buttons_6000; 296 pz_buttons = z_buttons_6000;
297 buttoncount = ARRAY_SIZE(z_buttons_6000); 297 buttoncount = ARRAY_SIZE(z_buttons_6000);
298 break; 298 break;
299 case Model_Zaurus_SLC3000: // fallthrough 299 case Model_Zaurus_SLC3000: // fallthrough
300 case Model_Zaurus_SLC1000: // fallthrough 300 case Model_Zaurus_SLC1000: // fallthrough
301 case Model_Zaurus_SLC7x0: 301 case Model_Zaurus_SLC7x0:
302 if ( isQWS( ) ) { 302 if ( isQWS( ) ) {
303 addPreHandler(this); // hinge-sensor-handler 303 addPreHandler(this); // hinge-sensor-handler
304 } 304 }
305 pz_buttons = z_buttons_c700; 305 pz_buttons = z_buttons_c700;
306 buttoncount = ARRAY_SIZE(z_buttons_c700); 306 buttoncount = ARRAY_SIZE(z_buttons_c700);
307 break; 307 break;
308 default: 308 default:
309 pz_buttons = z_buttons; 309 pz_buttons = z_buttons;
310 buttoncount = ARRAY_SIZE(z_buttons); 310 buttoncount = ARRAY_SIZE(z_buttons);
311 break; 311 break;
312 } 312 }
313 313
314 for ( int i = 0; i < buttoncount; i++ ) { 314 for ( int i = 0; i < buttoncount; i++ ) {
315 struct z_button *zb = pz_buttons + i; 315 struct z_button *zb = pz_buttons + i;
316 ODeviceButton b; 316 ODeviceButton b;
317 317
318 b.setKeycode( zb->code ); 318 b.setKeycode( zb->code );
319 b.setUserText( QObject::tr( "Button", zb->utext )); 319 b.setUserText( QObject::tr( "Button", zb->utext ));
320 b.setPixmap( OResource::loadPixmap( zb->pix )); 320 b.setPixmap( OResource::loadPixmap( zb->pix ));
321 b.setFactoryPresetPressedAction( OQCopMessage( makeChannel ( zb->fpressedservice ), zb->fpressedaction )); 321 b.setFactoryPresetPressedAction( OQCopMessage( makeChannel ( zb->fpressedservice ), zb->fpressedaction ));
322 b.setFactoryPresetHeldAction( OQCopMessage( makeChannel ( zb->fheldservice ), zb->fheldaction )); 322 b.setFactoryPresetHeldAction( OQCopMessage( makeChannel ( zb->fheldservice ), zb->fheldaction ));
323 d->m_buttons->append( b ); 323 d->m_buttons->append( b );
324 } 324 }
325 325
326 reloadButtonMapping(); 326 reloadButtonMapping();
327} 327}
328 328
329 329
330 330
331typedef struct sharp_led_status { 331typedef struct sharp_led_status {
332 int which; /* select which LED status is wanted. */ 332 int which; /* select which LED status is wanted. */
333 int status; /* set new led status if you call SHARP_LED_SETSTATUS */ 333 int status; /* set new led status if you call SHARP_LED_SETSTATUS */
334} sharp_led_status; 334} sharp_led_status;
335 335
336void Zaurus::buzzer( int sound ) 336void Zaurus::buzzer( int sound )
337{ 337{
338#ifndef QT_NO_SOUND 338#ifndef QT_NO_SOUND
339 Sound *snd = 0; 339 Sound *snd = 0;
340 340
341 // All devices except SL5500 have a DSP device 341 // All devices except SL5500 have a DSP device
342 if ( d->m_model != Model_Zaurus_SL5000 342 if ( d->m_model != Model_Zaurus_SL5000
343 && d->m_model != Model_Zaurus_SL5500 ) { 343 && d->m_model != Model_Zaurus_SL5500 ) {
344 344
345 switch ( sound ){ 345 switch ( sound ){
346 case SHARP_BUZ_TOUCHSOUND: { 346 case SHARP_BUZ_TOUCHSOUND: {
347 static Sound touch_sound("touchsound"); 347 static Sound touch_sound("touchsound");
348 snd = &touch_sound; 348 snd = &touch_sound;
349 } 349 }
350 break; 350 break;
351 case SHARP_BUZ_KEYSOUND: { 351 case SHARP_BUZ_KEYSOUND: {
352 static Sound key_sound( "keysound" ); 352 static Sound key_sound( "keysound" );
353 snd = &key_sound; 353 snd = &key_sound;
354 } 354 }
355 break; 355 break;
356 case SHARP_BUZ_SCHEDULE_ALARM: 356 case SHARP_BUZ_SCHEDULE_ALARM:
357 default: { 357 default: {
358 static Sound alarm_sound("alarm"); 358 static Sound alarm_sound("alarm");
359 snd = &alarm_sound; 359 snd = &alarm_sound;
360 } 360 }
361 break; 361 break;
362 } 362 }
363 } 363 }
364 364
365 // If a soundname is defined, we expect that this device has 365 // If a soundname is defined, we expect that this device has
366 // sound capabilities.. Otherwise we expect to have the buzzer 366 // sound capabilities.. Otherwise we expect to have the buzzer
367 // device.. 367 // device..
368 if ( snd && snd->isFinished() ){ 368 if ( snd && snd->isFinished() ){
369 changeMixerForAlarm( 0, "/dev/sound/mixer", snd ); 369 changeMixerForAlarm( 0, "/dev/sound/mixer", snd );
370 snd->play(); 370 snd->play();
371 } else if( !snd ) { 371 } else if( !snd ) {
372 int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK ); 372 int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK );
373 373
374 if ( fd >= 0 ) { 374 if ( fd >= 0 ) {
375 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); 375 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound );
376 ::close ( fd ); 376 ::close ( fd );
377 } 377 }
378 378
379 } 379 }
380#endif 380#endif
381} 381}
382 382
383 383
384void Zaurus::playAlarmSound() 384void Zaurus::playAlarmSound()
385{ 385{
386 buzzer( SHARP_BUZ_SCHEDULE_ALARM ); 386 buzzer( SHARP_BUZ_SCHEDULE_ALARM );
387} 387}
388 388
389void Zaurus::playTouchSound() 389void Zaurus::playTouchSound()
390{ 390{
391 buzzer( SHARP_BUZ_TOUCHSOUND ); 391 buzzer( SHARP_BUZ_TOUCHSOUND );
392} 392}
393 393
394void Zaurus::playKeySound() 394void Zaurus::playKeySound()
395{ 395{
396 buzzer( SHARP_BUZ_KEYSOUND ); 396 buzzer( SHARP_BUZ_KEYSOUND );
397} 397}
398 398
399 399
400QValueList <OLed> Zaurus::ledList() const 400QValueList <OLed> Zaurus::ledList() const
401{ 401{
402 QValueList <OLed> vl; 402 QValueList <OLed> vl;
403 vl << Led_Mail; 403 vl << Led_Mail;
404 return vl; 404 return vl;
405} 405}
406 406
407QValueList <OLedState> Zaurus::ledStateList( OLed l ) const 407QValueList <OLedState> Zaurus::ledStateList( OLed l ) const
408{ 408{
409 QValueList <OLedState> vl; 409 QValueList <OLedState> vl;
410 410
411 if ( l == Led_Mail ) 411 if ( l == Led_Mail )
412 vl << Led_Off << Led_On << Led_BlinkSlow; 412 vl << Led_Off << Led_On << Led_BlinkSlow;
413 return vl; 413 return vl;
414} 414}
415 415
416OLedState Zaurus::ledState( OLed which ) const 416OLedState Zaurus::ledState( OLed which ) const
417{ 417{
418 if ( which == Led_Mail ) 418 if ( which == Led_Mail )
419 return m_leds [0]; 419 return m_leds [0];
420 else 420 else
421 return Led_Off; 421 return Led_Off;
422} 422}
423 423
424bool Zaurus::setLedState( OLed which, OLedState st ) 424bool Zaurus::setLedState( OLed which, OLedState st )
425{ 425{
426 // Currently not supported on non_embedix kernels 426 // Currently not supported on non_embedix kernels
427 if (!m_embedix) 427 if (!m_embedix)
428 { 428 {
429 qDebug( "Zaurus::setLedState: ODevice handling for non-embedix kernels not yet implemented" ); 429 qDebug( "Zaurus::setLedState: ODevice handling for non-embedix kernels not yet implemented" );
430 return false; 430 return false;
431 } 431 }
432 432
433 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); 433 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK );
434 434
435 if ( which == Led_Mail ) { 435 if ( which == Led_Mail ) {
436 if ( fd >= 0 ) { 436 if ( fd >= 0 ) {
437 struct sharp_led_status leds; 437 struct sharp_led_status leds;
438 ::memset ( &leds, 0, sizeof( leds )); 438 ::memset ( &leds, 0, sizeof( leds ));
439 leds. which = SHARP_LED_MAIL_EXISTS; 439 leds. which = SHARP_LED_MAIL_EXISTS;
440 bool ok = true; 440 bool ok = true;
441 441
442 switch ( st ) { 442 switch ( st ) {
443 case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; 443 case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break;
444 case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; 444 case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break;
445 case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break; 445 case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break;
446 default : ok = false; 446 default : ok = false;
447 } 447 }
448 448
449 if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) { 449 if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) {
450 m_leds [0] = st; 450 m_leds [0] = st;
451 return true; 451 return true;
452 } 452 }
453 } 453 }
454 } 454 }
455 return false; 455 return false;
456} 456}
457 457
458int Zaurus::displayBrightnessResolution() const 458int Zaurus::displayBrightnessResolution() const
459{ 459{
460 int res = 1; 460 int res = 1;
461 if (m_embedix) 461 if (m_embedix)
462 { 462 {
463 int fd = ::open( SHARP_FL_IOCTL_DEVICE, O_RDWR|O_NONBLOCK ); 463 int fd = ::open( SHARP_FL_IOCTL_DEVICE, O_RDWR|O_NONBLOCK );
464 if ( fd ) 464 if ( fd )
465 { 465 {
466 int value = ::ioctl( fd, SHARP_FL_IOCTL_GET_STEP, 0 ); 466 int value = ::ioctl( fd, SHARP_FL_IOCTL_GET_STEP, 0 );
467 ::close( fd ); 467 ::close( fd );
468 return value ? value : res; 468 return value ? value : res;
469 } 469 }
470 } 470 }
471 else 471 else
472 { 472 {
473 int fd = ::open( m_backlightdev + "max_brightness", O_RDONLY|O_NONBLOCK ); 473 int fd = ::open( m_backlightdev + "max_brightness", O_RDONLY|O_NONBLOCK );
474 if ( fd ) 474 if ( fd )
475 { 475 {
476 char buf[100]; 476 char buf[100];
477 if ( ::read( fd, &buf[0], sizeof buf ) ) ::sscanf( &buf[0], "%d", &res ); 477 if ( ::read( fd, &buf[0], sizeof buf ) ) ::sscanf( &buf[0], "%d", &res );
478 ::close( fd ); 478 ::close( fd );
479 } 479 }
480 } 480 }
481 return res; 481 return res;
482} 482}
483 483
484bool Zaurus::setDisplayBrightness( int bright ) 484bool Zaurus::setDisplayBrightness( int bright )
485{ 485{
486 //qDebug( "Zaurus::setDisplayBrightness( %d )", bright ); 486 //qDebug( "Zaurus::setDisplayBrightness( %d )", bright );
487 bool res = false; 487 bool res = false;
488 488
489 if ( bright > 255 ) bright = 255; 489 if ( bright > 255 ) bright = 255;
490 if ( bright < 0 ) bright = 0; 490 if ( bright < 0 ) bright = 0;
491 491
492 int numberOfSteps = displayBrightnessResolution(); 492 int numberOfSteps = displayBrightnessResolution();
493 int val = ( bright == 1 ) ? 1 : ( bright * numberOfSteps ) / 255; 493 int val = ( bright == 1 ) ? 1 : ( bright * numberOfSteps ) / 255;
494 494
495 if ( m_embedix ) 495 if ( m_embedix )
496 { 496 {
497 int fd = ::open( SHARP_FL_IOCTL_DEVICE, O_WRONLY|O_NONBLOCK ); 497 int fd = ::open( SHARP_FL_IOCTL_DEVICE, O_WRONLY|O_NONBLOCK );
498 if ( fd ) 498 if ( fd )
499 { 499 {
500 res = ( ::ioctl( fd, SHARP_FL_IOCTL_STEP_CONTRAST, val ) == 0 ); 500 res = ( ::ioctl( fd, SHARP_FL_IOCTL_STEP_CONTRAST, val ) == 0 );
501 ::close( fd ); 501 ::close( fd );
502 } 502 }
503 } 503 }
504 else 504 else
505 { 505 {
506 int fd = ::open( m_backlightdev + "brightness", O_WRONLY|O_NONBLOCK ); 506 int fd = ::open( m_backlightdev + "brightness", O_WRONLY|O_NONBLOCK );
507 if ( fd ) 507 if ( fd )
508 { 508 {
509 char buf[100]; 509 char buf[100];
510 int len = ::snprintf( &buf[0], sizeof buf, "%d", val ); 510 int len = ::snprintf( &buf[0], sizeof buf, "%d", val );
511 res = ( ::write( fd, &buf[0], len ) == 0 ); 511 res = ( ::write( fd, &buf[0], len ) == 0 );
512 ::close( fd ); 512 ::close( fd );
513 } 513 }
514 } 514 }
515 return res; 515 return res;
516} 516}
517 517
518bool Zaurus::setDisplayStatus( bool on ) 518bool Zaurus::setDisplayStatus( bool on )
519{ 519{
520 bool res = false; 520 bool res = false;
521 if ( m_embedix ) 521 if ( m_embedix )
522 { 522 {
523 int fd = ::open( SHARP_FL_IOCTL_DEVICE, O_WRONLY|O_NONBLOCK ); 523 int fd = ::open( SHARP_FL_IOCTL_DEVICE, O_WRONLY|O_NONBLOCK );
524 if ( fd ) 524 if ( fd )
525 { 525 {
526 int ioctlnum = on ? SHARP_FL_IOCTL_ON : SHARP_FL_IOCTL_OFF; 526 int ioctlnum = on ? SHARP_FL_IOCTL_ON : SHARP_FL_IOCTL_OFF;
527 res = ( ::ioctl ( fd, ioctlnum, 0 ) == 0 ); 527 res = ( ::ioctl ( fd, ioctlnum, 0 ) == 0 );
528 ::close ( fd ); 528 ::close ( fd );
529 } 529 }
530 } 530 }
531 else 531 else
532 { 532 {
533 int fd = ::open( m_backlightdev + "power", O_WRONLY|O_NONBLOCK ); 533 int fd = ::open( m_backlightdev + "power", O_WRONLY|O_NONBLOCK );
534 if ( fd ) 534 if ( fd )
535 { 535 {
536 char buf[10]; 536 char buf[10];
537 buf[0] = on ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; 537 buf[0] = on ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
538 buf[1] = '\0'; 538 buf[1] = '\0';
539 res = ( ::write( fd, &buf[0], 2 ) == 0 ); 539 res = ( ::write( fd, &buf[0], 2 ) == 0 );
540 ::close( fd ); 540 ::close( fd );
541 } 541 }
542 } 542 }
543 return res; 543 return res;
544} 544}
545 545
546Transformation Zaurus::rotation() const 546Transformation Zaurus::rotation() const
547{ 547{
548 qDebug( "Zaurus::rotation()" ); 548 qDebug( "Zaurus::rotation()" );
549 Transformation rot; 549 Transformation rot;
550 550
551 switch ( d->m_model ) { 551 switch ( d->m_model ) {
552 case Model_Zaurus_SLC3000: // fallthrough 552 case Model_Zaurus_SLC3000: // fallthrough
553 case Model_Zaurus_SLC1000: // fallthrough 553 case Model_Zaurus_SLC1000:
554 {
555 OHingeStatus hs = readHingeSensor();
556 qDebug( "Zaurus::rotation() - hinge sensor = %d", (int) hs );
557 if ( hs == CASE_PORTRAIT ) rot = Rot0;
558 else if ( hs == CASE_UNKNOWN ) rot = Rot270;
559 else rot = Rot270;
560 }
561 break;
562
563 // SLC7x0 needs a special case here, because we were able to set the W100
564 // hardware default rotation on kernel 2.6 to Rot0
554 case Model_Zaurus_SLC7x0: 565 case Model_Zaurus_SLC7x0:
555 { 566 {
556 OHingeStatus hs = readHingeSensor(); 567 OHingeStatus hs = readHingeSensor();
557 qDebug( "Zaurus::rotation() - hinge sensor = %d", (int) hs ); 568 qDebug( "Zaurus::rotation() - hinge sensor = %d", (int) hs );
558 569
559 if ( m_embedix ) 570 if ( m_embedix )
560 { 571 {
561 if ( hs == CASE_PORTRAIT ) rot = Rot0; 572 if ( hs == CASE_PORTRAIT ) rot = Rot0;
562 else if ( hs == CASE_UNKNOWN ) rot = Rot0; 573 else if ( hs == CASE_UNKNOWN ) rot = Rot270;
563 else rot = Rot270; 574 else rot = Rot270;
564 } 575 }
565 else 576 else
566 { 577 {
567 if ( hs == CASE_PORTRAIT ) rot = Rot90; 578 if ( hs == CASE_PORTRAIT ) rot = Rot90;
568 else if ( hs == CASE_UNKNOWN ) rot = Rot0; 579 else if ( hs == CASE_UNKNOWN ) rot = Rot0;
569 else rot = Rot0; 580 else rot = Rot0;
570 } 581 }
571 } 582 }
572 break; 583 break;
573 case Model_Zaurus_SL6000: 584 case Model_Zaurus_SL6000:
574 case Model_Zaurus_SLB600: 585 case Model_Zaurus_SLB600:
575 case Model_Zaurus_SLA300: 586 case Model_Zaurus_SLA300:
576 case Model_Zaurus_SL5500: 587 case Model_Zaurus_SL5500:
577 case Model_Zaurus_SL5000: 588 case Model_Zaurus_SL5000:
578 default: 589 default:
579 rot = d->m_rotation; 590 rot = d->m_rotation;
580 break; 591 break;
581 } 592 }
582 593
583 return rot; 594 return rot;
584} 595}
585ODirection Zaurus::direction() const 596ODirection Zaurus::direction() const
586{ 597{
587 ODirection dir; 598 ODirection dir;
588 599
589 switch ( d->m_model ) { 600 switch ( d->m_model ) {
590 case Model_Zaurus_SLC3000: // fallthrough 601 case Model_Zaurus_SLC3000: // fallthrough
591 case Model_Zaurus_SLC1000: // fallthrough 602 case Model_Zaurus_SLC1000: // fallthrough
592 case Model_Zaurus_SLC7x0: { 603 case Model_Zaurus_SLC7x0: {
593 OHingeStatus hs = readHingeSensor(); 604 OHingeStatus hs = readHingeSensor();
594 if ( hs == CASE_PORTRAIT ) dir = CCW; 605 if ( hs == CASE_PORTRAIT ) dir = CCW;
595 else if ( hs == CASE_UNKNOWN ) dir = CCW; 606 else if ( hs == CASE_UNKNOWN ) dir = CCW;
596 else dir = CW; 607 else dir = CW;
597 } 608 }
598 break; 609 break;
599 case Model_Zaurus_SL6000: 610 case Model_Zaurus_SL6000:
600 case Model_Zaurus_SLA300: 611 case Model_Zaurus_SLA300:
601 case Model_Zaurus_SLB600: 612 case Model_Zaurus_SLB600:
602 case Model_Zaurus_SL5500: 613 case Model_Zaurus_SL5500:
603 case Model_Zaurus_SL5000: 614 case Model_Zaurus_SL5000:
604 default: dir = d->m_direction; 615 default: dir = d->m_direction;
605 break; 616 break;
606 } 617 }
607 return dir; 618 return dir;
608 619
609} 620}
610 621
611bool Zaurus::hasHingeSensor() const 622bool Zaurus::hasHingeSensor() const
612{ 623{
613 return d->m_model == Model_Zaurus_SLC7x0 || d->m_model == Model_Zaurus_SLC3000 || d->m_model == Model_Zaurus_SLC1000; 624 return d->m_model == Model_Zaurus_SLC7x0 || d->m_model == Model_Zaurus_SLC3000 || d->m_model == Model_Zaurus_SLC1000;
614} 625}
615 626
616OHingeStatus Zaurus::readHingeSensor() const 627OHingeStatus Zaurus::readHingeSensor() const
617{ 628{
618 if (m_embedix) 629 if (m_embedix)
619 { 630 {
620 int handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); 631 int handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK);
621 if (handle == -1) 632 if (handle == -1)
622 { 633 {
623 qWarning("Zaurus::readHingeSensor() - failed (%s)", "unknown reason" ); //FIXME: use strerror 634 qWarning("Zaurus::readHingeSensor() - failed (%s)", "unknown reason" ); //FIXME: use strerror
624 return CASE_UNKNOWN; 635 return CASE_UNKNOWN;
625 } 636 }
626 else 637 else
627 { 638 {
628 int retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); 639 int retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION);
629 ::close (handle); 640 ::close (handle);
630 if ( retval == CASE_CLOSED || retval == CASE_PORTRAIT || retval == CASE_LANDSCAPE ) 641 if ( retval == CASE_CLOSED || retval == CASE_PORTRAIT || retval == CASE_LANDSCAPE )
631 { 642 {
632 qDebug( "Zaurus::readHingeSensor() - result = %d", retval ); 643 qDebug( "Zaurus::readHingeSensor() - result = %d", retval );
633 return static_cast<OHingeStatus>( retval ); 644 return static_cast<OHingeStatus>( retval );
634 } 645 }
635 else 646 else
636 { 647 {
637 qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" ); 648 qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" );
638 return CASE_UNKNOWN; 649 return CASE_UNKNOWN;
639 } 650 }
640 } 651 }
641 } 652 }
642 else 653 else
643 { 654 {
644 // corgi keyboard is event source 0 in OZ kernel 2.6 655 // corgi keyboard is event source 0 in OZ kernel 2.6
645 OInputDevice* keyboard = OInputSystem::instance()->device( "event0" ); 656 OInputDevice* keyboard = OInputSystem::instance()->device( "event0" );
646 if ( keyboard && keyboard->isHeld( OInputDevice::Key_KP0 ) ) return CASE_LANDSCAPE; 657 if ( keyboard && keyboard->isHeld( OInputDevice::Key_KP0 ) ) return CASE_LANDSCAPE;
647 else if ( keyboard && keyboard->isHeld( OInputDevice::Key_KP1 ) ) return CASE_PORTRAIT; 658 else if ( keyboard && keyboard->isHeld( OInputDevice::Key_KP1 ) ) return CASE_PORTRAIT;
648 else if ( keyboard && keyboard->isHeld( OInputDevice::Key_KP2 ) ) return CASE_CLOSED; 659 else if ( keyboard && keyboard->isHeld( OInputDevice::Key_KP2 ) ) return CASE_CLOSED;
649 qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" ); 660 qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" );
650 return CASE_UNKNOWN; 661 return CASE_UNKNOWN;
651 } 662 }
652} 663}
653 664
654/* 665/*
655 * Take code from iPAQ device. 666 * Take code from iPAQ device.
656 * That way we switch the cursor directions depending on status of hinge sensor, eg. hardware direction. 667 * That way we switch the cursor directions depending on status of hinge sensor, eg. hardware direction.
657 * I hope that is ok - Alwin 668 * I hope that is ok - Alwin
658 */ 669 */
659bool Zaurus::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) 670bool Zaurus::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
660{ 671{
661 int newkeycode = keycode; 672 int newkeycode = keycode;
662 673
663 if (d->m_model != Model_Zaurus_SLC7x0 && d->m_model != Model_Zaurus_SLC3000 && d->m_model != Model_Zaurus_SLC1000) return false; 674 if (d->m_model != Model_Zaurus_SLC7x0 && d->m_model != Model_Zaurus_SLC3000 && d->m_model != Model_Zaurus_SLC1000) return false;
664 675
665 /* map cursor keys depending on the hinge status */ 676 /* map cursor keys depending on the hinge status */
666 switch ( keycode ) { 677 switch ( keycode ) {
667 // Rotate cursor keys 678 // Rotate cursor keys
668 case Key_Left : 679 case Key_Left :
669 case Key_Right: 680 case Key_Right:
670 case Key_Up : 681 case Key_Up :
671 case Key_Down : 682 case Key_Down :
672 { 683 {
673 if (rotation()==Rot90) { 684 if (rotation()==Rot90) {
674 newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4; 685 newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4;
675 } 686 }
676 } 687 }
677 break; 688 break;
678 689
679 } 690 }
680 if (newkeycode!=keycode) { 691 if (newkeycode!=keycode) {
681 if ( newkeycode != Key_unknown ) { 692 if ( newkeycode != Key_unknown ) {
682 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); 693 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
683 } 694 }
684 return true; 695 return true;
685 } 696 }
686 return false; 697 return false;
687} 698}
688 699
689bool Zaurus::suspend() { 700bool Zaurus::suspend() {
690 if ( !isQWS( ) ) // only qwsserver is allowed to suspend 701 if ( !isQWS( ) ) // only qwsserver is allowed to suspend
691 return false; 702 return false;
692 703
693 bool res = false; 704 bool res = false;
694 QCopEnvelope( "QPE/System", "aboutToSuspend()" ); 705 QCopEnvelope( "QPE/System", "aboutToSuspend()" );
695 706
696 struct timeval tvs, tvn; 707 struct timeval tvs, tvn;
697 ::gettimeofday ( &tvs, 0 ); 708 ::gettimeofday ( &tvs, 0 );
698 709
699 ::sync(); // flush fs caches 710 ::sync(); // flush fs caches
700 res = ( ::system ( "apm --suspend" ) == 0 ); 711 res = ( ::system ( "apm --suspend" ) == 0 );
701 712
702 // This is needed because some apm implementations are asynchronous and we 713 // This is needed because some apm implementations are asynchronous and we
703 // can not be sure when exactly the device is really suspended 714 // can not be sure when exactly the device is really suspended
704 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. 715 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists.
705 // on non embedix eg. 2.6 kernel line apm is synchronous so we don't need it here. 716 // on non embedix eg. 2.6 kernel line apm is synchronous so we don't need it here.
706 717
707 if ( res && m_embedix) { 718 if ( res && m_embedix) {
708 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed 719 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
709 ::usleep ( 200 * 1000 ); 720 ::usleep ( 200 * 1000 );
710 ::gettimeofday ( &tvn, 0 ); 721 ::gettimeofday ( &tvn, 0 );
711 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < m_timeOut ); 722 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < m_timeOut );
712 } 723 }
713 724
714 QCopEnvelope( "QPE/System", "returnFromSuspend()" ); 725 QCopEnvelope( "QPE/System", "returnFromSuspend()" );
715 726
716 return res; 727 return res;
717} 728}