Debinix Team Library SensorWLED
Provides methods to retrieve instant and peak values from the ADC input.
|
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... | |
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.
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.
analog_pin | ADC analog input pin |
mv_offset | ADC zero offset compensation (mV) |
slope | Adjust deviation of read ADC value |
samples | Number of samples for smoothing ADC values |
void SensorWLED::begin | ( | DynamicDataType_t const & | UserDynamicParams | ) |
Load and initilize the user preferences, and EEPROM CRC32 sums.
& | rUserParams Takes a D'ataEEPROMType_t' structure and loads program memory. |
Applies user parameters.
UserDynamicParams | Takes a DynamicDataType_t' structure and loads it into memory, and also writes the data to emulated EEPROM area for this instance. |
bool SensorWLED::updateAnalogRead | ( | void | ) |
Call continously (in loop()) for updated values.
double SensorWLED::getMappedValue | ( | void | ) |
Map the input analog value to a value optimized for actual capability of the controllers ADC and suppl voltage.
double SensorWLED::getMappedPeakValue | ( | void | ) |
Map the input analog value to a value optimized for actual capability of the controllers ADc and suppl voltage.
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.
bool SensorWLED::writeCalibrationEEPROM | ( | uint16_t | instance, |
uint32_t | crc32 | ||
) |
Saves static 'CalibrationData' struct to EEPROM.
instance | The actual instance (ADC channel) for which the data belongs to. |
crc32 | The calculated CRC32 sum for the struct to be written. |
CalibrationDataType_t SensorWLED::readCalibrationEEPROM | ( | uint16_t | instance | ) |
Memory load of EEPROM 'CalibrationData', and returns the struct.
instance | The specified instance for the EEPROM read |
bool SensorWLED::writeDynamicEEPROM | ( | uint16_t | instance, |
uint32_t | crc32 | ||
) |
Saves static 'DynamicData' struct to EEPROM.
instance | The actual instance (ADC channel) for which the data belongs to. |
crc32 | The calculated CRC32 sum for the struct to be written. |
DynamicDataType_t SensorWLED::readDynamicEEPROM | ( | uint16_t | instance | ) |
Memory load of EEPROM 'DynamicData', and returns the struct.
instance | The specified instance for the EEPROM read |
uint32_t SensorWLED::calculateCalibrationDataCRC32 | ( | CalibrationDataType_t | CalibrationData | ) |
Calculates the CRC32 sum for 'CalibrationData'.
CalibrationData | The actual instance 'CalibrationData' struct. |
uint32_t SensorWLED::calculateDynamicParamsCRC32 | ( | DynamicDataType_t | DynamicParams | ) |
Calculates the CRC32 sum for 'DynamicParams'.
DynamicParams | The actual instance 'DynamicParams' struct. |
|
static |
Gets the total number of created instances.
|
private |
Sets the analog pin for ADC input on the microcontroller.
a_pin | Pin number for analog readings on the microcontroller. |
mode | Arduino pin mode for analog input. |
|
private |
Applies the decay model to peak value.
peak_value | Value to decay with set model, rate and times. |
|
staticprivate |
Generate 32 bit CRC table.
table | The table that will be populated for CRC32 calculations. |
|
staticprivate |
Calculate 32 bit CRC.
table | CRC32 table required for calculations. |
initial | Initial CRC32 value. 0 if first update, can be called repetingly. |
buf | Pointer to start address of memory. |
len | Size of contingent memory area to apply the CRC32 algorithm. |
|
staticprivate |
Saves static 'Version' struct to EEPROM. Writes to fixed EEPROM address, common for all instances.
|
inlinestatic |
Emulated EEPROM areas for each instance.
|
inlinestatic |
Program version stored in emulated EEPROM.
|
inlinestaticprivate |
EEPROM write flag.