Example #1
0
namespace HotkeyManagerEmu
{

static u32 hotkeyDown[6];

static InputConfig s_config("Hotkeys", _trans("Hotkeys"), "Hotkeys");
InputConfig* GetConfig()
{
	return &s_config;
}

void GetStatus(u8 _port, HotkeyStatus* _pHotkeyStatus)
{
	memset(_pHotkeyStatus, 0, sizeof(*_pHotkeyStatus));
	_pHotkeyStatus->err = PAD_ERR_NONE;

	std::unique_lock<std::recursive_mutex> lk(s_config.controls_lock, std::try_to_lock);

	if (!lk.owns_lock())
	{
		// if gui has lock (messing with controls), skip this input cycle
		for (int i = 0; i < 6; i++)
			_pHotkeyStatus->button[i] = 0;

		return;
	}

	// get input
	((HotkeyManager*)s_config.controllers[_port])->GetInput(_pHotkeyStatus);
}

bool IsPressed(int Id, bool held)
{
	HotkeyStatus hotkey;
	memset(&hotkey, 0, sizeof(hotkey));
	GetStatus(0, &hotkey);
	unsigned int set = Id / 32;
	unsigned int setKey = Id % 32;
	if (hotkey.button[set] & (1 << setKey))
	{
		hotkeyDown[set] |= (1 << setKey);
		if (held)
			return true;
	}
	else
	{
		bool pressed = !!(hotkeyDown[set] & (1 << setKey));
		hotkeyDown[set] &= ~(1 << setKey);
		if (pressed)
			return true;
	}

	return false;
}

void Initialize(void* const hwnd)
{
	if (s_config.controllers.empty())
		s_config.controllers.push_back(new HotkeyManager());

	g_controller_interface.Initialize(hwnd);

	// load the saved controller config
	s_config.LoadConfig(true);

	for (unsigned int i = 0; i < 6; ++i)
		hotkeyDown[i] = 0;
}

void Shutdown()
{
	std::vector<ControllerEmu*>::const_iterator
		i = s_config.controllers.begin(),
		e = s_config.controllers.end();
	for (; i != e; ++i)
		delete *i;
	s_config.controllers.clear();

	g_controller_interface.Shutdown();
}

}
Example #2
0
void LoadConfig()
{
  s_config.LoadConfig(true);
}
Example #3
0
void Shutdown()
{
  s_config.ClearControllers();

  g_controller_interface.Shutdown();
}
Example #4
0
/**
 * Looks up the specified key code, and returns the associated event
 * id.  Returns 0 if the key was not found.
 */
