23#include <piduino/iodevice.h>
210 explicit Converter (
const std::string ¶meters =
"");
226 std::function<
Converter* (
const std::string &) > creator,
227 const std::string &
type =
"dac",
228 const std::string ¶meters =
"");
312 virtual long readChannel (
int channel = 0,
bool differential =
false);
320 virtual double readValue (
int channel = 0,
bool differential =
false);
329 virtual double readAverage (
int channel = 0,
bool differential =
false,
int count = 8);
338 virtual double readAverageValue (
int channel = 0,
bool differential =
false,
int count = 8);
348 virtual bool writeChannel (
long value,
int channel = -1,
bool differential =
false);
359 virtual bool writeValue (
double value,
int channel = -1,
bool differential =
false);
374 virtual double digitalToValue (
long digitalValue,
bool differential =
false)
const;
384 virtual double digitalToValue (
int channel,
long digitalValue,
bool differential =
false)
const;
402 virtual long valueToDigital (
int channel,
double value,
bool differential =
false)
const;
430 virtual long max (
bool differential =
false)
const;
436 virtual long min (
bool differential =
false)
const;
482 virtual bool setReference (
int referenceId,
int channel,
double fsr = 0.0);
The Converter class provides an interface for analog-to-digital and digital-to-analog converters.
virtual bool open(IoDevice::OpenMode mode=IoDevice::ReadWrite)
Opens the converter device with the specified mode.
virtual unsigned int flags() const
returns the flags associated with the converter.
static const std::map< std::string, Converter::ModeFlag > & stringToModeFlagMap()
Get the mapping of mode flags from their string representations.
virtual long setRange(long range)
Sets the digital range of the converter.
virtual void setEnable(bool enable)
Enables or disables the converter.
@ InternalReference
Internal reference voltage.
@ Internal3Reference
3rd internal reference voltage
@ Internal2Reference
2nd internal reference voltage
@ VddReference
Vdd reference voltage (analog or digital power supply depending on the converter)
@ DefaultReference
Default reference voltage.
@ ExternalReference
External reference voltage.
@ UnknownReference
Unknown reference voltage.
@ Internal4Reference
4th internal reference voltage
@ Internal1Reference
1st internal reference voltage
virtual long read()
Reads a digital value from the converter.
virtual bool setClock(int clock)
Sets the current clock setting.
virtual long valueToDigital(int channel, double value, bool differential=false) const
virtual int resolution() const
Returns the resolution of the converter in bits.
Converter(const std::string ¶meters="")
Constructs a Converter object.
virtual ~Converter()
Destroys the Converter object.
virtual bool setModeFlags(long flags, long mask=-1, int channel=-1)
Sets the mode flags for the converter.
ModeFlag
Flags that specify the channel mode for the converter.
@ PwrDwnR2
Power down mode (for DACs), resistor value depends on device.
@ PwrDwn
Power down mode (for DACs)
@ NoMode
No mode specified.
@ PwrDwnR3
Power down mode (for DACs), resistor value depends on device.
@ ActiveLow
Active low mode.
@ PwrDwnR1
Power down mode (for DACs), resistor value depends on device.
@ PwrDwnEn
Power down mode enable (for DACs)
@ Gain1
Gain1 = 000 -> The lowest gain level, the real value depends on the device.
@ DigitalOutput
Digital output mode.
@ PwrDwnMask
Power down mode (for DACs), resistor value depends on device.
@ FastMode
Fast mode (for DACs)
@ PwrDwn0
Power down mode (for DACs), LSB.
@ AnalogInput
Analog input mode (for ADCs)
@ Interrupt
Interrupt mode.
@ SaveToEEPROM
Save to EEPROM (for DACs)
@ EdgeRising
Edge rising trigger.
@ PwrDwnR4
Power down mode (for DACs), resistor value depends on device.
@ SingleShot
Single-shot mode (for ADCs)
@ NormalMode
Normal mode (default)
@ PullDown
Pull-down resistor enabled.
@ PwrDwn1
Power down mode (for DACs), MSB.
@ Gain8
Gain8 = 111 -> The highest gain level, the real value depends on the device.
@ AnalogOutput
Analog output mode (for DACs)
@ EdgeFalling
Edge falling trigger.
@ EdgeBoth
Both rising and falling edge triggers.
@ Continuous
Continuous mode (for ADCs)
@ PullUp
Pull-up resistor enabled.
@ DigitalInput
Digital input mode.
static const std::map< ModeFlag, std::string > & modeFlagToStringMap()
Get the mapping of mode flags to their string representations.
virtual int reference() const
Gets the current reference ID of the converter.
virtual bool setReference(int referenceId, double fsr=0.0)
Sets the reference value of the converter.
virtual double digitalToValue(long digitalValue, bool differential=false) const
Converts a digital value to an analog value.
static std::vector< Info > availableConverters()
Gets list of registered converter names.
virtual bool clearModeFlags(long flags, long mask=-1, int channel=-1)
Clears the mode flags for the converter.
@ ExternalClock
External clock setting.
@ DefaultClock
Default clock setting.
@ InternalClock
Internal clock setting.
@ UnknownClock
Unknown clock setting.
virtual int clock() const
Gets the current clock setting.
virtual long readChannel(int channel=0, bool differential=false)
Reads the digital value of a specific channel from the converter.
virtual bool write(long value)
Writes a value to the converter.
virtual long range() const
Gets the digital range of the converter.
virtual double fullScaleRange() const
Gets the current full-scale range of the converter.
virtual double readAverageValue(int channel=0, bool differential=false, int count=8)
Reads an average value from the converter.
Flags< ModeFlag, long > Mode
Type representing a combination of ModeFlag values.
virtual long valueToDigital(double value, bool differential=false) const
Converts a analog value to a digital value.
virtual double readAverage(int channel=0, bool differential=false, int count=8)
Reads an average value of count samples from the converter.
virtual bool setMode(Mode m, int channel=-1)
virtual long min(bool differential=false) const
Returns the minimum value the converter can produce.
virtual bool setFullScaleRange(double fsr)
Sets the full-scale range of the converter.
virtual double digitalToValue(int channel, long digitalValue, bool differential=false) const
virtual bool setFullScaleRange(int channel, double fsr)
static constexpr long InvalidValue
Invalid value for the converter.
virtual bool isEnabled() const
Checks if the converter is enabled.
static Converter * factory(const std::string &deviceName, const std::string ¶meters="")
Creates a converter instance from device name.
virtual long max(bool differential=false) const
Returns the maximum value the converter can produce.
Type type() const
Returns the type of the converter.
virtual bool isBipolar() const
Indicates if the converter supports bipolar operation.
virtual bool writeChannel(long value, int channel=-1, bool differential=false)
Writes a digital value to a specific channel of the converter.
virtual double readValue(int channel=0, bool differential=false)
Reads a value from the converter (ADC)
virtual long frequency() const
Gets the current clock frequency.
virtual void close()
Closes the converter device.
virtual bool setBipolar(bool bipolar)
Sets the bipolar mode of the converter.
virtual int numberOfChannels() const
Returns the number of channels supported by the converter.
virtual long setFrequency(long freq)
Sets the clock frequency.
virtual Mode mode(int channel=0) const
virtual bool toggle(int channel=-1)
Toggles the state of a specific channel on the converter.
virtual const std::string & deviceName() const
Returns the device name associated with the converter.
static void registerConverter(const std::string &deviceName, std::function< Converter *(const std::string &) > creator, const std::string &type="dac", const std::string ¶meters="")
Registers a converter class in the factory.
virtual int setResolution(int resolution)
Sets the resolution of the converter.
@ hasSetResolution
Indicates that the converter supports setting the resolution.
@ requiresWaitLoop
Indicates that the converter requires a wait loop to function correctly.
@ hasModeSetting
Indicates that the converter supports mode setting.
@ hasReference
Indicates that the converter has a reference voltage.
@ hasSetFrequency
Indicates that the converter supports setting the frequency.
@ hasToggle
Indicates that the converter supports toggling (GpioExpander only)
@ hasResolution
Indicates that the converter has a resolution.
@ hasClockSelection
Indicates that the converter supports clock selection.
@ hasBipolar
Indicates that the converter supports bipolar operation.
@ hasSetReference
Indicates that the converter supports setting the reference voltage.
@ hasReferencePerChannel
Indicates that the converter supports per-channel references.
@ hasFrequency
Indicates that the converter has a clock.
@ hasRange
Indicates that the converter has a range.
@ hasSetRange
Indicates that the converter supports setting the range.
@ hasSetBipolar
Indicates that the converter supports setting the bipolar mode.
virtual bool writeValue(double value, int channel=-1, bool differential=false)
Writes a value to the converter (DAC).
virtual int reference(int channel) const
virtual double fullScaleRange(int channel) const
void stop()
Stops the converter (disables it).
Converter(Private &dd)
Protected constructor for use by derived classes with private data.
virtual bool setReference(int referenceId, int channel, double fsr=0.0)
void run()
Starts the converter (enables it).
Type
Enumeration of converter types.
@ DigitalToAnalog
Digital-to-Analog Converter (DAC)
@ AnalogToDigital
Analog-to-Digital Converter (ADC)
@ GpioExpander
GPIO expander (not a converter, but can be used with converters)
@ Sensor
Sensor (not a converter, but can be used with converters)
@ UnknownType
No converter type specified.
A type-safe flags class for bitwise operations on enum values.
Abstract base class for input/output devices.
@ ReadWrite
Open the device for both input and output operations.
Internal implementation class for GpioDevice.
#define PIMP_DECLARE_PRIVATE(Class)
PIMP_DECLARE_PRIVATE.
Global namespace for Piduino.
Contains information about a registered converter.
std::string type
The type of the converter (e.g., "dac", "adc").
std::string name
The name of the converter class.
std::string parameters
Parameters for the converter, a colon-separated list of values.
Info(const std::string &name, const std::string &type, const std::string ¶meters)