void check_music() { if(SdPlay.isStopped()) { if(music_state != ISSTOP) { draw_music_state(255, 255, 255); music_state = ISSTOP; draw_music_state(0, 0, 0); } next_music(); } }
void *key_controll_pthread_fun() { int keyboard_fd; char *keyboard_str = "/dev/input/by-path/platform-i8042-serio-0-event-kbd"; //int open(const char *pathname, int flags); //int open(const char *pathname, int flags, mode_t mode); //int creat(const char *pathname, mode_t mode); if((keyboard_fd = open(keyboard_str , O_RDONLY )) < 0) { fprintf( stderr , "open %s failed:%s\n" , keyboard_str , strerror(errno)); exit(1); } // fprintf( stdout , "open %s success\n" , keyboard_str ); #if 0 struct input_event { struct timeval time; __u16 type; __u16 code; __s32 value; }; #endif struct input_event i_event; int read_bytes; int auto_display = 0; int keep_reading = 1; clear_frame_buffer( fb ); first_show(); show_weather(fb , weather_info); while(keep_reading) { // fprintf(stdout , "1\n"); if((read_bytes = read(keyboard_fd , &i_event , sizeof(struct input_event))) < 0) { fprintf(stdout , "read from keyboard error:%s\n" , strerror(errno)); exit(1); } else { // press key if(EV_KEY == i_event.type) { // value == 1 means key DOWN however 2 means key UP if(i_event.value == 1) { //fprintf(stdout , "key DOWN value=%d\n" , i_event.value); switch(i_event.code) { case KEY_LEFT : change_global_keycode(&global_keycode , i_event.code); // clear_frame_buffer( fb ); // pthread_cancel(auto_display_pthread); show_privious(); // show_weather(fb , weather_info); break; case KEY_RIGHT: change_global_keycode(&global_keycode , i_event.code); // clear_frame_buffer( fb ); // pthread_cancel(auto_display_pthread); show_next(); // show_weather(fb , weather_info); break; case KEY_N: change_global_keycode(&global_keycode , i_event.code); pthread_cancel(music_pthread); system("killall -9 madplay"); // pthread_mutex_lock(&music_mutex); next_music(); if(auto_display == 0) { // pthread_mutex_lock(&music_mutex); clear_frame_buffer( fb ); first_show(); show_weather(fb , weather_info); // pthread_mutex_lock(&music_mutex); } break; case KEY_P: change_global_keycode(&global_keycode , i_event.code); pthread_cancel(music_pthread); system("killall -9 madplay"); //int pthread_mutex_lock(pthread_mutex_t *mutex); // pthread_mutex_lock(&music_mutex); privious_music(); if(auto_display == 0) { // pthread_mutex_lock(&music_mutex); clear_frame_buffer( fb ); first_show(); show_weather(fb , weather_info); // pthread_mutex_lock(&music_mutex); } break; case KEY_SPACE: if(auto_display == 0) { auto_display = 1; auto_display_pthread = start_auto_display_pthread(); } else { auto_display = 0; pthread_cancel(auto_display_pthread); clear_frame_buffer( fb ); first_show(); show_weather(fb , weather_info); } break; case KEY_Q: change_global_keycode(&global_keycode , i_event.code); pthread_cancel(auto_display_pthread); pthread_cancel(music_pthread); system("killall -9 madplay"); goto END; } } #if 0 else if(i_event.value == 0) { fprintf(stdout , "key UP value=%d\n" , i_event.value); } else { fprintf(stdout , "do not know value=%d\n" , i_event.value); } #endif } } } END: fprintf(stdout ,"key_controll_pthread exit : %s\n" , __func__); //int close(int fd); close(keyboard_fd); //void pthread_exit(void *value_ptr); pthread_exit(NULL); }