39 #include <vrpn_Button.h>
40 #include <boost/lexical_cast.hpp>
41 #include <boost/any.hpp>
42 #include <boost/variant/get.hpp>
43 #include <json/value.h>
44 #include <json/reader.h>
56 boost::optional<int> sensor,
57 common::InterfaceList &ifaces)
58 : m_remote(
new vrpn_Button_Remote(src, conn.get())),
59 m_internals(ifaces), m_all(!sensor.is_initialized()) {
60 m_remote->register_change_handler(
this, &VRPNButtonHandler::handle);
61 m_remote->register_states_handler(
62 this, &VRPNButtonHandler::handle_states);
63 OSVR_DEV_VERBOSE(
"Constructed a ButtonHandler for " << src);
65 if (sensor.is_initialized()) {
66 m_sensors.setValue(*sensor);
70 m_remote->unregister_change_handler(
this,
71 &VRPNButtonHandler::handle);
72 m_remote->unregister_states_handler(
73 this, &VRPNButtonHandler::handle_states);
76 static void VRPN_CALLBACK handle(
void *userdata, vrpn_BUTTONCB info) {
81 static void VRPN_CALLBACK handle_states(
void *userdata,
82 vrpn_BUTTONSTATESCB info) {
86 virtual void update() { m_remote->mainloop(); }
89 void m_handle(vrpn_BUTTONCB
const &info) {
90 if (!m_all && !m_sensors.contains(info.button)) {
97 m_report(timestamp, info.button, info.state);
99 void m_handle(vrpn_BUTTONSTATESCB
const &info) {
101 m_all ? info.num_buttons - 1 : m_sensors.getValue();
103 m_sensors.getIntersection(RangeType::RangeZeroTo(maxChannel))
110 if (m_sensors.empty()) {
111 m_sensors.setRangeMaxMin(maxChannel);
113 m_sensors.extendRangeToMax(maxChannel);
119 for (
auto sensor : m_sensors.getIntersection(
120 RangeType::RangeZeroTo(maxChannel))) {
121 m_report(timestamp, sensor, info.states[sensor]);
128 report.
state =
static_cast<uint8_t
>(state);
131 unique_ptr<vrpn_Button_Remote> m_remote;
137 ButtonRemoteFactory::ButtonRemoteFactory(
145 shared_ptr<RemoteHandler> ret;
147 if (source.hasTransform()) {
149 "Ignoring transform found on route for Button data!");
152 auto const &devElt = source.getDeviceElement();
156 devElt.getFullDeviceName().c_str(),
157 source.getSensorNumber(), ifaces));
The result of resolving a tree node to a device: either an original source to connect to...
Header including PathTree.h and all additional headers needed to define related types.
Header to bring unique_ptr into the osvr namespace.
void setStateAndTriggerCallbacks(const OSVR_TimeValue ×tamp, ReportType const &report)
Set state and call callbacks for a report type.
void osvrStructTimevalToTimeValue(OSVR_TimeValue *dest, const struct timeval *src)
Converts from a TimeValue struct to your system's struct timeval.
Internal, configured header file for verbosity macros.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Base class for remote device handler classes.
Class holding shared implementation between the various handlers. Primarily used to avoid the need fo...