#include #include #include #include #include #include "keyboard.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "confile.h" #include "Util.h" #define KEY_EVENT_DEV0_NAME "/dev/input/event0" #define DEFAULT_MD_LEN 4096 int switch_video; unsigned char key_value; static pthread_t pkts_thread; int count=0; int osd_on=0; int light=0; int socket_descriptor; struct sockaddr_in address; //int *buffer; char rx_data[1024]; void * memmap(unsigned int phy_addr, unsigned int size); void* pkts_worker(void *arg) { printf("pkts_worker...\n"); int anjian_switch=0; uint32_t ulOld; int read_key; void* pMem = NULL; while(1) { // pMem = memmap(0x12150000, DEFAULT_MD_LEN); //gpio0 /// ulOld = *(uint32_t *)((char *)pMem + 0x3FC); //data // read_key = (ulOld &0x04)>>2; //get gpio0_2 value 0:FA 1:FE // printf("read_key: %d\n\r",read_key); // if(read_key==0x0) // { // mode=0; //count=1; //printf("key %d\n",key); // }else // mode= -1; // printf("mode %d\n",mode); anjian_switch =count; if(anjian_switch ==(switch_video+1)){ anjian_switch =1; } printf("-------------%x\n",anjian_switch); sendto(socket_descriptor,&anjian_switch,4,0,(struct sockaddr *)&address,sizeof(address)); usleep(500000); } } int *switch_memory_open(void) { char buf[128]; int fd; sprintf(buf, "/switch_mode"); fd = shm_open(buf, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if(fd < 0) { perror("shm_open"); exit(1); } if (ftruncate(fd, 4096) == -1) { perror("ftruncate"); exit(1); } int *retval = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); return retval; } int get_parameter(struct decoce_param *pparam) { if(confile_init()) { printf("config file parse filed!\n"); return -1; } pparam->sdi_switch = get_conf_int("sdi_switch", 0); pparam->osd_on = get_conf_int("osd_on", 0); //pparam->light = get_conf_int("light", 0); printf("sdi %d osd %d ",pparam->sdi_switch,pparam->osd_on); return 0; } int main(int argc, char **argv) { int key_fd = 0; struct input_event key_event = {0}; int ret; int port; int *switch_mode; int len; pthread_attr_t attr; //int *buffer; struct decoce_param param; //switch_video = 6; bzero(&address,sizeof(address)); address.sin_family=AF_INET; address.sin_addr.s_addr=inet_addr(argv[1]); port = atoi(argv[2]); address.sin_port=htons(port); socket_descriptor=socket(AF_INET,SOCK_DGRAM,0);//IPV4 switch_video = atoi(argv[3]); int flag_down=0; int count_down=0; key_fd = open(KEY_EVENT_DEV0_NAME, O_RDONLY); if(key_fd <= 0) { printf("---open /dev/input/event0 device error!---\n"); return ret; } pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); len = pthread_create(&pkts_thread, &attr, pkts_worker, NULL); pthread_attr_destroy(&attr); switch_mode = switch_memory_open(); get_parameter(¶m); printf("---\n"); //switch_mode[0] = 0x01; switch_mode[0] = param.sdi_switch; count = param.sdi_switch; switch_mode[1] = param.osd_on; //switch_mode[3] = param.light; osd_on = param.osd_on; //light = param.light; //buffer[0]=0x11; //_rx_data[0]=0x11; while(1) { ret = read(key_fd, &key_event, sizeof(key_event)); //printf("%d\n\r",ret); // printf("key_event.type %d EV_KEY %d \n",key_event.type,EV_KEY); // printf("key_event.value %d key_event.code %d count_down %d\n",key_event.value, key_event.code,count_down); } }