changed serialAvailable to serialAnyAvailable which does not calculate the number of bytes, only if there are any at all
This commit is contained in:
parent
defabc80ed
commit
ee3139d283
37
serial.c
37
serial.c
@ -116,15 +116,16 @@ SIGNAL(USART_UDRE_vect) {
|
|||||||
tx_buffer_tail = tail;
|
tx_buffer_tail = tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
int serialAvailable()
|
// Returns true if there is any data in the read buffer
|
||||||
|
int serialAnyAvailable()
|
||||||
{
|
{
|
||||||
return (RX_BUFFER_SIZE + rx_buffer_head - rx_buffer_tail) % RX_BUFFER_SIZE;
|
return (rx_buffer_head != rx_buffer_tail);
|
||||||
}
|
}
|
||||||
|
|
||||||
int serialRead()
|
int serialRead()
|
||||||
{
|
{
|
||||||
// if the head isn't ahead of the tail, we don't have any characters
|
// if the head isn't ahead of the tail, we don't have any characters
|
||||||
if (rx_buffer_head == rx_buffer_tail) {
|
if (serialAnyAvailable()) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
unsigned char c = rx_buffer[rx_buffer_tail];
|
unsigned char c = rx_buffer[rx_buffer_tail];
|
||||||
@ -227,33 +228,3 @@ void printFloat(double n)
|
|||||||
printInteger(round(fractional_part*1000));
|
printInteger(round(fractional_part*1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
// void printHex(unsigned long n)
|
|
||||||
// {
|
|
||||||
// printIntegerInBase(n, 16);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// void printOctal(unsigned long n)
|
|
||||||
// {
|
|
||||||
// printIntegerInBase(n, 8);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// void printBinary(unsigned long n)
|
|
||||||
// {
|
|
||||||
// printIntegerInBase(n, 2);
|
|
||||||
// }
|
|
||||||
|
|
||||||
/* Including print() adds approximately 1500 bytes to the binary size,
|
|
||||||
* so we replace it with the smaller and less-confusing printString(),
|
|
||||||
* printInteger(), etc.
|
|
||||||
void print(const char *format, ...)
|
|
||||||
{
|
|
||||||
char buf[256];
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, format);
|
|
||||||
vsnprintf(buf, 256, format, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
printString(buf);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
2
serial.h
2
serial.h
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
void beginSerial(long);
|
void beginSerial(long);
|
||||||
void serialWrite(unsigned char);
|
void serialWrite(unsigned char);
|
||||||
int serialAvailable(void);
|
int serialAnyAvailable(void);
|
||||||
int serialRead(void);
|
int serialRead(void);
|
||||||
void serialFlush(void);
|
void serialFlush(void);
|
||||||
void printMode(int);
|
void printMode(int);
|
||||||
|
Loading…
Reference in New Issue
Block a user