Loom_Analog class
Analog pin manager module.
Contents
Base classes
- class LoomSensor
- Abstract root of Loom sensor modules hierarchy.
Public types
- enum Conversion { NONE, VOLTAGE, THERMISTOR, PH, TURBIDITY, EC, TDS, SALINITY }
- Different types of conversions from analog to specified unit.
Protected variables
- uint8_t read_resolution
- Which resolution to read at (generally use 12 or 10)
- bool pin_enabled
- Whether pins A0-A5 are enabled for analog reading.
- uint16_t analog_vals
- Last known analog readings for pin A0-A5.
- float battery
- Battery voltage.
- bool enable_conversions
- Enable or disable all conversions.
- Conversion conversions
- Conversion (if any) to apply to analog value when printing / packaging.
- float temperature
- Temperature to use in conversions.
CONSTRUCTORS / DESTRUCTOR
-
Loom_Analog(LoomManager* manager,
const uint8_t num_samples = 8,
const uint8_t read_resolution = 12,
const bool enableA0 = true,
const bool enableA1 = true,
const bool enableA2 = true,
const bool enableA3 = true,
const bool enableA4 = true,
const bool enableA5 = true,
const Conversion convertA0 = Conversion::
NONE, const Conversion convertA1 = Conversion:: NONE, const Conversion convertA2 = Conversion:: NONE, const Conversion convertA3 = Conversion:: NONE, const Conversion convertA4 = Conversion:: NONE, const Conversion convertA5 = Conversion:: NONE, const float temperature = 25.0) - Analog manager module constructor.
- Loom_Analog(LoomManager* manager, JsonArrayConst p)
- Constructor that takes Json Array, extracts args and delegates to regular constructor.
- ~Loom_Analog() defaulted
- Destructor.
OPERATION
- void measure() override
- Take any relevant measurements.
- void package(JsonObject json) override
- Package a modules measurements or state.
- void add_config(JsonObject json) override
- Add configuration information to JsonObject.
PRINT INFORMATION
- void print_config() const override
- Display the configuration settings of the module.
- void print_measurements() const override
- Print the last set of measurements taken.
GETTERS
- auto get_analog_resolution() const -> uint8_t
- Get the current analog read resolution.
- auto get_analog_val(const uint8_t pin) const -> int
- Get the analog value of specified pin.
- auto get_battery() const -> float
- Get the battery voltage of the device.
- auto get_pin_enabled(const uint8_t pin) const -> bool
- Get if a pin is enabled in manager.
- auto get_conversion(const uint8_t pin) const -> Conversion
- Get the current conversion associated with a pin.
SETTERS
- void set_analog_resolution(const uint8_t res)
- Set the analog read resolution.
- void set_pin_enabled(const uint8_t pin, const bool e)
- Set the enable state of a pin.
- void set_conversion(const uint8_t pin, const Conversion c)
- Set the current conversion associated with a pin.
- void set_enable_conversions(const bool e)
- Enable or disable all conversions.
- void set_temperature(const float temp)
- Set temperature to use in conversions that require temperature compensation.
MISCELLANEOUS
- static auto conversion_name(const Conversion conversion) -> const char*
- Get string of name associated with conversion enum.
Enum documentation
enum Loom_ Analog:: Conversion
Different types of conversions from analog to specified unit.
| Enumerators | |
|---|---|
| NONE |
No conversion applied. |
| VOLTAGE |
Analog to voltage. |
| THERMISTOR |
Thermistor. |
| PH |
pH value |
| TURBIDITY |
Turbidity. |
| EC |
Electrical Conductivity. |
| TDS |
Total Dissolved Solids. |
| SALINITY |
Salinity. |
Function documentation
Loom_ Analog:: Loom_Analog(LoomManager* manager,
const uint8_t num_samples = 8,
const uint8_t read_resolution = 12,
const bool enableA0 = true,
const bool enableA1 = true,
const bool enableA2 = true,
const bool enableA3 = true,
const bool enableA4 = true,
const bool enableA5 = true,
const Conversion convertA0 = Conversion:: NONE,
const Conversion convertA1 = Conversion:: NONE,
const Conversion convertA2 = Conversion:: NONE,
const Conversion convertA3 = Conversion:: NONE,
const Conversion convertA4 = Conversion:: NONE,
const Conversion convertA5 = Conversion:: NONE,
const float temperature = 25.0)
Analog manager module constructor.
| Parameters | |
|---|---|
| manager | |
| num_samples in | Set(Int) | <8> | {1, 2, 4, 8, 16} | How many samples to take and average |
| read_resolution in | Int | <12> | [8-12] | How many bits to read analog values at |
| enableA0 in | Bool | <true> | {true, false} | Enable pin A0 for managing |
| enableA1 in | Bool | <true> | {true, false} | Enable pin A1 for managing |
| enableA2 in | Bool | <true> | {true, false} | Enable pin A2 for managing |
| enableA3 in | Bool | <true> | {true, false} | Enable pin A3 for managing |
| enableA4 in | Bool | <true> | {true, false} | Enable pin A4 for managing |
| enableA5 in | Bool | <true> | {true, false} | Enable pin A5 for managing |
| convertA0 in | Set(Conversion) | <0> | {0("No conversion"), 1("Analog to voltage"), 2("Thermistor" ), 3("pH"), 4("Turbidity"), 5("Electrical Conductivity"), 6("Total Dissolved Solids"), 7("Salinity")} | Conversion to apply to analog readings on pin A0 |
| convertA1 in | Set(Conversion) | <0> | {0("No conversion"), 1("Analog to voltage"), 2("Thermistor" ), 3("pH"), 4("Turbidity"), 5("Electrical Conductivity"), 6("Total Dissolved Solids"), 7("Salinity")} | Conversion to apply to analog readings on pin A1 |
| convertA2 in | Set(Conversion) | <0> | {0("No conversion"), 1("Analog to voltage"), 2("Thermistor" ), 3("pH"), 4("Turbidity"), 5("Electrical Conductivity"), 6("Total Dissolved Solids"), 7("Salinity")} | Conversion to apply to analog readings on pin A2 |
| convertA3 in | Set(Conversion) | <0> | {0("No conversion"), 1("Analog to voltage"), 2("Thermistor" ), 3("pH"), 4("Turbidity"), 5("Electrical Conductivity"), 6("Total Dissolved Solids"), 7("Salinity")} | Conversion to apply to analog readings on pin A3 |
| convertA4 in | Set(Conversion) | <0> | {0("No conversion"), 1("Analog to voltage"), 2("Thermistor" ), 3("pH"), 4("Turbidity"), 5("Electrical Conductivity"), 6("Total Dissolved Solids"), 7("Salinity")} | Conversion to apply to analog readings on pin A4 |
| convertA5 in | Set(Conversion) | <0> | {0("No conversion"), 1("Analog to voltage"), 2("Thermistor" ), 3("pH"), 4("Turbidity"), 5("Electrical Conductivity"), 6("Total Dissolved Solids"), 7("Salinity")} | Conversion to apply to analog readings on pin A5 |
| temperature in | float | <25.0> | [0.-100.] | Temperature to using in conversions |
Loom_ Analog:: Loom_Analog(LoomManager* manager,
JsonArrayConst p)
Constructor that takes Json Array, extracts args and delegates to regular constructor.
| Parameters | |
|---|---|
| manager | |
| p in | The array of constuctor args to expand |
void Loom_ Analog:: package(JsonObject json) override
Package a modules measurements or state.
| Parameters | |
|---|---|
| json out | Object to put data into |
void Loom_ Analog:: add_config(JsonObject json) override
Add configuration information to JsonObject.
| Parameters | |
|---|---|
| json in | Json configuration object to add to |
LoomManager iterates over modules to build complete configuration
void Loom_ Analog:: print_measurements() const override
Print the last set of measurements taken.
Does not package the data.
uint8_t Loom_ Analog:: get_analog_resolution() const
Get the current analog read resolution.
| Returns | Read resolution |
|---|
int Loom_ Analog:: get_analog_val(const uint8_t pin) const
Get the analog value of specified pin.
| Parameters | |
|---|---|
| pin in | Pin to read |
| Returns | The analog value |
float Loom_ Analog:: get_battery() const
Get the battery voltage of the device.
| Returns | The battery voltage |
|---|
bool Loom_ Analog:: get_pin_enabled(const uint8_t pin) const
Get if a pin is enabled in manager.
| Parameters | |
|---|---|
| pin in | Pin to get enable state of |
| Returns | The enabled state of pin |
Conversion Loom_ Analog:: get_conversion(const uint8_t pin) const
Get the current conversion associated with a pin.
| Parameters | |
|---|---|
| pin in | The pin to get conversion for |
| Returns | The current Conversion setting |
void Loom_ Analog:: set_analog_resolution(const uint8_t res)
Set the analog read resolution.
| Parameters | |
|---|---|
| res in | Resolution to read at (12 bit max) |
void Loom_ Analog:: set_pin_enabled(const uint8_t pin,
const bool e)
Set the enable state of a pin.
| Parameters | |
|---|---|
| pin in | The pin to set enable state of |
| e in | Enable state |
void Loom_ Analog:: set_conversion(const uint8_t pin,
const Conversion c)
Set the current conversion associated with a pin.
| Parameters | |
|---|---|
| pin in | The pin to set conversion for |
| c in | The Conversion to use |
void Loom_ Analog:: set_enable_conversions(const bool e)
Enable or disable all conversions.
| Parameters | |
|---|---|
| e in | Enable state |
void Loom_ Analog:: set_temperature(const float temp)
Set temperature to use in conversions that require temperature compensation.
| Parameters | |
|---|---|
| temp in | Temperature to use |
static const char* Loom_ Analog:: conversion_name(const Conversion conversion)
Get string of name associated with conversion enum.
| Returns | String of conversion |
|---|