YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
JoypadControl_nwc_yarp.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef YARP_DEV_JOYPADCONTROL_NWC_YARP_H
7#define YARP_DEV_JOYPADCONTROL_NWC_YARP_H
8
12#include <vector>
13#include <mutex>
15
23#include <yarp/dev/AllJoyData.h>
24
25#define DEFAULT_THREAD_PERIOD 10
26
27template <class T>
30{
31 private:
32 T data;
33 std::mutex mtx;
34 bool test=true;
35
36 public:
38 void onRead(T &v) override
39 {
40 if constexpr (std::is_same_v<T, yarp::dev::AxisDataList>)
41 {
42 test=!test;
43 }
44 std::lock_guard<std::mutex> lock(mtx);
45 data = v;
46 }
47
49 {
50 std::lock_guard<std::mutex> lock(mtx);
51 return data;
52 }
53};
54
68{
69private:
70 //---------------properties
71 yarp::os::Port m_rpcPort;
78 ReaderPort<yarp::dev::AllJoyData> m_allJoyDataPort;
79 std::vector<size_t> m_stickDof;
81
82 //--------------method
83 bool getJoypadInfo();
84
85public:
91 ~JoypadControl_nwc_yarp() override = default;
92
93 //number of available devices
94 size_t m_axis_count=0;
97 size_t m_hat_count=0;
98 size_t m_touch_count=0;
99 size_t m_stick_count=0;
100
101 //DeviceDriver
102 bool open(yarp::os::Searchable& config) override;
103 bool close() override;
104
105 //IJoypadController;
106 yarp::dev::ReturnValue getAxisCount(size_t& axis_count) override;
107 yarp::dev::ReturnValue getButtonCount(size_t& button_count) override;
108 yarp::dev::ReturnValue getTrackballCount(size_t& Trackball_count) override;
109 yarp::dev::ReturnValue getHatCount(size_t& Hat_count) override;
110 yarp::dev::ReturnValue getTouchSurfaceCount(size_t& touch_count) override;
111 yarp::dev::ReturnValue getStickCount(size_t& stick_count) override;
112 yarp::dev::ReturnValue getButton(size_t button_id, double& value) override;
113 yarp::dev::ReturnValue getTrackball(size_t trackball_id, yarp::dev::TrackballData& value) override;
114 yarp::dev::ReturnValue getHat(size_t hat_id, unsigned char& value) override;
115 yarp::dev::ReturnValue getAxis(size_t axis_id, double& value) override;
116 yarp::dev::ReturnValue getAllAxes(std::vector<double>& values) override;
117 yarp::dev::ReturnValue getStick(size_t stick_id, yarp::dev::StickData& value, JoypadCtrl_coordinateMode coordinate_mode) override;
118 yarp::dev::ReturnValue getTouch(size_t touch_id, std::vector<yarp::dev::TouchData>& value) override;
119};
120
121#endif
This class is the parameters parser for class JoypadControl_nwc_yarp.
JoypadControl_nwc_yarp: joypad input network wrapper on client side
yarp::dev::ReturnValue getTrackballCount(size_t &Trackball_count) override
Get number of trackballs.
bool close() override
Close the DeviceDriver.
JoypadControl_nwc_yarp & operator=(JoypadControl_nwc_yarp &&)=delete
~JoypadControl_nwc_yarp() override=default
yarp::dev::ReturnValue getAxisCount(size_t &axis_count) override
Get number of axes.
yarp::dev::ReturnValue getTouch(size_t touch_id, std::vector< yarp::dev::TouchData > &value) override
Get the value of a touch if present, return false otherwise.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
JoypadControl_nwc_yarp(JoypadControl_nwc_yarp &&)=delete
yarp::dev::ReturnValue getTouchSurfaceCount(size_t &touch_count) override
Get the number of touch surface.
JoypadControl_nwc_yarp & operator=(const JoypadControl_nwc_yarp &)=delete
yarp::dev::ReturnValue getButtonCount(size_t &button_count) override
Get number of buttons.
yarp::dev::ReturnValue getStick(size_t stick_id, yarp::dev::StickData &value, JoypadCtrl_coordinateMode coordinate_mode) override
Get the value of a stick if present, return false otherwise.
yarp::dev::ReturnValue getButton(size_t button_id, double &value) override
Get the value of a button.
yarp::dev::ReturnValue getAllAxes(std::vector< double > &values) override
Get the values of all available joystick axes.
yarp::dev::ReturnValue getHatCount(size_t &Hat_count) override
Get number of hats.
yarp::dev::ReturnValue getTrackball(size_t trackball_id, yarp::dev::TrackballData &value) override
Get the axes change of a Trackball.
yarp::dev::ReturnValue getAxis(size_t axis_id, double &value) override
Get the value of an axis if present, return false otherwise.
JoypadControl_nwc_yarp(const JoypadControl_nwc_yarp &)=delete
yarp::dev::ReturnValue getHat(size_t hat_id, unsigned char &value) override
Get the value of an Hat.
yarp::dev::ReturnValue getStickCount(size_t &stick_count) override
Get the number of the sticks.
void onRead(T &v) override
Callback method.
Interface implemented by all device drivers.
A mini-server for performing network communication in the background.
A mini-server for network communication.
Definition Port.h:46
A base class for nested structures that can be searched.
Definition Searchable.h:31