static void *ac_pushwaitthread(void *cookie){ miui_debug("pthread %s start...\n", __FUNCTION__); APUSHWAITDATAP dt = (APUSHWAITDATAP) cookie; if (dt->ctl->win->isActived) dt->ctl->win->threadnum++; else{ free(dt); return NULL; } int waitsz = 0; byte isvalid = 1; while (++waitsz<300){ if (!dt->ctl->win->isActived){ isvalid=0; break; } if (dt->moveY[0]==-50){ isvalid=0; break; } usleep(10); } #if 0 if ((isvalid)&&(dt->moveY[0]!=-50)){ dt->flagpointer[0]=dt->flagvalue; dt->ctl->ondraw(dt->ctl); aw_draw(dt->ctl->win); } #endif dt->ctl->win->threadnum--; free(dt); return NULL; }
static int screen_set_time(time_t time) { return_val_if_fail(time > 0, -1); miui_debug("set time %ld\n", time); time_orig = time; return 0; }
static void *ac_scrolltothread(void *cookie){ miui_debug("pthread %s start...\n", __FUNCTION__); ASCROLLTODATAP dt = (ASCROLLTODATAP) cookie; if (dt->ctl->win->isActived) dt->ctl->win->threadnum++; else{ free(dt); return NULL; } dt->ctl->forceNS = 1; while (dt->scrollY[0]!=dt->requestY){ int diff = floor(((float) (dt->scrollY[0] - dt->requestY)) * 0.5); if (abs(diff)<1) dt->scrollY[0] = dt->requestY; else dt->scrollY[0]-= diff; //-- REDRAW dt->ctl->ondraw(dt->ctl); aw_draw(dt->ctl->win); if (dt->requestHandler[0]!=dt->requestValue) break; if (!dt->ctl->win->isActived) break; if (ui_key_pressed(atmsg())){ ACONTROLP nctl = (ACONTROLP) dt->ctl->win->controls[dt->ctl->win->touchIndex]; if (nctl==dt->ctl) break; } } dt->ctl->forceNS = 0; dt->ctl->win->threadnum--; free(dt); return NULL; }
int screen_set_black(int black) { pthread_mutex_lock(&mutex_screen); int fd = open(acfg()->brightness_path, O_WRONLY); if (fd <= 0) { miui_error("open %s failed!\n", acfg()->brightness_path); } else { bool_black = black; if (bool_black) { if (write(fd,"0", 1) <= 0) { miui_error("%s write error %s", acfg()->brightness_path, strerror(errno)); } } else { miui_debug("screen_light_buf is %s\n", screen_light_buf); if (write(fd,screen_light_buf,strlen(screen_light_buf)) <= 0) { miui_error("%s write error %s", acfg()->brightness_path, strerror(errno)); } } close(fd); } pthread_mutex_unlock(&mutex_screen); return 0; }
static void *ac_flingthread(void *cookie){ miui_debug("pthread %s start...\n", __FUNCTION__); AFLINGDATAP dt = (AFLINGDATAP) cookie; if (dt->ctl->win->isActived) dt->ctl->win->threadnum++; else{ free(dt); return NULL; } int mz = akinetic_fling(dt->akin); float vz=0.0; while ((mz!=0)&&(dt->ctl->win->isActived)){ if (dt->ctl->forceNS) break; int zz=ceil(dt->akin->velocity); /*vz+=dt->akin->velocity-zz; if (abs(vz)>=1){ if (vz<0){ vz+=1.0; zz--; } else{ vz-=1.0; zz++; } }*/ //if (zz!=0){ dt->scrollY[0]+=zz; dt->ctl->ondraw(dt->ctl); aw_draw(dt->ctl->win); //} if (!dt->ctl->win->isActived) break; if ((dt->scrollY[0]<0-(dt->ctl->h/4))||(dt->scrollY[0]>dt->maxScrollY+(dt->ctl->h/4))) break; if (ui_key_pressed(atmsg())){ ACONTROLP nctl = (ACONTROLP) dt->ctl->win->controls[dt->ctl->win->touchIndex]; if (nctl==dt->ctl) break; } //usleep(4000); if ((dt->scrollY[0]<0)||(dt->scrollY[0]>dt->maxScrollY)) mz=akinetic_fling_dampered(dt->akin,0.6); else mz=akinetic_fling(dt->akin); } if (dt->ctl->win->isActived){ if ((dt->scrollY[0]<0)||(dt->scrollY[0]>dt->maxScrollY)){ ac_regbounce(dt->ctl,dt->scrollY,dt->maxScrollY); } } dt->ctl->win->threadnum--; free(dt); return NULL; }
//-- INPUT THREAD static void *ev_input_thread(void *cookie){ //-- Loop for Input miui_debug("pthread %s start..., evtouch_thack is %d..\n", __FUNCTION__, evtouch_thack); while (evthread_active){ //-- Wait For Input Event int r = poll(ev_fds, ev_count, -1); if (r >= 0){ //-- New Key Event unsigned n; for (n=0; n<ev_count; n++) { if (ev_fds[n].revents & ev_fds[n].events) ev_input_callback(ev_fds[n].fd, ev_fds[n].revents); } } } return NULL; }
static void *ev_input_thack(void *cookie){ miui_debug("pthread %s start, evtouch_thack is %d...\n", __FUNCTION__, evtouch_thack); while(evtouch_thack){ if (evtouch_state!=0){ if (evtouch_lastick<alib_tick()-10){ evtouch_locked = 1; evtouch_alreadyu= 1; evtouch_state = 0; evtouch_sx = 0; evtouch_sy = 0; evtouch_rx = 0; evtouch_ry = 0; ev_post_message(evtouch_code,0); } } usleep(20); } return NULL; }
static void *ac_bouncethread(void *cookie){ miui_debug("pthread %s start...\n", __FUNCTION__); ABOUNCEDATAP dt = (ABOUNCEDATAP) cookie; if (dt->ctl->win->isActived) dt->ctl->win->threadnum++; else{ free(dt); return NULL; } int bouncesz = 0; byte bouncetype = 0; if (dt->scrollY[0]<0) bouncesz = abs(dt->scrollY[0]); else if (dt->scrollY[0]>dt->maxScrollY){ bouncetype = 1; bouncesz = dt->scrollY[0] - dt->maxScrollY; } while (bouncesz>0){ if (dt->ctl->forceNS) break; bouncesz = floor(bouncesz*0.9); if (bouncetype) dt->scrollY[0] = dt->maxScrollY + bouncesz; else dt->scrollY[0] = 0 - bouncesz; //-- REDRAW dt->ctl->ondraw(dt->ctl); aw_draw(dt->ctl->win); if (!dt->ctl->win->isActived) break; if (ui_key_pressed(atmsg())){ ACONTROLP nctl = (ACONTROLP) dt->ctl->win->controls[dt->ctl->win->touchIndex]; if (nctl==dt->ctl) break; } if (dt->scrollY[0]==0) break; if (dt->scrollY[0]==dt->maxScrollY) break; } dt->ctl->win->threadnum--; free(dt); return NULL; }
int ev_init(){ miui_debug("function %s entery\n", __FUNCTION__); DIR *dir; struct dirent *de; int fd; dir = opendir("/dev/input"); if(dir != 0) { while((de = readdir(dir))) { unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; if(strncmp(de->d_name,"event",5)) continue; fd = openat(dirfd(dir), de->d_name, O_RDONLY); if(fd < 0) continue; /* read the evbits of the input device */ if (ioctl(fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits) < 0) { close(fd); continue; } /* ABS, KEY & REL */ if (!test_bit(EV_ABS, ev_bits) && !test_bit(EV_SYN, ev_bits) && !test_bit(EV_KEY, ev_bits) && !test_bit(EV_REL, ev_bits)) { close(fd); continue; } ev_fds[ev_count].fd = fd; ev_fds[ev_count].events = POLLIN; ev_count++; ev_dev_count++; if(ev_dev_count == MAX_DEVICES) break; } } //-- Create Watcher Thread evthread_active = 1; pthread_t input_thread_t; pthread_create(&input_thread_t, NULL, ev_input_thread, NULL); pthread_detach(input_thread_t); // atouch_sethack(1); return 0; }
/* Translate Event */ static byte aipTranslateEvent(AIP_EVP e, struct input_event * ev){ static int downX = -1; static int downY = -1; static int discard = 0; static int lastWasSynReport = 0; static int touchReleaseOnNextSynReport = 0; int i; int x, y; /* Not Used */ if (e->ignored){ return 1; } if ((ev->type==EV_REL) && (ev->code == REL_Z)){ /* This appears to be an accelerometer or another strange input device. It's not the touchscreen. */ e->ignored = 1; return AIP_TRANS_IGNONE; } /* Handle keyboard events, value of 1 indicates key down, 0 indicates key up */ if (ev->type == EV_KEY) { return AIP_TRANS_KEY; } /* Possibly Touchscreen */ if (ev->type == EV_ABS) { switch (ev->code) { case AIP_ABS_X: { e->p.synced |= 0x01; e->p.x = ev->value; miui_debug("EV: %s => ABS_X %d\n", e->device_name, ev->value); } break; case AIP_ABS_Y: { e->p.synced |= 0x02; e->p.y = ev->value; miui_debug("EV: %s => ABS_Y %d\n", e->device_name, ev->value); } break; case AIP_ABS_MT_POSITION: { e->mt_p.synced = 0x03; if (ev->value == (1 << 31)){ e->mt_p.x = 0; e->mt_p.y = 0; lastWasSynReport = 1; } else{ lastWasSynReport = 0; e->mt_p.x = (ev->value & 0x7FFF0000) >> 16; e->mt_p.y = (ev->value & 0xFFFF); } } break; case AIP_ABS_MT_TOUCH_MAJOR: { if (ev->value == 0) { e->mt_p.x = 0; e->mt_p.y = 0; touchReleaseOnNextSynReport = 1; } } break; case AIP_ABS_MT_PRESSURE: { if (ev->value == 0){ e->mt_p.x = 0; e->mt_p.y = 0; touchReleaseOnNextSynReport = 1; } } break; case AIP_ABS_MT_POSITION_X: { e->mt_p.synced |= 0x01; e->mt_p.x = ev->value; } break; case AIP_ABS_MT_POSITION_Y: { e->mt_p.synced |= 0x02; e->mt_p.y = ev->value; } break; default: { return AIP_TRANS_NONE; } } if (ev->code != AIP_ABS_MT_POSITION){ lastWasSynReport = 0; return AIP_TRANS_NONE; } } if (ev->code != AIP_ABS_MT_POSITION && (ev->type != EV_SYN || (ev->code != AIP_SYN_REPORT && ev->code != AIP_SYN_MT_REPORT) ) ){ lastWasSynReport = 0; return AIP_TRANS_NONE; } if (ev->code == AIP_SYN_MT_REPORT){ return AIP_TRANS_NONE; } if (lastWasSynReport == 1 || touchReleaseOnNextSynReport == 1){ /* Reset the value */ touchReleaseOnNextSynReport = 0; /* We are a finger-up state */ if (!discard){ /* Report the key up */ ev->type = EV_ABS; ev->code = 0; ev->value = (downX << 16) | downY; } downX = -1; downY = -1; if (discard){ discard = 0; return AIP_TRANS_NONE; } return AIP_TRANS_TOUCH; } lastWasSynReport = 1; if (e->p.synced & 0x03){ aipCalculateTouch(&e->p, &x, &y); } else if (e->mt_p.synced & 0x03){ aipCalculateTouch(&e->mt_p, &x, &y); } else{ return AIP_TRANS_NONE; } /* Swap & Flip Handler */ if (_aip->touch_swap_xy){ x ^= y; y ^= x; x ^= y; } if (_aip->touch_flip_x){ x = agw() - x; } if (_aip->touch_flip_y){ y = agh() - y; } /* Clear the current sync states */ e->p.synced = e->mt_p.synced = 0; /* If we have nothing useful to report, skip it */ if (x == -1 || y == -1){ return AIP_TRANS_NONE; } /* On first touch, see if we're at a virtual key */ if (downX == -1){ /* Attempt mapping to virtual key */ for (i=0; i<e->vkn; ++i){ int xd = abs(e->vks[i].x - x); int yd = abs(e->vks[i].y - y); if (xd < e->vks[i].w/2 && yd < e->vks[i].h/2){ ev->type = EV_KEY; ev->code = e->vks[i].scan; ev->value= 1; /* vibrate(VIBRATOR_TIME_MS); */ discard = 1; downX = 0; return AIP_TRANS_KEY; } } } /* If we were originally a button press, discard this event */ if (discard){ return AIP_TRANS_NONE; } /* Record where we started the touch for deciding if this is a key or a scroll */ downX = x; downY = y; ev->type = EV_ABS; ev->code = 1; ev->value = (x << 16) | y; return AIP_TRANS_TOUCH; }
//-- MIUI Input Handler static void atev_dump(ATEV *atev, int key){ miui_debug("key:%d, atev->x:%d, atev->y:%d, atev->d:%d, atev->k:%d, msg:%08x\n", \ key, atev->x, atev->y, atev->d, atev->k, atev->msg); }
static void input_event_dump(const char *str, struct input_event *ev) { miui_debug("[%s]ev->type:%4x , ev->code:%4x, ev->value:%4x\n",str, ev->type, ev->code, ev->value); }