tablet_leer.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016  
00017  
00018 // InterfacekitTest.cpp : Defines the entry point for the console application.
00019 //
00020 
00021 
00022 #include <stdio.h>
00023 #include <string.h>
00024 #include <unistd.h>
00025 #include <phidget21.h>
00026 int wert[100];
00027 int i;
00028 
00029 void display_generic_properties(CPhidgetHandle phid)
00030 {
00031         int sernum, version;
00032         const char *deviceptr, *label;
00033         CPhidget_getDeviceType(phid, &deviceptr);
00034         CPhidget_getSerialNumber(phid, &sernum);
00035         CPhidget_getDeviceVersion(phid, &version);
00036         CPhidget_getDeviceLabel(phid, &label);
00037 
00038         printf("%s\n", deviceptr);
00039         printf("Version: %8d SerialNumber: %10d\n", version, sernum);
00040         printf("Label: %s\n", label);
00041         return;
00042 }
00043 
00044 
00045 int IFK_SensorChangeHandler(CPhidgetInterfaceKitHandle IFK, void *userptr, int Index, int Value)
00046 {
00047 
00048         //printf("Sensor %d is %d\n", Index, Value);
00049         if (i <10)
00050         {
00051                 CPhidgetInterfaceKit_getSensorValue(IFK,0, &wert[0+(10*i)]);
00052                 //printf("Sensor0 manually is %d\n", wert[0]);
00053                 CPhidgetInterfaceKit_getSensorValue(IFK,1, &wert[1+(10*i)]);
00054                 //printf("Sensor0 manually is %d\n", wert[0]);
00055                 CPhidgetInterfaceKit_getSensorValue(IFK,2, &wert[2+(10*i)]);
00056                 //printf("Sensor0 manually is %d\n", wert[0]);
00057                 CPhidgetInterfaceKit_getSensorValue(IFK,3, &wert[3+(10*i)]);
00058                 //printf("Sensor0 manually is %d\n", wert[0]);
00059         }
00060 
00061         else
00062         {
00063 
00064                 //CPhidgetInterfaceKit_getSensorValue(IFK,1, &wert[1]);
00065                 //printf("Sensor1 manually is %d\n", wert[1]);
00066                 //CPhidgetInterfaceKit_getSensorValue(IFK,2, &wert[2]);
00067                 //printf("Sensor2 manually is %d\n", wert[2]);
00068                 //CPhidgetInterfaceKit_getSensorValue(IFK,3, &wert[3]);
00069                 //printf("Sensor0123 manually are %d %d %d %d ; \n", wert[0],wert[1],wert[2],wert[3]);
00070                 wert[94] = ((wert[0] + wert[10]+wert[20]+wert[30]+wert[40]+wert[50]+wert[60]+wert[70]+wert[80]+wert[90]) / 10);
00071                 wert[95] = ((wert[1] + wert[11]+wert[21]+wert[31]+wert[41]+wert[51]+wert[61]+wert[71]+wert[81]+wert[91]) / 10);
00072                 wert[96] = ((wert[2] + wert[12]+wert[22]+wert[32]+wert[42]+wert[52]+wert[62]+wert[72]+wert[82]+wert[92]) / 10);
00073                 wert[97] = ((wert[3] + wert[13]+wert[23]+wert[33]+wert[43]+wert[53]+wert[63]+wert[73]+wert[83]+wert[93]) / 10);
00074 
00075                 if ((wert[94] < 120) && (wert[95] <300) && (wert[96] < 110) && (wert[97] < 120))
00076                 {
00077                         printf("Sensor0123 manually are %d %d %d %d ; \n", wert[94],wert[95],wert[96],wert[97]);
00078                         printf("tablet empty\n");
00079                 }
00080                 else
00081                 {
00082                         printf("Sensor0123 manually are %d %d %d %d ; \n", wert[94],wert[95],wert[96],wert[97]);
00083                         printf("tablet NOT empty!\n");
00084                 }
00085 
00086                 for( i = 0; i < 100; i++)
00087                         wert[i]=0;
00088                 i =0;
00089         }
00090         i++;
00091         printf("i is %d \n",i);
00092         return 0;
00093 }
00094 
00095 
00096 int IFK_AttachHandler(CPhidgetHandle IFK, void *userptr)
00097 {
00098         //CPhidgetInterfaceKit_setSensorChangeTrigger((CPhidgetInterfaceKitHandle)IFK, 0, 0);
00099         printf("Attach handler ran!\n");
00100         return 0;
00101 }
00102 
00103 int test_interfacekit()
00104 {
00105         int numInputs, numOutputs, numSensors;
00106         int err;
00107 
00108         CPhidgetInterfaceKitHandle IFK = 0;
00109         CPhidget_enableLogging(PHIDGET_LOG_VERBOSE, NULL);
00110         CPhidgetInterfaceKit_create(&IFK);
00111         CPhidgetInterfaceKit_set_OnSensorChange_Handler(IFK, IFK_SensorChangeHandler, NULL);
00112         CPhidget_set_OnAttach_Handler((CPhidgetHandle)IFK, IFK_AttachHandler, NULL);
00113         //opening phidget
00114         CPhidget_open((CPhidgetHandle)IFK, -1);
00115 
00116         //wait 5 seconds for attachment
00117         if((err = CPhidget_waitForAttachment((CPhidgetHandle)IFK, 0)) != EPHIDGET_OK )
00118         {
00119                 const char *errStr;
00120                 CPhidget_getErrorDescription(err, &errStr);
00121                 printf("Error waiting for attachment: (%d): %s\n",err,errStr);
00122                 goto exit;
00123         }
00124 
00125         display_generic_properties((CPhidgetHandle)IFK);
00126         CPhidgetInterfaceKit_getOutputCount((CPhidgetInterfaceKitHandle)IFK, &numOutputs);
00127         CPhidgetInterfaceKit_getInputCount((CPhidgetInterfaceKitHandle)IFK, &numInputs);
00128         CPhidgetInterfaceKit_getSensorCount((CPhidgetInterfaceKitHandle)IFK, &numSensors);
00129         CPhidgetInterfaceKit_setOutputState((CPhidgetInterfaceKitHandle)IFK, 0, 1);
00130 
00131         printf("Sensors:%d Inputs:%d Outputs:%d\n", numSensors, numInputs, numOutputs);
00132 
00133 
00134         //err = CPhidget_setDeviceLabel((CPhidgetHandle)IFK, "test");
00135 
00136 
00137         while(1)
00138         {
00139                 sleep(1);
00140         }
00141 
00142         while(1)
00143         {
00144                 CPhidgetInterfaceKit_setOutputState(IFK, 7, 1);
00145                 CPhidgetInterfaceKit_setOutputState(IFK, 7, 0);
00146         }
00147 
00148 
00149 
00150         CPhidgetInterfaceKit_setOutputState(IFK, 0, 1);
00151         sleep(1);
00152         CPhidgetInterfaceKit_setOutputState(IFK, 0, 0);
00153         sleep(1);
00154         CPhidgetInterfaceKit_setOutputState(IFK, 0, 1);
00155         sleep(1);
00156         CPhidgetInterfaceKit_setOutputState(IFK, 0, 0);
00157 
00158         sleep(5);
00159 
00160 exit:
00161         CPhidget_close((CPhidgetHandle)IFK);
00162         CPhidget_delete((CPhidgetHandle)IFK);
00163 
00164         return 0;
00165 }
00166 
00167 int main(int argc, char* argv[])
00168 {
00169         test_interfacekit();
00170         return 0;
00171 }
00172 


cob_phidgets
Author(s): Florian Weisshardt
autogenerated on Sat Jun 8 2019 21:02:14