[Libphidget-cvs-commits] CVS: libphidget/src/phidget++ CDigitalIn.h,1.12,1.13 CInterfaceKit.cc,1.11,
Status: Alpha
Brought to you by:
jstrohm
From: Jack S. <js...@us...> - 2002-12-18 02:51:20
|
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory sc8-pr-cvs1:/tmp/cvs-serv29738/src/phidget++ Modified Files: CDigitalIn.h CInterfaceKit.cc CInterfaceKit.h CPhidget.h CPhidgetManager.cc CServoController.h CSubDevice.h CUniqueDevice.h Log Message: Fixed a lot that was wrong with the query system. Seems to work pretty good now. Wrote an example of how to use the query system. Index: CDigitalIn.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** CDigitalIn.h 17 Dec 2002 23:39:16 -0000 1.12 --- CDigitalIn.h 18 Dec 2002 02:51:16 -0000 1.13 *************** *** 22,26 **** * is when the CPhidgetManager function is called. */ ! class CDigitalIn:public CSubDevice { private: --- 22,26 ---- * is when the CPhidgetManager function is called. */ ! class CDigitalIn : public CSubDevice { private: Index: CInterfaceKit.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CInterfaceKit.cc,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** CInterfaceKit.cc 17 Dec 2002 23:39:16 -0000 1.11 --- CInterfaceKit.cc 18 Dec 2002 02:51:16 -0000 1.12 *************** *** 28,32 **** _analogInOffset=0; _digitalInOffset=_analogInCount; ! _digitalOutOffset=_analogInCount+_digitalInOffset; return; } --- 28,33 ---- _analogInOffset=0; _digitalInOffset=_analogInCount; ! _digitalOutOffset=_analogInCount+_digitalInCount; ! return; } *************** *** 284,286 **** --- 285,306 ---- METHOD_UNGUARD; + } + + void CInterfaceKit::query(const EDeviceClass tp, set < CUID >&devices) + { + + CPhidget::query(tp,devices); + + if (tp==LP_ALL || tp==LP_DIGITAL_IN || tp==LP_IN || tp==LP_SUB_DEVICE) + for (int t=0;t<_digitalInCount;t++) + devices.insert(CUID(UID().serial(),t+_digitalInOffset)); + + if (tp==LP_ALL || tp==LP_ANALOG_IN || tp==LP_IN || tp==LP_SUB_DEVICE) + for (int t=0;t<_analogInCount;t++) + devices.insert(CUID(UID().serial(),t+_analogInOffset)); + + if (tp==LP_ALL || tp==LP_DIGITAL_OUT || tp==LP_OUT || tp==LP_SUB_DEVICE) + for (int t=0;t<_digitalOutCount;t++) + devices.insert(CUID(UID().serial(),t+_digitalOutOffset)); + } Index: CInterfaceKit.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CInterfaceKit.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** CInterfaceKit.h 17 Dec 2002 23:39:16 -0000 1.10 --- CInterfaceKit.h 18 Dec 2002 02:51:16 -0000 1.11 *************** *** 138,150 **** CDigitalOut *digitalOut(const int id, bool create=true); ! virtual void query(const EDeviceClass tp, set < CUID >&devices) ! { ! if (tp == LP_INTERFACE_KIT_488 || tp==LP_INTERFACE_KIT_880) ! { ! devices.insert(UID()); ! } ! else ! CPhidget::query(tp,devices); ! } }; --- 138,145 ---- CDigitalOut *digitalOut(const int id, bool create=true); ! /** ! * Query for any subdevices that match this criteria ! */ ! void query(const EDeviceClass tp, set < CUID >&devices); }; Index: CPhidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidget.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CPhidget.h 17 Dec 2002 22:56:17 -0000 1.8 --- CPhidget.h 18 Dec 2002 02:51:16 -0000 1.9 *************** *** 66,73 **** virtual void query(const EDeviceClass tp, set < CUID >&devices) { if (tp == LP_PHIDGET) devices.insert(UID()); - else - CUniqueDevice::query(tp, devices); } }; --- 66,78 ---- virtual void query(const EDeviceClass tp, set < CUID >&devices) { + CUniqueDevice::query(tp, devices); + + // This phidget device matches the tp they are searching for + if (tp == phidgetTypeDeviceClass(phidgetType(device()))) + devices.insert(UID()); + + // Just looking for a phidget if (tp == LP_PHIDGET) devices.insert(UID()); } }; Index: CPhidgetManager.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.cc,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** CPhidgetManager.cc 17 Dec 2002 03:10:10 -0000 1.13 --- CPhidgetManager.cc 18 Dec 2002 02:51:17 -0000 1.14 *************** *** 118,170 **** set < CUID >devices; - // Ask libphidget for any known phidgets - /* - if ( - tp == LP_ALL || - tp == LP_PHIDGET || - tp == LP_TEXT_LCD || - tp == LP_SERVO_CONTROLLER || - tp == LP_INTERFACE_KIT_488 || - tp == LP_INTERFACE_KIT_880 || - tp == LP_TEXT_LCD - ) - */ - { - int phidget_count; - struct phidget **phidgets = error(phidgetGetPhidgets(&phidget_count)); - for (int t = 0; t < phidget_count; t++) - { - CUID temp_uid(error(phidgetSerial(phidgets[t]))); - enum EDeviceClass dc=error(phidgetTypeDeviceClass(error(phidgetType(phidgets[t])))); - if (tp==dc) - devices.insert(temp_uid); - else - if (tp==LP_PHIDGET || tp==LP_ALL) - devices.insert(temp_uid); ! /* ! if ( ! (tp == LP_PHIDGET) || ! (tp == LP_ALL) || ! (tp == LP_TEXT_LCD) || ! (tp == LP_SERVO_CONTROLLER) || ! (tp == LP_INTERFACE_KIT_488) || ! (tp == LP_INTERFACE_KIT_880) ) ! { ! CUID temp_uid(error(phidgetSerial(phidgets[t]))); ! printf("found\n"); ! devices.insert(temp_uid); ! } ! */ ! } ! } ! // Ask each known device if it knows about any devices that match the type we are searching for { ! for (int t = 0; t < _uniqueDevices.size(); t++) ! _uniqueDevices[t]->query(tp, devices); } // get a vector of the CUID instead of a set --- 118,159 ---- set < CUID >devices; ! // Ask libphidget for any known phidgets, these would be real Phidgets ! // and nothing else ! ! // Get list of phidgets ! int phidget_count; ! struct phidget **phidgets = error(phidgetGetPhidgets(&phidget_count)); ! for (int t = 0; t < phidget_count; t++) { ! // Look at each phidget and figure out what device class ! // they are ! CUID temp_uid(error(phidgetSerial(phidgets[t]))); ! enum EDeviceClass dc=error(phidgetTypeDeviceClass(error(phidgetType(phidgets[t])))); ! ! // if the device class is exactly what we are looking for ! // then we have a mtach ! if (tp==dc) ! devices.insert(temp_uid); ! ! // If the device class is a phidget or ALL then we have found it. ! if (tp==LP_PHIDGET || tp==LP_ALL) ! devices.insert(temp_uid); ! ! // handle some special cases ! if (tp==LP_INTERFACE_KIT && dc==LP_INTERFACE_KIT_880) ! devices.insert(temp_uid); ! ! if (tp==LP_INTERFACE_KIT && dc==LP_INTERFACE_KIT_488) ! devices.insert(temp_uid); } + + // Ask each known device if it knows about any devices that match the type + // we are searching for + for (int t = 0; t < _uniqueDevices.size(); t++) + _uniqueDevices[t]->query(tp, devices); // get a vector of the CUID instead of a set Index: CServoController.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServoController.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CServoController.h 17 Dec 2002 23:39:16 -0000 1.7 --- CServoController.h 18 Dec 2002 02:51:17 -0000 1.8 *************** *** 21,25 **** * Object that represents all servo controllers (both hard and soft). */ ! class CServoController:public CPhidget { private: --- 21,25 ---- * Object that represents all servo controllers (both hard and soft). */ ! class CServoController : public CPhidget { private: *************** *** 79,83 **** CPhidget::query(tp, devices); ! if (tp == LP_SERVO || tp == LP_ALL) for (int t = 0; t < _servoCount; t++) devices.insert(CUID (UID().serial(), t)); --- 79,83 ---- CPhidget::query(tp, devices); ! if (tp == LP_SERVO || tp == LP_ALL || tp == LP_SUB_DEVICE ) for (int t = 0; t < _servoCount; t++) devices.insert(CUID (UID().serial(), t)); Index: CSubDevice.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CSubDevice.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CSubDevice.h 17 Dec 2002 22:56:17 -0000 1.2 --- CSubDevice.h 18 Dec 2002 02:51:17 -0000 1.3 *************** *** 65,68 **** --- 65,79 ---- { } + + /** + * Queries for any unique id devices that may exists, or are known how to create. + */ + virtual void query(const EDeviceClass tp, set < CUID >&devices) + { + CUniqueDevice::query(tp,devices); + + if (tp==LP_SUB_DEVICE) + devices.insert(UID()); + } }; Index: CUniqueDevice.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CUniqueDevice.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CUniqueDevice.h 17 Dec 2002 23:39:16 -0000 1.8 --- CUniqueDevice.h 18 Dec 2002 02:51:17 -0000 1.9 *************** *** 98,108 **** virtual void query(const EDeviceClass tp, set < CUID >&devices) { ! switch(tp) ! { ! case LP_ALL: ! case LP_SUB_DEVICE: ! devices.insert(_uid); ! break; ! } } --- 98,103 ---- virtual void query(const EDeviceClass tp, set < CUID >&devices) { ! if (tp==LP_ALL) ! devices.insert(UID()); } |