Ejemplo n.º 1
0
static DFBResult
Test_Sensitivity( IDirectFB        *dfb,
                  DFBInputDeviceID  device_id )
{
     DFBResult             ret;
     IDirectFBInputDevice *device;
     IDirectFBEventBuffer *buffer;
     int                   i, n;
     int                   sensitivities[] = { 0x100, 0x200, 0x80 };

     D_INFO( "DFBTest/Input: Testing sensitivity with input device %u...\n", device_id );

     ret = dfb->GetInputDevice( dfb, device_id, &device );
     if (ret) {
          D_DERROR( ret, "DFBTest/Input: GetInputDevice( %u ) failed!\n", device_id );
          return ret;
     }

     ret = device->CreateEventBuffer( device, &buffer );
     if (ret) {
          D_DERROR( ret, "DFBTest/Input: CreateEventBuffer() failed!\n" );
          device->Release( device );
          return ret;
     }

     for (i=0; i<D_ARRAY_SIZE(sensitivities); i++) {
          DFBInputDeviceConfig config;
          unsigned int         move = 0;

          D_INFO( "DFBTest/Input: Setting sensitivity to 0x%x, please move mouse!\n", sensitivities[i] );

          config.flags       = DIDCONF_SENSITIVITY;
          config.sensitivity = sensitivities[i];

          ret = device->SetConfiguration( device, &config );
          if (ret) {
               D_DERROR( ret, "DFBTest/Input: SetConfiguration() failed!\n" );
               buffer->Release( buffer );
               device->Release( device );
               return ret;
          }

          buffer->Reset( buffer );

          for (n=0; n<500; n++) {
               DFBInputEvent event;

               buffer->WaitForEvent( buffer );

               buffer->GetEvent( buffer, DFB_EVENT(&event) );

               switch (event.type) {
                    case DIET_AXISMOTION:
                         if (event.flags & DIEF_AXISREL) {
                              //D_INFO( "DFBTest/Input: Motion (axis %d) by %d\n", event.axis, event.axisrel );

                              if (event.axisrel > 0)
                                   move += event.axisrel;
                              else
                                   move -= event.axisrel;
                         }

                         break;

                    default:
                         break;
               }
          }

          D_INFO( "DFBTest/Input: Average movement %d.\n", move / n );

          direct_thread_sleep( 1000000 );
     }

     buffer->Release( buffer );
     device->Release( device );

     return DFB_OK;
}