00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "analogNode.h"
00020 #include "config_device.h"
00021 #include "dataNodeTransmit.h"
00022 #include "dcast.h"
00023
00024
00025 TypeHandle AnalogNode::_type_handle;
00026
00027
00028
00029
00030
00031
00032 AnalogNode::
00033 AnalogNode(ClientBase *client, const string &device_name) :
00034 DataNode(device_name)
00035 {
00036 _xy_output = define_output("xy", EventStoreVec2::get_class_type());
00037 _xy = new EventStoreVec2(LPoint2f(0.0f, 0.0f));
00038
00039 nassertv(client != (ClientBase *)NULL);
00040 PT(ClientDevice) device =
00041 client->get_device(ClientAnalogDevice::get_class_type(), device_name);
00042
00043 if (device == (ClientDevice *)NULL) {
00044 device_cat.warning()
00045 << "Unable to open analog device " << device_name << "\n";
00046 return;
00047 }
00048
00049 if (!device->is_of_type(ClientAnalogDevice::get_class_type())) {
00050 device_cat.error()
00051 << "Inappropriate device type " << device->get_type()
00052 << " created; expected a ClientAnalogDevice.\n";
00053 return;
00054 }
00055
00056 _analog = DCAST(ClientAnalogDevice, device);
00057 }
00058
00059
00060
00061
00062
00063
00064 AnalogNode::
00065 ~AnalogNode() {
00066
00067
00068
00069 }
00070
00071
00072
00073
00074
00075
00076 void AnalogNode::
00077 write(ostream &out, int indent_level) const {
00078 DataNode::write(out, indent_level);
00079
00080 if (_analog != (ClientAnalogDevice *)NULL) {
00081 _analog->lock();
00082 _analog->write_controls(out, indent_level + 2);
00083 _analog->unlock();
00084 }
00085 }
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 void AnalogNode::
00101 do_transmit_data(const DataNodeTransmit &, DataNodeTransmit &output) {
00102 if (is_valid()) {
00103 _analog->poll();
00104
00105 LPoint2f out(0.0f, 0.0f);
00106
00107 _analog->lock();
00108 for (int i = 0; i < max_outputs; i++) {
00109 if (_outputs[i]._index >= 0 &&
00110 _analog->is_control_known(_outputs[i]._index)) {
00111 if (_outputs[i]._flip) {
00112 out[i] = -_analog->get_control_state(_outputs[i]._index);
00113 } else {
00114 out[i] = _analog->get_control_state(_outputs[i]._index);
00115 }
00116 }
00117 }
00118 _analog->unlock();
00119 _xy->set_value(out);
00120 output.set_data(_xy_output, EventParameter(_xy));
00121 }
00122 }