[Libphidget-cvs-commits] CVS: libphidget/src/libphidget SoftPhidget.h,1.2,1.3 phidget.c,1.30,1.31 ph
Status: Alpha
Brought to you by:
jstrohm
From: Jack S. <js...@us...> - 2003-06-30 02:49:19
|
Update of /cvsroot/libphidget/libphidget/src/libphidget In directory sc8-pr-cvs1:/tmp/cvs-serv8769/libphidget Modified Files: SoftPhidget.h phidget.c phidget.h Log Message: Initial checkin of support for the 888 Interface kit. Since I don't have one to test I really doubt this will work. Index: SoftPhidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/SoftPhidget.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SoftPhidget.h 23 Jun 2003 22:37:34 -0000 1.2 --- SoftPhidget.h 30 Jun 2003 02:49:16 -0000 1.3 *************** *** 456,460 **** 50,9,4,0,0,2,255,0,255,0,7,5,1,2,16,0,0,7,5,130,2,32,0,0,}; - #define ANALOG_FIRMWARE_SIZE 3451 const unsigned char ANALOG_FIRMWARE[ANALOG_FIRMWARE_SIZE] = {120, --- 456,459 ---- Index: phidget.c =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** phidget.c 24 Jun 2003 02:12:13 -0000 1.30 --- phidget.c 30 Jun 2003 02:49:16 -0000 1.31 *************** *** 539,544 **** j=0; - printf("%s ",buffer); - printf("Buffer:%d\n",buffer[0]); for (i=2;i<buffer[0];i+=2) { --- 539,542 ---- *************** *** 934,937 **** --- 932,936 ---- _registerDeviceType("Interface Kit 4/8/8", 0x0925, 0x8201, LP_INTERFACE_KIT_488); _registerDeviceType("Interface Kit 4/8/8", 0x06C2, 0x0040, LP_INTERFACE_KIT_488); + _registerDeviceType("Interface Kit 4/8/8", 0x06C2, 0x0045, LP_INTERFACE_KIT_888); _registerDeviceType("Interface Kit 8/8/0", 0x06C2, 0x0041, LP_INTERFACE_KIT_880); _registerDeviceType("Phidget LCD", 0x06C2, 0x0041, LP_INTERFACE_KIT_880); *************** *** 1519,1522 **** --- 1518,1522 ---- } + // TODO - Still working this one out enum ELPError phidget8Servo(struct phidget *phidgetDevice, int id, float percent, float maxvelocity, float acceleration) { *************** *** 1612,1615 **** --- 1612,1616 ---- return(_error(err)); + // For some reason this weird ordering was needed for the 488 digital[4]=!((buffer[0] & 1)==1); digital[5]=!((buffer[0] & 2)==2); *************** *** 1629,1638 **** } /** ! * Helper function to turn the Text LCD on and configure it */ enum ELPError phidgetInterfaceKitWrite(struct phidget *phidgetDevice, int index, int value) { char buffer[4]; buffer[0] = index+(value << 3); --- 1630,1724 ---- } + /** + * Helper function to read from an interface kit. + */ + enum ELPError phidgetInterfaceKit888Read(struct phidget *phidgetDevice, float analog[8], int digital[8]) + { + int t; + char buffer[8]; + enum ELPError err; + + // Not correct type of interface kit + if (phidgetDevice->type->deviceClass != LP_INTERFACE_KIT_888) + return (_error(LPE_WRONG_PHIDGET_CLASS_TYPE)); + + // Read 2 input packets because 1 isn't large enough all of the data + for (t=0;t<2;t++) + { + err=phidgetRead(phidgetDevice,buffer,sizeof(buffer)); + if (err!=LPE_NONE) + return(_error(err)); + + // This weird ordering was used in the 488 phidget + // so I'm wondering if it is needed for the 888 + digital[4]=!((buffer[1] & 1)==1); + digital[5]=!((buffer[1] & 2)==2); + digital[6]=!((buffer[1] & 4)==4); + digital[7]=!((buffer[1] & 8)==8); + digital[3]=!((buffer[1] & 16)==16); + digital[2]=!((buffer[1] & 32)==32); + digital[1]=!((buffer[1] & 64)==64); + digital[0]=!((buffer[1] & 128)==128); + + + if (!(buffer[0] & 0x01)) + { + // Read first section + analog[0]=((unsigned char)buffer[2]+((unsigned char)buffer[3] & 0x0f) * 256); + analog[1]=((unsigned char)buffer[4]+((unsigned char)buffer[3] & 0xf0) * 16); + analog[2]=((unsigned char)buffer[5]+((unsigned char)buffer[6] & 0x0f) * 256); + analog[3]=((unsigned char)buffer[7]+((unsigned char)buffer[6] & 0xf0) * 16); + } + else + { + // Read second section + analog[4]=((unsigned char)buffer[2]+((unsigned char)buffer[3] & 0x0f) * 256); + analog[5]=((unsigned char)buffer[4]+((unsigned char)buffer[3] & 0xf0) * 16); + analog[6]=((unsigned char)buffer[5]+((unsigned char)buffer[6] & 0x0f) * 256); + analog[7]=((unsigned char)buffer[7]+((unsigned char)buffer[6] & 0xf0) * 16); + } + } + + /* + New Packet format + + Input Packet Length: 8 Bytes + + The current state of this PhidgetInterfaceKit is too large to fit into a single packet. + So Bit 1 of Byte 0 indicates whether this is a Packet.0 or Packet.1 + + In the case of Packet.0 (!(Byte_0 & 0x01)), this is the assignments. + + Input_State 0-7 map onto Byte 1, bits 0-7, as shown. m_inputvalue = Data[1]; + + 12-Bit Sensor values are constructed from the packet as described: + newSensor[0] = ((unsigned char)Data[2] + ((unsigned char)Data[3] & 0x0f) * 256); + newSensor[1] = ((unsigned char)Data[4] + ((unsigned char)Data[3] & 0xf0) * 16); + newSensor[2] = ((unsigned char)Data[5] + ((unsigned char)Data[6] & 0x0f) * 256); + newSensor[3] = ((unsigned char)Data[7] + ((unsigned char)Data[6] & 0xf0) * 16); + + + In the case of Packet.1 (Byte_0 & 0x01), this is the assignments. + + Input_State 0-7 map onto Byte 1, bits 0-7, as shown. m_inputvalue = Data[1]; + + 12-Bit Sensor values are constructed from the packet as described: + newSensor[4] = ((unsigned char)Data[2] + ((unsigned char)Data[3] & 0x0f) * 256) * 4; + newSensor[5] = ((unsigned char)Data[4] + ((unsigned char)Data[3] & 0xf0) * 16) * 4; + newSensor[6] = ((unsigned char)Data[5] + ((unsigned char)Data[6] & 0x0f) * 256) * 4; + newSensor[7] = ((unsigned char)Data[7] + ((unsigned char)Data[6] & 0xf0) * 16) * 4; + */ + + return (_error(LPE_NONE)); + } + /** ! * Helper function to write to an interface kit */ enum ELPError phidgetInterfaceKitWrite(struct phidget *phidgetDevice, int index, int value) { char buffer[4]; + + // TODO - This doesn't work for the 888 yet, need to rework some internal data structures to get it working. buffer[0] = index+(value << 3); Index: phidget.h =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.h,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** phidget.h 23 Jun 2003 22:37:34 -0000 1.22 --- phidget.h 30 Jun 2003 02:49:16 -0000 1.23 *************** *** 82,85 **** --- 82,86 ---- LP_INTERFACE_KIT_880 = 301, //!< 880 interface kit LP_INTERFACE_KIT_488 = 302, //!< 488 interface kit + LP_INTERFACE_KIT_888 = 303, //!< 888 interface kit LP_ENCODER = 400, //!< Currently unsupported LP_POWER = 500, //!< PhidgetPower *************** *** 294,297 **** --- 295,307 ---- struct phidget *phidgetDevice, //!< The phidget to read from float analog[4], //!< This will be filled with the value of the four analog inputs + int digital[8] //!< This iwll be filled with the value of the four digital inputs. 1 is on, 0 is off. + ); + + /** + * Reads a 8/8/8 interface kit + */ + enum ELPError phidgetInterfaceKit888Read( + struct phidget *phidgetDevice, //!< The phidget to read from + float analog[8], //!< This will be filled with the value of the four analog inputs int digital[8] //!< This iwll be filled with the value of the four digital inputs. 1 is on, 0 is off. ); |