Panda3D
vrpnDial.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file vrpnDial.cxx
10  * @author drose
11  * @date 2001-01-26
12  */
13 
14 #include "vrpnDial.h"
15 #include "vrpnDialDevice.h"
16 #include "vrpnClient.h"
17 #include "config_vrpn.h"
18 
19 #include "indent.h"
20 
21 #include <algorithm>
22 
23 /**
24  *
25  */
26 VrpnDial::
27 VrpnDial(const std::string &dial_name, vrpn_Connection *connection) :
28  _dial_name(dial_name)
29 {
30  _dial = new vrpn_Dial_Remote(_dial_name.c_str(), connection);
31 
32  _dial->register_change_handler((void*)this, &vrpn_dial_callback);
33 }
34 
35 /**
36  *
37  */
38 VrpnDial::
39 ~VrpnDial() {
40  delete _dial;
41 }
42 
43 /**
44  * Adds the indicated VrpnDialDevice to the list of devices that are sharing
45  * this VrpnDial.
46  */
48 mark(VrpnDialDevice *device) {
49  if (vrpn_cat.is_debug()) {
50  vrpn_cat.debug() << *this << " marking " << *device << "\n";
51  }
52  _devices.push_back(device);
53 }
54 
55 /**
56  * Removes the indicated VrpnDialDevice from the list of devices that are
57  * sharing this VrpnDial.
58  */
60 unmark(VrpnDialDevice *device) {
61  if (vrpn_cat.is_debug()) {
62  vrpn_cat.debug() << *this << " unmarking " << *device << "\n";
63  }
64 
65  Devices::iterator di =
66  find(_devices.begin(), _devices.end(), device);
67 
68  if (di != _devices.end()) {
69  _devices.erase(di);
70  }
71 }
72 
73 /**
74  * Polls the connected device. Normally you should not call this directly;
75  * this will be called by the VrpnClient.
76  */
78 poll() {
79  _dial->mainloop();
80 }
81 
82 /**
83  *
84  */
85 void VrpnDial::
86 output(std::ostream &out) const {
87  out << _dial_name;
88 }
89 
90 /**
91  *
92  */
93 void VrpnDial::
94 write(std::ostream &out, int indent_level) const {
95  indent(out, indent_level)
96  << get_dial_name() << " ("
97  << _devices.size() << " devices)\n";
98 }
99 
100 /**
101  * Receives the dial event data from the VRPN code and sends it to any
102  * interested VrpnDialDevices.
103  */
104 void VRPN_CALLBACK VrpnDial::
105 vrpn_dial_callback(void *userdata, const vrpn_DIALCB info) {
106  VrpnDial *self = (VrpnDial *)userdata;
107 
108  if (vrpn_cat.is_debug()) {
109  vrpn_cat.debug()
110  << *self << " got dial " << info.dial << " = " << info.change << "\n";
111  }
112 
113  Devices::iterator di;
114  for (di = self->_devices.begin(); di != self->_devices.end(); ++di) {
115  VrpnDialDevice *device = (*di);
116  device->push_dial(info.dial, info.change);
117  }
118 }
void push_dial(int index, double offset)
Marks that the dial has been offset by the indicated amount.
The Panda interface to a VRPN dial device.
This is the actual interface to a particular VRPN dial device, and all of its numbered dials.
Definition: vrpnDial.h:37
void mark(VrpnDialDevice *device)
Adds the indicated VrpnDialDevice to the list of devices that are sharing this VrpnDial.
Definition: vrpnDial.cxx:48
void poll()
Polls the connected device.
Definition: vrpnDial.cxx:78
void unmark(VrpnDialDevice *device)
Removes the indicated VrpnDialDevice from the list of devices that are sharing this VrpnDial.
Definition: vrpnDial.cxx:60
const std::string & get_dial_name() const
Returns the name of the dial device that was used to create this VrpnDial.
Definition: vrpnDial.I:18
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.