2 * Copyright (C) 2016 Team Kodi
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this Program; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "RumbleGenerator.h"
22 #include "addons/AddonManager.h"
23 #include "games/controllers/Controller.h"
24 #include "games/controllers/ControllerFeature.h"
25 #include "input/joysticks/IInputReceiver.h"
27 #define RUMBLE_DURATION_MS 1000
29 using namespace JOYSTICK
;
31 CRumbleGenerator::CRumbleGenerator(const std::string
& controllerId
) :
32 CThread("RumbleGenerator"),
33 m_motors(GetMotors(controllerId
)),
35 m_type(RUMBLE_UNKNOWN
)
39 void CRumbleGenerator::NotifyUser(IInputReceiver
* receiver
)
41 if (receiver
&& !m_motors
.empty())
46 m_receiver
= receiver
;
47 m_type
= RUMBLE_NOTIFICATION
;
52 bool CRumbleGenerator::DoTest(IInputReceiver
* receiver
)
54 if (receiver
&& !m_motors
.empty())
59 m_receiver
= receiver
;
68 void CRumbleGenerator::Process(void)
72 case RUMBLE_NOTIFICATION
:
74 for (const std::string
& motor
: m_motors
)
75 m_receiver
->SetRumbleState(motor
, 1.0f
);
82 for (const std::string
& motor
: m_motors
)
83 m_receiver
->SetRumbleState(motor
, 0.0f
);
89 for (const std::string
& motor
: m_motors
)
91 m_receiver
->SetRumbleState(motor
, 1.0f
);
98 m_receiver
->SetRumbleState(motor
, 0.0f
);
107 std::vector
<std::string
> CRumbleGenerator::GetMotors(const std::string
& controllerId
)
109 using namespace ADDON
;
110 using namespace GAME
;
112 std::vector
<std::string
> motors
;
115 if (CAddonMgr::GetInstance().GetAddon(controllerId
, addon
, ADDON_GAME_CONTROLLER
))
117 ControllerPtr controller
= std::static_pointer_cast
<CController
>(addon
);
118 if (controller
->LoadLayout())
120 for (const CControllerFeature
& feature
: controller
->Layout().Features())
122 if (feature
.Type() == JOYSTICK::FEATURE_TYPE::MOTOR
)
123 motors
.push_back(feature
.Name());