NTC_THERMISTOR Driver 0.1.0
API reference
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ntc_thermistor::NtcThermistor< Port > Class Template Reference

Driver for one NTC thermistor in a resistor divider on an ADC port. More...

#include <ntc_thermistor.hpp>

Public Member Functions

 NtcThermistor (Port &port, const Config &config) noexcept
 Bind the driver to a port and store the configuration. No I/O, cannot fail.
 
 NtcThermistor (const NtcThermistor &)=delete
 One driver object per thermistor.
 
NtcThermistor & operator= (const NtcThermistor &)=delete
 One driver object per thermistor.
 
Result< void > EnsureInitialized () noexcept
 Start the driver, once: the only way to initialise it.
 
bool IsInitialized () const noexcept
 
Result< Reading > Read () noexcept
 Read the temperature: bias on, settle, sample_count conversions, bias off, convert.
 
Result< uint32_t > ReadResistance () noexcept
 Read the thermistor's resistance in ohms: the divider arithmetic only, no curve and no window.
 
Result< uint32_t > ReadRawCode () noexcept
 One raw conversion, with no averaging and no conversion: bias on, settle, one sample, bias off. A diagnostic: it is the code the port returned, and it has no retry.
 
Result< void > SetConfig (const Config &config) noexcept
 Replace the configuration. It is validated first; on failure the old one stays.
 
const Config & GetConfig () const &noexcept
 
void GetConfig () const &&=delete
 Not on a temporary driver: the reference would dangle (handbook KB-CPP20-044).
 
uint32_t GetLastCode () const noexcept
 

Detailed Description

template<AdcPort Port>
class ntc_thermistor::NtcThermistor< Port >

Driver for one NTC thermistor in a resistor divider on an ADC port.

Lifecycle: construct with the configuration (no I/O), then EnsureInitialized(), the one way to start; use; replace the configuration with SetConfig(). Every call that touches the port returns Error::NotInitialized until EnsureInitialized() has succeeded; no call starts it as a side effect.

Optional hooks: void DelayUs(uint32_t) (the wait between samples, sample_delay_us, and the settling time, settle_us; a Config that needs a wait the port cannot make is InvalidArgument) and bool SetBias(bool) (powers the divider only while sampling).

Template Parameters
PortYour class derived from AdcInterface<Port>.

Constructor & Destructor Documentation

◆ NtcThermistor()

template<AdcPort Port>
ntc_thermistor::NtcThermistor< Port >::NtcThermistor ( Port &  port,
const Config &  config 
)
inlinenoexcept

Bind the driver to a port and store the configuration. No I/O, cannot fail.

Parameters
portThe port; it must outlive the driver.
configThe thermistor and its divider; checked by EnsureInitialized() before any I/O. The curve's table, if any, must outlive the driver.

Member Function Documentation

◆ EnsureInitialized()

template<AdcPort Port>
Result< void > ntc_thermistor::NtcThermistor< Port >::EnsureInitialized ( )
noexcept

Start the driver, once: the only way to initialise it.

Checks the configuration (and that the port has the hooks it needs), brings the ADC up and, when the port has SetBias(), switches the divider off so that the first reading starts from a known state. After it succeeds, later calls return Ok at once with no I/O. After it fails, the driver stays uninitialised and the next call starts again.

Returns
Ok, InvalidArgument (the configuration fails Validate() or needs a hook the port lacks; no port call) or Bus.

◆ GetConfig()

template<AdcPort Port>
const Config & ntc_thermistor::NtcThermistor< Port >::GetConfig ( ) const &
inlinenoexcept
Returns
The configuration in use. No I/O.

◆ GetLastCode()

template<AdcPort Port>
uint32_t ntc_thermistor::NtcThermistor< Port >::GetLastCode ( ) const
inlinenoexcept
Returns
The last code the port returned, even one at or above scale; 0 before any sample. No I/O.

◆ IsInitialized()

template<AdcPort Port>
bool ntc_thermistor::NtcThermistor< Port >::IsInitialized ( ) const
inlinenoexcept
Returns
true after a successful EnsureInitialized(). No I/O.

◆ Read()

template<AdcPort Port>
Result< Reading > ntc_thermistor::NtcThermistor< Port >::Read ( )
noexcept

Read the temperature: bias on, settle, sample_count conversions, bias off, convert.

Returns
The reading, or NotInitialized, Bus (an ADC read or the bias switch failed; no retry), CodeOutOfScale, Unstable, OpenCircuit, ShortCircuit, BelowRange or AboveRange.

◆ ReadRawCode()

template<AdcPort Port>
Result< uint32_t > ntc_thermistor::NtcThermistor< Port >::ReadRawCode ( )
noexcept

One raw conversion, with no averaging and no conversion: bias on, settle, one sample, bias off. A diagnostic: it is the code the port returned, and it has no retry.

Returns
The code, or NotInitialized, Bus or CodeOutOfScale (the code is still kept for GetLastCode()). It never starts anything and changes no state but GetLastCode().

◆ ReadResistance()

template<AdcPort Port>
Result< uint32_t > ntc_thermistor::NtcThermistor< Port >::ReadResistance ( )
noexcept

Read the thermistor's resistance in ohms: the divider arithmetic only, no curve and no window.

Returns
Ohms, or the errors of Read() that come before the curve.

◆ SetConfig()

template<AdcPort Port>
Result< void > ntc_thermistor::NtcThermistor< Port >::SetConfig ( const Config &  config)
noexcept

Replace the configuration. It is validated first; on failure the old one stays.

Parameters
configThe new configuration; its table, if any, must outlive the driver.
Returns
Ok or InvalidArgument. No port call.

The documentation for this class was generated from the following file: