libphidget-cvs-commits Mailing List for Phidget Library (Page 2)
Status: Alpha
Brought to you by:
jstrohm
You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(66) |
Oct
|
Nov
|
Dec
(73) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(9) |
Jul
(5) |
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
(2) |
From: Jack S. <js...@us...> - 2002-12-21 03:31:43
|
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory sc8-pr-cvs1:/tmp/cvs-serv16418 Modified Files: CPhidgetManager.cc CPhidgetManager.h Log Message: More documentation Index: CPhidgetManager.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.cc,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** CPhidgetManager.cc 18 Dec 2002 02:51:17 -0000 1.14 --- CPhidgetManager.cc 21 Dec 2002 03:31:39 -0000 1.15 *************** *** 41,76 **** } - /* - void CPhidgetManager::addPossibleNewDevice(struct phidget *dev) - { - - // Does this device already exists? - for (int t=0;t<_phidgets.size();t++) - { - // We found already existing device, don't have to do anything - // the underlying library has already attached it - if (_phidgets[t]->_device==dev) - return; - } - - if (phidget_open(dev)==NULL) - throw runtime_error("Can't open phidget."); - - // What type of device is this? - switch(dev->type->deviceClass) - { - case SERVO_CONTROLLER: - _phidgets.push_back(new CServoController(dev)); - break; - case INTERFACE_KIT: - _phidgets.push_back(new CInterfaceKit(dev)); - break; - case OTHER: - phidget_close(dev); - break; - } - } - */ - CPhidgetManager::CPhidgetManager () { --- 41,44 ---- *************** *** 79,96 **** error(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(); - */ METHOD_UNGUARD; } --- 47,50 ---- *************** *** 99,113 **** { METHOD_GUARD; - /* - 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]; - } - */ error(phidgetDeinit()); METHOD_UNGUARD; } --- 53,59 ---- { METHOD_GUARD; error(phidgetDeinit()); + METHOD_UNGUARD; } *************** *** 118,124 **** set < CUID >devices; - - - // Ask libphidget for any known phidgets, these would be real Phidgets // and nothing else --- 64,67 ---- *************** *** 190,205 **** } - - //CPhidget *CPhidgetManager::phidget(const CUID &uid) - //{ - //// do we have a phidget with this id? - //return(dynamic_cast<CPhidget *>(find(uid))); - //} - - //CServoController *CPhidgetManager::servoController(const CUID &uid) - //{ - //return(dynamic_cast<CServoController *>(find(uid))); - //} - bool CPhidgetManager::checkForEvents() { --- 133,136 ---- *************** *** 226,230 **** // 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++) --- 157,160 ---- *************** *** 314,330 **** METHOD_UNGUARD; } - - /* - CServoController *CPhidgetManager::createServoController(const CUID &uid) - { - // Does a device by that ID exists? if so then we have an error - if (find(uid)!=NULL) - throw runtime_error("Can't create a default servo controller, because one already exists"); - - CServoController *sc=new CServoController(uid); - - _uniqueDevices.push_back(sc); - - return(sc); - } - */ --- 244,245 ---- Index: CPhidgetManager.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CPhidgetManager.h 17 Dec 2002 23:39:16 -0000 1.7 --- CPhidgetManager.h 21 Dec 2002 03:31:39 -0000 1.8 *************** *** 57,63 **** friend class CUniqueDevice; - vector <CUniqueDevice *>_uniqueDevices; - CPhidgetManager (); struct phidget *getDeviceHandle(const CUID &uid); CPhidget *createPhidget(const CUID &uid); --- 57,63 ---- friend class CUniqueDevice; CPhidgetManager (); + + vector <CUniqueDevice *>_uniqueDevices; struct phidget *getDeviceHandle(const CUID &uid); CPhidget *createPhidget(const CUID &uid); *************** *** 66,69 **** --- 66,70 ---- public: + /** * Deletes all currently allocated phidgets, only called when the application finishes *************** *** 78,99 **** * Returns a list of known devices currently available, filters based on tp */ ! vector <CUID >query(const EDeviceClass tp = LP_PHIDGET); /** * 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); /** ! * Search for any known devices (Phidgets or their sub-devices) that match this ! * unique id */ CUniqueDevice *find(const CUID &uid, bool create = false); /** ! * Check for attach/detach events (or any other events. */ bool checkForEvents(); --- 79,105 ---- * Returns a list of known devices currently available, filters based on tp */ ! vector <CUID >query( ! const EDeviceClass tp = LP_PHIDGET //<! The device class you are querying for ! ); /** * Returns a phidget by it's unique ID or NULL if it is not attached */ ! CPhidget *phidget ( ! const CUID &uid //<! Unique ID of phidget ); + /** + * Helper function to return a servo controller that matches the CUID or NULL is not attached. + */ CServoController *servoController(const CUID &uid); /** ! * Search for any known devices (Phidgets or their sub-devices) that match this unique id */ CUniqueDevice *find(const CUID &uid, bool create = false); /** ! * Check for attach/detach events (or any other events). */ bool checkForEvents(); |
From: Jack S. <js...@us...> - 2002-12-21 03:23:04
|
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory sc8-pr-cvs1:/tmp/cvs-serv14348 Modified Files: CPhidget.cc CPhidget.h Log Message: updated some documentation Index: CPhidget.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidget.cc,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CPhidget.cc 16 Sep 2002 06:43:33 -0000 1.6 --- CPhidget.cc 21 Dec 2002 03:23:01 -0000 1.7 *************** *** 10,13 **** --- 10,14 ---- #include "CPhidget.h" #include "CPhidgetManager.h" + #include <set> #include <string> #include <phidget.h> *************** *** 15,28 **** #include "helper.h" ! CPhidget::CPhidget (const CUID &uid):CUniqueDevice (uid), ! _device(CPhidgetManager::getInstance()->getDeviceHandle(uid)) { METHOD_GUARD; - // 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 = error(phidgetAttached(_device)) == 1; METHOD_UNGUARD; } --- 16,32 ---- #include "helper.h" ! CPhidget::CPhidget (const CUID &uid) : ! CUniqueDevice (uid), ! _device(CPhidgetManager::getInstance()->getDeviceHandle(uid)) { METHOD_GUARD; ! // Ask the phidget manager if we really exist as a device, if not throw an exception ! // as seen above, _device should have a non-null value if this phidget is attached (or ! // has been attached since the program started) ! if (_device == NULL) ! throw runtime_error("Phidget doesn't exist."); ! //_last_wasAttached = error(phidgetAttached(_device)) == 1; METHOD_UNGUARD; } *************** *** 31,35 **** { METHOD_GUARD; ! error(phidgetClose(_device)); METHOD_UNGUARD; } --- 35,39 ---- { METHOD_GUARD; ! error(phidgetClose(_device)); METHOD_UNGUARD; } *************** *** 38,42 **** { METHOD_GUARD; ! return (error(phidgetTypeDeviceClass(error(phidgetType(_device))))); METHOD_UNGUARD; } --- 42,46 ---- { METHOD_GUARD; ! return (error(phidgetTypeDeviceClass(error(phidgetType(_device))))); METHOD_UNGUARD; } *************** *** 45,49 **** { METHOD_GUARD; ! return (error(phidgetTypeName(error(phidgetType(_device))))); METHOD_UNGUARD; } --- 49,53 ---- { METHOD_GUARD; ! return (error(phidgetTypeName(error(phidgetType(_device))))); METHOD_UNGUARD; } *************** *** 52,56 **** { METHOD_GUARD; ! return (error(phidgetTypeVendorID(error(phidgetType(_device))))); METHOD_UNGUARD; } --- 56,60 ---- { METHOD_GUARD; ! return (error(phidgetTypeVendorID(error(phidgetType(_device))))); METHOD_UNGUARD; } *************** *** 59,63 **** { METHOD_GUARD; ! return (error(phidgetTypeProductID(error(phidgetType(_device))))); METHOD_UNGUARD; } --- 63,67 ---- { METHOD_GUARD; ! return (error(phidgetTypeProductID(error(phidgetType(_device))))); METHOD_UNGUARD; } *************** *** 66,73 **** { METHOD_GUARD; ! if (error(phidgetAttached(_device)) == 1) ! return (true); ! return (false); METHOD_UNGUARD; } --- 70,77 ---- { METHOD_GUARD; ! if (error(phidgetAttached(_device)) == 1) ! return (true); ! return (false); METHOD_UNGUARD; } *************** *** 94,96 **** --- 98,113 ---- METHOD_GUARD; METHOD_UNGUARD; + } + + void CPhidget::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: CPhidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidget.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CPhidget.h 18 Dec 2002 02:51:16 -0000 1.9 --- CPhidget.h 21 Dec 2002 03:23:01 -0000 1.10 *************** *** 24,48 **** { private: ! friend class CServoController; ! friend class CInterfaceKit; ! struct phidget *_device; /** ! * This constructor will only be called when a predefined phidget ! * 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); ! } /** --- 24,42 ---- { private: ! struct phidget *_device; //!< The libphidget phidget device that this CPhidget represents ! protected: /** ! * This constructor will be called by derived types to initialize a phidget */ ! CPhidget ( ! const CUID &uid //!< The CUID of the device you are creating ! ); /** * The device that this CPhidget uses */ ! struct phidget *device() { return (_device); } /** *************** *** 54,79 **** public: ! 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); ! ! // 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()); ! } }; --- 48,67 ---- public: ! 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. ! /** ! * Query for a device that matches the libphidget device class passed in. ! */ ! virtual void query( ! const EDeviceClass tp, //!< The device class we are looking for ! set < CUID >&devices //!< This will be filled with UID's of phidgets (or sub-objects) that match the device class ! ); }; |
From: Jack S. <js...@us...> - 2002-12-21 02:55:10
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory sc8-pr-cvs1:/tmp/cvs-serv8558 Modified Files: phidget.h Log Message: Minor spelling fix Index: phidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.h,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** phidget.h 19 Dec 2002 17:39:36 -0000 1.19 --- phidget.h 21 Dec 2002 02:55:07 -0000 1.20 *************** *** 108,113 **** /** ! * Libphidget error codes ! * An negative error is fatal, a postive error code (LPE_PHIDGET_NOT_ATTACHED) is a warning. */ enum ELPError --- 108,113 ---- /** ! * Libphidget error codes. ! * A negative error is fatal, a postive error code (LPE_PHIDGET_NOT_ATTACHED) is a warning. */ enum ELPError |
From: Jack S. <js...@us...> - 2002-12-19 17:39:43
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory sc8-pr-cvs1:/tmp/cvs-serv31576 Modified Files: phidget.h Log Message: Updated the documentation Index: phidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.h,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** phidget.h 18 Dec 2002 02:51:16 -0000 1.18 --- phidget.h 19 Dec 2002 17:39:36 -0000 1.19 *************** *** 19,28 **** * Theoretically it should be possible to use this library on any platform that * libusb supports but it has only been tested on linux. It may be used by itself ! * or in conjustion with the C++ phidget library also available on this site. If * you aren't familiar with phidgets don't ready any further, just go check them * out at <a href="http://www.phidgets.com>www.phidgets.com</a>.</p> * ! * <p>The starting place for this library is in the header, phidget.h. ! * </p> * */ --- 19,37 ---- * Theoretically it should be possible to use this library on any platform that * libusb supports but it has only been tested on linux. It may be used by itself ! * or in conjunction with the C++ phidget library also available on this site. If * you aren't familiar with phidgets don't ready any further, just go check them * out at <a href="http://www.phidgets.com>www.phidgets.com</a>.</p> * ! * <p>The starting place for this library is in the header, phidget.h.</p> ! * ! * <p>Below is a list of the different phidgets that are currently supported:</p> ! * <ul> ! * <li>Single Servo</li> ! * <li>Quad Servo</li> ! * <li>8-way Servo - coming soon</li> ! * <li>4/8/8 Interface Kit</li> ! * <li>8/8/0 Interface Kit - coming soon (keep your fingers crossed)</li> ! * <li>Text LCD</li> ! * </ul> * */ *************** *** 41,45 **** * and it has to look at all the USB devices again. When libusb adds a callback * I can make this more efficient, but it should be fine for now. The api shouldn't ! * change when they add that. */ --- 50,57 ---- * and it has to look at all the USB devices again. When libusb adds a callback * I can make this more efficient, but it should be fine for now. The api shouldn't ! * change when they add that.</p> ! * ! * <p>Also in this library are some "helper" functions that simplify writing data ! * to phidget servo controllers, lcds, and interface kits.</p> */ *************** *** 65,89 **** LP_SERVO_CONTROLLER = 200, /**< Identifies all servo controller phidgets */ LP_INTERFACE_KIT = 300, /**< Identifies all interface kit phidgets, support being added now */ LP_INTERFACE_KIT_880 = 301, /**< 880 interface kit */ LP_INTERFACE_KIT_488 = 302, /**< 488 interface kit */ LP_ENCODER = 400, /**< Currently unsupported */ LP_POWER = 500, /**< Currently unsupported */ LP_RFID = 600, /**< Currently unsupported */ LP_LED = 700, /**< Currently unsupported */ LP_TEXT_LCD = 800, /**< Text LCD */ // Phidget subdevices, a phidget subdevice is something a phidget controls LP_SUB_DEVICE = 101, /**< A SubDevice of a phidget, not used in this library */ ! LP_SERVO = 201, /**< Any servo that a servo controller controls */ ! LP_DIGITAL_IN = 394, /**< Any digital input that an interface kit controls */ ! LP_DIGITAL_OUT = 395, /**< Any digital output that an interface kit controls */ ! LP_ANALOG_IN = 396, /**< Any analog input that an interface kit controls */ ! LP_ANALOG_OUT = 397, /**< Any analog input that an interface kit controls */ ! LP_IN = 398, /**< Any input that an interface kit controls */ ! LP_OUT = 399, /**< Any output that an interface kit controls */ ! LP_OTHER = 0, /**< Identifies all unknown phidgets, this shouldn't exists */ ! LP_INVALID = -2, /**< Invalid device class */ }; --- 77,107 ---- LP_SERVO_CONTROLLER = 200, /**< Identifies all servo controller phidgets */ + LP_INTERFACE_KIT = 300, /**< Identifies all interface kit phidgets, support being added now */ LP_INTERFACE_KIT_880 = 301, /**< 880 interface kit */ LP_INTERFACE_KIT_488 = 302, /**< 488 interface kit */ + LP_ENCODER = 400, /**< Currently unsupported */ + LP_POWER = 500, /**< Currently unsupported */ + LP_RFID = 600, /**< Currently unsupported */ + LP_LED = 700, /**< Currently unsupported */ + LP_TEXT_LCD = 800, /**< Text LCD */ // Phidget subdevices, a phidget subdevice is something a phidget controls LP_SUB_DEVICE = 101, /**< A SubDevice of a phidget, not used in this library */ ! LP_SERVO = 201, /**< Sero sub-device, any servo that a servo controller controls */ ! LP_DIGITAL_IN = 394, /**< Digital in sub-device, any digital input that an interface kit controls */ ! LP_DIGITAL_OUT = 395, /**< Digltal out sub-device, any digital output that an interface kit controls */ ! LP_ANALOG_IN = 396, /**< Analog in sub-device, any analog input that an interface kit controls */ ! LP_ANALOG_OUT = 397, /**< Analog out sub-device, any analog input that an interface kit controls, currently phidget currently handles analog output */ ! LP_IN = 398, /**< Input sub-device, Any input that an interface kit controls */ ! LP_OUT = 399, /**< Output sub-device, Any output that an interface kit controls */ ! LP_OTHER = 0, /**< Identifies all unknown phidgets, this shouldn't exist */ ! LP_INVALID = -2, /**< Invalid device class, any negative device class is an error. */ }; *************** *** 119,290 **** #endif ! /** Must be called before before any other libphidget function. Right now this ! * initializes some internal structures and queries libusb for all USB devies, ! * looking for any phidgets. So any phidget plugged in after phidget_init is ! * called will not be detected. After libusb is modified to support attach/detach ! * events this library will be upgraded to support that functionality also. If ! * necessary it should be safe to call \a phidget_init multiple times as long as ! * 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(); ! /** ! * Returns a list of currently available phidgets If an error occurs then NULL is returned ! * and phidgetLastError() will return the error code. ! */ ! struct phidget **phidgetGetPhidgets(int *numPhidgets); ! /** ! * Open a phidget. If an error occurs then NULL is returned and phidgetLastError() will ! * 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 ); ! /** ! * Write some data to a phidget. Currently this function just uses a control ! * message, in the future it will adapt depending on the type of phidget we are ! * 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 ! ); ! /** ! * Read some data back from a phidget, haven't tested this yet because I don't ! * 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 ! ); ! /** ! * Send an angle (0.0 to 1.0) to a single servo. The phidget servo controllers ! * support a 12 bit 'angle', but this is arbitrary since different types of servos ! * support different ranges of motion. So I support a floating point 'percentage' ! * that controls the extent of rotation on the servo. If you know the range of ! * 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 ! ); ! /** ! * Sets the default value of the servo, this is the value the servo will be set to when the ! * 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 ! ); ! /** ! * Send an angle (0.0 to 1.0) to four servos. The phidget servo controllers ! * support a 12 bit 'angle', but this is arbitrary since different types of servos ! * support different ranges of motion. So I support a floating point 'percentage' ! * that controls the extent of rotation on the servo. If you know the range of ! * 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 ! ); ! /** ! * Sets the default value of the servo, this is the value the servo will be set to when the ! * device is closed (either on purpose, or when the signal handler catches it) ! */ ! enum ELPError phidgetQuadServoDefault(struct phidget *device, //<! The phidget whose default we want to set ! float percent1, //!< Percentage to move servo 1 ! float percent2, //!< Percentage to move servo 2 ! float percent3, //!< Percentage to move servo 3 ! float percent4 //!< Percentage to move servo 4 ! ); ! enum ELPError phidget8Servo(struct phidget *phidgetDevice, int id, float percent1, float maxvelocity, float acceleration); ! enum ELPError phidgetTextLCDOn(struct phidget *phidgetDevice); ! enum ELPError phidgetTextLCDOff(struct phidget *phidgetDevice); ! enum ELPError phidgetInterfaceKit488Read(struct phidget *phidgetDevice, float analog[4], int digital[8]); ! enum ELPError phidgetInterfaceKit880Read(struct phidget *phidgetDevice, float analog[8], int digital[8]); ! enum ELPError phidgetInterfaceKitWrite(struct phidget *phidgetDevice, int index, int value); ! enum ELPError phidgetTextLCDWrite(struct phidget *phidgetDevice, int row, int col, const char *str); ! enum ELPError phidgetTextLCDClear(struct phidget *phidgetDevice); ! /** ! * This checks for any new or changed devices, if anything has changed since the ! * last time this function has been called, then it returns 1, else it returns 0. If an ! * error occurs it returns an \a ELPError equivalent error number. ! * ! * This is an important function to call periodically. This performs the magic ! * of updating phidget structures. If you unplug a phidget that you have opened ! * then when it is reconnected you will be re-attached to the same USB device. ! */ ! int phidgetEvents(); ! /** ! * Return a phidget_type structure from a phidget device. If an error occurs it returns ! * 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); ! /** ! * Return the human readable description of a phidget type. If an error occurs it returns ! * 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); ! int phidgetWasAttached(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); --- 137,391 ---- #endif ! /** ! * Must be called before before any other libphidget function. Right now this ! * initializes some internal structures and queries libusb for all USB devies, ! * looking for any phidgets. So any phidget plugged in after phidget_init is ! * called will not be detected. After libusb is modified to support attach/detach ! * events this library will be upgraded to support that functionality also. If ! * necessary it should be safe to call \a phidget_init multiple times as long as ! * 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(); ! /** ! * Returns a list of currently available phidgets If an error occurs then NULL is returned ! * and phidgetLastError() will return the error code. ! */ ! struct phidget **phidgetGetPhidgets(int *numPhidgets); ! /** ! * Open a phidget. If an error occurs then NULL is returned and phidgetLastError() will ! * 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 ); ! /** ! * Write some data to a phidget. Currently this function just uses a control ! * message, in the future it will adapt depending on the type of phidget we are ! * 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 ! ); ! /** ! * Read some data back from a phidget, haven't tested this yet because I don't ! * 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 ! ); ! /** ! * Send an angle (0.0 to 1.0) to a single servo. The phidget servo controllers ! * support a 12 bit 'angle', but this is arbitrary since different types of servos ! * support different ranges of motion. So I support a floating point 'percentage' ! * that controls the extent of rotation on the servo. If you know the range of ! * 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 ! ); ! /** ! * Sets the default value of the servo, this is the value the servo will be set to when the ! * 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 ! ); ! /** ! * Send an angle (0.0 to 1.0) to four servos. The phidget servo controllers ! * support a 12 bit 'angle', but this is arbitrary since different types of servos ! * support different ranges of motion. So I support a floating point 'percentage' ! * that controls the extent of rotation on the servo. If you know the range of ! * 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 ! ); ! /** ! * Sets the default value of the servo, this is the value the servo will be set to when the ! * device is closed (either on purpose, or when the signal handler catches it) ! */ ! enum ELPError phidgetQuadServoDefault( ! struct phidget *device, //<! The phidget whose default we want to set ! float percent1, //!< Percentage to move servo 1 ! float percent2, //!< Percentage to move servo 2 ! float percent3, //!< Percentage to move servo 3 ! float percent4 //!< Percentage to move servo 4 ! ); ! //enum ELPError phidget8Servo(struct phidget *phidgetDevice, int id, float percent1, float maxvelocity, float acceleration); ! /** ! * Turns a Text LCD screen on. This does not clear the memory but simply turns the dispaly on. ! * So you can write to the display without it being on and when you switch it on it will show. ! */ ! enum ELPError phidgetTextLCDOn( ! struct phidget *phidgetDevice //!< The phidget to use ! ); ! ! /** ! * Turns a Text LCD screen off. This does not clear the memory. ! */ ! enum ELPError phidgetTextLCDOff( ! struct phidget *phidgetDevice //!< The phidget to use ! ); ! /** ! * Reads a 4/8/8 interface kit ! */ ! enum ELPError phidgetInterfaceKit488Read( ! struct phidget *phidgetDevice, //!< The phidget to read from ! float analog[4], //!< This will be filled with the value of the four analog inputs ! int digital[8] //!< This iwll be filled with the value of the four digital inputs. 1 is on, 0 is off. ! ); + /** + * Reads a 8/8/0 interface kit + */ + enum ELPError phidgetInterfaceKit880Read( + struct phidget *phidgetDevice, //!< The phidget to read from + float analog[8], //!< This will be filled with the value of eight analog inputs + int digital[8] //!< This will be filled with the value of eight digital inputs, 1 is on, 0 is off. + ); ! /** ! * Write data to any of the eight analog outputs of an interface kit (either 4/8/8 or 8/8/0). There are ! * no bounds checking on these values ! */ ! enum ELPError phidgetInterfaceKitWrite( ! struct phidget *phidgetDevice, //!< The phidget to write to ! int index, //!< The digital out to write a value to where 0 >= index < 8 is true. ! int value //!< The value either to write, 1 is on, 0 is off. ! ); ! /** ! * Writes a single line of text to a TextLCD screen. There are no bounds checking on these values. ! */ ! enum ELPError phidgetTextLCDWrite( ! struct phidget *phidgetDevice, //!< The phidget to write to ! int row, //!< The row to write the string where 0 >= row < 4 is true. ! int col, //!< The column to start the string on where 0 >= column < 12 is true. ! const char *str //!< The string to write. strlen(str)+col must be less than 12. ! ); ! /** ! * Sends four calls to phidgetTextLCDWrite clearing the screen. ! */ ! enum ELPError phidgetTextLCDClear( ! struct phidget *phidgetDevice //!< The phidget to write to ! ); ! /** ! * This checks for any new or changed devices, if anything has changed since the ! * last time this function has been called, then it returns 1, else it returns 0. If an ! * error occurs it returns an \a ELPError equivalent error number. ! * ! * This is an important function to call periodically. This performs the magic ! * of updating phidget structures. If you unplug a phidget that you have opened ! * then when it is reconnected you will be re-attached to the same USB device. ! */ ! int phidgetEvents(); ! /** ! * Return a phidget_type structure from a phidget device. If an error occurs it returns ! * a NULL and phidgetLastError() will return the error code. ! */ ! const struct phidget_type *phidgetType( ! const struct phidget *device //!< The phidget whose type you are requesting. ! ); ! /** ! * 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 //!< The phidget whose serial number you are requesting. ! ); ! /** ! * Return the human readable description of a phidget type. If an error occurs it returns ! * a NULL and phidgetLastError() will return the error code. ! */ ! const char *phidgetTypeName( ! const struct phidget_type *tp //!< Thep hidget whose type name you are requesting. ! ); ! ! /** ! * 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 //!< The phidget whose product ID you are requesting. ! ); + /** + * 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 //!< The phidget whose vendor ID you are requesting. + ); ! /** ! * 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 //!< The phidget whose type class you are requesting. ! ); ! /** ! * 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. ! * By calling phidgetAttached and phidgetWasAttached you can determine if the phidget just became attached or detached. ! */ ! int phidgetAttached( ! const struct phidget *device //!< The phidget whose attachment status you are requesting. ! ); ! ! /** ! * Returns the previous value that pridgetAttached would have returned. If an error occurs it returns an \a ELPError requivalent error number. ! * By calling phidgetAttached and phidgetWasAttached you can determine if the phidget just became attached or detached. ! */ ! int phidgetWasAttached( ! const struct phidget *device //!< The phidget whose previous attachment status you are requesting. ! ); ! ! ! /** ! * 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 //!< The error number you want made human readable ! ); |
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()); } |
From: Jack S. <js...@us...> - 2002-12-18 02:51:19
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory sc8-pr-cvs1:/tmp/cvs-serv29738/src/libphidget Modified Files: phidget.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: phidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.h,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** phidget.h 17 Dec 2002 23:39:15 -0000 1.17 --- phidget.h 18 Dec 2002 02:51:16 -0000 1.18 *************** *** 77,86 **** LP_SUB_DEVICE = 101, /**< A SubDevice of a phidget, not used in this library */ 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_ANALOG_OUT = 304, /**< Any analog input that an interface kit controls */ ! LP_IN = 305, /**< Any input that an interface kit controls */ ! LP_OUT = 306, /**< Any output that an interface kit controls */ LP_OTHER = 0, /**< Identifies all unknown phidgets, this shouldn't exists */ --- 77,86 ---- LP_SUB_DEVICE = 101, /**< A SubDevice of a phidget, not used in this library */ LP_SERVO = 201, /**< Any servo that a servo controller controls */ ! LP_DIGITAL_IN = 394, /**< Any digital input that an interface kit controls */ ! LP_DIGITAL_OUT = 395, /**< Any digital output that an interface kit controls */ ! LP_ANALOG_IN = 396, /**< Any analog input that an interface kit controls */ ! LP_ANALOG_OUT = 397, /**< Any analog input that an interface kit controls */ ! LP_IN = 398, /**< Any input that an interface kit controls */ ! LP_OUT = 399, /**< Any output that an interface kit controls */ LP_OTHER = 0, /**< Identifies all unknown phidgets, this shouldn't exists */ |
From: Jack S. <js...@us...> - 2002-12-18 02:51:19
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv29738/src/examples Modified Files: Makefile.am Added Files: query_example.cc 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. --- NEW FILE: query_example.cc --- #include <CPhidgetManager.h> #include <CInterfaceKit.h> #include <CDigitalIn.h> #include <CDigitalOut.h> #include <CAnalogIn.h> #include <CTextLCD.h> #include <unistd.h> static const char *revision="$Revision: 1.1 $"; main() { try { char adjusted_version[64]; memcpy(adjusted_version,revision+11,strlen(revision)-11-2); adjusted_version[strlen(revision)-11-2]=0; // What we are printf("query_example: shows how to query for different classes of phidgets and there devices\n"); // Get the version number printf("Version %s\n",adjusted_version); { vector<CUID> list=CPhidgetManager::getInstance()->query(LP_ALL); // Create as many phidgets as we can, so that they can let us know about there sub devices for (int t=0;t<list.size();t++) CUniqueDevice *p=CPhidgetManager::getInstance()->find(list[t],true); } printf("Device Totals:\n"); printf(" Devices:%d\n",CPhidgetManager::getInstance()->query(LP_ALL).size()); printf(" Phidgets:%d\n",CPhidgetManager::getInstance()->query(LP_PHIDGET).size()); printf(" Servo Controllers:%d\n",CPhidgetManager::getInstance()->query(LP_SERVO_CONTROLLER).size()); printf(" Interface Kits:%d\n",CPhidgetManager::getInstance()->query(LP_INTERFACE_KIT).size()); printf(" 880 Interface Kits:%d\n",CPhidgetManager::getInstance()->query(LP_INTERFACE_KIT_880).size()); printf(" 488 Interface Kits:%d\n",CPhidgetManager::getInstance()->query(LP_INTERFACE_KIT_488).size()); printf(" Text LCDs:%d\n",CPhidgetManager::getInstance()->query(LP_TEXT_LCD).size()); printf(" Sub devices:%d\n",CPhidgetManager::getInstance()->query(LP_SUB_DEVICE).size()); printf(" Servos:%d\n",CPhidgetManager::getInstance()->query(LP_SERVO).size()); printf(" Digital Inputs:%d\n",CPhidgetManager::getInstance()->query(LP_DIGITAL_IN).size()); printf(" Digital Outputs:%d\n",CPhidgetManager::getInstance()->query(LP_DIGITAL_OUT).size()); printf(" Analog Inputs:%d\n",CPhidgetManager::getInstance()->query(LP_ANALOG_IN).size()); printf(" Analog Outputs:%d\n",CPhidgetManager::getInstance()->query(LP_ANALOG_OUT).size()); printf(" Inputs:%d\n",CPhidgetManager::getInstance()->query(LP_IN).size()); printf(" Outputs:%d\n",CPhidgetManager::getInstance()->query(LP_OUT).size()); printf(" Other:%d\n",CPhidgetManager::getInstance()->query(LP_OTHER).size()); } 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.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Makefile.am 17 Dec 2002 03:10:10 -0000 1.4 --- Makefile.am 18 Dec 2002 02:51:16 -0000 1.5 *************** *** 1,3 **** ! bin_PROGRAMS = phidget_c phidget_cpp servo_example ik_example ik2lcd phidget_c_SOURCES = phidget_c.c --- 1,3 ---- ! bin_PROGRAMS = phidget_c phidget_cpp servo_example ik_example ik2lcd query_example phidget_c_SOURCES = phidget_c.c *************** *** 21,24 **** --- 21,28 ---- ik2lcd_LDADD = ../libphidget/libphidget.la ../phidget++/libphidget++.la ik2lcd_DEPENDENCIES = ../libphidget/libphidget.la ../phidget++/libphidget++.la + + query_example_SOURCES = query_example.cc + query_example_LDADD = ../libphidget/libphidget.la ../phidget++/libphidget++.la + query_example_DEPENDENCIES = ../libphidget/libphidget.la ../phidget++/libphidget++.la CFLAGS = -I../libphidget -L../libphidget |
From: Jack S. <js...@us...> - 2002-12-18 00:09:53
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv7835/examples Added Files: send.sh Log Message: Simple script that can take standard input and make it scroll down a Text LCD phidget --- NEW FILE: send.sh --- #!/bin/sh # Simple little script that uses pidget_cpp to send data out a TextLCD # use command line -u argument or change puid in here to the serial number # of your TextLCD # # Usage: # cat {somefile} | send.sh -u {phidget serial} # # so you could do this: # cat send.sh | send.sh -u 869 # # and the TextLCD would scroll the contents of that file # # or: # cat - | send.sh -u 869 # # Type stuff, and every time you press enter it will send to the phidget # # Enjoy! puid=869 if [ "$1" == "-u" ] then puid=$2 fi pcpp="./phidget_cpp -u $puid " $pcpp -t 0 0 " " $pcpp -t 1 0 " " $pcpp -t 2 0 " " $pcpp -t 3 0 " " $pcpp -ton cat - | while read a do aa=`printf "%-12s" "$a"` $pcpp -t 0 0 "$d" $pcpp -t 1 0 "$c" $pcpp -t 2 0 "$b" $pcpp -t 3 0 "$aa" d="$c" c="$b" b="$aa" done sleep 1 $pcpp -toff |
From: Jack S. <js...@us...> - 2002-12-17 23:57:05
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory sc8-pr-cvs1:/tmp/cvs-serv29511/libphidget Modified Files: phidget.h Log Message: Refactored, now UniqueDevices can have parents, and the different sub devices use the parent instead of their own instance of their controller. Started to work a bit on the query sub-system. Index: phidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.h,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** phidget.h 15 Dec 2002 22:55:25 -0000 1.16 --- phidget.h 17 Dec 2002 23:39:15 -0000 1.17 *************** *** 63,68 **** // 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_INTERFACE_KIT_880 = 301, /**< 880 interface kit */ LP_INTERFACE_KIT_488 = 302, /**< 488 interface kit */ --- 63,69 ---- // 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_INTERFACE_KIT_880 = 301, /**< 880 interface kit */ LP_INTERFACE_KIT_488 = 302, /**< 488 interface kit */ *************** *** 71,84 **** LP_RFID = 600, /**< Currently unsupported */ LP_LED = 700, /**< Currently unsupported */ ! LP_TEXT_LCD = 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 */ }; --- 72,90 ---- LP_RFID = 600, /**< Currently unsupported */ LP_LED = 700, /**< Currently unsupported */ ! LP_TEXT_LCD = 800, /**< Text LCD */ ! // Phidget subdevices, a phidget subdevice is something a phidget controls ! LP_SUB_DEVICE = 101, /**< A SubDevice of a phidget, not used in this library */ 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_ANALOG_OUT = 304, /**< Any analog input that an interface kit controls */ + LP_IN = 305, /**< Any input that an interface kit controls */ + LP_OUT = 306, /**< Any output that an interface kit controls */ LP_OTHER = 0, /**< Identifies all unknown phidgets, this shouldn't exists */ LP_INVALID = -2, /**< Invalid device class */ + }; |
From: Jack S. <js...@us...> - 2002-12-17 23:54:34
|
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory sc8-pr-cvs1:/tmp/cvs-serv29511/phidget++ Modified Files: CAnalogIn.cc CAnalogIn.h CDigitalIn.cc CDigitalIn.h CDigitalOut.cc CDigitalOut.h CInterfaceKit.cc CInterfaceKit.h CPhidgetManager.h CServo.cc CServo.h CServoController.h CTextLCD.cc CTextLCD.h CUID.h CUniqueDevice.h Log Message: Refactored, now UniqueDevices can have parents, and the different sub devices use the parent instead of their own instance of their controller. Started to work a bit on the query sub-system. Index: CAnalogIn.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CAnalogIn.cc,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CAnalogIn.cc 17 Dec 2002 21:29:46 -0000 1.9 --- CAnalogIn.cc 17 Dec 2002 23:39:16 -0000 1.10 *************** *** 15,19 **** CAnalogIn::CAnalogIn (CInterfaceKit *interfacekit, int id) : CSubDevice (interfacekit, id), - _interfaceKit(interfacekit), _value(0), _lastValue(0), --- 15,18 ---- *************** *** 32,39 **** // 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. ! _interfaceKit = dynamic_cast < CInterfaceKit *>(CPhidgetManager::getInstance()->find(CUID (uid.serial()), true)); // Let the controller know about this servo ! _interfaceKit->registerAnalogIn(this, uid.id()); METHOD_UNGUARD; --- 31,38 ---- // 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. ! parent(dynamic_cast < CInterfaceKit *>(CPhidgetManager::getInstance()->find(CUID (uid.serial()), true))); // Let the controller know about this servo ! interfaceKit().registerAnalogIn(this, uid.id()); METHOD_UNGUARD; *************** *** 44,48 **** METHOD_GUARD; if (!_systemManaged) ! _interfaceKit->unregisterAnalogIn(UID()); METHOD_UNGUARD; } --- 43,47 ---- METHOD_GUARD; if (!_systemManaged) ! interfaceKit().unregisterAnalogIn(UID()); METHOD_UNGUARD; } *************** *** 58,68 **** } ! float CAnalogIn::value() const { // If we don't have a new value then update our value if (!_newValue) ! _interfaceKit->update(); _newValue=false; return (_value); } --- 57,72 ---- } ! float CAnalogIn::value() { // If we don't have a new value then update our value if (!_newValue) ! interfaceKit().update(); _newValue=false; return (_value); + } + + CInterfaceKit &CAnalogIn::interfaceKit() + { + return(*(dynamic_cast<CInterfaceKit *>(parent()))); } Index: CAnalogIn.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CAnalogIn.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** CAnalogIn.h 17 Dec 2002 22:56:17 -0000 1.10 --- CAnalogIn.h 17 Dec 2002 23:39:16 -0000 1.11 *************** *** 26,30 **** friend class CInterfaceKit; - CInterfaceKit *_interfaceKit; float _value; float _lastValue; --- 26,29 ---- *************** *** 59,63 **** * one will be returned. */ ! float value() const; /** --- 58,62 ---- * one will be returned. */ ! float value(); /** *************** *** 70,81 **** return(_value); } - - /** - * No devices are contained in this device - */ - //CAnalogIn *find(const CUID &uid) - //{ - //return (NULL); - //} /** --- 69,72 ---- Index: CDigitalIn.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.cc,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** CDigitalIn.cc 17 Dec 2002 21:29:47 -0000 1.10 --- CDigitalIn.cc 17 Dec 2002 23:39:16 -0000 1.11 *************** *** 17,21 **** _value(false), _lastValue(false), - _interfaceKit(interfaceKit), _systemManaged(true) { --- 17,20 ---- *************** *** 32,39 **** // 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. ! _interfaceKit = dynamic_cast < CInterfaceKit *>(CPhidgetManager::getInstance()->find(CUID (uid.serial()), true)); // Let the controller know about this servo ! _interfaceKit->registerDigitalIn(this, uid.id()); METHOD_UNGUARD; --- 31,38 ---- // 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. ! parent(dynamic_cast < CInterfaceKit *>(CPhidgetManager::getInstance()->find(CUID (uid.serial()), true))); // Let the controller know about this servo ! interfaceKit().registerDigitalIn(this, uid.id()); METHOD_UNGUARD; *************** *** 44,48 **** METHOD_GUARD; if (!_systemManaged) ! _interfaceKit->unregisterDigitalIn(UID()); METHOD_UNGUARD; } --- 43,47 ---- METHOD_GUARD; if (!_systemManaged) ! interfaceKit().unregisterDigitalIn(UID()); METHOD_UNGUARD; } *************** *** 50,54 **** CInterfaceKit &CDigitalIn::interfaceKit() { ! return(*_interfaceKit); } --- 49,53 ---- CInterfaceKit &CDigitalIn::interfaceKit() { ! return(*(dynamic_cast<CInterfaceKit *>(parent()))); } *************** *** 63,71 **** } ! bool CDigitalIn::value() const { // If we don't have a new value then update our value if (!_newValue) ! _interfaceKit->update(); _newValue=false; --- 62,70 ---- } ! bool CDigitalIn::value() { // If we don't have a new value then update our value if (!_newValue) ! interfaceKit().update(); _newValue=false; Index: CDigitalIn.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** CDigitalIn.h 17 Dec 2002 22:56:17 -0000 1.11 --- CDigitalIn.h 17 Dec 2002 23:39:16 -0000 1.12 *************** *** 30,34 **** bool _lastValue; bool _systemManaged; - CInterfaceKit *_interfaceKit; mutable bool _newValue; --- 30,33 ---- *************** *** 59,63 **** * one will be returned. */ ! bool value() const; /** --- 58,62 ---- * one will be returned. */ ! bool value(); /** *************** *** 70,81 **** return(_value); } - - /** - * No devices are contained in this device - */ - //CDigitalIn *find(const CUID &uid) - //{ - //return (NULL); - //} /** --- 69,72 ---- Index: CDigitalOut.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalOut.cc,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CDigitalOut.cc 17 Dec 2002 22:56:17 -0000 1.9 --- CDigitalOut.cc 17 Dec 2002 23:39:16 -0000 1.10 *************** *** 13,17 **** CDigitalOut::CDigitalOut (CInterfaceKit *interfaceKit, int id) : CSubDevice (interfaceKit, id), - _interfaceKit(interfaceKit), _value(false), _systemManaged(true) --- 13,16 ---- *************** *** 24,29 **** if (_value) ! phidgetInterfaceKitWrite(_interfaceKit->device(),ordinal(),true); else ! phidgetInterfaceKitWrite(_interfaceKit->device(),ordinal(),false); } --- 23,33 ---- if (_value) ! phidgetInterfaceKitWrite(interfaceKit().device(),ordinal(),true); else ! phidgetInterfaceKitWrite(interfaceKit().device(),ordinal(),false); ! } ! ! CInterfaceKit &CDigitalOut::interfaceKit() ! { ! return(*(dynamic_cast<CInterfaceKit *>(parent()))); } Index: CDigitalOut.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalOut.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CDigitalOut.h 17 Dec 2002 22:56:17 -0000 1.9 --- CDigitalOut.h 17 Dec 2002 23:39:16 -0000 1.10 *************** *** 28,32 **** friend class CInterfaceKit; - CInterfaceKit *_interfaceKit; bool _value; bool _systemManaged; --- 28,31 ---- *************** *** 56,65 **** /** ! * No devices are contained in this device */ ! //CDigitalOut *find(const CUID &uid) ! //{ ! //return (NULL); ! //} }; --- 55,61 ---- /** ! * Returns a reference to the interface kit that this input is on. */ ! CInterfaceKit &interfaceKit() ; }; Index: CInterfaceKit.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CInterfaceKit.cc,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** CInterfaceKit.cc 17 Dec 2002 22:56:17 -0000 1.10 --- CInterfaceKit.cc 17 Dec 2002 23:39:16 -0000 1.11 *************** *** 266,270 **** } - /* CUniqueDevice *CInterfaceKit::find(const CUID &uid, bool create) { --- 266,269 ---- *************** *** 281,287 **** return (analogIn(uid.id()-_analogInOffset, create)); return (CPhidget::find(uid)); METHOD_UNGUARD; } - */ --- 280,286 ---- return (analogIn(uid.id()-_analogInOffset, create)); + return (CPhidget::find(uid)); METHOD_UNGUARD; } Index: CInterfaceKit.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CInterfaceKit.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CInterfaceKit.h 17 Dec 2002 22:56:17 -0000 1.9 --- CInterfaceKit.h 17 Dec 2002 23:39:16 -0000 1.10 *************** *** 117,121 **** void update(); ! //CUniqueDevice *find(const CUID &uid, bool create); /** --- 117,125 ---- void update(); ! /** ! * Search thru any subdevices for a device that matches ! * this find command ! */ ! CUniqueDevice *find(const CUID &uid, bool create); /** Index: CPhidgetManager.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CPhidgetManager.h 17 Dec 2002 22:56:17 -0000 1.6 --- CPhidgetManager.h 17 Dec 2002 23:39:16 -0000 1.7 *************** *** 89,93 **** /** ! * */ CUniqueDevice *find(const CUID &uid, bool create = false); --- 89,94 ---- /** ! * Search for any known devices (Phidgets or their sub-devices) that match this ! * unique id */ CUniqueDevice *find(const CUID &uid, bool create = false); Index: CServo.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServo.cc,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CServo.cc 17 Dec 2002 21:20:24 -0000 1.9 --- CServo.cc 17 Dec 2002 23:39:16 -0000 1.10 *************** *** 16,20 **** CServo::CServo(CServoController *controller, int id, CServo *orig) : CUniqueDevice(controller,id), ! _controller(controller), _position(0) { --- 16,20 ---- CServo::CServo(CServoController *controller, int id, CServo *orig) : CUniqueDevice(controller,id), ! servoController().controller), _position(0) { *************** *** 23,27 **** (*this)=(*orig); ! _controller=controller; } } --- 23,27 ---- (*this)=(*orig); ! servoController().controller; } } *************** *** 30,34 **** CServo::CServo (CServoController *controller, const int id) : CSubDevice (controller, id), - _controller(controller), _position(0), _systemManaged(true) --- 30,33 ---- *************** *** 39,43 **** CServo::CServo (const CUID &uid) : ! CSubDevice (uid), _position(0), _systemManaged(false) { --- 38,43 ---- CServo::CServo (const CUID &uid) : ! CSubDevice (uid), ! _position(0), _systemManaged(false) { *************** *** 45,52 **** // 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()); METHOD_UNGUARD; } --- 45,52 ---- // 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. ! parent(dynamic_cast < CServoController *>(CPhidgetManager::getInstance()->find(CUID (uid.serial()), true))); // Let the controller know about this servo ! servoController().registerServo(this, uid.id()); METHOD_UNGUARD; } *************** *** 56,60 **** METHOD_GUARD; if (!_systemManaged) ! _controller->unregisterServo(UID()); METHOD_UNGUARD; } --- 56,60 ---- METHOD_GUARD; if (!_systemManaged) ! servoController().unregisterServo(UID()); METHOD_UNGUARD; } *************** *** 64,68 **** METHOD_GUARD; _position = p; ! _controller->update(); METHOD_UNGUARD; } --- 64,73 ---- METHOD_GUARD; _position = p; ! servoController().update(); METHOD_UNGUARD; + } + + CServoController &CServo::servoController() + { + return(*(dynamic_cast<CServoController *>(parent()))); } Index: CServo.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServo.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CServo.h 17 Dec 2002 22:56:17 -0000 1.7 --- CServo.h 17 Dec 2002 23:39:16 -0000 1.8 *************** *** 26,30 **** friend class CServoController; - CServoController *_controller; float _position; bool _systemManaged; --- 26,29 ---- *************** *** 84,93 **** /** ! * No devices are contained in this device ! */ ! CServo *find(const CUID &uid) ! { ! return (NULL); ! } }; --- 83,89 ---- /** ! * Returns a reference to the servo controller that manages this servo ! */ ! CServoController &servoController(); }; Index: CServoController.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServoController.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CServoController.h 17 Dec 2002 22:56:17 -0000 1.6 --- CServoController.h 17 Dec 2002 23:39:16 -0000 1.7 *************** *** 55,59 **** /** ! * Returns a vector of servo's that are controlled by this object */ CUniqueDevice *find(const CUID &uid, bool create); --- 55,59 ---- /** ! * Search for any devices or sub-devices that match this uid */ CUniqueDevice *find(const CUID &uid, bool create); *************** *** 64,67 **** --- 64,70 ---- CServo *servo(int id, bool create = true); + /** + * Returns the number of servo's on this controller + */ int servoCount() const { *************** *** 69,72 **** --- 72,78 ---- } + /** + * Query for devices or sub-devices that match a certain class + */ virtual void query(const EDeviceClass tp, set < CUID >&devices) { Index: CTextLCD.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CTextLCD.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CTextLCD.cc 16 Dec 2002 04:54:56 -0000 1.2 --- CTextLCD.cc 17 Dec 2002 23:39:16 -0000 1.3 *************** *** 14,19 **** #include "helper.h" ! CTextLCD::CTextLCD (const CUID &uid) : ! CPhidget (uid) { METHOD_GUARD; --- 14,20 ---- #include "helper.h" ! CTextLCD::CTextLCD (const CUID &uid, bool autooff) : ! CPhidget (uid), ! _autooff(autooff) { METHOD_GUARD; *************** *** 29,46 **** { METHOD_GUARD; - METHOD_UNGUARD; - } ! CUniqueDevice *CTextLCD::find(const CUID &uid, bool create) ! { ! METHOD_GUARD; ! return (CPhidget::find(uid)); METHOD_UNGUARD; } ! void CTextLCD::update() { ! METHOD_GUARD; ! METHOD_UNGUARD; } --- 30,46 ---- { METHOD_GUARD; ! if (_autooff) ! off(); ! METHOD_UNGUARD; } ! void CTextLCD::clear() { ! sendText(" ",0,0); ! sendText(" ",1,0); ! sendText(" ",2,0); ! sendText(" ",3,0); } Index: CTextLCD.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CTextLCD.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CTextLCD.h 17 Dec 2002 03:10:10 -0000 1.3 --- CTextLCD.h 17 Dec 2002 23:39:16 -0000 1.4 *************** *** 23,35 **** { private: public: ! CTextLCD (const CUID &uid); virtual ~CTextLCD (); ! void update(); ! CUniqueDevice *find(const CUID &uid, bool create); void sendText(string text, int row, int col); void on(); void off(); virtual void query(const EDeviceClass tp, set < CUID >&devices) { --- 23,59 ---- { private: + bool _autooff; public: ! /** ! * Construct a Text LCD ! */ ! CTextLCD (const CUID &uid, bool autooff=false); ! ! /** ! * Destructor ! */ virtual ~CTextLCD (); ! ! /** ! * Send text to this display ! */ void sendText(string text, int row, int col); + + /** + * Clear this display + */ + void clear(); + + /** + * Turn the LCD on + */ void on(); + + /** + * Turn the LCD off + */ void off(); + virtual void query(const EDeviceClass tp, set < CUID >&devices) { Index: CUID.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CUID.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CUID.h 15 Dec 2002 20:40:11 -0000 1.5 --- CUID.h 17 Dec 2002 23:39:16 -0000 1.6 *************** *** 81,88 **** --- 81,97 ---- bool operator == (const CUID &id) const; + /** + * Less than operator + */ bool operator < (const CUID &id) const; + /** + * Greater than operator + */ bool operator > (const CUID &id) const; + /** + * Convert to string in the form 'serial:id' + */ string asString() const; }; Index: CUniqueDevice.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CUniqueDevice.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CUniqueDevice.h 17 Dec 2002 22:56:17 -0000 1.7 --- CUniqueDevice.h 17 Dec 2002 23:39:16 -0000 1.8 *************** *** 17,20 **** --- 17,23 ---- using namespace std; + /** + * Represents any device (Phidget or subdevice) that can be uniquely identified + */ class CUniqueDevice { *************** *** 22,51 **** CUID _uid; void init(); public: ! CUniqueDevice (const CUniqueDevice *dev, const int id) : ! _uid(dev, id) { init(); } CUniqueDevice (const CUID &uid) : ! _uid(uid) { init(); } const CUID &UID() const { return (_uid); } virtual ~CUniqueDevice (); /** * Looks for the specified unique id device. Classes that derive from this should ! * implement there own version to reveal any objects they can may contain. */ virtual CUniqueDevice *find(const CUID &uid, bool create = true) --- 25,87 ---- CUID _uid; + CUniqueDevice *_parent; void init(); + protected: + void parent(CUniqueDevice *parent) + { + _parent=parent; + } + public: ! /** ! * Construct a unique device that is a sub-device from another unique device ! * which is it's parent ! */ ! CUniqueDevice (CUniqueDevice *parent, const int id) : ! _uid(parent, id), ! _parent(parent) { init(); } + /** + * Construct a unique device that is a Phidget from a UID + */ CUniqueDevice (const CUID &uid) : ! _uid(uid), ! _parent(NULL) { init(); } + /** + * Returns a pointer to the parent of a unique device (a phidget) that is a sub-object. + * Returns NULL if this device is a phidget and therefore doesn't have a parent + */ + CUniqueDevice *parent() + { + return(_parent); + } + + /** + * The unique ID of this device + */ const CUID &UID() const { return (_uid); } + + /** + * Destructor + */ virtual ~CUniqueDevice (); /** * Looks for the specified unique id device. Classes that derive from this should ! * implement there own version to reveal any objects they can may contain. If they ! * don't manage any sub devices they can just rely on this method */ virtual CUniqueDevice *find(const CUID &uid, bool create = true) *************** *** 62,67 **** virtual void query(const EDeviceClass tp, set < CUID >&devices) { ! if (tp == LP_ALL) ! devices.insert(_uid); } --- 98,108 ---- virtual void query(const EDeviceClass tp, set < CUID >&devices) { ! switch(tp) ! { ! case LP_ALL: ! case LP_SUB_DEVICE: ! devices.insert(_uid); ! break; ! } } |
From: Jack S. <js...@us...> - 2002-12-17 23:31:45
|
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory sc8-pr-cvs1:/tmp/cvs-serv15446/phidget++ Modified Files: CAnalogIn.h CDigitalIn.h CDigitalOut.cc CDigitalOut.h CInterfaceKit.cc CInterfaceKit.h CPhidget.h CPhidgetManager.h CServo.h CServoController.h CSubDevice.h CUniqueDevice.h TSingleton.h Log Message: Cleaned up the phidget++ code, adding new comments and such Index: CAnalogIn.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CAnalogIn.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CAnalogIn.h 17 Dec 2002 21:29:47 -0000 1.9 --- CAnalogIn.h 17 Dec 2002 22:56:17 -0000 1.10 *************** *** 14,24 **** #include <stdio.h> - class CInterfaceKit; - using namespace std; /** ! * A single analog input from an interface kit. The only time value is updated ! * is when the CPhidgetManager function is called. */ class CAnalogIn : CSubDevice --- 14,23 ---- #include <stdio.h> using namespace std; + class CInterfaceKit; + /** ! * A single analog input from an interface kit. */ class CAnalogIn : CSubDevice *************** *** 28,43 **** CInterfaceKit *_interfaceKit; ! ! // This is the only real data for the servo ! float _value; ! float _lastValue; bool _systemManaged; mutable bool _newValue; ! CAnalogIn (CInterfaceKit *interfacekit, int id); ! void setValue(float value) ; public: CAnalogIn (const CUID &uid); --- 27,50 ---- CInterfaceKit *_interfaceKit; ! float _value; ! float _lastValue; bool _systemManaged; mutable bool _newValue; ! /** ! * This constructor is used when an InterfaceKit generates the device ! */ ! CAnalogIn (CInterfaceKit *interfacekit, int id); + /** + * InterfaceKit calls this to set the value of the input + */ + void setValue(float value) ; + public: + /** + * Should be used to construct user derivations of this class + */ CAnalogIn (const CUID &uid); *************** *** 48,56 **** /** ! * Return the current value of the analog input, this ! * value is only updates when CPhidgetManager->checkForEvents() ! * is called. */ float value() const; float oldValue() const { --- 55,69 ---- /** ! * Return the current value of the analog input. If this value is "stale" ! * then the InterfaceKit will be requested to update all values and the "fresh" ! * one will be returned. */ float value() const; + + /** + * This returns the current value of the analog input without regard to being + * "stale" or "fresh". It won't call InterfaceKit if the value needs to be + * updated. + */ float oldValue() const { *************** *** 61,70 **** * No devices are contained in this device */ ! CAnalogIn *find(const CUID &uid) ! { ! return (NULL); ! } virtual void onChange() {} }; --- 74,91 ---- * No devices are contained in this device */ ! //CAnalogIn *find(const CUID &uid) ! //{ ! //return (NULL); ! //} + /** + * User derived classes can overide this. + */ virtual void onChange() {} + + /** + * Returns a reference to the interface kit that this input is on. + */ + CInterfaceKit &interfaceKit() ; }; Index: CDigitalIn.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** CDigitalIn.h 17 Dec 2002 21:29:47 -0000 1.10 --- CDigitalIn.h 17 Dec 2002 22:56:17 -0000 1.11 *************** *** 14,21 **** #include <stdio.h> - class CInterfaceKit; - using namespace std; /** * A single digital input from an interface kit. The only time value is updated --- 14,21 ---- #include <stdio.h> using namespace std; + class CInterfaceKit; + /** * A single digital input from an interface kit. The only time value is updated *************** *** 27,31 **** friend class CInterfaceKit; - // This is the only real data for the interface kit bool _value; bool _lastValue; --- 27,30 ---- *************** *** 34,42 **** --- 33,50 ---- mutable bool _newValue; + /** + * This constructor is used when an InterfaceKit generates the device + */ CDigitalIn (CInterfaceKit *interfacekit, int id); + /** + * InterfaceKit calls this to set the value of the input + */ void setValue(bool value); public: + /** + * Should be used to construct user derivations of this class + */ CDigitalIn ( const CUID &uid); *************** *** 47,55 **** /** ! * Return the current value of the digital input, this ! * value is only updates when CPhidgetManager->checkForEvents() ! * is called. ! */ bool value() const; bool oldValue() const { --- 55,69 ---- /** ! * Return the current value of the digital input. If this value is "stale" ! * then the InterfaceKit will be requested to update all values and the "fresh" ! * one will be returned. ! */ bool value() const; + + /** + * This returns the current value of the digital input without regard to being + * "stale" or "fresh". It won't call InterfaceKit if the value needs to be + * updated. + */ bool oldValue() const { *************** *** 60,70 **** * No devices are contained in this device */ ! CDigitalIn *find(const CUID &uid) ! { ! return (NULL); ! } virtual void onChange() {} CInterfaceKit &interfaceKit() ; }; --- 74,90 ---- * No devices are contained in this device */ ! //CDigitalIn *find(const CUID &uid) ! //{ ! //return (NULL); ! //} + /** + * User derived classes can overide this. + */ virtual void onChange() {} + /** + * Returns a reference to the interface kit that this input is on. + */ CInterfaceKit &interfaceKit() ; }; Index: CDigitalOut.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalOut.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CDigitalOut.cc 17 Dec 2002 21:17:46 -0000 1.8 --- CDigitalOut.cc 17 Dec 2002 22:56:17 -0000 1.9 *************** *** 23,31 **** _value = val; - int temp=_interfaceKit->getDigitalInCount(); - if (_value) ! phidgetInterfaceKitWrite(_interfaceKit->device(),UID().id()-temp,true); else ! phidgetInterfaceKitWrite(_interfaceKit->device(),UID().id()-temp,false); } --- 23,29 ---- _value = val; if (_value) ! phidgetInterfaceKitWrite(_interfaceKit->device(),ordinal(),true); else ! phidgetInterfaceKitWrite(_interfaceKit->device(),ordinal(),false); } Index: CDigitalOut.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalOut.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CDigitalOut.h 17 Dec 2002 21:29:47 -0000 1.8 --- CDigitalOut.h 17 Dec 2002 22:56:17 -0000 1.9 *************** *** 14,20 **** #include <stdio.h> class CInterfaceKit; - using namespace std; /** --- 14,21 ---- #include <stdio.h> + using namespace std; + class CInterfaceKit; /** *************** *** 28,36 **** CInterfaceKit *_interfaceKit; - - // This is the only real data for the servo bool _value; bool _systemManaged; CDigitalOut (CInterfaceKit *interfacekit, int id); --- 29,38 ---- CInterfaceKit *_interfaceKit; bool _value; bool _systemManaged; + /** + * This constructor is used when an InterfaceKit generates the device + */ CDigitalOut (CInterfaceKit *interfacekit, int id); *************** *** 49,58 **** /** * No devices are contained in this device */ ! CDigitalOut *find(const CUID &uid) ! { ! return (NULL); ! } }; --- 51,65 ---- /** + * Returns the last written value + */ + bool value() const {return(_value);} + + /** * 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.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CInterfaceKit.cc 17 Dec 2002 21:17:47 -0000 1.9 --- CInterfaceKit.cc 17 Dec 2002 22:56:17 -0000 1.10 *************** *** 266,269 **** --- 266,270 ---- } + /* CUniqueDevice *CInterfaceKit::find(const CUID &uid, bool create) { *************** *** 284,285 **** --- 285,287 ---- METHOD_UNGUARD; } + */ Index: CInterfaceKit.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CInterfaceKit.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CInterfaceKit.h 17 Dec 2002 03:10:10 -0000 1.8 --- CInterfaceKit.h 17 Dec 2002 22:56:17 -0000 1.9 *************** *** 45,92 **** pair < bool, CDigitalOut *> *_digitalOuts; void registerDigitalIn(CDigitalIn *in,int id); void registerAnalogIn(CAnalogIn *in,int id); void unregisterDigitalIn(const CUID &uid); void unregisterAnalogIn(const CUID &uid); void setAnalogInCount(int num); void setDigitalInCount(int num); - void setDigitalOutCount(int num); ! CInterfaceKit(phidget *device); public: ! int getAnalogInCount() const {return(_analogInCount);} ! int getDigitalInCount() const {return(_digitalInCount);} ! int getDigitalOutCount() const {return(_digitalOutCount);} /** ! * Constructor to be used when a user derives from this phidget, the user must ! * get a CServoController from the PhidgetManager he wishes to replace and then ! * pass it to this constructor, in the constructor of his derived type. */ CInterfaceKit(const CUID &uid); /** ! * If this phidget is user defined then this will reset the original phidget ! * back into the manager and notify it of the current state of the device */ virtual ~CInterfaceKit (); void update(); ! CUniqueDevice *find(const CUID &uid, bool create); CAnalogIn *analogIn(const int id, bool create=true); CDigitalIn *digitalIn(const int id, bool create=true); CDigitalOut *digitalOut(const int id, bool create=true); virtual void query(const EDeviceClass tp, set < CUID >&devices) { - printf("query interface kit\n"); if (tp == LP_INTERFACE_KIT_488 || tp==LP_INTERFACE_KIT_880) { - printf("Found interface kit\n"); devices.insert(UID()); } --- 45,141 ---- pair < bool, CDigitalOut *> *_digitalOuts; + + /** + * Used by a CDigitalIn that was created by the user to + * register itself with an interface kit. + */ void registerDigitalIn(CDigitalIn *in,int id); + + /** + * Used by a CAnalogIn that was created by the user to + * register itself with an interface kit. + */ void registerAnalogIn(CAnalogIn *in,int id); + + /** + * Used by a CDigitalIn that was created by the user to + * unregister itself with an interface kit. + */ void unregisterDigitalIn(const CUID &uid); + + /** + * Used by a CAnalogIn that was created by the user to + * unregister itself with an interface kit. + */ void unregisterAnalogIn(const CUID &uid); + /** + * Used during construction of the interface kit to set the number of analog inputs + */ void setAnalogInCount(int num); + + /** + * Used during construction of the interface kit to set the number of digital inputs + */ void setDigitalInCount(int num); ! /** ! * Used during construction of the interface kit to set the number of digital outputs ! */ ! void setDigitalOutCount(int num); public: ! /** ! * Returns the number of analog inputs ! */ ! int analogInCount() const {return(_analogInCount);} ! ! /** ! * Returns the number of digital inputs ! */ ! int digitalInCount() const {return(_digitalInCount);} ! ! /** ! * Returns the number of digital outputs ! */ ! int digitalOutCount() const {return(_digitalOutCount);} /** ! * Constructor */ CInterfaceKit(const CUID &uid); /** ! * Destructor */ virtual ~CInterfaceKit (); + /** + * The interface kit updates all digital input values + */ void update(); ! //CUniqueDevice *find(const CUID &uid, bool create); + /** + * Returns a specific analog input, can create it if it hasn't been created already + */ CAnalogIn *analogIn(const int id, bool create=true); + + /** + * Returns a specific digital input, can create it if it hasn't been created already + */ CDigitalIn *digitalIn(const int id, bool create=true); + + /** + * Returns a specific digital output, can create it if it hasn't been created already + */ 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()); } Index: CPhidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidget.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CPhidget.h 17 Dec 2002 03:10:10 -0000 1.7 --- CPhidget.h 17 Dec 2002 22:56:17 -0000 1.8 *************** *** 13,37 **** #include "CUniqueDevice.h" struct phidget; - using namespace std; /** * All phidgets must be derived from this object */ ! 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; /** * This constructor will only be called when a predefined phidget --- 13,32 ---- #include "CUniqueDevice.h" + using namespace std; + struct phidget; /** * All phidgets must be derived from this object */ ! class CPhidget : public CUniqueDevice { private: friend class CServoController; friend class CInterfaceKit; + struct phidget *_device; + /** * This constructor will only be called when a predefined phidget *************** *** 58,74 **** virtual void processEvents(); - /** - * Was this phidget constructed by a user - */ - //bool userConstructed() const {return(_userConstructed);} - - /** - * If it was user constructed, then who used to be incharge of this device, else - * 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 --- 53,57 ---- Index: CPhidgetManager.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CPhidgetManager.h 13 Dec 2002 16:42:39 -0000 1.5 --- CPhidgetManager.h 17 Dec 2002 22:56:17 -0000 1.6 *************** *** 39,42 **** --- 39,44 ---- #include <vector> + using namespace std; + class CServo; class CUID; *************** *** 44,48 **** class CServoController; - using namespace std; /** --- 46,49 ---- *************** *** 56,70 **** 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); --- 57,65 ---- friend class CUniqueDevice; vector <CUniqueDevice *>_uniqueDevices; + CPhidgetManager (); struct phidget *getDeviceHandle(const CUID &uid); CPhidget *createPhidget(const CUID &uid); void registerDevice(CUniqueDevice *dev); void unregisterDevice(CUniqueDevice *dev); *************** *** 78,94 **** * 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; /** --- 73,82 ---- * be called. */ ! virtual ~CPhidgetManager (); /** ! * Returns a list of known devices currently available, filters based on tp */ ! vector <CUID >query(const EDeviceClass tp = LP_PHIDGET); /** *************** *** 96,132 **** */ 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); ! ! /** ! * 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(); --- 84,100 ---- */ CPhidget *phidget (const CUID &uid //<! Unique ID of phidget ! ); ! CServoController *servoController(const CUID &uid); /** ! * ! */ ! CUniqueDevice *find(const CUID &uid, bool create = false); /** * Check for attach/detach events (or any other events. */ ! bool checkForEvents(); Index: CServo.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServo.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CServo.h 17 Dec 2002 21:20:24 -0000 1.6 --- CServo.h 17 Dec 2002 22:56:17 -0000 1.7 *************** *** 14,21 **** #include <stdio.h> - class CServoController; - using namespace std; /** * A single servo --- 14,21 ---- #include <stdio.h> using namespace std; + class CServoController; + /** * A single servo *************** *** 27,42 **** 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 (); /** --- 27,49 ---- CServoController *_controller; float _position; bool _systemManaged; ! /** ! * Used by CServerController to construct a servo ! */ ! CServo (CServoController *controller, const int id); public: ! ! /** ! * Used when you derive from this class ! */ CServo (const CUID &uid); ! /** ! * Destructor ! */ ! virtual ~CServo(); /** *************** *** 78,82 **** /** * No devices are contained in this device ! */ CServo *find(const CUID &uid) { return (NULL); --- 85,90 ---- /** * No devices are contained in this device ! */ ! CServo *find(const CUID &uid) { return (NULL); Index: CServoController.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServoController.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CServoController.h 15 Dec 2002 20:40:11 -0000 1.5 --- CServoController.h 17 Dec 2002 22:56:17 -0000 1.6 *************** *** 14,21 **** #include <vector> - class CServo; - using namespace std; /** * Object that represents all servo controllers (both hard and soft). --- 14,21 ---- #include <vector> using namespace std; + class CServo; + /** * Object that represents all servo controllers (both hard and soft). *************** *** 23,52 **** 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); /** ! * Constructor to be used when a user derives from this phidget, the user must ! * get a CServoController from the PhidgetManager he wishes to replace and then ! * pass it to this constructor, in the constructor of his derived type. ! */ ! //CServoController(CServoController *orig); /** --- 23,45 ---- class CServoController:public CPhidget { ! private: friend class CServo; int _servoCount; pair < bool, CServo *>*_servos; + void setServoCount(int num); void registerServo(CServo *, int id); void unregisterServo(const CUID &uid); ! public: ! CServoController (const CUID &uid); /** ! * Constructor to be used when a user derives from this phidget, the user must ! * get a CServoController from the PhidgetManager he wishes to replace and then ! * 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)); ! } }; --- 47,80 ---- * 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 */ ! 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: CSubDevice.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CSubDevice.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CSubDevice.h 17 Dec 2002 21:17:47 -0000 1.1 --- CSubDevice.h 17 Dec 2002 22:56:17 -0000 1.2 *************** *** 6,18 **** #include "CPhidget.h" class CSubDevice : public CUniqueDevice { private: - // This is the only real data for the interface kit int _ordinal; ! public: void ordinal(int ordinal) { --- 6,27 ---- #include "CPhidget.h" + using namespace std; + + /** + * Any device that isn't a phidget but is managed by a phidget should + * derive from this + */ class CSubDevice : public CUniqueDevice { private: int _ordinal; ! protected: + /** + * Set's the ordinal value for this sub device. The phidget that manages this + * subdevice should call this function. + */ void ordinal(int ordinal) { *************** *** 20,27 **** } ! int ordinal() const ! { ! return(_ordinal); ! } CSubDevice::CSubDevice (CPhidget *parent, int id) : CUniqueDevice (parent, id) --- 29,35 ---- } ! /** ! * Construct a sub device ! */ CSubDevice::CSubDevice (CPhidget *parent, int id) : CUniqueDevice (parent, id) *************** *** 29,32 **** --- 37,64 ---- } + public: + + /** + * The number that describes which sub device this is (in relation to other subdevices + * of it's class). For example if you have a 880 interface kit. You would have eight + * CDigitalIn's whose ordinal is from 0 to 7. It would also have eight CDigitalOut's + * whose ordinal are also 0 to 7. + * + * This should always be true + * + * SomePhidget.getSubDevice(x).ordinal()==x + * + * but this may or may not be true + * + * SomePhidget.getSubDevice(x).UID().id()==x + */ + int ordinal() const + { + return(_ordinal); + } + + /** + * Construct a sub device + */ CSubDevice::CSubDevice (const CUID &uid) : CUniqueDevice (uid) Index: CUniqueDevice.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CUniqueDevice.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CUniqueDevice.h 17 Dec 2002 03:10:10 -0000 1.6 --- CUniqueDevice.h 17 Dec 2002 22:56:17 -0000 1.7 *************** *** 15,18 **** --- 15,19 ---- #include <set> + using namespace std; class CUniqueDevice Index: TSingleton.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/TSingleton.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TSingleton.h 12 Sep 2002 00:24:29 -0000 1.4 --- TSingleton.h 17 Dec 2002 22:56:17 -0000 1.5 *************** *** 72,154 **** template <class T >class TSingleton { ! private: ! TSingleton (const TSingleton <T >&); ! const TSingleton &operator = (const TSingleton <T >&); ! ! //! Pointer to static instance of the object ! static T *mSingleton; ! protected: /** * Singleton constructor */ ! TSingleton () ! { ! } ! ! public: ! virtual ~ TSingleton () ! { ! } ! /** ! * This static function can be called to get the single instance of this class. ! * The singleton object is not created until this function is called. The first ! * time it is called the object is created, and the same object is returned for ! * each subsequent call. ! */ ! static T *getInstance() ! { ! try { - if (mSingleton == NULL) - mSingleton = new T; - return mSingleton; } ! catch(const exception & e) { ! printf("Exception: %s\n", e.what()); ! throw; } - } /** * Returns where or not the singleton object has already been created */ ! static bool exists() ! { ! if (mSingleton != NULL) ! return (true); ! return (false); ! } /** * Deletes the allocated singleton object. The next call to getInstance() returns a new singleton object, not the original. ! */ static T *release() ! { ! if (mSingleton) ! delete mSingleton; ! mSingleton = NULL; ! return (NULL); ! } }; template <class T >class AutoDestroy { ! public: ! AutoDestroy() ! { ! } ! ~AutoDestroy() ! { ! try { ! T:: release(); } ! catch(exception & e) { ! printf("Exception:%s\n", e.what()); } - - } }; --- 72,155 ---- template <class T >class TSingleton { ! private: ! TSingleton (const TSingleton <T >&); ! const TSingleton &operator = (const TSingleton <T >&); ! //! Pointer to static instance of the object ! static T *mSingleton; + protected: /** * Singleton constructor */ ! TSingleton () ! { ! } ! public: ! virtual ~ TSingleton () { } ! ! /** ! * This static function can be called to get the single instance of this class. ! * The singleton object is not created until this function is called. The first ! * time it is called the object is created, and the same object is returned for ! * each subsequent call. ! */ ! static T *getInstance() { ! try ! { ! if (mSingleton == NULL) ! mSingleton = new T; ! return mSingleton; ! } ! catch(const exception & e) ! { ! printf("Exception: %s\n", e.what()); ! throw; ! } } /** * Returns where or not the singleton object has already been created */ ! static bool exists() ! { ! if (mSingleton != NULL) ! return (true); ! return (false); ! } ! /** * Deletes the allocated singleton object. The next call to getInstance() returns a new singleton object, not the original. ! */ ! static T *release() ! { ! if (mSingleton) ! delete mSingleton; ! mSingleton = NULL; ! return (NULL); ! } }; template <class T >class AutoDestroy { ! public: ! AutoDestroy() ! { } ! ~AutoDestroy() { ! try ! { ! T:: release(); ! } ! catch(exception & e) ! { ! printf("Exception:%s\n", e.what()); ! } } }; |
From: Jack S. <js...@us...> - 2002-12-17 23:31:43
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv15446/examples Modified Files: phidget_cpp.cc Log Message: Cleaned up the phidget++ code, adding new comments and such Index: phidget_cpp.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_cpp.cc,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** phidget_cpp.cc 17 Dec 2002 03:10:10 -0000 1.13 --- phidget_cpp.cc 17 Dec 2002 22:56:16 -0000 1.14 *************** *** 57,63 **** if (ik != NULL) printf("DI: %d DO: %d AI:%d\n", ! ik->getDigitalInCount(), ! ik->getDigitalOutCount(), ! ik->getAnalogInCount()); else printf("Unsupported\n"); --- 57,63 ---- if (ik != NULL) printf("DI: %d DO: %d AI:%d\n", ! ik->digitalInCount(), ! ik->digitalOutCount(), ! ik->analogInCount()); else printf("Unsupported\n"); |
From: Jack S. <js...@us...> - 2002-12-17 22:12:14
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv32475/examples Modified Files: phidget_c.c Log Message: Fixed another compiler issue. Now should compile in C Index: phidget_c.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_c.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** phidget_c.c 15 Dec 2002 22:55:24 -0000 1.17 --- phidget_c.c 17 Dec 2002 22:12:11 -0000 1.18 *************** *** 21,24 **** --- 21,29 ---- int t, count; struct phidget **phidgets; + int SERVO=0; + int IK488=0; + int IKDIGITALWRITE=0; + int IK880=0; + int TEXTLCD=0; // Initialize libphiget, here is where the devices are actually retrieved by the library *************** *** 74,82 **** } - int SERVO=0; - int IK488=0; - int IKDIGITALWRITE=0; - int IK880=0; - int TEXTLCD=0; if (argn==2) { --- 79,82 ---- |
From: Jack S. <js...@us...> - 2002-12-17 21:29:51
|
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory sc8-pr-cvs1:/tmp/cvs-serv16311/phidget++ Modified Files: CAnalogIn.cc CAnalogIn.h CDigitalIn.cc CDigitalIn.h CDigitalOut.h Log Message: Cleanup and now the inputs will automatically get InterfaceKit to update themselves when needed. Index: CAnalogIn.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CAnalogIn.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CAnalogIn.cc 17 Dec 2002 21:17:45 -0000 1.8 --- CAnalogIn.cc 17 Dec 2002 21:29:46 -0000 1.9 *************** *** 47,48 **** --- 47,68 ---- METHOD_UNGUARD; } + + void CAnalogIn::setValue(float value) + { + _newValue=true; + _lastValue=_value; + _value=value; + + if (_value != _lastValue) + onChange(); + } + + float CAnalogIn::value() const + { + // If we don't have a new value then update our value + if (!_newValue) + _interfaceKit->update(); + + _newValue=false; + return (_value); + } Index: CAnalogIn.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CAnalogIn.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CAnalogIn.h 17 Dec 2002 21:17:46 -0000 1.8 --- CAnalogIn.h 17 Dec 2002 21:29:47 -0000 1.9 *************** *** 32,59 **** float _value; float _lastValue; - //int _cardinal; bool _systemManaged; CAnalogIn (CInterfaceKit *interfacekit, int id); ! ! void setValue(float value) ! { ! _lastValue=_value; ! _value=value; ! ! if (_value != _lastValue) ! onChange(); ! } ! ! // Should only be called by interface kit ! //void setCardinal(int cardinal) ! //{ ! //_cardinal=cardinal; ! //} public: CAnalogIn (const CUID &uid); - //int cardinal() const {return(_cardinal);} /** --- 32,44 ---- float _value; float _lastValue; bool _systemManaged; + mutable bool _newValue; CAnalogIn (CInterfaceKit *interfacekit, int id); ! void setValue(float value) ; public: CAnalogIn (const CUID &uid); /** *************** *** 67,73 **** * is called. */ ! float value() const { ! return (_value); } --- 52,59 ---- * is called. */ ! float value() const; ! float oldValue() const { ! return(_value); } Index: CDigitalIn.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.cc,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CDigitalIn.cc 17 Dec 2002 21:17:46 -0000 1.9 --- CDigitalIn.cc 17 Dec 2002 21:29:47 -0000 1.10 *************** *** 52,53 **** --- 52,73 ---- return(*_interfaceKit); } + + void CDigitalIn::setValue(bool value) + { + _newValue=true; + _lastValue=_value; + _value=value; + + if (_value!=_lastValue) + onChange(); + } + + bool CDigitalIn::value() const + { + // If we don't have a new value then update our value + if (!_newValue) + _interfaceKit->update(); + + _newValue=false; + return (_value); + } Index: CDigitalIn.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CDigitalIn.h 17 Dec 2002 21:17:46 -0000 1.9 --- CDigitalIn.h 17 Dec 2002 21:29:47 -0000 1.10 *************** *** 31,57 **** bool _lastValue; bool _systemManaged; - //int _cardinal; CInterfaceKit *_interfaceKit; CDigitalIn (CInterfaceKit *interfacekit, int id); ! void setValue(bool value) ! { ! ! _lastValue=_value; ! _value=value; ! ! if (_value!=_lastValue) ! onChange(); ! } ! ! // should only be called by the interface kit ! //void setCardinal(int cardinal) ! //{ ! //_cardinal=cardinal; ! //} public: - //int cardinal() const {return(_cardinal);} CDigitalIn ( const CUID &uid); --- 31,42 ---- bool _lastValue; bool _systemManaged; CInterfaceKit *_interfaceKit; + mutable bool _newValue; CDigitalIn (CInterfaceKit *interfacekit, int id); ! void setValue(bool value); public: CDigitalIn ( const CUID &uid); *************** *** 66,72 **** * is called. */ ! bool value() const { ! return (_value); } --- 51,58 ---- * is called. */ ! bool value() const; ! bool oldValue() const { ! return(_value); } Index: CDigitalOut.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalOut.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CDigitalOut.h 17 Dec 2002 21:17:47 -0000 1.7 --- CDigitalOut.h 17 Dec 2002 21:29:47 -0000 1.8 *************** *** 32,42 **** bool _value; bool _systemManaged; - //int _cardinal; - - // Should only be called by interface kit - //void setCardinal(int cardinal) - //{ - //_cardinal=cardinal; - //} CDigitalOut (CInterfaceKit *interfacekit, int id); --- 32,35 ---- |
From: Jack S. <js...@us...> - 2002-12-17 21:20:27
|
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory sc8-pr-cvs1:/tmp/cvs-serv12987/phidget++ Modified Files: CServo.cc CServo.h CServoController.cc Log Message: Servo is now a SubDevice and has an ordinal number Index: CServo.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServo.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CServo.cc 16 Dec 2002 22:37:12 -0000 1.8 --- CServo.cc 17 Dec 2002 21:20:24 -0000 1.9 *************** *** 29,34 **** CServo::CServo (CServoController *controller, const int id) : ! CUniqueDevice (controller, id), ! _controller(controller), _position(0), _systemManaged(true) { --- 29,35 ---- CServo::CServo (CServoController *controller, const int id) : ! CSubDevice (controller, id), ! _controller(controller), ! _position(0), _systemManaged(true) { *************** *** 38,42 **** CServo::CServo (const CUID &uid) : ! CUniqueDevice (uid), _position(0), _systemManaged(false) { --- 39,43 ---- CServo::CServo (const CUID &uid) : ! CSubDevice (uid), _position(0), _systemManaged(false) { Index: CServo.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServo.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CServo.h 15 Dec 2002 20:40:11 -0000 1.5 --- CServo.h 17 Dec 2002 21:20:24 -0000 1.6 *************** *** 11,15 **** #define __CSERVO_H__ ! #include "CUniqueDevice.h" #include <stdio.h> --- 11,15 ---- #define __CSERVO_H__ ! #include "CSubDevice.h" #include <stdio.h> *************** *** 21,25 **** * A single servo */ ! class CServo:public CUniqueDevice { private: --- 21,25 ---- * A single servo */ ! class CServo : public CSubDevice { private: Index: CServoController.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServoController.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CServoController.cc 15 Dec 2002 17:32:44 -0000 1.7 --- CServoController.cc 17 Dec 2002 21:20:24 -0000 1.8 *************** *** 99,102 **** --- 99,103 ---- throw runtime_error("This servo id is already being used."); + servo->ordinal(id); _servos[id].first = false; _servos[id].second = servo; |
From: Jack S. <js...@us...> - 2002-12-17 21:17:50
|
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory sc8-pr-cvs1:/tmp/cvs-serv12162/phidget++ Modified Files: CAnalogIn.cc CAnalogIn.h CDigitalIn.cc CDigitalIn.h CDigitalOut.cc CDigitalOut.h CInterfaceKit.cc Makefile.am Added Files: CSubDevice.h Log Message: Moved some code to CSubDevice that was common among alll subdevices --- NEW FILE: CSubDevice.h --- #ifndef __CSUBDEVICE_H__ #define __CSUBDEVICE_H__ #include "CUniqueDevice.h" #include "CUID.h" #include "CPhidget.h" class CSubDevice : public CUniqueDevice { private: // This is the only real data for the interface kit int _ordinal; public: void ordinal(int ordinal) { _ordinal=ordinal; } int ordinal() const { return(_ordinal); } CSubDevice::CSubDevice (CPhidget *parent, int id) : CUniqueDevice (parent, id) { } CSubDevice::CSubDevice (const CUID &uid) : CUniqueDevice (uid) { } }; #endif Index: CAnalogIn.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CAnalogIn.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CAnalogIn.cc 16 Dec 2002 22:37:09 -0000 1.7 --- CAnalogIn.cc 17 Dec 2002 21:17:45 -0000 1.8 *************** *** 14,18 **** CAnalogIn::CAnalogIn (CInterfaceKit *interfacekit, int id) : ! CUniqueDevice (interfacekit, id), _interfaceKit(interfacekit), _value(0), --- 14,18 ---- CAnalogIn::CAnalogIn (CInterfaceKit *interfacekit, int id) : ! CSubDevice (interfacekit, id), _interfaceKit(interfacekit), _value(0), *************** *** 23,27 **** CAnalogIn::CAnalogIn (const CUID &uid) : ! CUniqueDevice (uid), _value(false), _lastValue(false), --- 23,27 ---- CAnalogIn::CAnalogIn (const CUID &uid) : ! CSubDevice (uid), _value(false), _lastValue(false), Index: CAnalogIn.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CAnalogIn.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CAnalogIn.h 16 Dec 2002 22:37:10 -0000 1.7 --- CAnalogIn.h 17 Dec 2002 21:17:46 -0000 1.8 *************** *** 11,15 **** #define __CANALOGIN_H__ ! #include "CUniqueDevice.h" #include <stdio.h> --- 11,15 ---- #define __CANALOGIN_H__ ! #include "CSubDevice.h" #include <stdio.h> *************** *** 22,26 **** * is when the CPhidgetManager function is called. */ ! class CAnalogIn : CUniqueDevice { private: --- 22,26 ---- * is when the CPhidgetManager function is called. */ ! class CAnalogIn : CSubDevice { private: *************** *** 32,36 **** float _value; float _lastValue; ! int _cardinal; bool _systemManaged; --- 32,36 ---- float _value; float _lastValue; ! //int _cardinal; bool _systemManaged; *************** *** 48,59 **** // Should only be called by interface kit ! void setCardinal(int cardinal) ! { ! _cardinal=cardinal; ! } public: CAnalogIn (const CUID &uid); ! int cardinal() const {return(_cardinal);} /** --- 48,59 ---- // Should only be called by interface kit ! //void setCardinal(int cardinal) ! //{ ! //_cardinal=cardinal; ! //} public: CAnalogIn (const CUID &uid); ! //int cardinal() const {return(_cardinal);} /** Index: CDigitalIn.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CDigitalIn.cc 17 Dec 2002 20:28:51 -0000 1.8 --- CDigitalIn.cc 17 Dec 2002 21:17:46 -0000 1.9 *************** *** 14,18 **** CDigitalIn::CDigitalIn (CInterfaceKit *interfaceKit, int id) : ! CUniqueDevice (interfaceKit, id), _value(false), _lastValue(false), --- 14,18 ---- CDigitalIn::CDigitalIn (CInterfaceKit *interfaceKit, int id) : ! CSubDevice (interfaceKit, id), _value(false), _lastValue(false), *************** *** 23,27 **** CDigitalIn::CDigitalIn (const CUID &uid) : ! CUniqueDevice (uid), _value(false), _lastValue(false), --- 23,27 ---- CDigitalIn::CDigitalIn (const CUID &uid) : ! CSubDevice (uid), _value(false), _lastValue(false), Index: CDigitalIn.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CDigitalIn.h 17 Dec 2002 20:28:51 -0000 1.8 --- CDigitalIn.h 17 Dec 2002 21:17:46 -0000 1.9 *************** *** 11,15 **** #define __CDIGITALIN_H__ ! #include "CUniqueDevice.h" #include <stdio.h> --- 11,15 ---- #define __CDIGITALIN_H__ ! #include "CSubDevice.h" #include <stdio.h> *************** *** 22,26 **** * is when the CPhidgetManager function is called. */ ! class CDigitalIn:public CUniqueDevice { private: --- 22,26 ---- * is when the CPhidgetManager function is called. */ ! class CDigitalIn:public CSubDevice { private: *************** *** 31,35 **** bool _lastValue; bool _systemManaged; ! int _cardinal; CInterfaceKit *_interfaceKit; --- 31,35 ---- bool _lastValue; bool _systemManaged; ! //int _cardinal; CInterfaceKit *_interfaceKit; *************** *** 47,57 **** // should only be called by the interface kit ! void setCardinal(int cardinal) ! { ! _cardinal=cardinal; ! } public: ! int cardinal() const {return(_cardinal);} CDigitalIn ( const CUID &uid); --- 47,57 ---- // should only be called by the interface kit ! //void setCardinal(int cardinal) ! //{ ! //_cardinal=cardinal; ! //} public: ! //int cardinal() const {return(_cardinal);} CDigitalIn ( const CUID &uid); Index: CDigitalOut.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalOut.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CDigitalOut.cc 15 Dec 2002 22:55:25 -0000 1.7 --- CDigitalOut.cc 17 Dec 2002 21:17:46 -0000 1.8 *************** *** 12,16 **** CDigitalOut::CDigitalOut (CInterfaceKit *interfaceKit, int id) : ! CUniqueDevice (interfaceKit, id), _interfaceKit(interfaceKit), _value(false), --- 12,16 ---- CDigitalOut::CDigitalOut (CInterfaceKit *interfaceKit, int id) : ! CSubDevice (interfaceKit, id), _interfaceKit(interfaceKit), _value(false), Index: CDigitalOut.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalOut.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CDigitalOut.h 16 Dec 2002 22:37:11 -0000 1.6 --- CDigitalOut.h 17 Dec 2002 21:17:47 -0000 1.7 *************** *** 11,15 **** #define __CDIGITALOUT_H__ ! #include "CUniqueDevice.h" #include <stdio.h> --- 11,15 ---- #define __CDIGITALOUT_H__ ! #include "CSubDevice.h" #include <stdio.h> *************** *** 22,26 **** * phidget as soon as the function is called. */ ! class CDigitalOut:CUniqueDevice { private: --- 22,26 ---- * phidget as soon as the function is called. */ ! class CDigitalOut : CSubDevice { private: *************** *** 32,42 **** bool _value; bool _systemManaged; ! int _cardinal; // Should only be called by interface kit ! void setCardinal(int cardinal) ! { ! _cardinal=cardinal; ! } CDigitalOut (CInterfaceKit *interfacekit, int id); --- 32,42 ---- bool _value; bool _systemManaged; ! //int _cardinal; // Should only be called by interface kit ! //void setCardinal(int cardinal) ! //{ ! //_cardinal=cardinal; ! //} CDigitalOut (CInterfaceKit *interfacekit, int id); Index: CInterfaceKit.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CInterfaceKit.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CInterfaceKit.cc 16 Dec 2002 22:37:11 -0000 1.8 --- CInterfaceKit.cc 17 Dec 2002 21:17:47 -0000 1.9 *************** *** 69,82 **** { METHOD_GUARD; ! in->setCardinal(id-_digitalInOffset); ! if (in->cardinal() < 0 || in->cardinal() >= _digitalInCount) throw runtime_error("Invalid digital input id"); ! if (_digitalIns[in->cardinal()].second != NULL) throw runtime_error("This digital input is already being used."); ! _digitalIns[in->cardinal()].first = false; ! _digitalIns[in->cardinal()].second = in; METHOD_UNGUARD; --- 69,82 ---- { METHOD_GUARD; ! in->ordinal(id-_digitalInOffset); ! if (in->ordinal() < 0 || in->ordinal() >= _digitalInCount) throw runtime_error("Invalid digital input id"); ! if (_digitalIns[in->ordinal()].second != NULL) throw runtime_error("This digital input is already being used."); ! _digitalIns[in->ordinal()].first = false; ! _digitalIns[in->ordinal()].second = in; METHOD_UNGUARD; *************** *** 132,145 **** { METHOD_GUARD; ! in->setCardinal(id-_analogInOffset); ! if (in->cardinal() < 0 || in->cardinal() >= _analogInCount) throw runtime_error("Invalid analog input id"); ! if (_analogIns[in->cardinal()].second != NULL) throw runtime_error("This analog input is already being used."); ! _analogIns[in->cardinal()].first = false; ! _analogIns[in->cardinal()].second = in; METHOD_UNGUARD; --- 132,145 ---- { METHOD_GUARD; ! in->ordinal(id-_analogInOffset); ! if (in->ordinal() < 0 || in->ordinal() >= _analogInCount) throw runtime_error("Invalid analog input id"); ! if (_analogIns[in->ordinal()].second != NULL) throw runtime_error("This analog input is already being used."); ! _analogIns[in->ordinal()].first = false; ! _analogIns[in->ordinal()].second = in; METHOD_UNGUARD; *************** *** 227,231 **** _digitalIns[id].first = true; _digitalIns[id].second = new CDigitalIn(this, id+_digitalInOffset); ! _digitalIns[id].second->setCardinal(id); } --- 227,231 ---- _digitalIns[id].first = true; _digitalIns[id].second = new CDigitalIn(this, id+_digitalInOffset); ! _digitalIns[id].second->ordinal(id); } Index: Makefile.am =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/Makefile.am,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Makefile.am 15 Dec 2002 20:40:12 -0000 1.8 --- Makefile.am 17 Dec 2002 21:17:47 -0000 1.9 *************** *** 10,13 **** --- 10,14 ---- CServoController.h \ CUID.h \ + CSubDevice.h \ CUniqueDevice.h \ CInterfaceKit.h \ |
From: Jack S. <js...@us...> - 2002-12-17 21:17:49
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv12162/examples Modified Files: ik2lcd.cc Log Message: Moved some code to CSubDevice that was common among alll subdevices Index: ik2lcd.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/ik2lcd.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ik2lcd.cc 17 Dec 2002 20:28:51 -0000 1.2 --- ik2lcd.cc 17 Dec 2002 21:17:45 -0000 1.3 *************** *** 56,77 **** char temp[12]; ! _lcd.sendText(" ",0,0); ! _lcd.sendText(" ",1,0); ! sprintf(temp,"Input %d\n",cardinal()); _lcd.sendText(temp,0,0); if (value()) { ! array[cardinal()]='*'; _lcd.sendText("Value:On ",1,0); ! interfaceKit().digitalOut(cardinal())->value(true); } else { ! array[cardinal()]='-'; _lcd.sendText("Value:Off",1,0); ! interfaceKit().digitalOut(cardinal())->value(false); } } --- 56,77 ---- char temp[12]; ! //_lcd.sendText(" ",0,0); ! //_lcd.sendText(" ",1,0); ! sprintf(temp,"Input %d\n",ordinal()); _lcd.sendText(temp,0,0); if (value()) { ! array[ordinal()]='*'; _lcd.sendText("Value:On ",1,0); ! interfaceKit().digitalOut(ordinal())->value(true); } else { ! array[ordinal()]='-'; _lcd.sendText("Value:Off",1,0); ! interfaceKit().digitalOut(ordinal())->value(false); } } *************** *** 99,102 **** --- 99,106 ---- array[8]=0; + lcd.sendText(" ",0,0); + lcd.sendText(" ",1,0); + lcd.sendText(" ",2,0); + lcd.sendText(" ",3,0); lcd.sendText("Digital:",2,0); lcd.on(); |
From: Jack S. <js...@us...> - 2002-12-17 20:28:54
|
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory sc8-pr-cvs1:/tmp/cvs-serv24725/phidget++ Modified Files: CDigitalIn.cc CDigitalIn.h Log Message: Added more features to the ik2lcd example. Sends more info to the TextLCD and turns on the same digital out when a digital in turned on. Index: CDigitalIn.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CDigitalIn.cc 16 Dec 2002 22:37:10 -0000 1.7 --- CDigitalIn.cc 17 Dec 2002 20:28:51 -0000 1.8 *************** *** 47,48 **** --- 47,53 ---- METHOD_UNGUARD; } + + CInterfaceKit &CDigitalIn::interfaceKit() + { + return(*_interfaceKit); + } Index: CDigitalIn.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CDigitalIn.h 16 Dec 2002 22:37:11 -0000 1.7 --- CDigitalIn.h 17 Dec 2002 20:28:51 -0000 1.8 *************** *** 80,83 **** --- 80,85 ---- virtual void onChange() {} + + CInterfaceKit &interfaceKit() ; }; |
From: Jack S. <js...@us...> - 2002-12-17 20:28:53
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv24725/examples Modified Files: ik2lcd.cc Log Message: Added more features to the ik2lcd example. Sends more info to the TextLCD and turns on the same digital out when a digital in turned on. Index: ik2lcd.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/ik2lcd.cc,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ik2lcd.cc 17 Dec 2002 03:09:30 -0000 1.1 --- ik2lcd.cc 17 Dec 2002 20:28:51 -0000 1.2 *************** *** 42,45 **** --- 42,46 ---- // this shows how to overload a digital input to catch change value events + char array[9]="--------"; class CMyDigitalIn : public CDigitalIn { *************** *** 63,69 **** --- 64,78 ---- if (value()) + { + array[cardinal()]='*'; _lcd.sendText("Value:On ",1,0); + interfaceKit().digitalOut(cardinal())->value(true); + } else + { + array[cardinal()]='-'; _lcd.sendText("Value:Off",1,0); + interfaceKit().digitalOut(cardinal())->value(false); + } } }; *************** *** 88,92 **** --- 97,103 ---- CTextLCD lcd(textLCDId); CMyDigitalIn *din[8]; + array[8]=0; + lcd.sendText("Digital:",2,0); lcd.on(); *************** *** 95,99 **** --- 106,113 ---- while (1) + { kit.update(); + lcd.sendText(array,3,0); + } // won't get here |
From: Jack S. <js...@us...> - 2002-12-17 03:10:14
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv29565/examples Modified Files: Makefile.am phidget_cpp.cc Log Message: Bug fixes and code modifications to support the new example ik2lcd. Also the start of the rebuild of the device query system in phidget++ Index: Makefile.am =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Makefile.am 16 Dec 2002 22:37:08 -0000 1.3 --- Makefile.am 17 Dec 2002 03:10:10 -0000 1.4 *************** *** 1,3 **** ! bin_PROGRAMS = phidget_c phidget_cpp servo_example ik_example phidget_c_SOURCES = phidget_c.c --- 1,3 ---- ! bin_PROGRAMS = phidget_c phidget_cpp servo_example ik_example ik2lcd phidget_c_SOURCES = phidget_c.c *************** *** 17,20 **** --- 17,24 ---- ik_example_LDADD = ../libphidget/libphidget.la ../phidget++/libphidget++.la ik_example_DEPENDENCIES = ../libphidget/libphidget.la ../phidget++/libphidget++.la + + ik2lcd_SOURCES = ik2lcd.cc + ik2lcd_LDADD = ../libphidget/libphidget.la ../phidget++/libphidget++.la + ik2lcd_DEPENDENCIES = ../libphidget/libphidget.la ../phidget++/libphidget++.la CFLAGS = -I../libphidget -L../libphidget Index: phidget_cpp.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_cpp.cc,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** phidget_cpp.cc 16 Dec 2002 04:54:56 -0000 1.12 --- phidget_cpp.cc 17 Dec 2002 03:10:10 -0000 1.13 *************** *** 24,205 **** static const char *revision="$Revision$"; - /* - class CMyServoController : public CServoController - { - public: - CMyServoController(const CUID &uid) : - CServoController(uid) - { - printf("Initializing My Servo Controller\n"); - } - ~CMyServoController() - { - printf("Destroying My Servo Controller\n"); - } - void onAttach() - { - printf("My Servo Controller: Attach\n"); - } - void onDetach() - { - printf("My Servo Controller: Detach\n"); - } - }; - - class CMyServo : public CServo - { - public: - CMyServo(const CUID &uid) : - CServo(uid) - { - printf("Construction of my servo class.\n"); - } - ~CMyServo() - { - printf("Destruction of my servo class.\n"); - } - void position(float f) - { - CServo::position(f); - printf("Rotating servo to %f\n",f); - } - }; - - - // Discovery of available phidgets, creation of phidget objects, and discovery of all devices afterwards. - void example1() - { - printf("example 1 - Discovery of phidgets\n"); - - { - // See what the system has available - CPhidgetManager *manager=CPhidgetManager::getInstance(); - CPhidgetManager::getInstance()->checkForEvents(); - - // This queries for any devices that are phidgets - vector< CUID > devices=manager->query(LP_ALL); - printf("All:%d\n",devices.size()); - CPhidgetManager::getInstance()->checkForEvents(); - - // Print out how many we found - devices=manager->query(LP_PHIDGET); - printf("Phidgets:%d\n",devices.size()); - CPhidgetManager::getInstance()->checkForEvents(); - - // Get the phidgets, this forces the manager to create them - // since they haven't already been created by the user. - for (int t=0;t<devices.size();t++) - { - CPhidget *phidg=dynamic_cast<CPhidget *>(manager->find(devices[t],true)); - } - CPhidgetManager::getInstance()->checkForEvents(); - - // Now let's see how many devices are available - devices=manager->query(LP_ALL); - printf("All:%d\n",devices.size()); - CPhidgetManager::getInstance()->checkForEvents(); - } - - // This makes the next example run like it's the first. - CPhidgetManager::release(); - printf("Done\n"); - } - - - // Just attacheding to a servo, don't have to worry about anything else - void example2() - { - printf("example 2 - Manipulating a servo\n"); - - { - // Create a servo - CServo servo(CUID(741,0)); - - servo.position(.5); - sleep(1); - CPhidgetManager::getInstance()->checkForEvents(); - } - - // This makes the next example run like it's the first. - CPhidgetManager::release(); - printf("Done\n"); - } - - void example3() - { - - printf("example 3 - Custom servo device\n"); - - { - // Create a servo - CMyServo servo(CUID(741,0)); - - servo.position(.2); - sleep(1); - CPhidgetManager::getInstance()->checkForEvents(); - servo.position(.5); - sleep(1); - CPhidgetManager::getInstance()->checkForEvents(); - servo.position(.8); - sleep(1); - CPhidgetManager::getInstance()->checkForEvents(); - } - - // This makes the next example run like it's the first. - CPhidgetManager::release(); - printf("Done\n"); - - } - - void example4() - { - printf("example 4 - Custom servo device\n"); - - { - CMyServoController controller(CUID(741)); - CServo servo(CUID(741,0)); - - servo.position(.2); - sleep(1); - CPhidgetManager::getInstance()->checkForEvents(); - servo.position(.5); - sleep(1); - CPhidgetManager::getInstance()->checkForEvents(); - servo.position(.8); - sleep(1); - CPhidgetManager::getInstance()->checkForEvents(); - } - - // This makes the next example run like it's the first. - CPhidgetManager::release(); - printf("Done\n"); - } - - void example5() - { - printf("example 5 - Custom servo device\n"); - - { - CMyServoController controller(CUID(741)); - CMyServo servo(CUID(741,0)); - - servo.position(.2); - sleep(1); - CPhidgetManager::getInstance()->checkForEvents(); - servo.position(.5); - sleep(1); - CPhidgetManager::getInstance()->checkForEvents(); - servo.position(.8); - sleep(1); - CPhidgetManager::getInstance()->checkForEvents(); - } - - // This makes the next example run like it's the first. - CPhidgetManager::release(); - printf("Done\n"); - } - - */ - void phidgets_ls() { --- 24,27 ---- |
From: Jack S. <js...@us...> - 2002-12-17 03:10:14
|
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory sc8-pr-cvs1:/tmp/cvs-serv29565/phidget++ Modified Files: CInterfaceKit.h CPhidget.h CPhidgetManager.cc CTextLCD.h CUniqueDevice.h Log Message: Bug fixes and code modifications to support the new example ik2lcd. Also the start of the rebuild of the device query system in phidget++ Index: CInterfaceKit.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CInterfaceKit.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CInterfaceKit.h 16 Dec 2002 22:37:11 -0000 1.7 --- CInterfaceKit.h 17 Dec 2002 03:10:10 -0000 1.8 *************** *** 13,16 **** --- 13,17 ---- #include "CPhidget.h" #include <vector> + #include <set> using namespace std; *************** *** 81,84 **** --- 82,97 ---- CDigitalIn *digitalIn(const int id, bool create=true); CDigitalOut *digitalOut(const int id, bool create=true); + + virtual void query(const EDeviceClass tp, set < CUID >&devices) + { + printf("query interface kit\n"); + if (tp == LP_INTERFACE_KIT_488 || tp==LP_INTERFACE_KIT_880) + { + printf("Found interface kit\n"); + devices.insert(UID()); + } + else + CPhidget::query(tp,devices); + } }; Index: CPhidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidget.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CPhidget.h 15 Dec 2002 20:40:11 -0000 1.6 --- CPhidget.h 17 Dec 2002 03:10:10 -0000 1.7 *************** *** 83,90 **** virtual void query(const EDeviceClass tp, set < CUID >&devices) { - CUniqueDevice::query(tp, devices); - if (tp == LP_PHIDGET) devices.insert(UID()); } }; --- 83,90 ---- virtual void query(const EDeviceClass tp, set < CUID >&devices) { if (tp == LP_PHIDGET) devices.insert(UID()); + else + CUniqueDevice::query(tp, devices); } }; Index: CPhidgetManager.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.cc,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** CPhidgetManager.cc 15 Dec 2002 23:41:55 -0000 1.12 --- CPhidgetManager.cc 17 Dec 2002 03:10:10 -0000 1.13 *************** *** 119,122 **** --- 119,123 ---- // Ask libphidget for any known phidgets + /* if ( tp == LP_ALL || *************** *** 125,157 **** tp == LP_SERVO_CONTROLLER || tp == LP_INTERFACE_KIT_488 || ! tp == LP_INTERFACE_KIT_880 ) { int phidget_count; struct phidget **phidgets = error(phidgetGetPhidgets(&phidget_count)); - for (int t = 0; t < phidget_count; t++) { if ( (tp == LP_PHIDGET) || (tp == LP_ALL) || (tp == LP_TEXT_LCD) || ! (tp == LP_SERVO_CONTROLLER && error(phidgetTypeDeviceClass(error(phidgetType(phidgets[t])))) == LP_SERVO_CONTROLLER) || (tp == LP_INTERFACE_KIT_488) || ! (tp == LP_INTERFACE_KIT_880) ! /*|| ! (tp == LP_INTERFACE_KIT && error(phidgetTypeDeviceClass(error(phidgetType(phidgets[t])))) == LP_INTERFACE_KIT)*/ ) { 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 - //if (tp == LP_ALL || tp == LP_SERVO || tp == LP_DIGITAL_IN || tp == LP_DIGITAL_OUT || tp == LP_TEXT_LCD) { for (int t = 0; t < _uniqueDevices.size(); t++) --- 126,166 ---- 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++) Index: CTextLCD.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CTextLCD.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CTextLCD.h 16 Dec 2002 04:54:56 -0000 1.2 --- CTextLCD.h 17 Dec 2002 03:10:10 -0000 1.3 *************** *** 13,16 **** --- 13,17 ---- #include "CPhidget.h" #include <vector> + #include <set> using namespace std; *************** *** 28,41 **** void update(); CUniqueDevice *find(const CUID &uid, bool create); - virtual void query(const EDeviceClass tp, set < CUID >&devices) - { - CPhidget::query(tp, devices); - //if (tp == LP_TEXT_LCD || tp == LP_ALL) - //for (int t = 0; t < _servoCount; t++) - //devices.insert(CUID (UID().serial(), t)); - } void sendText(string text, int row, int col); void on(); void off(); }; --- 29,42 ---- void update(); CUniqueDevice *find(const CUID &uid, bool create); void sendText(string text, int row, int col); void on(); void off(); + virtual void query(const EDeviceClass tp, set < CUID >&devices) + { + if (tp == LP_TEXT_LCD) + devices.insert(UID()); + else + CPhidget::query(tp,devices); + } }; Index: CUniqueDevice.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CUniqueDevice.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CUniqueDevice.h 15 Dec 2002 20:40:12 -0000 1.5 --- CUniqueDevice.h 17 Dec 2002 03:10:10 -0000 1.6 *************** *** 58,62 **** /** * Queries for any unique id devices that may exists, or are known how to create. ! */ virtual void query(const EDeviceClass tp, set < CUID >&devices) { if (tp == LP_ALL) --- 58,63 ---- /** * Queries for any unique id devices that may exists, or are known how to create. ! */ ! virtual void query(const EDeviceClass tp, set < CUID >&devices) { if (tp == LP_ALL) |
From: Jack S. <js...@us...> - 2002-12-17 03:09:33
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv29347/examples Added Files: ik2lcd.cc Log Message: This is a new example to show how to use 2 phidgets together. It requires an interface kit with 8 digital inputs and a TextLCD When running, it will accept digital input on phidget and send to the text lcd information about which inputs and what values are changing. --- NEW FILE: ik2lcd.cc --- #include <CPhidgetManager.h> #include <CInterfaceKit.h> #include <CDigitalIn.h> #include <CDigitalOut.h> #include <CAnalogIn.h> #include <CTextLCD.h> #include <unistd.h> static const char *revision="$Revision: 1.1 $"; CUID ikId; CUID textLCDId; /** * Find the first servo controller we can */ void findUsablePhidgets() { { // Look for a servo that we can use for all the examples vector<CUID> temp=CPhidgetManager::getInstance()->query(LP_INTERFACE_KIT_488); if (temp.size()<1) throw runtime_error("This application can't run without a phidget interface kit (see http://www.phidgets.com).\n"); ikId=temp[0]; printf("Interface Kit Controller found: %s\n",ikId.asString().c_str()); } { // Look for a servo that we can use for all the examples vector<CUID> temp=CPhidgetManager::getInstance()->query(LP_TEXT_LCD); if (temp.size()<1) throw runtime_error("This application can't run without a phidget text lcd kit (see http://www.phidgets.com).\n"); textLCDId=temp[0]; printf("Text LCD found: %s\n",textLCDId.asString().c_str()); } } // this shows how to overload a digital input to catch change value events class CMyDigitalIn : public CDigitalIn { public: CTextLCD &_lcd; CMyDigitalIn ( const CUID &uid, CTextLCD &lcd) : CDigitalIn(uid), _lcd(lcd) { } void onChange() { char temp[12]; _lcd.sendText(" ",0,0); _lcd.sendText(" ",1,0); sprintf(temp,"Input %d\n",cardinal()); _lcd.sendText(temp,0,0); if (value()) _lcd.sendText("Value:On ",1,0); else _lcd.sendText("Value:Off",1,0); } }; main() { try { char adjusted_version[64]; memcpy(adjusted_version,revision+11,strlen(revision)-11-2); adjusted_version[strlen(revision)-11-2]=0; // What we are printf("ik_example: code examples of how to communicate with interface kits\n"); // Get the version number printf("Version %s\n",adjusted_version); findUsablePhidgets(); CInterfaceKit kit(ikId); CTextLCD lcd(textLCDId); CMyDigitalIn *din[8]; lcd.on(); for (int t=0;t<8;t++) din[t]=new CMyDigitalIn(CUID(ikId.serial(),t+4),lcd); while (1) kit.update(); // won't get here for (int t=0;t<8;t++) delete din[t]; } catch(const exception &e) { printf("exception:%s\n",e.what()); } } |
From: Jack S. <js...@us...> - 2002-12-16 22:37:42
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv17868/examples Modified Files: Makefile.am Added Files: ik_example.cc Log Message: Added onChange events to Digital and Analog inputs, wrote an example script that uses these called ik_example. --- NEW FILE: ik_example.cc --- #include <CPhidgetManager.h> #include <CInterfaceKit.h> #include <CDigitalIn.h> #include <CDigitalOut.h> #include <CAnalogIn.h> #include <unistd.h> static const char *revision="$Revision: 1.1 $"; CUID phidgetId; /** * Find the first servo controller we can */ void findUsableInterfaceKit() { // Look for a servo that we can use for all the examples vector<CUID> temp=CPhidgetManager::getInstance()->query(LP_INTERFACE_KIT_488); if (temp.size()<1) throw runtime_error("This application can't run without a phidget interface kit (see http://www.phidgets.com).\n"); phidgetId=temp[0]; printf("Interface Kit Controller found: %s\n",phidgetId.asString().c_str()); } // this shows how to overload a digital input to catch change value events class CMyDigitalIn : public CDigitalIn { public: CMyDigitalIn ( const CUID &uid) : CDigitalIn(uid) { } void onChange() { printf("Change:%d\n",value()); } }; // this shows how to overload a analog input to catch change value events class CMyAnalogIn : public CAnalogIn { public: CMyAnalogIn ( const CUID &uid) : CAnalogIn(uid) { } void onChange() { printf("Change:%f\n",value()); } }; main() { try { char adjusted_version[64]; memcpy(adjusted_version,revision+11,strlen(revision)-11-2); adjusted_version[strlen(revision)-11-2]=0; // What we are printf("ik_example: code examples of how to communicate with interface kits\n"); // Get the version number printf("Version %s\n",adjusted_version); findUsableInterfaceKit(); CInterfaceKit kit(phidgetId); CMyDigitalIn *din[8]; CMyAnalogIn *ain[4]; for (int t=0;t<8;t++) din[t]=new CMyDigitalIn(CUID(phidgetId.serial(),t+4)); for (int t=0;t<4;t++) ain[t]=new CMyAnalogIn(CUID(phidgetId.serial(),t)); while (1) kit.update(); // won't get here for (int t=0;t<8;t++) delete din[t]; for (int t=0;t<4;t++) delete ain[t]; } catch(const exception &e) { printf("exception:%s\n",e.what()); } } Index: Makefile.am =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/Makefile.am,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile.am 12 Sep 2002 02:02:44 -0000 1.2 --- Makefile.am 16 Dec 2002 22:37:08 -0000 1.3 *************** *** 1,11 **** ! bin_PROGRAMS = phidget_c phidget_cpp servo_example phidget_c_SOURCES = phidget_c.c - phidget_c_LDADD = ../libphidget/libphidget.la phidget_c_DEPENDENCIES = ../libphidget/libphidget.la phidget_cpp_SOURCES = phidget_cpp.cc - phidget_cpp_LDADD = ../libphidget/libphidget.la ../phidget++/libphidget++.la phidget_cpp_DEPENDENCIES = ../libphidget/libphidget.la ../phidget++/libphidget++.la --- 1,9 ---- ! bin_PROGRAMS = phidget_c phidget_cpp servo_example ik_example phidget_c_SOURCES = phidget_c.c phidget_c_LDADD = ../libphidget/libphidget.la phidget_c_DEPENDENCIES = ../libphidget/libphidget.la phidget_cpp_SOURCES = phidget_cpp.cc phidget_cpp_LDADD = ../libphidget/libphidget.la ../phidget++/libphidget++.la phidget_cpp_DEPENDENCIES = ../libphidget/libphidget.la ../phidget++/libphidget++.la *************** *** 13,19 **** servo_example_SOURCES = servo_example.cc - servo_example_LDADD = ../libphidget/libphidget.la ../phidget++/libphidget++.la servo_example_DEPENDENCIES = ../libphidget/libphidget.la ../phidget++/libphidget++.la CFLAGS = -I../libphidget -L../libphidget --- 11,20 ---- servo_example_SOURCES = servo_example.cc servo_example_LDADD = ../libphidget/libphidget.la ../phidget++/libphidget++.la servo_example_DEPENDENCIES = ../libphidget/libphidget.la ../phidget++/libphidget++.la + + ik_example_SOURCES = ik_example.cc + ik_example_LDADD = ../libphidget/libphidget.la ../phidget++/libphidget++.la + ik_example_DEPENDENCIES = ../libphidget/libphidget.la ../phidget++/libphidget++.la CFLAGS = -I../libphidget -L../libphidget |
Update of /cvsroot/libphidget/libphidget/src/phidget++ In directory sc8-pr-cvs1:/tmp/cvs-serv17868/phidget++ Modified Files: CAnalogIn.cc CAnalogIn.h CDigitalIn.cc CDigitalIn.h CDigitalOut.h CInterfaceKit.cc CInterfaceKit.h CServo.cc Log Message: Added onChange events to Digital and Analog inputs, wrote an example script that uses these called ik_example. Index: CAnalogIn.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CAnalogIn.cc,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CAnalogIn.cc 15 Dec 2002 20:40:11 -0000 1.6 --- CAnalogIn.cc 16 Dec 2002 22:37:09 -0000 1.7 *************** *** 10,17 **** #include "CAnalogIn.h" #include "CInterfaceKit.h" ! CAnalogIn::CAnalogIn (CInterfaceKit *interfacekit, int id) : CUniqueDevice (interfacekit, id), ! _interfaceKit(interfacekit), _value(0), ! _lastValue(0) { } --- 10,48 ---- #include "CAnalogIn.h" #include "CInterfaceKit.h" + #include "CPhidgetManager.h" + #include <helper.h> ! CAnalogIn::CAnalogIn (CInterfaceKit *interfacekit, int id) : ! CUniqueDevice (interfacekit, id), ! _interfaceKit(interfacekit), ! _value(0), ! _lastValue(0), ! _systemManaged(false) ! { ! } ! ! CAnalogIn::CAnalogIn (const CUID &uid) : ! CUniqueDevice (uid), ! _value(false), ! _lastValue(false), ! _systemManaged(false) { + METHOD_GUARD; + + // We have to create it this way, because the phidget manager will + // be in charge of this servo controller, or return us a servo controller that has already been created. + _interfaceKit = dynamic_cast < CInterfaceKit *>(CPhidgetManager::getInstance()->find(CUID (uid.serial()), true)); + + // Let the controller know about this servo + _interfaceKit->registerAnalogIn(this, uid.id()); + + METHOD_UNGUARD; + } + + CAnalogIn::~CAnalogIn () + { + METHOD_GUARD; + if (!_systemManaged) + _interfaceKit->unregisterAnalogIn(UID()); + METHOD_UNGUARD; } Index: CAnalogIn.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CAnalogIn.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CAnalogIn.h 15 Dec 2002 23:41:55 -0000 1.6 --- CAnalogIn.h 16 Dec 2002 22:37:10 -0000 1.7 *************** *** 32,35 **** --- 32,37 ---- float _value; float _lastValue; + int _cardinal; + bool _systemManaged; *************** *** 40,53 **** _lastValue=_value; _value=value; } public: /** * Empty virtual constructor */ ! virtual ~ CAnalogIn () ! { ! } /** --- 42,64 ---- _lastValue=_value; _value=value; + + if (_value != _lastValue) + onChange(); + } + + // Should only be called by interface kit + void setCardinal(int cardinal) + { + _cardinal=cardinal; } public: + CAnalogIn (const CUID &uid); + int cardinal() const {return(_cardinal);} /** * Empty virtual constructor */ ! virtual ~CAnalogIn(); /** *************** *** 68,71 **** --- 79,84 ---- return (NULL); } + + virtual void onChange() {} }; Index: CDigitalIn.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.cc,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CDigitalIn.cc 15 Dec 2002 20:40:11 -0000 1.6 --- CDigitalIn.cc 16 Dec 2002 22:37:10 -0000 1.7 *************** *** 8,18 **** */ #include "CDigitalIn.h" #include "CInterfaceKit.h" ! CDigitalIn::CDigitalIn (CInterfaceKit *interfacekit, int id) : ! CUniqueDevice (interfacekit, id), _value(false), ! _lastValue(false) { } --- 8,48 ---- */ + #include "CPhidgetManager.h" #include "CDigitalIn.h" #include "CInterfaceKit.h" + #include <helper.h> ! CDigitalIn::CDigitalIn (CInterfaceKit *interfaceKit, int id) : ! CUniqueDevice (interfaceKit, id), _value(false), ! _lastValue(false), ! _interfaceKit(interfaceKit), ! _systemManaged(true) ! { ! } ! ! CDigitalIn::CDigitalIn (const CUID &uid) : ! CUniqueDevice (uid), ! _value(false), ! _lastValue(false), ! _systemManaged(false) { + METHOD_GUARD; + + // We have to create it this way, because the phidget manager will + // be in charge of this servo controller, or return us a servo controller that has already been created. + _interfaceKit = dynamic_cast < CInterfaceKit *>(CPhidgetManager::getInstance()->find(CUID (uid.serial()), true)); + + // Let the controller know about this servo + _interfaceKit->registerDigitalIn(this, uid.id()); + + METHOD_UNGUARD; + } + + CDigitalIn::~CDigitalIn () + { + METHOD_GUARD; + if (!_systemManaged) + _interfaceKit->unregisterDigitalIn(UID()); + METHOD_UNGUARD; } Index: CDigitalIn.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalIn.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CDigitalIn.h 15 Dec 2002 23:41:55 -0000 1.6 --- CDigitalIn.h 16 Dec 2002 22:37:11 -0000 1.7 *************** *** 30,33 **** --- 30,36 ---- bool _value; bool _lastValue; + bool _systemManaged; + int _cardinal; + CInterfaceKit *_interfaceKit; CDigitalIn (CInterfaceKit *interfacekit, int id); *************** *** 35,49 **** void setValue(bool value) { ! _lastValue=value; _value=value; } public: /** * Standard virtual destructor */ ! virtual ~ CDigitalIn () ! { ! } /** --- 38,63 ---- void setValue(bool value) { ! ! _lastValue=_value; _value=value; + + if (_value!=_lastValue) + onChange(); + } + + // should only be called by the interface kit + void setCardinal(int cardinal) + { + _cardinal=cardinal; } public: + int cardinal() const {return(_cardinal);} + CDigitalIn ( const CUID &uid); + /** * Standard virtual destructor */ ! virtual ~CDigitalIn (); /** *************** *** 64,67 **** --- 78,83 ---- return (NULL); } + + virtual void onChange() {} }; Index: CDigitalOut.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CDigitalOut.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CDigitalOut.h 15 Dec 2002 20:40:11 -0000 1.5 --- CDigitalOut.h 16 Dec 2002 22:37:11 -0000 1.6 *************** *** 32,36 **** --- 32,42 ---- bool _value; bool _systemManaged; + int _cardinal; + // Should only be called by interface kit + void setCardinal(int cardinal) + { + _cardinal=cardinal; + } CDigitalOut (CInterfaceKit *interfacekit, int id); Index: CInterfaceKit.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CInterfaceKit.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CInterfaceKit.cc 15 Dec 2002 23:41:55 -0000 1.7 --- CInterfaceKit.cc 16 Dec 2002 22:37:11 -0000 1.8 *************** *** 17,28 **** #include "helper.h" - //CInterfaceKit::CInterfaceKit (phidget *device) : - //CPhidget (device) CInterfaceKit::CInterfaceKit (const CUID &uid) : CPhidget (uid) { - //if (classType() != INTERFACE_KIT) - //throw runtime_error("Can't initialize a CInterfaceKit with a phidget that is not an interface kit"); - if (classType() == LP_INTERFACE_KIT_488) { --- 17,23 ---- *************** *** 30,33 **** --- 25,32 ---- setDigitalInCount(8); setDigitalOutCount(8); + + _analogInOffset=0; + _digitalInOffset=_analogInCount; + _digitalOutOffset=_analogInCount+_digitalInOffset; return; } *************** *** 38,71 **** setDigitalInCount(8); setDigitalOutCount(0); return; } ! ! ! 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::setDigitalInCount(int num) { METHOD_GUARD; _digitalInCount = num; --- 37,56 ---- setDigitalInCount(8); setDigitalOutCount(0); + + _analogInOffset=0; + _digitalInOffset=_analogInCount; + _digitalOutOffset=_analogInCount+_digitalInOffset; return; } ! 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) { METHOD_GUARD; + _digitalInCount = num; *************** *** 81,94 **** } ! /* ! 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::setDigitalOutCount(int num) { --- 66,100 ---- } ! void CInterfaceKit::registerDigitalIn(CDigitalIn *in, int id) { ! METHOD_GUARD; ! in->setCardinal(id-_digitalInOffset); ! if (in->cardinal() < 0 || in->cardinal() >= _digitalInCount) ! throw runtime_error("Invalid digital input id"); ! ! if (_digitalIns[in->cardinal()].second != NULL) ! throw runtime_error("This digital input is already being used."); ! ! _digitalIns[in->cardinal()].first = false; ! _digitalIns[in->cardinal()].second = in; ! ! METHOD_UNGUARD; } ! ! void CInterfaceKit::unregisterDigitalIn(const CUID &uid) ! { ! METHOD_GUARD; ! if ((uid.id() < 0+_digitalInOffset && uid.id() >= _digitalInCount+_digitalInOffset) || uid.serial() != UID().serial()) ! throw runtime_error("Invalid digital input id"); ! ! if (_digitalIns[uid.id()-_digitalInOffset].first) ! throw runtime_error("Can't unregister a system managed digital input"); ! ! _digitalIns[uid.id()-_digitalInOffset].first = true; ! _digitalIns[uid.id()-_digitalInOffset].second = NULL; ! METHOD_UNGUARD; ! } ! void CInterfaceKit::setDigitalOutCount(int num) { *************** *** 107,120 **** } - /* - 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)); - } - */ void CInterfaceKit::setAnalogInCount(int num) { --- 113,116 ---- *************** *** 133,163 **** } ! /* ! 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]; ! */ for (int t = 0; t < _digitalInCount; t++) if (_digitalIns[t].first) --- 129,165 ---- } ! void CInterfaceKit::registerAnalogIn(CAnalogIn *in, int id) { ! METHOD_GUARD; ! in->setCardinal(id-_analogInOffset); ! if (in->cardinal() < 0 || in->cardinal() >= _analogInCount) ! throw runtime_error("Invalid analog input id"); ! if (_analogIns[in->cardinal()].second != NULL) ! throw runtime_error("This analog input is already being used."); ! ! _analogIns[in->cardinal()].first = false; ! _analogIns[in->cardinal()].second = in; ! ! METHOD_UNGUARD; } ! void CInterfaceKit::unregisterAnalogIn(const CUID &uid) { ! METHOD_GUARD; ! if ((uid.id() < 0+_analogInOffset && uid.id() >= _analogInCount+_analogInOffset) || uid.serial() != UID().serial()) ! throw runtime_error("Invalid analog input id"); ! if (_analogIns[uid.id()-_analogInOffset].first) ! throw runtime_error("Can't unregister a system managed analog input"); ! _analogIns[uid.id()-_analogInOffset].first = true; ! _analogIns[uid.id()-_analogInOffset].second = NULL; ! METHOD_UNGUARD; ! } + CInterfaceKit::~CInterfaceKit () + { for (int t = 0; t < _digitalInCount; t++) if (_digitalIns[t].first) *************** *** 215,224 **** } - /* - const vector <CDigitalIn *>&CInterfaceKit::digitalIns() const - { - return (_digitalIns); - } - */ CDigitalIn *CInterfaceKit::digitalIn(const int id, bool create) { --- 217,220 ---- *************** *** 230,234 **** { _digitalIns[id].first = true; ! _digitalIns[id].second = new CDigitalIn(this, id); } --- 226,231 ---- { _digitalIns[id].first = true; ! _digitalIns[id].second = new CDigitalIn(this, id+_digitalInOffset); ! _digitalIns[id].second->setCardinal(id); } *************** *** 237,246 **** } - /* - const vector <CDigitalOut *>&CInterfaceKit::digitalOuts() const - { - return (_digitalOuts); - } - */ CDigitalOut *CInterfaceKit::digitalOut(const int id, bool create) { --- 234,237 ---- *************** *** 252,256 **** { _digitalOuts[id].first = true; ! _digitalOuts[id].second = new CDigitalOut(this, id+_digitalInCount); } --- 243,247 ---- { _digitalOuts[id].first = true; ! _digitalOuts[id].second = new CDigitalOut(this, id+_digitalOutOffset); } *************** *** 259,268 **** } - /* - const vector <CAnalogIn *>&CInterfaceKit::analogIns() const - { - return (_analogIns); - } - */ CAnalogIn *CInterfaceKit::analogIn(const int id, bool create) { --- 250,253 ---- *************** *** 274,278 **** { _analogIns[id].first = true; ! _analogIns[id].second = new CAnalogIn(this, id+_digitalInCount+_digitalOutCount); } --- 259,263 ---- { _analogIns[id].first = true; ! _analogIns[id].second = new CAnalogIn(this, id+_analogInOffset); } *************** *** 286,324 **** CUniqueDevice *temp; ! if (uid.serial() == UID().serial() && uid.id() >= 0 && uid.id() < _digitalInCount) ! return (digitalIn(uid.id(), create)); ! if (uid.serial() == UID().serial() && uid.id() >= _digitalInCount && uid.id() < (_digitalInCount+_digitalOutCount)) ! return (digitalOut(uid.id()-_digitalInCount, create)); ! if (uid.serial() == UID().serial() && uid.id() >= (_digitalInCount+_digitalOutCount) && uid.id() < (_digitalInCount+_digitalOutCount+_analogInCount)) ! return (analogIn(uid.id()-_digitalInCount-_digitalOutCount, create)); return (CPhidget::find(uid)); - /* - 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); - */ METHOD_UNGUARD; } --- 271,285 ---- CUniqueDevice *temp; ! if (uid.serial() == UID().serial() && uid.id() >= 0+_digitalInOffset && uid.id() < _digitalInCount+_digitalInOffset) ! return (digitalIn(uid.id()-_digitalInOffset, create)); ! if (uid.serial() == UID().serial() && uid.id() >= 0+_digitalOutOffset && uid.id() < _digitalOutCount+_digitalOutOffset) ! return (digitalOut(uid.id()-_digitalOutOffset, create)); ! if (uid.serial() == UID().serial() && uid.id() >= 0+_analogInOffset && uid.id() < _analogInCount+_analogInOffset) ! return (analogIn(uid.id()-_analogInOffset, create)); return (CPhidget::find(uid)); METHOD_UNGUARD; } Index: CInterfaceKit.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CInterfaceKit.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CInterfaceKit.h 15 Dec 2002 23:41:55 -0000 1.6 --- CInterfaceKit.h 16 Dec 2002 22:37:11 -0000 1.7 *************** *** 32,51 **** friend class CAnalogIn; int _digitalInCount; int _digitalOutCount; - int _analogInCount; pair < bool, CDigitalIn *> *_digitalIns; pair < bool, CDigitalOut *> *_digitalOuts; - pair < bool, CAnalogIn *> *_analogIns; - ! //vector <CDigitalIn *>_digitalIns; ! //vector <CDigitalOut *>_digitalOuts; ! //vector <CAnalogIn *>_analogIns; void setDigitalInCount(int num); void setDigitalOutCount(int num); - void setAnalogInCount(int num); CInterfaceKit(phidget *device); --- 32,55 ---- friend class CAnalogIn; + int _analogInCount; int _digitalInCount; int _digitalOutCount; + int _analogInOffset; + int _digitalInOffset; + int _digitalOutOffset; + + pair < bool, CAnalogIn *> *_analogIns; pair < bool, CDigitalIn *> *_digitalIns; pair < bool, CDigitalOut *> *_digitalOuts; ! void registerDigitalIn(CDigitalIn *in,int id); ! void registerAnalogIn(CAnalogIn *in,int id); ! void unregisterDigitalIn(const CUID &uid); ! void unregisterAnalogIn(const CUID &uid); + void setAnalogInCount(int num); void setDigitalInCount(int num); void setDigitalOutCount(int num); CInterfaceKit(phidget *device); *************** *** 53,59 **** public: int getDigitalInCount() const {return(_digitalInCount);} int getDigitalOutCount() const {return(_digitalOutCount);} - int getAnalogInCount() const {return(_analogInCount);} /** --- 57,63 ---- public: + int getAnalogInCount() const {return(_analogInCount);} int getDigitalInCount() const {return(_digitalInCount);} int getDigitalOutCount() const {return(_digitalOutCount);} /** *************** *** 62,66 **** * pass it to this constructor, in the constructor of his derived type. */ - //CInterfaceKit(CInterfaceKit *orig); CInterfaceKit(const CUID &uid); --- 66,69 ---- *************** *** 73,99 **** 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, bool create); CDigitalIn *digitalIn(const int id, bool create=true); CDigitalOut *digitalOut(const int id, bool create=true); - CAnalogIn *analogIn(const int id, bool create=true); }; --- 76,84 ---- void update(); CUniqueDevice *find(const CUID &uid, bool create); + CAnalogIn *analogIn(const int id, bool create=true); CDigitalIn *digitalIn(const int id, bool create=true); CDigitalOut *digitalOut(const int id, bool create=true); }; Index: CServo.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CServo.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CServo.cc 15 Dec 2002 20:40:11 -0000 1.7 --- CServo.cc 16 Dec 2002 22:37:12 -0000 1.8 *************** *** 37,50 **** } ! CServo::CServo (const CUID &uid):CUniqueDevice (uid), _position(0), ! _systemManaged(false) { METHOD_GUARD; ! // We have to create it this way, because the phidget manager will ! // be in charge of this servo controller, or return us a servo controller that has already been created. ! _controller = dynamic_cast < CServoController *>(CPhidgetManager::getInstance()->find(CUID (uid.serial()), true)); ! // Let the controller know about this servo ! _controller->registerServo(this, uid.id()); METHOD_UNGUARD; } --- 37,51 ---- } ! CServo::CServo (const CUID &uid) : ! CUniqueDevice (uid), _position(0), ! _systemManaged(false) { METHOD_GUARD; ! // We have to create it this way, because the phidget manager will ! // be in charge of this servo controller, or return us a servo controller that has already been created. ! _controller = dynamic_cast < CServoController *>(CPhidgetManager::getInstance()->find(CUID (uid.serial()), true)); ! // Let the controller know about this servo ! _controller->registerServo(this, uid.id()); METHOD_UNGUARD; } *************** *** 53,58 **** { METHOD_GUARD; ! if (!_systemManaged) ! _controller->unregisterServo(UID()); METHOD_UNGUARD; } --- 54,59 ---- { METHOD_GUARD; ! if (!_systemManaged) ! _controller->unregisterServo(UID()); METHOD_UNGUARD; } |
From: Jack S. <js...@us...> - 2002-12-16 22:23:41
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory sc8-pr-cvs1:/tmp/cvs-serv12735/libphidget Modified Files: phidget.c Log Message: minor bug where C wouldn't compile it, but C++ would Index: phidget.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** phidget.c 15 Dec 2002 23:41:55 -0000 1.25 --- phidget.c 16 Dec 2002 22:23:31 -0000 1.26 *************** *** 1380,1383 **** --- 1380,1384 ---- { char buffer[7]; + enum ELPError err; // Not correct type of interface kit *************** *** 1385,1389 **** return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE)); ! enum ELPError err=phidgetRead(phidgetDevice,buffer,sizeof(buffer)); if (err!=LPE_NONE) return(_error(err)); --- 1386,1390 ---- return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE)); ! err=phidgetRead(phidgetDevice,buffer,sizeof(buffer)); if (err!=LPE_NONE) return(_error(err)); *************** *** 1427,1430 **** --- 1428,1432 ---- int t=0; char buffer[7]; + enum ELPError err; // Not correct type of interface kit *************** *** 1434,1438 **** for (t=0;t<2;t++) { ! enum ELPError err=phidgetRead(phidgetDevice,buffer,sizeof(buffer)); if (err!=LPE_NONE) return(_error(err)); --- 1436,1440 ---- for (t=0;t<2;t++) { ! err=phidgetRead(phidgetDevice,buffer,sizeof(buffer)); if (err!=LPE_NONE) return(_error(err)); |