00001
00002
00003
00004
00005 #include <stdio.h>
00006 #include <string.h>
00007 #include <unistd.h>
00008 #include <phidget21.h>
00009
00010 void display_generic_properties(CPhidgetHandle phid)
00011 {
00012 int sernum, version;
00013 const char *deviceptr, *label;
00014 CPhidget_getDeviceType(phid, &deviceptr);
00015 CPhidget_getSerialNumber(phid, &sernum);
00016 CPhidget_getDeviceVersion(phid, &version);
00017 CPhidget_getDeviceLabel(phid, &label);
00018
00019 printf("%s\n", deviceptr);
00020 printf("Version: %8d SerialNumber: %10d\n", version, sernum);
00021 printf("Label: %s\n", label);
00022 return;
00023 }
00024
00025
00026 int IFK_DetachHandler(CPhidgetHandle IFK, void *userptr)
00027 {
00028 printf("Detach handler ran!\n");
00029 return 0;
00030 }
00031
00032 int IFK_ErrorHandler(CPhidgetHandle IFK, void *userptr, int ErrorCode, const char *ErrorString)
00033 {
00034 printf("Error handler: %d, %s\n", ErrorCode, ErrorString);
00035 return 0;
00036 }
00037
00038 int IFK_OutputChangeHandler(CPhidgetInterfaceKitHandle IFK, void *userptr, int Index, int Value)
00039 {
00040 printf("Output %d is %d\n", Index, Value);
00041 return 0;
00042 }
00043
00044 int IFK_InputChangeHandler(CPhidgetInterfaceKitHandle IFK, void *userptr, int Index, int Value)
00045 {
00046 printf("Input %d is %d\n", Index, Value);
00047 return 0;
00048 }
00049
00050 int IFK_SensorChangeHandler(CPhidgetInterfaceKitHandle IFK, void *userptr, int Index, int Value)
00051 {
00052 printf("Sensor %d is %d\n", Index, Value);
00053 return 0;
00054 }
00055
00056
00057 int IFK_AttachHandler(CPhidgetHandle IFK, void *userptr)
00058 {
00059
00060 printf("Attach handler ran!\n");
00061 return 0;
00062 }
00063
00064 int test_interfacekit()
00065 {
00066 int numInputs, numOutputs, numSensors;
00067 int err;
00068 CPhidgetInterfaceKitHandle IFK = 0;
00069
00070 CPhidget_enableLogging(PHIDGET_LOG_VERBOSE, NULL);
00071
00072 CPhidgetInterfaceKit_create(&IFK);
00073
00074 CPhidgetInterfaceKit_set_OnInputChange_Handler(IFK, IFK_InputChangeHandler, NULL);
00075 CPhidgetInterfaceKit_set_OnOutputChange_Handler(IFK, IFK_OutputChangeHandler, NULL);
00076 CPhidgetInterfaceKit_set_OnSensorChange_Handler(IFK, IFK_SensorChangeHandler, NULL);
00077 CPhidget_set_OnAttach_Handler((CPhidgetHandle)IFK, IFK_AttachHandler, NULL);
00078 CPhidget_set_OnDetach_Handler((CPhidgetHandle)IFK, IFK_DetachHandler, NULL);
00079 CPhidget_set_OnError_Handler((CPhidgetHandle)IFK, IFK_ErrorHandler, NULL);
00080
00081 CPhidget_open((CPhidgetHandle)IFK, -1);
00082
00083
00084 if((err = CPhidget_waitForAttachment((CPhidgetHandle)IFK, 0)) != EPHIDGET_OK )
00085 {
00086 const char *errStr;
00087 CPhidget_getErrorDescription(err, &errStr);
00088 printf("Error waiting for attachment: (%d): %s\n",err,errStr);
00089 goto exit;
00090 }
00091
00092 display_generic_properties((CPhidgetHandle)IFK);
00093 CPhidgetInterfaceKit_getOutputCount((CPhidgetInterfaceKitHandle)IFK, &numOutputs);
00094 CPhidgetInterfaceKit_getInputCount((CPhidgetInterfaceKitHandle)IFK, &numInputs);
00095 CPhidgetInterfaceKit_getSensorCount((CPhidgetInterfaceKitHandle)IFK, &numSensors);
00096
00097 CPhidgetInterfaceKit_setOutputState((CPhidgetInterfaceKitHandle)IFK, 0, 1);
00098
00099 printf("Sensors:%d Inputs:%d Outputs:%d\n", numSensors, numInputs, numOutputs);
00100
00101
00102
00103 while(1)
00104 {
00105 sleep(1);
00106 }
00107
00108 while(1)
00109 {
00110 CPhidgetInterfaceKit_setOutputState(IFK, 7, 1);
00111 CPhidgetInterfaceKit_setOutputState(IFK, 7, 0);
00112 }
00113
00114 CPhidgetInterfaceKit_setOutputState(IFK, 0, 1);
00115 sleep(1);
00116 CPhidgetInterfaceKit_setOutputState(IFK, 0, 0);
00117 sleep(1);
00118 CPhidgetInterfaceKit_setOutputState(IFK, 0, 1);
00119 sleep(1);
00120 CPhidgetInterfaceKit_setOutputState(IFK, 0, 0);
00121
00122 sleep(5);
00123
00124 exit:
00125 CPhidget_close((CPhidgetHandle)IFK);
00126 CPhidget_delete((CPhidgetHandle)IFK);
00127
00128 return 0;
00129 }
00130
00131 int main(int argc, char* argv[])
00132 {
00133 test_interfacekit();
00134 return 0;
00135 }
00136