main.c

来自「基于ARM9的LINUX下的按键驱动程序」· C语言 代码 · 共 82 行

C
82
字号
/*****************************************Copyright (c)****************************************************                               Guangzhou Zhiyuan Electronic Co.,LTD.**                                     graduate school**                                 http://www.zyinside.com****------------------------------------- File Info ------------------------------------------------------** File name:           main.c** Last modified Date:  2005-12-28** Last Version:        1.0** Descriptions:        Test program for KEY1's driver.**------------------------------------------------------------------------------------------------------** Created by:          Chenxibing** Created date:        2005-12-27** Version:             1.0** Descriptions:        Preliminary version.****------------------------------------------------------------------------------------------------------** Modified by:** Modified date:** Version:** Descriptions:***********************************************************************************************************/#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/ioctl.h>#include <errno.h>#include <fcntl.h>#include <sys/types.h>//#include <sys/time.h>//#include <sys/stat.h>/********************************************************************************************************** Function name: main()** Descriptions	: Read KEY's value and Pressed times.** Input	: NONE** Output	: NONE** Created by	: Chenxibing** Created Date	: 2005-12-27**-----------------------------------------------------------------------------------------------------** Modified by	:** Modified Date: **-----------------------------------------------------------------------------------------------------********************************************************************************************************/int main(int argc, char **argv){	int fd;	int result;	int key_value;	int times = 1;	fd = open("/dev/magic-key", 0);	if (fd < 0)	{		perror("Failed to open magic-key\n");		exit(1);	}		while(times < 10)	{		result = read(fd, &key_value, sizeof(key_value)) == sizeof(key_value);		if (!result)		{			if (errno == EINVAL)				printf("Wrong size!\n");			goto exit;			}		printf("KEY1's value is %d ;", key_value);		printf(" Be pressed %d times\n", times++);	}exit:	close(fd);	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?