YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeJoypad.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6#include "FakeJoypad.h"
7#include <cstdio>
8#include <yarp/os/LogStream.h>
9#include <cmath>
10#include <yarp/os/Time.h>
11#include <iostream>
12
13
14using namespace yarp::dev;
15using namespace yarp::sig;
16using namespace yarp::os;
17
18namespace {
19YARP_LOG_COMPONENT(FAKEJOYPAD, "yarp.device.FakeJoypad")
20}
21
23{
24 m_data_touch.resize(2);
25}
26
30
32{
33 if (!this->parseParams(config)) {return false;}
34
35 return true;
36}
37
39{
40 return true;
41}
42
44{
45 axes_count = m_axisCount;
46 return ReturnValue_ok;
47}
48
50{
51 button_count = m_buttonCount;
52 return ReturnValue_ok;
53}
54
60
62{
63 hat_count = m_hatCount;
64 return ReturnValue_ok;
65}
66
68{
69 touch_count = m_touchCount;
70 return ReturnValue_ok;
71}
72
74{
75 stick_count = m_stickCount;
76 return ReturnValue_ok;
77}
78
79ReturnValue FakeJoypad::getButton(size_t button_id, double& value)
80{
81 if (button_id > m_buttonCount)
82 {
83 yCError(FAKEJOYPAD) << "stick_id out of bounds when calling 'getButton' method";
85 }
86 value = button_id*11.0;
87 return ReturnValue_ok;
88}
89
90ReturnValue FakeJoypad::getAxis(size_t axis_id, double& value)
91{
92 if (axis_id > m_axisCount)
93 {
94 yCError(FAKEJOYPAD) << "axis_id out of bounds when calling 'getAxis' method";
96 }
97 value = axis_id * 10.0;
98 return ReturnValue_ok;
99}
100
102{
103 if (stick_id > m_stickCount)
104 {
105 yCError(FAKEJOYPAD) << "stick_id out of bounds when calling 'getStick' method";
107 }
109 {
110 value.s1 = m_data_stick.s1 = stick_id * 100;
111 value.s2 = m_data_stick.s2 = stick_id * 101;
112 }
113 else
114 {
115 value.s1 = m_data_stick.s1 = stick_id * 102;
116 value.s2 = m_data_stick.s2 = stick_id * 103;
117 }
118 return ReturnValue_ok;
119}
120
121ReturnValue FakeJoypad::getTouch(size_t touch_id, std::vector<yarp::dev::TouchData>& value)
122{
123 if (touch_id > m_touchCount)
124 {
125 yCError(FAKEJOYPAD) << "touch_id out of bounds when calling 'getTouch' method";
127 }
128 value.clear();
129 value.resize(2);
130 value[0].x = m_data_touch[0].x = (double)(touch_id) * 110.0;
131 value[0].y = m_data_touch[0].y = (double)(touch_id) * 111.0;
132 value[1].x = m_data_touch[1].x = (double)(touch_id) * 112.0;
133 value[1].y = m_data_touch[1].y = (double)(touch_id) * 113.0;
134 return ReturnValue_ok;
135}
136
137ReturnValue FakeJoypad::getHat(size_t hat_id, unsigned char& value)
138{
139 if (hat_id > m_hatCount)
140 {
141 yCError(FAKEJOYPAD) << "hat_id out of bounds when calling 'getHat' method";
143 }
144 value = hat_id * 12;
145 return ReturnValue_ok;
146}
147
149{
150 if (trackball_id > m_ballCount)
151 {
152 yCError(FAKEJOYPAD) << "trackball_id out of bounds when calling 'getTrackball' method";
154 }
155
156 value.x = m_data_trackBall.x = (double)(trackball_id)*120;
157 value.y = m_data_trackBall.y = (double)(trackball_id)*121;
158 return ReturnValue_ok;
159}
#define ReturnValue_ok
Definition ReturnValue.h:82
#define ReturnValue_error_input_out_of_bounds
Definition ReturnValue.h:89
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
yarp::dev::ReturnValue getStickCount(size_t &stick_count) override
Get the number of the sticks.
yarp::dev::ReturnValue getHatCount(size_t &hat_count) override
Get number of hats.
bool close() override
Close the DeviceDriver.
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.
yarp::dev::ReturnValue getTrackballCount(size_t &trackball_count) override
Get number of trackballs.
virtual ~FakeJoypad()
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::dev::ReturnValue getTouchSurfaceCount(size_t &touch_count) override
Get the number of touch surface.
yarp::dev::ReturnValue getButtonCount(size_t &button_count) override
Get number of buttons.
yarp::dev::ReturnValue getButton(size_t button_id, double &value) override
Get the value of a button.
yarp::dev::ReturnValue getHat(size_t hat_id, unsigned char &value) override
Get the value of an Hat.
yarp::dev::ReturnValue getAxis(size_t axis_id, double &value) override
Get the value of an axis if present, return false otherwise.
yarp::dev::ReturnValue getTrackball(size_t trackball_id, yarp::dev::TrackballData &value) override
Get the axes change of a Trackball.
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 getAxisCount(size_t &axis_count) override
Get number of axes.
A mini-server for performing network communication in the background.
A base class for nested structures that can be searched.
Definition Searchable.h:31
#define yCError(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.