From 2832e8e0a8be2085340121d0e4acd98021c28226 Mon Sep 17 00:00:00 2001 From: Mikal Hart Date: Thu, 17 Feb 2011 23:55:38 -0600 Subject: [PATCH] A modification of [New]SoftSerial to meet certain requests David Mellis asked about in preparation for integration into core: 1. Remove notion of library version 2. Remove little used "enable_timer0" method. 3. Rename is_listening to isListening i :insert : :set showmode --- libraries/SoftwareSerial/SoftwareSerial.cpp | 29 +++------------------ libraries/SoftwareSerial/SoftwareSerial.h | 5 +--- libraries/SoftwareSerial/icrmacros.h | 2 +- libraries/SoftwareSerial/keywords.txt | 4 +-- 4 files changed, 7 insertions(+), 33 deletions(-) diff --git a/libraries/SoftwareSerial/SoftwareSerial.cpp b/libraries/SoftwareSerial/SoftwareSerial.cpp index 926482673..d67fd9eba 100755 --- a/libraries/SoftwareSerial/SoftwareSerial.cpp +++ b/libraries/SoftwareSerial/SoftwareSerial.cpp @@ -421,7 +421,7 @@ void SoftwareSerial::end() // Read data from buffer int SoftwareSerial::read() { - if (!is_listening()) + if (!isListening()) return -1; // Empty buffer? @@ -436,7 +436,7 @@ int SoftwareSerial::read() int SoftwareSerial::available() { - if (!is_listening()) + if (!isListening()) return 0; return (_receive_buffer_tail + _SS_MAX_RX_BUFF - _receive_buffer_head) % _SS_MAX_RX_BUFF; @@ -488,30 +488,9 @@ void SoftwareSerial::write(uint8_t b) tunedDelay(_tx_delay); } -#if !defined(cbi) -#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) -#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) -#endif - -void SoftwareSerial::enable_timer0(bool enable) -{ - if (enable) -#if defined(__AVR_ATmega8__) - sbi(TIMSK, TOIE0); -#else - sbi(TIMSK0, TOIE0); -#endif - else -#if defined(__AVR_ATmega8__) - cbi(TIMSK, TOIE0); -#else - cbi(TIMSK0, TOIE0); -#endif -} - void SoftwareSerial::flush() { - if (!is_listening()) + if (!isListening()) return; uint8_t oldSREG = SREG; @@ -522,7 +501,7 @@ void SoftwareSerial::flush() int SoftwareSerial::peek() { - if (!is_listening()) + if (!isListening()) return -1; // Empty buffer? diff --git a/libraries/SoftwareSerial/SoftwareSerial.h b/libraries/SoftwareSerial/SoftwareSerial.h index d7cea594d..2fc998c23 100755 --- a/libraries/SoftwareSerial/SoftwareSerial.h +++ b/libraries/SoftwareSerial/SoftwareSerial.h @@ -40,7 +40,6 @@ http://arduiniana.org. ******************************************************************************/ #define _SS_MAX_RX_BUFF 64 // RX buffer size -#define _SS_VERSION 11 // software version of this library #ifndef GCC_VERSION #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) #endif @@ -86,10 +85,8 @@ public: void begin(long speed); bool listen(); void end(); - bool is_listening() { return this == active_object; } + bool isListening() { return this == active_object; } bool overflow() { bool ret = _buffer_overflow; _buffer_overflow = false; return ret; } - static int library_version() { return _SS_VERSION; } - static void enable_timer0(bool enable); int peek(); virtual void write(uint8_t byte); diff --git a/libraries/SoftwareSerial/icrmacros.h b/libraries/SoftwareSerial/icrmacros.h index b29f6ffd5..936eae848 100755 --- a/libraries/SoftwareSerial/icrmacros.h +++ b/libraries/SoftwareSerial/icrmacros.h @@ -58,7 +58,7 @@ http://arduiniana.org. ( ((p) == 50) ? 3 : \ ( ((p) == 51) ? 2 : \ ( ((p) == 52) ? 1 : \ - ( ((p) ==53) ? 0 : \ + ( ((p) == 53) ? 0 : \ ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \ 0 ) ) ) ) ) ) diff --git a/libraries/SoftwareSerial/keywords.txt b/libraries/SoftwareSerial/keywords.txt index 2ed9642e5..90d4c152d 100755 --- a/libraries/SoftwareSerial/keywords.txt +++ b/libraries/SoftwareSerial/keywords.txt @@ -16,10 +16,8 @@ begin KEYWORD2 end KEYWORD2 read KEYWORD2 available KEYWORD2 -is_listening KEYWORD2 +isListening KEYWORD2 overflow KEYWORD2 -library_version KEYWORD2 -enable_timer0 KEYWORD2 flush KEYWORD2 listen KEYWORD2