[Libphidget-cvs-commits] CVS: libphidget/src/phidget++ CTextLCD.cc,NONE,1.1 CTextLCD.h,NONE,1.1 CPhi
Status: Alpha
Brought to you by:
jstrohm
|
From: Jack S. <js...@us...> - 2002-12-15 05:05:31
|
Update of /cvsroot/libphidget/libphidget/src/phidget++
In directory sc8-pr-cvs1:/tmp/cvs-serv20168/phidget++
Modified Files:
CPhidgetManager.cc Makefile.am
Added Files:
CTextLCD.cc CTextLCD.h
Log Message:
Added support for TextLCD in the phidget++
--- NEW FILE: CTextLCD.cc ---
/*
* phidget++ library
* $Id: CTextLCD.cc,v 1.1 2002/12/15 05:05:28 jstrohm Exp $
*
* Copyright (c) 2002 Jack Strohm <js...@ja...>
*
* This library is covered by the LGPL, read LICENSE for details.
*/
#include "CTextLCD.h"
#include <stdio.h>
#include <stdexcept>
#include <phidget.h>
#include "helper.h"
CTextLCD::CTextLCD (const CUID &uid) :
CPhidget (uid)
{
METHOD_GUARD;
// Make sure it was constructed properly
if (classType() != LP_TEXT_LCD)
throw runtime_error("Can't initialize a CTextLCD with a phidget that is not a text lcd");
phidgetTextLCDOn(device());
METHOD_UNGUARD;
}
CTextLCD::~CTextLCD ()
{
METHOD_GUARD;
phidgetTextLCDOff(device());
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;
}
void CTextLCD::sendText(string text, int row, int col)
{
error(phidgetTextLCDWrite(device(), row,col,text.c_str()));
}
--- NEW FILE: CTextLCD.h ---
/*
* phidget++ library
* $Id: CTextLCD.h,v 1.1 2002/12/15 05:05:28 jstrohm Exp $
*
* Copyright (c) 2002 Jack Strohm <js...@ja...>
*
* This library is covered by the LGPL, read LICENSE for details.
*/
#ifndef __CTEXTLCD_H__
#define __CTEXTLCD_H__
#include "CPhidget.h"
#include <vector>
using namespace std;
/**
* Object that represents all text lcd's
*/
class CTextLCD : public CPhidget
{
private:
public:
CTextLCD (const CUID &uid);
virtual ~CTextLCD ();
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);
};
#endif
Index: CPhidgetManager.cc
===================================================================
RCS file: /cvsroot/libphidget/libphidget/src/phidget++/CPhidgetManager.cc,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** CPhidgetManager.cc 13 Dec 2002 22:53:57 -0000 1.9
--- CPhidgetManager.cc 15 Dec 2002 05:05:28 -0000 1.10
***************
*** 21,25 ****
{
METHOD_GUARD;
! _uniqueDevices.push_back(dev);
METHOD_UNGUARD;
}
--- 21,25 ----
{
METHOD_GUARD;
! _uniqueDevices.push_back(dev);
METHOD_UNGUARD;
}
***************
*** 28,40 ****
{
METHOD_GUARD;
! vector <CUniqueDevice *>::iterator i;
! for (i = _uniqueDevices.begin(); i != _uniqueDevices.end(); i++)
! if (*i == dev) {
! _uniqueDevices.erase(i, i);
! return;
}
! throw runtime_error("Can't unregister a device that wasn't registered.");
METHOD_UNGUARD;
}
--- 28,41 ----
{
METHOD_GUARD;
! vector <CUniqueDevice *>::iterator i;
! for (i = _uniqueDevices.begin(); i != _uniqueDevices.end(); i++)
! if (*i == dev)
! {
! _uniqueDevices.erase(i, i);
! return;
}
! throw runtime_error("Can't unregister a device that wasn't registered.");
METHOD_UNGUARD;
}
***************
*** 78,95 ****
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;
}
--- 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;
}
***************
*** 98,112 ****
{
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;
}
--- 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;
}
***************
*** 115,152 ****
{
METHOD_GUARD;
! set < CUID >devices;
! // Ask libphidget for any known phidgets
! if (tp == LP_ALL || tp == LP_PHIDGET || tp == LP_SERVO_CONTROLLER /*|| tp == LP_INTERFACE_KIT*/) {
! int phidget_count;
! struct phidget **phidgets = error(phidgetGetPhidgets(&phidget_count));
! for (int t = 0; t < phidget_count; t++)
! {
! if (
! (tp == LP_PHIDGET) ||
! (tp == LP_ALL) ||
! (tp == LP_SERVO_CONTROLLER && error(phidgetTypeDeviceClass(error(phidgetType(phidgets[t])))) == LP_SERVO_CONTROLLER) /*||
! (tp == LP_INTERFACE_KIT && error(phidgetTypeDeviceClass(error(phidgetType(phidgets[t])))) == LP_INTERFACE_KIT)*/ )
{
! CUID temp_uid(error(phidgetSerial(phidgets[t])));
! devices.insert(temp_uid);
}
}
- }
- // Ask each known device if it knows about any devices that match the type we are searching for
- if (tp == LP_ALL || tp == LP_SERVO || tp == LP_DIGITAL_IN || tp == LP_DIGITAL_OUT) {
- for (int t = 0; t < _uniqueDevices.size(); t++)
- _uniqueDevices[t]->query(tp, devices);
- }
- // get a vector of the CUID instead of a set
- vector <CUID >temp;
! for (set < CUID >::iterator i = devices.begin(); i != devices.end(); i++)
! temp.push_back(*i);
! return (temp);
METHOD_UNGUARD;
}
--- 116,163 ----
{
METHOD_GUARD;
! 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*/)
! {
! 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 && error(phidgetTypeDeviceClass(error(phidgetType(phidgets[t])))) == LP_INTERFACE_KIT)*/ )
! {
! CUID temp_uid(error(phidgetSerial(phidgets[t])));
! devices.insert(temp_uid);
! }
}
}
! // Ask each known device if it knows about any devices that match the type we are searching for
! if (tp == LP_ALL || tp == LP_SERVO || tp == LP_DIGITAL_IN || tp == LP_DIGITAL_OUT || tp == LP_TEXT_LCD)
! {
! for (int t = 0; t < _uniqueDevices.size(); t++)
! _uniqueDevices[t]->query(tp, devices);
! }
! // get a vector of the CUID instead of a set
! vector <CUID >temp;
!
! for (set < CUID >::iterator i = devices.begin(); i != devices.end(); i++)
! temp.push_back(*i);
!
! return (temp);
METHOD_UNGUARD;
}
***************
*** 156,173 ****
METHOD_GUARD;
! if (uid.id() != -1)
! throw runtime_error("invalid UID to find phidget. id must be -1");
! int phidget_count;
! struct phidget **phidgets = error(phidgetGetPhidgets(&phidget_count));
! for (int t = 0; t < phidget_count; t++) {
! // We open this device
! if (error(phidgetSerial(phidgets[t])) == uid.serial()) {
! return (error(phidgetOpen(phidgets[t])));
}
- }
! return (NULL);
METHOD_UNGUARD;
}
--- 167,186 ----
METHOD_GUARD;
! if (uid.id() != -1)
! throw runtime_error("invalid UID to find phidget. id must be -1");
! int phidget_count;
! struct phidget **phidgets = error(phidgetGetPhidgets(&phidget_count));
! for (int t = 0; t < phidget_count; t++)
! {
! // We open this device
! if (error(phidgetSerial(phidgets[t])) == uid.serial())
! {
! return (error(phidgetOpen(phidgets[t])));
! }
}
! return (NULL);
METHOD_UNGUARD;
}
***************
*** 188,200 ****
{
METHOD_GUARD;
! bool found = (error(phidgetEvents()) == 1);
! // Get the list of phidgets
! if (found) {
! for (int t = 0; t < _uniqueDevices.size(); t++)
! _uniqueDevices[t]->processEvents();
! }
! return (found);
METHOD_UNGUARD;
}
--- 201,214 ----
{
METHOD_GUARD;
! bool found = (error(phidgetEvents()) == 1);
! // Get the list of phidgets
! if (found)
! {
! for (int t = 0; t < _uniqueDevices.size(); t++)
! _uniqueDevices[t]->processEvents();
! }
! return (found);
METHOD_UNGUARD;
}
***************
*** 203,253 ****
{
METHOD_GUARD;
! CUniqueDevice *temp;
! bool isPhidget = false;
! // Is this a phidget or a phidget device we are trying to find?
! // Look at all known devices for this
! for (int t = 0; t < _uniqueDevices.size(); t++) {
! temp = _uniqueDevices[t]->find(uid, create);
! if (temp != NULL)
! return (temp);
! }
!
! // Wasn't found , so let's return because we were not asked to create this device
! if (!create)
! return (NULL);
! // Not found, is it a phidget? or a phidget device
! if (uid.id() == -1)
! isPhidget = true;
! // Make sure the phidget CUID(uid.serial()) exists
! CUID tempUID(uid.serial());
! bool devfound = false;
! if (!isPhidget)
! for (int t = 0; t < _uniqueDevices.size(); t++) {
! if (_uniqueDevices[t]->UID() == uid) {
! devfound = true;
! break;
! }
}
- // Device wasn't found, this is always true if isPhidget is true
- if (!devfound || isPhidget) {
- // Create tempUID, this is the tricky part.
- // How, without know about this phidget do we create it?
! temp = createPhidget(tempUID);
! if (isPhidget)
! return (temp);
! }
! // The base phidget should exists and can now create it for us.
! return (temp->find(uid, create));
METHOD_UNGUARD;
}
--- 217,271 ----
{
METHOD_GUARD;
! CUniqueDevice *temp;
! bool isPhidget = false;
! // Is this a phidget or a phidget device we are trying to find?
! // Look at all known devices for this
! for (int t = 0; t < _uniqueDevices.size(); t++)
! {
! temp = _uniqueDevices[t]->find(uid, create);
! if (temp != NULL)
! return (temp);
! }
! // Wasn't found , so let's return because we were not asked to create this device
! if (!create)
! return (NULL);
! // Not found, is it a phidget? or a phidget device
! if (uid.id() == -1)
! isPhidget = true;
+ // Make sure the phidget CUID(uid.serial()) exists
+ CUID tempUID(uid.serial());
! bool devfound = false;
! if (!isPhidget)
! for (int t = 0; t < _uniqueDevices.size(); t++)
! {
! if (_uniqueDevices[t]->UID() == uid)
! {
! devfound = true;
! break;
! }
}
! // Device wasn't found, this is always true if isPhidget is true
! if (!devfound || isPhidget)
! {
! // Create tempUID, this is the tricky part.
! // How, without know about this phidget do we create it?
+ temp = createPhidget(tempUID);
! if (isPhidget)
! return (temp);
! }
!
! // The base phidget should exists and can now create it for us.
! return (temp->find(uid, create));
METHOD_UNGUARD;
}
***************
*** 256,261 ****
{
METHOD_GUARD;
! // This device better not exists, we assume that has already been checked.
! if (uid.id() != -1)
throw runtime_error("Id must be -1 for all phidgets");
--- 274,279 ----
{
METHOD_GUARD;
! // This device better not exists, we assume that has already been checked.
! if (uid.id() != -1)
throw runtime_error("Id must be -1 for all phidgets");
***************
*** 272,276 ****
case LP_SERVO_CONTROLLER:
{
! CServoController *sc = new CServoController (uid);
return(sc);
break;
--- 290,294 ----
case LP_SERVO_CONTROLLER:
{
! CServoController *sc = new CServoController (uid);
return(sc);
break;
***************
*** 282,286 ****
! return (NULL);
METHOD_UNGUARD;
}
--- 300,304 ----
! return (NULL);
METHOD_UNGUARD;
}
Index: Makefile.am
===================================================================
RCS file: /cvsroot/libphidget/libphidget/src/phidget++/Makefile.am,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Makefile.am 14 Sep 2002 18:59:21 -0000 1.6
--- Makefile.am 15 Dec 2002 05:05:28 -0000 1.7
***************
*** 7,10 ****
--- 7,11 ----
CPhidgetManager.h \
CServo.h \
+ CTextLCD.h \
CServoController.h \
CUID.h \
***************
*** 17,20 ****
--- 18,22 ----
CPhidgetManager.cc \
CServo.cc \
+ CTextLCD.cc \
CServoController.cc \
CUID.cc \
***************
*** 55,57 ****
@ @ECHO@ "*** Documentation is not created - install Doxygen"
endif
!
\ No newline at end of file
--- 57,59 ----
@ @ECHO@ "*** Documentation is not created - install Doxygen"
endif
!
|