17#define buttActionGroupName "BUTTON_EXECUTE"
19#define JoyData yarp::dev::IJoypadEvent::joyData
23#ifndef YARP_NO_DEPRECATED
28 EventDrivenEnabled(
false)
33bool isEqual(
const float& a,
const float& b,
const float& tolerance)
35 return fabs(a - b) < tolerance;
38bool isEqual(
const double& a,
const double& b,
const double& tolerance)
40 return fabs(a - b) < tolerance;
49 for (
size_t i = 0;
i < a.
size();
i++)
51 if (
fabs(a[
i] - b[
i]) > tolerance)
62 if(getRawButtonCount(count) && count)
65 for(
unsigned int i = 0;
i < count;
i++)
67 getRawButton(
i, value);
68 old_buttons.push_back(value);
72 if(getRawAxisCount(count) && count)
75 for(
unsigned int i = 0;
i < count;
i++)
78 old_axes.push_back(value);
82 if(getRawHatCount(count) && count)
84 unsigned char value = 0;
85 for(
unsigned int i = 0;
i < count;
i++)
88 old_hats.push_back(value);
92 if(getRawTrackballCount(count) && count)
95 for(
unsigned int i = 0;
i < count;
i++)
97 getRawTrackball(
i, value);
98 old_trackballs.push_back(value);
102 if(getRawStickCount(count) && count)
105 for(
unsigned int i = 0;
i < count;
i++)
108 old_sticks.push_back(value);
113 if(getRawTouchSurfaceCount(count) && count)
116 for(
unsigned int i = 0;
i < count;
i++)
118 getRawTouch(
i, value);
119 old_touches.push_back(value);
134 std::vector<JoyData<float> >
buttons;
135 std::vector<JoyData<double> > axes;
136 std::vector<JoyData<unsigned char> >
hats;
137 std::vector<JoyData<yarp::sig::Vector> >
trackBalls;
138 std::vector<JoyData<yarp::sig::Vector> >
sticks;
139 std::vector<JoyData<yarp::sig::Vector> > Touch;
141 if(getRawButtonCount(count) && count)
144 for(
unsigned int i = 0;
i < count;
i++)
146 getRawButton(
i, value);
147 if(!
isEqual(value, old_buttons[
i], 0.00001f))
151 old_buttons[
i] = value;
156 if(getRawAxisCount(count) && count)
159 for(
unsigned int i = 0;
i < count;
i++)
161 getRawAxis(
i, value);
162 if(!
isEqual(value, old_axes[
i], 0.00001))
165 axes.emplace_back(
i, value);
171 if(getRawHatCount(count) && count)
173 unsigned char value = 0;
174 for(
unsigned int i = 0;
i < count;
i++)
177 if(value != old_hats[
i])
180 hats.emplace_back(
i, value);
186 if(getRawTrackballCount(count) && count)
189 for(
unsigned int i = 0;
i < count;
i++)
191 getRawTrackball(
i, value);
192 if(!
isEqual(value, old_trackballs[
i], 0.00001))
196 old_trackballs[
i] = value;
201 if(getRawStickCount(count) && count)
204 for(
unsigned int i = 0;
i < count;
i++)
207 if(!
isEqual(value, old_sticks[
i], 0.00001))
211 old_sticks[
i] = value;
216 if(getRawTouchSurfaceCount(count) && count)
219 for(
unsigned int i = 0;
i < count;
i++)
221 getRawTouch(
i, value);
222 if(!
isEqual(value, old_touches[
i], 0.00001))
225 Touch.emplace_back(
i, value);
226 old_touches[
i] = value;
249 EventDrivenEnabled =
true;
258 yError() <<
"IJoypadController: event thread is already running";
264 EventDrivenEnabled =
true;
270 yError() <<
"IJoypadController: you must provide a valid event to start the event thread";
279 EventDrivenEnabled =
false;
318 if (EventDrivenEnabled)
320 yError() <<
"EventDriven is enable.. you can't poll the joypad state";
328 if (EventDrivenEnabled)
330 yError() <<
"EventDriven is enable.. you can't poll the joypad state";
338 if (EventDrivenEnabled)
340 yError() <<
"EventDriven is enable.. you can't poll the joypad state";
349 if (EventDrivenEnabled)
351 yError() <<
"EventDriven is enable.. you can't poll the joypad state";
355 return getRawHat(
hat_id, value);
360 if (EventDrivenEnabled)
362 yError() <<
"EventDriven is enable.. you can't poll the joypad state";
366 return getRawAxis(
axis_id, value);
371 if (EventDrivenEnabled)
373 yError() <<
"EventDriven is enable.. you can't poll the joypad state";
382 if (EventDrivenEnabled)
384 yError() <<
"EventDriven is enable.. you can't poll the joypad state";
388 return getRawTouch(
touch_id, value);
393 if (m_actions.find(
action_id) != m_actions.end())
411 int&
actCount = count ? *count : dummy;
431 yDebug() <<
"error parsing cfg";
449 yCError(
IJOYPADCONTROLLER) <<
"Button's actions parameters must be in the format 'unsigned int string' and the button id must be in range";
bool isEqual(const float &a, const float &b, const float &tolerance)
#define buttActionGroupName
virtual bool executeAction(int action_id)
virtual bool parseActions(const yarp::os::Searchable &cfg, int *count=nullptr)
bool getTouch(unsigned int touch_id, yarp::sig::Vector &value) override final
Get the value of a touch if present, return false otherwise.
bool getStickDoF(unsigned int stick_id, unsigned int &DoF) override final
Get the Degree Of Freedom count for desired stick.
bool eventDriven(bool enable, yarp::dev::IJoypadEvent *event=nullptr) override
Activate event Driven mode.
bool getStickCount(unsigned int &stick_count) override final
Get the number of the sticks.
bool getButtonCount(unsigned int &button_count) override final
Get number of buttons.
bool getTrackball(unsigned int trackball_id, yarp::sig::Vector &value) override final
Get the axes change of a Trackball.
bool getHat(unsigned int hat_id, unsigned char &value) override final
Get the value of an Hat.
bool threadInit() override final
Initialization method.
bool getAxisCount(unsigned int &axis_count) override final
Get number of axes.
JoypadCtrl_coordinateMode
bool getTrackballCount(unsigned int &Trackball_count) override final
Get number of trackballs.
void run() override final
Loop function.
bool getButton(unsigned int button_id, float &value) override final
Get the value of a button.
bool getTouchSurfaceCount(unsigned int &touch_count) override final
Get the number of touch surface.
bool getHatCount(unsigned int &Hat_count) override final
Get number of hats.
bool getAxis(unsigned int axis_id, double &value) override final
Get the value of an axis if present, return false otherwise.
bool getStick(unsigned int stick_id, yarp::sig::Vector &value, JoypadCtrl_coordinateMode coordinate_mode) override final
Get the value of a stick if present, return false otherwise.
A simple collection of objects that can be described and transmitted in a portable way.
A mini-server for performing network communication in the background.
An abstraction for a periodic thread.
A base class for nested structures that can be searched.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.