Exemplo n.º 1
0
static void do_calibration_da9052(int do_calib)
{
    int i, x, y;
    int dx[3], dy[3];
    int tx[3], ty[3];
    int delta, delta_x[3], delta_y[3];
    struct input_absinfo absX, absY;
    
    if (do_calib) {
        /* calculate the expected point */
        x = info.xres / 4;
        y = info.yres / 4;

        dx[0] = x;
        dy[0] = info.yres / 2;
        dx[1] = info.xres / 2;
        dy[1] = y;
        dx[2] = info.xres - x;
        dy[2] = info.yres - y;

        for (i = 0; i < 3; i ++) {
        draw_cross(dx[i], dy[i], 0);
        get_input(&tx[i], &ty[i]);
	        log_write("Received x,y -> Expected x,y\n");
	        log_write("%d,%d -> %d,%d\n",
		        tx[i], ty[i], dx[i], dy[i]);
        draw_cross(dx[i], dy[i], 1);
        }


        /* check ok, calulate the result */
        delta = (tx[0] - tx[2]) * (ty[1] - ty[2])
                    - (tx[1] - tx[2]) * (ty[0] - ty[2]);
        delta_x[0] = (dx[0] - dx[2]) * (ty[1] - ty[2])
                    - (dx[1] - dx[2]) * (ty[0] - ty[2]);
        delta_x[1] = (tx[0] - tx[2]) * (dx[1] - dx[2])
                    - (tx[1] - tx[2]) * (dx[0] - dx[2]);
        delta_x[2] = dx[0] * (tx[1] * ty[2] - tx[2] * ty[1]) -
                    dx[1] * (tx[0] * ty[2] - tx[2] * ty[0]) +
                    dx[2] * (tx[0] * ty[1] - tx[1] * ty[0]);
        delta_y[0] = (dy[0] - dy[2]) * (ty[1] - ty[2])
                    - (dy[1] - dy[2]) * (ty[0] - ty[2]);
        delta_y[1] = (tx[0] - tx[2]) * (dy[1] - dy[2])
                    - (tx[1] - tx[2]) * (dy[0] - dy[2]);
        delta_y[2] = dy[0] * (tx[1] * ty[2] - tx[2] * ty[1]) -
                    dy[1] * (tx[0] * ty[2] - tx[2] * ty[0]) +
                    dy[2] * (tx[0] * ty[1] - tx[1] * ty[0]);

        cal_val[0] = delta_x[0];
        cal_val[1] = delta_x[1];
        cal_val[2] = delta_x[2];
        cal_val[3] = delta_y[0];
        cal_val[4] = delta_y[1];
        cal_val[5] = delta_y[2];
        cal_val[6] = delta;
		

        save_conf(cal_val);
        write_conf(cal_val);
    }

    /* Android input framework expects values based on the absmax.
	 Now that the touchscreen is calibrated set the input maximum
	 according to screen resolution, not the touch sensor resolution */
	if (ioctl(ts_fd, EVIOCGABS(ABS_X), &absX) == -1) {
		log_write("EVIOCGABS( failed\n");
	} else {
		log_write("Modifying x.max:%i -> %i\n", absX.maximum, info.xres);
		absX.maximum = info.xres;
		if (ioctl(ts_fd, EVIOCSABS(ABS_X), &absX) == -1)
			log_write("EVIOCSABS( failed\n");
	}

	if (ioctl(ts_fd, EVIOCGABS(ABS_Y), &absY) == -1) {
		log_write("EVIOCGABS( failed\n");
	} else {
		log_write("Modifying y.max:%i -> %i\n", absY.maximum, info.yres);
		absY.maximum = info.yres;
		if (ioctl(ts_fd, EVIOCSABS(ABS_Y), &absY) == -1)
			log_write("EVIOCSABS( failed\n");
	}
}
Exemplo n.º 2
0
/* show configuration dial, return 1 to cancel installation */
int
configure( void )
{
    OBJECT *tree = rs_object;
    int quit = 0;
    int x, y, w, h, ox, oy;
    MRETS mk;
    int savelinear, saveudset, savetime, saveptime;

    if( ma_info == &start ) /* ma_info points at our start */
	ObString(OK) = (char *)(rs_frstr[INSTRING]);

/* set accel buttons */
    savelinear = ma_info->linear;
    set_accelbox( savelinear );
/* set screensave buttons */
    saveudset = ma_info->udset;
    set_screenbox( saveudset );
    savetime = (ma_info->timeout)/3600;
    sl_x( SAVEBOX, savetime, SAVE_MIN, SAVE_MAX );
    /* set modem switch */
    if( ma_info->watch ) {
	Select(MODEM);
    } else {
	Deselect(MODEM);
    }
/* set stacy options box */
    if( ma_info->stacy ) {
	ObFlags( SWITCH ) = ObFlags( LITE ) = TOUCHEXIT;
    	if( ma_info->stacmask & SH_SCREEN ) Select( SWITCH );
    	if( ma_info->stacmask & SH_LIGHT ) Select( LITE );
    } else {
	ObFlags(SWITCH) = ObFlags(LITE) = NONE;
	ObState(SWITCH) = ObState(LITE) = DISABLED; /* deselects */
    }

/* set up park box */
    Supexec((long(*)())get_parktime);
    if( parktime >= 0 ) parktime = ma_info->savepark;
    saveptime = parktime;
    if( saveptime == 0 ) saveptime = 1;
    set_parkbox();
    if( parktime >= 0 )
    	sl_x( PARKBOX, parktime, PARK_MIN, PARK_MAX );
    	

/* set appropriate icons */
    graf_handle( &x, &y, &w, &h );
    if( y < 16 ) {
    /* if char cell is < 16 pixels high, use 8 pixel icons */
	ObSpec(IACCOFF).bitblk = (BITBLK *)(rs_frimg[ACCOFF8]);
	ObSpec(IACCSLOW).bitblk = (BITBLK *)(rs_frimg[ACCSLOW8]);
	ObSpec(IACCFAST).bitblk = (BITBLK *)(rs_frimg[ACCFAST8]);
	ObSpec(ISCREEN).bitblk = (BITBLK *)(rs_frimg[SCREEN8]);
	ObSpec(SAVEUP).bitblk = (BITBLK *)(rs_frimg[TIMEHI8]);
	ObSpec(SAVEDOWN).bitblk = (BITBLK *)(rs_frimg[TIMELO8]);
	ObSpec(IMODEM).bitblk = (BITBLK *)(rs_frimg[MODEM8]);
	ObSpec(IPARK).bitblk = (BITBLK *)(rs_frimg[PARK8]);
	ObSpec(PARKUP).bitblk = (BITBLK *)(rs_frimg[TIMEHI8]);
	ObSpec(PARKDOWN).bitblk = (BITBLK *)(rs_frimg[TIMELO8]);
	ObSpec(ILITE).bitblk = (BITBLK *)(rs_frimg[LITE8]);
	ObSpec(ISWITCH).bitblk = (BITBLK *)(rs_frimg[SCREEN8]);
    }

    form_center( rs_object, &x, &y, &w, &h );
    form_dial( FMD_START, 0, 0, 0, 0, x, y, w, h );
    form_dial( FMD_GROW, 0, 0, 0, 0, x, y, w, h );
    objc_draw( tree, 0, MAX_DEPTH, x, y, w, h );
    graf_mouse( ARROW, 0L );
    do {
	switch( form_do( rs_object, 0 ) & 0x7fff ) {
	case LITE:
	    if( IsSelected(LITE) ) { /* deselecting */
	    /* don't allow user to select screensave without litesave */
	    	Deselect(SWITCH);
	    	Deselect(LITE);
	    } else {
	    	Select(LITE);
	    }
	    Objc_draw( tree, STACOPTS, MAX_DEPTH, NULL );
	    break;
	case SWITCH:
	    if( IsSelected(SWITCH) ) { /* deselecting */
	    	Deselect(SWITCH);
	    } else {
	    /* don't allow user to select screensave without litesave */
		Select(LITE);
		Select(SWITCH);
	    }
	    Objc_draw( tree, STACOPTS, MAX_DEPTH, NULL );
	    break;
	case SCREEN:
	/* floggle the bit */
	    ma_info->udset ^= 1;
	    ma_info->updown = ma_info->udset;
	    set_screenbox( ma_info->udset );
	    Objc_draw( tree, SCRNSECT, MAX_DEPTH, NULL);
	    break;
	case ACCOFF:
	    ma_info->linear = -1;
	    break;
	case ACCSLOW:
	    ma_info->linear = 1;
	    break;
	case ACCFAST:
	    ma_info->linear = 0;
	    break;
	case SAVEUP:
	    sl_arrow( SAVEBOX, SAVEUP, 1, SAVE_MIN, SAVE_MAX, &savetime );
	    break;
	case SAVEDOWN:
	    sl_arrow( SAVEBOX, SAVEDOWN, -1, SAVE_MIN, SAVE_MAX, &savetime );
	    break;
	case SAVESLID:
	    sl_drag( SAVEBOX, SAVE_MIN, SAVE_MAX, &savetime );
	    break;
	case SAVEBOX:
    	    Graf_mkstate( &mk );
    	    objc_offset( tree, SAVESLID, &ox, &oy );
    	    if( mk.x < ox )
    	    	oy = -SAVE_PAGE;
    	    else
    	        oy = SAVE_PAGE;
	    sl_arrow( SAVEBOX, -1, oy, SAVE_MIN, SAVE_MAX, &savetime );
	    break;
	case PARK:
	    if( IsSelected( PARK ) ) { /* deselecting */
		saveptime = parktime;
	    	parktime = 0;
	    } else {
	    	parktime = saveptime;
		sl_x( PARKBOX, parktime, PARK_MIN, PARK_MAX );
	    }
	    set_parkbox();
	    Objc_draw( tree, PARKSECT, MAX_DEPTH, NULL );
	    break;
	case PARKUP:
	    sl_arrow( PARKBOX, PARKUP, 1, PARK_MIN, PARK_MAX, &parktime );
	    break;
	case PARKDOWN:
	    sl_arrow( PARKBOX, PARKDOWN, -1, PARK_MIN, PARK_MAX, &parktime );
	    break;
	case PARKSLID:
	    sl_drag( PARKBOX, PARK_MIN, PARK_MAX, &parktime );
	    break;
	case PARKBOX:
    	    Graf_mkstate( &mk );
    	    objc_offset( tree, PARKSLID, &ox, &oy );
    	    if( mk.x < ox )
    	    	oy = -PARK_PAGE;
    	    else
    	        oy = PARK_PAGE;
	    sl_arrow( PARKBOX, -1, oy, PARK_MIN, PARK_MAX, &parktime );
	    break;
	case SAVE:
	    save_conf( savetime );
	    rs_object[SAVE].ob_state = NORMAL;
	    Objc_draw( tree, ROOT, MAX_DEPTH, NULL );
	    break;
	case OK:
	    quit = OK;
	    break;
	case CANCEL:
	    quit = CANCEL;
	    break;
	}
	/* delay after touchexit objects */
	wait_bup();
    } while (!quit);


    form_dial( FMD_SHRINK, 0, 0, 0, 0, x, y, w, h );
    form_dial( FMD_FINISH, 0, 0, 0, 0, x, y, w, h );

    if( quit == CANCEL ) {
	ma_info->updown = ma_info->udset = saveudset;
	ma_info->linear = savelinear;
    } else {
    	if( IsSelected(MODEM) ) ma_info->watch = 1;
    	else ma_info->watch = 0;
	if( ma_info->stacy ) {
	    if( IsSelected(SWITCH) ) {
		ma_info->stacmask |= SH_SCREEN;
	    } else {
		ma_info->stacmask &= ~SH_SCREEN;
	    }
	    if( IsSelected(LITE) ) {
		ma_info->stacmask |= SH_LIGHT;
	    } else {
		ma_info->stacmask &= ~SH_LIGHT;
	    }
	}
 
	ma_info->timeout = savetime * 3600;
	ma_info->savepark = parktime;
	Supexec((long(*)())set_ptime);
    }
    return (quit == CANCEL);
}
Exemplo n.º 3
0
static int  do_calibration(void)
{
    int i, x, y;
    int dx[6], dy[6];
    int tx[6], ty[6];
    int delta, delta_x[6], delta_y[6];
	int status=0;
    
    /* calculate the expected point */
    x = info.xres / 4;
    y = info.yres / 4;
    dx[0] = x;
    dy[0] = info.yres / 2;
    dx[1] = info.xres / 2;
    dy[1] = y;
    dx[2] = info.xres - x;
    dy[2] = info.yres - y;
    dx[3] = 400;
    dy[3] = 360;
    dx[4] = 200;
    dy[4] = 360;
    dx[5] = 600;
    dy[5] = 240;

retry:

    for (i = 0; i < 3; i ++) {
		draw_cross(dx[i], dy[i], 0);
		get_input(&tx[i], &ty[i]);
		log_write("get event: %d,%d -> %d,%d\n", tx[i], ty[i], dx[i], dy[i]);
		draw_cross(dx[i], dy[i], 1);
    }

    if( (dx[0] == 0) || (dx[1] == 0) || (dx[2] == 0) || (dy[0] == 0) || (dy[1] == 0) || (dy[2] == 0)){
    		log_write("Calibration Got ZERO Value\n");
		goto retry;
    }

    if( (dy[0] < dy[1]) && (dy[1] - dy[0] < 10)){
		log_write("Point 0 and Point 1 Get too Closed\n");
		goto retry;
    }else if( dy[0] > dx[1]){
		goto retry;
    }

    if( (dy[1] < dy[2]) && (dy[2] - dy[1] < 10))
		goto retry;
    else if( dy[1] > dy[2])
		goto retry;

    /* check ok, calulate the result */
    delta = (tx[0] - tx[2]) * (ty[1] - ty[2])
                - (tx[1] - tx[2]) * (ty[0] - ty[2]);
    delta_x[0] = (dx[0] - dx[2]) * (ty[1] - ty[2])
                - (dx[1] - dx[2]) * (ty[0] - ty[2]);
    delta_x[1] = (tx[0] - tx[2]) * (dx[1] - dx[2])
                - (tx[1] - tx[2]) * (dx[0] - dx[2]);
    delta_x[2] = dx[0] * (tx[1] * ty[2] - tx[2] * ty[1]) -
                dx[1] * (tx[0] * ty[2] - tx[2] * ty[0]) +
                dx[2] * (tx[0] * ty[1] - tx[1] * ty[0]);
    delta_y[0] = (dy[0] - dy[2]) * (ty[1] - ty[2])
                - (dy[1] - dy[2]) * (ty[0] - ty[2]);
    delta_y[1] = (tx[0] - tx[2]) * (dy[1] - dy[2])
                - (tx[1] - tx[2]) * (dy[0] - dy[2]);
    delta_y[2] = dy[0] * (tx[1] * ty[2] - tx[2] * ty[1]) -
                dy[1] * (tx[0] * ty[2] - tx[2] * ty[0]) +
                dy[2] * (tx[0] * ty[1] - tx[1] * ty[0]);

    cal_val[0] = delta_x[0];
    cal_val[1] = delta_x[1];
    cal_val[2] = delta_x[2];
    cal_val[3] = delta_y[0];
    cal_val[4] = delta_y[1];
    cal_val[5] = delta_y[2];
    cal_val[6] = delta;
    
    for (i = 3; i < 6; i ++) {
	draw_cross(dx[i], dy[i], 0);
	get_input(&tx[i], &ty[i]);
	get_calibration_value(&tx[i],&ty[i]);
	if(tx[i] >= dx[i] )
		status = (tx[i] - dx[i] > status) ? tx[i] - dx[i]: status;
	else if(dx[i] > tx[i] ){
		status = (dx[i] - tx[i] > status) ? dx[i] - tx[i]: status;
	}

	if(ty[i] >= dy[i] )
		status = (ty[i] - dy[i] > status) ? ty[i] - dy[i]: status;
	else if(dy[i] > ty[i] ){
		status = (dy[i] - ty[i] > status) ? dy[i] - ty[i]: status;
	}
	log_write("get event: %d,%d -> %d,%d  status=%d\n", tx[i], ty[i], dx[i], dy[i],status);
	draw_cross(dx[i], dy[i], 1);
    }

	if(status > DIFF_VALUE){
		return status;
	}
	save_conf(cal_val);
    write_conf(cal_val);	
	return 0;
}