30#include <linux/joystick.h>
57 std::unique_lock lock(mutex);
69 const IceUtil::Time age = IceUtil::Time::now() - dataTimestamp->toTime();
74 topicPrx->reportGamepadState(deviceName, js.name, data, dataTimestamp);
80 <<
"No new signal from gamepad for " << age.toMilliSecondsDouble()
81 <<
" milliseconds. Not sending data. Timeout: "
102 if (js.open(deviceName, deviceEventName))
106 ARMARX_INFO <<
"opened a gamepad named " << js.name <<
" with " << js.numberOfAxis
107 <<
" axis and " << js.numberOfButtons <<
" buttons.";
108 if (js.numberOfAxis == 8 && js.numberOfButtons == 11)
135 while (readTask->isRunning())
141 ARMARX_WARNING <<
"failed to read gamepad data - trying to reconnect";
150 std::unique_lock lock(mutex);
151 IceUtil::Time now = IceUtil::Time::now();
152 dataTimestamp =
new TimestampVariant(now);
156 float axisFactor = 1.0f / 32768.f;
158 data.leftStickY = js.axis[0] * axisFactor;
159 data.leftStickX = js.axis[1] * axisFactor;
160 data.rightStickX = js.axis[3] * axisFactor;
161 data.rightStickY = js.axis[4] * axisFactor;
162 data.dPadX = js.axis[7] * axisFactor;
163 data.dPadY = js.axis[6] * axisFactor;
164 data.leftTrigger = js.axis[2] * axisFactor;
165 data.rightTrigger = js.axis[5] * axisFactor;
168 data.leftButton = js.buttonsPressed[4];
169 data.rightButton = js.buttonsPressed[5];
170 data.backButton = js.buttonsPressed[6];
171 data.startButton = js.buttonsPressed[7];
172 data.xButton = js.buttonsPressed[2];
173 data.yButton = js.buttonsPressed[3];
174 data.aButton = js.buttonsPressed[0];
175 data.bButton = js.buttonsPressed[1];
176 data.theMiddleButton = js.buttonsPressed[8];
177 data.leftStickButton = js.buttonsPressed[9];
178 data.rightStickButton = js.buttonsPressed[10];
182 <<
" left x (float): " << data.leftStickX
183 <<
" right trigger: " << data.rightTrigger;
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
Brief description of class GamepadUnit.
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)> >