gcc_pure
static unsigned
key_to_event(InputEvents::Mode mode, unsigned key_code)
{
  return input_config.GetKeyEvent(mode, key_code);
}
Example #5
0
namespace HotkeyManagerEmu
{
static u32 s_hotkeyDown[(NUM_HOTKEYS + 31) / 32];
static HotkeyStatus s_hotkey;
static bool s_enabled;

static InputConfig s_config("Hotkeys", _trans("Hotkeys"), "Hotkeys");

InputConfig* GetConfig()
{
  return &s_config;
}

void GetStatus()
{
  s_hotkey.err = PAD_ERR_NONE;

  // Get input
  static_cast<HotkeyManager*>(s_config.GetController(0))->GetInput(&s_hotkey);
}

bool IsEnabled()
{
  return s_enabled;
}

void Enable(bool enable_toggle)
{
  s_enabled = enable_toggle;
}

bool IsPressed(int Id, bool held)
{
  unsigned int set = Id / 32;
  unsigned int setKey = Id % 32;
  if (s_hotkey.button[set] & (1 << setKey))
  {
    bool pressed = !!(s_hotkeyDown[set] & (1 << setKey));
    s_hotkeyDown[set] |= (1 << setKey);
    if (!pressed || held)
      return true;
  }
  else
  {
    s_hotkeyDown[set] &= ~(1 << setKey);
  }

  return false;
}

void Initialize(void* const hwnd)
{
  if (s_config.ControllersNeedToBeCreated())
    s_config.CreateController<HotkeyManager>();

  g_controller_interface.Initialize(hwnd);

  // load the saved controller config
  s_config.LoadConfig(true);

  for (u32& key : s_hotkeyDown)
    key = 0;

  s_enabled = true;
}

void LoadConfig()
{
  s_config.LoadConfig(true);
}

void Shutdown()
{
  s_config.ClearControllers();

  g_controller_interface.Shutdown();
}
}
Example #6
0
ControllerEmu::ControlGroup* GetTurntableGroup(int number, WiimoteEmu::TurntableGroup group)
{
  return static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))
      ->GetTurntableGroup(group);
}
Example #7
0
void Shutdown()
{
  s_config.ClearControllers();

  WiimoteReal::Stop();
}
Example #8
0
namespace Wiimote
{
static InputConfig s_config(WIIMOTE_INI_NAME, _trans("Wii Remote"), "Wiimote");

InputConfig* GetConfig()
{
  return &s_config;
}

ControllerEmu::ControlGroup* GetWiimoteGroup(int number, WiimoteEmu::WiimoteGroup group)
{
  return static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->GetWiimoteGroup(group);
}

ControllerEmu::ControlGroup* GetNunchukGroup(int number, WiimoteEmu::NunchukGroup group)
{
  return static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->GetNunchukGroup(group);
}

ControllerEmu::ControlGroup* GetClassicGroup(int number, WiimoteEmu::ClassicGroup group)
{
  return static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->GetClassicGroup(group);
}

ControllerEmu::ControlGroup* GetGuitarGroup(int number, WiimoteEmu::GuitarGroup group)
{
  return static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->GetGuitarGroup(group);
}

ControllerEmu::ControlGroup* GetDrumsGroup(int number, WiimoteEmu::DrumsGroup group)
{
  return static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->GetDrumsGroup(group);
}

ControllerEmu::ControlGroup* GetTurntableGroup(int number, WiimoteEmu::TurntableGroup group)
{
  return static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))
      ->GetTurntableGroup(group);
}

void Shutdown()
{
  s_config.ClearControllers();

  WiimoteReal::Stop();
}

void Initialize(InitializeMode init_mode)
{
  if (s_config.ControllersNeedToBeCreated())
  {
    for (unsigned int i = WIIMOTE_CHAN_0; i < MAX_BBMOTES; ++i)
      s_config.CreateController<WiimoteEmu::Wiimote>(i);
  }

  g_controller_interface.RegisterDevicesChangedCallback(LoadConfig);

  LoadConfig();

  WiimoteReal::Initialize(init_mode);

  // Reload Wiimotes with our settings
  if (Movie::IsMovieActive())
    Movie::ChangeWiiPads();
}

void Connect(unsigned int index, bool connect)
{
  if (SConfig::GetInstance().m_bt_passthrough_enabled || index >= MAX_BBMOTES)
    return;

  const auto ios = IOS::HLE::GetIOS();
  if (!ios)
    return;

  const auto bluetooth = std::static_pointer_cast<IOS::HLE::Device::BluetoothEmu>(
      ios->GetDeviceByName("/dev/usb/oh1/57e/305"));

  if (bluetooth)
    bluetooth->AccessWiimoteByIndex(index)->Activate(connect);

  const char* message = connect ? "Wii Remote %u connected" : "Wii Remote %u disconnected";
  Core::DisplayMessage(StringFromFormat(message, index + 1), 3000);
}

void ResetAllWiimotes()
{
  for (int i = WIIMOTE_CHAN_0; i < MAX_BBMOTES; ++i)
    static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(i))->Reset();
}

void LoadConfig()
{
  s_config.LoadConfig(false);
  s_last_connect_request_counter.fill(0);
}

void Resume()
{
  WiimoteReal::Resume();
}

void Pause()
{
  WiimoteReal::Pause();
}

// An L2CAP packet is passed from the Core to the Wiimote on the HID CONTROL channel.
void ControlChannel(int number, u16 channel_id, const void* data, u32 size)
{
  if (g_wiimote_sources[number])
  {
    static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))
        ->ControlChannel(channel_id, data, size);
  }
}

// An L2CAP packet is passed from the Core to the Wiimote on the HID INTERRUPT channel.
void InterruptChannel(int number, u16 channel_id, const void* data, u32 size)
{
  if (g_wiimote_sources[number])
  {
    static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))
        ->InterruptChannel(channel_id, data, size);
  }
}

