[Libphidget-cvs-commits] CVS: libphidget/src/examples phidget_c.c,1.3,1.4
Status: Alpha
Brought to you by:
jstrohm
From: Jack S. <js...@us...> - 2002-09-14 01:25:19
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory usw-pr-cvs1:/tmp/cvs-serv9040 Modified Files: phidget_c.c Log Message: Added better error checks Index: phidget_c.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_c.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** phidget_c.c 12 Sep 2002 00:24:29 -0000 1.3 --- phidget_c.c 14 Sep 2002 01:25:16 -0000 1.4 *************** *** 17,82 **** * Simply goes thru all phidgets, looking for servos and then moving them slowly. */ ! int ! main(int argn, char *argv[]) { ! int t, count; ! struct phidget **phidgets; ! printf("----------------------------------------\n"); ! printf("Phidgets Device driver test.\n\n\n"); ! // Initialize libphiget, here is where the devices are actually retrieved by the library ! // We want the library to handle signals (passing it 1) ! phidgetInit(1); ! // Get an array of pointers to phidgets and a count of available phidgets ! phidgets = phidgetGetPhidgets(&count); ! printf("Device count:%d\n", count); ! for (t = 0; t < count; t++) { ! unsigned char buffer[6]; ! float k; ! struct phidget *dev = phidgetOpen(phidgets[t]); // Open the phidget #t ! // Make sure we opened it successfully ! if (dev == NULL) { ! printf("Can't open phidget:%s\n", phidgetErrorString(phidgetLastError())); ! exit(0); ! } ! // Print out some information about this phidget ! printf ! ("Phidget Name:%s Vendor:0x0%x Product:0x0%x Serial#:%06d\n", ! phidgetTypeName(phidgetType(dev)), ! phidgetTypeVendorID(phidgetType(dev)), phidgetTypeProductID(phidgetType(dev)), phidgetSerial(dev)); ! // Is it a servo controller ! if (phidgetTypeDeviceClass(phidgetType(dev)) == LP_SERVO_CONTROLLER) { ! for (k = 0; k < 1; k += .1) { ! int i; ! // Move a single servo (will move servo 0 of a 1 or 4 servo controller) ! phidgetSingleServo(dev, k); - // Wait a bit - sleep(1); ! // Process any events that have occured, like attach/detach ! phidgetEvents(); ! } ! } ! // Close the phidget ! phidgetClose(dev); ! printf("Finished\n"); ! } ! // done using all phidgets, free's phidget memory ! phidgetDeinit(); - printf("----------------------------------------\n"); ! return (0); } --- 17,111 ---- * Simply goes thru all phidgets, looking for servos and then moving them slowly. */ ! int main (int argn, char *argv[]) { ! int t, count; ! struct phidget **phidgets; ! printf ("----------------------------------------\n"); ! printf ("Phidgets Device driver test.\n\n\n"); ! // Initialize libphiget, here is where the devices are actually retrieved by the library ! // We want the library to handle signals (passing it 1) ! if (phidgetInit (1) != LPE_NONE) ! { ! printf("error - %s\n",phidgetErrorString(phidgetLastError())); ! return(1); ! } ! // Get an array of pointers to phidgets and a count of available phidgets ! phidgets = phidgetGetPhidgets (&count); ! if (phidgets==NULL) ! { ! printf("error - %s\n",phidgetErrorString(phidgetLastError())); ! return(2); ! } ! printf ("Device count:%d\n", count); ! for (t = 0; t < count; t++) ! { ! unsigned char buffer[6]; ! float k; ! struct phidget *dev = phidgetOpen (phidgets[t]); // Open the phidget #t ! // Make sure we opened it successfully ! if (dev==NULL) ! { ! printf("error - %s\n",phidgetErrorString(phidgetLastError())); ! return(3); ! } ! // Print out some information about this phidget ! printf ("Phidget Name:%s Vendor:0x0%x Product:0x0%x Serial#:%06d\n", ! phidgetTypeName (phidgetType (dev)), ! phidgetTypeVendorID (phidgetType (dev)), ! phidgetTypeProductID (phidgetType (dev)), phidgetSerial (dev)); ! if (phidgetLastError()!=LPE_NONE) ! { ! printf("error - %s\n",phidgetErrorString(phidgetLastError())); ! return(4); ! } ! // Is it a servo controller ! if (phidgetTypeDeviceClass (phidgetType (dev)) == LP_SERVO_CONTROLLER) ! { ! for (k = 0; k < 1; k += .1) ! { ! int i; ! ! // Move a single servo (will move servo 0 of a 1 or 4 servo controller) ! if (phidgetSingleServo (dev, k)!=LPE_NONE) ! { ! printf("error - %s\n",phidgetErrorString(phidgetLastError())); ! return(5); ! } ! // Wait a bit ! sleep (1); ! // Process any events that have occured, like attach/detach ! phidgetEvents (); ! } ! } ! ! // Close the phidget ! if (phidgetClose (dev)!=LPE_NONE) ! { ! printf("error - %s\n",phidgetErrorString(phidgetLastError())); ! return(6); ! } + printf ("Finished\n"); ! } ! // done using all phidgets, free's phidget memory ! phidgetDeinit (); ! ! printf ("----------------------------------------\n"); ! ! return (0); } |