Adding input action event

This commit is contained in:
Brad Davis 2015-10-23 09:18:44 -07:00
parent d83ad7fdc1
commit e8be92cab8
6 changed files with 26 additions and 3 deletions

View file

@ -627,7 +627,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
// Setup the userInputMapper with the actions
auto userInputMapper = DependencyManager::get<UserInputMapper>();
connect(userInputMapper.data(), &UserInputMapper::actionEvent, _controllerScriptingInterface, &ControllerScriptingInterface::actionEvent);
connect(userInputMapper.data(), &UserInputMapper::actionEvent, [this](int action, float state) {
if (state && action == toInt(controller::Action::TOGGLE_MUTE)) {
DependencyManager::get<AudioClient>()->toggleMute();

View file

@ -120,8 +120,6 @@ signals:
void wheelEvent(const WheelEvent& event);
void actionEvent(int action, float state);
private:
QString sanatizeName(const QString& name); /// makes a name clean for inclusing in JavaScript

View file

@ -44,6 +44,9 @@ static QVariantMap createDeviceMap(const controller::DeviceProxy::Pointer device
controller::ScriptingInterface::ScriptingInterface() {
auto userInputMapper = DependencyManager::get<UserInputMapper>();
connect(userInputMapper.data(), &UserInputMapper::actionEvent, this, &controller::ScriptingInterface::actionEvent);
connect(userInputMapper.data(), &UserInputMapper::inputEvent, this, &controller::ScriptingInterface::inputEvent);
// FIXME make this thread safe
connect(userInputMapper.data(), &UserInputMapper::hardwareChanged, [=] {
updateMaps();

View file

@ -129,6 +129,9 @@ namespace controller {
virtual void captureActionEvents() { _actionsCaptured = true; }
virtual void releaseActionEvents() { _actionsCaptured = false; }
signals:
void actionEvent(int action, float state);
void inputEvent(int action, float state);
private:
// Update the exposed variant maps reporting active hardware

View file

@ -516,6 +516,24 @@ void UserInputMapper::update(float deltaTime) {
}
// TODO: emit signal for pose changes
}
auto standardInputs = getStandardInputs();
if (_lastStandardStates.size() != standardInputs.size()) {
_lastStandardStates.resize(standardInputs.size());
for (auto& lastValue : _lastStandardStates) {
lastValue = 0;
}
}
for (int i = 0; i < standardInputs.size(); ++i) {
const auto& input = standardInputs[i].first;
float value = getValue(input);
float& oldValue = _lastStandardStates[i];
if (value != oldValue) {
oldValue = value;
emit inputEvent(input.id, value);
}
}
}
Input::NamedVector UserInputMapper::getAvailableInputs(uint16 deviceID) const {

View file

@ -117,6 +117,7 @@ namespace controller {
signals:
void actionEvent(int action, float state);
void inputEvent(int input, float state);
void hardwareChanged();
protected:
@ -130,6 +131,7 @@ namespace controller {
std::vector<float> _actionScales = std::vector<float>(toInt(Action::NUM_ACTIONS), 1.0f);
std::vector<float> _lastActionStates = std::vector<float>(toInt(Action::NUM_ACTIONS), 0.0f);
std::vector<Pose> _poseStates = std::vector<Pose>(toInt(Action::NUM_ACTIONS));
std::vector<float> _lastStandardStates = std::vector<float>();
glm::mat4 _sensorToWorldMat;