Panda3D
vrpnAnalog.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 vrpnAnalog.cxx
10  * @author drose
11  * @date 2001-01-26
12  */
13 
14 #include "vrpnAnalog.h"
15 #include "vrpnAnalogDevice.h"
16 #include "vrpnClient.h"
17 #include "config_vrpn.h"
18 
19 #include "indent.h"
20 
21 #include <algorithm>
22 
23 /**
24  *
25  */
26 VrpnAnalog::
27 VrpnAnalog(const std::string &analog_name, vrpn_Connection *connection) :
28  _analog_name(analog_name)
29 {
30  _analog = new vrpn_Analog_Remote(_analog_name.c_str(), connection);
31 
32  _analog->register_change_handler((void*)this, &vrpn_analog_callback);
33 }
34 
35 /**
36  *
37  */
38 VrpnAnalog::
39 ~VrpnAnalog() {
40  delete _analog;
41 }
42 
43 /**
44  * Adds the indicated VrpnAnalogDevice to the list of devices that are sharing
45  * this VrpnAnalog.
46  */
47 void VrpnAnalog::
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 VrpnAnalogDevice from the list of devices that are
57  * sharing this VrpnAnalog.
58  */
59 void VrpnAnalog::
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  *
75  */
76 void VrpnAnalog::
77 output(std::ostream &out) const {
78  out << _analog_name;
79 }
80 
81 /**
82  *
83  */
84 void VrpnAnalog::
85 write(std::ostream &out, int indent_level) const {
86  indent(out, indent_level)
87  << get_analog_name() << " ("
88  << _devices.size() << " devices)\n";
89 }
90 
91 /**
92  * Receives the analog event data from the VRPN code and sends it to any
93  * interested VrpnAnalogDevices.
94  */
95 void VRPN_CALLBACK VrpnAnalog::
96 vrpn_analog_callback(void *userdata, const vrpn_ANALOGCB info) {
97  VrpnAnalog *self = (VrpnAnalog *)userdata;
98 
99  Devices::iterator di;
100  for (di = self->_devices.begin(); di != self->_devices.end(); ++di) {
101  VrpnAnalogDevice *device = (*di);
102  for (int i = 0; i < info.num_channel; i++) {
103  device->set_axis_value(i, info.channel[i]);
104  }
105  }
106 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void unmark(VrpnAnalogDevice *device)
Removes the indicated VrpnAnalogDevice from the list of devices that are sharing this VrpnAnalog.
Definition: vrpnAnalog.cxx:60
The Panda interface to a VRPN analog device.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const std::string & get_analog_name() const
Returns the name of the analog device that was used to create this VrpnAnalog.
Definition: vrpnAnalog.I:19
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.
void mark(VrpnAnalogDevice *device)
Adds the indicated VrpnAnalogDevice to the list of devices that are sharing this VrpnAnalog.
Definition: vrpnAnalog.cxx:48
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the actual interface to a particular VRPN analog device, and all of its numbered controls.
Definition: vrpnAnalog.h:38