#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" int switch_video; unsigned char key_value; static pthread_t pkts_thread; int count=0; int osd_on=0; 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); 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; struct decoce_param param; switch_video = 5; 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; } switch_mode = switch_memory_open(); get_parameter(¶m); switch_mode[0] = param.sdi_switch; count = param.sdi_switch; switch_mode[1] = param.osd_on; osd_on = param.osd_on; while(1) { ret = read(key_fd, &key_event, sizeof(key_event)); if(ret) { if(key_event.type == EV_KEY && key_event.value == 1 ) { flag_down=1; count_down=1; }else if(key_event.type == EV_KEY && key_event.value == 2){ count_down++; }else if(key_event.type == EV_KEY && key_event.value == 0){ if(flag_down == 1){ //短按 if((key_event.code == 0x1E) && (count_down < 25)) { //key_value = 0x01; count++; if(count == (switch_video+1)){ count=1; } set_conf_int("sdi_switch",count); save_confile("/data/decode.cfg"); switch_mode[0] = count; } if((count_down > 50) && (key_event.code == 0x1E)){ printf("long\n"); osd_on ^= 0x01; switch_mode[1] = osd_on; // count_down=0; set_conf_int("osd_on",osd_on); save_confile("/data/decode.cfg"); } // count_down=0; } flag_down =0; count_down =0; } } } }