yarp-devices
Loading...
Searching...
No Matches
Wiimote.hpp
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3#ifndef __WIIMOTE_HPP__
4#define __WIIMOTE_HPP__
5
6#include <poll.h>
7
8#include <mutex>
9
10#include <yarp/conf/version.h>
11
12#include <yarp/os/Thread.h>
13
14#include <yarp/dev/DeviceDriver.h>
15#include <yarp/dev/IJoypadController.h>
16
17#include <xwiimote.h>
18
19#include "Wiimote_ParamsParser.h"
20
32{
33 int accelX {0};
34 int accelY {0};
35 int accelZ {0};
36
37 bool buttonA {false};
38 bool buttonB {false};
39
40 bool button1 {false};
41 bool button2 {false};
42};
43
48class WiimoteDispatcherThread : public yarp::os::Thread
49{
50public:
51
53 void beforeStart() override;
54
56 void run() override;
57
59 void setInterfacePointer(struct xwii_iface * iface)
60 {
61 this->iface = iface;
62 }
63
66
67private:
68
69 struct xwii_iface * iface {nullptr};
70 struct xwii_event event;
71
72 WiimoteEventData eventData;
73 mutable std::mutex eventDataMutex;
74
75 struct pollfd fds[2];
76 int fds_num {0};
77};
78
83class Wiimote : public yarp::dev::DeviceDriver,
84 public yarp::dev::IJoypadController,
86{
87public:
88 // --------- DeviceDriver Declarations. Implementation in DeviceDriverImpl.cpp ---------
89 bool open(yarp::os::Searchable& config) override;
90 bool close() override;
91
92 // --------- IJoypadController Declarations. Implementation in IJoypadControllerImpl.cpp ---------
93#if YARP_VERSION_COMPARE(>=, 4, 0, 0)
94 yarp::dev::ReturnValue getAxisCount(std::size_t & axis_count) override;
95 yarp::dev::ReturnValue getButtonCount(std::size_t & button_count) override;
96 yarp::dev::ReturnValue getTrackballCount(std::size_t & trackball_count) override;
97 yarp::dev::ReturnValue getHatCount(std::size_t & hat_count) override;
98 yarp::dev::ReturnValue getTouchSurfaceCount(std::size_t & touch_count) override;
99 yarp::dev::ReturnValue getStickCount(std::size_t & stick_count) override;
100 yarp::dev::ReturnValue getButton(std::size_t button_id, double & value) override;
101 yarp::dev::ReturnValue getTrackball(std::size_t trackball_id, yarp::dev::TrackballData & value) override;
102 yarp::dev::ReturnValue getHat(std::size_t hat_id, unsigned char & value) override;
103 yarp::dev::ReturnValue getAxis(std::size_t axis_id, double & value) override;
104 yarp::dev::ReturnValue getAllAxes(std::vector<double> & values) override;
105 yarp::dev::ReturnValue getStick(std::size_t stick_id, yarp::dev::StickData & value, yarp::dev::IJoypadController::JoypadCtrl_coordinateMode coordinate_mode) override;
106 yarp::dev::ReturnValue getTouch(std::size_t touch_id, std::vector<yarp::dev::TouchData> & value) override;
107#else
108 bool getAxisCount(unsigned int & axis_count) override;
109 bool getButtonCount(unsigned int & button_count) override;
110 bool getTrackballCount(unsigned int & trackball_count) override;
111 bool getHatCount(unsigned int & hat_count) override;
112 bool getTouchSurfaceCount(unsigned int & touch_count) override;
113 bool getStickCount(unsigned int & stick_count) override;
114 bool getStickDoF(unsigned int stick_id, unsigned int & DoF) override;
115 bool getButton(unsigned int button_id, float & value) override;
116 bool getTrackball(unsigned int trackball_id, yarp::sig::Vector & value) override;
117 bool getHat(unsigned int hat_id, unsigned char & value) override;
118 bool getAxis(unsigned int axis_id, double & value) override;
119 bool getStick(unsigned int stick_id, yarp::sig::Vector & value, yarp::dev::IJoypadController::JoypadCtrl_coordinateMode coordinate_mode) override;
120 bool getTouch(unsigned int touch_id, yarp::sig::Vector & value) override;
121#endif
122
123private:
124 static char * getDevicePath(int id);
125
126 struct xwii_iface * iface {nullptr};
127
128 WiimoteDispatcherThread dispatcherThread;
129};
130
131#endif // __WIIMOTE_HPP__
Thread that listens to Wiimote events.
Definition Wiimote.hpp:49
void run() override
Main body of the new thread.
Definition WiimoteDispatcherThread.cpp:29
void beforeStart() override
Called just before a new thread starts.
Definition WiimoteDispatcherThread.cpp:14
WiimoteEventData getEventData() const
Retrieve event data object.
Definition WiimoteDispatcherThread.cpp:100
void setInterfacePointer(struct xwii_iface *iface)
Set pointer to xwii_iface.
Definition Wiimote.hpp:59
Definition Wiimote_ParamsParser.h:48
Implementation for the Wiimote controller.
Definition Wiimote.hpp:86
Holds key state data from input events.
Definition Wiimote.hpp:32