14#define DEFAULT_THREAD_PERIOD 0.010
27 for (
size_t i = 0; i < b.size(); i++)
36 mutable std::mutex m_mutex;
67 ret.
ret = ReturnValue::return_code::return_value_error_not_ready;
83 ret.
ret = ReturnValue::return_code::return_value_error_not_ready;
99 ret.
ret = ReturnValue::return_code::return_value_error_not_ready;
115 ret.
ret = ReturnValue::return_code::return_value_error_not_ready;
131 ret.
ret = ReturnValue::return_code::return_value_error_not_ready;
147 ret.
ret = ReturnValue::return_code::return_value_error_not_ready;
163 ret.
ret = ReturnValue::return_code::return_value_error_not_ready;
177 ret.
ret = ReturnValue::return_code::return_value_error_not_ready;
192 ret.
ret = ReturnValue::return_code::return_value_error_not_ready;
196 unsigned char temp = 0;
208 ret.
ret = ReturnValue::return_code::return_value_error_not_ready;
212 std::vector<double> vals;
223 ret.
ret = ReturnValue::return_code::return_value_error_not_ready;
238 ret.
ret = ReturnValue::return_code::return_value_error_not_ready;
252 ret.
ret = ReturnValue::return_code::return_value_error_not_ready;
281 poly->
view(m_IJoypad);
284 if(m_IJoypad ==
nullptr)
296 m_RPCMsgs = std::make_unique<IJoypadControlRPCd>(this->m_IJoypad);
325 if (!v)
return false;
327 m_curr_axes.resize (m_numberOfAxes);
328 m_curr_buttons.resize (m_numberOfButtons);
329 m_curr_trackballs.resize (m_numberOfTrackballs);
330 m_curr_hats.resize (m_numberOfHats);
331 m_curr_sticks.resize (m_numberOfSticks);
332 m_curr_touches.
value.resize (m_numberOfTouchSurfaces);
334 m_last_axes.resize (m_numberOfAxes);
335 m_last_buttons.resize (m_numberOfButtons);
336 m_last_trackballs.resize (m_numberOfTrackballs);
337 m_last_hats.resize (m_numberOfHats);
338 m_last_sticks.resize (m_numberOfSticks);
339 m_last_touches.
value.resize (m_numberOfTouchSurfaces);
348bool JoypadControl_nws_yarp::openPorts()
367 b &= m_portTrackballs.
open(
m_name+
"/trackball:o");
382 return a.size() != b.size() ||
383 !std::equal(a.begin(), a.end(), b.begin());
387template <
class T,
class Compare>
390 return a.size() != b.size() ||
391 !std::equal(a.begin(), a.end(), b.begin(), comp);
396 std::ostringstream oss;
397 oss.precision(std::numeric_limits<double>::max_digits10);
399 for (std::size_t i = 0; i < v.size(); ++i)
415 auto& b = m_portButtons.
prepare();
417 for(
size_t i = 0; i < m_numberOfButtons; ++i)
419 if (!m_IJoypad->
getButton(i, m_curr_buttons[i]))
432 b.value = m_curr_buttons;
433 m_portButtons.
write();
434 m_last_buttons = m_curr_buttons;
439 b.value = m_curr_buttons;
440 m_portButtons.
write();
441 m_last_buttons = m_curr_buttons;
451 auto& b = m_portHats.
prepare();
453 for(
size_t i = 0; i < m_numberOfHats; ++i)
455 if (!m_IJoypad->
getHat(i, m_curr_hats[i]))
468 b.value.resize(m_curr_hats.size());
469 std::transform(m_curr_hats.begin(), m_curr_hats.end(), b.value.begin(), [](
unsigned char c) { return static_cast<char>(c); });
472 m_last_hats = m_curr_hats;
477 b.value.resize(m_curr_hats.size());
478 std::transform(m_curr_hats.begin(), m_curr_hats.end(), b.value.begin(), [](
unsigned char c) { return static_cast<char>(c); });
481 m_last_hats = m_curr_hats;
491 auto& b = m_portAxes.
prepare();
509 b.value = m_curr_axes;
511 m_last_axes = m_curr_axes;
516 b.value = m_curr_axes;
518 m_last_axes = m_curr_axes;
528 auto& b = m_portTrackballs.
prepare();
530 for(
size_t i = 0; i < m_numberOfTrackballs; ++i)
552 b.value = m_curr_trackballs;
553 m_portTrackballs.
write();
554 m_last_trackballs = m_curr_trackballs;
559 b.value = m_curr_trackballs;
560 m_portTrackballs.
write();
561 m_last_trackballs = m_curr_trackballs;
570 auto& b = m_portSticks.
prepare();
572 for(
size_t i = 0; i < m_numberOfSticks; ++i)
574 if (!m_IJoypad->
getStick(i, m_curr_sticks[i], m_coordsMode))
589 return lhs.s1 ==
rhs.s1 &&
594 b.value = m_curr_sticks;
595 m_portSticks.
write();
596 m_last_sticks = m_curr_sticks;
601 b.value = m_curr_sticks;
602 m_portSticks.
write();
603 m_last_sticks = m_curr_sticks;
612 auto& b = m_portTouches.
prepare();
615 m_curr_touches.
value.resize(m_numberOfTouchSurfaces);
616 for(
unsigned int i = 0; i < m_numberOfTouchSurfaces; ++i)
618 std::vector<yarp::dev::TouchData>
temp;
634 b.value = m_curr_touches.
value;
635 m_portTouches.
write();
636 m_last_touches = m_curr_touches;
641 b.value = m_curr_touches.
value;
642 m_portTouches.
write();
643 m_last_touches = m_curr_touches;
655 message.
HatsDataVal = std::vector<std::int8_t>(m_curr_hats.begin(), m_curr_hats.end());
687 m_portButtons.
close();
688 m_portSticks.
close();
689 m_portTouches.
close();
690 m_portTrackballs.
close();
702 if (!connection.
isValid()) {
return false;}
703 if (!m_RPCMsgs) {
return false;}
707 bool b = m_RPCMsgs->read(connection);
std::string printVector(const std::vector< double > &v)
bool VectorsDifferent(const std::vector< T > &a, const std::vector< T > &b)
#define DEFAULT_THREAD_PERIOD
bool VectorsDifferentC(const std::vector< T > &a, const std::vector< T > &b, Compare comp)
void cat(yarp::sig::VectorOf< T > &a, const yarp::sig::VectorOf< T > &b)
return_getAxis getAxis(const std::int32_t axis_id) override
return_getTouch getTouch(const std::int32_t touch_id) override
return_getButtonCount getButtonCount() override
return_getStickCount getStickCount() override
return_getButton getButton(const std::int32_t button_id) override
return_getTouchSurfaceCount getTouchSurfaceCount() override
return_getAxisCount getAxisCount() override
IJoypadControlRPCd(yarp::dev::IJoypadController *interfaces)
return_getHat getHat(const std::int32_t hat_id) override
return_getTrackball getTrackball(const std::int32_t trackball_id) override
return_getHatCount getHatCount() override
return_getTrackballCount getTrackballCount() override
return_getStick getStick(const std::int32_t stick_id, yarp::dev::IJoypadController::JoypadCtrl_coordinateMode mode) override
return_getAllAxes getAllAxes() override
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
bool detach() override
Detach the object (you must have first called attach).
void threadRelease() override
Release method.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
void run() override
Loop function.
bool threadInit() override
Initialization method.
bool open(yarp::os::Searchable ¶ms) override
Open the DeviceDriver.
bool attach(yarp::dev::PolyDriver *poly) override
Attach to another object.
~JoypadControl_nws_yarp() override
bool close() override
Close the DeviceDriver.
std::vector< double > ButtonDataVal
std::vector< yarp::dev::StickData > StickDataVal
std::vector< yarp::dev::TrackballData > TrackballDataVal
std::vector< double > AxisDataVal
std::vector< std::int8_t > HatsDataVal
std::vector< MultipleTouches > TouchDataVal
bool view(T *&x)
Get an interface to the device driver.
virtual yarp::dev::ReturnValue getTouchSurfaceCount(size_t &touch_count)=0
Get the number of touch surface.
virtual yarp::dev::ReturnValue getAxisCount(size_t &axis_count)=0
Get number of axes.
virtual yarp::dev::ReturnValue getTouch(size_t touch_id, std::vector< yarp::dev::TouchData > &value)=0
Get the value of a touch if present, return false otherwise.
virtual yarp::dev::ReturnValue getTrackball(size_t trackball_id, yarp::dev::TrackballData &value)=0
Get the axes change of a Trackball.
virtual yarp::dev::ReturnValue getAllAxes(std::vector< double > &values)
Get the values of all available joystick axes.
virtual yarp::dev::ReturnValue getButton(size_t button_id, double &value)=0
Get the value of a button.
virtual yarp::dev::ReturnValue getTrackballCount(size_t &Trackball_count)=0
Get number of trackballs.
JoypadCtrl_coordinateMode
virtual yarp::dev::ReturnValue getHatCount(size_t &Hat_count)=0
Get number of hats.
virtual yarp::dev::ReturnValue getHat(size_t hat_id, unsigned char &value)=0
Get the value of an Hat.
virtual yarp::dev::ReturnValue getButtonCount(size_t &button_count)=0
Get number of buttons.
virtual yarp::dev::ReturnValue getAxis(size_t axis_id, double &value)=0
Get the value of an axis if present, return false otherwise.
virtual yarp::dev::ReturnValue getStickCount(size_t &stick_count)=0
Get the number of the sticks.
virtual yarp::dev::ReturnValue getStick(size_t stick_id, yarp::dev::StickData &value, JoypadCtrl_coordinateMode coordinate_mode)=0
Get the value of a stick if present, return false otherwise.
A container for a device driver.
std::vector< MultipleTouches > value
bool detachAll() final
Detach the object (you must have first called attach).
std::vector< double > value
yarp::dev::ReturnValue ret
yarp::dev::ReturnValue ret
yarp::dev::ReturnValue ret
yarp::dev::ReturnValue ret
yarp::dev::ReturnValue ret
yarp::dev::ReturnValue ret
yarp::dev::ReturnValue ret
yarp::dev::StickData value
yarp::dev::ReturnValue ret
std::vector< yarp::dev::TouchData > value
yarp::dev::ReturnValue ret
std::int32_t Trackball_count
yarp::dev::ReturnValue ret
yarp::dev::ReturnValue ret
yarp::dev::TrackballData value
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
int getOutputCount() override
Determine how many output connections this port has.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
An interface for reading from a network connection.
virtual bool isValid() const =0
An abstraction for a periodic thread.
bool setPeriod(double period)
Set the (new) period of the thread.
bool isRunning() const
Returns true when the thread is started, false otherwise.
bool start()
Call this to start the thread.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
A base class for nested structures that can be searched.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCDebug(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.
typename vector_selector< T >::type VectorOf