Beispiel #1
0
Errcode wac_detect(Idriver *idr)
/*-----------------------------------------------------------------------
 * See if the input device is attatched.   Return Success (0) if
 * so,  otherwise a negative error code.  (see errcodes.h).
 *----------------------------------------------------------------------*/
{
    Errcode err;

    if ((err = init_wacom(idr)) < Success)
	return(err);
    /* flush any garbage left at comm port from last time... */
    flush_comm(idr->comm_port);
    return(wac_input(idr));
}
Beispiel #2
0
void termios_test_entry(void *p)
{
    int len = 0;
    int fd = -1;
    unsigned char *pBuf = RT_NULL;
    struct termios_test_s *pTerm = (struct termios_test_s *)p;

    if((fd = open_comm(pTerm->dev)) == -1)
    {
        rt_kprintf("Check the device name...\n");
        return;
    }

    pBuf = (unsigned char *)rt_malloc(BUFFER_SIZE);
    RT_ASSERT(pBuf != RT_NULL);

    memset(pBuf, 0x00, BUFFER_SIZE);

    config_comm(fd, pTerm->baud_rate, Default_parity, 8, 1);

    flush_comm(fd);

    rt_kprintf("Block recv 10 bytes.\n");
    /* Block recv 10 bytes */
    len = recv_comm(fd, pBuf, 10, RT_NULL);

    rt_kprintf("Recv:%s\n", pBuf);

    send_comm(fd, pBuf, len);
    rt_kprintf("Termios test exit.\n");

    close_comm(fd);

    rt_free(pBuf);
    pBuf = RT_NULL;
}
Beispiel #3
0
Errcode wac_input(Idriver *idr)
/*-----------------------------------------------------------------------
 * AniPro calls this to ask for the current mouse/tablet position,
 * button state, etc.
 *----------------------------------------------------------------------*/
{
    static char wlinebuf[7];
    char *s;
    union abcd_regs r;
    int stype;
    int dp;
    static int ux = 1024, uy = 512, temp = 0;
    static int ux_save = 1024, uy_save = 512, temp_save = 0;
    SHORT port = idr->comm_port;
    int i;


request_input:

    s = wlinebuf;

    /*	request 7-byte input */
    if (!string_to_tablet(port, "RQ1\n"))
    {
	return(Err_timeout);
    }

    /*	attempt to receive the header byte (it has it's MSB set) */
    do {

	/*  receive bytes */
	r.w.dx = port;
	r.b.ah = 2;
	jcomm(&r);
	if ((r.b.ah & 0x80) !=	0) {
	    return(Err_timeout);
	}

    /* until a header byte is received */
    } while (!(r.b.al & 0x80));

    /*	point 's' to the sample buffer */
    s = wlinebuf;

    /*	save header byte */
    *s++ = r.b.al;

    /*	get rest of bytes */
    for (i = 0; i < 6; i++) {

	/*  receive bytes */
	r.w.dx = port;
	r.b.ah = 2;
	jcomm(&r);
	if ((r.b.ah & 0x80) !=	0) {
	    return(Err_timeout);
	}

	/*  if a header byte is detected, then go back and request again */
	if (r.b.al & 0x80) {
	    goto request_input;
	}

	/*  put the in the sample buffer */
	*s++ = r.b.al;
    }

    s = wlinebuf;

    switch (*s & WAC_PSTYLUS) {
    case 0:
	stype = PUCK;
	break;
    case WAC_STYLUS:
	stype = STYLUS;
	break;
    case WAC_PSTYLUS:
	stype = PSTYLUS;
	break;
    default:
	flush_comm(port);
	return(Err_version);
    }


    /*	if pointing device is inside the tablet */
    if (*s & WAC_INSIDE) {

	/*  compute x-value and scale and clamp it */

	ux = ((wlinebuf[0] & 3) << 14) + (wlinebuf[1] << 7) + wlinebuf[2];
	ux -= 120;

	uy = ((wlinebuf[3] & 3) << 14) + (wlinebuf[4] << 7) + wlinebuf[5];
	uy -= 120;

	/*  get pressure/button field */

	temp = wlinebuf[6];

	ux_save = ux;
	uy_save = uy;
	temp_save = temp;

    } else {

	/*  pointing device is not inside the tablet, use last good value */

	ux = ux_save;
	uy = uy_save;
	temp = temp_save;

    }



    switch (stype)
    {
    case PSTYLUS:

	/*  temp is a 7-bit signed pressure value */
	if (temp & 0x40) {		/* extend sign bit if necessary */
	    temp |= 0xffffff80;
	}

	idr->buttons = 0;
	wac_pos[2] = 0;

	if (temp > -99 && temp < 99)  /* filter to reasonable values */
	{
	    wac_pos[0] = ux;
	    wac_pos[1] = uy;
	    if (temp < pmin)
		pmin = temp;
	    if (temp > pmax)
		pmax = temp;
	    dp = pmax-(pmin+PTHRESH);
	    temp -= pmin+PTHRESH;
	    if (temp > 0)
	    {
		wac_pos[2] = temp*PMAX/dp;
		idr->buttons = 1;
	    }
	}

	/* check for control key to interpret a right click
		(Arr, no side button on pressure sensitive stylus!) */
	if (jkey_shift() & 0x4)       /* right button on control key */
	    idr->buttons |= 0x2;
	break;

    case STYLUS:

	wac_pos[0] = ux;
	wac_pos[1] = uy;
	idr->buttons = temp & 0x03;
	break;

    case PUCK:
	wac_pos[0] = ux;
	wac_pos[1] = uy;
	/* left and top buttons are left mouse button, others are right
	   mouse button */
	idr->buttons = 0;
	temp &= WAC_BUTTONMASK;
	if (temp == 1 || temp == 2) {
	    idr->buttons |= 1;
	} else if (temp == 3 || temp == 4) {
	    idr->buttons |= 2;
	}
	break;
    }
    return(Success);
}