libphidget-cvs-commits Mailing List for Phidget Library (Page 5)
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) |
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory usw-pr-cvs1:/tmp/cvs-serv13770 Modified Files: CAnalogIn.cc CDigitalIn.cc CDigitalOut.cc CInterfaceKit.cc CPhidget.cc CPhidgetManager.cc CServoController.cc Added Files: helper.h Log Message: Added helper.h which contains a template that throws an excepception on detection of a libphidget error. Added calls to this template to the C++ code --- NEW FILE: helper.h --- #ifndef __HELPER_H__ #define __HELPER_H__ #include <stdexcept> #include <string> template <class X> X &error(X &value) { enum ELPError err; err=phidgetLastError(); if (err!=LPE_NONE) throw std::runtime_error(std::string("libphidget error >> ")+phidgetErrorString(err)); return(value); } template <class X> const X &error(const X &value) { enum ELPError err; err=phidgetLastError(); if (err!=LPE_NONE) throw std::runtime_error(std::string("libphidget error >> ")+phidgetErrorString(err)); return(value); } #endif Index: CAnalogIn.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CAnalogIn.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CAnalogIn.cc 12 Sep 2002 00:24:29 -0000 1.4 --- CAnalogIn.cc 14 Sep 2002 01:51:31 -0000 1.5 *************** *** 8,11 **** --- 8,12 ---- */ + /* #include "CAnalogIn.h" #include "CInterfaceKit.h" *************** *** 16,17 **** --- 17,19 ---- { } + */ Index: CDigitalIn.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CDigitalIn.cc 12 Sep 2002 00:24:29 -0000 1.4 --- CDigitalIn.cc 14 Sep 2002 01:51:31 -0000 1.5 *************** *** 8,11 **** --- 8,12 ---- */ + /* #include "CDigitalIn.h" #include "CInterfaceKit.h" *************** *** 15,16 **** --- 16,18 ---- { } + */ Index: CDigitalOut.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalOut.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CDigitalOut.cc 12 Sep 2002 00:24:29 -0000 1.4 --- CDigitalOut.cc 14 Sep 2002 01:51:31 -0000 1.5 *************** *** 8,11 **** --- 8,12 ---- */ + /* #include "CDigitalOut.h" #include "CInterfaceKit.h" *************** *** 28,29 **** --- 29,31 ---- temp2->update(); } + */ Index: CInterfaceKit.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CInterfaceKit.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CInterfaceKit.cc 12 Sep 2002 00:24:29 -0000 1.4 --- CInterfaceKit.cc 14 Sep 2002 01:51:31 -0000 1.5 *************** *** 8,11 **** --- 8,12 ---- */ + /* #include "CInterfaceKit.h" #include "CDigitalIn.h" *************** *** 125,126 **** --- 126,128 ---- return (NULL); } + */ Index: CPhidget.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidget.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CPhidget.cc 12 Sep 2002 00:24:29 -0000 1.4 --- CPhidget.cc 14 Sep 2002 01:51:31 -0000 1.5 *************** *** 13,16 **** --- 13,17 ---- #include <phidget.h> #include <usb.h> + #include "helper.h" CPhidget::CPhidget (const CUID &uid):CUniqueDevice (uid), *************** *** 22,31 **** throw runtime_error("Phidget doesn't exist."); ! _last_wasAttached = phidgetAttached(_device) == 1; } CPhidget::~CPhidget () { ! phidgetClose(_device); } --- 23,32 ---- throw runtime_error("Phidget doesn't exist."); ! _last_wasAttached = error(phidgetAttached(_device)) == 1; } CPhidget::~CPhidget () { ! error(phidgetClose(_device)); } *************** *** 33,37 **** { //return(_device->type->deviceClass); ! return (phidgetTypeDeviceClass(phidgetType(_device))); } --- 34,38 ---- { //return(_device->type->deviceClass); ! return (error(phidgetTypeDeviceClass(error(phidgetType(_device))))); } *************** *** 39,43 **** { //return(_device->type->name); ! return (phidgetTypeName(phidgetType(_device))); } --- 40,44 ---- { //return(_device->type->name); ! return (error(phidgetTypeName(error(phidgetType(_device))))); } *************** *** 45,49 **** { //return(_device->type->vendorID); ! return (phidgetTypeVendorID(phidgetType(_device))); } --- 46,50 ---- { //return(_device->type->vendorID); ! return (error(phidgetTypeVendorID(error(phidgetType(_device))))); } *************** *** 51,55 **** { //return(_device->type->productID); ! return (phidgetTypeProductID(phidgetType(_device))); } --- 52,56 ---- { //return(_device->type->productID); ! return (error(phidgetTypeProductID(error(phidgetType(_device))))); } *************** *** 57,61 **** { //if (_device->attached==1) ! if (phidgetAttached(_device) == 1) return (true); --- 58,62 ---- { //if (_device->attached==1) ! if (error(phidgetAttached(_device)) == 1) return (true); Index: CPhidgetManager.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CPhidgetManager.cc 12 Sep 2002 00:24:29 -0000 1.4 --- CPhidgetManager.cc 14 Sep 2002 01:51:31 -0000 1.5 *************** *** 13,16 **** --- 13,17 ---- #include "CPhidget.h" #include <phidget.h> + #include "helper.h" #include <set> *************** *** 69,73 **** CPhidgetManager::CPhidgetManager () { ! phidgetInit(1); /* --- 70,74 ---- CPhidgetManager::CPhidgetManager () { ! error(phidgetInit(1)); /* *************** *** 99,103 **** */ ! phidgetDeinit(); } --- 100,104 ---- */ ! error(phidgetDeinit()); } *************** *** 109,113 **** if (tp == LP_ALL || tp == LP_PHIDGET || tp == LP_SERVO_CONTROLLER || tp == LP_INTERFACE_KIT) { int phidget_count; ! struct phidget **phidgets = phidgetGetPhidgets(&phidget_count); --- 110,114 ---- 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)); *************** *** 117,124 **** (tp == LP_ALL) || (tp == LP_SERVO_CONTROLLER ! && phidgetTypeDeviceClass(phidgetType(phidgets[t])) == LP_SERVO_CONTROLLER) || (tp == LP_INTERFACE_KIT ! && phidgetTypeDeviceClass(phidgetType(phidgets[t])) == LP_INTERFACE_KIT)) { ! CUID temp_uid(phidgetSerial(phidgets[t])); devices.insert(temp_uid); --- 118,125 ---- (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); *************** *** 147,156 **** int phidget_count; ! struct phidget **phidgets = phidgetGetPhidgets(&phidget_count); for (int t = 0; t < phidget_count; t++) { // We open this device ! if (phidgetSerial(phidgets[t]) == uid.serial()) { ! return (phidgetOpen(phidgets[t])); } } --- 148,157 ---- int phidget_count; ! struct phidget **phidgets = error(phidgetGetPhidgets(&phidget_count)); for (int t = 0; t < phidget_count; t++) { // We open this device ! if (error(phidgetSerial(phidgets[t])) == uid.serial()) { ! return (error(phidgetOpen(phidgets[t]))); } } *************** *** 173,177 **** bool CPhidgetManager::checkForEvents() { ! bool found = (phidgetEvents() == 1); // Get the list of phidgets --- 174,178 ---- bool CPhidgetManager::checkForEvents() { ! bool found = (error(phidgetEvents()) == 1); // Get the list of phidgets Index: CServoController.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServoController.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CServoController.cc 12 Sep 2002 00:24:29 -0000 1.4 --- CServoController.cc 14 Sep 2002 01:51:31 -0000 1.5 *************** *** 13,16 **** --- 13,17 ---- #include <stdexcept> #include <phidget.h> + #include "helper.h" CServoController::CServoController (const CUID &uid):CPhidget (uid), _servoCount(-1), *************** *** 202,206 **** p4 = _servos[3].second->position(); ! phidgetQuadServo(device(), p1, p2, p3, p4); } } --- 203,207 ---- p4 = _servos[3].second->position(); ! error(phidgetQuadServo(device(), p1, p2, p3, p4)); } } |
From: Jack S. <js...@us...> - 2002-09-14 01:25:19
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory usw-pr-cvs1:/tmp/cvs-serv9040 Modified Files: phidget_c.c Log Message: Added better error checks Index: phidget_c.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_c.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** phidget_c.c 12 Sep 2002 00:24:29 -0000 1.3 --- phidget_c.c 14 Sep 2002 01:25:16 -0000 1.4 *************** *** 17,82 **** * Simply goes thru all phidgets, looking for servos and then moving them slowly. */ ! int ! main(int argn, char *argv[]) { ! int t, count; ! struct phidget **phidgets; ! printf("----------------------------------------\n"); ! printf("Phidgets Device driver test.\n\n\n"); ! // Initialize libphiget, here is where the devices are actually retrieved by the library ! // We want the library to handle signals (passing it 1) ! phidgetInit(1); ! // Get an array of pointers to phidgets and a count of available phidgets ! phidgets = phidgetGetPhidgets(&count); ! printf("Device count:%d\n", count); ! for (t = 0; t < count; t++) { ! unsigned char buffer[6]; ! float k; ! struct phidget *dev = phidgetOpen(phidgets[t]); // Open the phidget #t ! // Make sure we opened it successfully ! if (dev == NULL) { ! printf("Can't open phidget:%s\n", phidgetErrorString(phidgetLastError())); ! exit(0); ! } ! // Print out some information about this phidget ! printf ! ("Phidget Name:%s Vendor:0x0%x Product:0x0%x Serial#:%06d\n", ! phidgetTypeName(phidgetType(dev)), ! phidgetTypeVendorID(phidgetType(dev)), phidgetTypeProductID(phidgetType(dev)), phidgetSerial(dev)); ! // Is it a servo controller ! if (phidgetTypeDeviceClass(phidgetType(dev)) == LP_SERVO_CONTROLLER) { ! for (k = 0; k < 1; k += .1) { ! int i; ! // Move a single servo (will move servo 0 of a 1 or 4 servo controller) ! phidgetSingleServo(dev, k); - // Wait a bit - sleep(1); ! // Process any events that have occured, like attach/detach ! phidgetEvents(); ! } ! } ! // Close the phidget ! phidgetClose(dev); ! printf("Finished\n"); ! } ! // done using all phidgets, free's phidget memory ! phidgetDeinit(); - printf("----------------------------------------\n"); ! return (0); } --- 17,111 ---- * Simply goes thru all phidgets, looking for servos and then moving them slowly. */ ! int main (int argn, char *argv[]) { ! int t, count; ! struct phidget **phidgets; ! printf ("----------------------------------------\n"); ! printf ("Phidgets Device driver test.\n\n\n"); ! // Initialize libphiget, here is where the devices are actually retrieved by the library ! // We want the library to handle signals (passing it 1) ! if (phidgetInit (1) != LPE_NONE) ! { ! printf("error - %s\n",phidgetErrorString(phidgetLastError())); ! return(1); ! } ! // Get an array of pointers to phidgets and a count of available phidgets ! phidgets = phidgetGetPhidgets (&count); ! if (phidgets==NULL) ! { ! printf("error - %s\n",phidgetErrorString(phidgetLastError())); ! return(2); ! } ! printf ("Device count:%d\n", count); ! for (t = 0; t < count; t++) ! { ! unsigned char buffer[6]; ! float k; ! struct phidget *dev = phidgetOpen (phidgets[t]); // Open the phidget #t ! // Make sure we opened it successfully ! if (dev==NULL) ! { ! printf("error - %s\n",phidgetErrorString(phidgetLastError())); ! return(3); ! } ! // Print out some information about this phidget ! printf ("Phidget Name:%s Vendor:0x0%x Product:0x0%x Serial#:%06d\n", ! phidgetTypeName (phidgetType (dev)), ! phidgetTypeVendorID (phidgetType (dev)), ! phidgetTypeProductID (phidgetType (dev)), phidgetSerial (dev)); ! if (phidgetLastError()!=LPE_NONE) ! { ! printf("error - %s\n",phidgetErrorString(phidgetLastError())); ! return(4); ! } ! // Is it a servo controller ! if (phidgetTypeDeviceClass (phidgetType (dev)) == LP_SERVO_CONTROLLER) ! { ! for (k = 0; k < 1; k += .1) ! { ! int i; ! ! // Move a single servo (will move servo 0 of a 1 or 4 servo controller) ! if (phidgetSingleServo (dev, k)!=LPE_NONE) ! { ! printf("error - %s\n",phidgetErrorString(phidgetLastError())); ! return(5); ! } ! // Wait a bit ! sleep (1); ! // Process any events that have occured, like attach/detach ! phidgetEvents (); ! } ! } ! ! // Close the phidget ! if (phidgetClose (dev)!=LPE_NONE) ! { ! printf("error - %s\n",phidgetErrorString(phidgetLastError())); ! return(6); ! } + printf ("Finished\n"); ! } ! // done using all phidgets, free's phidget memory ! phidgetDeinit (); ! ! printf ("----------------------------------------\n"); ! ! return (0); } |
From: Jack S. <js...@us...> - 2002-09-14 01:24:43
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory usw-pr-cvs1:/tmp/cvs-serv8917 Modified Files: phidget.c Log Message: Fixed error check code Index: phidget.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** phidget.c 12 Sep 2002 02:35:15 -0000 1.6 --- phidget.c 14 Sep 2002 01:24:39 -0000 1.7 *************** *** 300,306 **** * When it is reatached we will search this list to see if it matches this device. */ ! void _addDevice(struct usb_device *device, struct phidget_type *ptd) { struct phidget *temp = malloc(sizeof(struct phidget)); --- 300,307 ---- * 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)); *************** *** 320,329 **** * then we close it. Serial must first be -1 */ ! phidgetOpen(temp); ! phidgetClose(temp); _usbDeviceList[_phidgetDeviceCount] = temp; _phidgetDeviceCount++; } --- 321,337 ---- * then we close it. Serial must first be -1 */ ! ! if (phidgetOpen(temp)==NULL) ! return(_error(phidgetLastError())); ! ! err=phidgetClose(temp); ! if (err!=LPE_NONE) ! return(_error(err)); _usbDeviceList[_phidgetDeviceCount] = temp; _phidgetDeviceCount++; + + return(LPE_NONE); } *************** *** 332,336 **** * only be called once during initialization. */ ! void _findPhidgets() { --- 340,344 ---- * only be called once during initialization. */ ! enum ELPError _findPhidgets() { *************** *** 353,359 **** dev->descriptor.idProduct); if (pdt != NULL) ! _addDevice(dev, pdt); } } } --- 361,375 ---- dev->descriptor.idProduct); if (pdt != NULL) ! { ! enum ELPError err; ! ! err=_addDevice(dev, pdt); ! ! if (err!=LPE_NONE) return(_error(err)); ! } } } + + return(LPE_NONE); } *************** *** 466,472 **** ! int phidgetInit(int catch_signals) { DBG("phidgetInit"); --- 482,490 ---- ! enum ELPError phidgetInit(int catch_signals) { + enum ELPError err; + DBG("phidgetInit"); *************** *** 492,496 **** _libPhidgetInitialized = 1; ! _findPhidgets(); --- 510,516 ---- _libPhidgetInitialized = 1; ! err=_findPhidgets(); ! if (err!=LPE_NONE) ! return(_error(err)); *************** *** 571,576 **** } ! struct phidget * ! phidgetOpen(struct phidget *phidgetDevice) { int ret; --- 591,595 ---- } ! struct phidget * phidgetOpen(struct phidget *phidgetDevice) { int ret; *************** *** 671,719 **** } ! enum ELPError ! phidgetClose(struct phidget *phidgetDevice) { ! DBG("phidgetClose"); ! if (_libPhidgetInitialized == 0) ! return (_error(LPE_NOT_INITIALIZED)); ! if (phidgetDevice == NULL) ! return (_error(LPE_INVALID_PHIDGET)); ! ! if (phidgetDevice->attached == 0) { ! if (phidgetDevice->openedState == WAS_OPENED) { ! phidgetDevice->openedState = WAS_CLOSED; ! return; ! } ! ! phidgetDevice->openedState = WAS_ERROR; ! return (_error(LPE_PHIDGET_ALREADY_CLOSED)); ! } ! if (phidgetDevice->handle) { ! if (phidgetDevice->type->deviceClass == LP_SERVO_CONTROLLER) { ! if (phidgetDevice->defaultData == NULL) { ! // Turn the servo's off ! char buffer[6] = { 0, 0, 0, 0, 0, 0 }; ! phidgetWrite(phidgetDevice, buffer, 6); ! } else { ! phidgetWrite(phidgetDevice, phidgetDevice->defaultData, phidgetDevice->defaultDataSize); ! } } ! usb_release_interface(phidgetDevice->handle, 0); ! usb_close(phidgetDevice->handle); ! phidgetDevice->handle = NULL; ! phidgetDevice->openedState = WAS_CLOSED; ! } else { ! phidgetDevice->openedState = WAS_ERROR; ! return (_error(LPE_PHIDGET_NOT_OPENED)); ! } ! return (_error(LPE_NONE)); } --- 690,749 ---- } ! enum ELPError phidgetClose(struct phidget *phidgetDevice) { ! DBG("phidgetClose"); + if (_libPhidgetInitialized == 0) + return (_error(LPE_NOT_INITIALIZED)); ! if (phidgetDevice == NULL) ! return (_error(LPE_INVALID_PHIDGET)); ! if (phidgetDevice->attached == 0) ! { ! if (phidgetDevice->openedState == WAS_OPENED) ! { ! phidgetDevice->openedState = WAS_CLOSED; ! return(_error(LPE_NONE)); ! } + phidgetDevice->openedState = WAS_ERROR; + return (_error(LPE_PHIDGET_ALREADY_CLOSED)); } ! if (phidgetDevice->handle) ! { ! if (phidgetDevice->type->deviceClass == LP_SERVO_CONTROLLER) ! { ! if (phidgetDevice->defaultData == NULL) ! { ! // Turn the servo's off ! 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)); ! } ! } + usb_release_interface(phidgetDevice->handle, 0); + usb_close(phidgetDevice->handle); + phidgetDevice->handle = NULL; + phidgetDevice->openedState = WAS_CLOSED; + } else + { + phidgetDevice->openedState = WAS_ERROR; + return (_error(LPE_PHIDGET_NOT_OPENED)); + } + + return (_error(LPE_NONE)); } *************** *** 731,735 **** return (_error(LPE_PHIDGET_NOT_OPENED)); ! if (usb_control_msg(phidgetDevice->handle, 0x21, 0x09, 0x200, 0, buffer, size, 5000) != 0) return (_error(LPE_CONTROL_MSG_ERROR)); return (_error(LPE_NONE)); --- 761,765 ---- 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)); |
From: Vadim T. <vt...@us...> - 2002-09-12 08:27:58
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory usw-pr-cvs1:/tmp/cvs-serv31645/src/examples Modified Files: .cvsignore Log Message: Added the binary name to reduce clutter Index: .cvsignore =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/.cvsignore,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** .cvsignore 7 Sep 2002 21:56:54 -0000 1.1 --- .cvsignore 12 Sep 2002 08:27:55 -0000 1.2 *************** *** 5,6 **** --- 5,7 ---- phidget_c phidget_cpp + servo_example |
From: Jack S. <js...@us...> - 2002-09-12 03:19:51
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory usw-pr-cvs1:/tmp/cvs-serv14596 Modified Files: servo_example.cc Log Message: One more example Index: servo_example.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/servo_example.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** servo_example.cc 12 Sep 2002 03:02:22 -0000 1.3 --- servo_example.cc 12 Sep 2002 03:19:48 -0000 1.4 *************** *** 88,91 **** --- 88,133 ---- } + /** + * A derived class that is a servo + */ + void example3() + { + class CMyServo : public CServo + { + public: + CMyServo(const CUID &uid) : + CServo(uid) + { + printf(" CMyServo: constructed\n"); + } + ~CMyServo() + { + printf(" CMyServo: destructor\n"); + } + void position(float f) + { + CServo::position(f); + printf(" CMyServo: position(%f)\n",f); + } + }; + + printf("example 3 - Bit more complex, construct our own derived servo\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"); + CMyServo servo(CUID(servoPhidgetID.serial(),0)); + + printf(" Center it.\n"); + servo.position(.5); + + printf(" Wait for it to move before we destroy the servo object (and thus by default disable the servo).\n"); + sleep(1); + } + + cleanup(); + }; + /** *************** *** 109,112 **** --- 151,155 ---- example1(); example2(); + example3(); } catch(const exception &e) |
From: Jack S. <js...@us...> - 2002-09-12 03:02:25
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory usw-pr-cvs1:/tmp/cvs-serv9737 Modified Files: servo_example.cc Log Message: Added second example Index: servo_example.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/servo_example.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** servo_example.cc 12 Sep 2002 02:06:44 -0000 1.2 --- servo_example.cc 12 Sep 2002 03:02:22 -0000 1.3 *************** *** 1,4 **** --- 1,5 ---- #include <CPhidgetManager.h> #include <CServo.h> + #include <CServoController.h> #include <unistd.h> *************** *** 13,16 **** --- 14,18 ---- void cleanup() { + printf("cleanup\n"); CPhidgetManager::release(); } *************** *** 39,50 **** void example1() { ! // Request servo #0 from the servo controller we previously found ! CServo servo(CUID(servoPhidgetID.serial(),0)); ! // Center it ! servo.position(.5); ! // Wait for it to move ! sleep(1); cleanup(); --- 41,87 ---- void example1() { ! printf("example 1 - Easy way to control a servo\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"); ! CServo servo(CUID(servoPhidgetID.serial(),0)); ! printf(" Center it.\n"); ! servo.position(.5); ! ! printf(" Wait for it to move before we destroy the servo object (and thus by default disable the servo).\n"); ! sleep(1); ! } ! ! cleanup(); ! } ! ! /** ! * The easiest way to use a servo controller ! */ ! void example2() ! { ! printf("example 2 - Easy way to use a 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 controller\n"); ! CServoController servoController(servoPhidgetID); ! ! printf(" Name:%s\n",servoController.name()); ! printf(" Servo Count:%d\n",servoController.servoCount()); ! ! printf(" Randoming 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.\n"); ! sleep(1); ! } cleanup(); *************** *** 71,74 **** --- 108,112 ---- example1(); + example2(); } catch(const exception &e) |
From: Jack S. <js...@us...> - 2002-09-12 03:02:09
|
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory usw-pr-cvs1:/tmp/cvs-serv9595 Modified Files: CServo.cc Log Message: Fixed a bug where a system managed servo couldn't be deleted by the system. Index: CServo.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServo.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CServo.cc 12 Sep 2002 00:24:29 -0000 1.4 --- CServo.cc 12 Sep 2002 03:02:07 -0000 1.5 *************** *** 46,51 **** CServo::~CServo () { ! if (!_systemManaged); ! _controller->unregisterServo(UID()); } --- 46,51 ---- CServo::~CServo () { ! if (!_systemManaged) ! _controller->unregisterServo(UID()); } |
From: Jack S. <js...@us...> - 2002-09-12 02:35:18
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory usw-pr-cvs1:/tmp/cvs-serv3431 Modified Files: phidget.c Log Message: Ok, hope this fixes everything, was having problem because I cut and paste this code out of another example. It didn't read the serial number properly. This uses the length of the serial number to extract the serial number from the string provided by the servo. Index: phidget.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** phidget.c 12 Sep 2002 01:15:22 -0000 1.5 --- phidget.c 12 Sep 2002 02:35:15 -0000 1.6 *************** *** 640,645 **** if (phidgetDevice->serial == -1) { ! char buffer[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; ! char serial[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; int i = 0, j = 0; --- 640,645 ---- if (phidgetDevice->serial == -1) { ! unsigned char buffer[128] = { 0 }; ! unsigned char serial[256] = { 0 }; int i = 0, j = 0; *************** *** 649,660 **** } ! j = 0; ! if (buffer[0] == 12 && buffer[1] == 3) { ! for (i = 0; i <= 10; i++) { ! if (buffer[i + 2] >= 48 && buffer[i + 2] <= 57) { ! serial[j] = buffer[i + 2]; ! j++; ! } ! } } serial[j] = (int) NULL; --- 649,657 ---- } ! j=0; ! for (i=2;i<buffer[0];i+=2) ! { ! serial[j]=buffer[i]; ! j++; } serial[j] = (int) NULL; |
From: Jack S. <js...@us...> - 2002-09-12 02:06:47
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory usw-pr-cvs1:/tmp/cvs-serv29451 Modified Files: servo_example.cc Log Message: First example added Index: servo_example.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/servo_example.cc,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** servo_example.cc 12 Sep 2002 02:02:45 -0000 1.1 --- servo_example.cc 12 Sep 2002 02:06:44 -0000 1.2 *************** *** 1,3 **** --- 1,5 ---- #include <CPhidgetManager.h> + #include <CServo.h> + #include <unistd.h> *************** *** 6,11 **** static const char *revision="$Revision$"; ! /* * Find the first servo controller we can */ --- 8,20 ---- static const char *revision="$Revision$"; + /** + * Releases the phidget manager, makes it look like the program has finished. + */ + void cleanup() + { + CPhidgetManager::release(); + } ! /** * Find the first servo controller we can */ *************** *** 21,24 **** --- 30,52 ---- printf("Servo Controller found: %s\n",servoPhidgetID.asString().c_str()); + + cleanup(); + } + + /** + * The easiest way to control a servo + */ + void example1() + { + // Request servo #0 from the servo controller we previously found + CServo servo(CUID(servoPhidgetID.serial(),0)); + + // Center it + servo.position(.5); + + // Wait for it to move + sleep(1); + + cleanup(); } *************** *** 41,44 **** --- 69,74 ---- findUsableServoPhidget(); + + example1(); } catch(const exception &e) |
From: Jack S. <js...@us...> - 2002-09-12 02:02:48
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory usw-pr-cvs1:/tmp/cvs-serv28438 Modified Files: Makefile.am Added Files: servo_example.cc Log Message: Initial version of servo_example, doesn't do much yet. --- NEW FILE: servo_example.cc --- #include <CPhidgetManager.h> CUID servoPhidgetID; /**< This will store the servo UID we will be working on */ static const char *revision="$Revision: 1.1 $"; /* * Find the first servo controller we can */ void findUsableServoPhidget() { // Look for a servo that we can use for all the examples vector<CUID> temp=CPhidgetManager::getInstance()->query(LP_SERVO_CONTROLLER); if (temp.size()<1) throw runtime_error("This application can't run without a phidget servo controller (see http://www.phidgets.com).\n"); servoPhidgetID=temp[0]; printf("Servo Controller found: %s\n",servoPhidgetID.asString().c_str()); } /** * This program is an example to show the many ways to interface with servos and phidget servo manager */ main() { try { char adjusted_version[64]; memcpy(adjusted_version,revision+11,strlen(revision)-11-2); // What we are printf("servo_example: code examples of how to communicate with servos\n"); // Get the version number printf("Version %s\n",adjusted_version); findUsableServoPhidget(); } catch(const exception &e) { printf("exception:%s\n",e.what()); } } Index: Makefile.am =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/Makefile.am,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile.am 7 Sep 2002 21:56:54 -0000 1.1 --- Makefile.am 12 Sep 2002 02:02:44 -0000 1.2 *************** *** 1,3 **** ! bin_PROGRAMS = phidget_c phidget_cpp phidget_c_SOURCES = phidget_c.c --- 1,3 ---- ! bin_PROGRAMS = phidget_c phidget_cpp servo_example phidget_c_SOURCES = phidget_c.c *************** *** 11,14 **** --- 11,20 ---- phidget_cpp_DEPENDENCIES = ../libphidget/libphidget.la ../phidget++/libphidget++.la + + servo_example_SOURCES = servo_example.cc + + servo_example_LDADD = ../libphidget/libphidget.la ../phidget++/libphidget++.la + servo_example_DEPENDENCIES = ../libphidget/libphidget.la ../phidget++/libphidget++.la + CFLAGS = -I../libphidget -L../libphidget CXXFLAGS = -I../libphidget -I../phidget++ -L../libphidget -L../phidget++ *************** *** 30,32 **** @ @ECHO@ "*** Documentation is not created - install Doxygen" endif ! \ No newline at end of file --- 36,38 ---- @ @ECHO@ "*** Documentation is not created - install Doxygen" endif ! |
From: Vadim T. <vt...@us...> - 2002-09-12 01:32:10
|
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory usw-pr-cvs1:/tmp/cvs-serv20619/src/phidget++ Modified Files: Makefile.am Log Message: Doxygen documentation will not be created on 'make all' run anymore. To create the documentation, run 'make docs'. Index: Makefile.am =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/Makefile.am,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Makefile.am 9 Sep 2002 08:48:33 -0000 1.4 --- Makefile.am 12 Sep 2002 01:32:07 -0000 1.5 *************** *** 41,50 **** if DOXYGEN_ENABLED ! all-local: @DOXYGEN@ else ! all-local: @ @ECHO@ "*** Documentation is not created - install Doxygen" --- 41,50 ---- if DOXYGEN_ENABLED ! docs: @DOXYGEN@ else ! docs: @ @ECHO@ "*** Documentation is not created - install Doxygen" |
From: Vadim T. <vt...@us...> - 2002-09-12 01:32:09
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory usw-pr-cvs1:/tmp/cvs-serv20619/src/libphidget Modified Files: Makefile.am Log Message: Doxygen documentation will not be created on 'make all' run anymore. To create the documentation, run 'make docs'. Index: Makefile.am =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Makefile.am 9 Sep 2002 08:48:33 -0000 1.3 --- Makefile.am 12 Sep 2002 01:32:07 -0000 1.4 *************** *** 12,21 **** if DOXYGEN_ENABLED ! all-local: @DOXYGEN@ else ! all-local: @ @ECHO@ "*** Documentation is not created - install Doxygen" --- 12,21 ---- if DOXYGEN_ENABLED ! docs: @DOXYGEN@ else ! docs: @ @ECHO@ "*** Documentation is not created - install Doxygen" |
From: Vadim T. <vt...@us...> - 2002-09-12 01:32:09
|
Update of /cvsroot/libphidget/libphidget In directory usw-pr-cvs1:/tmp/cvs-serv20619 Modified Files: Makefile.am Log Message: Doxygen documentation will not be created on 'make all' run anymore. To create the documentation, run 'make docs'. Index: Makefile.am =================================================================== RCS file: /cvsroot/libphidget/libphidget/Makefile.am,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Makefile.am 12 Sep 2002 00:24:28 -0000 1.7 --- Makefile.am 12 Sep 2002 01:32:07 -0000 1.8 *************** *** 66,67 **** --- 66,72 ---- @LN_S@ -f `pwd`/@PACKAGE@-@VERSION@.tar.gz /usr/src/redhat/SOURCES/@PACKAGE@-@VERSION@.tar.gz cd /usr/src/redhat/SPECS && @RPM@ -ba @PACKAGE@.spec + + docs: + + cd ./src/libphidget && ${MAKE} docs + cd ./src/phidget++ && ${MAKE} docs |
From: Jack S. <js...@us...> - 2002-09-12 01:31:21
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory usw-pr-cvs1:/tmp/cvs-serv20368 Modified Files: phidget_cpp.cc Log Message: Properly prints out the current version number of the example Index: phidget_cpp.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_cpp.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** phidget_cpp.cc 12 Sep 2002 00:24:29 -0000 1.3 --- phidget_cpp.cc 12 Sep 2002 01:31:18 -0000 1.4 *************** *** 17,20 **** --- 17,22 ---- CUID workingUID; + static const char *revision="$Revision$"; + /* class CMyServoController : public CServoController *************** *** 375,381 **** { try { // What we are printf("phidgets: a command line interface utility\n"); ! printf("version $Revision$\n\n"); // No arguments --- 377,388 ---- { try { + char adjusted_version[64]; + memcpy(adjusted_version,revision+11,strlen(revision)-11-2); + // What we are printf("phidgets: a command line interface utility\n"); ! ! // Get the version number ! printf("Version %s\n",adjusted_version); // No arguments |
From: Jack S. <js...@us...> - 2002-09-12 01:15:25
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory usw-pr-cvs1:/tmp/cvs-serv17077/libphidget Modified Files: phidget.c Log Message: Fixed a buffer initialization error Index: phidget.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** phidget.c 12 Sep 2002 00:24:29 -0000 1.4 --- phidget.c 12 Sep 2002 01:15:22 -0000 1.5 *************** *** 640,645 **** if (phidgetDevice->serial == -1) { ! char buffer[16] = { 0 }; ! char serial[16] = { 0 }; int i = 0, j = 0; --- 640,645 ---- if (phidgetDevice->serial == -1) { ! char buffer[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; ! char serial[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; int i = 0, j = 0; |
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory usw-pr-cvs1:/tmp/cvs-serv4358/src/phidget++ Modified Files: CAnalogIn.cc CAnalogIn.h CDigitalIn.cc CDigitalIn.h CDigitalOut.cc CDigitalOut.h CInterfaceKit.cc CInterfaceKit.h CPhidget.cc CPhidget.h CPhidgetManager.cc CPhidgetManager.h CServo.cc CServo.h CServoController.cc CServoController.h CUID.cc CUID.h CUniqueDevice.cc CUniqueDevice.h TSingleton.h lsphidget.cc Log Message: Merged back the results of INDENT branch changes Index: CAnalogIn.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CAnalogIn.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CAnalogIn.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CAnalogIn.cc 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 11,17 **** #include "CInterfaceKit.h" ! CAnalogIn::CAnalogIn (CInterfaceKit * interfacekit, int id): ! CUniqueDevice (interfacekit, id), ! _interfaceKit (interfacekit), _value (0), _lastValue (0) { } --- 11,17 ---- #include "CInterfaceKit.h" ! CAnalogIn::CAnalogIn (CInterfaceKit *interfacekit, int id):CUniqueDevice (interfacekit, id), ! _interfaceKit(interfacekit), _value(0), ! _lastValue(0) { } Index: CAnalogIn.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CAnalogIn.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CAnalogIn.h 8 Sep 2002 18:59:54 -0000 1.3 --- CAnalogIn.h 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 24,61 **** class CAnalogIn:CUniqueDevice { ! private: ! friend class CInterfaceKit; ! CInterfaceKit *_interfaceKit; ! // This is the only real data for the servo ! float _value; ! float _lastValue; ! CAnalogIn (CInterfaceKit * interfacekit, int id); ! public: /** * Empty virtual constructor */ ! virtual ~ CAnalogIn () ! { ! } /** * Return the current value of the analog input, this * value is only updates when CPhidgetManager->checkForEvents() * is called. ! */ float value () const ! { ! return (_value); ! } /** * No devices are contained in this device ! */ CAnalogIn *find (const CUID & uid) ! { ! return (NULL); ! } }; --- 24,61 ---- class CAnalogIn:CUniqueDevice { ! private: ! friend class CInterfaceKit; ! CInterfaceKit *_interfaceKit; ! // This is the only real data for the servo ! float _value; ! float _lastValue; ! CAnalogIn (CInterfaceKit *interfacekit, int id); ! public: /** * Empty virtual constructor */ ! virtual ~ CAnalogIn () ! { ! } /** * Return the current value of the analog input, this * value is only updates when CPhidgetManager->checkForEvents() * is called. ! */ float value() const ! { ! return (_value); ! } /** * No devices are contained in this device ! */ CAnalogIn *find(const CUID &uid) ! { ! return (NULL); ! } }; Index: CDigitalIn.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CDigitalIn.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CDigitalIn.cc 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 11,16 **** #include "CInterfaceKit.h" ! CDigitalIn::CDigitalIn (CInterfaceKit * interfacekit, int id): ! CUniqueDevice (interfacekit, id), _value (false), _lastValue (false) { } --- 11,16 ---- #include "CInterfaceKit.h" ! CDigitalIn::CDigitalIn (CInterfaceKit *interfacekit, int id):CUniqueDevice (interfacekit, id), _value(false), ! _lastValue(false) { } Index: CDigitalIn.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CDigitalIn.h 8 Sep 2002 18:59:54 -0000 1.3 --- CDigitalIn.h 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 24,58 **** class CDigitalIn:public CUniqueDevice { ! private: ! friend class CInterfaceKit; ! // This is the only real data for the servo ! bool _value; ! bool _lastValue; ! CDigitalIn (CInterfaceKit * interfacekit, int id); ! public: /** * Standard virtual destructor */ ! virtual ~ CDigitalIn () ! { ! } /** * Return the current value of the digital input, this * value is only updates when CPhidgetManager->checkForEvents() * is called. ! */ bool value () const ! { ! return (_value); ! } /** * No devices are contained in this device ! */ CDigitalIn *find (const CUID & uid) ! { ! return (NULL); ! } }; --- 24,58 ---- class CDigitalIn:public CUniqueDevice { ! private: ! friend class CInterfaceKit; ! // This is the only real data for the servo ! bool _value; ! bool _lastValue; ! CDigitalIn (CInterfaceKit *interfacekit, int id); ! public: /** * Standard virtual destructor */ ! virtual ~ CDigitalIn () ! { ! } /** * Return the current value of the digital input, this * value is only updates when CPhidgetManager->checkForEvents() * is called. ! */ bool value() const ! { ! return (_value); ! } /** * No devices are contained in this device ! */ CDigitalIn *find(const CUID &uid) ! { ! return (NULL); ! } }; Index: CDigitalOut.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalOut.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CDigitalOut.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CDigitalOut.cc 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 11,30 **** #include "CInterfaceKit.h" ! CDigitalOut::CDigitalOut (CInterfaceKit * interfacekit, int id): ! CUniqueDevice (interfacekit, id), _value (false) { } ! void ! CDigitalOut::value (bool val) { ! _value = val; ! // Tell the interface kit our value has changed, so it ! // sends it to the servo immediately ! CUniqueDevice *temp1 = parent (); ! CInterfaceKit *temp2 = dynamic_cast < CInterfaceKit * >(temp1); ! temp2->update (); } --- 11,29 ---- #include "CInterfaceKit.h" ! CDigitalOut::CDigitalOut (CInterfaceKit *interfacekit, int id):CUniqueDevice (interfacekit, id), ! _value(false) { } ! void CDigitalOut::value(bool val) { ! _value = val; ! // Tell the interface kit our value has changed, so it ! // sends it to the servo immediately ! CUniqueDevice *temp1 = parent(); ! CInterfaceKit *temp2 = dynamic_cast < CInterfaceKit *>(temp1); ! temp2->update(); } Index: CDigitalOut.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalOut.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CDigitalOut.h 8 Sep 2002 18:59:54 -0000 1.3 --- CDigitalOut.h 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 24,56 **** class CDigitalOut:CUniqueDevice { ! private: ! friend class CInterfaceKit; ! CInterfaceKit *_interfaceKit; ! // This is the only real data for the servo ! bool _value; ! CDigitalOut (CInterfaceKit * interfacekit, int id); ! public: /** * Standard empty virtual destructor */ ! virtual ~ CDigitalOut () ! { ! } /** * Sends a value to the interface kit ! */ void value (bool val); /** * No devices are contained in this device */ ! CDigitalOut *find (const CUID & uid) ! { ! return (NULL); ! } }; --- 24,56 ---- class CDigitalOut:CUniqueDevice { ! private: ! friend class CInterfaceKit; ! CInterfaceKit *_interfaceKit; ! // This is the only real data for the servo ! bool _value; ! CDigitalOut (CInterfaceKit *interfacekit, int id); ! public: /** * Standard empty virtual destructor */ ! virtual ~ CDigitalOut () ! { ! } /** * Sends a value to the interface kit ! */ void value(bool val); /** * No devices are contained in this device */ ! CDigitalOut *find(const CUID &uid) ! { ! return (NULL); ! } }; Index: CInterfaceKit.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CInterfaceKit.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CInterfaceKit.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CInterfaceKit.cc 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 16,144 **** #include <phidget.h> ! CInterfaceKit::CInterfaceKit (phidget * device): ! CPhidget (device) { ! if (classType () != INTERFACE_KIT) ! throw ! runtime_error ! ("Can't initialize a CInterfaceKit with a phidget that is not an interface kit"); ! switch (productID ()) ! { default: ! { ! char temp[128]; ! sprintf (temp, ! "Unknown type of interface kit Vendor ID:0x0%x Product ID:0x0%x\n", ! vendorID (), productID ()); ! throw runtime_error (temp); ! } } } ! void ! CInterfaceKit::setDigitalInCount (int num) { ! if (_digitalIns.size () != 0) ! throw runtime_error ("You can only call this function once"); ! for (int t = 0; t < num; t++) ! _digitalIns.push_back (new CDigitalIn (this, t)); } ! void ! CInterfaceKit::setDigitalOutCount (int num) { ! if (_digitalOuts.size () != 0) ! throw runtime_error ("You can only call this function once"); ! for (int t = 0; t < num; t++) ! _digitalOuts.push_back (new CDigitalOut (this, t)); } ! void ! CInterfaceKit::setAnalogInCount (int num) { ! if (_analogIns.size () != 0) ! throw runtime_error ("You can only call this function once"); ! for (int t = 0; t < num; t++) ! _analogIns.push_back (new CAnalogIn (this, t)); } ! CInterfaceKit::CInterfaceKit (CInterfaceKit * orig): ! CPhidget (orig) { ! for (int t = 0; t < orig->_digitalIns.size (); t++) ! _digitalIns.push_back (new CDigitalIn (this, t)); ! for (int t = 0; t < orig->_digitalOuts.size (); t++) ! _digitalOuts.push_back (new CDigitalOut (this, t)); ! for (int t = 0; t < orig->_analogIns.size (); t++) ! _analogIns.push_back (new CAnalogIn (this, t)); } CInterfaceKit::~CInterfaceKit () { ! for (int t = 0; t < _digitalIns.size (); t++) ! delete _digitalIns[t]; ! for (int t = 0; t < _digitalOuts.size (); t++) ! delete _digitalOuts[t]; ! for (int t = 0; t < _analogIns.size (); t++) ! delete _analogIns[t]; } ! void ! CInterfaceKit::update () { ! // Do nothing, we can't test this yet } ! const vector < CDigitalIn * >& ! CInterfaceKit::digitalIns () const { ! return (_digitalIns); } ! const vector < CDigitalOut * >& ! CInterfaceKit::digitalOuts () const { ! return (_digitalOuts); } ! const vector < CAnalogIn * >& ! CInterfaceKit::analogIns () const { ! return (_analogIns); } ! CUniqueDevice * ! CInterfaceKit::find (const CUID & uid) { ! CUniqueDevice *temp; ! for (int t = 0; t < _digitalIns.size (); t++) ! { ! temp = _digitalIns[t]->find (uid); ! if (temp != NULL) ! return (temp); } ! for (int t = 0; t < _digitalOuts.size (); t++) ! { ! temp = _digitalOuts[t]->find (uid); ! if (temp != NULL) ! return (temp); } ! for (int t = 0; t < _analogIns.size (); t++) ! { ! temp = _analogIns[t]->find (uid); ! if (temp != NULL) ! return (temp); } ! return (NULL); } --- 16,126 ---- #include <phidget.h> ! CInterfaceKit::CInterfaceKit (phidget *device):CPhidget (device) { ! if (classType() != INTERFACE_KIT) ! throw runtime_error("Can't initialize a CInterfaceKit with a phidget that is not an interface kit"); ! switch (productID()) { default: ! { ! char temp[128]; ! sprintf(temp, "Unknown type of interface kit Vendor ID:0x0%x Product ID:0x0%x\n", vendorID(), productID()); ! throw runtime_error(temp); ! } } } ! void CInterfaceKit::setDigitalInCount(int num) { ! if (_digitalIns.size() != 0) ! throw runtime_error("You can only call this function once"); ! for (int t = 0; t < num; t++) ! _digitalIns.push_back(new CDigitalIn (this, t)); } ! void CInterfaceKit::setDigitalOutCount(int num) { ! if (_digitalOuts.size() != 0) ! throw runtime_error("You can only call this function once"); ! for (int t = 0; t < num; t++) ! _digitalOuts.push_back(new CDigitalOut (this, t)); } ! void CInterfaceKit::setAnalogInCount(int num) { ! if (_analogIns.size() != 0) ! throw runtime_error("You can only call this function once"); ! for (int t = 0; t < num; t++) ! _analogIns.push_back(new CAnalogIn (this, t)); } ! CInterfaceKit::CInterfaceKit (CInterfaceKit *orig):CPhidget (orig) { ! for (int t = 0; t < orig->_digitalIns.size(); t++) ! _digitalIns.push_back(new CDigitalIn (this, t)); ! for (int t = 0; t < orig->_digitalOuts.size(); t++) ! _digitalOuts.push_back(new CDigitalOut (this, t)); ! for (int t = 0; t < orig->_analogIns.size(); t++) ! _analogIns.push_back(new CAnalogIn (this, t)); } CInterfaceKit::~CInterfaceKit () { ! for (int t = 0; t < _digitalIns.size(); t++) ! delete _digitalIns[t]; ! for (int t = 0; t < _digitalOuts.size(); t++) ! delete _digitalOuts[t]; ! for (int t = 0; t < _analogIns.size(); t++) ! delete _analogIns[t]; } ! void CInterfaceKit::update() { ! // Do nothing, we can't test this yet } ! const vector <CDigitalIn *>&CInterfaceKit::digitalIns() const { ! return (_digitalIns); } ! const vector <CDigitalOut *>&CInterfaceKit::digitalOuts() const { ! return (_digitalOuts); } ! const vector <CAnalogIn *>&CInterfaceKit::analogIns() const { ! return (_analogIns); } ! CUniqueDevice *CInterfaceKit::find(const CUID &uid) { ! CUniqueDevice *temp; ! for (int t = 0; t < _digitalIns.size(); t++) { ! temp = _digitalIns[t]->find(uid); ! if (temp != NULL) ! return (temp); } ! for (int t = 0; t < _digitalOuts.size(); t++) { ! temp = _digitalOuts[t]->find(uid); ! if (temp != NULL) ! return (temp); } ! for (int t = 0; t < _analogIns.size(); t++) { ! temp = _analogIns[t]->find(uid); ! if (temp != NULL) ! return (temp); } ! return (NULL); } Index: CInterfaceKit.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CInterfaceKit.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CInterfaceKit.h 8 Sep 2002 18:59:54 -0000 1.3 --- CInterfaceKit.h 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 26,43 **** class CInterfaceKit:public CPhidget { ! private: ! friend class CPhidgetManager; ! vector < CDigitalIn * >_digitalIns; ! vector < CDigitalOut * >_digitalOuts; ! vector < CAnalogIn * >_analogIns; ! void setDigitalInCount (int num); ! void setDigitalOutCount (int num); ! void setAnalogInCount (int num); ! CInterfaceKit (phidget * device); ! public: /** * Constructor to be used when a user derives from this phidget, the user must --- 26,43 ---- class CInterfaceKit:public CPhidget { ! private: ! friend class CPhidgetManager; ! vector <CDigitalIn *>_digitalIns; ! vector <CDigitalOut *>_digitalOuts; ! vector <CAnalogIn *>_analogIns; ! void setDigitalInCount(int num); ! void setDigitalOutCount(int num); ! void setAnalogInCount(int num); ! CInterfaceKit (phidget *device); ! public: /** * Constructor to be used when a user derives from this phidget, the user must *************** *** 45,49 **** * pass it to this constructor, in the constructor of his derived type. */ ! CInterfaceKit (CInterfaceKit * orig); /** --- 45,49 ---- * pass it to this constructor, in the constructor of his derived type. */ ! CInterfaceKit (CInterfaceKit *orig); /** *************** *** 51,80 **** * back into the manager and notify it of the current state of the device */ ! virtual ~ CInterfaceKit (); /** * Resends servo information to the controller */ ! void update (); /** * Returns a vector of digital in's that are controlled by this object */ ! const vector < CDigitalIn * >&digitalIns () const; /** * Returns a vector of digital out's that are controlled by this object */ ! const vector < CDigitalOut * >&digitalOuts () const; /** * Returns a vector of analog in's that are controlled by this object */ ! const vector < CAnalogIn * >&analogIns () const; /** * */ ! CUniqueDevice *find (const CUID & uid); }; --- 51,80 ---- * back into the manager and notify it of the current state of the device */ ! virtual ~ CInterfaceKit (); /** * Resends servo information to the controller */ ! void update(); /** * Returns a vector of digital in's that are controlled by this object */ ! const vector <CDigitalIn *>&digitalIns() const; /** * Returns a vector of digital out's that are controlled by this object */ ! const vector <CDigitalOut *>&digitalOuts() const; /** * Returns a vector of analog in's that are controlled by this object */ ! const vector <CAnalogIn *>&analogIns() const; /** * */ ! CUniqueDevice *find(const CUID &uid); }; Index: CPhidget.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidget.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CPhidget.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CPhidget.cc 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 14,91 **** #include <usb.h> ! CPhidget::CPhidget (const CUID & uid): ! CUniqueDevice (uid), ! _device (CPhidgetManager::getInstance ()->getDeviceHandle (uid)) { ! // Ask the phidget manager if we really exist as a device, if not throw an exception ! if (_device == NULL) ! throw runtime_error ("Phidget doesn't exist."); ! _last_wasAttached = phidgetAttached (_device) == 1; } CPhidget::~CPhidget () { ! phidgetClose (_device); } ! int ! CPhidget::classType () { ! //return(_device->type->deviceClass); ! return (phidgetTypeDeviceClass (phidgetType (_device))); } ! const char * ! CPhidget::name () { ! //return(_device->type->name); ! return (phidgetTypeName (phidgetType (_device))); } ! int ! CPhidget::vendorID () { ! //return(_device->type->vendorID); ! return (phidgetTypeVendorID (phidgetType (_device))); } ! int ! CPhidget::productID () { ! //return(_device->type->productID); ! return (phidgetTypeProductID (phidgetType (_device))); } ! bool CPhidget::isAttached () { ! //if (_device->attached==1) ! if (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 () { } --- 14,83 ---- #include <usb.h> ! CPhidget::CPhidget (const CUID &uid):CUniqueDevice (uid), ! _device(CPhidgetManager::getInstance()->getDeviceHandle(uid)) { ! // Ask the phidget manager if we really exist as a device, if not throw an exception ! if (_device == NULL) ! throw runtime_error("Phidget doesn't exist."); ! _last_wasAttached = phidgetAttached(_device) == 1; } CPhidget::~CPhidget () { ! phidgetClose(_device); } ! int CPhidget::classType() { ! //return(_device->type->deviceClass); ! return (phidgetTypeDeviceClass(phidgetType(_device))); } ! const char *CPhidget::name() { ! //return(_device->type->name); ! return (phidgetTypeName(phidgetType(_device))); } ! int CPhidget::vendorID() { ! //return(_device->type->vendorID); ! return (phidgetTypeVendorID(phidgetType(_device))); } ! int CPhidget::productID() { ! //return(_device->type->productID); ! return (phidgetTypeProductID(phidgetType(_device))); } ! bool CPhidget::isAttached() { ! //if (_device->attached==1) ! if (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() { } Index: CPhidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidget.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CPhidget.h 8 Sep 2002 18:59:54 -0000 1.3 --- CPhidget.h 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 22,36 **** class CPhidget:public CUniqueDevice { ! private: ! bool _last_wasAttached; ! //bool _userConstructed; ! //CPhidget *_replace; ! struct phidget *_device; ! // Some friends of phidget ! friend class CServoController; ! friend class CInterfaceKit; /** --- 22,36 ---- class CPhidget:public CUniqueDevice { ! private: ! bool _last_wasAttached; ! //bool _userConstructed; ! //CPhidget *_replace; ! struct phidget *_device; ! // Some friends of phidget ! friend class CServoController; ! friend class CInterfaceKit; /** *************** *** 38,63 **** * derives from CPhidget (ex. CServoController) */ ! CPhidget (phidget * device /*!< The libphidget phidget device handle */ ); ! protected: ! friend class CPhidgetManager; /** * The device that this CPhidget uses */ ! struct phidget *device () ! { ! return (_device); ! } /** * This checks to see if the device status has change. In the case of the base phidget * it checks if it is attached/detached. If a derived phidget overrides this method * it must call the base class method. ! */ virtual void processEvents (); /** * Was this phidget constructed by a user */ ! //bool userConstructed() const {return(_userConstructed);} /** --- 38,63 ---- * derives from CPhidget (ex. CServoController) */ ! CPhidget (phidget *device /*!< The libphidget phidget device handle */ ); ! protected: ! friend class CPhidgetManager; /** * The device that this CPhidget uses */ ! struct phidget *device() ! { ! return (_device); ! } /** * This checks to see if the device status has change. In the case of the base phidget * it checks if it is attached/detached. If a derived phidget overrides this method * it must call the base class method. ! */ virtual void processEvents(); /** * Was this phidget constructed by a user */ ! //bool userConstructed() const {return(_userConstructed);} /** *************** *** 65,89 **** * this will return NULL. */ ! //CPhidget *getReplacement() {return(_replace);} ! public: ! //CPhidget(CPhidget *orig /*!< The \a CPhidget that we are replacing */); //!< Users can create phidgets, but must pass an already available phidget to them. We must be derived from the same type as the phidget that get's passed in. ! CPhidget (const CUID & uid); ! virtual ~ CPhidget (); //!< If it is user constructed, this destructor replaces the original phidget back in the manager ! int classType (); //!< Get the device class as defined in the libphidget documentation. ! const char *name (); //!< Get the device name as defined in the libphidget documentation. ! int vendorID (); //!< Get the vendor ID as defined by the USB standard. ! int productID (); //!< Get the product ID as defined by the USB standard. ! bool isAttached (); //!< Returns if this device is attached or not. ! virtual void onAttach (); //!<This method is called when the device is attached. ! virtual void onDetach (); //!<This method is called when the device is detached. ! virtual void query (const EDeviceClass tp, set < CUID > &devices) ! { ! CUniqueDevice::query (tp, devices); ! if (tp == LP_PHIDGET) ! devices.insert (UID ()); ! } }; --- 65,89 ---- * this will return NULL. */ ! //CPhidget *getReplacement() {return(_replace);} ! public: ! //CPhidget(CPhidget *orig /*!< The \a CPhidget that we are replacing */); //!< Users can create phidgets, but must pass an already available phidget to them. We must be derived from the same type as the phidget that get's passed in. ! CPhidget (const CUID &uid); ! virtual ~ CPhidget (); //!< If it is user constructed, this destructor replaces the original phidget back in the manager ! int classType(); //!< Get the device class as defined in the libphidget documentation. ! const char *name(); //!< Get the device name as defined in the libphidget documentation. ! int vendorID(); //!< Get the vendor ID as defined by the USB standard. ! int productID(); //!< Get the product ID as defined by the USB standard. ! bool isAttached(); //!< Returns if this device is attached or not. ! virtual void onAttach(); //!<This method is called when the device is attached. ! virtual void onDetach(); //!<This method is called when the device is detached. ! virtual void query(const EDeviceClass tp, set < CUID >&devices) ! { ! CUniqueDevice::query(tp, devices); ! if (tp == LP_PHIDGET) ! devices.insert(UID()); ! } }; Index: CPhidgetManager.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CPhidgetManager.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CPhidgetManager.cc 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 15,39 **** #include <set> ! IMPLEMENT_SINGLETON (CPhidgetManager); ! void ! CPhidgetManager::registerDevice (CUniqueDevice * dev) { ! _uniqueDevices.push_back (dev); } ! void ! CPhidgetManager::unregisterDevice (CUniqueDevice * dev) { ! vector < CUniqueDevice * >::iterator i; ! for (i = _uniqueDevices.begin (); i != _uniqueDevices.end (); i++) ! if (*i == dev) ! { ! _uniqueDevices.erase (i, i); ! return; ! } ! throw runtime_error ("Can't unregister a device that wasn't registered."); } --- 15,36 ---- #include <set> ! IMPLEMENT_SINGLETON(CPhidgetManager); ! void CPhidgetManager::registerDevice(CUniqueDevice *dev) { ! _uniqueDevices.push_back(dev); } ! void CPhidgetManager::unregisterDevice(CUniqueDevice *dev) { ! vector <CUniqueDevice *>::iterator i; ! for (i = _uniqueDevices.begin(); i != _uniqueDevices.end(); i++) ! if (*i == dev) { ! _uniqueDevices.erase(i, i); ! return; ! } ! throw runtime_error("Can't unregister a device that wasn't registered."); } *************** *** 72,178 **** CPhidgetManager::CPhidgetManager () { ! phidgetInit (1); ! /* ! // Build classes to handle and open all devices ! 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(); ! */ } CPhidgetManager::~CPhidgetManager () { ! /* ! for (int t=0;t<_phidgets.size();t++) ! { ! if (_phidgets[t]->userConstructed()) ! throw runtime_error("All user constructed phidgets must be deleted before the phidget manager is destroyed."); ! delete _phidgets[t]; ! } ! */ ! phidgetDeinit (); } ! vector < CUID > CPhidgetManager::query (const EDeviceClass tp) { ! set < CUID > devices; ! // 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 = phidgetGetPhidgets (&phidget_count); ! for (int t = 0; t < phidget_count; t++) ! { ! if ( ! (tp == LP_PHIDGET) || ! (tp == LP_ALL) || ! (tp == LP_SERVO_CONTROLLER ! && phidgetTypeDeviceClass (phidgetType (phidgets[t])) == ! LP_SERVO_CONTROLLER) || (tp == LP_INTERFACE_KIT ! && ! phidgetTypeDeviceClass (phidgetType ! (phidgets ! [t])) == ! LP_INTERFACE_KIT)) ! { ! CUID temp_uid (phidgetSerial (phidgets[t])); ! devices.insert (temp_uid); } } } ! // Ask each known device if it knows about any devices that match the type we are searching for ! if (tp == LP_ALL || tp == LP_SERVO || tp == LP_DIGITAL_IN ! || tp == LP_DIGITAL_OUT) ! { ! for (int t = 0; t < _uniqueDevices.size (); t++) ! _uniqueDevices[t]->query (tp, devices); } ! // get a vector of the CUID instead of a set ! vector < CUID > temp; ! for (set < CUID >::iterator i = devices.begin (); i != devices.end (); i++) ! temp.push_back (*i); ! return (temp); } ! struct phidget * ! CPhidgetManager::getDeviceHandle (const CUID & uid) { ! if (uid.id () != -1) ! throw runtime_error ("invalid UID to find phidget. id must be -1"); ! int phidget_count; ! struct phidget **phidgets = phidgetGetPhidgets (&phidget_count); ! for (int t = 0; t < phidget_count; t++) ! { ! // We open this device ! if (phidgetSerial (phidgets[t]) == uid.serial ()) ! { ! return (phidgetOpen (phidgets[t])); } } ! return (NULL); } --- 69,160 ---- CPhidgetManager::CPhidgetManager () { ! phidgetInit(1); ! /* ! // Build classes to handle and open all devices ! 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(); ! */ } CPhidgetManager::~CPhidgetManager () { ! /* ! for (int t=0;t<_phidgets.size();t++) ! { ! if (_phidgets[t]->userConstructed()) ! throw runtime_error("All user constructed phidgets must be deleted before the phidget manager is destroyed."); ! delete _phidgets[t]; ! } ! */ ! phidgetDeinit(); } ! vector <CUID >CPhidgetManager::query(const EDeviceClass tp) { ! set < CUID >devices; ! // 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 = phidgetGetPhidgets(&phidget_count); ! for (int t = 0; t < phidget_count; t++) { ! if ( ! (tp == LP_PHIDGET) || ! (tp == LP_ALL) || ! (tp == LP_SERVO_CONTROLLER ! && phidgetTypeDeviceClass(phidgetType(phidgets[t])) == ! LP_SERVO_CONTROLLER) || (tp == LP_INTERFACE_KIT ! && phidgetTypeDeviceClass(phidgetType(phidgets[t])) == LP_INTERFACE_KIT)) { ! CUID temp_uid(phidgetSerial(phidgets[t])); ! devices.insert(temp_uid); } } } ! // Ask each known device if it knows about any devices that match the type we are searching for ! if (tp == LP_ALL || tp == LP_SERVO || tp == LP_DIGITAL_IN || tp == LP_DIGITAL_OUT) { ! for (int t = 0; t < _uniqueDevices.size(); t++) ! _uniqueDevices[t]->query(tp, devices); } ! // get a vector of the CUID instead of a set ! vector <CUID >temp; ! for (set < CUID >::iterator i = devices.begin(); i != devices.end(); i++) ! temp.push_back(*i); ! return (temp); } ! struct phidget *CPhidgetManager::getDeviceHandle(const CUID &uid) { ! if (uid.id() != -1) ! throw runtime_error("invalid UID to find phidget. id must be -1"); ! int phidget_count; ! struct phidget **phidgets = phidgetGetPhidgets(&phidget_count); ! for (int t = 0; t < phidget_count; t++) { ! // We open this device ! if (phidgetSerial(phidgets[t]) == uid.serial()) { ! return (phidgetOpen(phidgets[t])); } } ! return (NULL); } *************** *** 189,288 **** //} ! bool CPhidgetManager::checkForEvents () { ! bool ! found = (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 (); } ! return (found); } ! CUniqueDevice * ! CPhidgetManager::find (const CUID & uid, bool create) { ! CUniqueDevice *temp; ! bool isPhidget = false; ! // Is this a phidget or a phidget device we are trying to find? ! // Look at all known devices for this ! for (int t = 0; t < _uniqueDevices.size (); t++) ! { ! temp = _uniqueDevices[t]->find (uid, create); ! if (temp != NULL) ! return (temp); } ! // Wasn't found , so let's return because we were not asked to create this device ! if (!create) ! return (NULL); ! // Not found, is it a phidget? or a phidget device ! if (uid.id () == -1) ! isPhidget = true; ! // Make sure the phidget CUID(uid.serial()) exists ! CUID tempUID (uid.serial ()); ! bool devfound = false; ! if (!isPhidget) ! for (int t = 0; t < _uniqueDevices.size (); t++) ! { ! if (_uniqueDevices[t]->UID () == uid) ! { ! devfound = true; ! break; ! } ! } ! // Device wasn't found, this is always true if isPhidget is true ! if (!devfound || isPhidget) ! { ! // Create tempUID, this is the tricky part. ! // How, without know about this phidget do we create it? ! temp = createPhidget (tempUID); ! if (isPhidget) ! return (temp); } ! // The base phidget should exists and can now create it for us. ! return (temp->find (uid, create)); } ! CPhidget * ! CPhidgetManager::createPhidget (const CUID & uid) { ! // This device better not exists, we assume that has already been checked. ! if (uid.id () != -1) ! throw runtime_error ("Id must be -1 for all phidgets"); ! CServoController *sc = new CServoController (uid); ! //_uniqueDevices.push_back(sc); ! return (sc); } --- 171,262 ---- //} ! bool CPhidgetManager::checkForEvents() { ! bool found = (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(); } ! return (found); } ! CUniqueDevice *CPhidgetManager::find(const CUID &uid, bool create) { ! CUniqueDevice *temp; ! bool isPhidget = false; ! // Is this a phidget or a phidget device we are trying to find? ! // Look at all known devices for this ! for (int t = 0; t < _uniqueDevices.size(); t++) { ! temp = _uniqueDevices[t]->find(uid, create); ! if (temp != NULL) ! return (temp); } ! // Wasn't found , so let's return because we were not asked to create this device ! if (!create) ! return (NULL); ! // Not found, is it a phidget? or a phidget device ! if (uid.id() == -1) ! isPhidget = true; ! // Make sure the phidget CUID(uid.serial()) exists ! CUID tempUID(uid.serial()); ! bool devfound = false; ! if (!isPhidget) ! for (int t = 0; t < _uniqueDevices.size(); t++) { ! if (_uniqueDevices[t]->UID() == uid) { ! devfound = true; ! break; ! } ! } ! // Device wasn't found, this is always true if isPhidget is true ! if (!devfound || isPhidget) { ! // Create tempUID, this is the tricky part. ! // How, without know about this phidget do we create it? ! temp = createPhidget(tempUID); ! if (isPhidget) ! return (temp); } ! // The base phidget should exists and can now create it for us. ! return (temp->find(uid, create)); } ! CPhidget *CPhidgetManager::createPhidget(const CUID &uid) { ! // This device better not exists, we assume that has already been checked. ! if (uid.id() != -1) ! throw runtime_error("Id must be -1 for all phidgets"); ! CServoController *sc = new CServoController (uid); ! //_uniqueDevices.push_back(sc); ! return (sc); } Index: CPhidgetManager.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CPhidgetManager.h 8 Sep 2002 18:59:54 -0000 1.3 --- CPhidgetManager.h 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 49,74 **** * Singleton object that manages all phidgets. */ ! 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 --- 49,74 ---- * Singleton object that manages all phidgets. */ ! 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,114 **** * 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 ! ); ! CServoController *servoController (const CUID & uid); ! //CInterfaceKit *interfaceKit( ! //const CUID &uid ! //); /** * */ ! CUniqueDevice *find (const CUID & uid, bool create = false); ! //CServoController *createServoController(const CUID &uid); --- 78,114 ---- * 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 ! ); ! CServoController *servoController(const CUID &uid); ! //CInterfaceKit *interfaceKit( ! //const CUID &uid ! //); /** * */ ! CUniqueDevice *find(const CUID &uid, bool create = false); ! //CServoController *createServoController(const CUID &uid); *************** *** 116,132 **** * This goes thru all currently attached phidgets and returns a vector of any servos available */ ! //vector<CServo *> servos() const; /** * Returns a uniquely identified servo or NULL if it is not attached */ ! //CServo * servo( ! //const CUID &id //<! Unique ID of servo ! //); /** * Check for attach/detach events (or any other events. */ ! bool checkForEvents (); --- 116,132 ---- * This goes thru all currently attached phidgets and returns a vector of any servos available */ ! //vector<CServo *> servos() const; /** * Returns a uniquely identified servo or NULL if it is not attached */ ! //CServo * servo( ! //const CUID &id //<! Unique ID of servo ! //); /** * Check for attach/detach events (or any other events. */ ! bool checkForEvents(); Index: CServo.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServo.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CServo.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CServo.cc 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 27,60 **** */ ! CServo::CServo (CServoController * controller, const int id): ! CUniqueDevice (controller, id), ! _controller (controller), _position (0), _systemManaged (true) { } ! CServo::CServo (const CUID & uid): ! CUniqueDevice (uid), _position (0), _systemManaged (false) { ! // 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. ! _controller = ! dynamic_cast < ! CServoController * ! >(CPhidgetManager::getInstance ()->find (CUID (uid.serial ()), true)); ! // Let the controller know about this servo ! _controller->registerServo (this, uid.id ()); } CServo::~CServo () { ! if (!_systemManaged); ! _controller->unregisterServo (UID ()); } ! void ! CServo::position (float p) { ! _position = p; ! _controller->update (); } --- 27,56 ---- */ ! CServo::CServo (CServoController *controller, const int id):CUniqueDevice (controller, id), ! _controller(controller), _position(0), ! _systemManaged(true) { } ! CServo::CServo (const CUID &uid):CUniqueDevice (uid), _position(0), ! _systemManaged(false) { ! // 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. ! _controller = dynamic_cast < CServoController *>(CPhidgetManager::getInstance()->find(CUID (uid.serial()), true)); ! // Let the controller know about this servo ! _controller->registerServo(this, uid.id()); } CServo::~CServo () { ! if (!_systemManaged); ! _controller->unregisterServo(UID()); } ! void CServo::position(float p) { ! _position = p; ! _controller->update(); } Index: CServo.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServo.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CServo.h 8 Sep 2002 18:59:54 -0000 1.3 --- CServo.h 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 23,82 **** class CServo:public CUniqueDevice { ! private: ! friend class CServoController; ! CServoController *_controller; ! // This is the only real data for the servo ! float _position; ! bool _systemManaged; ! //CServo(CServoController *controller,int id, CServo *orig=NULL); ! public: ! CServo (CServoController * controller, const int id); ! CServo (const CUID & uid); ! virtual ~ CServo (); /** * Set's the current position of this servo */ ! void position (float percent //!< Percentage to turn this servo ! ); /** * Return the last position sent to the servo */ ! float position () const ! { ! return (_position); ! } /** * On controllers that support this it will return the real world * position of this servo. If it doesn't, it returns the same * as getPosition() ! */ float realPosition () const ! { ! return (position ()); ! } /** * Makes a copy of the servo, just the real data, not anything about * which controller it is attached to or other information set in the * constructor only ! */ const CServo & operator = (const CServo * a) { ! _position = a->_position; ! return (*this); ! } /** * No devices are contained in this device ! */ CServo *find (const CUID & uid) ! { ! return (NULL); ! } }; --- 23,82 ---- class CServo:public CUniqueDevice { ! private: ! friend class CServoController; ! CServoController *_controller; ! // This is the only real data for the servo ! float _position; ! bool _systemManaged; ! //CServo(CServoController *controller,int id, CServo *orig=NULL); ! public: ! CServo (CServoController *controller, const int id); ! CServo (const CUID &uid); ! virtual ~ CServo (); /** * Set's the current position of this servo */ ! void position(float percent //!< Percentage to turn this servo ! ); /** * Return the last position sent to the servo */ ! float position() const ! { ! return (_position); ! } /** * On controllers that support this it will return the real world * position of this servo. If it doesn't, it returns the same * as getPosition() ! */ float realPosition() const ! { ! return (position()); ! } /** * Makes a copy of the servo, just the real data, not anything about * which controller it is attached to or other information set in the * constructor only ! */ const CServo &operator = (const CServo *a) { ! _position = a->_position; ! return (*this); ! } /** * No devices are contained in this device ! */ CServo *find(const CUID &uid) ! { ! return (NULL); ! } }; Index: CServoController.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServoController.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CServoController.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CServoController.cc 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 14,52 **** #include <phidget.h> ! CServoController::CServoController (const CUID & uid): ! CPhidget (uid), _servoCount (-1), _servos (NULL) { ! // Make sure it was constructed properly ! if (classType () != LP_SERVO_CONTROLLER) ! throw ! runtime_error ! ("Can't initialize a CServoController with a phidget that is not a servo controller"); ! switch (productID ()) ! { case 0x0038: ! { ! setServoCount (4); ! break; ! } case 0x0039: ! { ! setServoCount (1); ! break; ! } case 0x003B: ! { ! setServoCount (8); ! break; ! } default: ! { ! char temp[128]; ! sprintf (temp, ! "Unknown type of servo controller Vendor ID:0x0%x Product ID:0x0%x\n", ! vendorID (), productID ()); ! throw runtime_error (temp); ! } } } --- 14,47 ---- #include <phidget.h> ! CServoController::CServoController (const CUID &uid):CPhidget (uid), _servoCount(-1), ! _servos(NULL) { ! // Make sure it was constructed properly ! if (classType() != LP_SERVO_CONTROLLER) ! throw runtime_error("Can't initialize a CServoController with a phidget that is not a servo controller"); ! switch (productID()) { case 0x0038: ! { ! setServoCount(4); ! break; ! } case 0x0039: ! { ! setServoCount(1); ! break; ! } case 0x003B: ! { ! setServoCount(8); ! break; ! } default: ! { ! char temp[128]; ! sprintf(temp, "Unknown type of servo controller Vendor ID:0x0%x Product ID:0x0%x\n", vendorID(), productID()); ! throw runtime_error(temp); ! } } } *************** *** 54,128 **** CServoController::~CServoController () { ! for (int t = 0; t < _servoCount; t++) ! if (_servos[t].first) ! delete _servos[t].second; ! delete[]_servos; } ! CUniqueDevice * ! CServoController::find (const CUID & uid, bool create) { ! if (uid.serial () == UID ().serial () && uid.id () >= 0 ! && uid.id () < _servoCount) return (servo (uid.id (), create)); ! return (CPhidget::find (uid)); } ! CServo * ! CServoController::servo (const int id, bool create) { ! if (id < 0 || id >= _servoCount) ! throw runtime_error ("Invalid servo id"); ! if (create && _servos[id].second == NULL) ! { ! _servos[id].first = true; ! _servos[id].second = new CServo (this, id); } ! return (_servos[id].second); } ! void ! CServoController::registerServo (CServo * servo, int id) { ! if (id < 0 || id >= _servoCount) ! throw runtime_error ("Invalid servo id"); ! if (_servos[id].second != NULL) ! throw runtime_error ("This servo id is already being used."); ! _servos[id].first = false; ! _servos[id].second = servo; } ! void ! CServoController::unregisterServo (const CUID & uid) { ! if ((uid.id () < 0 && uid.id () >= _servoCount) ! || uid.serial () != UID ().serial ()) ! throw runtime_error ("Invalid servo id"); ! if (_servos[uid.id ()].first) ! throw runtime_error ("Can't unregister a system managed servo"); ! _servos[uid.id ()].first = true; ! _servos[uid.id ()].second = NULL; } ! void ! CServoController::setServoCount (int num) { ! _servoCount = num; ! _servos = new pair < bool, CServo * >[_servoCount]; ! for (int t = 0; t < _servoCount; t++) ! { ! _servos[t].first = true; ! _servos[t].second = NULL; } } --- 49,116 ---- CServoController::~CServoController () { ! for (int t = 0; t < _servoCount; t++) ! if (_servos[t].first) ! delete _servos[t].second; ! delete[]_servos; } ! CUniqueDevice *CServoController::find(const CUID &uid, bool create) { ! if (uid.serial() == UID().serial() && uid.id() >= 0 && uid.id() < _servoCount) ! return (servo(uid.id(), create)); ! return (CPhidget::find(uid)); } ! CServo *CServoController::servo(const int id, bool create) { ! if (id < 0 || id >= _servoCount) ! throw runtime_error("Invalid servo id"); ! if (create && _servos[id].second == NULL) { ! _servos[id].first = true; ! _servos[id].second = new CServo (this, id); } ! return (_servos[id].second); } ! void CServoController::registerServo(CServo *servo, int id) { ! if (id < 0 || id >= _servoCount) ! throw runtime_error("Invalid servo id"); ! if (_servos[id].second != NULL) ! throw runtime_error("This servo id is already being used."); ! _servos[id].first = false; ! _servos[id].second = servo; } ! void CServoController::unregisterServo(const CUID &uid) { ! if ((uid.id() < 0 && uid.id() >= _servoCount) ! || uid.serial() != UID().serial()) ! throw runtime_error("Invalid servo id"); ! if (_servos[uid.id()].first) ! throw runtime_error("Can't unregister a system managed servo"); ! _servos[uid.id()].first = true; ! _servos[uid.id()].second = NULL; } ! void CServoController::setServoCount(int num) { ! _servoCount = num; ! _servos = new pair < bool, CServo *>[_servoCount]; ! for (int t = 0; t < _servoCount; t++) { ! _servos[t].first = true; ! _servos[t].second = NULL; } } *************** *** 200,220 **** */ ! void ! CServoController::update () { ! if (_servoCount) ! { ! float p1 = 0, p2 = 0, p3 = 0, p4 = 0; ! if (_servoCount >= 1 && _servos[0].second != NULL) ! p1 = _servos[0].second->position (); ! if (_servoCount >= 2 && _servos[1].second != NULL) ! p2 = _servos[1].second->position (); ! if (_servoCount >= 3 && _servos[2].second != NULL) ! p3 = _servos[2].second->position (); ! if (_servoCount >= 4 && _servos[3].second != NULL) ! p4 = _servos[3].second->position (); ! phidgetQuadServo (device (), p1, p2, p3, p4); } } --- 188,206 ---- */ ! void CServoController::update() { ! if (_servoCount) { ! float p1 = 0, p2 = 0, p3 = 0, p4 = 0; ! if (_servoCount >= 1 && _servos[0].second != NULL) ! p1 = _servos[0].second->position(); ! if (_servoCount >= 2 && _servos[1].second != NULL) ! p2 = _servos[1].second->position(); ! if (_servoCount >= 3 && _servos[2].second != NULL) ! p3 = _servos[2].second->position(); ! if (_servoCount >= 4 && _servos[3].second != NULL) ! p4 = _servos[3].second->position(); ! phidgetQuadServo(device(), p1, p2, p3, p4); } } Index: CServoController.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServoController.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CServoController.h 8 Sep 2002 18:59:54 -0000 1.3 --- CServoController.h 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 23,45 **** class CServoController:public CPhidget { ! private: ! friend class CServo; ! //friend class CPhidgetManager; ! //vector<CServo *> _servos; ! int _servoCount; ! void setServoCount (int num); ! pair < bool, CServo * >*_servos; ! void registerServo (CServo *, int id); ! void unregisterServo (const CUID & uid); ! public: ! CServoController (const CUID & uid); ! //CServoController(phidget *device); /** --- 23,45 ---- class CServoController:public CPhidget { ! private: ! friend class CServo; ! //friend class CPhidgetManager; ! //vector<CServo *> _servos; ! int _servoCount; ! void setServoCount(int num); ! pair < bool, CServo *>*_servos; ! void registerServo(CServo *, int id); ! void unregisterServo(const CUID &uid); ! public: ! CServoController (const CUID &uid); ! //CServoController(phidget *device); /** *************** *** 48,52 **** * pass it to this constructor, in the constructor of his derived type. */ ! //CServoController(CServoController *orig); /** --- 48,52 ---- * pass it to this constructor, in the constructor of his derived type. */ ! //CServoController(CServoController *orig); /** *************** *** 54,88 **** * back into the manager and notify it of the current state of the device */ ! virtual ~ CServoController (); /** * Resends servo information to the controller */ ! void update (); /** * Returns a vector of servo's that are controlled by this object */ ! //const vector <CServo *> &servos() const; ! CUniqueDevice *find (const CUID & uid, bool create); /** * returns a previously created servo */ ! CServo *servo (int id, bool create = true); ! int servoCount () const ! { ! return (_servoCount); ! } ! virtual void query (const EDeviceClass tp, set < CUID > &devices) ! { ! CPhidget::query (tp, devices); ! if (tp == LP_SERVO || tp == LP_ALL) ! for (int t = 0; t < _servoCount; t++) ! devices.insert (CUID (UID ().serial (), t)); ! } }; --- 54,88 ---- * back into the manager and notify it of the current state of the device */ ! virtual ~ CServoController (); /** * Resends servo information to the controller */ ! void update(); /** * Returns a vector of servo's that are controlled by this object */ ! //const vector <CServo *> &servos() const; ! CUniqueDevice *find(const CUID &uid, bool create); /** * returns a previously created servo */ ! CServo *servo(int id, bool create = true); ! int servoCount() const ! { ! return (_servoCount); ! } ! virtual void query(const EDeviceClass tp, set < CUID >&devices) ! { ! CPhidget::query(tp, devices); ! if (tp == LP_SERVO || tp == LP_ALL) ! for (int t = 0; t < _servoCount; t++) ! devices.insert(CUID (UID().serial(), t)); ! } }; Index: CUID.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CUID.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CUID.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CUID.cc 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 12,105 **** ! 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); - if (_id != id._id) - 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)); ! } --- 12,100 ---- ! 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); ! if (_id != id._id) ! return (false); ! return (true); ! } ! CUID::~CUID () { } ! int CUID::serial() ! const ! { ! return (_serial); ! } ! int CUID::id() const ! { ! return (_id); ! } ! bool CUID::op... [truncated message content] |
From: Vadim T. <vt...@us...> - 2002-09-12 00:24:32
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory usw-pr-cvs1:/tmp/cvs-serv4358/src/libphidget Modified Files: phidget.c phidget.h Log Message: Merged back the results of INDENT branch changes Index: phidget.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** phidget.c 8 Sep 2002 18:59:54 -0000 1.3 --- phidget.c 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 43,67 **** struct phidget_type { ! /*! ! * Currently supported names are: ! * - RFID VID/PID ! * - QuadServo .1 Degree ! * - UniServo .1 Degree ! * - 8-AdvancedServo ! * - Interface Kit 884 ! * - Interface Kit 088 [...1772 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.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** phidget.h 8 Sep 2002 18:59:54 -0000 1.3 --- phidget.h 12 Sep 2002 00:24:29 -0000 1.4 *************** *** 59,82 **** enum EDeviceClass { ! LP_ALL = 1, /**< All devices match this */ ! // Actual phidget types ! 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_ENCODER = 400, /**< Currently unsupported */ ! LP_POWER = 500, /**< Currently unsupported */ ! LP_RFID = 600, /**< Currently unsupported */ ! LP_LED = 700, /**< Currently unsupported */ ! LP_TEXTLCD = 800, /**< Currently unsupported */ ! // Phidget devices, a phidget device is something a phidget controls ! LP_SERVO = 201, /**< Any servo that a servo controller controls */ ! LP_DIGITAL_IN = 301, /**< Any digital input that an interface kit controls */ ! LP_DIGITAL_OUT = 302, /**< Any digital output that an interface kit controls */ ! LP_ANALOG_IN = 303, /**< Any analog input that an interface kit controls */ ! LP_OTHER = 0, /**< Identifies all unknown phidgets, this shouldn't exists */ ! LP_INVALID = -2, /**< Invalid device class */ }; --- 59,82 ---- enum EDeviceClass { ! LP_ALL = 1, /**< All devices match this */ ! // Actual phidget types ! 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_ENCODER = 400, /**< Currently unsupported */ ! LP_POWER = 500, /**< Currently unsupported */ ! LP_RFID = 600, /**< Currently unsupported */ ! LP_LED = 700, /**< Currently unsupported */ ! LP_TEXTLCD = 800, /**< Currently unsupported */ ! // Phidget devices, a phidget device is something a phidget controls ! LP_SERVO = 201, /**< Any servo that a servo controller controls */ ! LP_DIGITAL_IN = 301, /**< Any digital input that an interface kit controls */ ! LP_DIGITAL_OUT = 302, /**< Any digital output that an interface kit controls */ ! LP_ANALOG_IN = 303, /**< Any analog input that an interface kit controls */ ! LP_OTHER = 0, /**< Identifies all unknown phidgets, this shouldn't exists */ ! LP_INVALID = -2, /**< Invalid device class */ }; *************** *** 87,107 **** enum ELPError { ! LPE_NONE = 0, /**< No error has occured */ ! LPE_PHIDGET_NOT_ATTACHED = 1, /**< Phidget is not attached, this is really a warning */ ! LPE_UNKNOWN = -1, /**< An unknown error has occured */ ! LPE_INVALID_PHIDGET_CLASS = LP_INVALID, /**< Invalid device class (same as LP_INVALID), most likely the device class was NULL */ ! LPE_INVALID_PHIDGET = -3, /**< Invalid phidget, most likely the phidget was NULL */ ! LPE_NOT_INITIALIZED = -4, /**< libphidget hasn't been initialized */ ! LPE_WRONG_PHIDGET_CLASS_TYPE = -5, /**< The wrong device class type was passed to a function */ ! LPE_UNKNOWN_PHIDGET_CLASS_TYPE = -6, /**< An unknown device class type was passed to a function */ ! LPE_SET_CONFIGURATION_FAILED = -7, /**< During the initialization of a phidget the configuration for the USB device could not be set */ ! LPE_CLAIM_INTERFACE_FAILED = -8, /**< During the initialization of a phidget the interface for the USB device could not be claimed */ ! LPE_SET_ALT_INTERFACE_FAILED = -9, /**< During the initialization of a phidget the alternate interface for the USB device could not be set */ ! LPE_NO_SERIAL_RETURNED = -10, /**< The serial number could not be requested from the phidget */ ! LPE_PHIDGET_ALREADY_CLOSED = -11, /**< Phidget is already closed */ ! LPE_PHIDGET_ALREADY_OPENED = -12, /**< Phidget is already opened */ ! LPE_PHIDGET_NOT_OPENED = -13, /**< Phidget is not opened */ ! LPE_CONTROL_MSG_ERROR = -14, /**< Error sending a control message to a phidget */ ! LPE_BULK_READ_ERROR = -15 /**< Error reading bulk data from a phidget */ }; --- 87,107 ---- enum ELPError { ! LPE_NONE = 0, /**< No error has occured */ ! LPE_PHIDGET_NOT_ATTACHED = 1, /**< Phidget is not attached, this is really a warning */ ! LPE_UNKNOWN = -1, /**< An unknown error has occured */ ! LPE_INVALID_PHIDGET_CLASS = LP_INVALID, /**< Invalid device class (same as LP_INVALID), most likely the device class was NULL */ ! LPE_INVALID_PHIDGET = -3, /**< Invalid phidget, most likely the phidget was NULL */ ! LPE_NOT_INITIALIZED = -4, /**< libphidget hasn't been initialized */ ! LPE_WRONG_PHIDGET_CLASS_TYPE = -5, /**< The wrong device class type was passed to a function */ ! LPE_UNKNOWN_PHIDGET_CLASS_TYPE = -6, /**< An unknown device class type was passed to a function */ ! LPE_SET_CONFIGURATION_FAILED = -7, /**< During the initialization of a phidget the configuration for the USB device could not be set */ ! LPE_CLAIM_INTERFACE_FAILED = -8, /**< During the initialization of a phidget the interface for the USB device could not be claimed */ ! LPE_SET_ALT_INTERFACE_FAILED = -9, /**< During the initialization of a phidget the alternate interface for the USB device could not be set */ ! LPE_NO_SERIAL_RETURNED = -10, /**< The serial number could not be requested from the phidget */ ! LPE_PHIDGET_ALREADY_CLOSED = -11, /**< Phidget is already closed */ ! LPE_PHIDGET_ALREADY_OPENED = -12, /**< Phidget is already opened */ ! LPE_PHIDGET_NOT_OPENED = -13, /**< Phidget is not opened */ ! LPE_CONTROL_MSG_ERROR = -14, /**< Error sending a control message to a phidget */ ! LPE_BULK_READ_ERROR = -15 /**< Error reading bulk data from a phidget */ }; *************** *** 119,128 **** * long as \a phidget_deinit is called between each call to \a phidget_init. */ ! enum ELPError phidgetInit (int catchSignals); /** Must be called at the end of your program. Frees some internal data * structures. If this isn't called then there will be memory leaks. */ ! enum ELPError phidgetDeinit (); /** --- 119,128 ---- * long as \a phidget_deinit is called between each call to \a phidget_init. */ ! enum ELPError phidgetInit(int catchSignals); /** Must be called at the end of your program. Frees some internal data * structures. If this isn't called then there will be memory leaks. */ ! enum ELPError phidgetDeinit(); /** *************** *** 130,134 **** * and phidgetLastError() will return the error code. */ ! struct phidget **phidgetGetPhidgets (int *numPhidgets); /** --- 130,134 ---- * and phidgetLastError() will return the error code. */ ! struct phidget **phidgetGetPhidgets(int *numPhidgets); /** *************** *** 136,147 **** * return the error code. */ ! struct phidget *phidgetOpen (struct phidget *phidget //<! The phidget that we want to open ! ); /** * Close a phidget */ ! enum ELPError phidgetClose (struct phidget *device //<! The phidget to be closed ! ); /** --- 136,147 ---- * return the error code. */ ! struct phidget *phidgetOpen(struct phidget *phidget //<! The phidget that we want to open ! ); /** * Close a phidget */ ! enum ELPError phidgetClose(struct phidget *device //<! The phidget to be closed ! ); /** *************** *** 150,157 **** * writing to. */ ! enum ELPError phidgetWrite (struct phidget *device, //<! The phidget to be written to ! char *bytes, //<! Pointer to data that is to be written to the device ! int size //<! Size in bytes of data pointed to by \a bytes ! ); /** --- 150,157 ---- * writing to. */ ! enum ELPError phidgetWrite(struct phidget *device, //<! The phidget to be written to ! char *bytes, //<! Pointer to data that is to be written to the device ! int size //<! Size in bytes of data pointed to by \a bytes ! ); /** *************** *** 159,166 **** * have an interface kit or any phidget that supports reads. */ ! enum ELPError phidgetRead (struct phidget *device, //<! The phidget to be read from ! char *bytes, //<! Pointer allocated large enough to hold \a size bytes of data ! int size //<! Size in bytes of data to read from device ! ); /** --- 159,166 ---- * have an interface kit or any phidget that supports reads. */ ! enum ELPError phidgetRead(struct phidget *device, //<! The phidget to be read from ! char *bytes, //<! Pointer allocated large enough to hold \a size bytes of data ! int size //<! Size in bytes of data to read from device ! ); /** *************** *** 171,177 **** * motion on your servo you can simple say percent = desired_angle / range. */ ! enum ELPError phidgetSingleServo (struct phidget *device, //<! The phidget to be controlled ! float percent //<! Percentage to move servo 1 ! ); /** --- 171,177 ---- * motion on your servo you can simple say percent = desired_angle / range. */ ! enum ELPError phidgetSingleServo(struct phidget *device, //<! The phidget to be controlled ! float percent //<! Percentage to move servo 1 ! ); /** *************** *** 179,185 **** * device is closed (either on purpose, or when the signal handler catches it) */ ! enum ELPError pidgetSingleServoDefault (struct phidget *device, //<! The phidget whose default we want to set ! float percent //!< Percentage to move servo 1 ! ); /** --- 179,185 ---- * device is closed (either on purpose, or when the signal handler catches it) */ ! enum ELPError pidgetSingleServoDefault(struct phidget *device, //<! The phidget whose default we want to set ! float percent //!< Percentage to move servo 1 ! ); /** *************** *** 190,199 **** * motion on your servo you can simple say percent = desired_angle / range. */ ! enum ELPError phidgetQuadServo (struct phidget *device, //!< The phidget to be contorlled ! float percent1, //!< Percentage to move servo 1 ! float percent2, //!< Percentage to move servo 2 ! float percent3, //!< Percentage to move servo 3 ! float percent4 //!< Percentage to move servo 4 ! ); /** --- 190,199 ---- * motion on your servo you can simple say percent = desired_angle / range. */ ! enum ELPError phidgetQuadServo(struct phidget *device, //!< The phidget to be contorlled ! float percent1, //!< Percentage to move servo 1 ! float percent2, //!< Percentage to move servo 2 ! float percent3, //!< Percentage to move servo 3 ! float percent4 //!< Percentage to move servo 4 ! ); /** *************** *** 201,210 **** * 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 ! float percent3, //!< Percentage to move servo 3 ! float percent4 //!< Percentage to move servo 4 ! ); /** --- 201,210 ---- * 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 ! float percent3, //!< Percentage to move servo 3 ! float percent4 //!< Percentage to move servo 4 ! ); /** *************** *** 217,221 **** * then when it is reconnected you will be re-attached to the same USB device. */ ! int phidgetEvents (); --- 217,221 ---- * then when it is reconnected you will be re-attached to the same USB device. */ ! int phidgetEvents(); *************** *** 224,233 **** * a NULL and phidgetLastError() will return the error code. */ ! const struct phidget_type *phidgetType (const struct phidget *device); /** * Return the serial number from a phidget. If an error occurs it returns an \a ELPError equivalent error number. */ ! int phidgetSerial (const struct phidget *device); /** --- 224,233 ---- * a NULL and phidgetLastError() will return the error code. */ ! const struct phidget_type *phidgetType(const struct phidget *device); /** * Return the serial number from a phidget. If an error occurs it returns an \a ELPError equivalent error number. */ ! int phidgetSerial(const struct phidget *device); /** *************** *** 235,269 **** * a NULL and phidgetLastError() will return the error code. */ ! const char *phidgetTypeName (const struct phidget_type *tp); /** * Returns the product ID of a phidget type If an error occurs it returns an \a ELPError equivalent error number. */ ! int phidgetTypeProductID (const struct phidget_type *tp); /** * Returns a vendor ID of a phidget type If an error occurs it returns an \a ELPError equivalent error number. */ ! int phidgetTypeVendorID (const struct phidget_type *tp); /** * Returns the device class of a phidget type If an error occurs it returns an \a ELPError equivalent error number. */ ! enum EDeviceClass phidgetTypeDeviceClass (const struct phidget_type *tp); /** * Returns 1 if a phidget is attached, 0 if it isn't attached. If an error occurs it returns an \a ELPError equivalent error number. */ ! int phidgetAttached (const struct phidget *device); /** * Returns the last error that occured. No defined error can occur during this call. */ ! enum ELPError phidgetLastError (); /** * Returns a human readable string that describes the error number. */ ! const char *phidgetErrorString (const enum ELPError err); --- 235,269 ---- * a NULL and phidgetLastError() will return the error code. */ ! const char *phidgetTypeName(const struct phidget_type *tp); /** * Returns the product ID of a phidget type If an error occurs it returns an \a ELPError equivalent error number. */ ! int phidgetTypeProductID(const struct phidget_type *tp); /** * Returns a vendor ID of a phidget type If an error occurs it returns an \a ELPError equivalent error number. */ ! int phidgetTypeVendorID(const struct phidget_type *tp); /** * Returns the device class of a phidget type If an error occurs it returns an \a ELPError equivalent error number. */ ! enum EDeviceClass phidgetTypeDeviceClass(const struct phidget_type *tp); /** * Returns 1 if a phidget is attached, 0 if it isn't attached. If an error occurs it returns an \a ELPError equivalent error number. */ ! int phidgetAttached(const struct phidget *device); /** * Returns the last error that occured. No defined error can occur during this call. */ ! enum ELPError phidgetLastError(); /** * Returns a human readable string that describes the error number. */ ! const char *phidgetErrorString(const enum ELPError err); |
From: Vadim T. <vt...@us...> - 2002-09-12 00:24:31
|
Update of /cvsroot/libphidget/libphidget In directory usw-pr-cvs1:/tmp/cvs-serv4358 Modified Files: Makefile.am indent.rules Added Files: indent.defs Log Message: Merged back the results of INDENT branch changes Index: Makefile.am =================================================================== RCS file: /cvsroot/libphidget/libphidget/Makefile.am,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Makefile.am 9 Sep 2002 22:57:32 -0000 1.6 --- Makefile.am 12 Sep 2002 00:24:28 -0000 1.7 *************** *** 16,21 **** @ for FILE in `@FIND@ . -name "*.h" -o -name "*.c" -o -name "*.cc"` ; do \ ! @INDENT@ --ignore-profile --standard-output `@CAT@ ./indent.rules` $$FILE > $$FILE.indent; \ if @TEST@ -n "`@DIFF@ $$FILE $$FILE.indent`" ; then \ @MV@ $$FILE.indent $$FILE; \ else \ --- 16,26 ---- @ for FILE in `@FIND@ . -name "*.h" -o -name "*.c" -o -name "*.cc"` ; do \ ! @INDENT@ --ignore-profile --standard-output `@CAT@ ./indent.rules` `@CAT@ ./indent.defs` $$FILE > $$FILE.indent; \ if @TEST@ -n "`@DIFF@ $$FILE $$FILE.indent`" ; then \ + if @TEST@ ! -s $$FILE.indent ; then \ + @ECHO@ "@INDENT@ run resulted in an empty file: $$FILE.indent; most probably the options in ./indent.rules are wrong"; \ + @RM@ $$FILE.indent; \ + exit 1; \ + fi; \ @MV@ $$FILE.indent $$FILE; \ else \ *************** *** 32,37 **** @ for FILE in `@FIND@ . -name "*.h" -o -name "*.c" -o -name "*.cc"` ; do \ ! @INDENT@ --standard-output $$FILE > $$FILE.indent; \ if @TEST@ -n "`@DIFF@ $$FILE $$FILE.indent`" ; then \ @MV@ $$FILE.indent $$FILE; \ else \ --- 37,47 ---- @ for FILE in `@FIND@ . -name "*.h" -o -name "*.c" -o -name "*.cc"` ; do \ ! @INDENT@ --standard-output `@CAT@ ./indent.defs` $$FILE > $$FILE.indent; \ if @TEST@ -n "`@DIFF@ $$FILE $$FILE.indent`" ; then \ + if @TEST@ ! -s $$FILE.indent ; then \ + @ECHO@ "@INDENT@ run resulted in an empty file: $$FILE.indent; most probably the options in ./indent.rules are wrong"; \ + @RM@ $$FILE.indent; \ + exit 1; \ + fi; \ @MV@ $$FILE.indent $$FILE; \ else \ Index: indent.rules =================================================================== RCS file: /cvsroot/libphidget/libphidget/indent.rules,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** indent.rules 8 Sep 2002 04:24:31 -0000 1.1 --- indent.rules 12 Sep 2002 00:24:28 -0000 1.2 *************** *** 1 **** ! --gnu-style --- 1,24 ---- ! --no-blank-lines-after-declarations ! --blank-lines-after-procedures ! --no-blank-lines-after-commas ! --break-before-boolean-operator ! --braces-on-if-line ! --brace-indent4 ! --braces-after-struct-decl-line ! --no-comment-delimiters-on-blank-lines ! --cuddle-else ! --else-endif-column1 ! --space-after-cast ! --declaration-indentation4 ! --dont-format-first-column-comments ! --dont-format-comments ! --honour-newlines ! --indent-level4 ! --parameter-indentation5 ! --continue-at-parentheses ! --no-space-after-function-call-names ! --no-space-after-parentheses ! --procnames-start-lines ! --dont-star-comments ! --leave-optional-blank-lines ! --line-length128 |
From: Vadim T. <vt...@us...> - 2002-09-12 00:24:31
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory usw-pr-cvs1:/tmp/cvs-serv4358/src/examples Modified Files: phidget_c.c phidget_cpp.cc Log Message: Merged back the results of INDENT branch changes Index: phidget_c.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_c.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** phidget_c.c 8 Sep 2002 18:59:54 -0000 1.2 --- phidget_c.c 12 Sep 2002 00:24:29 -0000 1.3 *************** *** 18,88 **** */ int ! main (int argn, char *argv[]) { ! int t, count; ! struct phidget **phidgets; ! printf ("----------------------------------------\n"); ! printf ("Phidgets Device driver test.\n\n\n"); ! // Initialize libphiget, here is where the devices are actually retrieved by the library ! // We want the library to handle signals (passing it 1) ! phidgetInit (1); ! // Get an array of pointers to phidgets and a count of available phidgets ! phidgets = phidgetGetPhidgets (&count); ! printf ("Device count:%d\n", count); ! for (t = 0; t < count; t++) ! { ! unsigned char buffer[6]; ! float k; ! struct phidget *dev = phidgetOpen (phidgets[t]); // Open the phidget #t ! // Make sure we opened it successfully ! if (dev == NULL) ! { ! printf ("Can't open phidget:%s\n", ! phidgetErrorString (phidgetLastError ())); ! exit (0); } ! // Print out some information about this phidget ! printf ! ("Phidget Name:%s Vendor:0x0%x Product:0x0%x Serial#:%06d\n", ! phidgetTypeName (phidgetType (dev)), ! phidgetTypeVendorID (phidgetType (dev)), ! phidgetTypeProductID (phidgetType (dev)), phidgetSerial (dev)); ! // Is it a servo controller ! if (phidgetTypeDeviceClass (phidgetType (dev)) == LP_SERVO_CONTROLLER) ! { ! for (k = 0; k < 1; k += .1) ! { ! int i; ! // Move a single servo (will move servo 0 of a 1 or 4 servo controller) ! phidgetSingleServo (dev, k); ! // Wait a bit ! sleep (1); ! // Process any events that have occured, like attach/detach ! phidgetEvents (); } } ! // Close the phidget ! phidgetClose (dev); ! printf ("Finished\n"); } ! // done using all phidgets, free's phidget memory ! phidgetDeinit (); ! printf ("----------------------------------------\n"); ! return (0); } --- 18,82 ---- */ int ! main(int argn, char *argv[]) { ! int t, count; ! struct phidget **phidgets; ! printf("----------------------------------------\n"); ! printf("Phidgets Device driver test.\n\n\n"); ! // Initialize libphiget, here is where the devices are actually retrieved by the library ! // We want the library to handle signals (passing it 1) ! phidgetInit(1); ! // Get an array of pointers to phidgets and a count of available phidgets ! phidgets = phidgetGetPhidgets(&count); ! printf("Device count:%d\n", count); ! for (t = 0; t < count; t++) { ! unsigned char buffer[6]; ! float k; ! struct phidget *dev = phidgetOpen(phidgets[t]); // Open the phidget #t ! // Make sure we opened it successfully ! if (dev == NULL) { ! printf("Can't open phidget:%s\n", phidgetErrorString(phidgetLastError())); ! exit(0); } ! // Print out some information about this phidget ! printf ! ("Phidget Name:%s Vendor:0x0%x Product:0x0%x Serial#:%06d\n", ! phidgetTypeName(phidgetType(dev)), ! phidgetTypeVendorID(phidgetType(dev)), phidgetTypeProductID(phidgetType(dev)), phidgetSerial(dev)); ! // Is it a servo controller ! if (phidgetTypeDeviceClass(phidgetType(dev)) == LP_SERVO_CONTROLLER) { ! for (k = 0; k < 1; k += .1) { ! int i; ! // Move a single servo (will move servo 0 of a 1 or 4 servo controller) ! phidgetSingleServo(dev, k); ! // Wait a bit ! sleep(1); ! // Process any events that have occured, like attach/detach ! phidgetEvents(); } } ! // Close the phidget ! phidgetClose(dev); ! printf("Finished\n"); } ! // done using all phidgets, free's phidget memory ! phidgetDeinit(); ! printf("----------------------------------------\n"); ! return (0); } Index: phidget_cpp.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_cpp.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** phidget_cpp.cc 8 Sep 2002 18:59:54 -0000 1.2 --- phidget_cpp.cc 12 Sep 2002 00:24:29 -0000 1.3 *************** *** 196,342 **** 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"); } void ! readUID (const string & arg) { ! bool colon_found = false; ! string temp; ! char last_char; ! int serial = -1; ! int id = -1; ! for (int t = 0; t < arg.length (); t++) ! { ! last_char = arg[t]; ! if (arg[t] == ':') ! { ! if (colon_found) ! throw runtime_error ("More than one colon found in UID\n"); ! colon_found = true; ! serial = atoi (temp.c_str ()); ! temp = ""; ! } ! else if (arg[t] >= '0' && arg[t] <= '9') ! { ! temp += arg.substr (t, 1); ! } ! else ! throw runtime_error ("Invalid character in UID:" + arg); } ! if (colon_found && temp.length () > 0 && last_char != ':') ! id = atoi (temp.c_str ()); ! else if (!colon_found) ! serial = atoi (temp.c_str ()); ! workingUID = CUID (serial, id); } void ! query () { ! if (workingUID.serial () == -1) ! throw runtime_error ("Must use parameter -u with query command\n"); ! CPhidgetManager *manager = CPhidgetManager::getInstance (); ! CUniqueDevice *dev = manager->find (workingUID, true); ! printf ("%-10s ", workingUID.asString ().c_str ()); ! printf (">> "); ! // What type of device is this? ! CPhidget *phidget; ! if ((phidget = dynamic_cast < CPhidget * >(dev)) != NULL) ! { ! printf ("Phidget [%s] ", phidget->name ()); ! } ! else ! { ! if (dynamic_cast < CServo * >(dev) != NULL) ! printf ("Servo "); } ! printf ("\n"); } void ! moveServo (const string & parm) { ! float p = atof (parm.c_str ()); ! CServo servo (workingUID); ! printf ("Moving servo to position %f\n", p); ! servo.position (p); ! sleep (1); } void ! help () { ! printf ("Arguments:\n\n"); ! printf (" -l (default) list all phidets \n"); ! printf (" -u {UID} set the working UID\n"); ! printf (" -q query the working UID\n"); ! printf (" -h help\n"); ! printf ! (" -p {percent} adjust the position of a servo referenced by UID\n"); ! printf ("\n"); } --- 196,328 ---- 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"); } void ! readUID(const string & arg) { ! bool colon_found = false; ! string temp; ! char last_char; ! int serial = -1; ! int id = -1; ! for (int t = 0; t < arg.length(); t++) { ! last_char = arg[t]; ! if (arg[t] == ':') { ! if (colon_found) ! throw runtime_error("More than one colon found in UID\n"); ! colon_found = true; ! serial = atoi(temp.c_str()); ! temp = ""; ! } else if (arg[t] >= '0' && arg[t] <= '9') { ! temp += arg.substr(t, 1); ! } else ! throw runtime_error("Invalid character in UID:" + arg); } ! if (colon_found && temp.length() > 0 && last_char != ':') ! id = atoi(temp.c_str()); ! else if (!colon_found) ! serial = atoi(temp.c_str()); ! workingUID = CUID (serial, id); } void ! query() { ! if (workingUID.serial() == -1) ! throw runtime_error("Must use parameter -u with query command\n"); ! CPhidgetManager *manager = CPhidgetManager::getInstance(); ! CUniqueDevice *dev = manager->find(workingUID, true); ! printf("%-10s ", workingUID.asString().c_str()); ! printf(">> "); ! // What type of device is this? ! CPhidget *phidget; ! if ((phidget = dynamic_cast < CPhidget *>(dev)) !=NULL) { ! printf("Phidget [%s] ", phidget->name()); ! } else { ! if (dynamic_cast < CServo *>(dev) != NULL) ! printf("Servo "); } ! printf("\n"); } void ! moveServo(const string & parm) { ! float p = atof(parm.c_str()); ! CServo servo(workingUID); ! printf("Moving servo to position %f\n", p); ! servo.position(p); ! sleep(1); } void ! help() { ! printf("Arguments:\n\n"); ! printf(" -l (default) list all phidets \n"); ! printf(" -u {UID} set the working UID\n"); ! printf(" -q query the working UID\n"); ! printf(" -h help\n"); ! printf(" -p {percent} adjust the position of a servo referenced by UID\n"); ! printf("\n"); } *************** *** 344,391 **** int ! processArgs (int argn, char *argv[]) { ! if (argn == 0) ! return (0); ! // Read an argument ! string arg = argv[0]; ! if (arg == "-u") // The unique device ID to work with { ! if (argn < 2) ! throw runtime_error ("Expected argument after -u"); ! string parm = argv[1]; ! readUID (parm); ! return (processArgs (argn - 2, argv + 2)); ! } ! else if (arg == "-q") ! { ! query (); ! return (processArgs (argn - 1, argv + 1)); ! } ! else if (arg == "-h") ! { ! help (); ! return (processArgs (argn - 1, argv + 1)); ! } ! else if (arg == "-l") ! { ! phidgets_ls (); ! return (processArgs (argn - 1, argv + 1)); ! } ! else if (arg == "-p") ! { ! if (argn < 2) ! throw runtime_error ("Expected argument after -p"); ! string parm = argv[1]; ! moveServo (parm); ! return (processArgs (argn - 2, argv + 2)); } ! throw runtime_error ("Invalid argument:" + arg); } --- 330,369 ---- int ! processArgs(int argn, char *argv[]) { ! if (argn == 0) ! return (0); ! // Read an argument ! string arg = argv[0]; ! if (arg == "-u") // The unique device ID to work with { ! if (argn < 2) ! throw runtime_error("Expected argument after -u"); ! string parm = argv[1]; ! readUID(parm); ! return (processArgs(argn - 2, argv + 2)); ! } else if (arg == "-q") { ! query(); ! return (processArgs(argn - 1, argv + 1)); ! } else if (arg == "-h") { ! help(); ! return (processArgs(argn - 1, argv + 1)); ! } else if (arg == "-l") { ! phidgets_ls(); ! return (processArgs(argn - 1, argv + 1)); ! } else if (arg == "-p") { ! if (argn < 2) ! throw runtime_error("Expected argument after -p"); ! string parm = argv[1]; ! moveServo(parm); ! return (processArgs(argn - 2, argv + 2)); } ! throw runtime_error("Invalid argument:" + arg); } *************** *** 394,421 **** int ! main (int argn, char *argv[]) { ! try ! { ! // What we are ! printf ("phidgets: a command line interface utility\n"); ! printf ("version $Revision$\n\n"); ! // No arguments ! if (argn <= 1) ! { ! phidgets_ls (); ! return (0); ! } ! // Recursive argument parser, remove the executable name ! return (processArgs (argn - 1, argv + 1)); ! } ! catch (const exception & e) ! { ! printf ("Exception: %s\n", e.what ()); ! return (-1); ! } ! return (0); } --- 372,396 ---- int ! main(int argn, char *argv[]) { ! try { ! // What we are ! printf("phidgets: a command line interface utility\n"); ! printf("version $Revision$\n\n"); ! // No arguments ! if (argn <= 1) { ! phidgets_ls(); ! return (0); ! } ! // Recursive argument parser, remove the executable name ! return (processArgs(argn - 1, argv + 1)); ! } ! catch(const exception & e) { ! printf("Exception: %s\n", e.what()); ! return (-1); ! } ! return (0); } |
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory usw-pr-cvs1:/tmp/cvs-serv32136/src/phidget++ Modified Files: Tag: INDENT CAnalogIn.cc CAnalogIn.h CDigitalIn.cc CDigitalIn.h CDigitalOut.cc CDigitalOut.h CInterfaceKit.cc CInterfaceKit.h CPhidget.cc CPhidget.h CPhidgetManager.cc CPhidgetManager.h CServo.cc CServo.h CServoController.cc CServoController.h CUID.cc CUID.h CUniqueDevice.cc CUniqueDevice.h TSingleton.h lsphidget.cc Log Message: Another massive commit - this time, the indent [supposedly] works fine and produces stable code, regardless of how many times it's been run. Hope this works... Index: CAnalogIn.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CAnalogIn.cc,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CAnalogIn.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CAnalogIn.cc 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 11,17 **** #include "CInterfaceKit.h" ! CAnalogIn::CAnalogIn (CInterfaceKit * interfacekit, int id): ! CUniqueDevice (interfacekit, id), ! _interfaceKit (interfacekit), _value (0), _lastValue (0) { } --- 11,17 ---- #include "CInterfaceKit.h" ! CAnalogIn::CAnalogIn (CInterfaceKit *interfacekit, int id):CUniqueDevice (interfacekit, id), ! _interfaceKit(interfacekit), _value(0), ! _lastValue(0) { } Index: CAnalogIn.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CAnalogIn.h,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CAnalogIn.h 8 Sep 2002 18:59:54 -0000 1.3 --- CAnalogIn.h 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 24,61 **** class CAnalogIn:CUniqueDevice { ! private: ! friend class CInterfaceKit; ! CInterfaceKit *_interfaceKit; ! // This is the only real data for the servo ! float _value; ! float _lastValue; ! CAnalogIn (CInterfaceKit * interfacekit, int id); ! public: /** * Empty virtual constructor */ ! virtual ~ CAnalogIn () ! { ! } /** * Return the current value of the analog input, this * value is only updates when CPhidgetManager->checkForEvents() * is called. ! */ float value () const ! { ! return (_value); ! } /** * No devices are contained in this device ! */ CAnalogIn *find (const CUID & uid) ! { ! return (NULL); ! } }; --- 24,61 ---- class CAnalogIn:CUniqueDevice { ! private: ! friend class CInterfaceKit; ! CInterfaceKit *_interfaceKit; ! // This is the only real data for the servo ! float _value; ! float _lastValue; ! CAnalogIn (CInterfaceKit *interfacekit, int id); ! public: /** * Empty virtual constructor */ ! virtual ~ CAnalogIn () ! { ! } /** * Return the current value of the analog input, this * value is only updates when CPhidgetManager->checkForEvents() * is called. ! */ float value() const ! { ! return (_value); ! } /** * No devices are contained in this device ! */ CAnalogIn *find(const CUID &uid) ! { ! return (NULL); ! } }; Index: CDigitalIn.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.cc,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CDigitalIn.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CDigitalIn.cc 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 11,16 **** #include "CInterfaceKit.h" ! CDigitalIn::CDigitalIn (CInterfaceKit * interfacekit, int id): ! CUniqueDevice (interfacekit, id), _value (false), _lastValue (false) { } --- 11,16 ---- #include "CInterfaceKit.h" ! CDigitalIn::CDigitalIn (CInterfaceKit *interfacekit, int id):CUniqueDevice (interfacekit, id), _value(false), ! _lastValue(false) { } Index: CDigitalIn.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.h,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CDigitalIn.h 8 Sep 2002 18:59:54 -0000 1.3 --- CDigitalIn.h 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 24,58 **** class CDigitalIn:public CUniqueDevice { ! private: ! friend class CInterfaceKit; ! // This is the only real data for the servo ! bool _value; ! bool _lastValue; ! CDigitalIn (CInterfaceKit * interfacekit, int id); ! public: /** * Standard virtual destructor */ ! virtual ~ CDigitalIn () ! { ! } /** * Return the current value of the digital input, this * value is only updates when CPhidgetManager->checkForEvents() * is called. ! */ bool value () const ! { ! return (_value); ! } /** * No devices are contained in this device ! */ CDigitalIn *find (const CUID & uid) ! { ! return (NULL); ! } }; --- 24,58 ---- class CDigitalIn:public CUniqueDevice { ! private: ! friend class CInterfaceKit; ! // This is the only real data for the servo ! bool _value; ! bool _lastValue; ! CDigitalIn (CInterfaceKit *interfacekit, int id); ! public: /** * Standard virtual destructor */ ! virtual ~ CDigitalIn () ! { ! } /** * Return the current value of the digital input, this * value is only updates when CPhidgetManager->checkForEvents() * is called. ! */ bool value() const ! { ! return (_value); ! } /** * No devices are contained in this device ! */ CDigitalIn *find(const CUID &uid) ! { ! return (NULL); ! } }; Index: CDigitalOut.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalOut.cc,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CDigitalOut.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CDigitalOut.cc 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 11,30 **** #include "CInterfaceKit.h" ! CDigitalOut::CDigitalOut (CInterfaceKit * interfacekit, int id): ! CUniqueDevice (interfacekit, id), _value (false) { } ! void ! CDigitalOut::value (bool val) { ! _value = val; ! // Tell the interface kit our value has changed, so it ! // sends it to the servo immediately ! CUniqueDevice *temp1 = parent (); ! CInterfaceKit *temp2 = dynamic_cast < CInterfaceKit * >(temp1); ! temp2->update (); } --- 11,29 ---- #include "CInterfaceKit.h" ! CDigitalOut::CDigitalOut (CInterfaceKit *interfacekit, int id):CUniqueDevice (interfacekit, id), ! _value(false) { } ! void CDigitalOut::value(bool val) { ! _value = val; ! // Tell the interface kit our value has changed, so it ! // sends it to the servo immediately ! CUniqueDevice *temp1 = parent(); ! CInterfaceKit *temp2 = dynamic_cast < CInterfaceKit *>(temp1); ! temp2->update(); } Index: CDigitalOut.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalOut.h,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CDigitalOut.h 8 Sep 2002 18:59:54 -0000 1.3 --- CDigitalOut.h 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 24,56 **** class CDigitalOut:CUniqueDevice { ! private: ! friend class CInterfaceKit; ! CInterfaceKit *_interfaceKit; ! // This is the only real data for the servo ! bool _value; ! CDigitalOut (CInterfaceKit * interfacekit, int id); ! public: /** * Standard empty virtual destructor */ ! virtual ~ CDigitalOut () ! { ! } /** * Sends a value to the interface kit ! */ void value (bool val); /** * No devices are contained in this device */ ! CDigitalOut *find (const CUID & uid) ! { ! return (NULL); ! } }; --- 24,56 ---- class CDigitalOut:CUniqueDevice { ! private: ! friend class CInterfaceKit; ! CInterfaceKit *_interfaceKit; ! // This is the only real data for the servo ! bool _value; ! CDigitalOut (CInterfaceKit *interfacekit, int id); ! public: /** * Standard empty virtual destructor */ ! virtual ~ CDigitalOut () ! { ! } /** * Sends a value to the interface kit ! */ void value(bool val); /** * No devices are contained in this device */ ! CDigitalOut *find(const CUID &uid) ! { ! return (NULL); ! } }; Index: CInterfaceKit.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CInterfaceKit.cc,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CInterfaceKit.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CInterfaceKit.cc 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 16,144 **** #include <phidget.h> ! CInterfaceKit::CInterfaceKit (phidget * device): ! CPhidget (device) { ! if (classType () != INTERFACE_KIT) ! throw ! runtime_error ! ("Can't initialize a CInterfaceKit with a phidget that is not an interface kit"); ! switch (productID ()) ! { default: ! { ! char temp[128]; ! sprintf (temp, ! "Unknown type of interface kit Vendor ID:0x0%x Product ID:0x0%x\n", ! vendorID (), productID ()); ! throw runtime_error (temp); ! } } } ! void ! CInterfaceKit::setDigitalInCount (int num) { ! if (_digitalIns.size () != 0) ! throw runtime_error ("You can only call this function once"); ! for (int t = 0; t < num; t++) ! _digitalIns.push_back (new CDigitalIn (this, t)); } ! void ! CInterfaceKit::setDigitalOutCount (int num) { ! if (_digitalOuts.size () != 0) ! throw runtime_error ("You can only call this function once"); ! for (int t = 0; t < num; t++) ! _digitalOuts.push_back (new CDigitalOut (this, t)); } ! void ! CInterfaceKit::setAnalogInCount (int num) { ! if (_analogIns.size () != 0) ! throw runtime_error ("You can only call this function once"); ! for (int t = 0; t < num; t++) ! _analogIns.push_back (new CAnalogIn (this, t)); } ! CInterfaceKit::CInterfaceKit (CInterfaceKit * orig): ! CPhidget (orig) { ! for (int t = 0; t < orig->_digitalIns.size (); t++) ! _digitalIns.push_back (new CDigitalIn (this, t)); ! for (int t = 0; t < orig->_digitalOuts.size (); t++) ! _digitalOuts.push_back (new CDigitalOut (this, t)); ! for (int t = 0; t < orig->_analogIns.size (); t++) ! _analogIns.push_back (new CAnalogIn (this, t)); } CInterfaceKit::~CInterfaceKit () { ! for (int t = 0; t < _digitalIns.size (); t++) ! delete _digitalIns[t]; ! for (int t = 0; t < _digitalOuts.size (); t++) ! delete _digitalOuts[t]; ! for (int t = 0; t < _analogIns.size (); t++) ! delete _analogIns[t]; } ! void ! CInterfaceKit::update () { ! // Do nothing, we can't test this yet } ! const vector < CDigitalIn * >& ! CInterfaceKit::digitalIns () const { ! return (_digitalIns); } ! const vector < CDigitalOut * >& ! CInterfaceKit::digitalOuts () const { ! return (_digitalOuts); } ! const vector < CAnalogIn * >& ! CInterfaceKit::analogIns () const { ! return (_analogIns); } ! CUniqueDevice * ! CInterfaceKit::find (const CUID & uid) { ! CUniqueDevice *temp; ! for (int t = 0; t < _digitalIns.size (); t++) ! { ! temp = _digitalIns[t]->find (uid); ! if (temp != NULL) ! return (temp); } ! for (int t = 0; t < _digitalOuts.size (); t++) ! { ! temp = _digitalOuts[t]->find (uid); ! if (temp != NULL) ! return (temp); } ! for (int t = 0; t < _analogIns.size (); t++) ! { ! temp = _analogIns[t]->find (uid); ! if (temp != NULL) ! return (temp); } ! return (NULL); } --- 16,126 ---- #include <phidget.h> ! CInterfaceKit::CInterfaceKit (phidget *device):CPhidget (device) { ! if (classType() != INTERFACE_KIT) ! throw runtime_error("Can't initialize a CInterfaceKit with a phidget that is not an interface kit"); ! switch (productID()) { default: ! { ! char temp[128]; ! sprintf(temp, "Unknown type of interface kit Vendor ID:0x0%x Product ID:0x0%x\n", vendorID(), productID()); ! throw runtime_error(temp); ! } } } ! void CInterfaceKit::setDigitalInCount(int num) { ! if (_digitalIns.size() != 0) ! throw runtime_error("You can only call this function once"); ! for (int t = 0; t < num; t++) ! _digitalIns.push_back(new CDigitalIn (this, t)); } ! void CInterfaceKit::setDigitalOutCount(int num) { ! if (_digitalOuts.size() != 0) ! throw runtime_error("You can only call this function once"); ! for (int t = 0; t < num; t++) ! _digitalOuts.push_back(new CDigitalOut (this, t)); } ! void CInterfaceKit::setAnalogInCount(int num) { ! if (_analogIns.size() != 0) ! throw runtime_error("You can only call this function once"); ! for (int t = 0; t < num; t++) ! _analogIns.push_back(new CAnalogIn (this, t)); } ! CInterfaceKit::CInterfaceKit (CInterfaceKit *orig):CPhidget (orig) { ! for (int t = 0; t < orig->_digitalIns.size(); t++) ! _digitalIns.push_back(new CDigitalIn (this, t)); ! for (int t = 0; t < orig->_digitalOuts.size(); t++) ! _digitalOuts.push_back(new CDigitalOut (this, t)); ! for (int t = 0; t < orig->_analogIns.size(); t++) ! _analogIns.push_back(new CAnalogIn (this, t)); } CInterfaceKit::~CInterfaceKit () { ! for (int t = 0; t < _digitalIns.size(); t++) ! delete _digitalIns[t]; ! for (int t = 0; t < _digitalOuts.size(); t++) ! delete _digitalOuts[t]; ! for (int t = 0; t < _analogIns.size(); t++) ! delete _analogIns[t]; } ! void CInterfaceKit::update() { ! // Do nothing, we can't test this yet } ! const vector <CDigitalIn *>&CInterfaceKit::digitalIns() const { ! return (_digitalIns); } ! const vector <CDigitalOut *>&CInterfaceKit::digitalOuts() const { ! return (_digitalOuts); } ! const vector <CAnalogIn *>&CInterfaceKit::analogIns() const { ! return (_analogIns); } ! CUniqueDevice *CInterfaceKit::find(const CUID &uid) { ! CUniqueDevice *temp; ! for (int t = 0; t < _digitalIns.size(); t++) { ! temp = _digitalIns[t]->find(uid); ! if (temp != NULL) ! return (temp); } ! for (int t = 0; t < _digitalOuts.size(); t++) { ! temp = _digitalOuts[t]->find(uid); ! if (temp != NULL) ! return (temp); } ! for (int t = 0; t < _analogIns.size(); t++) { ! temp = _analogIns[t]->find(uid); ! if (temp != NULL) ! return (temp); } ! return (NULL); } Index: CInterfaceKit.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CInterfaceKit.h,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CInterfaceKit.h 8 Sep 2002 18:59:54 -0000 1.3 --- CInterfaceKit.h 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 26,43 **** class CInterfaceKit:public CPhidget { ! private: ! friend class CPhidgetManager; ! vector < CDigitalIn * >_digitalIns; ! vector < CDigitalOut * >_digitalOuts; ! vector < CAnalogIn * >_analogIns; ! void setDigitalInCount (int num); ! void setDigitalOutCount (int num); ! void setAnalogInCount (int num); ! CInterfaceKit (phidget * device); ! public: /** * Constructor to be used when a user derives from this phidget, the user must --- 26,43 ---- class CInterfaceKit:public CPhidget { ! private: ! friend class CPhidgetManager; ! vector <CDigitalIn *>_digitalIns; ! vector <CDigitalOut *>_digitalOuts; ! vector <CAnalogIn *>_analogIns; ! void setDigitalInCount(int num); ! void setDigitalOutCount(int num); ! void setAnalogInCount(int num); ! CInterfaceKit (phidget *device); ! public: /** * Constructor to be used when a user derives from this phidget, the user must *************** *** 45,49 **** * pass it to this constructor, in the constructor of his derived type. */ ! CInterfaceKit (CInterfaceKit * orig); /** --- 45,49 ---- * pass it to this constructor, in the constructor of his derived type. */ ! CInterfaceKit (CInterfaceKit *orig); /** *************** *** 51,80 **** * back into the manager and notify it of the current state of the device */ ! virtual ~ CInterfaceKit (); /** * Resends servo information to the controller */ ! void update (); /** * Returns a vector of digital in's that are controlled by this object */ ! const vector < CDigitalIn * >&digitalIns () const; /** * Returns a vector of digital out's that are controlled by this object */ ! const vector < CDigitalOut * >&digitalOuts () const; /** * Returns a vector of analog in's that are controlled by this object */ ! const vector < CAnalogIn * >&analogIns () const; /** * */ ! CUniqueDevice *find (const CUID & uid); }; --- 51,80 ---- * back into the manager and notify it of the current state of the device */ ! virtual ~ CInterfaceKit (); /** * Resends servo information to the controller */ ! void update(); /** * Returns a vector of digital in's that are controlled by this object */ ! const vector <CDigitalIn *>&digitalIns() const; /** * Returns a vector of digital out's that are controlled by this object */ ! const vector <CDigitalOut *>&digitalOuts() const; /** * Returns a vector of analog in's that are controlled by this object */ ! const vector <CAnalogIn *>&analogIns() const; /** * */ ! CUniqueDevice *find(const CUID &uid); }; Index: CPhidget.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidget.cc,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CPhidget.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CPhidget.cc 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 14,91 **** #include <usb.h> ! CPhidget::CPhidget (const CUID & uid): ! CUniqueDevice (uid), ! _device (CPhidgetManager::getInstance ()->getDeviceHandle (uid)) { ! // Ask the phidget manager if we really exist as a device, if not throw an exception ! if (_device == NULL) ! throw runtime_error ("Phidget doesn't exist."); ! _last_wasAttached = phidgetAttached (_device) == 1; } CPhidget::~CPhidget () { ! phidgetClose (_device); } ! int ! CPhidget::classType () { ! //return(_device->type->deviceClass); ! return (phidgetTypeDeviceClass (phidgetType (_device))); } ! const char * ! CPhidget::name () { ! //return(_device->type->name); ! return (phidgetTypeName (phidgetType (_device))); } ! int ! CPhidget::vendorID () { ! //return(_device->type->vendorID); ! return (phidgetTypeVendorID (phidgetType (_device))); } ! int ! CPhidget::productID () { ! //return(_device->type->productID); ! return (phidgetTypeProductID (phidgetType (_device))); } ! bool CPhidget::isAttached () { ! //if (_device->attached==1) ! if (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 () { } --- 14,83 ---- #include <usb.h> ! CPhidget::CPhidget (const CUID &uid):CUniqueDevice (uid), ! _device(CPhidgetManager::getInstance()->getDeviceHandle(uid)) { ! // Ask the phidget manager if we really exist as a device, if not throw an exception ! if (_device == NULL) ! throw runtime_error("Phidget doesn't exist."); ! _last_wasAttached = phidgetAttached(_device) == 1; } CPhidget::~CPhidget () { ! phidgetClose(_device); } ! int CPhidget::classType() { ! //return(_device->type->deviceClass); ! return (phidgetTypeDeviceClass(phidgetType(_device))); } ! const char *CPhidget::name() { ! //return(_device->type->name); ! return (phidgetTypeName(phidgetType(_device))); } ! int CPhidget::vendorID() { ! //return(_device->type->vendorID); ! return (phidgetTypeVendorID(phidgetType(_device))); } ! int CPhidget::productID() { ! //return(_device->type->productID); ! return (phidgetTypeProductID(phidgetType(_device))); } ! bool CPhidget::isAttached() { ! //if (_device->attached==1) ! if (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() { } Index: CPhidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidget.h,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CPhidget.h 8 Sep 2002 18:59:54 -0000 1.3 --- CPhidget.h 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 22,36 **** class CPhidget:public CUniqueDevice { ! private: ! bool _last_wasAttached; ! //bool _userConstructed; ! //CPhidget *_replace; ! struct phidget *_device; ! // Some friends of phidget ! friend class CServoController; ! friend class CInterfaceKit; /** --- 22,36 ---- class CPhidget:public CUniqueDevice { ! private: ! bool _last_wasAttached; ! //bool _userConstructed; ! //CPhidget *_replace; ! struct phidget *_device; ! // Some friends of phidget ! friend class CServoController; ! friend class CInterfaceKit; /** *************** *** 38,63 **** * derives from CPhidget (ex. CServoController) */ ! CPhidget (phidget * device /*!< The libphidget phidget device handle */ ); ! protected: ! friend class CPhidgetManager; /** * The device that this CPhidget uses */ ! struct phidget *device () ! { ! return (_device); ! } /** * This checks to see if the device status has change. In the case of the base phidget * it checks if it is attached/detached. If a derived phidget overrides this method * it must call the base class method. ! */ virtual void processEvents (); /** * Was this phidget constructed by a user */ ! //bool userConstructed() const {return(_userConstructed);} /** --- 38,63 ---- * derives from CPhidget (ex. CServoController) */ ! CPhidget (phidget *device /*!< The libphidget phidget device handle */ ); ! protected: ! friend class CPhidgetManager; /** * The device that this CPhidget uses */ ! struct phidget *device() ! { ! return (_device); ! } /** * This checks to see if the device status has change. In the case of the base phidget * it checks if it is attached/detached. If a derived phidget overrides this method * it must call the base class method. ! */ virtual void processEvents(); /** * Was this phidget constructed by a user */ ! //bool userConstructed() const {return(_userConstructed);} /** *************** *** 65,89 **** * this will return NULL. */ ! //CPhidget *getReplacement() {return(_replace);} ! public: ! //CPhidget(CPhidget *orig /*!< The \a CPhidget that we are replacing */); //!< Users can create phidgets, but must pass an already available phidget to them. We must be derived from the same type as the phidget that get's passed in. ! CPhidget (const CUID & uid); ! virtual ~ CPhidget (); //!< If it is user constructed, this destructor replaces the original phidget back in the manager ! int classType (); //!< Get the device class as defined in the libphidget documentation. ! const char *name (); //!< Get the device name as defined in the libphidget documentation. ! int vendorID (); //!< Get the vendor ID as defined by the USB standard. ! int productID (); //!< Get the product ID as defined by the USB standard. ! bool isAttached (); //!< Returns if this device is attached or not. ! virtual void onAttach (); //!<This method is called when the device is attached. ! virtual void onDetach (); //!<This method is called when the device is detached. ! virtual void query (const EDeviceClass tp, set < CUID > &devices) ! { ! CUniqueDevice::query (tp, devices); ! if (tp == LP_PHIDGET) ! devices.insert (UID ()); ! } }; --- 65,89 ---- * this will return NULL. */ ! //CPhidget *getReplacement() {return(_replace);} ! public: ! //CPhidget(CPhidget *orig /*!< The \a CPhidget that we are replacing */); //!< Users can create phidgets, but must pass an already available phidget to them. We must be derived from the same type as the phidget that get's passed in. ! CPhidget (const CUID &uid); ! virtual ~ CPhidget (); //!< If it is user constructed, this destructor replaces the original phidget back in the manager ! int classType(); //!< Get the device class as defined in the libphidget documentation. ! const char *name(); //!< Get the device name as defined in the libphidget documentation. ! int vendorID(); //!< Get the vendor ID as defined by the USB standard. ! int productID(); //!< Get the product ID as defined by the USB standard. ! bool isAttached(); //!< Returns if this device is attached or not. ! virtual void onAttach(); //!<This method is called when the device is attached. ! virtual void onDetach(); //!<This method is called when the device is detached. ! virtual void query(const EDeviceClass tp, set < CUID >&devices) ! { ! CUniqueDevice::query(tp, devices); ! if (tp == LP_PHIDGET) ! devices.insert(UID()); ! } }; Index: CPhidgetManager.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.cc,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CPhidgetManager.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CPhidgetManager.cc 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 15,39 **** #include <set> ! IMPLEMENT_SINGLETON (CPhidgetManager); ! void ! CPhidgetManager::registerDevice (CUniqueDevice * dev) { ! _uniqueDevices.push_back (dev); } ! void ! CPhidgetManager::unregisterDevice (CUniqueDevice * dev) { ! vector < CUniqueDevice * >::iterator i; ! for (i = _uniqueDevices.begin (); i != _uniqueDevices.end (); i++) ! if (*i == dev) ! { ! _uniqueDevices.erase (i, i); ! return; ! } ! throw runtime_error ("Can't unregister a device that wasn't registered."); } --- 15,36 ---- #include <set> ! IMPLEMENT_SINGLETON(CPhidgetManager); ! void CPhidgetManager::registerDevice(CUniqueDevice *dev) { ! _uniqueDevices.push_back(dev); } ! void CPhidgetManager::unregisterDevice(CUniqueDevice *dev) { ! vector <CUniqueDevice *>::iterator i; ! for (i = _uniqueDevices.begin(); i != _uniqueDevices.end(); i++) ! if (*i == dev) { ! _uniqueDevices.erase(i, i); ! return; ! } ! throw runtime_error("Can't unregister a device that wasn't registered."); } *************** *** 72,178 **** CPhidgetManager::CPhidgetManager () { ! phidgetInit (1); ! /* ! // Build classes to handle and open all devices ! 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(); ! */ } CPhidgetManager::~CPhidgetManager () { ! /* ! for (int t=0;t<_phidgets.size();t++) ! { ! if (_phidgets[t]->userConstructed()) ! throw runtime_error("All user constructed phidgets must be deleted before the phidget manager is destroyed."); ! delete _phidgets[t]; ! } ! */ ! phidgetDeinit (); } ! vector < CUID > CPhidgetManager::query (const EDeviceClass tp) { ! set < CUID > devices; ! // 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 = phidgetGetPhidgets (&phidget_count); ! for (int t = 0; t < phidget_count; t++) ! { ! if ( ! (tp == LP_PHIDGET) || ! (tp == LP_ALL) || ! (tp == LP_SERVO_CONTROLLER ! && phidgetTypeDeviceClass (phidgetType (phidgets[t])) == ! LP_SERVO_CONTROLLER) || (tp == LP_INTERFACE_KIT ! && ! phidgetTypeDeviceClass (phidgetType ! (phidgets ! [t])) == ! LP_INTERFACE_KIT)) ! { ! CUID temp_uid (phidgetSerial (phidgets[t])); ! devices.insert (temp_uid); } } } ! // Ask each known device if it knows about any devices that match the type we are searching for ! if (tp == LP_ALL || tp == LP_SERVO || tp == LP_DIGITAL_IN ! || tp == LP_DIGITAL_OUT) ! { ! for (int t = 0; t < _uniqueDevices.size (); t++) ! _uniqueDevices[t]->query (tp, devices); } ! // get a vector of the CUID instead of a set ! vector < CUID > temp; ! for (set < CUID >::iterator i = devices.begin (); i != devices.end (); i++) ! temp.push_back (*i); ! return (temp); } ! struct phidget * ! CPhidgetManager::getDeviceHandle (const CUID & uid) { ! if (uid.id () != -1) ! throw runtime_error ("invalid UID to find phidget. id must be -1"); ! int phidget_count; ! struct phidget **phidgets = phidgetGetPhidgets (&phidget_count); ! for (int t = 0; t < phidget_count; t++) ! { ! // We open this device ! if (phidgetSerial (phidgets[t]) == uid.serial ()) ! { ! return (phidgetOpen (phidgets[t])); } } ! return (NULL); } --- 69,160 ---- CPhidgetManager::CPhidgetManager () { ! phidgetInit(1); ! /* ! // Build classes to handle and open all devices ! 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(); ! */ } CPhidgetManager::~CPhidgetManager () { ! /* ! for (int t=0;t<_phidgets.size();t++) ! { ! if (_phidgets[t]->userConstructed()) ! throw runtime_error("All user constructed phidgets must be deleted before the phidget manager is destroyed."); ! delete _phidgets[t]; ! } ! */ ! phidgetDeinit(); } ! vector <CUID >CPhidgetManager::query(const EDeviceClass tp) { ! set < CUID >devices; ! // 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 = phidgetGetPhidgets(&phidget_count); ! for (int t = 0; t < phidget_count; t++) { ! if ( ! (tp == LP_PHIDGET) || ! (tp == LP_ALL) || ! (tp == LP_SERVO_CONTROLLER ! && phidgetTypeDeviceClass(phidgetType(phidgets[t])) == ! LP_SERVO_CONTROLLER) || (tp == LP_INTERFACE_KIT ! && phidgetTypeDeviceClass(phidgetType(phidgets[t])) == LP_INTERFACE_KIT)) { ! CUID temp_uid(phidgetSerial(phidgets[t])); ! devices.insert(temp_uid); } } } ! // Ask each known device if it knows about any devices that match the type we are searching for ! if (tp == LP_ALL || tp == LP_SERVO || tp == LP_DIGITAL_IN || tp == LP_DIGITAL_OUT) { ! for (int t = 0; t < _uniqueDevices.size(); t++) ! _uniqueDevices[t]->query(tp, devices); } ! // get a vector of the CUID instead of a set ! vector <CUID >temp; ! for (set < CUID >::iterator i = devices.begin(); i != devices.end(); i++) ! temp.push_back(*i); ! return (temp); } ! struct phidget *CPhidgetManager::getDeviceHandle(const CUID &uid) { ! if (uid.id() != -1) ! throw runtime_error("invalid UID to find phidget. id must be -1"); ! int phidget_count; ! struct phidget **phidgets = phidgetGetPhidgets(&phidget_count); ! for (int t = 0; t < phidget_count; t++) { ! // We open this device ! if (phidgetSerial(phidgets[t]) == uid.serial()) { ! return (phidgetOpen(phidgets[t])); } } ! return (NULL); } *************** *** 189,288 **** //} ! bool CPhidgetManager::checkForEvents () { ! bool ! found = (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 (); } ! return (found); } ! CUniqueDevice * ! CPhidgetManager::find (const CUID & uid, bool create) { ! CUniqueDevice *temp; ! bool isPhidget = false; ! // Is this a phidget or a phidget device we are trying to find? ! // Look at all known devices for this ! for (int t = 0; t < _uniqueDevices.size (); t++) ! { ! temp = _uniqueDevices[t]->find (uid, create); ! if (temp != NULL) ! return (temp); } ! // Wasn't found , so let's return because we were not asked to create this device ! if (!create) ! return (NULL); ! // Not found, is it a phidget? or a phidget device ! if (uid.id () == -1) ! isPhidget = true; ! // Make sure the phidget CUID(uid.serial()) exists ! CUID tempUID (uid.serial ()); ! bool devfound = false; ! if (!isPhidget) ! for (int t = 0; t < _uniqueDevices.size (); t++) ! { ! if (_uniqueDevices[t]->UID () == uid) ! { ! devfound = true; ! break; ! } ! } ! // Device wasn't found, this is always true if isPhidget is true ! if (!devfound || isPhidget) ! { ! // Create tempUID, this is the tricky part. ! // How, without know about this phidget do we create it? ! temp = createPhidget (tempUID); ! if (isPhidget) ! return (temp); } ! // The base phidget should exists and can now create it for us. ! return (temp->find (uid, create)); } ! CPhidget * ! CPhidgetManager::createPhidget (const CUID & uid) { ! // This device better not exists, we assume that has already been checked. ! if (uid.id () != -1) ! throw runtime_error ("Id must be -1 for all phidgets"); ! CServoController *sc = new CServoController (uid); ! //_uniqueDevices.push_back(sc); ! return (sc); } --- 171,262 ---- //} ! bool CPhidgetManager::checkForEvents() { ! bool found = (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(); } ! return (found); } ! CUniqueDevice *CPhidgetManager::find(const CUID &uid, bool create) { ! CUniqueDevice *temp; ! bool isPhidget = false; ! // Is this a phidget or a phidget device we are trying to find? ! // Look at all known devices for this ! for (int t = 0; t < _uniqueDevices.size(); t++) { ! temp = _uniqueDevices[t]->find(uid, create); ! if (temp != NULL) ! return (temp); } ! // Wasn't found , so let's return because we were not asked to create this device ! if (!create) ! return (NULL); ! // Not found, is it a phidget? or a phidget device ! if (uid.id() == -1) ! isPhidget = true; ! // Make sure the phidget CUID(uid.serial()) exists ! CUID tempUID(uid.serial()); ! bool devfound = false; ! if (!isPhidget) ! for (int t = 0; t < _uniqueDevices.size(); t++) { ! if (_uniqueDevices[t]->UID() == uid) { ! devfound = true; ! break; ! } ! } ! // Device wasn't found, this is always true if isPhidget is true ! if (!devfound || isPhidget) { ! // Create tempUID, this is the tricky part. ! // How, without know about this phidget do we create it? ! temp = createPhidget(tempUID); ! if (isPhidget) ! return (temp); } ! // The base phidget should exists and can now create it for us. ! return (temp->find(uid, create)); } ! CPhidget *CPhidgetManager::createPhidget(const CUID &uid) { ! // This device better not exists, we assume that has already been checked. ! if (uid.id() != -1) ! throw runtime_error("Id must be -1 for all phidgets"); ! CServoController *sc = new CServoController (uid); ! //_uniqueDevices.push_back(sc); ! return (sc); } Index: CPhidgetManager.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.h,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CPhidgetManager.h 8 Sep 2002 18:59:54 -0000 1.3 --- CPhidgetManager.h 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 49,74 **** * Singleton object that manages all phidgets. */ ! 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 --- 49,74 ---- * Singleton object that manages all phidgets. */ ! 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,114 **** * 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 ! ); ! CServoController *servoController (const CUID & uid); ! //CInterfaceKit *interfaceKit( ! //const CUID &uid ! //); /** * */ ! CUniqueDevice *find (const CUID & uid, bool create = false); ! //CServoController *createServoController(const CUID &uid); --- 78,114 ---- * 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 ! ); ! CServoController *servoController(const CUID &uid); ! //CInterfaceKit *interfaceKit( ! //const CUID &uid ! //); /** * */ ! CUniqueDevice *find(const CUID &uid, bool create = false); ! //CServoController *createServoController(const CUID &uid); *************** *** 116,132 **** * This goes thru all currently attached phidgets and returns a vector of any servos available */ ! //vector<CServo *> servos() const; /** * Returns a uniquely identified servo or NULL if it is not attached */ ! //CServo * servo( ! //const CUID &id //<! Unique ID of servo ! //); /** * Check for attach/detach events (or any other events. */ ! bool checkForEvents (); --- 116,132 ---- * This goes thru all currently attached phidgets and returns a vector of any servos available */ ! //vector<CServo *> servos() const; /** * Returns a uniquely identified servo or NULL if it is not attached */ ! //CServo * servo( ! //const CUID &id //<! Unique ID of servo ! //); /** * Check for attach/detach events (or any other events. */ ! bool checkForEvents(); Index: CServo.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServo.cc,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CServo.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CServo.cc 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 27,60 **** */ ! CServo::CServo (CServoController * controller, const int id): ! CUniqueDevice (controller, id), ! _controller (controller), _position (0), _systemManaged (true) { } ! CServo::CServo (const CUID & uid): ! CUniqueDevice (uid), _position (0), _systemManaged (false) { ! // 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. ! _controller = ! dynamic_cast < ! CServoController * ! >(CPhidgetManager::getInstance ()->find (CUID (uid.serial ()), true)); ! // Let the controller know about this servo ! _controller->registerServo (this, uid.id ()); } CServo::~CServo () { ! if (!_systemManaged); ! _controller->unregisterServo (UID ()); } ! void ! CServo::position (float p) { ! _position = p; ! _controller->update (); } --- 27,56 ---- */ ! CServo::CServo (CServoController *controller, const int id):CUniqueDevice (controller, id), ! _controller(controller), _position(0), ! _systemManaged(true) { } ! CServo::CServo (const CUID &uid):CUniqueDevice (uid), _position(0), ! _systemManaged(false) { ! // 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. ! _controller = dynamic_cast < CServoController *>(CPhidgetManager::getInstance()->find(CUID (uid.serial()), true)); ! // Let the controller know about this servo ! _controller->registerServo(this, uid.id()); } CServo::~CServo () { ! if (!_systemManaged); ! _controller->unregisterServo(UID()); } ! void CServo::position(float p) { ! _position = p; ! _controller->update(); } Index: CServo.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServo.h,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CServo.h 8 Sep 2002 18:59:54 -0000 1.3 --- CServo.h 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 23,82 **** class CServo:public CUniqueDevice { ! private: ! friend class CServoController; ! CServoController *_controller; ! // This is the only real data for the servo ! float _position; ! bool _systemManaged; ! //CServo(CServoController *controller,int id, CServo *orig=NULL); ! public: ! CServo (CServoController * controller, const int id); ! CServo (const CUID & uid); ! virtual ~ CServo (); /** * Set's the current position of this servo */ ! void position (float percent //!< Percentage to turn this servo ! ); /** * Return the last position sent to the servo */ ! float position () const ! { ! return (_position); ! } /** * On controllers that support this it will return the real world * position of this servo. If it doesn't, it returns the same * as getPosition() ! */ float realPosition () const ! { ! return (position ()); ! } /** * Makes a copy of the servo, just the real data, not anything about * which controller it is attached to or other information set in the * constructor only ! */ const CServo & operator = (const CServo * a) { ! _position = a->_position; ! return (*this); ! } /** * No devices are contained in this device ! */ CServo *find (const CUID & uid) ! { ! return (NULL); ! } }; --- 23,82 ---- class CServo:public CUniqueDevice { ! private: ! friend class CServoController; ! CServoController *_controller; ! // This is the only real data for the servo ! float _position; ! bool _systemManaged; ! //CServo(CServoController *controller,int id, CServo *orig=NULL); ! public: ! CServo (CServoController *controller, const int id); ! CServo (const CUID &uid); ! virtual ~ CServo (); /** * Set's the current position of this servo */ ! void position(float percent //!< Percentage to turn this servo ! ); /** * Return the last position sent to the servo */ ! float position() const ! { ! return (_position); ! } /** * On controllers that support this it will return the real world * position of this servo. If it doesn't, it returns the same * as getPosition() ! */ float realPosition() const ! { ! return (position()); ! } /** * Makes a copy of the servo, just the real data, not anything about * which controller it is attached to or other information set in the * constructor only ! */ const CServo &operator = (const CServo *a) { ! _position = a->_position; ! return (*this); ! } /** * No devices are contained in this device ! */ CServo *find(const CUID &uid) ! { ! return (NULL); ! } }; Index: CServoController.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServoController.cc,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CServoController.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CServoController.cc 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 14,52 **** #include <phidget.h> ! CServoController::CServoController (const CUID & uid): ! CPhidget (uid), _servoCount (-1), _servos (NULL) { ! // Make sure it was constructed properly ! if (classType () != LP_SERVO_CONTROLLER) ! throw ! runtime_error ! ("Can't initialize a CServoController with a phidget that is not a servo controller"); ! switch (productID ()) ! { case 0x0038: ! { ! setServoCount (4); ! break; ! } case 0x0039: ! { ! setServoCount (1); ! break; ! } case 0x003B: ! { ! setServoCount (8); ! break; ! } default: ! { ! char temp[128]; ! sprintf (temp, ! "Unknown type of servo controller Vendor ID:0x0%x Product ID:0x0%x\n", ! vendorID (), productID ()); ! throw runtime_error (temp); ! } } } --- 14,47 ---- #include <phidget.h> ! CServoController::CServoController (const CUID &uid):CPhidget (uid), _servoCount(-1), ! _servos(NULL) { ! // Make sure it was constructed properly ! if (classType() != LP_SERVO_CONTROLLER) ! throw runtime_error("Can't initialize a CServoController with a phidget that is not a servo controller"); ! switch (productID()) { case 0x0038: ! { ! setServoCount(4); ! break; ! } case 0x0039: ! { ! setServoCount(1); ! break; ! } case 0x003B: ! { ! setServoCount(8); ! break; ! } default: ! { ! char temp[128]; ! sprintf(temp, "Unknown type of servo controller Vendor ID:0x0%x Product ID:0x0%x\n", vendorID(), productID()); ! throw runtime_error(temp); ! } } } *************** *** 54,128 **** CServoController::~CServoController () { ! for (int t = 0; t < _servoCount; t++) ! if (_servos[t].first) ! delete _servos[t].second; ! delete[]_servos; } ! CUniqueDevice * ! CServoController::find (const CUID & uid, bool create) { ! if (uid.serial () == UID ().serial () && uid.id () >= 0 ! && uid.id () < _servoCount) return (servo (uid.id (), create)); ! return (CPhidget::find (uid)); } ! CServo * ! CServoController::servo (const int id, bool create) { ! if (id < 0 || id >= _servoCount) ! throw runtime_error ("Invalid servo id"); ! if (create && _servos[id].second == NULL) ! { ! _servos[id].first = true; ! _servos[id].second = new CServo (this, id); } ! return (_servos[id].second); } ! void ! CServoController::registerServo (CServo * servo, int id) { ! if (id < 0 || id >= _servoCount) ! throw runtime_error ("Invalid servo id"); ! if (_servos[id].second != NULL) ! throw runtime_error ("This servo id is already being used."); ! _servos[id].first = false; ! _servos[id].second = servo; } ! void ! CServoController::unregisterServo (const CUID & uid) { ! if ((uid.id () < 0 && uid.id () >= _servoCount) ! || uid.serial () != UID ().serial ()) ! throw runtime_error ("Invalid servo id"); ! if (_servos[uid.id ()].first) ! throw runtime_error ("Can't unregister a system managed servo"); ! _servos[uid.id ()].first = true; ! _servos[uid.id ()].second = NULL; } ! void ! CServoController::setServoCount (int num) { ! _servoCount = num; ! _servos = new pair < bool, CServo * >[_servoCount]; ! for (int t = 0; t < _servoCount; t++) ! { ! _servos[t].first = true; ! _servos[t].second = NULL; } } --- 49,116 ---- CServoController::~CServoController () { ! for (int t = 0; t < _servoCount; t++) ! if (_servos[t].first) ! delete _servos[t].second; ! delete[]_servos; } ! CUniqueDevice *CServoController::find(const CUID &uid, bool create) { ! if (uid.serial() == UID().serial() && uid.id() >= 0 && uid.id() < _servoCount) ! return (servo(uid.id(), create)); ! return (CPhidget::find(uid)); } ! CServo *CServoController::servo(const int id, bool create) { ! if (id < 0 || id >= _servoCount) ! throw runtime_error("Invalid servo id"); ! if (create && _servos[id].second == NULL) { ! _servos[id].first = true; ! _servos[id].second = new CServo (this, id); } ! return (_servos[id].second); } ! void CServoController::registerServo(CServo *servo, int id) { ! if (id < 0 || id >= _servoCount) ! throw runtime_error("Invalid servo id"); ! if (_servos[id].second != NULL) ! throw runtime_error("This servo id is already being used."); ! _servos[id].first = false; ! _servos[id].second = servo; } ! void CServoController::unregisterServo(const CUID &uid) { ! if ((uid.id() < 0 && uid.id() >= _servoCount) ! || uid.serial() != UID().serial()) ! throw runtime_error("Invalid servo id"); ! if (_servos[uid.id()].first) ! throw runtime_error("Can't unregister a system managed servo"); ! _servos[uid.id()].first = true; ! _servos[uid.id()].second = NULL; } ! void CServoController::setServoCount(int num) { ! _servoCount = num; ! _servos = new pair < bool, CServo *>[_servoCount]; ! for (int t = 0; t < _servoCount; t++) { ! _servos[t].first = true; ! _servos[t].second = NULL; } } *************** *** 200,220 **** */ ! void ! CServoController::update () { ! if (_servoCount) ! { ! float p1 = 0, p2 = 0, p3 = 0, p4 = 0; ! if (_servoCount >= 1 && _servos[0].second != NULL) ! p1 = _servos[0].second->position (); ! if (_servoCount >= 2 && _servos[1].second != NULL) ! p2 = _servos[1].second->position (); ! if (_servoCount >= 3 && _servos[2].second != NULL) ! p3 = _servos[2].second->position (); ! if (_servoCount >= 4 && _servos[3].second != NULL) ! p4 = _servos[3].second->position (); ! phidgetQuadServo (device (), p1, p2, p3, p4); } } --- 188,206 ---- */ ! void CServoController::update() { ! if (_servoCount) { ! float p1 = 0, p2 = 0, p3 = 0, p4 = 0; ! if (_servoCount >= 1 && _servos[0].second != NULL) ! p1 = _servos[0].second->position(); ! if (_servoCount >= 2 && _servos[1].second != NULL) ! p2 = _servos[1].second->position(); ! if (_servoCount >= 3 && _servos[2].second != NULL) ! p3 = _servos[2].second->position(); ! if (_servoCount >= 4 && _servos[3].second != NULL) ! p4 = _servos[3].second->position(); ! phidgetQuadServo(device(), p1, p2, p3, p4); } } Index: CServoController.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServoController.h,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CServoController.h 8 Sep 2002 18:59:54 -0000 1.3 --- CServoController.h 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 23,45 **** class CServoController:public CPhidget { ! private: ! friend class CServo; ! //friend class CPhidgetManager; ! //vector<CServo *> _servos; ! int _servoCount; ! void setServoCount (int num); ! pair < bool, CServo * >*_servos; ! void registerServo (CServo *, int id); ! void unregisterServo (const CUID & uid); ! public: ! CServoController (const CUID & uid); ! //CServoController(phidget *device); /** --- 23,45 ---- class CServoController:public CPhidget { ! private: ! friend class CServo; ! //friend class CPhidgetManager; ! //vector<CServo *> _servos; ! int _servoCount; ! void setServoCount(int num); ! pair < bool, CServo *>*_servos; ! void registerServo(CServo *, int id); ! void unregisterServo(const CUID &uid); ! public: ! CServoController (const CUID &uid); ! //CServoController(phidget *device); /** *************** *** 48,52 **** * pass it to this constructor, in the constructor of his derived type. */ ! //CServoController(CServoController *orig); /** --- 48,52 ---- * pass it to this constructor, in the constructor of his derived type. */ ! //CServoController(CServoController *orig); /** *************** *** 54,88 **** * back into the manager and notify it of the current state of the device */ ! virtual ~ CServoController (); /** * Resends servo information to the controller */ ! void update (); /** * Returns a vector of servo's that are controlled by this object */ ! //const vector <CServo *> &servos() const; ! CUniqueDevice *find (const CUID & uid, bool create); /** * returns a previously created servo */ ! CServo *servo (int id, bool create = true); ! int servoCount () const ! { ! return (_servoCount); ! } ! virtual void query (const EDeviceClass tp, set < CUID > &devices) ! { ! CPhidget::query (tp, devices); ! if (tp == LP_SERVO || tp == LP_ALL) ! for (int t = 0; t < _servoCount; t++) ! devices.insert (CUID (UID ().serial (), t)); ! } }; --- 54,88 ---- * back into the manager and notify it of the current state of the device */ ! virtual ~ CServoController (); /** * Resends servo information to the controller */ ! void update(); /** * Returns a vector of servo's that are controlled by this object */ ! //const vector <CServo *> &servos() const; ! CUniqueDevice *find(const CUID &uid, bool create); /** * returns a previously created servo */ ! CServo *servo(int id, bool create = true); ! int servoCount() const ! { ! return (_servoCount); ! } ! virtual void query(const EDeviceClass tp, set < CUID >&devices) ! { ! CPhidget::query(tp, devices); ! if (tp == LP_SERVO || tp == LP_ALL) ! for (int t = 0; t < _servoCount; t++) ! devices.insert(CUID (UID().serial(), t)); ! } }; Index: CUID.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CUID.cc,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** CUID.cc 8 Sep 2002 18:59:54 -0000 1.3 --- CUID.cc 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 12,105 **** ! 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); - if (_id != id._id) - 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)); ! } --- 12,100 ---- ! 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 (_s... [truncated message content] |
From: Vadim T. <vt...@us...> - 2002-09-11 03:10:24
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory usw-pr-cvs1:/tmp/cvs-serv32136/src/examples Modified Files: Tag: INDENT phidget_c.c phidget_cpp.cc Log Message: Another massive commit - this time, the indent [supposedly] works fine and produces stable code, regardless of how many times it's been run. Hope this works... Index: phidget_c.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_c.c,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** phidget_c.c 8 Sep 2002 18:59:54 -0000 1.2 --- phidget_c.c 11 Sep 2002 03:10:22 -0000 1.2.2.1 *************** *** 18,88 **** */ int ! main (int argn, char *argv[]) { ! int t, count; ! struct phidget **phidgets; ! printf ("----------------------------------------\n"); ! printf ("Phidgets Device driver test.\n\n\n"); ! // Initialize libphiget, here is where the devices are actually retrieved by the library ! // We want the library to handle signals (passing it 1) ! phidgetInit (1); ! // Get an array of pointers to phidgets and a count of available phidgets ! phidgets = phidgetGetPhidgets (&count); ! printf ("Device count:%d\n", count); ! for (t = 0; t < count; t++) ! { ! unsigned char buffer[6]; ! float k; ! struct phidget *dev = phidgetOpen (phidgets[t]); // Open the phidget #t ! // Make sure we opened it successfully ! if (dev == NULL) ! { ! printf ("Can't open phidget:%s\n", ! phidgetErrorString (phidgetLastError ())); ! exit (0); } ! // Print out some information about this phidget ! printf ! ("Phidget Name:%s Vendor:0x0%x Product:0x0%x Serial#:%06d\n", ! phidgetTypeName (phidgetType (dev)), ! phidgetTypeVendorID (phidgetType (dev)), ! phidgetTypeProductID (phidgetType (dev)), phidgetSerial (dev)); ! // Is it a servo controller ! if (phidgetTypeDeviceClass (phidgetType (dev)) == LP_SERVO_CONTROLLER) ! { ! for (k = 0; k < 1; k += .1) ! { ! int i; ! // Move a single servo (will move servo 0 of a 1 or 4 servo controller) ! phidgetSingleServo (dev, k); ! // Wait a bit ! sleep (1); ! // Process any events that have occured, like attach/detach ! phidgetEvents (); } } ! // Close the phidget ! phidgetClose (dev); ! printf ("Finished\n"); } ! // done using all phidgets, free's phidget memory ! phidgetDeinit (); ! printf ("----------------------------------------\n"); ! return (0); } --- 18,82 ---- */ int ! main(int argn, char *argv[]) { ! int t, count; ! struct phidget **phidgets; ! printf("----------------------------------------\n"); ! printf("Phidgets Device driver test.\n\n\n"); ! // Initialize libphiget, here is where the devices are actually retrieved by the library ! // We want the library to handle signals (passing it 1) ! phidgetInit(1); ! // Get an array of pointers to phidgets and a count of available phidgets ! phidgets = phidgetGetPhidgets(&count); ! printf("Device count:%d\n", count); ! for (t = 0; t < count; t++) { ! unsigned char buffer[6]; ! float k; ! struct phidget *dev = phidgetOpen(phidgets[t]); // Open the phidget #t ! // Make sure we opened it successfully ! if (dev == NULL) { ! printf("Can't open phidget:%s\n", phidgetErrorString(phidgetLastError())); ! exit(0); } ! // Print out some information about this phidget ! printf ! ("Phidget Name:%s Vendor:0x0%x Product:0x0%x Serial#:%06d\n", ! phidgetTypeName(phidgetType(dev)), ! phidgetTypeVendorID(phidgetType(dev)), phidgetTypeProductID(phidgetType(dev)), phidgetSerial(dev)); ! // Is it a servo controller ! if (phidgetTypeDeviceClass(phidgetType(dev)) == LP_SERVO_CONTROLLER) { ! for (k = 0; k < 1; k += .1) { ! int i; ! // Move a single servo (will move servo 0 of a 1 or 4 servo controller) ! phidgetSingleServo(dev, k); ! // Wait a bit ! sleep(1); ! // Process any events that have occured, like attach/detach ! phidgetEvents(); } } ! // Close the phidget ! phidgetClose(dev); ! printf("Finished\n"); } ! // done using all phidgets, free's phidget memory ! phidgetDeinit(); ! printf("----------------------------------------\n"); ! return (0); } Index: phidget_cpp.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_cpp.cc,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** phidget_cpp.cc 8 Sep 2002 18:59:54 -0000 1.2 --- phidget_cpp.cc 11 Sep 2002 03:10:22 -0000 1.2.2.1 *************** *** 196,342 **** 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"); } void ! readUID (const string & arg) { ! bool colon_found = false; ! string temp; ! char last_char; ! int serial = -1; ! int id = -1; ! for (int t = 0; t < arg.length (); t++) ! { ! last_char = arg[t]; ! if (arg[t] == ':') ! { ! if (colon_found) ! throw runtime_error ("More than one colon found in UID\n"); ! colon_found = true; ! serial = atoi (temp.c_str ()); ! temp = ""; ! } ! else if (arg[t] >= '0' && arg[t] <= '9') ! { ! temp += arg.substr (t, 1); ! } ! else ! throw runtime_error ("Invalid character in UID:" + arg); } ! if (colon_found && temp.length () > 0 && last_char != ':') ! id = atoi (temp.c_str ()); ! else if (!colon_found) ! serial = atoi (temp.c_str ()); ! workingUID = CUID (serial, id); } void ! query () { ! if (workingUID.serial () == -1) ! throw runtime_error ("Must use parameter -u with query command\n"); ! CPhidgetManager *manager = CPhidgetManager::getInstance (); ! CUniqueDevice *dev = manager->find (workingUID, true); ! printf ("%-10s ", workingUID.asString ().c_str ()); ! printf (">> "); ! // What type of device is this? ! CPhidget *phidget; ! if ((phidget = dynamic_cast < CPhidget * >(dev)) != NULL) ! { ! printf ("Phidget [%s] ", phidget->name ()); ! } ! else ! { ! if (dynamic_cast < CServo * >(dev) != NULL) ! printf ("Servo "); } ! printf ("\n"); } void ! moveServo (const string & parm) { ! float p = atof (parm.c_str ()); ! CServo servo (workingUID); ! printf ("Moving servo to position %f\n", p); ! servo.position (p); ! sleep (1); } void ! help () { ! printf ("Arguments:\n\n"); ! printf (" -l (default) list all phidets \n"); ! printf (" -u {UID} set the working UID\n"); ! printf (" -q query the working UID\n"); ! printf (" -h help\n"); ! printf ! (" -p {percent} adjust the position of a servo referenced by UID\n"); ! printf ("\n"); } --- 196,328 ---- 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"); } void ! readUID(const string & arg) { ! bool colon_found = false; ! string temp; ! char last_char; ! int serial = -1; ! int id = -1; ! for (int t = 0; t < arg.length(); t++) { ! last_char = arg[t]; ! if (arg[t] == ':') { ! if (colon_found) ! throw runtime_error("More than one colon found in UID\n"); ! colon_found = true; ! serial = atoi(temp.c_str()); ! temp = ""; ! } else if (arg[t] >= '0' && arg[t] <= '9') { ! temp += arg.substr(t, 1); ! } else ! throw runtime_error("Invalid character in UID:" + arg); } ! if (colon_found && temp.length() > 0 && last_char != ':') ! id = atoi(temp.c_str()); ! else if (!colon_found) ! serial = atoi(temp.c_str()); ! workingUID = CUID (serial, id); } void ! query() { ! if (workingUID.serial() == -1) ! throw runtime_error("Must use parameter -u with query command\n"); ! CPhidgetManager *manager = CPhidgetManager::getInstance(); ! CUniqueDevice *dev = manager->find(workingUID, true); ! printf("%-10s ", workingUID.asString().c_str()); ! printf(">> "); ! // What type of device is this? ! CPhidget *phidget; ! if ((phidget = dynamic_cast < CPhidget *>(dev)) !=NULL) { ! printf("Phidget [%s] ", phidget->name()); ! } else { ! if (dynamic_cast < CServo *>(dev) != NULL) ! printf("Servo "); } ! printf("\n"); } void ! moveServo(const string & parm) { ! float p = atof(parm.c_str()); ! CServo servo(workingUID); ! printf("Moving servo to position %f\n", p); ! servo.position(p); ! sleep(1); } void ! help() { ! printf("Arguments:\n\n"); ! printf(" -l (default) list all phidets \n"); ! printf(" -u {UID} set the working UID\n"); ! printf(" -q query the working UID\n"); ! printf(" -h help\n"); ! printf(" -p {percent} adjust the position of a servo referenced by UID\n"); ! printf("\n"); } *************** *** 344,391 **** int ! processArgs (int argn, char *argv[]) { ! if (argn == 0) ! return (0); ! // Read an argument ! string arg = argv[0]; ! if (arg == "-u") // The unique device ID to work with { ! if (argn < 2) ! throw runtime_error ("Expected argument after -u"); ! string parm = argv[1]; ! readUID (parm); ! return (processArgs (argn - 2, argv + 2)); ! } ! else if (arg == "-q") ! { ! query (); ! return (processArgs (argn - 1, argv + 1)); ! } ! else if (arg == "-h") ! { ! help (); ! return (processArgs (argn - 1, argv + 1)); ! } ! else if (arg == "-l") ! { ! phidgets_ls (); ! return (processArgs (argn - 1, argv + 1)); ! } ! else if (arg == "-p") ! { ! if (argn < 2) ! throw runtime_error ("Expected argument after -p"); ! string parm = argv[1]; ! moveServo (parm); ! return (processArgs (argn - 2, argv + 2)); } ! throw runtime_error ("Invalid argument:" + arg); } --- 330,369 ---- int ! processArgs(int argn, char *argv[]) { ! if (argn == 0) ! return (0); ! // Read an argument ! string arg = argv[0]; ! if (arg == "-u") // The unique device ID to work with { ! if (argn < 2) ! throw runtime_error("Expected argument after -u"); ! string parm = argv[1]; ! readUID(parm); ! return (processArgs(argn - 2, argv + 2)); ! } else if (arg == "-q") { ! query(); ! return (processArgs(argn - 1, argv + 1)); ! } else if (arg == "-h") { ! help(); ! return (processArgs(argn - 1, argv + 1)); ! } else if (arg == "-l") { ! phidgets_ls(); ! return (processArgs(argn - 1, argv + 1)); ! } else if (arg == "-p") { ! if (argn < 2) ! throw runtime_error("Expected argument after -p"); ! string parm = argv[1]; ! moveServo(parm); ! return (processArgs(argn - 2, argv + 2)); } ! throw runtime_error("Invalid argument:" + arg); } *************** *** 394,421 **** int ! main (int argn, char *argv[]) { ! try ! { ! // What we are ! printf ("phidgets: a command line interface utility\n"); ! printf ("version $Revision$\n\n"); ! // No arguments ! if (argn <= 1) ! { ! phidgets_ls (); ! return (0); ! } ! // Recursive argument parser, remove the executable name ! return (processArgs (argn - 1, argv + 1)); ! } ! catch (const exception & e) ! { ! printf ("Exception: %s\n", e.what ()); ! return (-1); ! } ! return (0); } --- 372,396 ---- int ! main(int argn, char *argv[]) { ! try { ! // What we are ! printf("phidgets: a command line interface utility\n"); ! printf("version $Revision$\n\n"); ! // No arguments ! if (argn <= 1) { ! phidgets_ls(); ! return (0); ! } ! // Recursive argument parser, remove the executable name ! return (processArgs(argn - 1, argv + 1)); ! } ! catch(const exception & e) { ! printf("Exception: %s\n", e.what()); ! return (-1); ! } ! return (0); } |
From: Vadim T. <vt...@us...> - 2002-09-11 03:10:24
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory usw-pr-cvs1:/tmp/cvs-serv32136/src/libphidget Modified Files: Tag: INDENT phidget.c phidget.h Log Message: Another massive commit - this time, the indent [supposedly] works fine and produces stable code, regardless of how many times it's been run. Hope this works... Index: phidget.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** phidget.c 8 Sep 2002 18:59:54 -0000 1.3 --- phidget.c 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 43,67 **** struct phidget_type { ! /*! ! * Currently supported names are: ! * - RFID VID/PID ! * - QuadServo .1 Degree ! * - UniServo .1 Degree ! * - 8-AdvancedServo ! * - Interface Kit 884 ! * - Interface Kit 088 [...1772 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.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** phidget.h 8 Sep 2002 18:59:54 -0000 1.3 --- phidget.h 11 Sep 2002 03:10:22 -0000 1.3.2.1 *************** *** 59,82 **** enum EDeviceClass { ! LP_ALL = 1, /**< All devices match this */ ! // Actual phidget types ! 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_ENCODER = 400, /**< Currently unsupported */ ! LP_POWER = 500, /**< Currently unsupported */ ! LP_RFID = 600, /**< Currently unsupported */ ! LP_LED = 700, /**< Currently unsupported */ ! LP_TEXTLCD = 800, /**< Currently unsupported */ ! // Phidget devices, a phidget device is something a phidget controls ! LP_SERVO = 201, /**< Any servo that a servo controller controls */ ! LP_DIGITAL_IN = 301, /**< Any digital input that an interface kit controls */ ! LP_DIGITAL_OUT = 302, /**< Any digital output that an interface kit controls */ ! LP_ANALOG_IN = 303, /**< Any analog input that an interface kit controls */ ! LP_OTHER = 0, /**< Identifies all unknown phidgets, this shouldn't exists */ ! LP_INVALID = -2, /**< Invalid device class */ }; --- 59,82 ---- enum EDeviceClass { ! LP_ALL = 1, /**< All devices match this */ ! // Actual phidget types ! 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_ENCODER = 400, /**< Currently unsupported */ ! LP_POWER = 500, /**< Currently unsupported */ ! LP_RFID = 600, /**< Currently unsupported */ ! LP_LED = 700, /**< Currently unsupported */ ! LP_TEXTLCD = 800, /**< Currently unsupported */ ! // Phidget devices, a phidget device is something a phidget controls ! LP_SERVO = 201, /**< Any servo that a servo controller controls */ ! LP_DIGITAL_IN = 301, /**< Any digital input that an interface kit controls */ ! LP_DIGITAL_OUT = 302, /**< Any digital output that an interface kit controls */ ! LP_ANALOG_IN = 303, /**< Any analog input that an interface kit controls */ ! LP_OTHER = 0, /**< Identifies all unknown phidgets, this shouldn't exists */ ! LP_INVALID = -2, /**< Invalid device class */ }; *************** *** 87,107 **** enum ELPError { ! LPE_NONE = 0, /**< No error has occured */ ! LPE_PHIDGET_NOT_ATTACHED = 1, /**< Phidget is not attached, this is really a warning */ ! LPE_UNKNOWN = -1, /**< An unknown error has occured */ ! LPE_INVALID_PHIDGET_CLASS = LP_INVALID, /**< Invalid device class (same as LP_INVALID), most likely the device class was NULL */ ! LPE_INVALID_PHIDGET = -3, /**< Invalid phidget, most likely the phidget was NULL */ ! LPE_NOT_INITIALIZED = -4, /**< libphidget hasn't been initialized */ ! LPE_WRONG_PHIDGET_CLASS_TYPE = -5, /**< The wrong device class type was passed to a function */ ! LPE_UNKNOWN_PHIDGET_CLASS_TYPE = -6, /**< An unknown device class type was passed to a function */ ! LPE_SET_CONFIGURATION_FAILED = -7, /**< During the initialization of a phidget the configuration for the USB device could not be set */ ! LPE_CLAIM_INTERFACE_FAILED = -8, /**< During the initialization of a phidget the interface for the USB device could not be claimed */ ! LPE_SET_ALT_INTERFACE_FAILED = -9, /**< During the initialization of a phidget the alternate interface for the USB device could not be set */ ! LPE_NO_SERIAL_RETURNED = -10, /**< The serial number could not be requested from the phidget */ ! LPE_PHIDGET_ALREADY_CLOSED = -11, /**< Phidget is already closed */ ! LPE_PHIDGET_ALREADY_OPENED = -12, /**< Phidget is already opened */ ! LPE_PHIDGET_NOT_OPENED = -13, /**< Phidget is not opened */ ! LPE_CONTROL_MSG_ERROR = -14, /**< Error sending a control message to a phidget */ ! LPE_BULK_READ_ERROR = -15 /**< Error reading bulk data from a phidget */ }; --- 87,107 ---- enum ELPError { ! LPE_NONE = 0, /**< No error has occured */ ! LPE_PHIDGET_NOT_ATTACHED = 1, /**< Phidget is not attached, this is really a warning */ ! LPE_UNKNOWN = -1, /**< An unknown error has occured */ ! LPE_INVALID_PHIDGET_CLASS = LP_INVALID, /**< Invalid device class (same as LP_INVALID), most likely the device class was NULL */ ! LPE_INVALID_PHIDGET = -3, /**< Invalid phidget, most likely the phidget was NULL */ ! LPE_NOT_INITIALIZED = -4, /**< libphidget hasn't been initialized */ ! LPE_WRONG_PHIDGET_CLASS_TYPE = -5, /**< The wrong device class type was passed to a function */ ! LPE_UNKNOWN_PHIDGET_CLASS_TYPE = -6, /**< An unknown device class type was passed to a function */ ! LPE_SET_CONFIGURATION_FAILED = -7, /**< During the initialization of a phidget the configuration for the USB device could not be set */ ! LPE_CLAIM_INTERFACE_FAILED = -8, /**< During the initialization of a phidget the interface for the USB device could not be claimed */ ! LPE_SET_ALT_INTERFACE_FAILED = -9, /**< During the initialization of a phidget the alternate interface for the USB device could not be set */ ! LPE_NO_SERIAL_RETURNED = -10, /**< The serial number could not be requested from the phidget */ ! LPE_PHIDGET_ALREADY_CLOSED = -11, /**< Phidget is already closed */ ! LPE_PHIDGET_ALREADY_OPENED = -12, /**< Phidget is already opened */ ! LPE_PHIDGET_NOT_OPENED = -13, /**< Phidget is not opened */ ! LPE_CONTROL_MSG_ERROR = -14, /**< Error sending a control message to a phidget */ ! LPE_BULK_READ_ERROR = -15 /**< Error reading bulk data from a phidget */ }; *************** *** 119,128 **** * long as \a phidget_deinit is called between each call to \a phidget_init. */ ! enum ELPError phidgetInit (int catchSignals); /** Must be called at the end of your program. Frees some internal data * structures. If this isn't called then there will be memory leaks. */ ! enum ELPError phidgetDeinit (); /** --- 119,128 ---- * long as \a phidget_deinit is called between each call to \a phidget_init. */ ! enum ELPError phidgetInit(int catchSignals); /** Must be called at the end of your program. Frees some internal data * structures. If this isn't called then there will be memory leaks. */ ! enum ELPError phidgetDeinit(); /** *************** *** 130,134 **** * and phidgetLastError() will return the error code. */ ! struct phidget **phidgetGetPhidgets (int *numPhidgets); /** --- 130,134 ---- * and phidgetLastError() will return the error code. */ ! struct phidget **phidgetGetPhidgets(int *numPhidgets); /** *************** *** 136,147 **** * return the error code. */ ! struct phidget *phidgetOpen (struct phidget *phidget //<! The phidget that we want to open ! ); /** * Close a phidget */ ! enum ELPError phidgetClose (struct phidget *device //<! The phidget to be closed ! ); /** --- 136,147 ---- * return the error code. */ ! struct phidget *phidgetOpen(struct phidget *phidget //<! The phidget that we want to open ! ); /** * Close a phidget */ ! enum ELPError phidgetClose(struct phidget *device //<! The phidget to be closed ! ); /** *************** *** 150,157 **** * writing to. */ ! enum ELPError phidgetWrite (struct phidget *device, //<! The phidget to be written to ! char *bytes, //<! Pointer to data that is to be written to the device ! int size //<! Size in bytes of data pointed to by \a bytes ! ); /** --- 150,157 ---- * writing to. */ ! enum ELPError phidgetWrite(struct phidget *device, //<! The phidget to be written to ! char *bytes, //<! Pointer to data that is to be written to the device ! int size //<! Size in bytes of data pointed to by \a bytes ! ); /** *************** *** 159,166 **** * have an interface kit or any phidget that supports reads. */ ! enum ELPError phidgetRead (struct phidget *device, //<! The phidget to be read from ! char *bytes, //<! Pointer allocated large enough to hold \a size bytes of data ! int size //<! Size in bytes of data to read from device ! ); /** --- 159,166 ---- * have an interface kit or any phidget that supports reads. */ ! enum ELPError phidgetRead(struct phidget *device, //<! The phidget to be read from ! char *bytes, //<! Pointer allocated large enough to hold \a size bytes of data ! int size //<! Size in bytes of data to read from device ! ); /** *************** *** 171,177 **** * motion on your servo you can simple say percent = desired_angle / range. */ ! enum ELPError phidgetSingleServo (struct phidget *device, //<! The phidget to be controlled ! float percent //<! Percentage to move servo 1 ! ); /** --- 171,177 ---- * motion on your servo you can simple say percent = desired_angle / range. */ ! enum ELPError phidgetSingleServo(struct phidget *device, //<! The phidget to be controlled ! float percent //<! Percentage to move servo 1 ! ); /** *************** *** 179,185 **** * device is closed (either on purpose, or when the signal handler catches it) */ ! enum ELPError pidgetSingleServoDefault (struct phidget *device, //<! The phidget whose default we want to set ! float percent //!< Percentage to move servo 1 ! ); /** --- 179,185 ---- * device is closed (either on purpose, or when the signal handler catches it) */ ! enum ELPError pidgetSingleServoDefault(struct phidget *device, //<! The phidget whose default we want to set ! float percent //!< Percentage to move servo 1 ! ); /** *************** *** 190,199 **** * motion on your servo you can simple say percent = desired_angle / range. */ ! enum ELPError phidgetQuadServo (struct phidget *device, //!< The phidget to be contorlled ! float percent1, //!< Percentage to move servo 1 ! float percent2, //!< Percentage to move servo 2 ! float percent3, //!< Percentage to move servo 3 ! float percent4 //!< Percentage to move servo 4 ! ); /** --- 190,199 ---- * motion on your servo you can simple say percent = desired_angle / range. */ ! enum ELPError phidgetQuadServo(struct phidget *device, //!< The phidget to be contorlled ! float percent1, //!< Percentage to move servo 1 ! float percent2, //!< Percentage to move servo 2 ! float percent3, //!< Percentage to move servo 3 ! float percent4 //!< Percentage to move servo 4 ! ); /** *************** *** 201,210 **** * 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 ! float percent3, //!< Percentage to move servo 3 ! float percent4 //!< Percentage to move servo 4 ! ); /** --- 201,210 ---- * 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 ! float percent3, //!< Percentage to move servo 3 ! float percent4 //!< Percentage to move servo 4 ! ); /** *************** *** 217,221 **** * then when it is reconnected you will be re-attached to the same USB device. */ ! int phidgetEvents (); --- 217,221 ---- * then when it is reconnected you will be re-attached to the same USB device. */ ! int phidgetEvents(); *************** *** 224,233 **** * a NULL and phidgetLastError() will return the error code. */ ! const struct phidget_type *phidgetType (const struct phidget *device); /** * Return the serial number from a phidget. If an error occurs it returns an \a ELPError equivalent error number. */ ! int phidgetSerial (const struct phidget *device); /** --- 224,233 ---- * a NULL and phidgetLastError() will return the error code. */ ! const struct phidget_type *phidgetType(const struct phidget *device); /** * Return the serial number from a phidget. If an error occurs it returns an \a ELPError equivalent error number. */ ! int phidgetSerial(const struct phidget *device); /** *************** *** 235,269 **** * a NULL and phidgetLastError() will return the error code. */ ! const char *phidgetTypeName (const struct phidget_type *tp); /** * Returns the product ID of a phidget type If an error occurs it returns an \a ELPError equivalent error number. */ ! int phidgetTypeProductID (const struct phidget_type *tp); /** * Returns a vendor ID of a phidget type If an error occurs it returns an \a ELPError equivalent error number. */ ! int phidgetTypeVendorID (const struct phidget_type *tp); /** * Returns the device class of a phidget type If an error occurs it returns an \a ELPError equivalent error number. */ ! enum EDeviceClass phidgetTypeDeviceClass (const struct phidget_type *tp); /** * Returns 1 if a phidget is attached, 0 if it isn't attached. If an error occurs it returns an \a ELPError equivalent error number. */ ! int phidgetAttached (const struct phidget *device); /** * Returns the last error that occured. No defined error can occur during this call. */ ! enum ELPError phidgetLastError (); /** * Returns a human readable string that describes the error number. */ ! const char *phidgetErrorString (const enum ELPError err); --- 235,269 ---- * a NULL and phidgetLastError() will return the error code. */ ! const char *phidgetTypeName(const struct phidget_type *tp); /** * Returns the product ID of a phidget type If an error occurs it returns an \a ELPError equivalent error number. */ ! int phidgetTypeProductID(const struct phidget_type *tp); /** * Returns a vendor ID of a phidget type If an error occurs it returns an \a ELPError equivalent error number. */ ! int phidgetTypeVendorID(const struct phidget_type *tp); /** * Returns the device class of a phidget type If an error occurs it returns an \a ELPError equivalent error number. */ ! enum EDeviceClass phidgetTypeDeviceClass(const struct phidget_type *tp); /** * Returns 1 if a phidget is attached, 0 if it isn't attached. If an error occurs it returns an \a ELPError equivalent error number. */ ! int phidgetAttached(const struct phidget *device); /** * Returns the last error that occured. No defined error can occur during this call. */ ! enum ELPError phidgetLastError(); /** * Returns a human readable string that describes the error number. */ ! const char *phidgetErrorString(const enum ELPError err); |
From: Vadim T. <vt...@us...> - 2002-09-11 03:10:24
|
Update of /cvsroot/libphidget/libphidget In directory usw-pr-cvs1:/tmp/cvs-serv32136 Modified Files: Tag: INDENT indent.defs Log Message: Another massive commit - this time, the indent [supposedly] works fine and produces stable code, regardless of how many times it's been run. Hope this works... Index: indent.defs =================================================================== RCS file: /cvsroot/libphidget/libphidget/Attic/indent.defs,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** indent.defs 10 Sep 2002 03:27:46 -0000 1.1.2.2 --- indent.defs 11 Sep 2002 03:10:21 -0000 1.1.2.3 *************** *** 24,25 **** --- 24,27 ---- -T<CUID> -Tvector + -Tprivate + -Tpublic |
From: Vadim T. <vt...@us...> - 2002-09-11 02:35:33
|
Update of /cvsroot/libphidget/libphidget In directory usw-pr-cvs1:/tmp/cvs-serv23520 Modified Files: Tag: INDENT indent.rules Log Message: Set of rules that are aestetically [marginally] acceptable and don't cause the code to flip-flop between 'make indent' runs... Index: indent.rules =================================================================== RCS file: /cvsroot/libphidget/libphidget/indent.rules,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** indent.rules 10 Sep 2002 03:27:46 -0000 1.1.2.1 --- indent.rules 11 Sep 2002 02:35:29 -0000 1.1.2.2 *************** *** 1,5 **** ! --gnu-style --dont-format-comments - --blank-lines-after-block-comments --honour-newlines --line-length128 --- 1,24 ---- ! --no-blank-lines-after-declarations ! --blank-lines-after-procedures ! --no-blank-lines-after-commas ! --break-before-boolean-operator ! --braces-on-if-line ! --brace-indent4 ! --braces-after-struct-decl-line ! --no-comment-delimiters-on-blank-lines ! --cuddle-else ! --else-endif-column1 ! --space-after-cast ! --declaration-indentation4 ! --dont-format-first-column-comments --dont-format-comments --honour-newlines + --indent-level4 + --parameter-indentation5 + --continue-at-parentheses + --no-space-after-function-call-names + --no-space-after-parentheses + --procnames-start-lines + --dont-star-comments + --leave-optional-blank-lines --line-length128 |
From: Vadim T. <vt...@us...> - 2002-09-11 02:31:05
|
Update of /cvsroot/libphidget/libphidget In directory usw-pr-cvs1:/tmp/cvs-serv22591 Modified Files: Tag: INDENT Makefile.am Log Message: Fixed the bug when bad indent rules resulted in all the content files being lost Index: Makefile.am =================================================================== RCS file: /cvsroot/libphidget/libphidget/Makefile.am,v retrieving revision 1.6.2.1 retrieving revision 1.6.2.2 diff -C2 -d -r1.6.2.1 -r1.6.2.2 *** Makefile.am 10 Sep 2002 03:01:33 -0000 1.6.2.1 --- Makefile.am 11 Sep 2002 02:31:02 -0000 1.6.2.2 *************** *** 18,21 **** --- 18,26 ---- @INDENT@ --ignore-profile --standard-output `@CAT@ ./indent.rules` `@CAT@ ./indent.defs` $$FILE > $$FILE.indent; \ if @TEST@ -n "`@DIFF@ $$FILE $$FILE.indent`" ; then \ + if @TEST@ ! -s $$FILE.indent ; then \ + @ECHO@ "@INDENT@ run resulted in an empty file: $$FILE.indent; most probably the options in ./indent.rules are wrong"; \ + @RM@ $$FILE.indent; \ + exit 1; \ + fi; \ @MV@ $$FILE.indent $$FILE; \ else \ *************** *** 34,37 **** --- 39,47 ---- @INDENT@ --standard-output `@CAT@ ./indent.defs` $$FILE > $$FILE.indent; \ if @TEST@ -n "`@DIFF@ $$FILE $$FILE.indent`" ; then \ + if @TEST@ ! -s $$FILE.indent ; then \ + @ECHO@ "@INDENT@ run resulted in an empty file: $$FILE.indent; most probably the options in ./indent.rules are wrong"; \ + @RM@ $$FILE.indent; \ + exit 1; \ + fi; \ @MV@ $$FILE.indent $$FILE; \ else \ |