Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

I have two C files one is ev_test.c and capture.c, the capture.c file is to capture the images from the camera sensor, Now, i need to access the capture.c file from ev_test.c,

NOTE:

The ev_test.c is key press event interrupt generator file, in that i configured the a key= "volumebutton", if i press the key "volumebutton" it must call the main function of the capture.c file and it must capture the images

Can any one help me on how to call the main function in this

NOTE:

If you want the C files i can send you for reference

THE MAIN FUNCTION OF ev_test.c is
C
int main (int argc, char **argv)
{
	int fd, rd, i, j, k;
	struct input_event ev[64];
	int version;
	unsigned short id[4];
	unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
	char name[256] = "Unknown";
	int abs[5];

	if (argc < 2) {
		printf("Usage: evtest /dev/input/eventX\n");
		printf("Where X = input device number\n");
		return 1;
	}

	if ((fd = open(argv[argc - 1], O_RDONLY)) < 0) {
		perror("evtest");
		return 1;
	}

	if (ioctl(fd, EVIOCGVERSION, &version)) {
		perror("evtest: can't get version");
		return 1;
	}

	printf("Input driver version is %d.%d.%d\n",
		version >> 16, (version >> 8) & 0xff, version & 0xff);

	ioctl(fd, EVIOCGID, id);
	printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n",
		id[ID_BUS], id[ID_VENDOR], id[ID_PRODUCT], id[ID_VERSION]);

	ioctl(fd, EVIOCGNAME(sizeof(name)), name);
	printf("Input device name: \"%s\"\n", name);

	memset(bit, 0, sizeof(bit));
	ioctl(fd, EVIOCGBIT(0, EV_MAX), bit[0]);
	printf("Supported events:\n");

	for (i = 0; i < EV_MAX; i++)
		if (test_bit(i, bit[0])) {
			printf("  Event type %d (%s)\n", i, events[i] ? events[i] : "?");
			if (!i) continue;
			ioctl(fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
			for (j = 0; j < KEY_MAX; j++) 
				if (test_bit(j, bit[i])) {
					printf("    Event code %d (%s)\n", j, names[i] ? (names[i][j] ? names[i][j] : "?") : "?");
					if (i == EV_ABS) {
						ioctl(fd, EVIOCGABS(j), abs);
						for (k = 0; k < 5; k++)
							if ((k < 3) || abs[k])
								printf("      %s %6d\n", absval[k], abs[k]);
					}
				}
		}
		

	printf("Testing ... (interrupt to exit)\n");

	while (1) {
		rd = read(fd, ev, sizeof(struct input_event) * 64);

		if (rd < (int) sizeof(struct input_event)) {
			printf("yyy\n");
			perror("\nevtest: error reading");
			return 1;
		}
		printf("OVIYA RD=%d SIZE=%d\n",rd, sizeof(struct input_event));
		for (i = 0; i < rd / sizeof(struct input_event); i++)
			
			if (ev[i].type == KEY_VOLUMEDOWN) {
			
				printf("Event: time %ld.%06ld, -------------- %s ------------\n",
					ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].code ? "Config Sync" : "Report Sync" );
			} else if (ev[i].type == EV_MSC && (ev[i].code == MSC_RAW || ev[i].code == MSC_SCAN)) {
				printf("Event: time %ld.%06ld, type %d (%s), code %d (%s), value %02x\n",
					ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].type,
					events[ev[i].type] ? events[ev[i].type] : "?",
					ev[i].code,
					names[ev[i].type] ? (names[ev[i].type][ev[i].code] ? names[ev[i].type][ev[i].code] : "?") : "?",
					ev[i].value);
			} else {
				printf("OVIYA CHECK3--------------\n");
				printf("Event: time %ld.%06ld, type %d (%s), code %d (%s), value %d\n",
					ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].type,
					events[ev[i].type] ? events[ev[i].type] : "?",
					ev[i].code,
					names[ev[i].type] ? (names[ev[i].type][ev[i].code] ? names[ev[i].type][ev[i].code] : "?") : "?",
					ev[i].value);
			}	

	}
}


Thanks
shan

[Edit]Code block added and shouting from title removed[/Edit]
Posted
Updated 14-Jun-13 2:35am
v4

The usual way to call a 'C' function defined in another file without a common header file is to declare it as extern.

//file1.c

//declare a 'foreign' function which is not defined

extern int OtherFunction( char**, int );

//implement the functions that belong in this file scope

int MainFunction1( void )
{
//The declared but not implemented 'OtherFunction' can be called here

  int iResult = OtherFunction( &aString, iCountStrings );
//...
}


The file1.c code will compile but it won't link because it relies on an external function that hasn't been defined. So now file2.c can be added which implements the 'missing' function.

//file2.c

int OtherFunction( char** aStrings, int iCountStrings )
{
//...
}


The file2.c is compiled on its own and then the output linked with the output of compiling file1.c to form a single executable which links successfully because everything necessary is now present.

It should I hope be obvious how to apply this pattern to your situation to enable the calling of one file scope function from another in a different file.
 
Share this answer
 
Why arent you call the executable with a complete commandline to do the job?

Otherwise cleanup the main function in a parser and call function. The call function is then better accessable.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900