[Libphidget-cvs-commits] CVS: libphidget/src/libphidget phidget.c,1.6,1.7
Status: Alpha
Brought to you by:
jstrohm
|
From: Jack S. <js...@us...> - 2002-09-14 01:24:43
|
Update of /cvsroot/libphidget/libphidget/src/libphidget
In directory usw-pr-cvs1:/tmp/cvs-serv8917
Modified Files:
phidget.c
Log Message:
Fixed error check code
Index: phidget.c
===================================================================
RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** phidget.c 12 Sep 2002 02:35:15 -0000 1.6
--- phidget.c 14 Sep 2002 01:24:39 -0000 1.7
***************
*** 300,306 ****
* When it is reatached we will search this list to see if it matches this device.
*/
! void
_addDevice(struct usb_device *device, struct phidget_type *ptd)
{
struct phidget *temp = malloc(sizeof(struct phidget));
--- 300,307 ----
* When it is reatached we will search this list to see if it matches this device.
*/
! enum ELPError
_addDevice(struct usb_device *device, struct phidget_type *ptd)
{
+ enum ELPError err;
struct phidget *temp = malloc(sizeof(struct phidget));
***************
*** 320,329 ****
* then we close it. Serial must first be -1
*/
! phidgetOpen(temp);
! phidgetClose(temp);
_usbDeviceList[_phidgetDeviceCount] = temp;
_phidgetDeviceCount++;
}
--- 321,337 ----
* then we close it. Serial must first be -1
*/
!
! if (phidgetOpen(temp)==NULL)
! return(_error(phidgetLastError()));
!
! err=phidgetClose(temp);
! if (err!=LPE_NONE)
! return(_error(err));
_usbDeviceList[_phidgetDeviceCount] = temp;
_phidgetDeviceCount++;
+
+ return(LPE_NONE);
}
***************
*** 332,336 ****
* only be called once during initialization.
*/
! void
_findPhidgets()
{
--- 340,344 ----
* only be called once during initialization.
*/
! enum ELPError
_findPhidgets()
{
***************
*** 353,359 ****
dev->descriptor.idProduct);
if (pdt != NULL)
! _addDevice(dev, pdt);
}
}
}
--- 361,375 ----
dev->descriptor.idProduct);
if (pdt != NULL)
! {
! enum ELPError err;
!
! err=_addDevice(dev, pdt);
!
! if (err!=LPE_NONE) return(_error(err));
! }
}
}
+
+ return(LPE_NONE);
}
***************
*** 466,472 ****
! int
phidgetInit(int catch_signals)
{
DBG("phidgetInit");
--- 482,490 ----
! enum ELPError
phidgetInit(int catch_signals)
{
+ enum ELPError err;
+
DBG("phidgetInit");
***************
*** 492,496 ****
_libPhidgetInitialized = 1;
! _findPhidgets();
--- 510,516 ----
_libPhidgetInitialized = 1;
! err=_findPhidgets();
! if (err!=LPE_NONE)
! return(_error(err));
***************
*** 571,576 ****
}
! struct phidget *
! phidgetOpen(struct phidget *phidgetDevice)
{
int ret;
--- 591,595 ----
}
! struct phidget * phidgetOpen(struct phidget *phidgetDevice)
{
int ret;
***************
*** 671,719 ****
}
! enum ELPError
! phidgetClose(struct phidget *phidgetDevice)
{
! DBG("phidgetClose");
! if (_libPhidgetInitialized == 0)
! return (_error(LPE_NOT_INITIALIZED));
! if (phidgetDevice == NULL)
! return (_error(LPE_INVALID_PHIDGET));
!
! if (phidgetDevice->attached == 0) {
! if (phidgetDevice->openedState == WAS_OPENED) {
! phidgetDevice->openedState = WAS_CLOSED;
! return;
! }
!
! phidgetDevice->openedState = WAS_ERROR;
! return (_error(LPE_PHIDGET_ALREADY_CLOSED));
! }
! if (phidgetDevice->handle) {
! if (phidgetDevice->type->deviceClass == LP_SERVO_CONTROLLER) {
! if (phidgetDevice->defaultData == NULL) {
! // Turn the servo's off
! char buffer[6] = { 0, 0, 0, 0, 0, 0 };
! phidgetWrite(phidgetDevice, buffer, 6);
! } else {
! phidgetWrite(phidgetDevice, phidgetDevice->defaultData, phidgetDevice->defaultDataSize);
! }
}
! usb_release_interface(phidgetDevice->handle, 0);
! usb_close(phidgetDevice->handle);
! phidgetDevice->handle = NULL;
! phidgetDevice->openedState = WAS_CLOSED;
! } else {
! phidgetDevice->openedState = WAS_ERROR;
! return (_error(LPE_PHIDGET_NOT_OPENED));
! }
! return (_error(LPE_NONE));
}
--- 690,749 ----
}
! enum ELPError phidgetClose(struct phidget *phidgetDevice)
{
! DBG("phidgetClose");
+ if (_libPhidgetInitialized == 0)
+ return (_error(LPE_NOT_INITIALIZED));
! if (phidgetDevice == NULL)
! return (_error(LPE_INVALID_PHIDGET));
! if (phidgetDevice->attached == 0)
! {
! if (phidgetDevice->openedState == WAS_OPENED)
! {
! phidgetDevice->openedState = WAS_CLOSED;
! return(_error(LPE_NONE));
! }
+ phidgetDevice->openedState = WAS_ERROR;
+ return (_error(LPE_PHIDGET_ALREADY_CLOSED));
}
! if (phidgetDevice->handle)
! {
! if (phidgetDevice->type->deviceClass == LP_SERVO_CONTROLLER)
! {
! if (phidgetDevice->defaultData == NULL)
! {
! // Turn the servo's off
! char buffer[6] = { 0, 0, 0, 0, 0, 0 };
! enum ELPError err=phidgetWrite(phidgetDevice, buffer, 6);
! if (err!=LPE_NONE)
! return(_error(err));
! } else
! {
! enum ELPError err;
!
! err=phidgetWrite(phidgetDevice, phidgetDevice->defaultData, phidgetDevice->defaultDataSize);
! if (err!=LPE_NONE)
! return(_error(err));
! }
! }
+ usb_release_interface(phidgetDevice->handle, 0);
+ usb_close(phidgetDevice->handle);
+ phidgetDevice->handle = NULL;
+ phidgetDevice->openedState = WAS_CLOSED;
+ } else
+ {
+ phidgetDevice->openedState = WAS_ERROR;
+ return (_error(LPE_PHIDGET_NOT_OPENED));
+ }
+
+ return (_error(LPE_NONE));
}
***************
*** 731,735 ****
return (_error(LPE_PHIDGET_NOT_OPENED));
! if (usb_control_msg(phidgetDevice->handle, 0x21, 0x09, 0x200, 0, buffer, size, 5000) != 0)
return (_error(LPE_CONTROL_MSG_ERROR));
return (_error(LPE_NONE));
--- 761,765 ----
return (_error(LPE_PHIDGET_NOT_OPENED));
! if (usb_control_msg(phidgetDevice->handle, 0x21, 0x09, 0x200, 0, buffer, size, 5000)!=size)
return (_error(LPE_CONTROL_MSG_ERROR));
return (_error(LPE_NONE));
|