VRPN 06.04 |
An application can open a dial device, like a knob, which can send differential orientation values back. This class is similar to the vrpn_Analog class, but it deals with dials or other orienters that can turn forever. The same device may be treated as both an analog and a dial by a server program; the client selects which behavior by connecting the appropriate remote class to the server. Selections from the #include file//---------------------------------------------------------- // User routine to handle a change in dial values. This is called when // the dial callback is called (when a message from its counterpart // across the connetion arrives). typedef struct { struct timeval msg_time; // Timestamp when change happened vrpn_int32 dial; // which dial changed vrpn_float64 change; // Fraction of a revolution it changed } vrpn_DIALCB; typedef void (*vrpn_DIALCHANGEHANDLER) (void * userdata, const vrpn_DIALCB info); // Open a dial device that is on the other end of a connection // and handle updates from it. This is the type of device // that user code will deal with. class vrpn_Dial_Remote: public vrpn_Dial { public: // The name of the device to connect to. // Optional argument to be used when the Remote MUST listen on // a connection that is already open. vrpn_Dial_Remote (const char * name, vrpn_Connection * c = NULL); ~vrpn_Dial_Remote(); // This routine calls the mainloop of the connection it's on virtual void mainloop(); // (un)Register a callback handler to handle dial updates virtual int register_change_handler(void *userdata, vrpn_DIALCHANGEHANDLER handler); virtual int unregister_change_handler(void *userdata, vrpn_DIALCHANGEHANDLER handler); }; Using vrpn_Dial_RemoteA vrpn_Dial_Remote object is used by passing the name of the dial device you want to connect to as a parameter to the constructor, and then using the dial device interface to read in values of different dials. Here is a simple example program that just prints the new value of each dial as the reports arrive: #include <stdlib.h> #include <stdio.h> #include <vrpn_Dial.h> /***************************************************************************** * Callback handler * *****************************************************************************/ void handle_dial (void *, const vrpn_DIALCB d) { printf("Dial %ld spun by %lf\n", d.dial, d.change); } int main(int argc, char *argv[]) { int done = 0; vrpn_Dial_Remote *dial; /* initialize the dial */ dial = new vrpn_Dial_Remote("Dial0@ioglab"); // Set up the dial callback handler dial->register_change_handler(NULL, handle_dial); /* * main interactive loop */ while ( ! done ) { // Let the dial device do its thing dial->mainloop(); } } /* main */ |