[Libphidget-cvs-commits] CVS: libphidget/src/libphidget phidget.c,1.26,1.27 phidget.h,1.20,1.21
Status: Alpha
Brought to you by:
jstrohm
|
From: Jack S. <js...@us...> - 2002-12-23 04:38:44
|
Update of /cvsroot/libphidget/libphidget/src/libphidget
In directory sc8-pr-cvs1:/tmp/cvs-serv25634/libphidget
Modified Files:
phidget.c phidget.h
Log Message:
Lot's of changes with how servo controller classes work. Now added seperate classes for servo controllers (uni and quad).
Index: phidget.c
===================================================================
RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** phidget.c 16 Dec 2002 22:23:31 -0000 1.26
--- phidget.c 23 Dec 2002 04:38:40 -0000 1.27
***************
*** 95,98 ****
--- 95,104 ----
void *defaultData;
+ /** Size of extra data */
+ int extraDataSize;
+
+ /** Extra data used to store any configuration info for a phidget */
+ void *extraData;
+
/** Virtual state of the device, this keeps the state of the device even when it is detached. */
enum
***************
*** 561,565 ****
--- 567,574 ----
temp->attached = 0;
temp->openedState = WAS_CLOSED;
+ temp->defaultDataSize = 0;
temp->defaultData = NULL;
+ temp->extraDataSize = 0;
+ temp->extraData = NULL;
/**
***************
*** 899,904 ****
_clearDeviceTypes();
! _registerDeviceType("QuadServo .1 Degree", 0x06C2, 0x0038, LP_SERVO_CONTROLLER);
! _registerDeviceType("UniServo .1 Degree", 0x06C2, 0x0039, LP_SERVO_CONTROLLER);
_registerDeviceType("Interface Kit 4/8/8", 0x0925, 0x8201, LP_INTERFACE_KIT_488);
_registerDeviceType("Interface Kit 4/8/8", 0x06C2, 0x0040, LP_INTERFACE_KIT_488);
--- 908,913 ----
_clearDeviceTypes();
! _registerDeviceType("QuadServo .1 Degree", 0x06C2, 0x0038, LP_QUAD_SERVO);
! _registerDeviceType("UniServo .1 Degree", 0x06C2, 0x0039, LP_UNI_SERVO);
_registerDeviceType("Interface Kit 4/8/8", 0x0925, 0x8201, LP_INTERFACE_KIT_488);
_registerDeviceType("Interface Kit 4/8/8", 0x06C2, 0x0040, LP_INTERFACE_KIT_488);
***************
*** 907,911 ****
_registerDeviceType("PhidgetTextLCD ECMA1010 Ver 1.0", 0x06C2, 0x0050,LP_TEXT_LCD);
//_registerDeviceType("RFID VID/PID", 0x06C2, 0x0030, LP_OTHER);
! //_registerDeviceType("8-AdvancedServo", 0x06C2, 0x003B, LP_SERVO_CONTROLLER);
//_registerDeviceType("Interface Kit 32-32-0", 0x06C2, 0x0042, LP_INTERFACE_KIT);
//_registerDeviceType("Interface Kit 0-256-0", 0x06C2, 0x0043, LP_INTERFACE_KIT);
--- 916,920 ----
_registerDeviceType("PhidgetTextLCD ECMA1010 Ver 1.0", 0x06C2, 0x0050,LP_TEXT_LCD);
//_registerDeviceType("RFID VID/PID", 0x06C2, 0x0030, LP_OTHER);
! //_registerDeviceType("8-AdvancedServo", 0x06C2, 0x003B, LP_8WAY_SERVO);
//_registerDeviceType("Interface Kit 32-32-0", 0x06C2, 0x0042, LP_INTERFACE_KIT);
//_registerDeviceType("Interface Kit 0-256-0", 0x06C2, 0x0043, LP_INTERFACE_KIT);
***************
*** 1128,1132 ****
if (phidgetDevice->handle)
{
! if (phidgetDevice->type->deviceClass == LP_SERVO_CONTROLLER)
{
if (phidgetDevice->defaultData == NULL)
--- 1137,1144 ----
if (phidgetDevice->handle)
{
! if (
! phidgetDevice->type->deviceClass == LP_UNI_SERVO ||
! phidgetDevice->type->deviceClass == LP_QUAD_SERVO
! )
{
if (phidgetDevice->defaultData == NULL)
***************
*** 1212,1234 ****
enum ELPError phidgetSingleServo(struct phidget *phidgetDevice, float percent)
{
! int pulse;
! char buffer[6] = { 0 };
! DBG("phidgetSingleServo");
! if (phidgetDevice == NULL)
! return (_error(LPE_INVALID_PHIDGET));
! if (phidgetDevice->type == NULL)
! return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE));
! // Not a servo
! if (phidgetDevice->type->deviceClass != LP_SERVO_CONTROLLER)
! return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE));
! pulse = (int) (((percent) * 180) * 10.6f + 230);
! buffer[0] = pulse % 256;
! buffer[1] = (pulse / 256);
! return (phidgetWrite(phidgetDevice, buffer, sizeof(buffer)));
}
--- 1224,1287 ----
enum ELPError phidgetSingleServo(struct phidget *phidgetDevice, float percent)
{
! int _min=230,_max=(int) (180 * 10.6f + 230)+_min;
! int pulse;
! char buffer[6] = { 0 };
! DBG("phidgetSingleServo");
! if (phidgetDevice == NULL)
! return (_error(LPE_INVALID_PHIDGET));
! if (phidgetDevice->type == NULL)
! return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE));
! // Not a servo
! if (phidgetDevice->type->deviceClass != LP_UNI_SERVO)
! return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE));
! //pulse = (int) (((percent) * 180) * 10.6f + 230);
! if (phidgetDevice->extraData!=NULL)
! {
! int *temp=(int *)phidgetDevice->extraData;
! _min=temp[0];
! _max=temp[1];
! }
! //pulse = (int) (((percent) * 180) * 10.6f + 230);
! pulse=(percent*(_max-_min))+_min;
!
! buffer[0] = pulse % 256;
! buffer[1] = (pulse / 256);
!
! return (phidgetWrite(phidgetDevice, buffer, sizeof(buffer)));
! }
!
! /**
! * Helper function to set the minimum and maximum pulse values for a servo on a phidget
! */
! enum ELPError phidgetSingleServoSetMinMaxPulse(struct phidget *phidgetDevice, int minimum, int maximum)
! {
! int buffer[2];
!
! DBG("phidgetSingleServoSetMinMaxPulse");
!
! if (phidgetDevice == NULL)
! return (_error(LPE_INVALID_PHIDGET));
! if (phidgetDevice->type == NULL)
! return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE));
!
! // Not a servo
! if (phidgetDevice->type->deviceClass != LP_UNI_SERVO)
! return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE));
!
! // Free any defaults that have already been set
! if (phidgetDevice->extraData != NULL)
! free(phidgetDevice);
!
! buffer[0]=minimum;
! buffer[1]=maximum;
!
! phidgetDevice->extraDataSize = sizeof(buffer);
! phidgetDevice->extraData = malloc(phidgetDevice->extraDataSize);
! memcpy(phidgetDevice->extraData, buffer, phidgetDevice->extraDataSize);
}
***************
*** 1250,1254 ****
// Not a servo
! if (phidgetDevice->type->deviceClass != LP_SERVO_CONTROLLER)
return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE));
--- 1303,1307 ----
// Not a servo
! if (phidgetDevice->type->deviceClass != LP_UNI_SERVO)
return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE));
***************
*** 1276,1279 ****
--- 1329,1336 ----
int pulse1, pulse2, pulse3, pulse4;
char buffer[6] = { 0 };
+ int _min1=230,_max1=(int) (180 * 10.6f + 230)+_min1;
+ int _min2=230,_max2=(int) (180 * 10.6f + 230)+_min2;
+ int _min3=230,_max3=(int) (180 * 10.6f + 230)+_min3;
+ int _min4=230,_max4=(int) (180 * 10.6f + 230)+_min4;
DBG("phidgetQuadServo");
***************
*** 1286,1297 ****
// Not a servo
! if (phidgetDevice->type->deviceClass != LP_SERVO_CONTROLLER)
return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE));
! pulse1 = (int) (((percent1) * 180) * 10.6f + 230);
! pulse2 = (int) (((percent2) * 180) * 10.6f + 230);
! pulse3 = (int) (((percent3) * 180) * 10.6f + 230);
! pulse4 = (int) (((percent4) * 180) * 10.6f + 230);
buffer[0] = pulse1 % 256;
--- 1343,1371 ----
// Not a servo
! if (phidgetDevice->type->deviceClass != LP_QUAD_SERVO)
return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE));
! //pulse1 = (int) (((percent1) * 180) * 10.6f + 230);
! //pulse2 = (int) (((percent2) * 180) * 10.6f + 230);
! //pulse3 = (int) (((percent3) * 180) * 10.6f + 230);
! //pulse4 = (int) (((percent4) * 180) * 10.6f + 230);
!
! if (phidgetDevice->extraData!=NULL)
! {
! int *temp=(int *)phidgetDevice->extraData;
! _min1=temp[0];
! _max1=temp[1];
! _min2=temp[2];
! _min2=temp[3];
! _min3=temp[4];
! _max3=temp[5];
! _max4=temp[6];
! _max4=temp[7];
! }
! pulse1=(percent1*(_max1-_min1))+_min1;
! pulse2=(percent2*(_max2-_min2))+_min2;
! pulse3=(percent3*(_max3-_min3))+_min3;
! pulse4=(percent4*(_max4-_min4))+_min4;
buffer[0] = pulse1 % 256;
***************
*** 1324,1328 ****
// Not a servo
! if (phidgetDevice->type->deviceClass != LP_SERVO_CONTROLLER)
return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE));
--- 1398,1402 ----
// Not a servo
! if (phidgetDevice->type->deviceClass != LP_QUAD_SERVO)
return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE));
***************
*** 1351,1354 ****
--- 1425,1469 ----
return (_error(LPE_NONE));
+ }
+
+ /**
+ * Helper function to set the minimum and maximum pulse values for a quad servo on a phidget
+ */
+ enum ELPError phidgetQuadServoSetMinMaxPulse(struct phidget *phidgetDevice,
+ int minimum0, int maximum0,
+ int minimum1, int maximum1,
+ int minimum2, int maximum2,
+ int minimum3, int maximum3
+ )
+ {
+ int buffer[8];
+
+ DBG("phidgetSingleServoSetMinMaxPulse");
+
+ if (phidgetDevice == NULL)
+ return (_error(LPE_INVALID_PHIDGET));
+ if (phidgetDevice->type == NULL)
+ return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE));
+
+ // Not a servo
+ if (phidgetDevice->type->deviceClass != LP_QUAD_SERVO)
+ return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE));
+
+ // Free any defaults that have already been set
+ if (phidgetDevice->extraData != NULL)
+ free(phidgetDevice);
+
+ buffer[0]=minimum0;
+ buffer[1]=maximum0;
+ buffer[2]=minimum1;
+ buffer[3]=maximum1;
+ buffer[4]=minimum2;
+ buffer[5]=maximum2;
+ buffer[6]=minimum3;
+ buffer[7]=maximum3;
+
+ phidgetDevice->extraDataSize = sizeof(buffer);
+ phidgetDevice->extraData = malloc(phidgetDevice->extraDataSize);
+ memcpy(phidgetDevice->extraData, buffer, phidgetDevice->extraDataSize);
}
Index: phidget.h
===================================================================
RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** phidget.h 21 Dec 2002 02:55:07 -0000 1.20
--- phidget.h 23 Dec 2002 04:38:40 -0000 1.21
***************
*** 71,107 ****
enum EDeviceClass
{
! LP_ALL = 1, /**< All devices match this */
// 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 */
!
! 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. */
};
--- 71,102 ----
enum EDeviceClass
{
! LP_ALL = 1, //!< All devices match this
// Actual phidget types
! LP_PHIDGET = 100, //!< Generic phidget, not used in this library
! LP_SERVO_CONTROLLER = 200, //!< Identifies all servo controller phidgets
! LP_UNI_SERVO = 201, //!< Single servo controller
! LP_QUAD_SERVO = 202, //!< Quad servo controller
! LP_8WAY_SERVO = 203, //!< 8 Way servo controller
! 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.
};
***************
*** 215,218 ****
--- 210,222 ----
);
+ /**
+ * Helper function to set the minimum and maximum pulse values for a servo on a phidget
+ */
+ enum ELPError phidgetSingleServoSetMinMaxPulse(
+ struct phidget *phidgetDevice, //<! The phidget whoses pulse values we want to set
+ int minimum, //<! The minimum pulse value (when percent=0)
+ int maximum //<! The maximum pulse value (when percent=1)
+ );
+
/**
* Send an angle (0.0 to 1.0) to four servos. The phidget servo controllers
***************
*** 240,243 ****
--- 244,262 ----
float percent3, //!< Percentage to move servo 3
float percent4 //!< Percentage to move servo 4
+ );
+
+ /**
+ * Helper function to set the minimum and maximum pulse values for a quad servo on a phidget
+ */
+ enum ELPError phidgetQuadServoSetMinMaxPulse(
+ struct phidget *phidgetDevice, //<! The phidget whoses pulse values we want to set
+ int minimum0, //<! The minium pulse value for servo 0 (when percent=0)
+ int maximum0, //<! The minium pulse value for servo 0 (when percent=1)
+ int minimum1, //<! The minium pulse value for servo 1 (when percent=0)
+ int maximum1, //<! The minium pulse value for servo 1 (when percent=1)
+ int minimum2, //<! The minium pulse value for servo 2 (when percent=0)
+ int maximum2, //<! The minium pulse value for servo 2 (when percent=1)
+ int minimum3, //<! The minium pulse value for servo 3 (when percent=0)
+ int maximum3 //<! The minium pulse value for servo 3 (when percent=1)
);
|