コード例 #1
0
RelAxisEventHandler::RelAxisEventHandler(UInput& uinput, int slot, bool extra_devices,
                                         int device_id, int code, int repeat, float value) :
  m_code(UIEvent::create(static_cast<uint16_t>(device_id), EV_REL, code)),
  m_value(value),
  m_repeat(repeat),
  m_stick_value(0.0f),
  m_rest_value(0.0f),
  m_rel_emitter()
{
  m_code.resolve_device_id(slot, extra_devices);
  m_rel_emitter = uinput.add_rel(m_code.get_device_id(), m_code.code);
}
コード例 #2
0
RelRepeatAxisEventHandler::RelRepeatAxisEventHandler(UInput& uinput, int slot, bool extra_devices,
                                                     const UIEvent& code, int value, float repeat) :
  m_code(code),
  m_value(value),
  m_repeat(repeat),
  m_stick_value(0),
  m_timer(0),
  m_rel_emitter()
{  
  m_code.resolve_device_id(slot, extra_devices);
  m_rel_emitter = uinput.add_rel(m_code.get_device_id(), m_code.code);
}
コード例 #3
0
UIEventEmitterPtr
MacroButtonEventHandler::get_emitter(UInput& uinput, const UIEvent& ev)
{
  Emitter::iterator it = m_emitter.find(ev);
  if (it != m_emitter.end())
  {
    return it->second;
  }
  else
  {
    UIEventEmitterPtr emitter = uinput.add(ev);
    m_emitter[ev] = emitter;
    return emitter;
  }
}
コード例 #4
0
ファイル: keyboard_dispatcher.cpp プロジェクト: Ape/xboxdrv
KeyboardDispatcher::KeyboardDispatcher(VirtualKeyboard& gui_keyboard,
                                       UInput& uinput) :
  m_uinput(uinput),
  m_emitter(KEY_CNT)
{
  const KeyboardDescription& desc = *gui_keyboard.get_description();

  for(int y = 0; y < desc.get_height(); ++y)
  {
    for(int x = 0; x < desc.get_width(); ++x)
    {
      Key* key = desc.get_key(x, y);
      if (key)
      {
        m_emitter[key->get_code()] = uinput.add_key(0, key->get_code());
      }
    }
  }

  gui_keyboard.set_key_callback(boost::bind(&KeyboardDispatcher::on_key, this, _1, _2));
}
コード例 #5
0
ControllerSlotConfigPtr
ControllerSlotConfig::create(UInput& uinput, int slot, bool extra_devices, const ControllerSlotOptions& opts)
{  
  ControllerSlotConfigPtr m_config(new ControllerSlotConfig);

  for(ControllerSlotOptions::Options::const_iterator i = opts.get_options().begin();
      i != opts.get_options().end(); ++i)
  {
    const ControllerOptions& ctrl_opt = i->second;

    ControllerConfigPtr config(new ControllerConfig(uinput, slot, extra_devices, ctrl_opt));
    create_modifier(ctrl_opt, &config->get_modifier());
    m_config->add_config(config);

#ifdef FIXME
    // introspection of the config
    std::cout << "==[[ Active Modifier ]]==" << std::endl;
    for(std::vector<ModifierPtr>::iterator mod = config->get_modifier().begin(); 
        mod != config->get_modifier().end(); 
        ++mod)
    {
      std::cout << (*mod)->str() << std::endl;
    }
#endif
  }

  // LED
  //ioctl(fd, UI_SET_EVBIT, EV_LED);
  //ioctl(fd, UI_SET_LEDBIT, LED_MISC);

  if (opts.get_force_feedback())
  {
    // FF_GAIN     - relative strength of rumble
    // FF_RUMBLE   - basic rumble (delay, time)
    // FF_CONSTANT - envelope, emulate with rumble
    // FF_RAMP     - same as constant, except strength grows
    // FF_PERIODIC - envelope
    // |- FF_SINE      types of periodic effects
    // |- FF_TRIANGLE
    // |- FF_SQUARE
    // |- FF_SAW_UP
    // |- FF_SAW_DOWN
    // '- FF_CUSTOM
    
    // FIXME: this should go through the regular resolution process
    uint32_t ff_device = UInput::create_device_id(slot, opts.get_ff_device());

    // basic types
    uinput.add_ff(ff_device, FF_RUMBLE);
    uinput.add_ff(ff_device, FF_PERIODIC);
    uinput.add_ff(ff_device, FF_CONSTANT);
    uinput.add_ff(ff_device, FF_RAMP);

    // periodic effect subtypes
    uinput.add_ff(ff_device, FF_SINE);
    uinput.add_ff(ff_device, FF_TRIANGLE);
    uinput.add_ff(ff_device, FF_SQUARE);
    uinput.add_ff(ff_device, FF_SAW_UP);
    uinput.add_ff(ff_device, FF_SAW_DOWN);
    uinput.add_ff(ff_device, FF_CUSTOM);

    // gin support
    uinput.add_ff(ff_device, FF_GAIN);

    // Unsupported effects
    // uinput.add_ff(ff_device, FF_SPRING);
    // uinput.add_ff(ff_device, FF_FRICTION);
    // uinput.add_ff(ff_device, FF_DAMPER);
    // uinput.add_ff(ff_device, FF_INERTIA);

    uinput.set_ff_callback(ff_device, boost::bind(&ControllerSlotConfig::set_rumble, m_config.get(), _1, _2));
  }

  return m_config;
}
コード例 #6
0
MacroButtonEventHandler::MacroButtonEventHandler(UInput& uinput, int slot, bool extra_devices,
                                                 const std::vector<MacroEvent>& events) :
  m_events(events),
  m_send_in_progress(false),
  m_countdown(0),
  m_event_counter(),
  m_emitter()
{
  for(std::vector<MacroEvent>::iterator i = m_events.begin(); i != m_events.end(); ++i)
  {
    switch(i->type)
    {
      case MacroEvent::kInitOp:
        switch(i->init.event.type)
        {
          case EV_REL:
            assert(!"not implemented");
            break;

          case EV_KEY:
            assert(!"not implemented");
            break;

          case EV_ABS:
            i->init.event.resolve_device_id(slot, extra_devices);
            i->init.emitter = new UIEventEmitterPtr(
              uinput.add_abs(i->init.event.get_device_id(), i->init.event.code,
                             i->init.minimum, i->init.maximum, 
                             i->init.fuzz, i->init.flat));
            break;

          default:
            assert(!"not implemented");
            break;
        }
        break;

      case MacroEvent::kSendOp:
        switch(i->send.event.type)
        {
          case EV_REL:
            i->send.event.resolve_device_id(slot, extra_devices);
            i->send.emitter = new UIEventEmitterPtr(get_emitter(uinput, i->send.event));
            break;

          case EV_KEY:
            i->send.event.resolve_device_id(slot, extra_devices);
            i->send.emitter = new UIEventEmitterPtr(get_emitter(uinput, i->send.event));
            break;

          case EV_ABS:
            i->send.event.resolve_device_id(slot, extra_devices);
            // BROKEN: need to get the UIEventEmitterPtr inited earlier
            // not doing a add_abs() here, its the users job to use a
            // init command for that
            break;

          default:
            assert(!"not implemented");
            break;
        }
        break;

      default:
        // nothing to do
        break;
    }
  }
}