Beispiel #1
0
static void
EvdevPtrMotion(KdPointerInfo * pi, struct input_event *ev)
{
    Kevdev *ke = pi->driverPrivate;
    int i;
    int flags = KD_MOUSE_DELTA | pi->buttonState;

    for (i = 0; i <= ke->max_rel; i++)
        if (ke->rel[i]) {
            int a;

            for (a = 0; a <= ke->max_rel; a++) {
                if (ISBITSET(ke->relbits, a)) {
                    if (a == 0)
                        KdEnqueuePointerEvent(pi, flags, ke->rel[a], 0, 0);
                    else if (a == 1)
                        KdEnqueuePointerEvent(pi, flags, 0, ke->rel[a], 0);
                }
                ke->rel[a] = 0;
            }
            break;
        }
    for (i = 0; i < ke->max_abs; i++)
        if (ke->abs[i] != ke->prevabs[i]) {
            int a;

            ErrorF("abs");
            for (a = 0; a <= ke->max_abs; a++) {
                if (ISBITSET(ke->absbits, a))
                    ErrorF(" %d=%d", a, ke->abs[a]);
                ke->prevabs[a] = ke->abs[a];
            }
            ErrorF("\n");
            break;
        }

    if (ev->code == REL_WHEEL) {
        for (i = 0; i < abs(ev->value); i++) {
            if (ev->value > 0)
                flags |= KD_BUTTON_4;
            else
                flags |= KD_BUTTON_5;

            KdEnqueuePointerEvent(pi, flags, 0, 0, 0);

            if (ev->value > 0)
                flags &= ~KD_BUTTON_4;
            else
                flags &= ~KD_BUTTON_5;

            KdEnqueuePointerEvent(pi, flags, 0, 0, 0);
        }
    }

}
int updateSensorRecordFromSSRAESC(const void *record) {

	sensorRES_t *pRec = (sensorRES_t *) record;
	uint8_t stype;
	int index, i=0;

	stype = find_sensor(pRec->sensor_number);

	// 0xC3 types use the assertion7_0 for the value to be set
	// so skip the reseach and call the correct event reporting
	// function
	if (stype == 0xC3) {

		shouldReport(stype, 0x00, &index);
		reportSensorEventAssert(pRec, index);

	} else {
		// Scroll through each bit position .  Determine
		// if any bit is either asserted or Deasserted.
		for(i=0;i<8;i++) {

			if ((ISBITSET(pRec->assert_state7_0,i))  &&
				(shouldReport(stype, i, &index)))
			{
				reportSensorEventAssert(pRec, index);
			}
			if ((ISBITSET(pRec->assert_state14_8,i))  &&
				(shouldReport(stype, i+8, &index)))
			{
				reportSensorEventAssert(pRec, index);
			}
			if ((ISBITSET(pRec->deassert_state7_0,i))  &&
				(shouldReport(stype, i, &index)))
			{
				reportSensorEventDeassert(pRec, index);
			}
			if ((ISBITSET(pRec->deassert_state14_8,i))  &&
				(shouldReport(stype, i+8, &index)))
			{
				reportSensorEventDeassert(pRec, index);
			}
		}

	}


	return 0;
}
/* validate a ArcaBook FAST message for multicast */
static int32_t ABFastValidate(const uint8_t *src, int32_t srcLen,
                              uint8_t *pmap, int32_t * pPmapLen)
{
    int32_t iOffset = 0;          /* offset within src of current position   */
    /* int32_t pPmapLen;             length of pmap */

    /* Duplicate of a check made before we come here
    if(srcLen < AB_MIN_FAST_MSG)
        return AB_INCOMPLETE_ERROR; */

    /* decode the pmap
	pPmapLen = PmapLen(src,AB_MAX_PMAP);
	memcpy(pmap,src,pPmapLen);    */
	* pPmapLen = copyPmap( pmap, src, AB_MAX_PMAP );
	iOffset += * pPmapLen;

	/* Make sure pmap is valid with a stop bit */
	if( (* pPmapLen < 1) || (pmap[* pPmapLen - 1] < 0x80) )
		return AB_INVALID_HEADER;

	/* pmap must always have field 0, TYPE   */
	if(!ISBITSET(pmap,AB_MSG_TYPE))
		return AB_INVALID_HEADER;

	return AB_OK;   
}
/* Decode an ASCII string and put the result in *data 
 *
 * field	The field ID we are decoding, ( AB_MSG_TYPE, etc.)
 * buf		The buffer containing the FAST message
 * len		Pointer to the length of buf, on return this will hold the number of bytes processed
 * data		This will hold the result
 * pState	Pointer to the FAST state information for the applicable field
 * pmap		The FAST pmap
 */
static int32_t DecodeASCII ( const uint8_t *buf, int32_t *len, char *data,
                             FAST_STATE *pState, const uint8_t *pmap)
{
	int32_t iSize;

	/* Check the state structure to see if we have an encoded value */
	if(!ISBITSET(pmap,pState ->field))
	{
		if(pState ->valid)
		{
			if(pState ->encodeType == OP_COPY)
				memcpy(data,pState ->value.int8Val,pState ->size);
			else
				return AB_INVALID_STATE;
		}
		else
			return AB_INVALID_STATE;

		*len = 0;
		return AB_OK;
	}

	/* move over the string, all but the last byte */
	iSize = 0;
	while(*len > iSize && buf[iSize] < 0x80)
	{
		data[iSize] = buf [iSize];
		iSize++;
	}

	/* clear the high bit and move over the last byte  */
	if(*len > iSize)
	{
		data[iSize] =  (buf [iSize] & 0x7f);
		iSize++;
	}
	else
	   return AB_INCOMPLETE_ERROR;

	/* See if we need to save this value for encoding */
	if(pState ->encodeType == OP_COPY)
	{
		/* If the string is too long, we can not copy encode it */
		if(iSize <= AB_MAX_STRLEN)
		{
			pState ->valid = 1; 
			memcpy(pState ->value.int8Val,data,iSize);
			pState ->size = iSize;
		}
		else
			pState ->valid = 0; 
	}

	*len = iSize;
	return AB_OK;   
}
/* Decode a signed 32-bit integer and place the result in *data 
 * 
 * buf		The buffer containing the FAST message
 * len		Pointer to the length of buf, on return this will hold
 *          the number of bytes processed
 * data		This will hold the result, in NETWORK byte order
 * pState	Pointer to the FAST state information for the applicable field
 * pmap		The FAST pmap
 * 
 */
static int32_t DecodeI32 ( const uint8_t *buf, int32_t *len, int32_t *data,
                           FAST_STATE *pState, const uint8_t *pmap)
{
	int32_t iSize;

	/* Check the state structure to see if we have an encoded value */
	if(!ISBITSET(pmap, pState ->field))
	{
		// See if this field is valid in the state
		if(pState ->valid)
		{
			if( pState ->encodeType == OP_INCR)
				pState ->value.uint32Val++;
			else if(pState ->encodeType == OP_COPY)
				;
			else
				return AB_INVALID_STATE;

			*data = htonl ( pState ->value.uint32Val );
		}
		else
        {
			return AB_INVALID_STATE;
        }
		*len = 0;
		return AB_OK;
	}

	/* convert the number, move over all but the last byte */
	*data = 0;
	iSize = 0;
	while(*len > iSize  && buf[iSize] < 0x80)
	   *data = (*data << 7) | buf [iSize++];

	/* clear the high bit and move over the last byte */
	if(iSize < *len)
		*data = (*data << 7) | (buf [iSize++] & 0x7f);
	else
		return AB_INCOMPLETE_ERROR;

	/* See if we need to save this value for encoding */
	if(pState ->encodeType == OP_COPY || pState ->encodeType == OP_INCR)
	{
		pState ->valid = 1; 
		pState ->value.uint32Val = *data;
		pState ->size = sizeof(pState ->value.uint32Val);
	}

    *data = htonl ( *data );
	*len = iSize;
	return AB_OK;   
}
Beispiel #6
0
int16_t qssp::sf_ReceivePacket()
{
    int16_t value = FALSE;

    if( ISBITSET(thisport->rxBuf[SEQNUM], ACK_BIT ) ) {
        //  Received an ACK packet, need to check if it matches the previous sent packet
        if( ( thisport->rxBuf[SEQNUM] & 0x7F) == (thisport->txSeqNo & 0x7f)) {
            //  It matches the last packet sent by us
            SETBIT( thisport->txSeqNo, ACK_BIT );
            thisport->SendState = SSP_ACKED;
            value = FALSE;
             if (debug)
                qDebug()<<"Received ACK:"<<(thisport->txSeqNo & 0x7F);
        }
        // else ignore the ACK packet
    } else {
        //  Received a 'data' packet, figure out what type of packet we received...
        if( thisport->rxBuf[SEQNUM] == 0 ) {
             if (debug)
                qDebug()<<"Received SYNC Request";
            // Synchronize sequence number with host
#ifdef ACTIVE_SYNCH
            thisport->sendSynch = TRUE;
#endif
            sf_SendAckPacket(thisport->rxBuf[SEQNUM] );
            thisport->rxSeqNo = 0;
            value = FALSE;
        } else if( thisport->rxBuf[SEQNUM] == thisport->rxSeqNo ) {
            // Already seen this packet, just ack it, don't act on the packet.
            sf_SendAckPacket(thisport->rxBuf[SEQNUM] );
            value = FALSE;
        } else {
            //New Packet
            thisport->rxSeqNo = thisport->rxBuf[SEQNUM];
            // Let the application do something with the data/packet.

            // skip the first two bytes (length and seq. no.) in the buffer.
             if (debug)
                qDebug()<<"Received DATA PACKET seq="<<thisport->rxSeqNo<<"Data="<<(uint8_t)thisport->rxBuf[2]<<(uint8_t)thisport->rxBuf[3]<<(uint8_t)thisport->rxBuf[4];
            pfCallBack( &(thisport->rxBuf[2]), thisport->rxBufLen);

            // after we send the ACK, it is possible for the host to send a new packet.
            // Thus the application needs to copy the data and reset the receive buffer
            // inside of thisport->pfCallBack()
            sf_SendAckPacket(thisport->rxBuf[SEQNUM] );
            value = TRUE;
        }
    }
    return value;
}
Beispiel #7
0
void APU::Channel4Callback(Uint8* pStream, int length)
{
    SDL_memset(pStream, 0x00, length);

    if (!ISBITSET(m_SoundOnOff, 7))
        return;

    /*int v = 0;
    for (int index = 0; index < length; index++)
    {
        pStream[index] = (Uint8)(0xFF * std::sin(v * 2 * M_PI / 44100));
        v += 600;
    }*/
}
Beispiel #8
0
long long sumPrimes(int n) {
    char b[n/8+1];//250001
    long long i, p;
    long long s = 0;
memset(b, 255, sizeof(b)); //b,11111111,250001

    for (p=2; p<n; p++) {
        if (ISBITSET(b,p)) {
            //printf("%d\n", p);
            s += p;
            for (i=p*p; i<n; i+=p) {
                CLEARBIT(b, i); 
            }
        }
    }
    return s; 
}
/* Decode a BitMap and put the result in *data 
 *
 * field	The field ID we are decoding, ( AB_MSG_TYPE, etc.)
 * buf		The buffer containing the FAST message
 * len		Pointer to the length of buf, on return this will hold the number of bytes processed
 * data		This will hold the result
 * state	The FAST state information
 * pmap		The FAST pmap
 */
