mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 05:57:29 +02:00
Added preferences for the Perception Neuron plugin.
By default this plugin is disabled. The server address and port number are also configurable.
This commit is contained in:
parent
1970deab92
commit
9b0ce556e7
3 changed files with 99 additions and 26 deletions
|
@ -17,7 +17,7 @@ PreferencesDialog {
|
||||||
id: root
|
id: root
|
||||||
objectName: "GeneralPreferencesDialog"
|
objectName: "GeneralPreferencesDialog"
|
||||||
title: "General Settings"
|
title: "General Settings"
|
||||||
showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Sixense Controllers"]
|
showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Sixense Controllers", "Perception Neuron"]
|
||||||
property var settings: Settings {
|
property var settings: Settings {
|
||||||
category: root.objectName
|
category: root.objectName
|
||||||
property alias x: root.x
|
property alias x: root.x
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <NumericalConstants.h>
|
#include <NumericalConstants.h>
|
||||||
#include <StreamUtils.h>
|
#include <StreamUtils.h>
|
||||||
|
#include <Preferences.h>
|
||||||
|
#include <SettingHandle.h>
|
||||||
|
|
||||||
Q_DECLARE_LOGGING_CATEGORY(inputplugins)
|
Q_DECLARE_LOGGING_CATEGORY(inputplugins)
|
||||||
Q_LOGGING_CATEGORY(inputplugins, "hifi.inputplugins")
|
Q_LOGGING_CATEGORY(inputplugins, "hifi.inputplugins")
|
||||||
|
@ -30,6 +32,10 @@ Q_LOGGING_CATEGORY(inputplugins, "hifi.inputplugins")
|
||||||
const char* NeuronPlugin::NAME = "Neuron";
|
const char* NeuronPlugin::NAME = "Neuron";
|
||||||
const char* NeuronPlugin::NEURON_ID_STRING = "Perception Neuron";
|
const char* NeuronPlugin::NEURON_ID_STRING = "Perception Neuron";
|
||||||
|
|
||||||
|
const bool DEFAULT_ENABLED = false;
|
||||||
|
const QString DEFAULT_SERVER_ADDRESS = "localhost";
|
||||||
|
const int DEFAULT_SERVER_PORT = 7001;
|
||||||
|
|
||||||
// indices of joints of the Neuron standard skeleton.
|
// indices of joints of the Neuron standard skeleton.
|
||||||
// This is 'almost' the same as the High Fidelity standard skeleton.
|
// This is 'almost' the same as the High Fidelity standard skeleton.
|
||||||
// It is missing a thumb joint.
|
// It is missing a thumb joint.
|
||||||
|
@ -356,6 +362,39 @@ static void SocketStatusChangedCallback(void* context, SOCKET_REF sender, Socket
|
||||||
// NeuronPlugin
|
// NeuronPlugin
|
||||||
//
|
//
|
||||||
|
|
||||||
|
void NeuronPlugin::init() {
|
||||||
|
loadSettings();
|
||||||
|
|
||||||
|
auto preferences = DependencyManager::get<Preferences>();
|
||||||
|
static const QString NEURON_PLUGIN { "Perception Neuron" };
|
||||||
|
{
|
||||||
|
auto getter = [this]()->QString { return _serverAddress; };
|
||||||
|
auto setter = [this](const QString& value) { _serverAddress = value; saveSettings(); };
|
||||||
|
auto preference = new EditPreference(NEURON_PLUGIN, "Server Address", getter, setter);
|
||||||
|
preference->setPlaceholderText("");
|
||||||
|
preferences->addPreference(preference);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
static const int MIN_PORT_NUMBER { 0 };
|
||||||
|
static const int MAX_PORT_NUMBER { 65535 };
|
||||||
|
|
||||||
|
auto getter = [this]()->float { return (float)_serverPort; };
|
||||||
|
auto setter = [this](float value) { _serverPort = (int)value; saveSettings(); };
|
||||||
|
auto preference = new SpinnerPreference(NEURON_PLUGIN, "Server Port", getter, setter);
|
||||||
|
|
||||||
|
preference->setMin(MIN_PORT_NUMBER);
|
||||||
|
preference->setMax(MAX_PORT_NUMBER);
|
||||||
|
preference->setStep(1);
|
||||||
|
preferences->addPreference(preference);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto getter = [this]()->bool { return _enabled; };
|
||||||
|
auto setter = [this](bool value) { _enabled = value; saveSettings(); };
|
||||||
|
auto preference = new CheckPreference(NEURON_PLUGIN, "Enabled", getter, setter);
|
||||||
|
preferences->addPreference(preference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool NeuronPlugin::isSupported() const {
|
bool NeuronPlugin::isSupported() const {
|
||||||
// Because it's a client/server network architecture, we can't tell
|
// Because it's a client/server network architecture, we can't tell
|
||||||
// if the neuron is actually connected until we connect to the server.
|
// if the neuron is actually connected until we connect to the server.
|
||||||
|
@ -365,6 +404,10 @@ bool NeuronPlugin::isSupported() const {
|
||||||
bool NeuronPlugin::activate() {
|
bool NeuronPlugin::activate() {
|
||||||
InputPlugin::activate();
|
InputPlugin::activate();
|
||||||
|
|
||||||
|
loadSettings();
|
||||||
|
|
||||||
|
if (_enabled) {
|
||||||
|
|
||||||
// register with userInputMapper
|
// register with userInputMapper
|
||||||
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
||||||
userInputMapper->registerDevice(_inputDevice);
|
userInputMapper->registerDevice(_inputDevice);
|
||||||
|
@ -374,24 +417,25 @@ bool NeuronPlugin::activate() {
|
||||||
BRRegisterCommandDataCallback((void*)this, CommandDataReceivedCallback);
|
BRRegisterCommandDataCallback((void*)this, CommandDataReceivedCallback);
|
||||||
BRRegisterSocketStatusCallback((void*)this, SocketStatusChangedCallback);
|
BRRegisterSocketStatusCallback((void*)this, SocketStatusChangedCallback);
|
||||||
|
|
||||||
// TODO: Pull these from prefs dialog?
|
// convert _serverAddress into a c-string.
|
||||||
// localhost is fine for now.
|
QByteArray serverAddressByteArray = _serverAddress.toUtf8();
|
||||||
_serverAddress = "localhost";
|
char* cstr = serverAddressByteArray.data();
|
||||||
_serverPort = 7001; // default port for TCP Axis Neuron server.
|
|
||||||
|
|
||||||
_socketRef = BRConnectTo((char*)_serverAddress.c_str(), _serverPort);
|
_socketRef = BRConnectTo(cstr, _serverPort);
|
||||||
if (!_socketRef) {
|
if (!_socketRef) {
|
||||||
// error
|
qCWarning(inputplugins) << "NeuronPlugin: error connecting to " << _serverAddress << ":" << _serverPort << ", error = " << BRGetLastErrorMessage();
|
||||||
qCCritical(inputplugins) << "NeuronPlugin: error connecting to " << _serverAddress.c_str() << ":" << _serverPort << ", error = " << BRGetLastErrorMessage();
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
qCDebug(inputplugins) << "NeuronPlugin: success connecting to " << _serverAddress.c_str() << ":" << _serverPort;
|
qCDebug(inputplugins) << "NeuronPlugin: success connecting to " << _serverAddress << ":" << _serverPort;
|
||||||
|
|
||||||
emit deviceConnected(getName());
|
emit deviceConnected(getName());
|
||||||
|
|
||||||
BRRegisterAutoSyncParmeter(_socketRef, Cmd_CombinationMode);
|
BRRegisterAutoSyncParmeter(_socketRef, Cmd_CombinationMode);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NeuronPlugin::deactivate() {
|
void NeuronPlugin::deactivate() {
|
||||||
|
@ -407,6 +451,7 @@ void NeuronPlugin::deactivate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
InputPlugin::deactivate();
|
InputPlugin::deactivate();
|
||||||
|
saveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NeuronPlugin::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
|
void NeuronPlugin::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
|
||||||
|
@ -426,11 +471,36 @@ void NeuronPlugin::pluginUpdate(float deltaTime, const controller::InputCalibrat
|
||||||
}
|
}
|
||||||
|
|
||||||
void NeuronPlugin::saveSettings() const {
|
void NeuronPlugin::saveSettings() const {
|
||||||
InputPlugin::saveSettings();
|
Settings settings;
|
||||||
|
QString idString = getID();
|
||||||
|
settings.beginGroup(idString);
|
||||||
|
{
|
||||||
|
settings.setValue(QString("enabled"), _enabled);
|
||||||
|
settings.setValue(QString("serverAddress"), _serverAddress);
|
||||||
|
settings.setValue(QString("serverPort"), _serverPort);
|
||||||
|
}
|
||||||
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NeuronPlugin::loadSettings() {
|
void NeuronPlugin::loadSettings() {
|
||||||
InputPlugin::loadSettings();
|
Settings settings;
|
||||||
|
QString idString = getID();
|
||||||
|
settings.beginGroup(idString);
|
||||||
|
{
|
||||||
|
// enabled
|
||||||
|
_enabled = settings.value("enabled", QVariant(DEFAULT_ENABLED)).toBool();
|
||||||
|
|
||||||
|
// serverAddress
|
||||||
|
_serverAddress = settings.value("serverAddress", QVariant(DEFAULT_SERVER_ADDRESS)).toString();
|
||||||
|
|
||||||
|
// serverPort
|
||||||
|
bool canConvertPortToInt = false;
|
||||||
|
int port = settings.value("serverPort", QVariant(DEFAULT_SERVER_PORT)).toInt(&canConvertPortToInt);
|
||||||
|
if (canConvertPortToInt) {
|
||||||
|
_serverPort = port;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -478,3 +548,4 @@ void NeuronPlugin::InputDevice::update(float deltaTime, const controller::InputC
|
||||||
_poseStateMap[controller::RIGHT_HAND_THUMB1] = controller::Pose(rightHandThumb1DefaultAbsTranslation, glm::quat(), glm::vec3(), glm::vec3());
|
_poseStateMap[controller::RIGHT_HAND_THUMB1] = controller::Pose(rightHandThumb1DefaultAbsTranslation, glm::quat(), glm::vec3(), glm::vec3());
|
||||||
_poseStateMap[controller::LEFT_HAND_THUMB1] = controller::Pose(leftHandThumb1DefaultAbsTranslation, glm::quat(), glm::vec3(), glm::vec3());
|
_poseStateMap[controller::LEFT_HAND_THUMB1] = controller::Pose(leftHandThumb1DefaultAbsTranslation, glm::quat(), glm::vec3(), glm::vec3());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ public:
|
||||||
bool isHandController() const override { return false; }
|
bool isHandController() const override { return false; }
|
||||||
|
|
||||||
// Plugin functions
|
// Plugin functions
|
||||||
|
virtual void init() override;
|
||||||
virtual bool isSupported() const override;
|
virtual bool isSupported() const override;
|
||||||
virtual const QString getName() const override { return NAME; }
|
virtual const QString getName() const override { return NAME; }
|
||||||
const QString getID() const override { return NEURON_ID_STRING; }
|
const QString getID() const override { return NEURON_ID_STRING; }
|
||||||
|
@ -68,7 +69,8 @@ protected:
|
||||||
static const char* NAME;
|
static const char* NAME;
|
||||||
static const char* NEURON_ID_STRING;
|
static const char* NEURON_ID_STRING;
|
||||||
|
|
||||||
std::string _serverAddress;
|
bool _enabled;
|
||||||
|
QString _serverAddress;
|
||||||
int _serverPort;
|
int _serverPort;
|
||||||
void* _socketRef;
|
void* _socketRef;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue