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