static int32_t DecodeBitmap (uint32_t field, const uint8_t *buf, int32_t *len, uint8_t *data, const uint8_t *pmap)
{
	int32_t iSize;
	int32_t j;
	int32_t bit=0; 

	/* We never encode this type, so just return OK */
	if(!ISBITSET(pmap,field))
	{
		*len = 0;
		return AB_OK;   
	}

	/* move over the bytes, 7-bits at a time */
	iSize = 0;
	while(*len > iSize)
	{
		data[iSize] = 0;
		for(j=0;j<8;j++)
		{
			bit = (8*iSize)+j;

			/* is this bit set in the FAST field ? */
			if(ISBITSET(buf,bit))
				data[iSize] |= (0x80 >> bit % 8);
		}

		iSize++;

		/* we are done once we hit the stop bit */
		if(buf[bit / 7] >= 0x80)
			break;
	}

	/* Did we have enough room ?  */
	if(*len <= iSize)
	   return AB_INCOMPLETE_ERROR;  

	*len = bit / 7 + 1;
	return AB_OK;   
}
Beispiel #10
0
static Status
EvdevPtrEnable(KdPointerInfo * pi)
{
    int fd;
    unsigned long ev[NBITS(EV_MAX)];
    Kevdev *ke;

    if (!pi || !pi->path)
        return BadImplementation;

    fd = open(pi->path, 2);
    if (fd < 0)
        return BadMatch;

    if (ioctl(fd, EVIOCGRAB, 1) < 0)
        perror("Grabbing evdev mouse device failed");

    if (ioctl(fd, EVIOCGBIT(0 /*EV*/, sizeof(ev)), ev) < 0) {
        perror("EVIOCGBIT 0");
        close(fd);
        return BadMatch;
    }
    ke = calloc(1, sizeof(Kevdev));
    if (!ke) {
        close(fd);
        return BadAlloc;
    }
    if (ISBITSET(ev, EV_KEY)) {
        if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(ke->keybits)), ke->keybits) < 0) {
            perror("EVIOCGBIT EV_KEY");
            free(ke);
            close(fd);
            return BadMatch;
        }
    }
    if (ISBITSET(ev, EV_REL)) {
        if (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(ke->relbits)), ke->relbits) < 0) {
            perror("EVIOCGBIT EV_REL");
            free(ke);
            close(fd);
            return BadMatch;
        }
        for (ke->max_rel = REL_MAX; ke->max_rel >= 0; ke->max_rel--)
            if (ISBITSET(ke->relbits, ke->max_rel))
                break;
    }
    if (ISBITSET(ev, EV_ABS)) {
        int i;

        if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(ke->absbits)), ke->absbits) < 0) {
            perror("EVIOCGBIT EV_ABS");
            free(ke);
            close(fd);
            return BadMatch;
        }
        for (ke->max_abs = ABS_MAX; ke->max_abs >= 0; ke->max_abs--)
            if (ISBITSET(ke->absbits, ke->max_abs))
                break;
        for (i = 0; i <= ke->max_abs; i++) {
            if (ISBITSET(ke->absbits, i))
                if (ioctl(fd, EVIOCGABS(i), &ke->absinfo[i]) < 0) {
                    perror("EVIOCGABS");
                    break;
                }
            ke->prevabs[i] = ABS_UNSET;
        }
        if (i <= ke->max_abs) {
            free(ke);
            close(fd);
            return BadValue;
        }
    }
    if (!KdRegisterFd(fd, EvdevPtrRead, pi)) {
        free(ke);
        close(fd);
        return BadAlloc;
    }
    pi->driverPrivate = ke;
    ke->fd = fd;

    return Success;
}
Beispiel #11
0
static Bool
EvdevKbdInit (void)
{
    int         i;
    int         fd;
    int         n = 0;
    char        name[100];

    if (!EvdevInputType)
        EvdevInputType = KdAllocInputType ();

    for (i = 0; i < NUM_DEFAULT_EVDEV; i++)
    {
        fd = open (kdefaultEvdev1[i], 2);
        if (fd >= 0)
        {
            ioctl(fd, EVIOCGRAB, 1);

            ioctl(fd, EVIOCGNAME(sizeof(name)), name);
            ErrorF("Name is %s\n", name);
            ioctl(fd, EVIOCGPHYS(sizeof(name)), name);
            ErrorF("Phys Loc is %s\n", name);
            ioctl(fd, EVIOCGUNIQ(sizeof(name)), name);
            ErrorF("Unique is %s\n", name);

        }

        if (fd >= 0)
        {
            unsigned long   ev[NBITS(EV_MAX)];
            Kevdev          *ke;

            if (ioctl (fd, EVIOCGBIT(0 /*EV*/, sizeof (ev)), ev) < 0)
            {
                perror ("EVIOCGBIT 0");
                close (fd);
                continue;
            }
            ke = xalloc (sizeof (Kevdev));
            if (!ke)
            {
                close (fd);
                continue;
            }
            memset (ke, '\0', sizeof (Kevdev));
            if (ISBITSET (ev, EV_KEY))
            {
                if (ioctl (fd, EVIOCGBIT (EV_KEY, sizeof (ke->keybits)),
                           ke->keybits) < 0)
                {
                    perror ("EVIOCGBIT EV_KEY");
                    xfree (ke);
                    close (fd);
                    continue;
                }
            }
            if (ISBITSET (ev, EV_REL))
            {
                if (ioctl (fd, EVIOCGBIT (EV_REL, sizeof (ke->relbits)),
                           ke->relbits) < 0)
                {
                    perror ("EVIOCGBIT EV_REL");
                    xfree (ke);
                    close (fd);
                    continue;
                }
                for (ke->max_rel = REL_MAX; ke->max_rel >= 0; ke->max_rel--)
                    if (ISBITSET(ke->relbits, ke->max_rel))
                        break;
            }
            if (ISBITSET (ev, EV_ABS))
            {
                int i;

                if (ioctl (fd, EVIOCGBIT (EV_ABS, sizeof (ke->absbits)),
                           ke->absbits) < 0)
                {
                    perror ("EVIOCGBIT EV_ABS");
                    xfree (ke);
                    close (fd);
                    continue;
                }
                for (ke->max_abs = ABS_MAX; ke->max_abs >= 0; ke->max_abs--)
                    if (ISBITSET(ke->absbits, ke->max_abs))
                        break;
                for (i = 0; i <= ke->max_abs; i++)
                {
                    if (ISBITSET (ke->absbits, i))
                        if (ioctl (fd, EVIOCGABS(i), &ke->absinfo[i]) < 0)
                        {
                            perror ("EVIOCGABS");
                            break;
                        }
                    ke->prevabs[i] = ABS_UNSET;
                }
                if (i <= ke->max_abs)
                {
                    xfree (ke);
                    close (fd);
                    continue;
                }
            }
            if (KdRegisterFd (EvdevInputType, fd, EvdevRead1, NULL))
                n++;
        }
    }
    return TRUE;
}