22 m_ports.push_back(&m_buttonsPort );
23 m_ports.push_back(&m_axisPort );
24 m_ports.push_back(&m_stickPort );
25 m_ports.push_back(&m_trackballPort);
26 m_ports.push_back(&m_touchPort );
27 m_ports.push_back(&m_hatsPort );
31 bool JoypadControlClient::getJoypadInfo()
38 std::vector<std::tuple<int, JoypadControl::LoopablePort*, std::string> > vocabs_ports;
39 vocabs_ports.emplace_back(
VOCAB_BUTTON, &m_buttonsPort,
"/buttons");
40 vocabs_ports.emplace_back(
VOCAB_AXIS, &m_axisPort,
"/axis");
41 vocabs_ports.emplace_back(
VOCAB_STICK, &m_stickPort,
"/stick");
42 vocabs_ports.emplace_back(
VOCAB_TRACKBALL, &m_trackballPort,
"/trackballs");
43 vocabs_ports.emplace_back(
VOCAB_TOUCH, &m_touchPort,
"/touch");
44 vocabs_ports.emplace_back(
VOCAB_HAT, &m_hatsPort,
"/hat");
46 for(
auto vocab_port : vocabs_ports)
48 if (!getCount(std::get<0>(vocab_port), count)) {
54 std::string destination;
55 std::string portname = m_local + std::get<2>(vocab_port) +
":i";
56 std::get<1>(vocab_port)->valid =
true;
57 std::get<1>(vocab_port)->count = count;
61 for(
unsigned int i = 0; i < count; i++)
63 unsigned int dofCount;
66 yCError(JOYPADCONTROLCLIENT) <<
"Unable to get sticks DoF";
69 m_stickDof.push_back(dofCount);
73 yCInfo(JOYPADCONTROLCLIENT) <<
"Opening" << portname;
75 if(!std::get<1>(vocab_port)->contactable->open(portname))
77 yCError(JOYPADCONTROLCLIENT) <<
"Unable to open" << portname <<
"port";
81 source = m_remote + std::get<2>(vocab_port) +
":o";
82 destination = m_local + std::get<2>(vocab_port) +
":i";
85 yCError(JOYPADCONTROLCLIENT) <<
"Unable to connect" << portname <<
"port";
89 std::get<1>(vocab_port)->useCallback();
98 if(config.
check(
"help"))
100 yCInfo(JOYPADCONTROLCLIENT) <<
"Parameter:\n\n" <<
101 "local - prefix of the local port\n" <<
102 "remote - prefix of the port provided to and opened by JoypadControlServer\n";
104 if(!config.
check(
"local"))
106 yCError(JOYPADCONTROLCLIENT) <<
"Unable to 'local' parameter. check configuration file";
112 if(!m_rpcPort.
open(m_local +
"/rpc:o"))
114 yCError(JOYPADCONTROLCLIENT) <<
"Unable to open rpc port.";
118 yCInfo(JOYPADCONTROLCLIENT) <<
"rpc port opened. starting the handshake";
120 if(!config.
check(
"remote"))
122 yCError(JOYPADCONTROLCLIENT) <<
"Unable to find the 'remote' parameter. check configuration file";
130 yCError(JOYPADCONTROLCLIENT) <<
"Handshake failed. unable to connect to remote port" << m_remote +
"/rpc:i";
134 yCInfo(JOYPADCONTROLCLIENT) <<
"Handshake succeeded! retrieving info";
138 yCError(JOYPADCONTROLCLIENT) <<
"Unable to get joypad info.";
153 port->onTimeout(0.5);
158 bool JoypadControlClient::getCount(
const int& vocab_toget,
unsigned int& value)
165 value = m_buttonsPort.count;
170 value = m_axisPort.count;
174 value = m_trackballPort.count;
179 value = m_touchPort.count;
184 value = m_stickPort.count;
189 value = m_hatsPort.count;
202 m_rpcPort.
write(cmd, response);
252 m_rpcPort.
write(cmd, response);
275 m_rpcPort.
write(cmd, response);
283 yCError(JOYPADCONTROLCLIENT) <<
"GetButton() error. VOCAB_FAILED";
289 std::lock_guard<std::mutex> l(m_buttonsPort.mutex);
290 if(button_id < m_buttonsPort.storage.size())
292 value = m_buttonsPort.storage[button_id];
297 yCError(JOYPADCONTROLCLIENT) <<
"GetButton() error. button_id out of bound";
315 m_rpcPort.
write(cmd, response);
329 std::lock_guard<std::mutex> l(m_trackballPort.mutex);
330 if(trackball_id < m_trackballPort.storage.size() / 2)
332 value.
push_back(m_trackballPort.storage[trackball_id * 2]);
333 value.
push_back(m_trackballPort.storage[trackball_id * 2 + 1]);
354 m_rpcPort.
write(cmd, response);
367 std::lock_guard<std::mutex> l(m_hatsPort.mutex);
368 if(hat_id < m_hatsPort.storage.size())
370 value = m_hatsPort.storage[hat_id];
391 m_rpcPort.
write(cmd, response);
399 yCError(JOYPADCONTROLCLIENT) <<
"GetAxis() error. VOCAB_FAILED";
405 std::lock_guard<std::mutex> l(m_axisPort.mutex);
406 if(axis_id < m_axisPort.storage.size())
408 value = m_axisPort.storage[axis_id];
413 yCError(JOYPADCONTROLCLIENT) <<
"GetAxis() error. Axis_id out of bound";
422 if(m_rpc_only || coordinate_mode == IJoypadController::JypCtrlcoord_POLAR)
433 m_rpcPort.
write(cmd, response);
449 m_rpcPort.
write(cmd, response);
452 for(
int i = 0; i < dof; i++)
472 std::lock_guard<std::mutex> l(m_stickPort.mutex);
478 yCError(JOYPADCONTROLCLIENT) <<
"GetStick() error. Stick_id out of bound";
481 for(
size_t j = 0; j < stick_id; j++)
483 offset += m_stickDof[j];
486 for(
size_t i = 0; i < m_stickDof[stick_id]; ++i)
488 value.
push_back(m_stickPort.storage[offset + i]);
507 m_rpcPort.
write(cmd, response);
521 std::lock_guard<std::mutex> l(m_touchPort.mutex);
522 if(touch_id < m_touchPort.storage.size()/2)
524 value.
push_back(m_touchPort.storage[touch_id * 2]);
525 value.
push_back(m_touchPort.storage[touch_id * 2 + 1]);
538 std::vector<JoypadControl::LoopablePort*> portv;
539 portv.push_back(&m_buttonsPort);
540 portv.push_back(&m_axisPort);
541 portv.push_back(&m_hatsPort);
542 portv.push_back(&m_touchPort);
543 portv.push_back(&m_trackballPort);
544 portv.push_back(&m_stickPort);
548 p->contactable->interrupt();
549 p->contactable->close();
constexpr yarp::conf::vocab32_t VOCAB_OK
constexpr yarp::conf::vocab32_t VOCAB_GET
constexpr yarp::conf::vocab32_t VOCAB_VALUE
constexpr yarp::conf::vocab32_t VOCAB_COUNT
constexpr yarp::conf::vocab32_t VOCAB_BUTTON
constexpr yarp::conf::vocab32_t VOCAB_IJOYPADCTRL
constexpr yarp::conf::vocab32_t VOCAB_TOUCH
constexpr yarp::conf::vocab32_t VOCAB_HAT
constexpr yarp::conf::vocab32_t VOCAB_TRACKBALL
constexpr yarp::conf::vocab32_t VOCAB_CARTESIAN
constexpr yarp::conf::vocab32_t VOCAB_STICKDOF
constexpr yarp::conf::vocab32_t VOCAB_AXIS
constexpr yarp::conf::vocab32_t VOCAB_POLAR
constexpr yarp::conf::vocab32_t VOCAB_STICK
bool getRawAxisCount(unsigned int &axis_count) override
bool getRawHatCount(unsigned int &Hat_count) override
bool getRawButtonCount(unsigned int &button_count) override
bool getRawTrackballCount(unsigned int &Trackball_count) override
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool getRawButton(unsigned int button_id, float &value) override
bool getRawHat(unsigned int hat_id, unsigned char &value) override
bool getRawStickDoF(unsigned int stick_id, unsigned int &DoF) override
bool close() override
Close the DeviceDriver.
bool getRawStickCount(unsigned int &stick_count) override
bool getRawStick(unsigned int stick_id, yarp::sig::Vector &value, JoypadCtrl_coordinateMode coordinate_mode) override
bool getRawTrackball(unsigned int trackball_id, yarp::sig::Vector &value) override
bool getRawTouch(unsigned int touch_id, yarp::sig::Vector &value) override
bool getRawTouchSurfaceCount(unsigned int &touch_count) override
bool getRawAxis(unsigned int axis_id, double &value) override
void run() override
Loop function.
std::vector< JoypadControl::LoopablePort * > m_ports
JoypadCtrl_coordinateMode
bool getStickDoF(unsigned int stick_id, unsigned int &DoF) override final
Get the Degree Of Freedom count for desired stick.
bool getStickCount(unsigned int &stick_count) override final
Get the number of the sticks.
A simple collection of objects that can be described and transmitted in a portable way.
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
bool start()
Call this to start the thread.
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
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.
A base class for nested structures that can be searched.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual yarp::conf::vocab32_t asVocab32() const
Get vocabulary identifier as an integer.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual bool isFloat64() const
Checks if value is a 64-bit floating point number.
virtual bool isInt32() const
Checks if value is a 32-bit integer.
virtual std::string asString() const
Get string value.
void push_back(const T &elem)
Push a new element in the vector: size is changed.
#define yCInfo(component,...)
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface for the device drivers.
An interface to the operating system, including Port based communication.