diff --git a/library.json b/library.json index 5320ca4..1e29cc1 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Arduino-SDI-12", - "version": "1.1.0", + "version": "1.1.2", "keywords": "SDI-12, sdi12, communication, bus, sensor, Decagon", "description": "Arduino library for SDI-12 communications to a wide variety of environmental sensors.", "repository": diff --git a/library.properties b/library.properties index 119cdbf..596e2dc 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino-SDI-12 -version=1.1.0 +version=1.1.2 author=Kevin M. Smith , Shannon Hicks maintainer=Sara Damiano sentence=Arduino library for SDI-12 communications to a wide variety of environmental sensors. diff --git a/src/SDI12.cpp b/src/SDI12.cpp index 9ec8f2c..46fa7ce 100644 --- a/src/SDI12.cpp +++ b/src/SDI12.cpp @@ -124,32 +124,19 @@ SDI-12.org, official site of the SDI-12 Support Group. 0.1 - Include the header file for this library. 0.2 - defines the size of the buffer -0.3 - defines value for DISABLED state (see section 2) -0.4 - defines value for ENABLED state (not used, reserved for future) -0.5 - defines value for DISABLED state (see section 2) -0.6 - defines value for TRANSMITTING state (see section 2) -0.7 - defines value for LISTENING state -0.8 - defines value for the spacing of bits. - 1200 bits per second implies 833 microseconds per bit. - 830 seems to be a reliable value given the overhead of the call. -0.10 - a static pointer to the active object. See section 6. -0.11 - a reference to the data pin, used throughout the library -0.12 - holds the buffer overflow status +0.3 - a static pointer to the active object. See section 6. */ #include "SDI12.h" // 0.1 header file for this library #define SDI12_BUFFER_SIZE 64 // 0.2 max RX buffer size -#define DISABLED 0 // 0.3 value for DISABLED state -#define ENABLED 1 // 0.4 value for ENABLED state -#define HOLDING 2 // 0.5 value for DISABLED state -#define TRANSMITTING 3 // 0.6 value for TRANSMITTING state -#define LISTENING 4 // 0.7 value for LISTENING state -#define SPACING 830 // 0.8 bit timing in microseconds (1200 baud = 1200 bits/second ~ 830 µs/bit) -SDI12 *SDI12::_activeObject = NULL; // 0.10 pointer to active SDI12 object +SDI12 *SDI12::_activeObject = NULL; // 0.3 pointer to active SDI12 object +static const uint16_t bitWidth_micros = (uint16_t) 833; // The size of a bit in microseconds + // 1200 baud = 1200 bits/second ~ 833.333 µs/bit + // 830 seems to be a reliable value given the overhead of the call. /* =========== 1. Buffer Setup ============================================ @@ -218,12 +205,10 @@ HOLDING --> TRANSMITTING --> LISTENING --> done reading, forceHold(); HOLDING 2.1 - Sets up parity and interrupts for different processor types - that is, imports the interrupts and parity for the AVR processors where they exist. -2.2 - A function to return a string with the current line state. +2.2 - A private helper function to turn pin interupts on or off 2.3 - Sets the proper state. This is a private function, and only used -internally. It uses #define values of HOLDING, TRANSMITTING, LISTENING, -and DISABLED to determine which state should be set. The grid above -defines the settings applied in changing to each state. +internally. The grid above defines the settings applied in changing to each state. 2.4 - A public function which forces the line into a "holding" state. This is generally unneeded, but for deployments where interference is an @@ -255,75 +240,69 @@ uint8_t SDI12::parity_even_bit(uint8_t v) } #endif -// 2.2 - Returns the current state -const char *SDI12::getStateName(uint8_t state) +// 2.2 - a helper function to switch pin interrupts on or off +void SDI12::setPinInterrupts(bool enable) { - const char * retval = "UNKNOWN"; - if (state == HOLDING) { - retval = "HOLDING"; - } - else if (state == TRANSMITTING) { - retval = "TRANSMITTING"; - } - else if (state == LISTENING) { - retval = "LISTENING"; - } - else if (state == ENABLED) { - retval = "ENABLED"; - } - else if (state == DISABLED) { - retval = "DISABLED"; + #ifndef SDI12_EXTERNAL_PCINT + if (enable) + { + #if defined __AVR__ + *digitalPinToPCICR(_dataPin) |= (1<