bool ButtonPressed(int number)
{
  if (s_last_connect_request_counter[number] > 0)
  {
    --s_last_connect_request_counter[number];
    if (g_wiimote_sources[number] && NetPlay::IsNetPlayRunning())
      Wiimote::NetPlay_GetButtonPress(number, false);
    return false;
  }

  bool button_pressed = false;

  if (WIIMOTE_SRC_EMU & g_wiimote_sources[number])
    button_pressed =
        static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->CheckForButtonPress();

  if (WIIMOTE_SRC_REAL & g_wiimote_sources[number])
    button_pressed = WiimoteReal::CheckForButtonPress(number);

  if (g_wiimote_sources[number] && NetPlay::IsNetPlayRunning())
    button_pressed = Wiimote::NetPlay_GetButtonPress(number, button_pressed);

  return button_pressed;
}

// This function is called periodically by the Core to update Wiimote state.
void Update(int number, bool connected)
{
  if (connected)
  {
    if (WIIMOTE_SRC_EMU & g_wiimote_sources[number])
      static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->Update();
    else
      WiimoteReal::Update(number);
  }
  else
  {
    if (ButtonPressed(number))
    {
      Connect(number, true);
      // arbitrary value so it doesn't try to send multiple requests before Dolphin can react
      // if Wii Remotes are polled at 200Hz then this results in one request being sent per 500ms
      s_last_connect_request_counter[number] = 100;
    }
  }
}

// Get a mask of attached the pads (eg: controller 1 & 4 -> 0x9)
unsigned int GetAttached()
{
  unsigned int attached = 0;
  for (unsigned int i = 0; i < MAX_BBMOTES; ++i)
    if (g_wiimote_sources[i])
      attached |= (1 << i);
  return attached;
}

// Save/Load state
void DoState(PointerWrap& p)
{
  for (int i = 0; i < MAX_BBMOTES; ++i)
    static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(i))->DoState(p);
}
}
Example #9
0
// Save/Load state
void DoState(PointerWrap& p)
{
  for (int i = 0; i < MAX_BBMOTES; ++i)
    static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(i))->DoState(p);
}
Example #10
0
void LoadConfig()
{
  s_config.LoadConfig(false);
  s_last_connect_request_counter.fill(0);
}
Example #11
0
void ResetAllWiimotes()
{
  for (int i = WIIMOTE_CHAN_0; i < MAX_BBMOTES; ++i)
    static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(i))->Reset();
}
Example #12
0
namespace HotkeyManagerEmu
{

static u32 s_hotkeyDown[(NUM_HOTKEYS + 31) / 32];
static HotkeyStatus s_hotkey;
static bool s_enabled;

static InputConfig s_config("Hotkeys", _trans("Hotkeys"), "Hotkeys");

InputConfig* GetConfig()
{
	return &s_config;
}

void GetStatus()
{
	s_hotkey.err = PAD_ERR_NONE;

	// get input
	((HotkeyManager*)s_config.controllers[0])->GetInput(&s_hotkey);
}

bool IsEnabled()
{
	return s_enabled;
}

void Enable(bool enable_toggle)
{
	s_enabled = enable_toggle;
}

bool IsPressed(int Id, bool held)
{
	unsigned int set = Id / 32;
	unsigned int setKey = Id % 32;
	if (s_hotkey.button[set] & (1 << setKey))
	{
		bool pressed = !!(s_hotkeyDown[set] & (1 << setKey));
		s_hotkeyDown[set] |= (1 << setKey);
		if (!pressed || held)
			return true;
	}
	else
	{
		s_hotkeyDown[set] &= ~(1 << setKey);
	}

	return false;
}

void Initialize(void* const hwnd)
{
	if (s_config.controllers.empty())
		s_config.controllers.push_back(new HotkeyManager());

	g_controller_interface.Initialize(hwnd);

	// load the saved controller config
	s_config.LoadConfig(true);

	for (u32& key : s_hotkeyDown)
		key = 0;

	s_enabled = true;
}

void LoadConfig()
{
	s_config.LoadConfig(true);
}

void Shutdown()
{
	std::vector<ControllerEmu*>::const_iterator
		i = s_config.controllers.begin(),
		e = s_config.controllers.end();
	for (; i != e; ++i)
		delete *i;
	s_config.controllers.clear();

	g_controller_interface.Shutdown();
}

}