mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-05-10 20:09:33 +02:00
expose Controller.triggerHapticPulse to javascript (currently does nothing)
This commit is contained in:
parent
35b80ba066
commit
6ca02dcad2
5 changed files with 71 additions and 53 deletions
|
@ -51,10 +51,13 @@ public:
|
||||||
|
|
||||||
float getValue(const Input& input) const;
|
float getValue(const Input& input) const;
|
||||||
float getValue(ChannelType channelType, uint16_t channel) const;
|
float getValue(ChannelType channelType, uint16_t channel) const;
|
||||||
Pose getPoseValue(uint16_t channel) const;
|
Pose getPoseValue(uint16_t channel) const;
|
||||||
|
|
||||||
const QString& getName() const { return _name; }
|
const QString& getName() const { return _name; }
|
||||||
|
|
||||||
|
// By default, Input Devices do not support haptics
|
||||||
|
virtual bool triggerHapticPulse(float strength, float duration, bool leftHand) { return false; }
|
||||||
|
|
||||||
// Update call MUST be called once per simulation loop
|
// Update call MUST be called once per simulation loop
|
||||||
// It takes care of updating the action states and deltas
|
// It takes care of updating the action states and deltas
|
||||||
virtual void update(float deltaTime, const InputCalibrationData& inputCalibrationData) {};
|
virtual void update(float deltaTime, const InputCalibrationData& inputCalibrationData) {};
|
||||||
|
|
|
@ -76,69 +76,73 @@ controller::ScriptingInterface::ScriptingInterface() {
|
||||||
|
|
||||||
namespace controller {
|
namespace controller {
|
||||||
|
|
||||||
QObject* ScriptingInterface::newMapping(const QString& mappingName) {
|
QObject* ScriptingInterface::newMapping(const QString& mappingName) {
|
||||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
return new MappingBuilderProxy(*userInputMapper, userInputMapper->newMapping(mappingName));
|
return new MappingBuilderProxy(*userInputMapper, userInputMapper->newMapping(mappingName));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptingInterface::enableMapping(const QString& mappingName, bool enable) {
|
void ScriptingInterface::enableMapping(const QString& mappingName, bool enable) {
|
||||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
userInputMapper->enableMapping(mappingName, enable);
|
userInputMapper->enableMapping(mappingName, enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
float ScriptingInterface::getValue(const int& source) const {
|
float ScriptingInterface::getValue(const int& source) const {
|
||||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
return userInputMapper->getValue(Input((uint32_t)source));
|
return userInputMapper->getValue(Input((uint32_t)source));
|
||||||
}
|
}
|
||||||
|
|
||||||
float ScriptingInterface::getButtonValue(StandardButtonChannel source, uint16_t device) const {
|
float ScriptingInterface::getButtonValue(StandardButtonChannel source, uint16_t device) const {
|
||||||
return getValue(Input(device, source, ChannelType::BUTTON).getID());
|
return getValue(Input(device, source, ChannelType::BUTTON).getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
float ScriptingInterface::getAxisValue(StandardAxisChannel source, uint16_t device) const {
|
float ScriptingInterface::getAxisValue(StandardAxisChannel source, uint16_t device) const {
|
||||||
return getValue(Input(device, source, ChannelType::AXIS).getID());
|
return getValue(Input(device, source, ChannelType::AXIS).getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
Pose ScriptingInterface::getPoseValue(const int& source) const {
|
Pose ScriptingInterface::getPoseValue(const int& source) const {
|
||||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
return userInputMapper->getPose(Input((uint32_t)source));
|
return userInputMapper->getPose(Input((uint32_t)source));
|
||||||
}
|
}
|
||||||
|
|
||||||
Pose ScriptingInterface::getPoseValue(StandardPoseChannel source, uint16_t device) const {
|
Pose ScriptingInterface::getPoseValue(StandardPoseChannel source, uint16_t device) const {
|
||||||
return getPoseValue(Input(device, source, ChannelType::POSE).getID());
|
return getPoseValue(Input(device, source, ChannelType::POSE).getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<Action> ScriptingInterface::getAllActions() {
|
QVector<Action> ScriptingInterface::getAllActions() {
|
||||||
return DependencyManager::get<UserInputMapper>()->getAllActions();
|
return DependencyManager::get<UserInputMapper>()->getAllActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ScriptingInterface::getDeviceName(unsigned int device) {
|
QString ScriptingInterface::getDeviceName(unsigned int device) {
|
||||||
return DependencyManager::get<UserInputMapper>()->getDeviceName((unsigned short)device);
|
return DependencyManager::get<UserInputMapper>()->getDeviceName((unsigned short)device);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<Input::NamedPair> ScriptingInterface::getAvailableInputs(unsigned int device) {
|
QVector<Input::NamedPair> ScriptingInterface::getAvailableInputs(unsigned int device) {
|
||||||
return DependencyManager::get<UserInputMapper>()->getAvailableInputs((unsigned short)device);
|
return DependencyManager::get<UserInputMapper>()->getAvailableInputs((unsigned short)device);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScriptingInterface::findDevice(QString name) {
|
int ScriptingInterface::findDevice(QString name) {
|
||||||
return DependencyManager::get<UserInputMapper>()->findDevice(name);
|
return DependencyManager::get<UserInputMapper>()->findDevice(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<QString> ScriptingInterface::getDeviceNames() {
|
QVector<QString> ScriptingInterface::getDeviceNames() {
|
||||||
return DependencyManager::get<UserInputMapper>()->getDeviceNames();
|
return DependencyManager::get<UserInputMapper>()->getDeviceNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
float ScriptingInterface::getActionValue(int action) {
|
float ScriptingInterface::getActionValue(int action) {
|
||||||
return DependencyManager::get<UserInputMapper>()->getActionState(Action(action));
|
return DependencyManager::get<UserInputMapper>()->getActionState(Action(action));
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScriptingInterface::findAction(QString actionName) {
|
int ScriptingInterface::findAction(QString actionName) {
|
||||||
return DependencyManager::get<UserInputMapper>()->findAction(actionName);
|
return DependencyManager::get<UserInputMapper>()->findAction(actionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<QString> ScriptingInterface::getActionNames() const {
|
QVector<QString> ScriptingInterface::getActionNames() const {
|
||||||
return DependencyManager::get<UserInputMapper>()->getActionNames();
|
return DependencyManager::get<UserInputMapper>()->getActionNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ScriptingInterface::triggerHapticPulse(unsigned int device, float strength, float duration, bool leftHand) const {
|
||||||
|
return DependencyManager::get<UserInputMapper>()->triggerHapticPulse(device, strength, duration, leftHand);
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptingInterface::updateMaps() {
|
void ScriptingInterface::updateMaps() {
|
||||||
QVariantMap newHardware;
|
QVariantMap newHardware;
|
||||||
|
|
|
@ -82,7 +82,9 @@ namespace controller {
|
||||||
Q_INVOKABLE float getButtonValue(StandardButtonChannel source, uint16_t device = 0) const;
|
Q_INVOKABLE float getButtonValue(StandardButtonChannel source, uint16_t device = 0) const;
|
||||||
Q_INVOKABLE float getAxisValue(StandardAxisChannel source, uint16_t device = 0) const;
|
Q_INVOKABLE float getAxisValue(StandardAxisChannel source, uint16_t device = 0) const;
|
||||||
Q_INVOKABLE Pose getPoseValue(const int& source) const;
|
Q_INVOKABLE Pose getPoseValue(const int& source) const;
|
||||||
Q_INVOKABLE Pose getPoseValue(StandardPoseChannel source, uint16_t device = 0) const;
|
Q_INVOKABLE Pose getPoseValue(StandardPoseChannel source, uint16_t device = 0) const;
|
||||||
|
|
||||||
|
Q_INVOKABLE bool triggerHapticPulse(unsigned int device, float strength, float duration, bool leftHand = true) const;
|
||||||
|
|
||||||
Q_INVOKABLE QObject* newMapping(const QString& mappingName = QUuid::createUuid().toString());
|
Q_INVOKABLE QObject* newMapping(const QString& mappingName = QUuid::createUuid().toString());
|
||||||
Q_INVOKABLE void enableMapping(const QString& mappingName, bool enable = true);
|
Q_INVOKABLE void enableMapping(const QString& mappingName, bool enable = true);
|
||||||
|
|
|
@ -336,6 +336,14 @@ QVector<QString> UserInputMapper::getActionNames() const {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool UserInputMapper::triggerHapticPulse(uint16 deviceID, float strength, float duration, bool leftHand) {
|
||||||
|
Locker locker(_lock);
|
||||||
|
if (_registeredDevices.find(deviceID) != _registeredDevices.end()) {
|
||||||
|
return _registeredDevices[deviceID]->triggerHapticPulse(strength, duration, leftHand);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int actionMetaTypeId = qRegisterMetaType<Action>();
|
int actionMetaTypeId = qRegisterMetaType<Action>();
|
||||||
int inputMetaTypeId = qRegisterMetaType<Input>();
|
int inputMetaTypeId = qRegisterMetaType<Input>();
|
||||||
int inputPairMetaTypeId = qRegisterMetaType<Input::NamedPair>();
|
int inputPairMetaTypeId = qRegisterMetaType<Input::NamedPair>();
|
||||||
|
|
|
@ -89,6 +89,7 @@ namespace controller {
|
||||||
void setActionState(Action action, float value) { _actionStates[toInt(action)] = value; }
|
void setActionState(Action action, float value) { _actionStates[toInt(action)] = value; }
|
||||||
void deltaActionState(Action action, float delta) { _actionStates[toInt(action)] += delta; }
|
void deltaActionState(Action action, float delta) { _actionStates[toInt(action)] += delta; }
|
||||||
void setActionState(Action action, const Pose& value) { _poseStates[toInt(action)] = value; }
|
void setActionState(Action action, const Pose& value) { _poseStates[toInt(action)] = value; }
|
||||||
|
bool triggerHapticPulse(uint16 deviceID, float strength, float duration, bool leftHand);
|
||||||
|
|
||||||
static Input makeStandardInput(controller::StandardButtonChannel button);
|
static Input makeStandardInput(controller::StandardButtonChannel button);
|
||||||
static Input makeStandardInput(controller::StandardAxisChannel axis);
|
static Input makeStandardInput(controller::StandardAxisChannel axis);
|
||||||
|
|
Loading…
Reference in a new issue