From: Gerrit V. <vo...@ca...> - 2009-01-30 06:38:01
|
Hi, On Thu, 2009-01-29 at 13:29 +0000, Christoph Schmidt-Hieber wrote: > Hi, > thank you both for your replies. > > Gerrit Voss wrote: > > > > I have an idea, give me a second to get a sample implementation. Short > > question, what kind of data are you receiving ? > > I'm using two optical mouse infrared sensors which are attached to a > programmable I/O board (Arduino). The Arduino board is attached to the > USB bus. I'm receiving information from four coordinates (x and y from > each sensor), but I'm only using two of them (x from sensor 1 and y from > sensor 2). Thus, the two sensors combine to a single "virtual mouse". > I'm using libserial to read out the USB bus. In brief, here is the > relevant code snippet: > > void read_arduino(boost::shared_ptr<SerialPort> dev_file, > std::valarray<int>& x1, std::valarray<int>& y1, > std::valarray<int>& x2, std::valarray<int>& y2) > { > std::string l = dev_file->ReadLine(); > > /* assert that the string contains 6 bytes (X1, Y1, X2, Y2, '\r', > '\n') */ > if (l.length() == 6) { > > /* Read 4 bytes, convert to integers */ > x1[1] = int(l[0]); /* X Sensor 1 */ > y1[1] = int(l[1]); /* Y Sensor 1 */ > x2[1] = int(l[2]); /* X Sensor 2 */ > y2[1] = int(l[3]); /* Y Sensor 2 */ > > /* store coordinates for next plot */ > x1[0]=x1[1]; > y1[0]=y1[1]; > x2[0]=x2[1]; > y2[0]=y2[1]; > } > } > > I could easily change the output of the I/O board if that would make > integration into OpenSG easier. I've started to modify the > OSGCSMTrackball class so that it reads the custom device rather than the > regular mouse in OSGCSMTrackball::changed. However, the problem is that > OSGCSMTrackball::changed is only called upon events from the regular > mouse, but not when the custom device is active. ok, took a second longer but I added a second sample which should be closer to your needs. They are Linux examples because there I found them easier to do as I already had sample code. The interesting code bits are in Source/Contrib/ComplexSceneManager/Sensor/InterfaceSensors and Source/Contrib/ComplexSceneManager/Sensor/InterfaceSensors/Devices. with examples in Examples/CSM/Simple-SpaceNav Examples/CSM/Simple-EventMouse. The EventMouse example should be closer to your needs. What is does it reads the raw mouse input from /dev/input/eventXX and converts it to relative mouse data which can be directly pushed into the Trackball. It does so in a separate thread so it is not need external triggers and once a frame the outer sensor picks up the latest data (if something changed). In general there are two parts the XXXSensor parts which provides the interface to OpenSG and the XXXDeviceInterface parts which are the threads that poll the data. From the OpenSG side you create the sensor that delivers the data you need, e.g. MouseDataInterfaceSensor for the event mouse example. This one creates the low level device interface from the interfaceName parameter, in this case Linux2AxisEventInterface. The options parameter is just a bag that is generically pushed through to the device interface, currently only at init time. So you have to make sure that the options match the device interface created by name. What you will have to do for your example would be to write your own interfaces/option classes along the lines of OSGLinux2AxisEventInterface and OSGLinuxEventOptions. The only trick to watch out for is that the resulting mouse data is already covnerted so that it directly can go into the trackball as relative data. This translations seems rather unintuitive. (e.g. the -100 100 values in the example). Hope it helps a little, feel free to ask if something looks rather strange ;-) kind regards, gerrit |