OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
wiimote_protocol.hpp
1#pragma once
2#include <ossia/detail/hash_map.hpp>
3#include <ossia/detail/timer.hpp>
4#include <ossia/network/base/protocol.hpp>
5#include <ossia/network/common/complex_type.hpp>
6#include <ossia/network/common/device_parameter.hpp>
7#include <ossia/network/context_functions.hpp>
8#include <ossia/network/domain/domain.hpp>
9#include <ossia/protocols/wiimote/wiimote_parameter.hpp>
10
11#include <array>
12#include <cinttypes>
13#include <cstdint>
14#include <thread>
15
16#define MAX_WIIMOTES_COUNT 4
17
18struct wiimote_t;
19
20namespace ossia::net
21{
22class OSSIA_EXPORT wiimote_protocol final : public ossia::net::protocol_base
23{
24 struct wiimote_parameters
25 {
26 ossia::hash_map<uint16_t, device_parameter*> button_parameters;
27
28 device_parameter* wiimote_axis{};
29 device_parameter* wiimote_gravity{};
30
31 device_parameter* nunchuk_button_c{};
32 device_parameter* nunchuk_button_z{};
33
34 device_parameter* nunchuk_axis{};
35 device_parameter* nunchuk_gravity{};
36 device_parameter* nunchuk_joystick{};
37
38 device_parameter* ir_cursor;
39 device_parameter* ir_detection;
40 };
41
42public:
43 wiimote_protocol(ossia::net::network_context_ptr ptr, const bool enable_ir);
44 ~wiimote_protocol();
45
46 void set_device(ossia::net::device_base& dev) override;
47
48 bool pull(ossia::net::parameter_base& param) override;
49 bool push(const ossia::net::parameter_base& param, const ossia::value& v) override;
50 bool push_raw(const ossia::net::full_parameter_data&) override;
51 bool observe(ossia::net::parameter_base& param, bool enable) override;
52
53 bool update(ossia::net::node_base&) override;
54
55private:
56 void create_wiimote_parameters(const unsigned int wiimote_id);
57 void close_event_loop();
58
59 void process_events();
60 void handle_wiimote_event(const unsigned int wiimote_id);
61
62 std::array<wiimote_parameters, MAX_WIIMOTES_COUNT> m_wiimotes_parameters;
63
64 ossia::timer m_timer;
65 bool m_running{};
66 bool m_ready{};
67 const bool m_enable_ir{};
68
69 struct wiimote_t** m_wiimotes{};
70 unsigned int m_wiimote_count{};
71 ossia::net::device_base* m_device{};
72};
73}
Root of a device tree.
Definition ossia/network/base/device.hpp:58
The node_base class.
Definition node.hpp:48
The parameter_base class.
Definition ossia/network/base/parameter.hpp:48
The protocol_base class.
Definition protocol.hpp:40
The value class.
Definition value.hpp:173
Full information about a parameter.
Definition parameter_data.hpp:61