libphidget-cvs-commits Mailing List for Phidget Library (Page 4)
Status: Alpha
Brought to you by:
jstrohm
You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(66) |
Oct
|
Nov
|
Dec
(73) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(9) |
Jul
(5) |
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
(2) |
From: Jack S. <js...@us...> - 2002-12-13 22:54:01
|
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory sc8-pr-cvs1:/tmp/cvs-serv23320/phidget++ Modified Files: CPhidgetManager.cc Log Message: Removed the INTERFACE_KIT class. Not used anymore Index: CPhidgetManager.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CPhidgetManager.cc 13 Dec 2002 16:42:34 -0000 1.8 --- CPhidgetManager.cc 13 Dec 2002 22:53:57 -0000 1.9 *************** *** 118,138 **** // Ask libphidget for any known phidgets ! if (tp == LP_ALL || tp == LP_PHIDGET || tp == LP_SERVO_CONTROLLER || tp == LP_INTERFACE_KIT) { int phidget_count; struct phidget **phidgets = error(phidgetGetPhidgets(&phidget_count)); ! for (int t = 0; t < phidget_count; t++) { ! if ( ! (tp == LP_PHIDGET) || ! (tp == LP_ALL) || ! (tp == LP_SERVO_CONTROLLER ! && error(phidgetTypeDeviceClass(error(phidgetType(phidgets[t])))) == ! LP_SERVO_CONTROLLER) || (tp == LP_INTERFACE_KIT ! && error(phidgetTypeDeviceClass(error(phidgetType(phidgets[t])))) == LP_INTERFACE_KIT)) { ! CUID temp_uid(error(phidgetSerial(phidgets[t]))); ! devices.insert(temp_uid); ! } } } --- 118,138 ---- // Ask libphidget for any known phidgets ! if (tp == LP_ALL || tp == LP_PHIDGET || tp == LP_SERVO_CONTROLLER /*|| tp == LP_INTERFACE_KIT*/) { int phidget_count; struct phidget **phidgets = error(phidgetGetPhidgets(&phidget_count)); ! for (int t = 0; t < phidget_count; t++) ! { ! if ( ! (tp == LP_PHIDGET) || ! (tp == LP_ALL) || ! (tp == LP_SERVO_CONTROLLER && error(phidgetTypeDeviceClass(error(phidgetType(phidgets[t])))) == LP_SERVO_CONTROLLER) /*|| ! (tp == LP_INTERFACE_KIT && error(phidgetTypeDeviceClass(error(phidgetType(phidgets[t])))) == LP_INTERFACE_KIT)*/ ) ! { ! CUID temp_uid(error(phidgetSerial(phidgets[t]))); ! devices.insert(temp_uid); ! } } } |
From: Jack S. <js...@us...> - 2002-12-13 22:54:00
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory sc8-pr-cvs1:/tmp/cvs-serv23320/libphidget Modified Files: phidget.h Log Message: Removed the INTERFACE_KIT class. Not used anymore Index: phidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** phidget.h 13 Dec 2002 22:10:26 -0000 1.11 --- phidget.h 13 Dec 2002 22:53:56 -0000 1.12 *************** *** 64,68 **** LP_PHIDGET = 100, /**< Generic phidget, not used in this library */ LP_SERVO_CONTROLLER = 200, /**< Identifies all servo controller phidgets */ ! LP_INTERFACE_KIT = 300, /**< Identifies all interface kit phidgets, support being added now */ LP_INTERFACE_KIT_880 = 301, /**< 880 interface kit */ LP_INTERFACE_KIT_488 = 302, /**< 488 interface kit */ --- 64,68 ---- LP_PHIDGET = 100, /**< Generic phidget, not used in this library */ LP_SERVO_CONTROLLER = 200, /**< Identifies all servo controller phidgets */ ! //LP_INTERFACE_KIT = 300, /**< Identifies all interface kit phidgets, support being added now */ LP_INTERFACE_KIT_880 = 301, /**< 880 interface kit */ LP_INTERFACE_KIT_488 = 302, /**< 488 interface kit */ |
From: Jack S. <js...@us...> - 2002-12-13 22:10:30
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory sc8-pr-cvs1:/tmp/cvs-serv9445/libphidget Modified Files: phidget.c phidget.h Log Message: fixed some spelling mistakes Index: phidget.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** phidget.c 13 Dec 2002 22:05:16 -0000 1.15 --- phidget.c 13 Dec 2002 22:10:26 -0000 1.16 *************** *** 46,51 **** * - UniServo .1 Degree Supported libusb * - 8-AdvancedServo Waiting for firmware patch libusb ! * - Interface Kit 884 Digital Input only HID ! * - Interface Kit 088 Digital Input only HID * - Interface Kit 32-32-0 Not supported yet * - Interface Kit 0-256-0 Not supported yet --- 46,51 ---- * - UniServo .1 Degree Supported libusb * - 8-AdvancedServo Waiting for firmware patch libusb ! * - Interface Kit 488 Digital Input only HID ! * - Interface Kit 880 Digital Input only HID * - Interface Kit 32-32-0 Not supported yet * - Interface Kit 0-256-0 Not supported yet *************** *** 901,907 **** _registerDeviceType("QuadServo .1 Degree", 0x06C2, 0x0038, LP_SERVO_CONTROLLER); _registerDeviceType("UniServo .1 Degree", 0x06C2, 0x0039, LP_SERVO_CONTROLLER); ! _registerDeviceType("Interface Kit 884", 0x0925, 0x8201, LP_INTERFACE_KIT_884); ! _registerDeviceType("Interface Kit 884", 0x06C2, 0x0040, LP_INTERFACE_KIT_884); ! _registerDeviceType("Interface Kit 088", 0x06C2, 0x0041, LP_INTERFACE_KIT_088); //_registerDeviceType("RFID VID/PID", 0x06C2, 0x0030, LP_OTHER); //_registerDeviceType("8-AdvancedServo", 0x06C2, 0x003B, LP_SERVO_CONTROLLER); --- 901,907 ---- _registerDeviceType("QuadServo .1 Degree", 0x06C2, 0x0038, LP_SERVO_CONTROLLER); _registerDeviceType("UniServo .1 Degree", 0x06C2, 0x0039, LP_SERVO_CONTROLLER); ! _registerDeviceType("Interface Kit 4/8/8", 0x0925, 0x8201, LP_INTERFACE_KIT_488); ! _registerDeviceType("Interface Kit 4/8/8", 0x06C2, 0x0040, LP_INTERFACE_KIT_488); ! _registerDeviceType("Interface Kit 8/8/0", 0x06C2, 0x0041, LP_INTERFACE_KIT_880); //_registerDeviceType("RFID VID/PID", 0x06C2, 0x0030, LP_OTHER); //_registerDeviceType("8-AdvancedServo", 0x06C2, 0x003B, LP_SERVO_CONTROLLER); *************** *** 1376,1385 **** * Helper function to read from an interface kit. */ ! enum ELPError phidgetInterfaceKit884Read(struct phidget *phidgetDevice, float analog[4], int digital[8]) { char buffer[7]; // Not correct type of interface kit ! if (phidgetDevice->type->deviceClass != LP_INTERFACE_KIT_884) return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE)); --- 1376,1385 ---- * Helper function to read from an interface kit. */ ! enum ELPError phidgetInterfaceKit488Read(struct phidget *phidgetDevice, float analog[4], int digital[8]) { char buffer[7]; // Not correct type of interface kit ! if (phidgetDevice->type->deviceClass != LP_INTERFACE_KIT_488) return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE)); *************** *** 1408,1412 **** * Helper function to read from an interface kit. */ ! enum ELPError phidgetInterfaceKit088Read(struct phidget *phidgetDevice, float analog[8], int digital[8]) { int t=0; --- 1408,1412 ---- * Helper function to read from an interface kit. */ ! enum ELPError phidgetInterfaceKit880Read(struct phidget *phidgetDevice, float analog[8], int digital[8]) { int t=0; *************** *** 1414,1418 **** // Not correct type of interface kit ! if (phidgetDevice->type->deviceClass != LP_INTERFACE_KIT_088) return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE)); --- 1414,1418 ---- // Not correct type of interface kit ! if (phidgetDevice->type->deviceClass != LP_INTERFACE_KIT_880) return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE)); Index: phidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** phidget.h 13 Dec 2002 22:05:16 -0000 1.10 --- phidget.h 13 Dec 2002 22:10:26 -0000 1.11 *************** *** 65,70 **** LP_SERVO_CONTROLLER = 200, /**< Identifies all servo controller phidgets */ LP_INTERFACE_KIT = 300, /**< Identifies all interface kit phidgets, support being added now */ ! LP_INTERFACE_KIT_088 = 301, /**< 088 interface kit */ ! LP_INTERFACE_KIT_884 = 302, /**< 884 interface kit */ LP_ENCODER = 400, /**< Currently unsupported */ LP_POWER = 500, /**< Currently unsupported */ --- 65,70 ---- LP_SERVO_CONTROLLER = 200, /**< Identifies all servo controller phidgets */ LP_INTERFACE_KIT = 300, /**< Identifies all interface kit phidgets, support being added now */ ! LP_INTERFACE_KIT_880 = 301, /**< 880 interface kit */ ! LP_INTERFACE_KIT_488 = 302, /**< 488 interface kit */ LP_ENCODER = 400, /**< Currently unsupported */ LP_POWER = 500, /**< Currently unsupported */ *************** *** 212,216 **** enum ELPError phidget8Servo(struct phidget *phidgetDevice, int id, float percent1, float maxvelocity, float acceleration); ! enum ELPError phidgetInterfaceKit448(struct phidget *phidgetDevice, float analog[4], int digital[8]); enum ELPError phidgetInterfaceKit880(struct phidget *phidgetDevice, float analog[8], int digital[8]); --- 212,216 ---- enum ELPError phidget8Servo(struct phidget *phidgetDevice, int id, float percent1, float maxvelocity, float acceleration); ! enum ELPError phidgetInterfaceKit488(struct phidget *phidgetDevice, float analog[4], int digital[8]); enum ELPError phidgetInterfaceKit880(struct phidget *phidgetDevice, float analog[8], int digital[8]); |
From: Jack S. <js...@us...> - 2002-12-13 22:10:30
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv9445/examples Modified Files: phidget_c.c Log Message: fixed some spelling mistakes Index: phidget_c.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_c.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** phidget_c.c 13 Dec 2002 22:05:15 -0000 1.10 --- phidget_c.c 13 Dec 2002 22:10:26 -0000 1.11 *************** *** 93,97 **** } else ! if (phidgetTypeDeviceClass (phidgetType (dev)) == LP_INTERFACE_KIT_884) { int t,k; --- 93,97 ---- } else ! if (phidgetTypeDeviceClass (phidgetType (dev)) == LP_INTERFACE_KIT_488) { int t,k; *************** *** 101,105 **** float analog[8]; int digital[8]; ! if (phidgetInterfaceKit884Read(dev,analog,digital)<0) { printf("error - %s\n",phidgetErrorString(phidgetLastError())); --- 101,105 ---- float analog[8]; int digital[8]; ! if (phidgetInterfaceKit488Read(dev,analog,digital)<0) { printf("error - %s\n",phidgetErrorString(phidgetLastError())); *************** *** 125,129 **** } else ! if (phidgetTypeDeviceClass (phidgetType (dev)) == LP_INTERFACE_KIT_088) { int t,k; --- 125,129 ---- } else ! if (phidgetTypeDeviceClass (phidgetType (dev)) == LP_INTERFACE_KIT_880) { int t,k; *************** *** 133,137 **** float analog[8]; int digital[8]; ! if (phidgetInterfaceKit088Read(dev,analog,digital)<0) { printf("error - %s\n",phidgetErrorString(phidgetLastError())); --- 133,137 ---- float analog[8]; int digital[8]; ! if (phidgetInterfaceKit880Read(dev,analog,digital)<0) { printf("error - %s\n",phidgetErrorString(phidgetLastError())); |
From: Jack S. <js...@us...> - 2002-12-13 22:05:20
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory sc8-pr-cvs1:/tmp/cvs-serv7153/libphidget Modified Files: phidget.c phidget.h Log Message: Fixed some bugs and added a test for 088 phidget Index: phidget.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** phidget.c 13 Dec 2002 21:16:23 -0000 1.14 --- phidget.c 13 Dec 2002 22:05:16 -0000 1.15 *************** *** 901,907 **** _registerDeviceType("QuadServo .1 Degree", 0x06C2, 0x0038, LP_SERVO_CONTROLLER); _registerDeviceType("UniServo .1 Degree", 0x06C2, 0x0039, LP_SERVO_CONTROLLER); ! _registerDeviceType("Interface Kit 884", 0x0925, 0x8201, LP_INTERFACE_KIT); ! _registerDeviceType("Interface Kit 884", 0x06C2, 0x0040, LP_INTERFACE_KIT); ! _registerDeviceType("Interface Kit 088", 0x06C2, 0x0041, LP_INTERFACE_KIT); //_registerDeviceType("RFID VID/PID", 0x06C2, 0x0030, LP_OTHER); //_registerDeviceType("8-AdvancedServo", 0x06C2, 0x003B, LP_SERVO_CONTROLLER); --- 901,907 ---- _registerDeviceType("QuadServo .1 Degree", 0x06C2, 0x0038, LP_SERVO_CONTROLLER); _registerDeviceType("UniServo .1 Degree", 0x06C2, 0x0039, LP_SERVO_CONTROLLER); ! _registerDeviceType("Interface Kit 884", 0x0925, 0x8201, LP_INTERFACE_KIT_884); ! _registerDeviceType("Interface Kit 884", 0x06C2, 0x0040, LP_INTERFACE_KIT_884); ! _registerDeviceType("Interface Kit 088", 0x06C2, 0x0041, LP_INTERFACE_KIT_088); //_registerDeviceType("RFID VID/PID", 0x06C2, 0x0030, LP_OTHER); //_registerDeviceType("8-AdvancedServo", 0x06C2, 0x003B, LP_SERVO_CONTROLLER); *************** *** 1343,1347 **** // Free any defaults that have already been set if (phidgetDevice->defaultData != NULL) ! free(phidgetDevice); phidgetDevice->defaultDataSize = sizeof(buffer); --- 1343,1347 ---- // Free any defaults that have already been set if (phidgetDevice->defaultData != NULL) ! free(phidgetDevice); phidgetDevice->defaultDataSize = sizeof(buffer); *************** *** 1376,1383 **** * Helper function to read from an interface kit. */ ! enum ELPError phidgetInterfaceKit488Read(struct phidget *phidgetDevice, float analog[4], int digital[8]) { char buffer[7]; enum ELPError err=phidgetRead(phidgetDevice,buffer,sizeof(buffer)); if (err!=LPE_NONE) --- 1376,1387 ---- * Helper function to read from an interface kit. */ ! enum ELPError phidgetInterfaceKit884Read(struct phidget *phidgetDevice, float analog[4], int digital[8]) { char buffer[7]; + // Not correct type of interface kit + if (phidgetDevice->type->deviceClass != LP_INTERFACE_KIT_884) + return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE)); + enum ELPError err=phidgetRead(phidgetDevice,buffer,sizeof(buffer)); if (err!=LPE_NONE) *************** *** 1404,1411 **** * Helper function to read from an interface kit. */ ! enum ELPError phidgetInterfaceKit880Read(struct phidget *phidgetDevice, float analog[8], int digital[8]) { int t=0; char buffer[7]; for (t=0;t<2;t++) --- 1408,1419 ---- * Helper function to read from an interface kit. */ ! enum ELPError phidgetInterfaceKit088Read(struct phidget *phidgetDevice, float analog[8], int digital[8]) { int t=0; char buffer[7]; + + // Not correct type of interface kit + if (phidgetDevice->type->deviceClass != LP_INTERFACE_KIT_088) + return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE)); for (t=0;t<2;t++) Index: phidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** phidget.h 13 Dec 2002 21:16:23 -0000 1.9 --- phidget.h 13 Dec 2002 22:05:16 -0000 1.10 *************** *** 65,68 **** --- 65,70 ---- LP_SERVO_CONTROLLER = 200, /**< Identifies all servo controller phidgets */ LP_INTERFACE_KIT = 300, /**< Identifies all interface kit phidgets, support being added now */ + LP_INTERFACE_KIT_088 = 301, /**< 088 interface kit */ + LP_INTERFACE_KIT_884 = 302, /**< 884 interface kit */ LP_ENCODER = 400, /**< Currently unsupported */ LP_POWER = 500, /**< Currently unsupported */ |
From: Jack S. <js...@us...> - 2002-12-13 22:05:19
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv7153/examples Modified Files: phidget_c.c Log Message: Fixed some bugs and added a test for 088 phidget Index: phidget_c.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_c.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** phidget_c.c 13 Dec 2002 21:16:22 -0000 1.9 --- phidget_c.c 13 Dec 2002 22:05:15 -0000 1.10 *************** *** 93,96 **** --- 93,97 ---- } else + if (phidgetTypeDeviceClass (phidgetType (dev)) == LP_INTERFACE_KIT_884) { int t,k; *************** *** 100,104 **** float analog[8]; int digital[8]; ! if (phidgetInterfaceKit488Read(dev,analog,digital)<0) { printf("error - %s\n",phidgetErrorString(phidgetLastError())); --- 101,105 ---- float analog[8]; int digital[8]; ! if (phidgetInterfaceKit884Read(dev,analog,digital)<0) { printf("error - %s\n",phidgetErrorString(phidgetLastError())); *************** *** 123,127 **** } } ! phidgetEvents (); // Close the phidget --- 124,163 ---- } } ! else ! if (phidgetTypeDeviceClass (phidgetType (dev)) == LP_INTERFACE_KIT_088) ! { ! int t,k; ! ! while(1) ! { ! float analog[8]; ! int digital[8]; ! if (phidgetInterfaceKit088Read(dev,analog,digital)<0) ! { ! printf("error - %s\n",phidgetErrorString(phidgetLastError())); ! return(-1); ! } ! ! printf("%c%c%c%c%c%c%c%c %8f %8f %8f %8f %8f %8f %8f %8f\n", ! digital[0]==1 ? '*' : '-', ! digital[1]==1 ? '*' : '-', ! digital[2]==1 ? '*' : '-', ! digital[3]==1 ? '*' : '-', ! digital[4]==1 ? '*' : '-', ! digital[5]==1 ? '*' : '-', ! digital[6]==1 ? '*' : '-', ! digital[7]==1 ? '*' : '-', ! analog[0], ! analog[1], ! analog[2], ! analog[3], ! analog[4], ! analog[5], ! analog[6], ! analog[7]); ! ! ! } ! } // Close the phidget |
From: Jack S. <js...@us...> - 2002-12-13 21:16:27
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv21336/examples Modified Files: phidget_c.c Log Message: hopefully added the reading of interface kit 880 and fixed a bug in the phidgetRead function Index: phidget_c.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_c.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** phidget_c.c 13 Dec 2002 20:45:13 -0000 1.8 --- phidget_c.c 13 Dec 2002 21:16:22 -0000 1.9 *************** *** 98,104 **** while(1) { ! float analog[4]; int digital[8]; ! phidgetInterfaceKit488Read(dev,analog,digital); printf("%c%c%c%c%c%c%c%c %8f %8f %8f %8f\n", --- 98,108 ---- while(1) { ! float analog[8]; int digital[8]; ! if (phidgetInterfaceKit488Read(dev,analog,digital)<0) ! { ! printf("error - %s\n",phidgetErrorString(phidgetLastError())); ! return(-1); ! } printf("%c%c%c%c%c%c%c%c %8f %8f %8f %8f\n", |
From: Jack S. <js...@us...> - 2002-12-13 21:16:26
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory sc8-pr-cvs1:/tmp/cvs-serv21336/libphidget Modified Files: phidget.c phidget.h Log Message: hopefully added the reading of interface kit 880 and fixed a bug in the phidgetRead function Index: phidget.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** phidget.c 13 Dec 2002 20:45:14 -0000 1.13 --- phidget.c 13 Dec 2002 21:16:23 -0000 1.14 *************** *** 1198,1202 **** return (_error(LPE_PHIDGET_NOT_OPENED)); ! if (usb_bulk_read(phidgetDevice->handle, 0x01, buffer, size, 5000) != 0) return (_error(LPE_BULK_READ_ERROR)); --- 1198,1204 ---- return (_error(LPE_PHIDGET_NOT_OPENED)); ! //if (usb_bulk_read(phidgetDevice->handle, 0x01, buffer, size, 5000) != 0) ! //return (_error(LPE_BULK_READ_ERROR)); ! if (usb_bulk_read(phidgetDevice->handle, 0x01, buffer, size, 5000) != size) return (_error(LPE_BULK_READ_ERROR)); *************** *** 1374,1382 **** * Helper function to read from an interface kit. */ ! void phidgetInterfaceKit488Read(struct phidget *phidgetDevice, float analog[4], int digital[8]) { char buffer[7]; ! phidgetRead(phidgetDevice,buffer,sizeof(buffer)); digital[0]=(buffer[0] & 1)==1; --- 1376,1386 ---- * Helper function to read from an interface kit. */ ! enum ELPError phidgetInterfaceKit488Read(struct phidget *phidgetDevice, float analog[4], int digital[8]) { char buffer[7]; ! enum ELPError err=phidgetRead(phidgetDevice,buffer,sizeof(buffer)); ! if (err!=LPE_NONE) ! return(_error(err)); digital[0]=(buffer[0] & 1)==1; *************** *** 1393,1396 **** --- 1397,1446 ---- analog[2]=((unsigned char)buffer[6]+((unsigned char)buffer[5] & 0x0f) * 256); analog[3]=((unsigned char)buffer[4]+((unsigned char)buffer[5] & 0xf0) * 16); + + return (_error(LPE_NONE)); + } + + /** + * Helper function to read from an interface kit. + */ + enum ELPError phidgetInterfaceKit880Read(struct phidget *phidgetDevice, float analog[8], int digital[8]) + { + int t=0; + char buffer[7]; + + for (t=0;t<2;t++) + { + enum ELPError err=phidgetRead(phidgetDevice,buffer,sizeof(buffer)); + if (err!=LPE_NONE) + return(_error(err)); + if ((buffer[0] & 1)!=1) + { + // Packet 0 + digital[0]=(buffer[0] & 16)==16; + digital[1]=(buffer[0] & 32)==32; + digital[2]=(buffer[0] & 64)==64; + digital[3]=(buffer[0] & 128)==128; + + analog[7]=((unsigned char)buffer[1]+((unsigned char)buffer[2] & 0x0f) * 256); + analog[6]=((unsigned char)buffer[3]+((unsigned char)buffer[2] & 0xf0) * 16); + analog[5]=((unsigned char)buffer[4]+((unsigned char)buffer[5] & 0x0f) * 256); + analog[4]=((unsigned char)buffer[6]+((unsigned char)buffer[5] & 0xf0) * 16); + } + else + { + // Packet 1 + digital[4]=(buffer[0] & 16)==16; + digital[5]=(buffer[0] & 32)==32; + digital[6]=(buffer[0] & 64)==64; + digital[7]=(buffer[0] & 128)==128; + + analog[3]=((unsigned char)buffer[1]+((unsigned char)buffer[2] & 0x0f) * 256); + analog[2]=((unsigned char)buffer[3]+((unsigned char)buffer[2] & 0xf0) * 16); + analog[1]=((unsigned char)buffer[4]+((unsigned char)buffer[5] & 0x0f) * 256); + analog[0]=((unsigned char)buffer[6]+((unsigned char)buffer[5] & 0xf0) * 16); + } + } + + return (_error(LPE_NONE)); } Index: phidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** phidget.h 13 Dec 2002 16:42:30 -0000 1.8 --- phidget.h 13 Dec 2002 21:16:23 -0000 1.9 *************** *** 210,213 **** --- 210,216 ---- enum ELPError phidget8Servo(struct phidget *phidgetDevice, int id, float percent1, float maxvelocity, float acceleration); + enum ELPError phidgetInterfaceKit448(struct phidget *phidgetDevice, float analog[4], int digital[8]); + enum ELPError phidgetInterfaceKit880(struct phidget *phidgetDevice, float analog[8], int digital[8]); + /** * This checks for any new or changed devices, if anything has changed since the |
From: Jack S. <js...@us...> - 2002-12-13 20:45:47
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv8973/examples Modified Files: phidget_c.c Log Message: Support reading of interface kit 488 using libusb Index: phidget_c.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_c.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** phidget_c.c 13 Dec 2002 16:42:17 -0000 1.7 --- phidget_c.c 13 Dec 2002 20:45:13 -0000 1.8 *************** *** 92,95 **** --- 92,122 ---- } } + else + { + int t,k; + + while(1) + { + float analog[4]; + int digital[8]; + phidgetInterfaceKit488Read(dev,analog,digital); + + printf("%c%c%c%c%c%c%c%c %8f %8f %8f %8f\n", + digital[0]==1 ? '*' : '-', + digital[1]==1 ? '*' : '-', + digital[2]==1 ? '*' : '-', + digital[3]==1 ? '*' : '-', + digital[4]==1 ? '*' : '-', + digital[5]==1 ? '*' : '-', + digital[6]==1 ? '*' : '-', + digital[7]==1 ? '*' : '-', + analog[0], + analog[1], + analog[2], + analog[3]); + + + } + } phidgetEvents (); |
From: Jack S. <js...@us...> - 2002-12-13 20:45:20
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory sc8-pr-cvs1:/tmp/cvs-serv8973/libphidget Modified Files: phidget.c Log Message: Support reading of interface kit 488 using libusb Index: phidget.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** phidget.c 13 Dec 2002 16:42:21 -0000 1.12 --- phidget.c 13 Dec 2002 20:45:14 -0000 1.13 *************** *** 22,27 **** // TODO - change this ! #define DBG(a) printf("*** DEBUG *** : %s\n",a) ! //#define DBG(a) int _libPhidgetInitialized = 0; /**< Private variable to determine if the libphidget is initialized */ --- 22,27 ---- // TODO - change this ! //#define DBG(a) printf("*** DEBUG *** : %s\n",a) ! #define DBG(a) int _libPhidgetInitialized = 0; /**< Private variable to determine if the libphidget is initialized */ *************** *** 1370,1373 **** --- 1370,1397 ---- } */ + + /** + * Helper function to read from an interface kit. + */ + void phidgetInterfaceKit488Read(struct phidget *phidgetDevice, float analog[4], int digital[8]) + { + char buffer[7]; + + phidgetRead(phidgetDevice,buffer,sizeof(buffer)); + + digital[0]=(buffer[0] & 1)==1; + digital[1]=(buffer[0] & 2)==2; + digital[2]=(buffer[0] & 4)==4; + digital[3]=(buffer[0] & 8)==8; + digital[4]=(buffer[0] & 16)==16; + digital[5]=(buffer[0] & 32)==32; + digital[6]=(buffer[0] & 64)==64; + digital[7]=(buffer[0] & 128)==128; + + analog[0]=((unsigned char)buffer[3]+((unsigned char)buffer[2] & 0x0f) * 256); + analog[1]=((unsigned char)buffer[1]+((unsigned char)buffer[2] & 0xf0) * 16); + analog[2]=((unsigned char)buffer[6]+((unsigned char)buffer[5] & 0x0f) * 256); + analog[3]=((unsigned char)buffer[4]+((unsigned char)buffer[5] & 0xf0) * 16); + } /** |
From: Jack S. <js...@us...> - 2002-12-13 16:43:19
|
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory sc8-pr-cvs1:/tmp/cvs-serv15013/phidget++ Modified Files: CPhidgetManager.cc CPhidgetManager.h Log Message: I think I figured out how to not use the HID at all. Removing what I added yesterday to start supporting HID. Index: CPhidgetManager.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CPhidgetManager.cc 16 Sep 2002 06:57:50 -0000 1.7 --- CPhidgetManager.cc 13 Dec 2002 16:42:34 -0000 1.8 *************** *** 75,79 **** { METHOD_GUARD; ! error(phidgetInit(1)); /* --- 75,80 ---- { METHOD_GUARD; ! ! error(phidgetInit(1)); /* Index: CPhidgetManager.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CPhidgetManager.h 12 Sep 2002 00:24:29 -0000 1.4 --- CPhidgetManager.h 13 Dec 2002 16:42:39 -0000 1.5 *************** *** 51,74 **** class CPhidgetManager:public TSingleton <CPhidgetManager > { ! private: ! friend class TSingleton <CPhidgetManager >; ! friend class CPhidget; ! friend class CUniqueDevice; ! ! //vector <CPhidget *> _phidgets; ! vector <CUniqueDevice *>_uniqueDevices; ! CPhidgetManager (); ! //void addPossibleNewDevice(struct phidget *dev); ! //void replacePhidget(CPhidget *a,CPhidget *b); ! struct phidget *getDeviceHandle(const CUID &uid); ! CPhidget *createPhidget(const CUID &uid); ! void registerDevice(CUniqueDevice *dev); ! void unregisterDevice(CUniqueDevice *dev); ! public: /** * Deletes all currently allocated phidgets, only called when the application finishes --- 51,74 ---- class CPhidgetManager:public TSingleton <CPhidgetManager > { ! private: ! friend class TSingleton <CPhidgetManager >; ! friend class CPhidget; ! friend class CUniqueDevice; ! //vector <CPhidget *> _phidgets; ! vector <CUniqueDevice *>_uniqueDevices; ! CPhidgetManager (); ! //void addPossibleNewDevice(struct phidget *dev); ! //void replacePhidget(CPhidget *a,CPhidget *b); ! ! struct phidget *getDeviceHandle(const CUID &uid); ! CPhidget *createPhidget(const CUID &uid); ! void registerDevice(CUniqueDevice *dev); ! void unregisterDevice(CUniqueDevice *dev); ! public: /** * Deletes all currently allocated phidgets, only called when the application finishes *************** *** 78,99 **** * be called. */ ! virtual ~ CPhidgetManager (); ! // Discovery functions /** ! * Returns a list of know devices currently available ! */ ! vector <CUID >query(const EDeviceClass tp = LP_PHIDGET); /** ! * Get a vector of all phidgets ! */ ! //const vector<CPhidget *> &phidgets() const; /** * Returns a phidget by it's unique ID or NULL if it is not attached ! */ ! CPhidget *phidget (const CUID &uid //<! Unique ID of phidget ); --- 78,99 ---- * be called. */ ! virtual ~ CPhidgetManager (); ! // Discovery functions /** ! * Returns a list of know devices currently available ! */ ! vector <CUID >query(const EDeviceClass tp = LP_PHIDGET); /** ! * Get a vector of all phidgets ! */ ! //const vector<CPhidget *> &phidgets() const; /** * Returns a phidget by it's unique ID or NULL if it is not attached ! */ ! CPhidget *phidget (const CUID &uid //<! Unique ID of phidget ); |
From: Jack S. <js...@us...> - 2002-12-13 16:43:12
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory sc8-pr-cvs1:/tmp/cvs-serv15013/libphidget Modified Files: phidget.c phidget.h Log Message: I think I figured out how to not use the HID at all. Removing what I added yesterday to start supporting HID. Index: phidget.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** phidget.c 13 Dec 2002 05:15:13 -0000 1.11 --- phidget.c 13 Dec 2002 16:42:21 -0000 1.12 *************** *** 13,16 **** --- 13,17 ---- #include "phidget.h" #include <signal.h> + #include <dirent.h> #include "SoftPhidget.h" *************** *** 60,64 **** int productID; /**< USB Product ID. See the USB specification for more information. */ enum EDeviceClass deviceClass; /**< Device class */ - enum EStyle style; /**< Style of device, libusb or HID, hope to get away from HID totally */ }; --- 61,64 ---- *************** *** 73,94 **** const struct phidget_type *type; ! /** Union to handle the two different ways to access phidgets */ ! union ! { ! struct ! { ! /** libusb handle to the phidget, try not to use this if at all possible. ! * If this is NULL, the device isn't opened. */ ! struct usb_dev_handle *handle; ! /** libusb device to the phidget, try not to use this if at all possible */ ! struct usb_device *device; ! } libusb; ! struct ! { ! int handle; ! char *path; ! } HID; ! } handle; /** The serial number of the phidget for unique identificatoin */ --- 73,82 ---- const struct phidget_type *type; ! /** libusb handle to the phidget, try not to use this if at all possible. ! * If this is NULL, the device isn't opened. */ ! struct usb_dev_handle *handle; ! /** libusb device to the phidget, try not to use this if at all possible */ ! struct usb_device *device; /** The serial number of the phidget for unique identificatoin */ *************** *** 403,407 **** * Private function to register a new device type */ ! void _registerDeviceType(const char *name, int vendorID, int productID, int deviceClass, enum EStyle style) { int len; --- 391,395 ---- * Private function to register a new device type */ ! void _registerDeviceType(const char *name, int vendorID, int productID, int deviceClass) { int len; *************** *** 414,418 **** _typeList[_typeCount].productID = productID; _typeList[_typeCount].deviceClass = deviceClass; - _typeList[_typeCount].style = style; len = strlen(name); --- 402,405 ---- *************** *** 459,463 **** { // Close any devices that are open ! if (_usbDeviceList[t]->handle.libusb.handle != NULL) phidgetClose(_usbDeviceList[t]); } --- 446,450 ---- { // Close any devices that are open ! if (_usbDeviceList[t]->handle != NULL) phidgetClose(_usbDeviceList[t]); } *************** *** 568,573 **** temp->type = ptd; ! temp->handle.libusb.handle = NULL; ! temp->handle.libusb.device = device; temp->serial = _serial; temp->wasAttached = 0; --- 555,560 ---- temp->type = ptd; ! temp->handle = NULL; ! temp->device = device; temp->serial = _serial; temp->wasAttached = 0; *************** *** 794,798 **** for (t=0;t<_phidgetDeviceCount;t++) { ! if ( _usbDeviceList[t]->handle.libusb.device == dev) { // We found this device --- 781,785 ---- for (t=0;t<_phidgetDeviceCount;t++) { ! if ( _usbDeviceList[t]->device == dev) { // We found this device *************** *** 824,828 **** if ( _usbDeviceList[t]->serial==serial) { ! _usbDeviceList[t]->handle.libusb.device=dev; // It has changed // We found this device --- 811,815 ---- if ( _usbDeviceList[t]->serial==serial) { ! _usbDeviceList[t]->device=dev; // It has changed // We found this device *************** *** 862,867 **** if (_usbDeviceList[t]->openedState == WAS_OPENED) { ! usb_release_interface(_usbDeviceList[t]->handle.libusb.handle, 0); ! usb_close(_usbDeviceList[t]->handle.libusb.handle); _usbDeviceList[t]->openedState = WAS_OPENED; } --- 849,854 ---- if (_usbDeviceList[t]->openedState == WAS_OPENED) { ! usb_release_interface(_usbDeviceList[t]->handle, 0); ! usb_close(_usbDeviceList[t]->handle); _usbDeviceList[t]->openedState = WAS_OPENED; } *************** *** 878,882 **** { _usbDeviceList[t]->openedState = WAS_CLOSED; ! _usbDeviceList[t]->handle.libusb.handle = NULL; phidgetOpen(_usbDeviceList[t]); } --- 865,869 ---- { _usbDeviceList[t]->openedState = WAS_CLOSED; ! _usbDeviceList[t]->handle = NULL; phidgetOpen(_usbDeviceList[t]); } *************** *** 897,900 **** --- 884,890 ---- + /** + * Used to initialize the phidget library + */ enum ELPError phidgetInit(int catch_signals) { *************** *** 909,917 **** _clearDeviceTypes(); ! _registerDeviceType("QuadServo .1 Degree", 0x06C2, 0x0038, LP_SERVO_CONTROLLER, LIBUSB); ! _registerDeviceType("UniServo .1 Degree", 0x06C2, 0x0039, LP_SERVO_CONTROLLER, LIBUSB); ! _registerDeviceType("Interface Kit 884", 0x0925, 0x8201, LP_INTERFACE_KIT, HID); ! _registerDeviceType("Interface Kit 884", 0x06C2, 0x0040, LP_INTERFACE_KIT, HID); ! _registerDeviceType("Interface Kit 088", 0x06C2, 0x0041, LP_INTERFACE_KIT, HID); //_registerDeviceType("RFID VID/PID", 0x06C2, 0x0030, LP_OTHER); //_registerDeviceType("8-AdvancedServo", 0x06C2, 0x003B, LP_SERVO_CONTROLLER); --- 899,907 ---- _clearDeviceTypes(); ! _registerDeviceType("QuadServo .1 Degree", 0x06C2, 0x0038, LP_SERVO_CONTROLLER); ! _registerDeviceType("UniServo .1 Degree", 0x06C2, 0x0039, LP_SERVO_CONTROLLER); ! _registerDeviceType("Interface Kit 884", 0x0925, 0x8201, LP_INTERFACE_KIT); ! _registerDeviceType("Interface Kit 884", 0x06C2, 0x0040, LP_INTERFACE_KIT); ! _registerDeviceType("Interface Kit 088", 0x06C2, 0x0041, LP_INTERFACE_KIT); //_registerDeviceType("RFID VID/PID", 0x06C2, 0x0030, LP_OTHER); //_registerDeviceType("8-AdvancedServo", 0x06C2, 0x003B, LP_SERVO_CONTROLLER); *************** *** 1042,1046 **** ! if (phidgetDevice->handle.libusb.handle != NULL) { phidgetDevice->openedState = WAS_ERROR; --- 1032,1036 ---- ! if (phidgetDevice->handle != NULL) { phidgetDevice->openedState = WAS_ERROR; *************** *** 1056,1083 **** } ! phidgetDevice->handle.libusb.handle = usb_open(phidgetDevice->handle.libusb.device); ! if (phidgetDevice->handle.libusb.handle) { ! while (usb_set_configuration(phidgetDevice->handle.libusb.handle, 1)<0); ! /* ! ret = usb_set_configuration(phidgetDevice->handle.libusb.handle, 1); ! if (ret < 0) { printf("Can't set configuration:%d\n",ret); ! usb_close(phidgetDevice->handle.libusb.handle); ! phidgetDevice->handle.libusb.handle = NULL; ! phidgetDevice->openedState = WAS_ERROR; ! _error(LPE_SET_CONFIGURATION_FAILED); ! return NULL; } - */ ! ret = usb_claim_interface(phidgetDevice->handle.libusb.handle, 0); if (ret < 0) { ! usb_close(phidgetDevice->handle.libusb.handle); ! phidgetDevice->handle.libusb.handle = NULL; phidgetDevice->openedState = WAS_ERROR; _error(LPE_CLAIM_INTERFACE_FAILED); --- 1046,1072 ---- } ! phidgetDevice->handle = usb_open(phidgetDevice->device); ! if (phidgetDevice->handle) { ! //while (usb_set_configuration(phidgetDevice->handle, 1)<0); ! ret = usb_set_configuration(phidgetDevice->handle, 1); ! if (ret < 0) ! { printf("Can't set configuration:%d\n",ret); ! usb_close(phidgetDevice->handle); ! phidgetDevice->handle = NULL; ! phidgetDevice->openedState = WAS_ERROR; ! _error(LPE_SET_CONFIGURATION_FAILED); ! return NULL; } ! ret = usb_claim_interface(phidgetDevice->handle, 0); if (ret < 0) { ! usb_close(phidgetDevice->handle); ! phidgetDevice->handle = NULL; phidgetDevice->openedState = WAS_ERROR; _error(LPE_CLAIM_INTERFACE_FAILED); *************** *** 1085,1094 **** } ! ret = usb_set_altinterface(phidgetDevice->handle.libusb.handle, 0); if (ret < 0) { ! usb_release_interface(phidgetDevice->handle.libusb.handle, 0); ! usb_close(phidgetDevice->handle.libusb.handle); ! phidgetDevice->handle.libusb.handle = NULL; phidgetDevice->openedState = WAS_ERROR; _error(LPE_SET_ALT_INTERFACE_FAILED); --- 1074,1083 ---- } ! ret = usb_set_altinterface(phidgetDevice->handle, 0); if (ret < 0) { ! usb_release_interface(phidgetDevice->handle, 0); ! usb_close(phidgetDevice->handle); ! phidgetDevice->handle = NULL; phidgetDevice->openedState = WAS_ERROR; _error(LPE_SET_ALT_INTERFACE_FAILED); *************** *** 1136,1140 **** ! if (phidgetDevice->handle.libusb.handle) { if (phidgetDevice->type->deviceClass == LP_SERVO_CONTROLLER) --- 1125,1129 ---- ! if (phidgetDevice->handle) { if (phidgetDevice->type->deviceClass == LP_SERVO_CONTROLLER) *************** *** 1154,1160 **** } ! usb_release_interface(phidgetDevice->handle.libusb.handle, 0); ! usb_close(phidgetDevice->handle.libusb.handle); ! phidgetDevice->handle.libusb.handle = NULL; phidgetDevice->openedState = WAS_CLOSED; } else --- 1143,1149 ---- } ! usb_release_interface(phidgetDevice->handle, 0); ! usb_close(phidgetDevice->handle); ! phidgetDevice->handle = NULL; phidgetDevice->openedState = WAS_CLOSED; } else *************** *** 1180,1187 **** if (phidgetDevice->attached == 0) return (_error(LPE_PHIDGET_NOT_ATTACHED)); ! if (phidgetDevice->handle.libusb.handle == NULL) return (_error(LPE_PHIDGET_NOT_OPENED)); ! ret=usb_control_msg(phidgetDevice->handle.libusb.handle, 0x21, 0x09, 0x200, 0, buffer, size, 5000); if (ret!=size) return (_error(LPE_CONTROL_MSG_ERROR)); --- 1169,1176 ---- if (phidgetDevice->attached == 0) return (_error(LPE_PHIDGET_NOT_ATTACHED)); ! if (phidgetDevice->handle == NULL) return (_error(LPE_PHIDGET_NOT_OPENED)); ! ret=usb_control_msg(phidgetDevice->handle, 0x21, 0x09, 0x200, 0, buffer, size, 5000); if (ret!=size) return (_error(LPE_CONTROL_MSG_ERROR)); *************** *** 1206,1213 **** return (_error(LPE_PHIDGET_NOT_ATTACHED)); ! if (phidgetDevice->handle.libusb.handle == NULL) return (_error(LPE_PHIDGET_NOT_OPENED)); ! if (usb_bulk_read(phidgetDevice->handle.libusb.handle, 0x01, buffer, size, 5000) != 0) return (_error(LPE_BULK_READ_ERROR)); --- 1195,1202 ---- return (_error(LPE_PHIDGET_NOT_ATTACHED)); ! if (phidgetDevice->handle == NULL) return (_error(LPE_PHIDGET_NOT_OPENED)); ! if (usb_bulk_read(phidgetDevice->handle, 0x01, buffer, size, 5000) != 0) return (_error(LPE_BULK_READ_ERROR)); Index: phidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** phidget.h 13 Dec 2002 05:15:13 -0000 1.7 --- phidget.h 13 Dec 2002 16:42:30 -0000 1.8 *************** *** 106,119 **** }; - /** - * Style of device, libusb or HID, hope to get away from HID totally - */ - enum EStyle - { - LIBUSB=0, /**< This device uses libusb */ - HID=1 /**< This device uses HID driver */ - }; - - #ifdef __cplusplus extern "C" --- 106,109 ---- |
From: Jack S. <js...@us...> - 2002-12-13 16:42:56
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv15013/examples Modified Files: phidget_c.c Log Message: I think I figured out how to not use the HID at all. Removing what I added yesterday to start supporting HID. Index: phidget_c.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_c.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** phidget_c.c 13 Dec 2002 05:01:09 -0000 1.6 --- phidget_c.c 13 Dec 2002 16:42:17 -0000 1.7 *************** *** 27,31 **** // 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())); --- 27,31 ---- // 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())); *************** *** 75,82 **** { int i; // Move a single servo (will move servo 0 of a 1 or 4 servo controller) ! //if (phidgetSingleServo (dev, k)<0) ! if (phidget8Servo (dev, k,0,.1,.1)<0) { printf("error - %s\n",phidgetErrorString(phidgetLastError())); --- 75,83 ---- { int i; + printf ("%f\n",k); // Move a single servo (will move servo 0 of a 1 or 4 servo controller) ! //if (phidget8Servo (dev, k,0,.1,.1)<0) ! if (phidgetSingleServo (dev, k)<0) { printf("error - %s\n",phidgetErrorString(phidgetLastError())); *************** *** 91,94 **** --- 92,96 ---- } } + phidgetEvents (); // Close the phidget |
From: Jack S. <js...@us...> - 2002-12-13 05:15:18
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory sc8-pr-cvs1:/tmp/cvs-serv20240 Modified Files: phidget.c phidget.h Log Message: Added the concept of devices styles, in this case they can be either libusb or HID. Now have to add support to HID. Index: phidget.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** phidget.c 13 Dec 2002 05:01:09 -0000 1.10 --- phidget.c 13 Dec 2002 05:15:13 -0000 1.11 *************** *** 60,63 **** --- 60,64 ---- int productID; /**< USB Product ID. See the USB specification for more information. */ enum EDeviceClass deviceClass; /**< Device class */ + enum EStyle style; /**< Style of device, libusb or HID, hope to get away from HID totally */ }; *************** *** 402,406 **** * Private function to register a new device type */ ! void _registerDeviceType(const char *name, int vendorID, int productID, int deviceClass) { int len; --- 403,407 ---- * Private function to register a new device type */ ! void _registerDeviceType(const char *name, int vendorID, int productID, int deviceClass, enum EStyle style) { int len; *************** *** 413,416 **** --- 414,418 ---- _typeList[_typeCount].productID = productID; _typeList[_typeCount].deviceClass = deviceClass; + _typeList[_typeCount].style = style; len = strlen(name); *************** *** 907,925 **** _clearDeviceTypes(); ! _registerDeviceType("RFID VID/PID", 0x06C2, 0x0030, LP_OTHER); ! _registerDeviceType("QuadServo .1 Degree", 0x06C2, 0x0038, LP_SERVO_CONTROLLER); ! _registerDeviceType("UniServo .1 Degree", 0x06C2, 0x0039, LP_SERVO_CONTROLLER); ! _registerDeviceType("8-AdvancedServo", 0x06C2, 0x003B, LP_SERVO_CONTROLLER); ! _registerDeviceType("Interface Kit 884", 0x0925, 0x8201, LP_INTERFACE_KIT); ! _registerDeviceType("Interface Kit 884", 0x06C2, 0x0040, LP_INTERFACE_KIT); ! _registerDeviceType("Interface Kit 088", 0x06C2, 0x0041, LP_INTERFACE_KIT); ! _registerDeviceType("Interface Kit 32-32-0", 0x06C2, 0x0042, LP_INTERFACE_KIT); ! _registerDeviceType("Interface Kit 0-256-0", 0x06C2, 0x0043, LP_INTERFACE_KIT); ! _registerDeviceType("Receiver Ver 1.0", 0x06C2, 0x0048, LP_OTHER); ! _registerDeviceType("PhidgetLED Ver 1.0", 0x06C2, 0x0049, LP_OTHER); ! _registerDeviceType("PhidgetEncoder Ver 1.0", 0x06C2, 0x004B, LP_OTHER); ! _registerDeviceType("PhidgetPower Ver 1.01", 0x06C2, 0x004E, LP_OTHER); ! _registerDeviceType("PhidgetTextLCD ECMA1010 Ver 1.0", 0x06C2, 0x0050, LP_OTHER); ! _registerDeviceType("PhidgetGraphicLCD Ver 1.0", 0x06C2, 0x0058, LP_OTHER); //_registerDeviceType("SoftPhidget", 0x06C2, 0x0060, LP_OTHER); --- 909,927 ---- _clearDeviceTypes(); ! _registerDeviceType("QuadServo .1 Degree", 0x06C2, 0x0038, LP_SERVO_CONTROLLER, LIBUSB); ! _registerDeviceType("UniServo .1 Degree", 0x06C2, 0x0039, LP_SERVO_CONTROLLER, LIBUSB); ! _registerDeviceType("Interface Kit 884", 0x0925, 0x8201, LP_INTERFACE_KIT, HID); ! _registerDeviceType("Interface Kit 884", 0x06C2, 0x0040, LP_INTERFACE_KIT, HID); ! _registerDeviceType("Interface Kit 088", 0x06C2, 0x0041, LP_INTERFACE_KIT, HID); ! //_registerDeviceType("RFID VID/PID", 0x06C2, 0x0030, LP_OTHER); ! //_registerDeviceType("8-AdvancedServo", 0x06C2, 0x003B, LP_SERVO_CONTROLLER); ! //_registerDeviceType("Interface Kit 32-32-0", 0x06C2, 0x0042, LP_INTERFACE_KIT); ! //_registerDeviceType("Interface Kit 0-256-0", 0x06C2, 0x0043, LP_INTERFACE_KIT); ! //_registerDeviceType("Receiver Ver 1.0", 0x06C2, 0x0048, LP_OTHER); ! //_registerDeviceType("PhidgetLED Ver 1.0", 0x06C2, 0x0049, LP_OTHER); ! //_registerDeviceType("PhidgetEncoder Ver 1.0", 0x06C2, 0x004B, LP_OTHER); ! //_registerDeviceType("PhidgetPower Ver 1.01", 0x06C2, 0x004E, LP_OTHER); ! //_registerDeviceType("PhidgetTextLCD ECMA1010 Ver 1.0", 0x06C2, 0x0050, LP_OTHER); ! //_registerDeviceType("PhidgetGraphicLCD Ver 1.0", 0x06C2, 0x0058, LP_OTHER); //_registerDeviceType("SoftPhidget", 0x06C2, 0x0060, LP_OTHER); Index: phidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** phidget.h 13 Dec 2002 05:01:09 -0000 1.6 --- phidget.h 13 Dec 2002 05:15:13 -0000 1.7 *************** *** 106,109 **** --- 106,119 ---- }; + /** + * Style of device, libusb or HID, hope to get away from HID totally + */ + enum EStyle + { + LIBUSB=0, /**< This device uses libusb */ + HID=1 /**< This device uses HID driver */ + }; + + #ifdef __cplusplus extern "C" |
From: Jack S. <js...@us...> - 2002-12-13 05:01:13
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory sc8-pr-cvs1:/tmp/cvs-serv16527/src/libphidget Modified Files: phidget.c phidget.h Log Message: Has some changes for supporting soft phidgets but that code is commented out. Also fixed some problems in the example code. Index: phidget.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** phidget.c 16 Sep 2002 18:22:18 -0000 1.9 --- phidget.c 13 Dec 2002 05:01:09 -0000 1.10 *************** *** 13,16 **** --- 13,17 ---- #include "phidget.h" #include <signal.h> + #include "SoftPhidget.h" /** *************** *** 20,33 **** // TODO - change this [...2144 lines suppressed...] ! case LPE_CLAIM_INTERFACE_FAILED: ! return ("During the initialization of a phidget the interface for the USB device could not be claimed"); ! case LPE_SET_ALT_INTERFACE_FAILED: ! return ("During the initialization of a phidget the alternate interface for the USB device could not be set"); ! case LPE_NO_SERIAL_RETURNED: ! return ("The serial number could not be requested from the phidget"); ! case LPE_PHIDGET_ALREADY_CLOSED: ! return ("Phidget is already closed"); ! case LPE_PHIDGET_ALREADY_OPENED: ! return ("Phidget is already opened"); ! case LPE_PHIDGET_NOT_OPENED: ! return ("Phidget is not opened"); ! case LPE_CONTROL_MSG_ERROR: ! return ("Error sending a control message to a phidget"); ! case LPE_BULK_READ_ERROR: ! return ("Error reading bulk data from a phidget"); ! default: ! return ("not an error number"); ! } }; Index: phidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** phidget.h 16 Sep 2002 06:40:57 -0000 1.5 --- phidget.h 13 Dec 2002 05:01:09 -0000 1.6 *************** *** 201,205 **** * device is closed (either on purpose, or when the signal handler catches it) */ ! enum ELPError pidgetQuadServoDefault(struct phidget *device, //<! The phidget whose default we want to set float percent1, //!< Percentage to move servo 1 float percent2, //!< Percentage to move servo 2 --- 201,205 ---- * device is closed (either on purpose, or when the signal handler catches it) */ ! enum ELPError phidgetQuadServoDefault(struct phidget *device, //<! The phidget whose default we want to set float percent1, //!< Percentage to move servo 1 float percent2, //!< Percentage to move servo 2 *************** *** 207,210 **** --- 207,212 ---- float percent4 //!< Percentage to move servo 4 ); + + enum ELPError phidget8Servo(struct phidget *phidgetDevice, int id, float percent1, float maxvelocity, float acceleration); /** |
From: Jack S. <js...@us...> - 2002-12-13 05:01:13
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv16527/src/examples Modified Files: phidget_c.c phidget_cpp.cc Log Message: Has some changes for supporting soft phidgets but that code is commented out. Also fixed some problems in the example code. Index: phidget_c.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_c.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** phidget_c.c 16 Sep 2002 06:45:42 -0000 1.5 --- phidget_c.c 13 Dec 2002 05:01:09 -0000 1.6 *************** *** 77,81 **** // Move a single servo (will move servo 0 of a 1 or 4 servo controller) ! if (phidgetSingleServo (dev, k)<0) { printf("error - %s\n",phidgetErrorString(phidgetLastError())); --- 77,82 ---- // Move a single servo (will move servo 0 of a 1 or 4 servo controller) ! //if (phidgetSingleServo (dev, k)<0) ! if (phidget8Servo (dev, k,0,.1,.1)<0) { printf("error - %s\n",phidgetErrorString(phidgetLastError())); Index: phidget_cpp.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_cpp.cc,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** phidget_cpp.cc 17 Sep 2002 01:40:31 -0000 1.6 --- phidget_cpp.cc 13 Dec 2002 05:01:09 -0000 1.7 *************** *** 231,235 **** else { ! printf("%8d Unsupported Phidget\n", uid.serial()); } } --- 231,235 ---- else { ! printf("%8d %32s Unsupported\n", uid.serial(),"unknown device"); } } |
From: Jack S. <js...@us...> - 2002-09-17 01:40:34
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory usw-pr-cvs1:/tmp/cvs-serv16330 Modified Files: phidget_cpp.cc servo_example.cc Log Message: Fixed problem where printing version numbers were not null terminated properly. Index: phidget_cpp.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_cpp.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** phidget_cpp.cc 16 Sep 2002 23:37:07 -0000 1.5 --- phidget_cpp.cc 17 Sep 2002 01:40:31 -0000 1.6 *************** *** 379,382 **** --- 379,383 ---- char adjusted_version[64]; memcpy(adjusted_version,revision+11,strlen(revision)-11-2); + adjusted_version[strlen(revision)-11-2]=0; // What we are Index: servo_example.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/servo_example.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** servo_example.cc 16 Sep 2002 06:45:42 -0000 1.5 --- servo_example.cc 17 Sep 2002 01:40:31 -0000 1.6 *************** *** 199,202 **** --- 199,203 ---- char adjusted_version[64]; memcpy(adjusted_version,revision+11,strlen(revision)-11-2); + adjusted_version[strlen(revision)-11-2]=0; // What we are |
From: Jack S. <js...@us...> - 2002-09-16 23:37:10
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory usw-pr-cvs1:/tmp/cvs-serv15763 Modified Files: phidget_cpp.cc Log Message: The example didn't properly handle unsupported phidgets (find method returns a NULL for an unsupported phidget). Index: phidget_cpp.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_cpp.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** phidget_cpp.cc 12 Sep 2002 01:31:18 -0000 1.4 --- phidget_cpp.cc 16 Sep 2002 23:37:07 -0000 1.5 *************** *** 197,243 **** */ ! void ! phidgets_ls() { ! CPhidgetManager *manager = CPhidgetManager::getInstance(); ! ! vector <CUID >phidgets = manager->query(LP_PHIDGET); ! printf("\n"); ! printf(" UID Name Misc\n"); ! printf("-------- -------------------------------- ----------------\n"); ! for (int t = 0; t < phidgets.size(); t++) { ! const CUID &uid = phidgets[t]; ! CPhidget *phidget = dynamic_cast < CPhidget *>(manager->find(uid, true)); ! if (phidget == NULL) ! throw runtime_error("obtained a phidget CUID that was not a phidget, this can't happen."); ! printf("%8d %32s ", phidget->UID().serial(), phidget->name()); ! CServoController *sc = dynamic_cast < CServoController *>(phidget); ! if (sc != NULL) { ! printf("Servos: %d\n", sc->servoCount()); } ! /* ! else ! if (ik!=NULL) ! { ! printf("DigitalIn: %d\n",ik->digitalIns().size()); ! printf(" DigitalOut: %d\n",ik->digitalOuts().size()); ! printf(" AnalogIns: %d\n",ik->analogIns().size()); ! } ! */ ! else ! printf("Unsupported\n"); ! } ! printf("-------- -------------------------------- ----------------\n"); ! printf("\n\n"); ! printf("Total phidgets:%d\n", phidgets.size()); ! printf("\n"); } --- 197,243 ---- */ ! void phidgets_ls() { ! CPhidgetManager *manager = CPhidgetManager::getInstance(); ! vector <CUID >phidgets = manager->query(LP_PHIDGET); ! printf("\n"); ! printf(" UID Name Misc\n"); ! printf("-------- -------------------------------- ----------------\n"); ! for (int t = 0; t < phidgets.size(); t++) ! { ! const CUID &uid = phidgets[t]; ! CUniqueDevice *ud=manager->find(uid,true); ! if (ud!=NULL) ! { ! //CPhidget *phidget = dynamic_cast < CPhidget *>(manager->find(uid, true)); ! CPhidget *phidget = dynamic_cast < CPhidget *>(ud); ! ! if (phidget == NULL) ! throw runtime_error("obtained a phidget CUID that was not a phidget, this can't happen."); ! printf("%8d %32s ", phidget->UID().serial(), phidget->name()); ! ! CServoController *sc = dynamic_cast < CServoController *>(phidget); ! if (sc != NULL) ! printf("Servos: %d\n", sc->servoCount()); ! else ! printf("Unsupported\n"); ! } ! else ! { ! printf("%8d Unsupported Phidget\n", uid.serial()); ! } } ! printf("-------- -------------------------------- ----------------\n"); ! printf("\n\n"); ! printf("Total phidgets:%d\n", phidgets.size()); ! printf("\n"); } |
From: Jack S. <js...@us...> - 2002-09-16 18:22:21
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory usw-pr-cvs1:/tmp/cvs-serv14333 Modified Files: phidget.c Log Message: Woops, had C++ style variable declartions in C code. Index: phidget.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** phidget.c 16 Sep 2002 06:40:57 -0000 1.8 --- phidget.c 16 Sep 2002 18:22:18 -0000 1.9 *************** *** 345,348 **** --- 345,349 ---- { int i = 0, j = 0, ret=0; + struct usb_dev_handle *handle; unsigned char buffer[128] = { 0 }; unsigned char serial[256] = { 0 }; *************** *** 350,354 **** DBG("_getSerial"); ! struct usb_dev_handle *handle= usb_open(device); if (handle==NULL) --- 351,355 ---- DBG("_getSerial"); ! handle= usb_open(device); if (handle==NULL) |
From: Jack S. <js...@us...> - 2002-09-16 06:57:53
|
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory usw-pr-cvs1:/tmp/cvs-serv6265/phidget++ Modified Files: CPhidgetManager.cc Log Message: Fixed problem where if any phidget besides a servo manager was attached the library would throw an exception. Now it should ignore any unknown phidgets. This is a temporary solution, a better solution is coming soon. Index: CPhidgetManager.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.cc,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CPhidgetManager.cc 16 Sep 2002 06:43:33 -0000 1.6 --- CPhidgetManager.cc 16 Sep 2002 06:57:50 -0000 1.7 *************** *** 259,268 **** throw runtime_error("Id must be -1 for all phidgets"); ! CServoController *sc = new CServoController (uid); ! //_uniqueDevices.push_back(sc); ! return (sc); METHOD_UNGUARD; } --- 259,285 ---- throw runtime_error("Id must be -1 for all phidgets"); + struct phidget *_device=CPhidgetManager::getInstance()->getDeviceHandle(uid); ! if (_device!=NULL) ! { ! enum EDeviceClass deviceClass=error(phidgetTypeDeviceClass(error(phidgetType(_device)))); ! ! phidgetClose(_device); ! switch (deviceClass) ! { ! case LP_SERVO_CONTROLLER: ! { ! CServoController *sc = new CServoController (uid); ! return(sc); ! break; ! } ! default: ! return(NULL); // unsupported device type ! } ! } ! ! return (NULL); METHOD_UNGUARD; } |
From: Jack S. <js...@us...> - 2002-09-16 06:45:45
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory usw-pr-cvs1:/tmp/cvs-serv32501 Modified Files: phidget_c.c servo_example.cc Log Message: Added better error checking to phidget_c.c (ignores warnings, or positive errors). Also added example4 to servo_example which shows how to derive a CServoController that can detect attach/detach events. Index: phidget_c.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_c.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** phidget_c.c 14 Sep 2002 01:25:16 -0000 1.4 --- phidget_c.c 16 Sep 2002 06:45:42 -0000 1.5 *************** *** 62,66 **** phidgetTypeProductID (phidgetType (dev)), phidgetSerial (dev)); ! if (phidgetLastError()!=LPE_NONE) { printf("error - %s\n",phidgetErrorString(phidgetLastError())); --- 62,66 ---- phidgetTypeProductID (phidgetType (dev)), phidgetSerial (dev)); ! if (phidgetLastError()<0) { printf("error - %s\n",phidgetErrorString(phidgetLastError())); *************** *** 77,81 **** // 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())); --- 77,81 ---- // Move a single servo (will move servo 0 of a 1 or 4 servo controller) ! if (phidgetSingleServo (dev, k)<0) { printf("error - %s\n",phidgetErrorString(phidgetLastError())); *************** *** 92,96 **** // Close the phidget ! if (phidgetClose (dev)!=LPE_NONE) { printf("error - %s\n",phidgetErrorString(phidgetLastError())); --- 92,96 ---- // Close the phidget ! if (phidgetClose (dev)<0) { printf("error - %s\n",phidgetErrorString(phidgetLastError())); Index: servo_example.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/servo_example.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** servo_example.cc 12 Sep 2002 03:19:48 -0000 1.4 --- servo_example.cc 16 Sep 2002 06:45:42 -0000 1.5 *************** *** 130,133 **** --- 130,192 ---- }; + /* + * A derived class that is a servo controller + */ + void example4() + { + class CMyServoController : public CServoController + { + public: + CMyServoController(const CUID &uid) : + CServoController(uid) + { + printf(" CMyServoController: constructed\n"); + } + ~CMyServoController() + { + printf(" CMyServoController: destructor\n"); + } + virtual void onAttach() + { + CServoController::onAttach(); + printf(" CMyServoController: attach\n"); + } + virtual void onDetach() + { + CServoController::onDetach(); + printf(" CMyServoController: deattach\n"); + } + }; + + printf("example 4 - Bit more complex, construct our own derived servo controller\n"); + + // We have this brace to make sure all the stack objects get destroyed before we call cleanup, + // cleanup will throw an exception when it is called and objects are still out in the "world" + { + printf(" Request servo #0 from the servo controller\n"); + CMyServoController servoController(servoPhidgetID); + + printf(" Name:%s\n",servoController.name()); + printf(" Servo Count:%d\n",servoController.servoCount()); + + printf(" Randomly moving all servos.\n"); + for (int t=0;t<servoController.servoCount();t++) + { + servoController.servo(t,true)->position((rand()%1000)/1000.0); + } + + printf(" Wait for them to move. this will delay for 10 seconds, good time to attach/detach it.\n"); + time_t start=time(NULL); + + while ((time(NULL)-start)<10) + { + CPhidgetManager::getInstance()->checkForEvents(); + } + } + + cleanup(); + }; + + /** *************** *** 152,155 **** --- 211,215 ---- example2(); example3(); + example4(); } catch(const exception &e) |
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory usw-pr-cvs1:/tmp/cvs-serv31521 Modified Files: CPhidget.cc CPhidget.h CPhidgetManager.cc CServo.cc CServoController.cc CUID.cc CUniqueDevice.cc helper.h Log Message: Major changes in how the event model works, it seems to work correctly now. Also added GUARD defines around all functions and methods. This will output a nice stack dump when exceptions occur. Index: CPhidget.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidget.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CPhidget.cc 14 Sep 2002 01:51:31 -0000 1.5 --- CPhidget.cc 16 Sep 2002 06:43:33 -0000 1.6 *************** *** 18,21 **** --- 18,22 ---- _device(CPhidgetManager::getInstance()->getDeviceHandle(uid)) { + METHOD_GUARD; // Ask the phidget manager if we really exist as a device, if not throw an exception *************** *** 23,84 **** throw runtime_error("Phidget doesn't exist."); ! _last_wasAttached = error(phidgetAttached(_device)) == 1; } CPhidget::~CPhidget () { error(phidgetClose(_device)); } int CPhidget::classType() { ! //return(_device->type->deviceClass); return (error(phidgetTypeDeviceClass(error(phidgetType(_device))))); } const char *CPhidget::name() { ! //return(_device->type->name); return (error(phidgetTypeName(error(phidgetType(_device))))); } int CPhidget::vendorID() { ! //return(_device->type->vendorID); return (error(phidgetTypeVendorID(error(phidgetType(_device))))); } int CPhidget::productID() { ! //return(_device->type->productID); return (error(phidgetTypeProductID(error(phidgetType(_device))))); } bool CPhidget::isAttached() { ! //if (_device->attached==1) if (error(phidgetAttached(_device)) == 1) return (true); return (false); } void CPhidget::processEvents() { ! bool temp = isAttached(); ! ! if (!_last_wasAttached && temp) ! onAttach(); ! else if (_last_wasAttached && !temp) ! onDetach(); ! _last_wasAttached = temp; } void CPhidget::onAttach() { } void CPhidget::onDetach() { } --- 24,96 ---- throw runtime_error("Phidget doesn't exist."); ! //_last_wasAttached = error(phidgetAttached(_device)) == 1; ! METHOD_UNGUARD; } CPhidget::~CPhidget () { + METHOD_GUARD; error(phidgetClose(_device)); + METHOD_UNGUARD; } int CPhidget::classType() { ! METHOD_GUARD; return (error(phidgetTypeDeviceClass(error(phidgetType(_device))))); + METHOD_UNGUARD; } const char *CPhidget::name() { ! METHOD_GUARD; return (error(phidgetTypeName(error(phidgetType(_device))))); + METHOD_UNGUARD; } int CPhidget::vendorID() { ! METHOD_GUARD; return (error(phidgetTypeVendorID(error(phidgetType(_device))))); + METHOD_UNGUARD; } int CPhidget::productID() { ! METHOD_GUARD; return (error(phidgetTypeProductID(error(phidgetType(_device))))); + METHOD_UNGUARD; } bool CPhidget::isAttached() { ! METHOD_GUARD; if (error(phidgetAttached(_device)) == 1) return (true); return (false); + METHOD_UNGUARD; } void CPhidget::processEvents() { ! METHOD_GUARD; ! bool is=error(phidgetAttached(_device))==1; ! bool was=error(phidgetWasAttached(_device))==1; ! if (is && !was) onAttach(); ! if (!is && was) onDetach(); ! METHOD_UNGUARD; } void CPhidget::onAttach() { + METHOD_GUARD; + METHOD_UNGUARD; } void CPhidget::onDetach() { + METHOD_GUARD; + METHOD_UNGUARD; } Index: CPhidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidget.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CPhidget.h 12 Sep 2002 00:24:29 -0000 1.4 --- CPhidget.h 16 Sep 2002 06:43:33 -0000 1.5 *************** *** 23,27 **** { private: ! bool _last_wasAttached; //bool _userConstructed; --- 23,27 ---- { private: ! //bool _last_wasAttached; //bool _userConstructed; Index: CPhidgetManager.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CPhidgetManager.cc 14 Sep 2002 01:51:31 -0000 1.5 --- CPhidgetManager.cc 16 Sep 2002 06:43:33 -0000 1.6 *************** *** 20,28 **** --- 20,31 ---- void CPhidgetManager::registerDevice(CUniqueDevice *dev) { + METHOD_GUARD; _uniqueDevices.push_back(dev); + METHOD_UNGUARD; } void CPhidgetManager::unregisterDevice(CUniqueDevice *dev) { + METHOD_GUARD; vector <CUniqueDevice *>::iterator i; *************** *** 34,37 **** --- 37,41 ---- throw runtime_error("Can't unregister a device that wasn't registered."); + METHOD_UNGUARD; } *************** *** 70,73 **** --- 74,78 ---- CPhidgetManager::CPhidgetManager () { + METHOD_GUARD; error(phidgetInit(1)); *************** *** 86,93 **** --- 91,100 ---- for (int t=0;t<_phidgets.size();t++) _phidgets[t]->processEvents(); */ + METHOD_UNGUARD; } CPhidgetManager::~CPhidgetManager () { + METHOD_GUARD; /* for (int t=0;t<_phidgets.size();t++) *************** *** 101,108 **** --- 108,117 ---- error(phidgetDeinit()); + METHOD_UNGUARD; } vector <CUID >CPhidgetManager::query(const EDeviceClass tp) { + METHOD_GUARD; set < CUID >devices; *************** *** 139,146 **** --- 148,157 ---- return (temp); + METHOD_UNGUARD; } struct phidget *CPhidgetManager::getDeviceHandle(const CUID &uid) { + METHOD_GUARD; if (uid.id() != -1) *************** *** 158,161 **** --- 169,173 ---- return (NULL); + METHOD_UNGUARD; } *************** *** 174,193 **** bool CPhidgetManager::checkForEvents() { bool found = (error(phidgetEvents()) == 1); // Get the list of phidgets if (found) { - /* - int phidget_count; - struct phidget **phidgets=phidget_get_phidgets(&phidget_count); - - for (int t=0;t<phidget_count;t++) - { - // We open this device - addPossibleNewDevice(phidgets[t]); - } - for (int t=0;t<_phidgets.size();t++) _phidgets[t]->processEvents(); - */ - for (int t = 0; t < _uniqueDevices.size(); t++) _uniqueDevices[t]->processEvents(); --- 186,194 ---- bool CPhidgetManager::checkForEvents() { + METHOD_GUARD; bool found = (error(phidgetEvents()) == 1); // Get the list of phidgets if (found) { for (int t = 0; t < _uniqueDevices.size(); t++) _uniqueDevices[t]->processEvents(); *************** *** 195,202 **** --- 196,205 ---- return (found); + METHOD_UNGUARD; } CUniqueDevice *CPhidgetManager::find(const CUID &uid, bool create) { + METHOD_GUARD; CUniqueDevice *temp; bool isPhidget = false; *************** *** 246,253 **** --- 249,258 ---- // The base phidget should exists and can now create it for us. return (temp->find(uid, create)); + METHOD_UNGUARD; } CPhidget *CPhidgetManager::createPhidget(const CUID &uid) { + METHOD_GUARD; // This device better not exists, we assume that has already been checked. if (uid.id() != -1) *************** *** 260,263 **** --- 265,269 ---- return (sc); + METHOD_UNGUARD; } Index: CServo.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServo.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CServo.cc 12 Sep 2002 03:02:07 -0000 1.5 --- CServo.cc 16 Sep 2002 06:43:33 -0000 1.6 *************** *** 11,14 **** --- 11,15 ---- #include "CServoController.h" #include "CPhidgetManager.h" + #include "helper.h" /* *************** *** 31,34 **** --- 32,37 ---- _systemManaged(true) { + METHOD_GUARD; + METHOD_UNGUARD; } *************** *** 36,39 **** --- 39,43 ---- _systemManaged(false) { + METHOD_GUARD; // We have to create it this way, because the phidget manager will // be in charge of this servo controller, or return us a servo controller that has already been created. *************** *** 42,56 **** --- 46,65 ---- // Let the controller know about this servo _controller->registerServo(this, uid.id()); + METHOD_UNGUARD; } CServo::~CServo () { + METHOD_GUARD; if (!_systemManaged) _controller->unregisterServo(UID()); + METHOD_UNGUARD; } void CServo::position(float p) { + METHOD_GUARD; _position = p; _controller->update(); + METHOD_UNGUARD; } Index: CServoController.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServoController.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CServoController.cc 14 Sep 2002 01:51:31 -0000 1.5 --- CServoController.cc 16 Sep 2002 06:43:33 -0000 1.6 *************** *** 15,21 **** #include "helper.h" ! CServoController::CServoController (const CUID &uid):CPhidget (uid), _servoCount(-1), ! _servos(NULL) { // Make sure it was constructed properly if (classType() != LP_SERVO_CONTROLLER) --- 15,24 ---- #include "helper.h" ! CServoController::CServoController (const CUID &uid) : ! CPhidget (uid), ! _servoCount(-1), ! _servos(NULL) { + METHOD_GUARD; // Make sure it was constructed properly if (classType() != LP_SERVO_CONTROLLER) *************** *** 46,53 **** --- 49,58 ---- } } + METHOD_UNGUARD; } CServoController::~CServoController () { + METHOD_GUARD; for (int t = 0; t < _servoCount; t++) if (_servos[t].first) *************** *** 55,70 **** --- 60,79 ---- delete[]_servos; + METHOD_UNGUARD; } CUniqueDevice *CServoController::find(const CUID &uid, bool create) { + METHOD_GUARD; if (uid.serial() == UID().serial() && uid.id() >= 0 && uid.id() < _servoCount) return (servo(uid.id(), create)); return (CPhidget::find(uid)); + METHOD_UNGUARD; } CServo *CServoController::servo(const int id, bool create) { + METHOD_GUARD; if (id < 0 || id >= _servoCount) throw runtime_error("Invalid servo id"); *************** *** 76,83 **** --- 85,94 ---- return (_servos[id].second); + METHOD_UNGUARD; } void CServoController::registerServo(CServo *servo, int id) { + METHOD_GUARD; if (id < 0 || id >= _servoCount) throw runtime_error("Invalid servo id"); *************** *** 88,95 **** --- 99,108 ---- _servos[id].first = false; _servos[id].second = servo; + METHOD_UNGUARD; } void CServoController::unregisterServo(const CUID &uid) { + METHOD_GUARD; if ((uid.id() < 0 && uid.id() >= _servoCount) || uid.serial() != UID().serial()) *************** *** 103,110 **** --- 116,125 ---- _servos[uid.id()].first = true; _servos[uid.id()].second = NULL; + METHOD_UNGUARD; } void CServoController::setServoCount(int num) { + METHOD_GUARD; _servoCount = num; *************** *** 115,118 **** --- 130,134 ---- _servos[t].second = NULL; } + METHOD_UNGUARD; } *************** *** 191,194 **** --- 207,211 ---- void CServoController::update() { + METHOD_GUARD; if (_servoCount) { float p1 = 0, p2 = 0, p3 = 0, p4 = 0; *************** *** 205,208 **** --- 222,226 ---- error(phidgetQuadServo(device(), p1, p2, p3, p4)); } + METHOD_UNGUARD; } Index: CUID.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CUID.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CUID.cc 12 Sep 2002 00:24:29 -0000 1.4 --- CUID.cc 16 Sep 2002 06:43:33 -0000 1.5 *************** *** 10,50 **** #include "CUID.h" #include "CUniqueDevice.h" ! CUID::CUID (const int serial):_serial(serial), ! _id(-1) { } ! CUID::CUID (const int serial, const int id):_serial(serial), ! _id(id) { } ! CUID::CUID ():_serial(-1), ! _id(-1) { } ! CUID::CUID (const CUniqueDevice *device, const int id):_serial(device->UID().serial()), ! _id(id) { } CUID::CUID (const CUID &id) { (*this) = id; } ! const CUID &CUID::operator = (const CUID &id) { _serial = id._serial; _id = id._id; return (*this); } ! bool CUID::operator == (const CUID &id) ! const { if (_serial != id._serial) return (false); --- 10,69 ---- #include "CUID.h" #include "CUniqueDevice.h" + #include "helper.h" ! CUID::CUID (const int serial) : ! _serial(serial), ! _id(-1) { + METHOD_GUARD; + METHOD_UNGUARD; } ! CUID::CUID (const int serial, const int id) : ! _serial(serial), ! _id(id) { + METHOD_GUARD; + METHOD_UNGUARD; } ! CUID::CUID () : ! _serial(-1), ! _id(-1) { + METHOD_GUARD; + METHOD_UNGUARD; } ! CUID::CUID (const CUniqueDevice *device, const int id) : ! _serial(device->UID().serial()), ! _id(id) { + METHOD_GUARD; + METHOD_UNGUARD; } CUID::CUID (const CUID &id) { + METHOD_GUARD; (*this) = id; + METHOD_UNGUARD; } ! const CUID &CUID::operator = (const CUID &id) ! { ! METHOD_GUARD; _serial = id._serial; _id = id._id; return (*this); + METHOD_UNGUARD; } ! bool CUID::operator == (const CUID &id) const ! { ! METHOD_GUARD; if (_serial != id._serial) return (false); *************** *** 52,100 **** return (false); return (true); ! } ! CUID::~CUID () ! { ! } ! int CUID::serial() ! const ! { ! return (_serial); ! } ! int CUID::id() const ! { ! return (_id); ! } - bool CUID::operator < (const CUID &id) - const - { - if (_serial < id._serial) - return (true); - if (_serial > id._serial) - return (false); - return (_id < id._id); - } - bool CUID::operator > (const CUID &id) const - { - if (_serial < id._serial) - return (false); - if (_serial > id._serial) - return (true); - return (_id > id._id); - } ! string CUID::asString() ! const ! { ! char temp[16]; ! if (_id == -1) ! sprintf(temp, "%d", _serial); ! else ! sprintf(temp, "%d:%d", _serial, _id); ! return (string(temp)); ! } --- 71,131 ---- return (false); return (true); ! METHOD_UNGUARD; ! } ! CUID::~CUID () ! { ! METHOD_GUARD; ! METHOD_UNGUARD; ! } ! int CUID::serial() const ! { ! METHOD_GUARD; ! return (_serial); ! METHOD_UNGUARD; ! } + int CUID::id() const + { + METHOD_GUARD; + return (_id); + METHOD_UNGUARD; + } ! bool CUID::operator < (const CUID &id) const ! { ! METHOD_GUARD; ! if (_serial < id._serial) ! return (true); ! if (_serial > id._serial) ! return (false); ! return (_id < id._id); ! METHOD_UNGUARD; ! } ! bool CUID::operator > (const CUID &id) const ! { ! METHOD_GUARD; ! if (_serial < id._serial) ! return (false); ! if (_serial > id._serial) ! return (true); ! return (_id > id._id); ! METHOD_UNGUARD; ! } ! string CUID::asString() const ! { ! METHOD_GUARD; ! char temp[16]; ! ! if (_id == -1) ! sprintf(temp, "%d", _serial); ! else ! sprintf(temp, "%d:%d", _serial, _id); ! ! return (string(temp)); ! METHOD_UNGUARD; ! } Index: CUniqueDevice.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CUniqueDevice.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CUniqueDevice.cc 12 Sep 2002 00:24:29 -0000 1.4 --- CUniqueDevice.cc 16 Sep 2002 06:43:33 -0000 1.5 *************** *** 1,12 **** --- 1,17 ---- #include "CUniqueDevice.h" #include "CPhidgetManager.h" + #include "helper.h" void CUniqueDevice::init() { + METHOD_GUARD; CPhidgetManager::getInstance()->registerDevice(this); + METHOD_UNGUARD; } CUniqueDevice::~CUniqueDevice () { + METHOD_GUARD; CPhidgetManager::getInstance()->unregisterDevice(this); + METHOD_UNGUARD; } Index: helper.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/helper.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** helper.h 14 Sep 2002 01:51:31 -0000 1.1 --- helper.h 16 Sep 2002 06:43:33 -0000 1.2 *************** *** 4,11 **** --- 4,105 ---- #include <stdexcept> #include <string> + #include <iostream> + + + // These guard functions produce a nice stack dump on an exception + //#define MESSAGE_ON_FUNCTION_ENTER + //#define MESSAGE_ON_METHOD_ENTER + + #define LOG std::cout + + // define object check routine, see if this is NULL + #define CHECK_OBJECT if (this==NULL) throw(runtime_error("this was NULL")); + + #ifdef _WIN32 + #define LOCATION __FILE__ << "#" << __LINE__ << " " + #else + #define LOCATION __FILE__ << "#" << __LINE__ << " " << __PRETTY_FUNCTION__ + #endif + + + #ifdef MESSAGE_ON_FUNCTION_ENTER + #define FUNCTION_ENTER_MESSAGE LOG << "Function: " << LOCATION << std::endl + #else // MESSAGE_ON_FUNCTION_ENTER + #define FUNCTION_ENTER_MESSAGE + #endif // MESSAGE_ON_FUNCTION_ENTER + + #ifdef MESSAGE_ON_METHOD_ENTER + #define METHOD_ENTER_MESSAGE LOG << "Method: " << LOCATION << std::endl + #else // MESSAGE_ON_METHOD_ENTER + #define METHOD_ENTER_MESSAGE + #endif // MESSAGE_ON_METHOD_ENTER + + + + + + #define METHOD_GUARD \ + CHECK_OBJECT; \ + METHOD_ENTER_MESSAGE; \ + try \ + { \ + + #define METHOD_UNGUARD } \ + catch(const string &msg) \ + { \ + LOG << LOCATION << " "; \ + LOG << "String:" << msg << std::endl; \ + throw; \ + } \ + catch(const std::exception &e) \ + { \ + LOG << LOCATION << " "; \ + LOG << "Exception:" << e.what() << std::endl; \ + throw; \ + } \ + catch(...) \ + { \ + LOG << LOCATION << " "; \ + LOG << "Unknown exception caught." << std::endl; \ + throw; \ + } + + + + + // function guards + #define FUNC_GUARD \ + FUNCTION_ENTER_MESSAGE; \ + try \ + { \ + + #define FUNC_UNGUARD } \ + catch(const string &msg) \ + { \ + LOG << LOCATION << " "; \ + LOG << "String:" << msg << endl; \ + throw; \ + } \ + catch(const std::exception &e) \ + { \ + LOG << LOCATION << " "; \ + LOG << "Exception:" << e.what() << endl; \ + throw; \ + } \ + catch(...) \ + { \ + LOG << LOCATION << " "; \ + LOG << "Unknown exception caught." << endl; \ + throw; \ + } + + + + template <class X> X &error(X &value) { + FUNC_GUARD; enum ELPError err; *************** *** 16,19 **** --- 110,114 ---- return(value); + FUNC_UNGUARD; } *************** *** 21,24 **** --- 116,120 ---- const X &error(const X &value) { + FUNC_GUARD; enum ELPError err; *************** *** 29,33 **** --- 125,131 ---- return(value); + FUNC_UNGUARD; } + #endif |
From: Jack S. <js...@us...> - 2002-09-16 06:41:00
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory usw-pr-cvs1:/tmp/cvs-serv30676 Modified Files: phidget.c phidget.h Log Message: A very large set of changes to get events working again. Index: phidget.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** phidget.c 14 Sep 2002 01:24:39 -0000 1.7 --- phidget.c 16 Sep 2002 06:40:57 -0000 1.8 *************** *** 15,34 **** /** ! * We only support 128 USB devices */ #define MAX_USB_DEVICES 128 //#define DBG(a) printf("*** DEBUG *** : %s\n",a) #define DBG(a) ! int _libPhidgetInitialized = 0; ! ! /**< Private variable to determine if the libphidget is initialized */ ! int _typeCount = 0; ! ! /**< count of known phidget types */ ! struct phidget_type *_typeList = NULL; ! ! /**< Array that will hold all the type structures */ int _phidgetDeviceCount = 0; //*< Count of known phidgets */ struct phidget *_usbDeviceList[MAX_USB_DEVICES]; //*< Array that will hold all of the phidget structures */ --- 15,29 ---- /** ! * We only support 128 USB devices (because USB only supports 128 devices) */ #define MAX_USB_DEVICES 128 + // TODO - change this //#define DBG(a) printf("*** DEBUG *** : %s\n",a) #define DBG(a) ! int _libPhidgetInitialized = 0; /**< Private variable to determine if the libphidget is initialized */ ! int _typeCount = 0; /**< count of known phidget types */ ! struct phidget_type *_typeList = NULL; /**< Array that will hold all the type structures */ int _phidgetDeviceCount = 0; //*< Count of known phidgets */ struct phidget *_usbDeviceList[MAX_USB_DEVICES]; //*< Array that will hold all of the phidget structures */ *************** *** 72,92 **** struct phidget { ! const struct phidget_type *type; /**< Type of phidget that this currently opened phidget is */ ! struct usb_dev_handle *handle; /**< libusb handle to the phidget, try not to use this if at all possible. If this is NULL, the device isn't opened. */ ! struct usb_device *device; /**< libusb device to the phidget, try not to use this if at all possible */ ! int serial; /**< The serial number of the phidget for unique identificatoin */ ! int attached; /**< Is this phidget currently attached */ ! enum ! { ! WAS_OPENED, /**< The Device has been opened */ ! WAS_CLOSED, /**< The device has been closed */ ! WAS_ERROR /**< The device is in an unknown state */ ! } ! openedState; /**< Virtual state of the device, this keeps the state of the device even when it is detached. */ ! int defaultDataSize; /**< Size of default data */ ! void *defaultData; /**< Used to store default information for when the phidget is closed, different for each phidget */ }; /** * Private method to set the last phidget error value --- 67,127 ---- struct phidget { ! /** Type of phidget that this currently opened phidget is */ ! const struct phidget_type *type; ! /** libusb handle to the phidget, try not to use this if at all possible. ! * If this is NULL, the device isn't opened. */ ! struct usb_dev_handle *handle; ! ! /** libusb device to the phidget, try not to use this if at all possible */ ! struct usb_device *device; ! ! /** The serial number of the phidget for unique identificatoin */ ! int serial; ! ! /** Is this phidget currently attached */ ! int attached; ! ! /** Previous state of attached */ ! int wasAttached; ! ! /** Size of default data */ ! int defaultDataSize; ! ! /** Used to store default information for when the phidget is closed, different for each phidget */ ! void *defaultData; ! ! /** Virtual state of the device, this keeps the state of the device even when it is detached. */ ! enum ! { ! WAS_OPENED, /**< The Device has been opened */ ! WAS_CLOSED, /**< The device has been closed */ ! WAS_ERROR /**< The device is in an unknown state */ ! } openedState; }; + + int _stateAttached( struct phidget *device) + { + DBG("_stateAttached"); + device->wasAttached=device->attached; + device->attached=1; + + if (device->wasAttached!=device->attached) + return(1); + return(0); + } + + int _stateDetached( struct phidget *device) + { + DBG("_stateDetached"); + device->wasAttached=device->attached; + device->attached=0; + + if (device->wasAttached!=device->attached) + return(1); + return(0); + } + /** * Private method to set the last phidget error value *************** *** 100,104 **** /** ! * Returns the value of the last error, this is used when a function returns a pointer, if the pointer is NULL just check here for the last error */ enum ELPError --- 135,140 ---- /** ! * Returns the value of the last error, this is used when a function returns a pointer, ! * if the pointer is NULL just check here for the last error */ enum ELPError *************** *** 110,114 **** /** ! * Returns a pointer to a phidget_type structure, used for determining information about a specific phidget */ const struct phidget_type * --- 146,151 ---- /** ! * Returns a pointer to a phidget_type structure, used for determining information about a ! * specific phidget */ const struct phidget_type * *************** *** 145,148 **** --- 182,197 ---- /** + * Returns 1 if a phidget is was previously attached, 0 if it wasn't attached + * wasAttached becomes attached after each call to phidgetEvents + */ + int + phidgetWasAttached(const struct phidget *device) + { + if (device == NULL) + return (_error(LPE_INVALID_PHIDGET)); + return (device->wasAttached); + } + + /** * Returns the human readable name of the phidget type */ *************** *** 245,250 **** /** ! * Pfi zgd vun gion to Find a device type by vendor ID and product ID. Can't call \a registerDeviceType any more ! * after this function is called. */ struct phidget_type * --- 294,299 ---- /** ! * Private function to Find a device type by vendor ID and product ID. ! * Can't call \a registerDeviceType any more after this function is called. */ struct phidget_type * *************** *** 293,316 **** } /** * Private function to add a new device that we have found. There are 2 ways devices are added. * The first way is at the beginning, when we initialize and look for all connected devices. * The second is on attach. ! * Now when a device is detached it don't be removed from this list. Just marched as detached. * When it is reatached we will search this list to see if it matches this device. */ enum ELPError ! _addDevice(struct usb_device *device, struct phidget_type *ptd) { enum ELPError err; struct phidget *temp = malloc(sizeof(struct phidget)); ! DBG("addDevice"); temp->type = ptd; temp->handle = NULL; temp->device = device; ! temp->serial = -1; ! temp->attached = 1; temp->openedState = WAS_CLOSED; temp->defaultData = NULL; --- 342,435 ---- } + int _getSerial(struct usb_device *device, struct phidget_type *ptd) + { + int i = 0, j = 0, ret=0; + unsigned char buffer[128] = { 0 }; + unsigned char serial[256] = { 0 }; + + DBG("_getSerial"); + + struct usb_dev_handle *handle= usb_open(device); + + if (handle==NULL) + { + _error(LPE_NO_SERIAL_RETURNED); + return(-1); + } + + // TODO - figure out why this is needed + // it seems that sometimes when I set the configuration it doesn't work, so I have to try again + // this seems to work though. Could cause a hangup. + while (usb_set_configuration(handle, 1)<0); + /* + ret = usb_set_configuration(handle, 1); + if (ret < 0) + { + usb_close(handle); + _error(LPE_SET_CONFIGURATION_FAILED); + return(-1); + } + */ + + ret = usb_claim_interface(handle, 0); + if (ret < 0) + { + usb_close(handle); + _error(LPE_CLAIM_INTERFACE_FAILED); + return(-1); + } + + ret = usb_set_altinterface(handle, 0); + if (ret < 0) + { + usb_release_interface(handle, 0); + usb_close(handle); + _error(LPE_SET_ALT_INTERFACE_FAILED); + return(-1); + } + + i=usb_control_msg(handle, 0x80, 0x06, 0x0303, 0, buffer, sizeof(buffer), 5000); + + if (i!=buffer[0] || i<0) + { + _error(LPE_NO_SERIAL_RETURNED); + return (-1); + } + + j=0; + for (i=2;i<buffer[0];i+=2) + { + serial[j]=buffer[i]; + j++; + } + serial[j] = (int) NULL; + j++; + + usb_release_interface(handle, 0); + usb_close(handle); + return(atoi(serial)); + } + /** * Private function to add a new device that we have found. There are 2 ways devices are added. * The first way is at the beginning, when we initialize and look for all connected devices. * The second is on attach. ! * Now when a device is detached it won't be removed from this list. Just marked as detached. * When it is reatached we will search this list to see if it matches this device. */ enum ELPError ! _addDevice(struct usb_device *device, struct phidget_type *ptd, int _serial) { enum ELPError err; struct phidget *temp = malloc(sizeof(struct phidget)); ! DBG("_addDevice"); temp->type = ptd; temp->handle = NULL; temp->device = device; ! temp->serial = _serial; ! temp->wasAttached = 0; ! temp->attached = 0; temp->openedState = WAS_CLOSED; temp->defaultData = NULL; *************** *** 321,325 **** * then we close it. Serial must first be -1 */ ! if (phidgetOpen(temp)==NULL) return(_error(phidgetLastError())); --- 440,449 ---- * then we close it. Serial must first be -1 */ ! if (temp->serial<0) ! { ! return(_error(phidgetLastError())); ! } ! ! /* if (phidgetOpen(temp)==NULL) return(_error(phidgetLastError())); *************** *** 328,331 **** --- 452,456 ---- if (err!=LPE_NONE) return(_error(err)); + */ _usbDeviceList[_phidgetDeviceCount] = temp; *************** *** 336,482 **** } ! /** ! * Private function to looks at all USB devices and finds the ones that are phidgets. This should ! * only be called once during initialization. */ ! enum ELPError ! _findPhidgets() { ! struct usb_bus *bus; ! struct usb_device *dev; ! ! DBG("findPhidgets"); ! ! usb_init(); ! ! usb_find_busses(); ! usb_find_devices(); ! _clearDevices(); ! for (bus = usb_busses; bus; bus = bus->next) { ! for (dev = bus->devices; dev; dev = dev->next) { ! struct phidget_type *pdt = _findDevice(dev->descriptor.idVendor, ! dev->descriptor.idProduct); ! if (pdt != NULL) ! { ! enum ELPError err; - err=_addDevice(dev, pdt); ! if (err!=LPE_NONE) return(_error(err)); ! } ! } ! } ! return(LPE_NONE); ! } - /** - * Check for any changes in the USB bus that would affect the phidget library, returns 1 if a change has occured. - */ - int - phidgetEvents() - { - int change = 0; - int found[MAX_USB_DEVICES]; - struct usb_bus *bus; - struct usb_device *dev; - int t; - DBG("phidgetEvents"); - if (_libPhidgetInitialized == 0) - return (LPE_NOT_INITIALIZED); ! for (t = 0; t < MAX_USB_DEVICES; t++) { ! found[t] = 0; ! } ! usb_find_busses(); ! usb_find_devices(); ! for (bus = usb_busses; bus; bus = bus->next) { ! for (dev = bus->devices; dev; dev = dev->next) { ! struct phidget_type *pdt = _findDevice(dev->descriptor.idVendor, ! dev->descriptor.idProduct); ! if (pdt != NULL) { ! // Does this device already exists? ! for (t = 0; t < _phidgetDeviceCount; t++) { ! if (_usbDeviceList[t]->device == dev) { ! // We found this device ! found[t] = 1; ! break; ! } ! } ! // Not found yet, mark it and load it ! // We really need to check to see if any of the detached devices have it. ! // If they do we delete this one and set the previous one to attached ! if (found[t] == 0) { ! found[t] = 2; ! _addDevice(dev, pdt); ! change = 1; ! for (t = 0; t < _phidgetDeviceCount - 1; t++) { ! if (_usbDeviceList[t]->attached == 0) ! if (_usbDeviceList[_phidgetDeviceCount - 1]->serial == _usbDeviceList[t]->serial) { ! DBG("Found a previously attached phidget"); ! // We found a match ! _usbDeviceList[t]->handle = NULL; ! _usbDeviceList[t]->device = dev; ! _usbDeviceList[t]->attached = 1; ! if (_usbDeviceList[t]->openedState == WAS_OPENED) { ! _usbDeviceList[t]->openedState = WAS_CLOSED; ! phidgetOpen(_usbDeviceList[t]); } ! // Now delete that last item ! free(_usbDeviceList[_phidgetDeviceCount - 1]); ! _usbDeviceList[_phidgetDeviceCount - 1] = NULL; ! _phidgetDeviceCount = _phidgetDeviceCount - 1; ! found[t] = 1; ! change = 1; break; ! } ! } } - } } - } ! // Mark all detached phidgets ! for (t = 0; t < MAX_USB_DEVICES; t++) { ! if (found[t] == 0) // We didn't find this device ! if (_usbDeviceList[t] != NULL) // we have a pointer to one ! if (_usbDeviceList[t]->attached == 1) // It says it should be attached, so it isn't { ! DBG("Phidget was detached\n"); ! // This device is detached ! // If this device is open then close it. ! if (_usbDeviceList[t]->openedState == WAS_OPENED) { ! usb_release_interface(_usbDeviceList[t]->handle, 0); ! usb_close(_usbDeviceList[t]->handle); ! _usbDeviceList[t]->openedState = WAS_OPENED; ! } ! _usbDeviceList[t]->handle = NULL; ! _usbDeviceList[t]->device = NULL; ! _usbDeviceList[t]->attached = 0; ! change = 1; ! } ! } ! return (change); } --- 461,741 ---- } ! /** ! * Check for any changes in the USB bus that would affect the phidget library, ! * returns 1 if a change has occured. ! * ! * USB only supports 128 devices, because this library automatically remembers ! * disconnected devices there could be problems if you plugged in 128 phidgets, ! * disconnected one of them, and then plugged in 1 new phidgets (requiring 129 ! * total phidgets). In that case an error will occur because we are out of ! * static memory. I really don't think this is an issue, if someone has that ! * many phidgets I will be glad to modify the code to handle it. */ ! int phidgetEvents() { ! int change = 0; ! enum ! { ! NOT_FOUND, ! FOUND_WAS_NEW, ! FOUND_WAS_OLD ! } found[MAX_USB_DEVICES]; ! struct usb_bus *bus; ! struct usb_device *dev; ! int t; ! DBG("phidgetEvents"); ! // must call phidgetInit before using any phidgetLibrary function ! if (_libPhidgetInitialized == 0) ! return (LPE_NOT_INITIALIZED); ! // We need to detect: ! // USB attaches ! // if we have seen it before, handle properly ! // if we haven't add a new phidget device ! // USB detaches ! // only one way to handle this ! ! // Initilize the "found it" array to NOT_FOUND ! for (t = 0; t < _phidgetDeviceCount; t++) ! found[t] = NOT_FOUND; + // Lib USB calls + usb_find_busses(); + usb_find_devices(); ! // Go thru all USB busses ! for (bus = usb_busses; bus; bus = bus->next) ! { ! // Step thru each device on that bus ! for (dev = bus->devices; dev; dev = dev->next) ! { ! // See if it is a phidget, and if it is get the phidget_type ! struct phidget_type *pdt = _findDevice(dev->descriptor.idVendor, dev->descriptor.idProduct); ! // It is a phidget ! if (pdt!=NULL) ! { ! int serial=-1; ! int wasFound=0; ! // Is this an already attached and used phidget? ! for (t=0;t<_phidgetDeviceCount;t++) ! { ! if ( _usbDeviceList[t]->device == dev) ! { ! // We found this device ! found[t] = FOUND_WAS_OLD; ! wasFound=1; + // Device found - Go to the next USB device + break; + } + } ! if (wasFound==0) ! { ! serial=_getSerial(dev,pdt); ! // have we seen this phidget before ! for (t=0;t<_phidgetDeviceCount;t++) ! { ! if ( _usbDeviceList[t]->serial==serial) ! { ! _usbDeviceList[t]->device=dev; // It has changed ! // We found this device ! found[t] = FOUND_WAS_OLD; ! wasFound=1; ! // Device found - Go to the next USB device ! break; ! } ! } ! } ! // Was the device found ! if (wasFound==0) ! { ! // No this is a new device we need to add it. ! found[_phidgetDeviceCount]=FOUND_WAS_NEW; ! _addDevice(dev, pdt,serial); ! change=1; ! // on to the next device ! continue; } ! } ! } ! } ! for (t=0;t<_phidgetDeviceCount;t++) ! { ! switch(found[t]) ! { ! case NOT_FOUND: ! if (_stateDetached(_usbDeviceList[t])==1) ! { ! // This device is detached ! // If this device is open then close it. ! if (_usbDeviceList[t]->openedState == WAS_OPENED) ! { ! usb_release_interface(_usbDeviceList[t]->handle, 0); ! usb_close(_usbDeviceList[t]->handle); ! _usbDeviceList[t]->openedState = WAS_OPENED; ! } ! // State changed ! change=1; ! } ! break; ! case FOUND_WAS_OLD: ! case FOUND_WAS_NEW: ! if (_stateAttached(_usbDeviceList[t])==1) ! { ! if (_usbDeviceList[t]->openedState == WAS_OPENED) ! { ! _usbDeviceList[t]->openedState = WAS_CLOSED; ! _usbDeviceList[t]->handle = NULL; ! phidgetOpen(_usbDeviceList[t]); ! } + // State changed + change=1; + } break; ! default: ! printf("This can't occur\n"); ! exit(-1); } } ! ! return(change); ! ! ! ! ! ! /* ! ! ! ! ! ! ! ! ! // ------------------------------------------------------------------------------- ! ! // Initilize the found it array to 0 ! for (t = 0; t < MAX_USB_DEVICES; t++) ! found[t] = 0; ! ! // Lib USB calls ! usb_find_busses(); ! usb_find_devices(); ! ! ! // Go thru all USB busses ! for (bus = usb_busses; bus; bus = bus->next) ! { ! // Step thru each device on that bus ! for (dev = bus->devices; dev; dev = dev->next) { ! // See if it is a phidget, and if it is get the phidget_type ! struct phidget_type *pdt = _findDevice(dev->descriptor.idVendor, dev->descriptor.idProduct); ! // This USB device is a phidget ! if (pdt != NULL) ! { ! // Check all known devices and see if we have seen this device ! for (t = 0; t < _phidgetDeviceCount; t++) ! { ! if (_usbDeviceList[t]->device == dev) ! { ! // We found this device ! // This means that it wasn't detached ! found[t] = 1; ! // Go to the next USB device ! continue; ! } ! } ! // Not found yet, mark it and load it ! // We really need to check to see if any of the detached ! // devices have it. If they do we delete this one and set ! // the previous one to attached ! if (found[t] == 0) ! { ! found[t] = 2; ! _addDevice(dev, pdt); ! change = 1; ! for (t = 0; t < _phidgetDeviceCount - 1; t++) { ! if (_usbDeviceList[t]->attached == 0) ! if (_usbDeviceList[_phidgetDeviceCount - 1]->serial == _usbDeviceList[t]->serial) { ! DBG("Found a previously attached phidget"); ! ! // We found a match ! ! _usbDeviceList[t]->handle = NULL; ! _usbDeviceList[t]->device = dev; ! _usbDeviceList[t]->attached = 1; ! ! if (_usbDeviceList[t]->openedState == WAS_OPENED) { ! _usbDeviceList[t]->openedState = WAS_CLOSED; ! phidgetOpen(_usbDeviceList[t]); ! } ! // Now delete that last item ! free(_usbDeviceList[_phidgetDeviceCount - 1]); ! _usbDeviceList[_phidgetDeviceCount - 1] = NULL; ! _phidgetDeviceCount = _phidgetDeviceCount - 1; ! ! found[t] = 1; ! ! change = 1; ! ! break; ! } ! } ! } ! } ! } ! } ! ! // Mark all detached phidgets ! for (t = 0; t < MAX_USB_DEVICES; t++) { ! if (found[t] == 0) // We didn't find this device ! if (_usbDeviceList[t] != NULL) // we have a pointer to one ! if (_usbDeviceList[t]->attached == 1) // It says it should be attached, so it isn't ! { ! DBG("Phidget was detached\n"); ! ! // This device is detached ! // If this device is open then close it. ! if (_usbDeviceList[t]->openedState == WAS_OPENED) { ! usb_release_interface(_usbDeviceList[t]->handle, 0); ! usb_close(_usbDeviceList[t]->handle); ! _usbDeviceList[t]->openedState = WAS_OPENED; ! } ! ! _usbDeviceList[t]->handle = NULL; ! _usbDeviceList[t]->device = NULL; ! _usbDeviceList[t]->attached = 0; ! ! change = 1; ! } ! } ! */ ! ! return (change); } *************** *** 489,492 **** --- 748,753 ---- DBG("phidgetInit"); + usb_init(); + _catchSignals = 0; *************** *** 510,516 **** --- 771,779 ---- _libPhidgetInitialized = 1; + /* err=_findPhidgets(); if (err!=LPE_NONE) return(_error(err)); + */ *************** *** 536,541 **** } ! return (_error(LPE_NONE)); } --- 799,805 ---- } + phidgetEvents(); ! return (phidgetLastError()); } *************** *** 632,635 **** --- 896,900 ---- ret = usb_set_configuration(phidgetDevice->handle, 1); if (ret < 0) { + printf("Can't set configuration:%d\n",ret); usb_close(phidgetDevice->handle); phidgetDevice->handle = NULL; *************** *** 663,667 **** int i = 0, j = 0; ! if (usb_control_msg(phidgetDevice->handle, 0x80, 0x06, 0x0303, 0, buffer, sizeof(buffer), 5000) == -1) { _error(LPE_NO_SERIAL_RETURNED); return (NULL); --- 928,936 ---- int i = 0, j = 0; ! i=usb_control_msg(phidgetDevice->handle, 0x80, 0x06, 0x0303, 0, buffer, sizeof(buffer), 5000); ! ! if (i!=buffer[0] || i<0) ! { ! printf("%d [%d]\n",i,buffer[0]); _error(LPE_NO_SERIAL_RETURNED); return (NULL); *************** *** 722,735 **** char buffer[6] = { 0, 0, 0, 0, 0, 0 }; ! enum ELPError err=phidgetWrite(phidgetDevice, buffer, 6); ! if (err!=LPE_NONE) ! return(_error(err)); } else { enum ELPError err; ! err=phidgetWrite(phidgetDevice, phidgetDevice->defaultData, phidgetDevice->defaultDataSize); ! if (err!=LPE_NONE) ! return(_error(err)); } } --- 991,1000 ---- char buffer[6] = { 0, 0, 0, 0, 0, 0 }; ! phidgetWrite(phidgetDevice, buffer, 6); } else { enum ELPError err; ! phidgetWrite(phidgetDevice, phidgetDevice->defaultData, phidgetDevice->defaultDataSize); } } *************** *** 751,767 **** phidgetWrite(struct phidget *phidgetDevice, char *buffer, int size) { ! DBG("phidgetWrite"); ! if (_libPhidgetInitialized == 0) ! return (_error(LPE_NOT_INITIALIZED)); ! if (phidgetDevice == NULL) ! return (_error(LPE_INVALID_PHIDGET)); ! if (phidgetDevice->attached == 0) ! return (_error(LPE_PHIDGET_NOT_ATTACHED)); ! if (phidgetDevice->handle == NULL) ! return (_error(LPE_PHIDGET_NOT_OPENED)); ! if (usb_control_msg(phidgetDevice->handle, 0x21, 0x09, 0x200, 0, buffer, size, 5000)!=size) ! return (_error(LPE_CONTROL_MSG_ERROR)); ! return (_error(LPE_NONE)); } --- 1016,1035 ---- phidgetWrite(struct phidget *phidgetDevice, char *buffer, int size) { ! int ret; ! DBG("phidgetWrite"); ! if (_libPhidgetInitialized == 0) ! return (_error(LPE_NOT_INITIALIZED)); ! if (phidgetDevice == NULL) ! return (_error(LPE_INVALID_PHIDGET)); ! if (phidgetDevice->attached == 0) ! return (_error(LPE_PHIDGET_NOT_ATTACHED)); ! if (phidgetDevice->handle == NULL) ! return (_error(LPE_PHIDGET_NOT_OPENED)); ! ret=usb_control_msg(phidgetDevice->handle, 0x21, 0x09, 0x200, 0, buffer, size, 5000); ! if (ret!=size) ! return (_error(LPE_CONTROL_MSG_ERROR)); ! ! return (_error(LPE_NONE)); } Index: phidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** phidget.h 12 Sep 2002 00:24:29 -0000 1.4 --- phidget.h 16 Sep 2002 06:40:57 -0000 1.5 *************** *** 257,260 **** --- 257,263 ---- int phidgetAttached(const struct phidget *device); + int phidgetWasAttached(const struct phidget *device); + + /** * Returns the last error that occured. No defined error can occur during this call. |
From: Vadim T. <vt...@us...> - 2002-09-14 18:59:26
|
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory usw-pr-cvs1:/tmp/cvs-serv26556/src/phidget++ Modified Files: Makefile.am Log Message: Fixed the makefiles so the include files are now deployed Index: Makefile.am =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/Makefile.am,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile.am 12 Sep 2002 01:32:07 -0000 1.5 --- Makefile.am 14 Sep 2002 18:59:21 -0000 1.6 *************** *** 1,18 **** lib_LTLIBRARIES = libphidget++.la ! libphidget___la_SOURCES = CPhidget.h \ ! CInterfaceKit.h \ ! CPhidgetManager.h \ ! CServo.h \ ! CServoController.h \ ! CUID.h \ ! CUniqueDevice.h \ ! TSingleton.h \ ! CPhidget.cc \ ! CPhidgetManager.cc \ ! CServo.cc \ ! CServoController.cc \ ! CUID.cc \ ! CUniqueDevice.cc # These are not active yet --- 1,23 ---- lib_LTLIBRARIES = libphidget++.la ! headerdir = ${prefix}/include ! ! header_DATA = CPhidget.h \ ! CInterfaceKit.h \ ! CPhidgetManager.h \ ! CServo.h \ ! CServoController.h \ ! CUID.h \ ! CUniqueDevice.h \ ! TSingleton.h ! ! libphidget___la_SOURCES = ${header_DATA} \ ! helper.h \ ! CPhidget.cc \ ! CPhidgetManager.cc \ ! CServo.cc \ ! CServoController.cc \ ! CUID.cc \ ! CUniqueDevice.cc # These are not active yet |
From: Vadim T. <vt...@us...> - 2002-09-14 18:59:26
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory usw-pr-cvs1:/tmp/cvs-serv26556/src/libphidget Modified Files: Makefile.am Log Message: Fixed the makefiles so the include files are now deployed Index: Makefile.am =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/Makefile.am,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Makefile.am 12 Sep 2002 01:32:07 -0000 1.4 --- Makefile.am 14 Sep 2002 18:59:21 -0000 1.5 *************** *** 1,5 **** lib_LTLIBRARIES = libphidget.la ! libphidget_la_SOURCES = phidget.h \ phidget.c --- 1,9 ---- lib_LTLIBRARIES = libphidget.la ! headerdir = ${prefix}/include ! ! header_DATA = phidget.h ! ! libphidget_la_SOURCES = ${header_DATA} \ phidget.c |