[Libphidget-cvs-commits] CVS: libphidget/src/examples ik_example.cc,NONE,1.1 Makefile.am,1.2,1.3
Status: Alpha
Brought to you by:
jstrohm
From: Jack S. <js...@us...> - 2002-12-16 22:37:42
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv17868/examples Modified Files: Makefile.am Added Files: ik_example.cc Log Message: Added onChange events to Digital and Analog inputs, wrote an example script that uses these called ik_example. --- NEW FILE: ik_example.cc --- #include <CPhidgetManager.h> #include <CInterfaceKit.h> #include <CDigitalIn.h> #include <CDigitalOut.h> #include <CAnalogIn.h> #include <unistd.h> static const char *revision="$Revision: 1.1 $"; CUID phidgetId; /** * Find the first servo controller we can */ void findUsableInterfaceKit() { // Look for a servo that we can use for all the examples vector<CUID> temp=CPhidgetManager::getInstance()->query(LP_INTERFACE_KIT_488); if (temp.size()<1) throw runtime_error("This application can't run without a phidget interface kit (see http://www.phidgets.com).\n"); phidgetId=temp[0]; printf("Interface Kit Controller found: %s\n",phidgetId.asString().c_str()); } // this shows how to overload a digital input to catch change value events class CMyDigitalIn : public CDigitalIn { public: CMyDigitalIn ( const CUID &uid) : CDigitalIn(uid) { } void onChange() { printf("Change:%d\n",value()); } }; // this shows how to overload a analog input to catch change value events class CMyAnalogIn : public CAnalogIn { public: CMyAnalogIn ( const CUID &uid) : CAnalogIn(uid) { } void onChange() { printf("Change:%f\n",value()); } }; main() { try { char adjusted_version[64]; memcpy(adjusted_version,revision+11,strlen(revision)-11-2); adjusted_version[strlen(revision)-11-2]=0; // What we are printf("ik_example: code examples of how to communicate with interface kits\n"); // Get the version number printf("Version %s\n",adjusted_version); findUsableInterfaceKit(); CInterfaceKit kit(phidgetId); CMyDigitalIn *din[8]; CMyAnalogIn *ain[4]; for (int t=0;t<8;t++) din[t]=new CMyDigitalIn(CUID(phidgetId.serial(),t+4)); for (int t=0;t<4;t++) ain[t]=new CMyAnalogIn(CUID(phidgetId.serial(),t)); while (1) kit.update(); // won't get here for (int t=0;t<8;t++) delete din[t]; for (int t=0;t<4;t++) delete ain[t]; } catch(const exception &e) { printf("exception:%s\n",e.what()); } } Index: Makefile.am =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/Makefile.am,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile.am 12 Sep 2002 02:02:44 -0000 1.2 --- Makefile.am 16 Dec 2002 22:37:08 -0000 1.3 *************** *** 1,11 **** ! bin_PROGRAMS = phidget_c phidget_cpp servo_example phidget_c_SOURCES = phidget_c.c - phidget_c_LDADD = ../libphidget/libphidget.la phidget_c_DEPENDENCIES = ../libphidget/libphidget.la phidget_cpp_SOURCES = phidget_cpp.cc - phidget_cpp_LDADD = ../libphidget/libphidget.la ../phidget++/libphidget++.la phidget_cpp_DEPENDENCIES = ../libphidget/libphidget.la ../phidget++/libphidget++.la --- 1,9 ---- ! bin_PROGRAMS = phidget_c phidget_cpp servo_example ik_example phidget_c_SOURCES = phidget_c.c phidget_c_LDADD = ../libphidget/libphidget.la phidget_c_DEPENDENCIES = ../libphidget/libphidget.la phidget_cpp_SOURCES = phidget_cpp.cc phidget_cpp_LDADD = ../libphidget/libphidget.la ../phidget++/libphidget++.la phidget_cpp_DEPENDENCIES = ../libphidget/libphidget.la ../phidget++/libphidget++.la *************** *** 13,19 **** servo_example_SOURCES = servo_example.cc - servo_example_LDADD = ../libphidget/libphidget.la ../phidget++/libphidget++.la servo_example_DEPENDENCIES = ../libphidget/libphidget.la ../phidget++/libphidget++.la CFLAGS = -I../libphidget -L../libphidget --- 11,20 ---- servo_example_SOURCES = servo_example.cc servo_example_LDADD = ../libphidget/libphidget.la ../phidget++/libphidget++.la servo_example_DEPENDENCIES = ../libphidget/libphidget.la ../phidget++/libphidget++.la + + ik_example_SOURCES = ik_example.cc + ik_example_LDADD = ../libphidget/libphidget.la ../phidget++/libphidget++.la + ik_example_DEPENDENCIES = ../libphidget/libphidget.la ../phidget++/libphidget++.la CFLAGS = -I../libphidget -L../libphidget |