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
22FakeJoypad::FakeJoypad() = default;
23
24FakeJoypad::~FakeJoypad() = default;
25
27{
28 if (!this->parseParams(config)) {return false;}
29
30 return true;
31}
32
34{
35 return true;
36}
37
39{
40 axes_count = m_axisCount;
41 return true;
42}
43
45{
46 button_count = m_buttonCount;
47 return true;
48}
49
51{
52 trackball_count = m_ballCount;
53 return true;
54}
55
57{
58 hat_count = m_hatCount;
59 return true;
60}
61
63{
64 touch_count = m_touchCount;
65 return true;
66}
67
69{
70 stick_count = m_stickCount;
71 return true;
72}
73
74bool FakeJoypad::getRawStickDoF(unsigned int stick_id, unsigned int& DoF)
75{
76 if(stick_id > m_stickCount)
77 {
78 yCError(FAKEJOYPAD) << "stick_id out of bounds when calling 'getRawStickDoF' method";
79 return false;
80 }
81 DoF = 2;
82 return true;
83}
84
85bool FakeJoypad::getRawButton(unsigned int button_id, float& value)
86{
87 if (button_id > m_buttonCount)
88 {
89 yCError(FAKEJOYPAD) << "stick_id out of bounds when calling 'getRawButton' method";
90 return false;
91 }
92 value = button_id*10.0;
93 return true;
94}
95
96bool FakeJoypad::getRawAxis(unsigned int axis_id, double& value)
97{
98 if (axis_id > m_axisCount)
99 {
100 yCError(FAKEJOYPAD) << "axis_id out of bounds when calling 'getRawAxis' method";
101 return false;
102 }
103 value = axis_id * 10.0;
104 return true;
105}
106
108{
109 if (stick_id > m_stickCount)
110 {
111 yCError(FAKEJOYPAD) << "stick_id out of bounds when calling 'getRawStickDoF' method";
112 return false;
113 }
114 value = stick_id * 10;
115 return true;
116}
117
119{
120 if (touch_id > m_touchCount)
121 {
122 yCError(FAKEJOYPAD) << "touch_id out of bounds when calling 'getRawTouch' method";
123 return false;
124 }
125 value.resize(3);
126 value[0] = (double)(touch_id) * 10.0;
127 value[1] = (double)(touch_id) * 11.0;
128 value[2] = (double)(touch_id) * 12.0;
129 return true;
130}
131
132bool FakeJoypad::getRawHat(unsigned int hat_id, unsigned char& value)
133{
134 if (hat_id > m_hatCount)
135 {
136 yCError(FAKEJOYPAD) << "hat_id out of bounds when calling 'getRawHat' method";
137 return false;
138 }
139 value = hat_id * 10;
140 return true;
141}
142
144{
145 if (trackball_id > m_ballCount)
146 {
147 yCError(FAKEJOYPAD) << "trackball_id out of bounds when calling 'getRawTrackball' method";
148 return false;
149 }
150
151 value.resize(2);
152 value[0] = (double)(trackball_id)*10;
153 value[1] = (double)(trackball_id)*11;
154 return true;
155}
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
bool getRawAxisCount(unsigned int &axis_count) 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 getRawTouch(unsigned int touch_id, yarp::sig::Vector &value) override
bool getRawTrackballCount(unsigned int &trackball_count) override
virtual ~FakeJoypad()
bool getRawStick(unsigned int stick_id, yarp::sig::Vector &value, JoypadCtrl_coordinateMode coordinate_mode) override
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool getRawHatCount(unsigned int &hat_count) override
bool getRawButtonCount(unsigned int &button_count) override
bool getRawHat(unsigned int hat_id, unsigned char &value) override
bool getRawButton(unsigned int button_id, float &value) override
bool getRawTouchSurfaceCount(unsigned int &touch_count) override
bool getRawTrackball(unsigned int trackball_id, yarp::sig::Vector &value) override
bool getRawAxis(unsigned int axis_id, double &value) override
A mini-server for performing network communication in the background.
A base class for nested structures that can be searched.
Definition Searchable.h:31
void resize(size_t size) override
Resize the vector.
Definition Vector.h:221
#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.