VTB: release CVBuffer after it actually has been rendered
[xbmc.git] / xbmc / input / joysticks / RumbleGenerator.cpp
blob96ef444e25b48d77d4c6dfcea7168ba27d5c12f3
1 /*
2 * Copyright (C) 2016 Team Kodi
3 * http://kodi.tv
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)
8 * any later version.
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)),
34 m_receiver(nullptr),
35 m_type(RUMBLE_UNKNOWN)
39 void CRumbleGenerator::NotifyUser(IInputReceiver* receiver)
41 if (receiver && !m_motors.empty())
43 if (IsRunning())
44 StopThread(true);
46 m_receiver = receiver;
47 m_type = RUMBLE_NOTIFICATION;
48 Create();
52 bool CRumbleGenerator::DoTest(IInputReceiver* receiver)
54 if (receiver && !m_motors.empty())
56 if (IsRunning())
57 StopThread(true);
59 m_receiver = receiver;
60 m_type = RUMBLE_TEST;
61 Create();
63 return true;
65 return false;
68 void CRumbleGenerator::Process(void)
70 switch (m_type)
72 case RUMBLE_NOTIFICATION:
74 for (const std::string& motor : m_motors)
75 m_receiver->SetRumbleState(motor, 1.0f);
77 Sleep(1000);
79 if (m_bStop)
80 break;
82 for (const std::string& motor : m_motors)
83 m_receiver->SetRumbleState(motor, 0.0f);
85 break;
87 case RUMBLE_TEST:
89 for (const std::string& motor : m_motors)
91 m_receiver->SetRumbleState(motor, 1.0f);
93 Sleep(1000);
95 if (m_bStop)
96 break;
98 m_receiver->SetRumbleState(motor, 0.0f);
100 break;
102 default:
103 break;
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;
114 AddonPtr addon;
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());
128 return motors;