Update of /cvsroot/libphidget/libphidget/src/examples
In directory usw-pr-cvs1:/tmp/cvs-serv15763
Modified Files:
phidget_cpp.cc
Log Message:
The example didn't properly handle unsupported phidgets (find method returns a NULL for an unsupported phidget).
Index: phidget_cpp.cc
===================================================================
RCS file: /cvsroot/libphidget/libphidget/src/examples/phidget_cpp.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** phidget_cpp.cc 12 Sep 2002 01:31:18 -0000 1.4
--- phidget_cpp.cc 16 Sep 2002 23:37:07 -0000 1.5
***************
*** 197,243 ****
*/
! void
! phidgets_ls()
{
! CPhidgetManager *manager = CPhidgetManager::getInstance();
!
! vector <CUID >phidgets = manager->query(LP_PHIDGET);
! printf("\n");
! printf(" UID Name Misc\n");
! printf("-------- -------------------------------- ----------------\n");
! for (int t = 0; t < phidgets.size(); t++) {
! const CUID &uid = phidgets[t];
! CPhidget *phidget = dynamic_cast < CPhidget *>(manager->find(uid, true));
! if (phidget == NULL)
! throw runtime_error("obtained a phidget CUID that was not a phidget, this can't happen.");
! printf("%8d %32s ", phidget->UID().serial(), phidget->name());
! CServoController *sc = dynamic_cast < CServoController *>(phidget);
! if (sc != NULL) {
! printf("Servos: %d\n", sc->servoCount());
}
! /*
! else
! if (ik!=NULL)
! {
! printf("DigitalIn: %d\n",ik->digitalIns().size());
! printf(" DigitalOut: %d\n",ik->digitalOuts().size());
! printf(" AnalogIns: %d\n",ik->analogIns().size());
! }
! */
! else
! printf("Unsupported\n");
! }
! printf("-------- -------------------------------- ----------------\n");
! printf("\n\n");
! printf("Total phidgets:%d\n", phidgets.size());
! printf("\n");
}
--- 197,243 ----
*/
! void phidgets_ls()
{
! CPhidgetManager *manager = CPhidgetManager::getInstance();
! vector <CUID >phidgets = manager->query(LP_PHIDGET);
! printf("\n");
! printf(" UID Name Misc\n");
! printf("-------- -------------------------------- ----------------\n");
! for (int t = 0; t < phidgets.size(); t++)
! {
! const CUID &uid = phidgets[t];
! CUniqueDevice *ud=manager->find(uid,true);
! if (ud!=NULL)
! {
! //CPhidget *phidget = dynamic_cast < CPhidget *>(manager->find(uid, true));
! CPhidget *phidget = dynamic_cast < CPhidget *>(ud);
!
! if (phidget == NULL)
! throw runtime_error("obtained a phidget CUID that was not a phidget, this can't happen.");
! printf("%8d %32s ", phidget->UID().serial(), phidget->name());
!
! CServoController *sc = dynamic_cast < CServoController *>(phidget);
! if (sc != NULL)
! printf("Servos: %d\n", sc->servoCount());
! else
! printf("Unsupported\n");
! }
! else
! {
! printf("%8d Unsupported Phidget\n", uid.serial());
! }
}
! printf("-------- -------------------------------- ----------------\n");
! printf("\n\n");
! printf("Total phidgets:%d\n", phidgets.size());
! printf("\n");
}
|