Skip to content

3. Constructor, Destructor, SDI12.begin(), and SDI12.end()

Sara Damiano edited this page Aug 13, 2024 · 7 revisions

3.1 The Constructor

The constructor requires a single parameter: the pin to be used for the data line. When the constructor is called it resets the buffer overflow status to FALSE and assigns the pin number "dataPin" to the private variable "_dataPin".

SDI12::SDI12(uint8_t dataPin){ _bufferOverflow = false; _dataPin = dataPin; }

3.2 The Destructor

When the destructor is called, it's main task is to disable any interrupts that had been previously assigned to the pin, so that the pin will behave as expected when used for other purposes. This is achieved by putting the SDI-12 object in the DISABLED state.

SDI12::~SDI12(){ setState(DISABLED); }

3.3 Begin

This is called to begin the functionality of the SDI-12 object. It has no parameters as the SDI-12 protocol is fully specified (e.g. the baud rate is set). It sets the object as the active object (if multiple SDI-12 instances are being used simultaneously).

void SDI12::begin() { setState(HOLDING); setActive(); }

3.4 End

This can be called to temporarily cease all functionality of the SDI-12 object. It is not as harsh as destroying the object with the destructor, as it will maintain the memory buffer.

void SDI12::end() { setState(DISABLED); }