17 #define buttActionGroupName "BUTTON_EXECUTE"
19 #define JoyData yarp::dev::IJoypadEvent::joyData
23 #ifndef YARP_NO_DEPRECATED
28 EventDrivenEnabled(false)
33 bool isEqual(
const float& a,
const float& b,
const float& tolerance)
35 return fabs(a - b) < tolerance;
38 bool 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);
127 bool perform =
false;
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))
150 buttons.emplace_back(i, value);
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))
195 trackBalls.emplace_back(i, value);
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))
210 sticks.emplace_back(i, value);
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;
233 m_event->action(buttons, axes, hats, trackBalls, sticks, Touch);
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;
288 return getRawAxisCount(axis_count);
293 return getRawButtonCount(button_count);
298 return getRawTrackballCount(Trackball_count);
303 return getRawHatCount(Hat_count);
308 return getRawTouchSurfaceCount(touch_count);
313 return getRawStickCount(stick_count);
318 if (EventDrivenEnabled)
320 yError() <<
"EventDriven is enable.. you can't poll the joypad state";
323 return getRawStickDoF(stick_id, DoF);
328 if (EventDrivenEnabled)
330 yError() <<
"EventDriven is enable.. you can't poll the joypad state";
333 return getRawButton(button_id, value);
338 if (EventDrivenEnabled)
340 yError() <<
"EventDriven is enable.. you can't poll the joypad state";
344 return getRawTrackball(trackball_id, value);
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";
377 return getRawStick(stick_id, value, coordinate_mode);
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())
395 yCInfo(IJOYPADCONTROLLER) <<
"executing script" << action_id <<
":" << m_actions[action_id];
396 int ret = system(m_actions[action_id].c_str());
401 yCWarning(IJOYPADCONTROLLER) <<
"no scripts associated to button" << action_id;
411 int& actCount = count ? *count : dummy;
420 if(!actionsGroup.
size())
427 for(i = 1; i < actionsGroup.
size(); i++)
431 yDebug() <<
"error parsing cfg";
437 unsigned int buttonCount;
438 if(!this->getButtonCount(buttonCount))
440 yCError(IJOYPADCONTROLLER) <<
"unable to get button count while parsing the actions";
446 (
unsigned int) keyvalue.
get(0).
asInt32() > buttonCount-1 ||
449 yCError(IJOYPADCONTROLLER) <<
"Button's actions parameters must be in the format 'unsigned int string' and the button id must be in range";
458 yCInfo(IJOYPADCONTROLLER) << actCount <<
"action parsed successfully";
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)
JoypadCtrl_coordinateMode
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.
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.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
An abstraction for a periodic thread.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
virtual bool isString() const
Checks if value is a string.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual bool isList() const
Checks if value is a list.
virtual Bottle * asList() const
Get list value.
virtual bool isInt32() const
Checks if value is a 32-bit integer.
virtual std::string asString() const
Get string value.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface for the device drivers.
An interface to the operating system, including Port based communication.