Adafruit Library
Public Member Functions | List of all members
Wippersnapper_AnalogIO Class Reference

Class that provides an interface for reading and controlling analog pins. Stores information about analog input pins. More...

#include <Wippersnapper_AnalogIO.h>

Public Member Functions

 Wippersnapper_AnalogIO (int32_t totalAnalogInputPins, float aRef)
 Initializes Analog IO class. More...
 
 ~Wippersnapper_AnalogIO ()
 Destructor for Analog IO class.
 
void setAref (float refVoltage)
 Sets the device's reference voltage. More...
 
float getAref ()
 Returns the device's reference voltage. More...
 
void initAnalogInputPin (int pin, float period, wippersnapper_pin_v1_ConfigurePinRequest_Pull pullMode, wippersnapper_pin_v1_ConfigurePinRequest_AnalogReadMode analogReadMode)
 Initializes an analog input pin. More...
 
void deinitAnalogPin (wippersnapper_pin_v1_ConfigurePinRequest_Direction direction, int pin)
 Deinitializes an analog pin. More...
 
void disableAnalogInPin (int pin)
 Disables an analog input pin from sampling. More...
 
uint16_t getPinValue (int pin)
 Reads the raw ADC value of an analog pin. Value is always scaled to 16-bit. More...
 
float getPinValueVolts (int pin)
 Calculates analog pin's voltage provided a 16-bit ADC value. More...
 
void setADCResolution (int resolution)
 Sets the device's ADC resolution, either natively via calling Arduino API's analogReadResolution() or via scaling. More...
 
int getADCresolution ()
 Gets the scaled ADC resolution. More...
 
int getNativeResolution ()
 Gets the device's native ADC resolution. More...
 
bool timerExpired (long currentTime, analogInputPin pin, long periodOffset=0)
 Checks if pin's period is expired. More...
 
void update ()
 Iterates thru analog inputs.
 
bool encodePinEvent (uint8_t pinName, wippersnapper_pin_v1_ConfigurePinRequest_AnalogReadMode readMode, uint16_t pinValRaw=0, float pinValVolts=0.0)
 Encodes an analog input pin event into a signal message and publish it to IO. More...
 

Detailed Description

Class that provides an interface for reading and controlling analog pins. Stores information about analog input pins.

Constructor & Destructor Documentation

◆ Wippersnapper_AnalogIO()

Wippersnapper_AnalogIO::Wippersnapper_AnalogIO ( int32_t  totalAnalogInputPins,
float  aRef 
)

Initializes Analog IO class.

Parameters
totalAnalogInputPinsTotal number of analog input pins to allocate.
aRefADC's voltage reference value, in volts.

Member Function Documentation

◆ setAref()

void Wippersnapper_AnalogIO::setAref ( float  refVoltage)

Sets the device's reference voltage.

Parameters
refVoltageThe voltage reference to use during conversions.

◆ getAref()

float Wippersnapper_AnalogIO::getAref ( )

Returns the device's reference voltage.

Returns
Analog reference voltage, in volts.

◆ initAnalogInputPin()

void Wippersnapper_AnalogIO::initAnalogInputPin ( int  pin,
float  period,
wippersnapper_pin_v1_ConfigurePinRequest_Pull  pullMode,
wippersnapper_pin_v1_ConfigurePinRequest_AnalogReadMode  analogReadMode 
)

Initializes an analog input pin.

Parameters
pinThe analog pin to read from.
periodTime between measurements, in seconds.
pullModeThe pin's pull value.
analogReadModeDefines if pin will read and return an ADC value or a voltage value.

◆ deinitAnalogPin()

void Wippersnapper_AnalogIO::deinitAnalogPin ( wippersnapper_pin_v1_ConfigurePinRequest_Direction  direction,
int  pin 
)

Deinitializes an analog pin.

Parameters
directionThe analog pin's direction.
pinThe analog pin to deinitialize.

◆ disableAnalogInPin()

void Wippersnapper_AnalogIO::disableAnalogInPin ( int  pin)

Disables an analog input pin from sampling.

Parameters
pinThe analog input pin to disable.

◆ getPinValue()

uint16_t Wippersnapper_AnalogIO::getPinValue ( int  pin)

Reads the raw ADC value of an analog pin. Value is always scaled to 16-bit.

Parameters
pinThe pin to be read.
Returns
The pin's ADC value.

◆ getPinValueVolts()

float Wippersnapper_AnalogIO::getPinValueVolts ( int  pin)

Calculates analog pin's voltage provided a 16-bit ADC value.

Parameters
pinThe value from a previous ADC reading.
Returns
The pin's voltage.

◆ setADCResolution()

void Wippersnapper_AnalogIO::setADCResolution ( int  resolution)

Sets the device's ADC resolution, either natively via calling Arduino API's analogReadResolution() or via scaling.

Parameters
resolutionThe desired analog resolution, in bits.

◆ getADCresolution()

int Wippersnapper_AnalogIO::getADCresolution ( )

Gets the scaled ADC resolution.

Returns
resolution The scaled analog resolution, in bits.

◆ getNativeResolution()

int Wippersnapper_AnalogIO::getNativeResolution ( )

Gets the device's native ADC resolution.

Returns
resolution The native analog resolution, in bits.

◆ timerExpired()

bool Wippersnapper_AnalogIO::timerExpired ( long  currentTime,
analogInputPin  pin,
long  periodOffset = 0 
)

Checks if pin's period is expired.

Parameters
currentTimeThe current software timer value.
pinThe desired analog pin to check
periodOffsetOffset to add to the pin's period (used for on_change).
Returns
True if pin's period expired, False otherwise.

◆ encodePinEvent()

bool Wippersnapper_AnalogIO::encodePinEvent ( uint8_t  pinName,
wippersnapper_pin_v1_ConfigurePinRequest_AnalogReadMode  readMode,
uint16_t  pinValRaw = 0,
float  pinValVolts = 0.0 
)

Encodes an analog input pin event into a signal message and publish it to IO.

Parameters
pinNameSpecifies the pin's name.
readModeRead mode - raw ADC or voltage.
pinValRawRaw pin value, used if readmode is raw.
pinValVoltsRaw pin value expressed in Volts, used if readmode is volts.
Returns
True if successfully encoded a PinEvent signal message, False otherwise.

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