From ee3139d283219484d32f779a79310ae3b491f901 Mon Sep 17 00:00:00 2001 From: Simen Svale Skogsrud Date: Wed, 1 Jun 2011 09:36:15 +0200 Subject: [PATCH] changed serialAvailable to serialAnyAvailable which does not calculate the number of bytes, only if there are any at all --- serial.c | 37 ++++--------------------------------- serial.h | 2 +- 2 files changed, 5 insertions(+), 34 deletions(-) diff --git a/serial.c b/serial.c index c10d4ad..6c5fdcb 100644 --- a/serial.c +++ b/serial.c @@ -116,15 +116,16 @@ SIGNAL(USART_UDRE_vect) { 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() { // 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; } else { unsigned char c = rx_buffer[rx_buffer_tail]; @@ -227,33 +228,3 @@ void printFloat(double n) 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); -} -*/ diff --git a/serial.h b/serial.h index ac64387..8b528ac 100644 --- a/serial.h +++ b/serial.h @@ -27,7 +27,7 @@ void beginSerial(long); void serialWrite(unsigned char); -int serialAvailable(void); +int serialAnyAvailable(void); int serialRead(void); void serialFlush(void); void printMode(int);