tablet_leer.c
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 // InterfacekitTest.cpp : Defines the entry point for the console application.
19 //
20 
21 
22 #include <stdio.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include <phidget21.h>
26 int wert[100];
27 int i;
28 
29 void display_generic_properties(CPhidgetHandle phid)
30 {
31  int sernum, version;
32  const char *deviceptr, *label;
33  CPhidget_getDeviceType(phid, &deviceptr);
34  CPhidget_getSerialNumber(phid, &sernum);
35  CPhidget_getDeviceVersion(phid, &version);
36  CPhidget_getDeviceLabel(phid, &label);
37 
38  printf("%s\n", deviceptr);
39  printf("Version: %8d SerialNumber: %10d\n", version, sernum);
40  printf("Label: %s\n", label);
41  return;
42 }
43 
44 
45 int IFK_SensorChangeHandler(CPhidgetInterfaceKitHandle IFK, void *userptr, int Index, int Value)
46 {
47 
48  //printf("Sensor %d is %d\n", Index, Value);
49  if (i <10)
50  {
51  CPhidgetInterfaceKit_getSensorValue(IFK,0, &wert[0+(10*i)]);
52  //printf("Sensor0 manually is %d\n", wert[0]);
53  CPhidgetInterfaceKit_getSensorValue(IFK,1, &wert[1+(10*i)]);
54  //printf("Sensor0 manually is %d\n", wert[0]);
55  CPhidgetInterfaceKit_getSensorValue(IFK,2, &wert[2+(10*i)]);
56  //printf("Sensor0 manually is %d\n", wert[0]);
57  CPhidgetInterfaceKit_getSensorValue(IFK,3, &wert[3+(10*i)]);
58  //printf("Sensor0 manually is %d\n", wert[0]);
59  }
60 
61  else
62  {
63 
64  //CPhidgetInterfaceKit_getSensorValue(IFK,1, &wert[1]);
65  //printf("Sensor1 manually is %d\n", wert[1]);
66  //CPhidgetInterfaceKit_getSensorValue(IFK,2, &wert[2]);
67  //printf("Sensor2 manually is %d\n", wert[2]);
68  //CPhidgetInterfaceKit_getSensorValue(IFK,3, &wert[3]);
69  //printf("Sensor0123 manually are %d %d %d %d ; \n", wert[0],wert[1],wert[2],wert[3]);
70  wert[94] = ((wert[0] + wert[10]+wert[20]+wert[30]+wert[40]+wert[50]+wert[60]+wert[70]+wert[80]+wert[90]) / 10);
71  wert[95] = ((wert[1] + wert[11]+wert[21]+wert[31]+wert[41]+wert[51]+wert[61]+wert[71]+wert[81]+wert[91]) / 10);
72  wert[96] = ((wert[2] + wert[12]+wert[22]+wert[32]+wert[42]+wert[52]+wert[62]+wert[72]+wert[82]+wert[92]) / 10);
73  wert[97] = ((wert[3] + wert[13]+wert[23]+wert[33]+wert[43]+wert[53]+wert[63]+wert[73]+wert[83]+wert[93]) / 10);
74 
75  if ((wert[94] < 120) && (wert[95] <300) && (wert[96] < 110) && (wert[97] < 120))
76  {
77  printf("Sensor0123 manually are %d %d %d %d ; \n", wert[94],wert[95],wert[96],wert[97]);
78  printf("tablet empty\n");
79  }
80  else
81  {
82  printf("Sensor0123 manually are %d %d %d %d ; \n", wert[94],wert[95],wert[96],wert[97]);
83  printf("tablet NOT empty!\n");
84  }
85 
86  for( i = 0; i < 100; i++)
87  wert[i]=0;
88  i =0;
89  }
90  i++;
91  printf("i is %d \n",i);
92  return 0;
93 }
94 
95 
96 int IFK_AttachHandler(CPhidgetHandle IFK, void *userptr)
97 {
98  //CPhidgetInterfaceKit_setSensorChangeTrigger((CPhidgetInterfaceKitHandle)IFK, 0, 0);
99  printf("Attach handler ran!\n");
100  return 0;
101 }
102 
104 {
105  int numInputs, numOutputs, numSensors;
106  int err;
107 
108  CPhidgetInterfaceKitHandle IFK = 0;
109  CPhidget_enableLogging(PHIDGET_LOG_VERBOSE, NULL);
110  CPhidgetInterfaceKit_create(&IFK);
111  CPhidgetInterfaceKit_set_OnSensorChange_Handler(IFK, IFK_SensorChangeHandler, NULL);
112  CPhidget_set_OnAttach_Handler((CPhidgetHandle)IFK, IFK_AttachHandler, NULL);
113  //opening phidget
114  CPhidget_open((CPhidgetHandle)IFK, -1);
115 
116  //wait 5 seconds for attachment
117  if((err = CPhidget_waitForAttachment((CPhidgetHandle)IFK, 0)) != EPHIDGET_OK )
118  {
119  const char *errStr;
120  CPhidget_getErrorDescription(err, &errStr);
121  printf("Error waiting for attachment: (%d): %s\n",err,errStr);
122  goto exit;
123  }
124 
125  display_generic_properties((CPhidgetHandle)IFK);
126  CPhidgetInterfaceKit_getOutputCount((CPhidgetInterfaceKitHandle)IFK, &numOutputs);
127  CPhidgetInterfaceKit_getInputCount((CPhidgetInterfaceKitHandle)IFK, &numInputs);
128  CPhidgetInterfaceKit_getSensorCount((CPhidgetInterfaceKitHandle)IFK, &numSensors);
129  CPhidgetInterfaceKit_setOutputState((CPhidgetInterfaceKitHandle)IFK, 0, 1);
130 
131  printf("Sensors:%d Inputs:%d Outputs:%d\n", numSensors, numInputs, numOutputs);
132 
133 
134  //err = CPhidget_setDeviceLabel((CPhidgetHandle)IFK, "test");
135 
136 
137  while(1)
138  {
139  sleep(1);
140  }
141 
142  while(1)
143  {
144  CPhidgetInterfaceKit_setOutputState(IFK, 7, 1);
145  CPhidgetInterfaceKit_setOutputState(IFK, 7, 0);
146  }
147 
148 
149 
150  CPhidgetInterfaceKit_setOutputState(IFK, 0, 1);
151  sleep(1);
152  CPhidgetInterfaceKit_setOutputState(IFK, 0, 0);
153  sleep(1);
154  CPhidgetInterfaceKit_setOutputState(IFK, 0, 1);
155  sleep(1);
156  CPhidgetInterfaceKit_setOutputState(IFK, 0, 0);
157 
158  sleep(5);
159 
160 exit:
161  CPhidget_close((CPhidgetHandle)IFK);
162  CPhidget_delete((CPhidgetHandle)IFK);
163 
164  return 0;
165 }
166 
167 int main(int argc, char* argv[])
168 {
170  return 0;
171 }
172 
int test_interfacekit()
Definition: tablet_leer.c:103
void display_generic_properties(CPhidgetHandle phid)
Definition: tablet_leer.c:29
int main(int argc, char *argv[])
Definition: tablet_leer.c:167
int i
Definition: tablet_leer.c:27
int IFK_SensorChangeHandler(CPhidgetInterfaceKitHandle IFK, void *userptr, int Index, int Value)
Definition: tablet_leer.c:45
int wert[100]
Definition: tablet_leer.c:26
int IFK_AttachHandler(CPhidgetHandle IFK, void *userptr)
Definition: tablet_leer.c:96


cob_phidgets
Author(s): Florian Weisshardt
autogenerated on Wed Apr 7 2021 02:11:43