1 // Copyright 2010 Dolphin Emulator Project
2 // Licensed under GPLv2+
3 // Refer to the license.txt file included.
4 
5 #include "Core/HW/GCPad.h"
6 
7 #include <cstring>
8 
9 #include "Common/Common.h"
10 #include "Core/HW/GCPadEmu.h"
11 #include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
12 #include "InputCommon/ControllerInterface/ControllerInterface.h"
13 #include "InputCommon/GCPadStatus.h"
14 #include "InputCommon/InputConfig.h"
15 
16 namespace Pad
17 {
18 static InputConfig s_config("GCPadNew", _trans("Pad"), "GCPad");
GetConfig()19 InputConfig* GetConfig()
20 {
21   return &s_config;
22 }
23 
Shutdown()24 void Shutdown()
25 {
26   s_config.UnregisterHotplugCallback();
27 
28   s_config.ClearControllers();
29 }
30 
Initialize()31 void Initialize()
32 {
33   if (s_config.ControllersNeedToBeCreated())
34   {
35     for (unsigned int i = 0; i < 4; ++i)
36       s_config.CreateController<GCPad>(i);
37   }
38 
39   s_config.RegisterHotplugCallback();
40 
41   // Load the saved controller config
42   s_config.LoadConfig(true);
43 }
44 
LoadConfig()45 void LoadConfig()
46 {
47   s_config.LoadConfig(true);
48 }
49 
IsInitialized()50 bool IsInitialized()
51 {
52   return !s_config.ControllersNeedToBeCreated();
53 }
54 
GetStatus(int pad_num)55 GCPadStatus GetStatus(int pad_num)
56 {
57   return static_cast<GCPad*>(s_config.GetController(pad_num))->GetInput();
58 }
59 
GetGroup(int pad_num,PadGroup group)60 ControllerEmu::ControlGroup* GetGroup(int pad_num, PadGroup group)
61 {
62   return static_cast<GCPad*>(s_config.GetController(pad_num))->GetGroup(group);
63 }
64 
Rumble(const int pad_num,const ControlState strength)65 void Rumble(const int pad_num, const ControlState strength)
66 {
67   static_cast<GCPad*>(s_config.GetController(pad_num))->SetOutput(strength);
68 }
69 
ResetRumble(const int pad_num)70 void ResetRumble(const int pad_num)
71 {
72   static_cast<GCPad*>(s_config.GetController(pad_num))->SetOutput(0.0);
73 }
74 
GetMicButton(const int pad_num)75 bool GetMicButton(const int pad_num)
76 {
77   return static_cast<GCPad*>(s_config.GetController(pad_num))->GetMicButton();
78 }
79 }  // namespace Pad
80