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/os/Thread.h>
11
12#include <yarp/dev/DeviceDriver.h>
13#include <yarp/dev/IJoypadController.h>
14
15#include <xwiimote.h>
16
17#include "Wiimote_ParamsParser.h"
18
30{
31 int accelX {0};
32 int accelY {0};
33 int accelZ {0};
34
35 bool buttonA {false};
36 bool buttonB {false};
37
38 bool button1 {false};
39 bool button2 {false};
40};
41
46class WiimoteDispatcherThread : public yarp::os::Thread
47{
48public:
49
51 void beforeStart() override;
52
54 void run() override;
55
57 void setInterfacePointer(struct xwii_iface * iface)
58 {
59 this->iface = iface;
60 }
61
64
65private:
66
67 struct xwii_iface * iface {nullptr};
68 struct xwii_event event;
69
70 WiimoteEventData eventData;
71 mutable std::mutex eventDataMutex;
72
73 struct pollfd fds[2];
74 int fds_num {0};
75};
76
81class Wiimote : public yarp::dev::DeviceDriver,
82 public yarp::dev::IJoypadController,
84{
85public:
86 // --------- DeviceDriver Declarations. Implementation in DeviceDriverImpl.cpp ---------
87 bool open(yarp::os::Searchable& config) override;
88 bool close() override;
89
90 // --------- IJoypadController Declarations. Implementation in IJoypadControllerImpl.cpp ---------
91 bool getAxisCount(unsigned int & axis_count) override;
92 bool getButtonCount(unsigned int & button_count) override;
93 bool getTrackballCount(unsigned int & trackball_count) override;
94 bool getHatCount(unsigned int & hat_count) override;
95 bool getTouchSurfaceCount(unsigned int & touch_count) override;
96 bool getStickCount(unsigned int & stick_count) override;
97 bool getStickDoF(unsigned int stick_id, unsigned int & DoF) override;
98 bool getButton(unsigned int button_id, float & value) override;
99 bool getTrackball(unsigned int trackball_id, yarp::sig::Vector & value) override;
100 bool getHat(unsigned int hat_id, unsigned char & value) override;
101 bool getAxis(unsigned int axis_id, double & value) override;
102 bool getStick(unsigned int stick_id, yarp::sig::Vector & value, yarp::dev::IJoypadController::JoypadCtrl_coordinateMode coordinate_mode) override;
103 bool getTouch(unsigned int touch_id, yarp::sig::Vector & value) override;
104
105private:
106 static char * getDevicePath(int id);
107
108 struct xwii_iface * iface {nullptr};
109
110 WiimoteDispatcherThread dispatcherThread;
111};
112
113#endif // __WIIMOTE_HPP__
Thread that listens to Wiimote events.
Definition Wiimote.hpp:47
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:57
Definition Wiimote_ParamsParser.h:48
Implementation for the Wiimote controller.
Definition Wiimote.hpp:84
Holds key state data from input events.
Definition Wiimote.hpp:30