29#include <linux/joystick.h>
54 std::unique_lock lock(mutex);
66 const IceUtil::Time age = IceUtil::Time::now() - dataTimestamp->toTime();
71 topicPrx->reportGamepadState(deviceName, js.name, data, dataTimestamp);
77 <<
"No new signal from gamepad for " << age.toMilliSecondsDouble()
78 <<
" milliseconds. Not sending data. Timeout: "
99 if (js.open(deviceName, deviceEventName))
103 ARMARX_INFO <<
"opened a gamepad named " << js.name <<
" with " << js.numberOfAxis
104 <<
" axis and " << js.numberOfButtons <<
" buttons.";
105 if (js.numberOfAxis == 8 && js.numberOfButtons == 11)
132 while (readTask->isRunning())
138 ARMARX_WARNING <<
"failed to read gamepad data - trying to reconnect";
147 std::unique_lock lock(mutex);
148 IceUtil::Time now = IceUtil::Time::now();
149 dataTimestamp =
new TimestampVariant(now);
153 float axisFactor = 1.0f / 32768.f;
155 data.leftStickY = js.axis[0] * axisFactor;
156 data.leftStickX = js.axis[1] * axisFactor;
157 data.rightStickX = js.axis[3] * axisFactor;
158 data.rightStickY = js.axis[4] * axisFactor;
159 data.dPadX = js.axis[7] * axisFactor;
160 data.dPadY = js.axis[6] * axisFactor;
161 data.leftTrigger = js.axis[2] * axisFactor;
162 data.rightTrigger = js.axis[5] * axisFactor;
165 data.leftButton = js.buttonsPressed[4];
166 data.rightButton = js.buttonsPressed[5];
167 data.backButton = js.buttonsPressed[6];
168 data.startButton = js.buttonsPressed[7];
169 data.xButton = js.buttonsPressed[2];
170 data.yButton = js.buttonsPressed[3];
171 data.aButton = js.buttonsPressed[0];
172 data.bButton = js.buttonsPressed[1];
173 data.theMiddleButton = js.buttonsPressed[8];
174 data.leftStickButton = js.buttonsPressed[9];
175 data.rightStickButton = js.buttonsPressed[10];
179 <<
" left x (float): " << data.leftStickX
180 <<
" right trigger: " << data.rightTrigger;
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
void onInitComponent() override
void onDisconnectComponent() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
void vibrate(const ::Ice::Current &=::Ice::emptyCurrent) override
bool openGamepadConnection()
void onExitComponent() override
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
SimplePeriodicTask(Ts...) -> SimplePeriodicTask< std::function< void(void)> >