Debinix Team Library SensorWLED
Provides methods to retrieve instant and peak values from the ADC input.
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
SensorWLED Class Reference

Track instant and peak DC ADC input readings. More...

#include <SensorWLED.h>

Public Member Functions

 SensorWLED (uint16_t analog_pin, float mv_offset=0.0, float slope=1.0, uint16_t samples=0)
 Sets up the static 'eeprom_offset'-array which hold each instance start address for configuration location in EEPROM. More...
 
 ~SensorWLED (void)
 Deallocate SensorWLED object, set data pin to INPUT.
 
void begin (DynamicDataType_t const &rDynamicParams)
 Load and initilize the user preferences, and EEPROM CRC32 sums. More...
 
bool updateAnalogRead (void)
 Call continously (in loop()) for updated values. More...
 
double getMappedValue (void)
 Map the input analog value to a value optimized for actual capability of the controllers ADC and suppl voltage. More...
 
double getMappedPeakValue (void)
 Map the input analog value to a value optimized for actual capability of the controllers ADc and suppl voltage. More...
 
VersionType_t readVersionEEPROM (void)
 Memory load of EEPROM Id and Pgm version, and returns the information. This use a fixed EEPROM address, common for all instances. More...
 
bool writeCalibrationEEPROM (uint16_t instance, uint32_t crc32)
 Saves static 'CalibrationData' struct to EEPROM. More...
 
CalibrationDataType_t readCalibrationEEPROM (uint16_t instance)
 Memory load of EEPROM 'CalibrationData', and returns the struct. More...
 
bool writeDynamicEEPROM (uint16_t instance, uint32_t crc32)
 Saves static 'DynamicData' struct to EEPROM. More...
 
DynamicDataType_t readDynamicEEPROM (uint16_t instance)
 Memory load of EEPROM 'DynamicData', and returns the struct. More...
 
uint32_t calculateCalibrationDataCRC32 (CalibrationDataType_t CalibrationData)
 Calculates the CRC32 sum for 'CalibrationData'. More...
 
uint32_t calculateDynamicParamsCRC32 (DynamicDataType_t DynamicParams)
 Calculates the CRC32 sum for 'DynamicParams'. More...
 

Static Public Member Functions

static uint16_t getInstanceNumber (void)
 Gets the total number of created instances. More...
 

Public Attributes

uint32_t cal_crc32
 CRC32 sum of stored EEPROM (begin) calibration data.
 
uint32_t dyn_crc32
 CRC32 sum of stored EEPROM (begin) dynamic data.
 
CalibrationDataType_t CalibrationData
 ADC channel setup and calibration.
 
DynamicDataType_t DynamicParams
 Static and dynamic setup parameters.
 

Static Public Attributes

static uint16_t eeprom_area [MAXINSTANCES+1]
 Emulated EEPROM areas for each instance. More...
 
static VersionType_t Version
 Program version stored in emulated EEPROM. More...
 
static uint16_t instance_counter = 0
 Number of instances.
 

Private Member Functions

void setAnalogPin (uint16_t a_pin, uint16_t mode=INPUT)
 Sets the analog pin for ADC input on the microcontroller. More...
 
uint32_t applyDecay (uint32_t peak_value)
 Applies the decay model to peak value. More...
 

Static Private Member Functions

static void generateTableCRC32 (uint32_t(&table)[CRC32_TABLE_SIZE])
 Generate 32 bit CRC table. More...
 
static uint32_t updateCRC32 (uint32_t(&table)[CRC32_TABLE_SIZE], uint32_t initial, const void *buf, size_t len)
 Calculate 32 bit CRC. More...
 
static bool writeVersionEEPROM (void)
 Saves static 'Version' struct to EEPROM. Writes to fixed EEPROM address, common for all instances. More...
 

Private Attributes

uint32_t previous_poll_millis_tm
 Holds previous ADC poll time.
 
uint32_t previous_hold_millis_tm
 Holds previous ADC hold time.
 
uint32_t raw_input_value
 ADC raw input at bits capability.
 
double mapped_input_value
 ADC values mapped to VCC range.
 
uint32_t pk_raw_input_value
 ADC peak input at bits capability.
 
double pk_mapped_input_value
 ADC peak mapped to VCC range.
 

Static Private Attributes

static bool eeprom_version_written_flag
 EEPROM write flag. More...
 

Detailed Description

Track instant and peak DC ADC input readings.

        The analog microcontroller reading from analog input is
    divided and methods returns these as read, while the other methods
    holds the peak-value while decaying with user set parameters.

Constructor & Destructor Documentation

◆ SensorWLED()

SensorWLED::SensorWLED ( uint16_t  analog_pin,
float  mv_offset = 0.0,
float  slope = 1.0,
uint16_t  samples = 0 
)

Sets up the static 'eeprom_offset'-array which hold each instance start address for configuration location in EEPROM.

Parameters
analog_pinADC analog input pin
mv_offsetADC zero offset compensation (mV)
slopeAdjust deviation of read ADC value
samplesNumber of samples for smoothing ADC values

Member Function Documentation

◆ begin()

void SensorWLED::begin ( DynamicDataType_t const &  UserDynamicParams)

Load and initilize the user preferences, and EEPROM CRC32 sums.

Parameters
&rUserParams Takes a D'ataEEPROMType_t' structure and loads program memory.

Applies user parameters.

Parameters
UserDynamicParamsTakes a DynamicDataType_t' structure and loads it into memory, and also writes the data to emulated EEPROM area for this instance.

◆ updateAnalogRead()

bool SensorWLED::updateAnalogRead ( void  )

Call continously (in loop()) for updated values.

Returns
Returns true when a new value is available.

