Thread: [Libphidget-cvs-commits] CVS: libphidget/src/libphidget SoftPhidget.h,1.1,1.2 phidget.c,1.27,1.28 ph
Status: Alpha
Brought to you by:
jstrohm
|
From: Jack S. <js...@us...> - 2003-06-23 22:37:37
|
Update of /cvsroot/libphidget/libphidget/src/libphidget
In directory sc8-pr-cvs1:/tmp/cvs-serv24449/src/libphidget
Modified Files:
SoftPhidget.h phidget.c phidget.h
Log Message:
Added support for the Power phidget along with initial support for the AdvancedServo soft phidget. Currently regular phidgets don't work though.
Index: SoftPhidget.h
===================================================================
RCS file: /cvsroot/libphidget/libphidget/src/libphidget/SoftPhidget.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SoftPhidget.h 16 Dec 2002 21:26:29 -0000 1.1
--- SoftPhidget.h 23 Jun 2003 22:37:34 -0000 1.2
***************
*** 1,672 ****
! int SOFT_SERVO8_SIZE=7510;
! const unsigned char SOFT_SERVO8_CODE[7510] = {0x53,
! 0x1d,0x6e,0x2,0x0,0xe,0x2,0x10,0xcb,0x0,0x0,0x0,0x0,0x0,0x2,0x11,0x8d,0x75,0x81,0x7a,0x78,0x7a,0x76,0x0,0xd8,0xfc,
! 0x90,0x0,0x0,0xae,0x83,0xaf,0x82,0x90,0x0,0x0,0x12,0x0,0x4c,0x60,0x5,0xe4,0xf0,0xa3,0x80,0xf6,0x90,0x0,0xaa,0x12,0x0,
! 0x55,0x90,0x0,0xae,0x12,0x0,0x55,0x90,0x0,0xb2,0x12,0x0,0x73,0x90,0x0,0xb8,0x12,0x0,0x73,0x75,0xd0,0x0,0x12,0x11,0xad,
! 0x2,0x0,0xbe,0xef,0x65,0x82,0x70,0x3,0xee,0x65,0x83,0x22,0xe4,0x93,0xf8,0x74,0x1,0x93,0xf9,0x74,0x2,0x93,0xfe,0x74,0x3,
! 0x93,0xf5,0x82,0x8e,0x83,0xe8,0x69,0x70,0x1,0x22,0xe4,0x93,0xf6,0xa3,0x8,0x80,0xf4,0xe4,0x93,0xfc,0x74,0x1,0x93,0xfd,0x74,
! 0x2,0x93,0xfe,0x74,0x3,0x93,0xff,0x74,0x4,0x93,0xf8,0x74,0x5,0x93,0xf5,0x82,0x88,0x83,0x12,0x0,0x4c,0x70,0x1,0x22,0xe4,
! 0x93,0xa3,0xa8,0x83,0xa9,0x82,0x8c,0x83,0x8d,0x82,0xf0,0xa3,0xac,0x83,0xad,0x82,0x88,0x83,0x89,0x82,0x80,0xe3,0x30,0x30,0x6,
! 0x5c,0x7b,0x7b,0x6,0x5c,0x0,0x0,0x6,0x5c,0x6,0x5c,0x0,0x0,0x6,0x5c,0x6,0x5c,0x80,0xfe,0xec,0x4d,0x70,0x1,0x22,0xe8,
[...1874 lines suppressed...]
+ 84,32,96,6,120,75,230,68,4,246,120,74,230,84,64,96,6,120,75,230,68,2,246,120,74,
+ 230,84,128,96,6,120,75,230,68,1,246,120,73,230,6,255,120,75,134,3,239,36,93,248,166,
+ 3,120,72,230,195,51,246,24,230,51,246,2,12,198,34,117,137,32,67,135,128,117,141,243,117,
+ 152,64,194,153,117,153,170,210,142,117,144,255,117,160,255,117,176,255,117,128,255,120,90,118,1,
+ 120,82,118,0,120,82,230,195,148,32,80,21,120,82,230,36,93,248,118,0,120,82,230,36,125,
+ 248,118,0,120,82,6,128,227,18,10,81,18,11,38,144,254,233,224,255,126,0,144,254,232,224,
+ 251,122,0,139,2,228,120,92,47,246,238,58,24,246,210,175,210,168,144,255,252,224,68,128,240,
+ 120,92,230,112,3,24,230,20,112,5,18,12,187,128,3,18,12,93,120,82,118,0,120,82,230,
+ 195,148,32,80,27,120,82,230,36,93,248,230,255,120,82,230,36,125,248,230,111,96,4,120,90,
+ 118,1,120,82,6,128,221,120,90,230,20,112,73,144,255,82,224,84,128,96,65,120,82,118,0,
+ 120,82,230,195,148,32,80,43,120,82,230,36,93,248,230,255,120,82,230,36,96,245,130,228,52,
+ 254,245,131,239,240,120,82,230,36,93,248,230,255,120,82,230,36,125,248,166,7,120,82,6,128,
+ 205,144,255,82,116,32,240,120,90,118,0,2,13,245,40,3,80,0,104,0,105,0,100,0,103,
+ 0,101,0,116,0,73,0,110,0,116,0,101,0,114,0,102,0,97,0,99,0,101,0,75,0,
+ 105,0,116,0,18,1,16,1,0,0,0,8,194,6,67,0,0,5,1,2,3,1,28,3,80,
+ 0,104,0,105,0,100,0,103,0,101,0,116,0,115,0,32,0,73,0,110,0,99,0,46,0,
+ 9,2,32,0,1,1,0,128,50,9,4,0,0,2,255,0,255,0,7,5,1,2,64,0,0,
+ 7,5,130,2,32,0,0,};
Index: phidget.c
===================================================================
RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** phidget.c 23 Dec 2002 04:38:40 -0000 1.27
--- phidget.c 23 Jun 2003 22:37:34 -0000 1.28
***************
*** 22,27 ****
// TODO - change this
! //#define DBG(a) printf("*** DEBUG *** : %s\n",a)
! #define DBG(a)
int _libPhidgetInitialized = 0; /**< Private variable to determine if the libphidget is initialized */
--- 22,27 ----
// TODO - change this
! #define DBG(a) printf("*** DEBUG *** : %s\n",a)
! //#define DBG(a)
int _libPhidgetInitialized = 0; /**< Private variable to determine if the libphidget is initialized */
***************
*** 48,51 ****
--- 48,52 ----
* - Interface Kit 488 Digital Input only HID
* - Interface Kit 880 Digital Input only HID
+ * - PhidgetPower Ver 1.01 Supported
* - Interface Kit 32-32-0 Not supported yet
* - Interface Kit 0-256-0 Not supported yet
***************
*** 53,57 ****
* - PhidgetLED Ver 1.0 Not supported yet
* - PhidgetEncoder Ver 1.0 Not supported yet
- * - PhidgetPower Ver 1.01 Not supported yet
* - PhidgetTextLCD ECMA1010 Ver 1.0 Not supported yet
* - PhidgetGraphicLCD Ver 1.0 Not supported yet
--- 54,57 ----
***************
*** 199,203 ****
* An array of serial holders
*/
! struct SerialHolder *Serials=NULL;
/**
--- 199,203 ----
* An array of serial holders
*/
! //struct SerialHolder *Serials=NULL;
/**
***************
*** 211,214 ****
--- 211,215 ----
* the attach/detachment of phidgets
*/
+ /*
void _addNewSerial(struct usb_bus *bus,struct usb_device *device,int SerialNumber)
{
***************
*** 233,236 ****
--- 234,238 ----
Serials[SerialCount-1].serial=SerialNumber;
}
+ */
/*
***************
*** 474,477 ****
--- 476,480 ----
int _getSerial(struct usb_device *device, struct phidget_type *ptd)
{
+ DBG("Get Serial");
int i = 0, j = 0, ret=0;
struct usb_dev_handle *handle;
***************
*** 522,525 ****
--- 525,533 ----
}
+ for (i=0;i<128;i++)
+ {
+ buffer[i]=0;
+ serial[i]=0;
+ }
i=usb_control_msg(handle, 0x80, 0x06, 0x0303, 0, buffer, sizeof(buffer), 5000);
if (i!=buffer[0] || i<0)
***************
*** 531,534 ****
--- 539,544 ----
j=0;
+ printf("%s ",buffer);
+ printf("Buffer:%d\n",buffer[0]);
for (i=2;i<buffer[0];i+=2)
{
***************
*** 539,542 ****
--- 549,554 ----
j++;
+ printf("Serial:[%s]\n",serial);
+
usb_release_interface(handle, 0);
usb_close(handle);
***************
*** 596,600 ****
}
- /*
void _getSoftPhidgetInfo(int *Version,int *SerialNumber,int *productID,struct usb_dev_handle *handle)
{
--- 608,611 ----
***************
*** 692,697 ****
_getSoftPhidgetInfo(&Version,&SerialNumber,&productID,handle);
! //printf("Version:%d Serial:%d ProductID:0x0%x\n",Version,SerialNumber,productID);
! _addNewSerial(bus,dev,SerialNumber);
switch(productID)
--- 703,708 ----
_getSoftPhidgetInfo(&Version,&SerialNumber,&productID,handle);
! printf("Version:%d Serial:%d ProductID:0x0%x\n",Version,SerialNumber,productID);
! //_addNewSerial(bus,dev,SerialNumber);
switch(productID)
***************
*** 702,705 ****
--- 713,717 ----
if (usb_bulk_write(handle, 0x01, (void *)SOFT_SERVO8_CODE,SOFT_SERVO8_SIZE, 5000) != SOFT_SERVO8_SIZE)
{
+ printf("Error, can't write firmware\n");
exit(-1);
}
***************
*** 711,714 ****
--- 723,729 ----
usb_close(handle);
+
+ DBG("Waiting for reboot");
+ sleep(1);
}
}
***************
*** 717,721 ****
return(_error(LPE_NONE));
}
- */
/**
--- 732,735 ----
***************
*** 753,757 ****
// Not supported yet
! //_checkForSoftPhidgets();
// We need to detect:
--- 767,774 ----
// Not supported yet
! if (_checkForSoftPhidgets()!=LPE_NONE)
! return(0);
!
!
// We need to detect:
***************
*** 763,767 ****
! // Initilize the "found it" array to NOT_FOUND
for (t = 0; t < _phidgetDeviceCount; t++)
found[t] = NOT_FOUND;
--- 780,784 ----
! // Initialize the "found it" array to NOT_FOUND
for (t = 0; t < _phidgetDeviceCount; t++)
found[t] = NOT_FOUND;
***************
*** 773,779 ****
--- 790,798 ----
// Go thru all USB busses
+ DBG("Going thru all USB Busses");
for (bus = usb_busses; bus; bus = bus->next)
{
// Step thru each device on that bus
+ DBG("Going thru each device on that bus");
for (dev = bus->devices; dev; dev = dev->next)
{
***************
*** 784,787 ****
--- 803,807 ----
if (pdt!=NULL)
{
+ DBG("Is this device a phidget? - yes");
int serial=-1;
int wasFound=0;
***************
*** 803,817 ****
if (wasFound==0)
{
! //printf("Bus:0x0%x Dev:0x0%x\n",bus,dev);
! /*
if (_isSoftPhidget(pdt))
{
! serial=0;//_getSoftSerial(bus,dev);
}
else
! */
! serial=_getSerial(dev,pdt);
! //printf(" Serial:%d\n",serial);
// have we seen this phidget before
--- 823,843 ----
if (wasFound==0)
{
! printf("Bus:0x0%x Dev:0x0%x\n",bus,dev);
if (_isSoftPhidget(pdt))
{
! DBG(" softphidget found - getting serial new way");
! int productID;
! int Version;
! struct usb_dev_handle *handle = usb_open(dev);
! _getSoftPhidgetInfo(&Version,&serial,&productID,handle);
! usb_close(handle);
}
else
! {
! DBG(" getting serial old fashioned way\n");
! serial=_getSerial(dev,pdt);
! }
! printf(" Serial:%d\n",serial);
// have we seen this phidget before
***************
*** 844,850 ****
--- 870,879 ----
}
}
+ else
+ DBG("Is this device a phidget? - no");
}
}
+ DBG("Going thru phidgets");
for (t=0;t<_phidgetDeviceCount;t++)
{
***************
*** 888,892 ****
}
-
return(change);
}
--- 917,920 ----
***************
*** 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);
--- 944,948 ----
_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);
***************
*** 922,928 ****
//_registerDeviceType("PhidgetLED Ver 1.0", 0x06C2, 0x0049, LP_OTHER);
//_registerDeviceType("PhidgetEncoder Ver 1.0", 0x06C2, 0x004B, LP_OTHER);
! //_registerDeviceType("PhidgetPower Ver 1.01", 0x06C2, 0x004E, LP_OTHER);
//_registerDeviceType("PhidgetGraphicLCD Ver 1.0", 0x06C2, 0x0058, LP_OTHER);
! //_registerDeviceType("SoftPhidget", 0x06C2, 0x0060, LP_OTHER);
_libPhidgetInitialized = 1;
--- 950,956 ----
//_registerDeviceType("PhidgetLED Ver 1.0", 0x06C2, 0x0049, LP_OTHER);
//_registerDeviceType("PhidgetEncoder Ver 1.0", 0x06C2, 0x004B, LP_OTHER);
! _registerDeviceType("PhidgetPower Ver 1.01", 0x06C2, 0x004E, LP_POWER);
//_registerDeviceType("PhidgetGraphicLCD Ver 1.0", 0x06C2, 0x0058, LP_OTHER);
! _registerDeviceType("SoftPhidget", 0x06C2, 0x0060, LP_OTHER);
_libPhidgetInitialized = 1;
***************
*** 1174,1177 ****
--- 1202,1207 ----
enum ELPError phidgetWrite(struct phidget *phidgetDevice, char *buffer, int size)
{
+ int sizeleft,wrote;
+ int a,b;
int ret;
DBG("phidgetWrite");
***************
*** 1185,1191 ****
--- 1215,1291 ----
return (_error(LPE_PHIDGET_NOT_OPENED));
+
+ // If this isn't a soft phidget we use control messages so
+ /*
ret=usb_control_msg(phidgetDevice->handle, 0x21, 0x09, 0x200, 0, buffer, size, 5000);
+
if (ret!=size)
+ {
+ char temp[64];
+ sprintf(temp,"Tried to write %d, but got error %d\n",size,ret);
+ DBG(temp);
return (_error(LPE_CONTROL_MSG_ERROR));
+ }
+ */
+
+
+ // Only works for writing to soft phidgets
+ ret=usb_bulk_write(phidgetDevice->handle, 0x01, (void *)buffer,size, 5000);
+ printf("%d\n",ret);
+
+
+ // Keep trying
+ //ret=usb_control_msg(phidgetDevice->handle, 0x21, 0x09, 0x200, 0, buffer, size, 5000);
+
+ //for (a=0;a<255;a++)
+ //for (b=0;b<255;b++)
+ //{
+ //ret=usb_control_msg(phidgetDevice->handle, a, b, 0x200, 0, buffer, size, 5000);
+ //if (ret!=-1)
+ //printf("%d %d %d\n",a,b,ret);
+ //}
+ //exit(-1);
+
+
+ //128 6 16
+ //ret=usb_control_msg(phidgetDevice->handle, 0x21, 0x09, 0x200, 0, buffer, size, 5000);
+ //ret=usb_control_msg(phidgetDevice->handle, 128, 6, 0x200, 0, buffer, size, 5000);
+
+
+ /*
+ sizeleft=size;
+ wrote=0;
+
+ while (sizeleft>0)
+ {
+ printf("Try to write %d\n",sizeleft);
+ ret=usb_bulk_write(phidgetDevice->handle, 0x01, (void *)(buffer+wrote),sizeleft, 5000);
+
+ if (ret!=-1)
+ {
+ if (ret<0)
+ {
+ char temp[64];
+ sprintf(temp,"Tried to write %d, but got error %d\n",size,ret);
+ DBG(temp);
+ return (_error(LPE_CONTROL_MSG_ERROR));
+ }
+
+ sizeleft-=ret;
+ wrote+=ret;
+ }
+ }
+ */
+
+
+ /*
+ if (ret!=size)
+ {
+ char temp[64];
+ sprintf(temp,"Tried to write %d but only wrote %d\n",size,ret);
+ DBG(temp);
+ return (_error(LPE_CONTROL_MSG_ERROR));
+ }
+ */
return (_error(LPE_NONE));
***************
*** 1468,1476 ****
}
- /*
enum ELPError phidget8Servo(struct phidget *phidgetDevice, int id, float percent, float maxvelocity, float acceleration)
{
char buffer[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
! float *temp=&buffer;
DBG("phidget8Servo");
--- 1568,1577 ----
}
enum ELPError phidget8Servo(struct phidget *phidgetDevice, int id, float percent, float maxvelocity, float acceleration)
{
+ /*
+ // Bad doesn't work, not sure where I got this from.
char buffer[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
! float *temp=(float *)buffer;
DBG("phidget8Servo");
***************
*** 1486,1491 ****
return (phidgetWrite(phidgetDevice, buffer, sizeof(buffer)));
}
- */
/**
--- 1587,1647 ----
return (phidgetWrite(phidgetDevice, buffer, sizeof(buffer)));
+ */
+
+ /* Ok, couldn't figure out the protocol from everything I had been told, so i decided to
+ * figure it out on my own, put values in and see what happens
+ */
+
+
+ int k;
+ int t;
+ char buffer[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+
+ buffer[0]=id; // Which servo to control
+
+ buffer[1]=0; // These three didn't seem to do much in the protocol
+ buffer[2]=0;
+ buffer[3]=0;
+
+
+ buffer[4]=0;
+ buffer[5]=0;
+ buffer[6]=0; // The position goes here
+ buffer[7]=0;
+ buffer[8]=0;
+ buffer[9]=0;
+ buffer[10]=0;
+ buffer[11]=0;
+ buffer[12]=0;
+ buffer[13]=0;
+ buffer[14]=0; // Needs to be over 6 I think? or
+ buffer[15]=1; // Has to be 1 or greater
+
+ // Write the position, this seems to work.
+ ((int *)(buffer+5))[0] = percent*16218;
+
+
+ //buffer[7]=buffer[5];
+ //buffer[6]=buffer[4];
+ //buffer[4]=0;
+ //buffer[5]=0;
+
+ // This stuff didn't work either
+ //
+ //((short int *)(buffer+4))[0] = (int)(percent*16218);
+ //((int *)(buffer+4))[1] = rand()%16218;
+ //((int *)(buffer+4))[2] = rand()%16218;
+
+ //((int *)(buffer+4))[0] = (int)((percent/10.0 /*+ 23.0*/) * 16218);
+ //((int *)(buffer+4))[1] = (int)((maxvelocity / 50.0) * 16218);
+ //((int *)(buffer+4))[2] = (int)((acceleration / 50.0) * 16218);
+
+ //((int *)(buffer+4))[0]=16218/2;
+ //((int *)(buffer+4))[1]=16218/2;
+ //((int *)(buffer+4))[2]=16218/2;
+
+ // Write to the phidget
+ return (phidgetWrite(phidgetDevice, buffer, sizeof(buffer)));
}
/**
***************
*** 1533,1537 ****
buffer[2] = 0;
buffer[3] = 0;
! phidgetWrite(phidgetDevice,buffer,4);
}
--- 1689,1693 ----
buffer[2] = 0;
buffer[3] = 0;
! return(phidgetWrite(phidgetDevice,buffer,4));
}
***************
*** 1586,1589 ****
--- 1742,1760 ----
/**
+ * Helper function to set the Pulse on and Pulse off length for the PhidgetPower controller
+ */
+ enum ELPError phidgetPower( struct phidget *phidgetDevice, int index, int on, int off )
+ {
+ char buffer[6];
+ buffer[0] = (unsigned char)index ;
+ buffer[1] = (unsigned char)(on % 256);
+ buffer[2] = (unsigned char)(on / 256);
+ buffer[3] = (unsigned char)(off % 256);
+ buffer[4] = (unsigned char)(off / 256);
+
+ return(phidgetWrite(phidgetDevice,buffer,6));
+ }
+
+ /**
* Helper function to clear the Text LCD
*/
***************
*** 1607,1611 ****
buffer[2] = 0x42; // 0: 0 1 0 0 0 0 1 0 <- Power Save, Oscillator Circuit ON
buffer[7] = 3;
! phidgetWrite(phidgetDevice,buffer,8);
}
--- 1778,1782 ----
buffer[2] = 0x42; // 0: 0 1 0 0 0 0 1 0 <- Power Save, Oscillator Circuit ON
buffer[7] = 3;
! return(phidgetWrite(phidgetDevice,buffer,8));
}
***************
*** 1620,1624 ****
buffer[1] = 0x40; // 0: 0 1 0 0 0 0 0 0 <- Power Save, Oscillator Circuit ON
buffer[7] = 2;
! phidgetWrite(phidgetDevice,buffer,8);
}
--- 1791,1795 ----
buffer[1] = 0x40; // 0: 0 1 0 0 0 0 0 0 <- Power Save, Oscillator Circuit ON
buffer[7] = 2;
! return(phidgetWrite(phidgetDevice,buffer,8));
}
Index: phidget.h
===================================================================
RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** phidget.h 23 Dec 2002 04:38:40 -0000 1.21
--- phidget.h 23 Jun 2003 22:37:34 -0000 1.22
***************
*** 83,87 ****
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
--- 83,87 ----
LP_INTERFACE_KIT_488 = 302, //!< 488 interface kit
LP_ENCODER = 400, //!< Currently unsupported
! LP_POWER = 500, //!< PhidgetPower
LP_RFID = 600, //!< Currently unsupported
LP_LED = 700, //!< Currently unsupported
***************
*** 189,192 ****
--- 189,202 ----
);
+ /**
+ * Set the Pulse on and Pulse off length for the PhidgetPower controller
+ */
+ enum ELPError phidgetPower(
+ struct phidget *device, //<! The phidget to write to
+ int index, //<! The index of the output to adjust
+ int on, //<! 0-65535, time on per pulse; in 128 us increments
+ int off //<! 0-65535, time off per pulse; in 128 us increments
+ );
+
/**
* Send an angle (0.0 to 1.0) to a single servo. The phidget servo controllers
***************
*** 261,265 ****
);
! //enum ELPError phidget8Servo(struct phidget *phidgetDevice, int id, float percent1, float maxvelocity, float acceleration);
/**
--- 271,275 ----
);
! enum ELPError phidget8Servo(struct phidget *phidgetDevice, int id, float percent1, float maxvelocity, float acceleration);
/**
|