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


cob_phidgets
Author(s): Florian Weisshardt
autogenerated on Thu Aug 27 2015 12:46:06