◆ getMappedValue()

double SensorWLED::getMappedValue ( void  )

Map the input analog value to a value optimized for actual capability of the controllers ADC and suppl voltage.

Returns
The mapped instantanous analog value.

◆ getMappedPeakValue()

double SensorWLED::getMappedPeakValue ( void  )

Map the input analog value to a value optimized for actual capability of the controllers ADc and suppl voltage.

Returns
The mapped peak analog value.

◆ readVersionEEPROM()

VersionType_t SensorWLED::readVersionEEPROM ( void  )

Memory load of EEPROM Id and Pgm version, and returns the information. This use a fixed EEPROM address, common for all instances.

Returns
The Version struct data.

◆ writeCalibrationEEPROM()

bool SensorWLED::writeCalibrationEEPROM ( uint16_t  instance,
uint32_t  crc32 
)

Saves static 'CalibrationData' struct to EEPROM.

Parameters
instanceThe actual instance (ADC channel) for which the data belongs to.
crc32The calculated CRC32 sum for the struct to be written.
Returns
Boolean (true) value when data is written.

◆ readCalibrationEEPROM()

CalibrationDataType_t SensorWLED::readCalibrationEEPROM ( uint16_t  instance)

Memory load of EEPROM 'CalibrationData', and returns the struct.

Parameters
instanceThe specified instance for the EEPROM read
Returns
The CalibrationData struct data.

◆ writeDynamicEEPROM()

bool SensorWLED::writeDynamicEEPROM ( uint16_t  instance,
uint32_t  crc32 
)

Saves static 'DynamicData' struct to EEPROM.

Parameters
instanceThe actual instance (ADC channel) for which the data belongs to.
crc32The calculated CRC32 sum for the struct to be written.
Returns
Boolean (true) value when data is written.

◆ readDynamicEEPROM()

DynamicDataType_t SensorWLED::readDynamicEEPROM ( uint16_t  instance)

Memory load of EEPROM 'DynamicData', and returns the struct.

Parameters
instanceThe specified instance for the EEPROM read
Returns
The DynamicData struct data.

◆ calculateCalibrationDataCRC32()

uint32_t SensorWLED::calculateCalibrationDataCRC32 ( CalibrationDataType_t  CalibrationData)

Calculates the CRC32 sum for 'CalibrationData'.

Parameters
CalibrationDataThe actual instance 'CalibrationData' struct.
Returns
The calculated CRC32 sum for the struct 'CalibrationData'.

◆ calculateDynamicParamsCRC32()

uint32_t SensorWLED::calculateDynamicParamsCRC32 ( DynamicDataType_t  DynamicParams)

Calculates the CRC32 sum for 'DynamicParams'.

Parameters
DynamicParamsThe actual instance 'DynamicParams' struct.
Returns
The calculated CRC32 sum for the struct 'DynamicParams'.

◆ getInstanceNumber()

uint16_t SensorWLED::getInstanceNumber ( void  )
static

Gets the total number of created instances.

Returns
Instances created.

◆ setAnalogPin()

void SensorWLED::setAnalogPin ( uint16_t  a_pin,
uint16_t  mode = INPUT 
)
private

Sets the analog pin for ADC input on the microcontroller.

Parameters
a_pinPin number for analog readings on the microcontroller.
modeArduino pin mode for analog input.

◆ applyDecay()

uint32_t SensorWLED::applyDecay ( uint32_t  peak_value)
private

Applies the decay model to peak value.

Parameters
peak_valueValue to decay with set model, rate and times.
Returns
The reduced, decayed input peak value.

◆ generateTableCRC32()

void SensorWLED::generateTableCRC32 ( uint32_t(&)  table[CRC32_TABLE_SIZE])
staticprivate

Generate 32 bit CRC table.

Parameters
tableThe table that will be populated for CRC32 calculations.

◆ updateCRC32()

uint32_t SensorWLED::updateCRC32 ( uint32_t(&)  table[CRC32_TABLE_SIZE],
uint32_t  initial,
const void *  buf,
size_t  len 
)
staticprivate

Calculate 32 bit CRC.

Parameters
tableCRC32 table required for calculations.
initialInitial CRC32 value. 0 if first update, can be called repetingly.
bufPointer to start address of memory.
lenSize of contingent memory area to apply the CRC32 algorithm.
Returns
Calculated CRC32 value.

◆ writeVersionEEPROM()

bool SensorWLED::writeVersionEEPROM ( void  )
staticprivate

Saves static 'Version' struct to EEPROM. Writes to fixed EEPROM address, common for all instances.

Returns
true if EEPROM written.

Member Data Documentation

◆ eeprom_area

uint16_t SensorWLED::eeprom_area[MAXINSTANCES+1]
inlinestatic
Initial value:
= {
0, 0x100, 0x200, 0x300, 0x400, 0x500,
0x600, 0x700, 0x800, 0x900, 0xA00}

Emulated EEPROM areas for each instance.

◆ Version

VersionType_t SensorWLED::Version
inlinestatic
Initial value:
#define VERSION_MAJOR
Semantic versioning (M.m.p)
Definition: SensorWLED.h:38
#define VERSION_PATCH
Semantic versioning (M.m.p)
Definition: SensorWLED.h:40
#define EEPROM_ID
EEPROM id marker (never touch)
Definition: SensorWLED.h:37
#define VERSION_MINOR
Semantic versioning (M.m.p)
Definition: SensorWLED.h:39

Program version stored in emulated EEPROM.

◆ eeprom_version_written_flag

bool SensorWLED::eeprom_version_written_flag
inlinestaticprivate
Initial value:
=
false

EEPROM write flag.


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