⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vr4181.c

📁 miniucgui1.30版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
                /* is it a pen-release? */                if ( (data[0] & 0x4000) == 0 ) {                        /* TODO: in order to provide maximum responsiveness                         * maybe return the data in the filter                         * if the filter count is still below                         * the output threshold.                         */                        /* reset the limiter */                        have_last_data = 0;                        /* reset the filter */                        iir_count = 0;                        iir_accum_x = 0;                        iir_accum_y = 0;                        iir_accum_z = 0;                        /* return the pen (button) state only, */                        /* indicating that the pen is up (no buttons are down) */                        *pb = 0;                        return 3;                }                /* ignore pen-down since we don't know where it is */                return 0;        }        /* we have position data */        /*         * Combine the complementary panel readings into one value (except z)         * This effectively doubles the sampling freqency, reducing noise by approx 3db.         * Again, please don't quote the 3db figure.         * I think it also cancels out changes in the overall resistance of the panel         * such as may be caused by changes in panel temperature.         */        data_x = data[2] - data[1];        data_y = data[4] - data[3];        data_z = data[5];        /* isn't z big enough for valid position data? */        if ( data_z <= low_z_limit ) {#if TEST                printf("Discarding low-z sample.\n");#endif                return 0;        }        /* has the position changed more than we will allow? */        if (have_last_data) {                if ( (abs(data_x - last_data_x) > data_change_limit)                        || ( abs(data_y - last_data_y) > data_change_limit ) )                {#if TEST                        printf("Discarding changed-too-much sample.\n");#endif                        return 0;                }        }        /* save last position */        last_data_x = data_x;        last_data_y = data_y;        have_last_data = 1;        /* is filter full? */        if ( iir_count == iir_sample_depth ) {                /* make room for new sample */                iir_accum_x -= iir_accum_x >> iir_shift_bits;                iir_accum_y -= iir_accum_y >> iir_shift_bits;                iir_accum_z -= iir_accum_z >> iir_shift_bits;                iir_count--;        }        /* feed new sample to filter */        iir_accum_x += data_x;        iir_accum_y += data_y;        iir_accum_z += data_z;        /* TODO: optimize the unnecessary count--/++ when filter full */        iir_count++;        /* aren't we over the threshold yet? */        if (iir_count <= iir_output_threshold)                return 0;        /* Touch-panel only reports left button. */        /* I moved this up here in preparation for the below-threshold         * on pen-up filter output TODO above.         */        *pb = LBUTTON;        /* figure filter output */        /* TODO: optimize for shifts instead of divides (when possible)? */        iir_out_x = (iir_accum_x * iir_gain) / iir_count;        iir_out_y = (iir_accum_y * iir_gain) / iir_count;        iir_out_z = (iir_accum_z * iir_gain) / iir_count;#if TEST        if ( show_filtered )                printf("data: %hd, %hd, %hd  accum: %d, %d, %d  out: %d, %d, %d\n",                        data_x, data_y, data_z,                        iir_accum_x, iir_accum_y, iir_accum_z,                        iir_out_x, iir_out_y, iir_out_z);#endif        /* transformation enabled? */        if (Vr_enable_transform)        {                /* Transform filtered position info to screen coordinates.                 * Yes, x and y are meant to be swapped.                 * Odd as it seems, the x value really represents the y position                 * of the pen and the y value represents the x position of the pen.                 * This has to do with the way the touch panel hardware works.                 * It applies a voltage to the y axis to measure x, then applies a                 * voltage to the x axis to measure y.                 * X and y values from the touch-panel driver are those                 * voltage measurements, not position measurements.                 */#ifdef REMOTE_TEST                XYPOINT transformed = {iir_out_x, iir_out_y};#else                                XYPOINT transformed = {iir_out_y, iir_out_x};#endif                                transformed = DeviceToScreen(transformed);                /*                 * HACK: move this from quarter pixels to whole pixels for now                 * at least until I decide on the right interface to get the                 * quarter-pixel data up to the next layer.                 */                *px = transformed.x >> 2;                *py = transformed.y >> 2;        }        else        {                /*                 * Return untransformed filtered position info.                 * Same odd swapping of x and y due to the way that                 * the touch panel works (see above).                 */                *px = iir_out_y;                *py = iir_out_x;        }        /* Return filtered pressure.*/        *pz = iir_out_z;        return 2;}/************************  Low Level Input Operations **********************//* * Mouse operations -- Event */static int mouse_update(void){    return 1;}static void mouse_getxy (int* x, int* y){    *x = mousex;    *y = mousey;}static int mouse_getbutton(void){    return mousez;}static int keyboard_update(void){    switch ((btn_state) & 0x0fff)    {    case 0x7://keycode = Key_Up    break;    case 0x9://keycode = Key_Right    break;    case 0x8://keycode = Key_Down        break;    case 0xa://keycode = Key_Left        break;    case 0x3://keycode = Key_Up    break;    case 0x4://keycode = Key_Down    break;    case 0x1://keycode = Key_Backspace    break;    case 0x2://keycode = Key_Escape    break;    case 0x5://keycode = Key_CONTRAST    break;    case 0x6://keycode = Key_BACKLIGHT    break;    case 256://keycode = Key_AP1    break;    case 257://keycode = Key_AP2      break;    case 258://keycode = Key_AP3       break;    case 259://keycode = Key_AP4        break;    }                return 0;}static const char* keyboard_getstate(void){    return (char *)state;}#ifdef _LITE_VERSION static int wait_event (int which, int maxfd, fd_set *in, fd_set *out, fd_set *except,                struct timeval *timeout){    fd_set rfds;    int    e;    int    retvalue = 0;    int    x,y,z,b;    int    result;    if (!in) {        in = &rfds;        FD_ZERO (in);    }    if (which & IAL_MOUSEEVENT && ts >= 0) {        FD_SET (ts, in);        if (ts > maxfd) maxfd = ts;    }#ifdef _VR_BUTTONS        if (which & IAL_KEYEVENT && btn_fd >= 0){            FD_SET (btn_fd, in);            if(btn_fd > maxfd)            maxfd = btn_fd;    }#endif            e = select (maxfd + 1, in, out, except, timeout) ;    if (e > 0) {         if (ts >= 0 && FD_ISSET (ts, in)) {            FD_CLR (ts, in);            /* FIXME: while telnet: x & y should be exchanged. */            result = VrTpanelRead (ts, &x, &y, &z, &b);            if (result == 2 || result == 3) {                mousex = x;                mousey = y;                mousez = b;#if REMOTE_TEST                            fprintf(stderr,"result:\t\t%d\n",result);                fprintf(stderr,"mousex\tmousey\tmousez:\t%d\t%d\t%d\n",mousex,mousey,mousez);#endif                        mousez = ( mousez > 0 ? 4:0);                retvalue |=IAL_MOUSEEVENT;             }        }        #ifdef _VR_BUTTONS        if (btn_fd >= 0 && FD_ISSET(btn_fd, in)) {            unsigned short code;            FD_CLR(btn_fd, in);            result = read (btn_fd, &code, sizeof(code));            btn_state = code;            retvalue |= IAL_KEYEVENT;        }#endif                               } else if (e < 0) {        return -1;    }    return retvalue;}#elsestatic int wait_event (int which, fd_set *in, fd_set *out, fd_set *except,                struct timeval *timeout){    int    x,y,z,b,result;    struct pollfd ufd;    if (which & IAL_MOUSEEVENT) {        ufd.fd     = ts;        ufd.events = POLLIN;         if (poll (&ufd, 1, timeout) > 0) {            result = VrTpanelRead(ts, &x, &y, &z, &b);            if (result == 2 || result == 3) {                mousex = x;                mousey = y;                mousez = b;                return IAL_MOUSEEVENT;            }        }    }    return 0;}#endifBOOL InitVR4181Input (INPUT* input, const char* mdev, const char* mtype){    int i;    ts = VrTpanelInit();    if ( ts < 0 ) {        fprintf (stderr, "IAL: Can not open vr41xx touch screen!\n");        return FALSE;    }    for(i = 0; i < NR_KEYS; i++)        state[i] = 0;#ifdef _VR_BUTTONS    btn_fd = open (BTN_DEV_FILE, O_RDONLY);    if (btn_fd < 0) {        return FALSE;    }#endif    input->update_mouse = mouse_update;    input->get_mouse_xy = mouse_getxy;    input->set_mouse_xy = NULL;    input->get_mouse_button = mouse_getbutton;    input->set_mouse_range = NULL;    input->update_keyboard = keyboard_update;    input->get_keyboard_state = keyboard_getstate;    input->set_leds = NULL;    input->wait_event = wait_event;    mousex = 0;    mousey = 0;    return TRUE;}void TermVR4181Input (void){    if ( ts >= 0 )        close(ts);}#endif /* _VR4181_IAL */

⌨️ 快捷键说明

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