13 static const char* const dev = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";
16 static int number = 4000;
18 static fpos_t dev_start;
21 next_space(char* ptr) {
22 while(*ptr != ' ') ++ptr;
26 static unsigned char offset = 0x000f;
27 static unsigned char buffer[256];
28 static const unsigned char space = ' ';
29 static const unsigned char minus = '-';
31 #define asci_2_digit(asci) (asci & offset)
32 #define add_next_value(val,_ptr) *val=(*val<<3)+(*val<<1)+asci_2_digit(*_ptr)
33 #define is_space(_ptr) !(*_ptr ^ space)
34 #define is_minus(_ptr) !(*_ptr ^ minus)
39 if(minus == *ptr) { ++ptr; x = -1 * ((*ptr)-offset); ++ptr; }
40 while(space != *ptr) {
41 x = (x << 3) + (x << 1);
47 if(minus == *ptr) { ++ptr; y = -1 * ((*ptr)-offset); ++ptr; }
48 while(space != *ptr) {
49 y = (y << 3) + (y << 1);;
55 if(minus == *ptr) { ++ptr; z = -1 * ((*ptr)-offset); ++ptr; }
56 while(space != *ptr) {
57 z = (z << 3) + (z << 1);
63 static void inline driver_read() {
68 main (int argc, char* argv[])
72 printf ("Starting application...\n");
74 printf ("Standard way of reading...\n");
76 for (i = 0; i < number; ++i)
82 fscanf(fd,"%i %i %i", &x, &y, &z);
85 //printf("%.3i. Coords: (x,y,z)=(%i, %i, %i)\n", i+1, x, y, z);
88 printf("clock ticks pased: %i\n", (int)(t1-t0) / 1000);
90 printf ("No closing file...\n");
95 for (i = 0; i < number; ++i)
98 fscanf(fd,"%i %i %i", &x, &y, &z);
99 fseek (fd ,0 ,SEEK_SET);
100 //printf("%.3i. Coords: (x,y,z)=(%i, %i, %i)\n", i+1, x, y, z);
104 printf("clock ticks pased: %i\n", (int)(t1-t0) / 1000);
106 printf ("No closing file (setpos)...\n");
107 fd = fopen(dev, "r");
108 fgetpos (fd, &dev_start);
110 for (i = 0; i < number; ++i)
113 fscanf(fd,"%i %i %i", &x, &y, &z);
114 fsetpos (fd, &dev_start);
115 //printf("%.3i. Coords: (x,y,z)=(%i, %i, %i)\n", i+1, x, y, z);
119 printf("clock ticks pased: %i\n", (int)(t1-t0) / 1000);
121 printf ("Linux kernel...\n");
122 int de = open(dev, O_RDONLY);
124 for (i = 0; i < number; ++i)
126 lseek(de, 0, SEEK_SET);
127 read(de, buffer, 255);
128 sscanf((char*)buffer,"%i %i %i", &x, &y, &z);
129 //printf("%.3i. Coords: (x,y,z)=(%i, %i, %i)\n", i+1, x, y, z);
133 printf("clock ticks pased: %i\n", (int)(t1-t0) / 1000);
135 printf ("Linux kernel (own conversion)...\n");
136 de = open(dev, O_RDONLY);
138 for (i = 0; i < number; ++i)
140 lseek(de, 0, SEEK_SET);
141 read(de, buffer, 255);
143 //printf("%.3i. Coords: (x,y,z)=(%i, %i, %i)\n", i+1, x, y, z);
147 printf("clock ticks pased: %i\n", (int)(t1-t0) / 1000);
150 printf ("Application stoped.\n");