Beispiel #1
0
/**********************************************************************
 * serial_read (int read_timeout)
 *
 * return data one byte at a time
 *
 * read_timeout - serial timeout (in milliseconds)
 *
 * returns 0 on success, -1 on error, -2 on timeout
 *
 **********************************************************************/
int serial_read (int read_timeout, u_char *readbuf)
{
	static u_char cache[512];
	static u_char *cachep = cache;
	static u_char *cachee = cache;
	int recv;
	*readbuf = '\0';

	/* if still data in cache, get it */
	if (cachep < cachee) {
		*readbuf = *cachep++;
		return 0;
		/* return (int) *cachep++; */
	}
	recv = char_read ((char *)cache, 1, read_timeout);

	if ((recv == -1) || (recv == -2))
		return recv;

	cachep = cache;
	cachee = cache + recv;
	cachep = cache;
	cachee = cache + recv;

	if (recv) {
		upsdebugx(5,"received: %02x", *cachep);
		*readbuf = *cachep++;
		return 0;
	}
	return -1;
}
Beispiel #2
0
size_t	my_read(char buf[], size_t size)
{
	char			read_char[5] = {0};
	int				len;

	if ((data = ft_initdata(buf)) == NULL)
		return (0);
	while (!(*(unsigned int *)read_char == KEY_ENTRY) && data->i < size \
		&& !shell->exit && !data->exit_cmd)
	{
		ft_bzero(read_char, 5);
		char_read(shell->fdy, read_char, 4);
		if (!ft_isonekey(read_char))
			ft_makebuf(*read_char, buf, data);
		else
			ft_checkkey(read_char, buf, data);
	}
	if (data->exit_cmd)
	{
		data->len = 0;
		ft_bzero(buf, BUF_SIZE);
	}
	else
		ft_addtohistorique(buf, data->len);
	len = data->len;
	free(data);
	return (len);
}
Beispiel #3
0
void LCD_PrintCharXY(unsigned int x, unsigned int y, u32 c)
{
    u8 row, col, width;
    u8 font[CHAR_BUF_SIZE];
    const u8 *offset;
    offset = font;
    char_read(font, c, &width);
    if (! offset || ! width) {
        printf("Could not locate character U-%04x\n", (int)c);
        return;
    }
    // Check if the requested character is available
    LCD_DrawStart(x, y, x + width - 1,  y + get_height() - 1, DRAW_NWSE);
    for (col = 0; col < width; col++)
    {
        const u8 *data = offset++;
        u8 bit = 0;
        // Data is right aligned,adrawn top to bottom
        for (row = 0; row < get_height(); ++row)
        {
            if (bit == 8) {
                data = offset++;
                bit = 0;
            }
            if (*data & (1 << bit)) {
                LCD_DrawPixelXY(x + col, y + row, cur_str.color);
            }
            bit++;
        }
    }
    LCD_DrawStop();
}
Beispiel #4
0
int hypcnread(int dev, io_req_t ior)
{
	struct tty *tp = &hypcn_tty;
	tp->t_state |= TS_CARR_ON;
	return char_read(tp, ior);
}
Beispiel #5
0
bool IVCONV::stlb_read ( FILE *filein )

/******************************************************************************/

/*
Purpose:

STLB_READ reads a binary STL (stereolithography) file.

Example:

80 byte string = header containing nothing in particular

4 byte int = number of faces

For each face:

3 4-byte floats = components of normal vector to face;
3 4-byte floats = coordinates of first node;
3 4-byte floats = coordinates of second node;
3 4-byte floats = coordinates of third and final node;
2-byte int = attribute, whose value is 0.

Modified:

24 May 1999

Author:

John Burkardt
*/
{
	short int attribute = 0;
	char c;
	float cvec[3];
	int icor3;
	int i;
	int iface;
	int ivert;
	/* 
	80 byte Header.
	*/
	for ( i = 0; i < 80; ++i ) {
		c = char_read ( filein );
		if ( debug ) {
			printf ( "%d\n", c );
		}
		bytes_num = bytes_num + 1;
	}
	/*
	Number of faces.
	*/
	face_num = long_int_read ( filein );
	bytes_num = bytes_num + 4;
	/*
	For each (triangular) face,
    components of normal vector,
    coordinates of three vertices,
    2 byte "attribute".
	*/
	for ( iface = 0; iface < face_num; iface++ ) {
		
		face_order[iface] = 3;
		face_material[iface] = 0;
		
		for ( i = 0; i < 3; ++i ) {
			face_normal[iface][i] = float_read ( filein );
			bytes_num = bytes_num + 4;
		}
		
		for ( ivert = 0; ivert < face_order[iface]; ivert++ ) {
			
			for ( i = 0; i < 3; ++i ) {
				cvec[i] = float_read ( filein );
				bytes_num = bytes_num + 4;
			}
			
			if ( cor3_num < 1000 ) {
				icor3 = rcol_find ( cor3, cor3_num, cvec );
			}
			else {
				icor3 = -1;
			}
			
			if ( icor3 == -1 ) {
				icor3 = cor3_num;
//				if ( cor3_num < COR3_MAX ) 
				{
					cor3[cor3_num] = cvec;
//					cor3[cor3_num][1] = cvec[1];
//					cor3[cor3_num][2] = cvec[2];
				}
				cor3_num = cor3_num + 1;
			}
			else {
				dup_num = dup_num + 1;
			}
			
			face[ivert][iface] = icor3;
			
		}
		attribute = short_int_read ( filein );
		if ( debug ) {
			printf ( "ATTRIBUTE = %d\n", attribute );
		}
		bytes_num = bytes_num + 2;
	}
	
	return true;
}