Serial Wombat Arduino Library

Loading...
Searching...
No Matches
Public Member Functions | List of all members
SerialWombatResistanceInput Class Reference

A class to make resistance measurements with the Serial Wombat 18AB chip. More...

`#include <SerialWombatResistanceInput.h>`

Inheritance diagram for SerialWombatResistanceInput:
[legend]
Collaboration diagram for SerialWombatResistanceInput:
[legend]

## Public Member Functions
| SerialWombatResistanceInput (SerialWombatChip &serialWombatChip)
| Constructor for the SerialWombatResistanceInput class.
int16_t | begin (uint8_t pin)
| Initialize a resistance input on a given pin.
int16_t | begin (uint8_t pin, uint16_t averageSamples, uint16_t filterConstant)
| Initialize a resistance input on a given pin.
int16_t | begin (uint8_t pin, uint16_t averageSamples, uint16_t filterConstant, ResistanceInputPublicDataOutput output)
| Initialize a resistance input on a given pin.
uint16_t | readFilteredOhms ()
| Retreive a filtered Resistance measurement.
uint16_t | readAveragedOhms ()
| Retreive an averaged Resistance measurement.
uint16_t | readMaximumOhms (bool resetAfterRead)
| Retreive the maximum single sample Resistance value in Ohms.
uint16_t | readMinimumOhms (bool resetAfterRead)
| Retreive the maximum single sample Resistance value in Ohms.
uint8_t | pin ()
| Used for inheritance.
uint8_t | swPinModeNumber ()
| Used for ineheritance.
Public Member Functions inherited from SerialWombatPin
| SerialWombatPin (SerialWombatChip &serialWombatChip)
| Instantiates a Serial Wombat Pin.
| SerialWombatPin (SerialWombatChip &serialWombatChip, uint8_t pin)
| Instantiates a Serial Wombat Pin.
uint16_t | readPublicData ()
| Read the 16 Bit public data associated with this pin.
void | pinMode (uint8_t mode, bool pullDown=false, bool openDrain=false)
| Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings.
void | digitalWrite (uint8_t val)
| Set output pin High or Low.
int | digitalRead ()
| Reads the state of the Pin.
uint16_t | writePublicData (uint16_t value)
| Write a 16 bit value to this pin.
uint8_t | pin ()
| Returns the current SW pin number. Used primarily for virtual calls by derived classes.
uint8_t | swPinModeNumber ()
| Returns the Mode number. Used primarily by derived classes to populate packet data.
int16_t | initPacketNoResponse (uint8_t packetNumber, uint8_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55, uint8_t param4=0x55)
int16_t | initPacketNoResponse (uint8_t packetNumber, uint16_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55)
int16_t | initPacketNoResponse (uint8_t packetNumber, uint16_t param0, uint16_t param1, uint8_t param2=0x55)
int16_t | disable ()
| Disables the pin mode (if applicable)
int16_t | enablePullup (bool enabled)
| Enables the weak pull up on a pin. Implemented on SW18AB only.
int16_t | enablePullDown (bool enabled)
| Enables the weak pull down on a pin. Implemented on SW18AB only.
int16_t | enableOpenDrain (bool enabled)
| Enables open drain mode on a pin. Implemented on SW18AB only.
Public Member Functions inherited from SerialWombatAbstractProcessedInput
| SerialWombatAbstractProcessedInput (SerialWombatChip &sw)
| Constructor for the SerialWombatAbstractScaledOutput Class.
int16_t | writeInverted (bool inverted)
| if enabled subtract the input value from 65535 before doing any other processing.
int16_t | writeFirstOrderFilteringConstant (uint16_t constant)
| Set a first order filtering constant to be applied to the signal Higher is heavier filtering.
int16_t | writeAveragingNumberOfSamples (uint16_t numberOfSamples)
| Set a number of samples to average for each update of the downstream signal.
int16_t | writeExcludeBelowAbove (uint16_t low, uint16_t high)
| Sets input value ranges which are discarded rather than processed.
int16_t | configureQueue (SerialWombatQueue *queue, Period period, bool queueHighByte=true, bool queueLowByte=true)
| Sets up the queueing feature for this pin mode. Queue must have been initialized prior to this queue.
int16_t | configureOutputValue (OutputValue outputValue)
| Configures whether the pin's public data value is averaged, filtered, or neither.
int16_t | writeTransformScaleRange (uint16_t min, uint16_t max)
| Scale incoming values to a range of 0 to 65535.
int16_t | writeTransformLinearMXB (int32_t m, int32_t b)
| Scale incoming values based on an mx+b linear equation.
int16_t | configureIntegrator (uint16_t negativeMaxIndex, uint16_t negativeMidIndex, uint16_t negativeDeadZone, uint16_t positiveDeadZone, uint16_t positiveMidIndex, uint16_t positiveMaxIndex, uint16_t midIncrement, uint16_t maxIncrement, uint16_t initialValue, uint8_t updateFrequencyMask=0)
| Sort incoming data into one of 5 ranges, and integrate based on linear interpolation in those ranges.
int16_t | writeProcessedInputEnable (bool enabled)
| Enables or disables all input processing functions If disabled, the raw input value is placed directly in the pin's 16 bit public data buffer.
uint16_t | readMinimum (bool resetAfterRead=false)
| Retreive the maximum public data output value since the last call with reset= true.
uint16_t | readMaximum (bool resetAfterRead=false)
| Retreive the minimum public data output value since the last call with reset= true.
uint16_t | readAverage ()
| Retreive the last completed averaged value.
uint16_t | readFiltered ()
| Retreive the filtered value.

## Additional Inherited Members
Public Types inherited from SerialWombatAbstractProcessedInput
enum | Period { PERIOD_1mS = 0 , PERIOD_2mS = 1 , PERIOD_4mS = 2 , PERIOD_8mS = 3 , PERIOD_16mS = 4 , PERIOD_32mS = 5 , PERIOD_64mS = 6 , PERIOD_128mS = 7 , PERIOD_256mS = 8 , PERIOD_512mS = 9 , PERIOD_1024mS = 10 }
enum | OutputValue { RAW = 0 , FIRST_ORDER_FILTERED = 1 , AVERAGE = 2 }
enum | Transform { NONE = 0 , SCALE_RANGE = 1 , LINEAR_MXB = 2 }
Protected Attributes inherited from SerialWombatPin
uint8_t | _pin = 255
SerialWombatChip & | _sw
uint8_t | _pinMode = 0

## Detailed Description

A class to make resistance measurements with the Serial Wombat 18AB chip.

The SerialWombatResistanceInput class is used to make resistance measurements on a given pin up to about 60 kOhm.

This pin mode is only available on the SerialWombat 18AB chip

Any analog-capable pin may be used to make a measurement (0-4, 16-19).

Averaging of samples and first order IIR filtering (20 Hz sampling) of input are available

For a good explanation of 1st order FIR filter calculations, see: https://www.monocilindro.com/2017/04/08/how-to-implement-a-1st-order-iir-filter-in-5-minutes/

Filtering adds lag. The higher the filter constant value, the longer it takes for the filter to settle when given a steady input.

Declare and initialize a SerialWombatResistanceInput instance for each pin being used as a resistance input.

A tutorial is available here:

https://youtu.be/8ynBmxZSE_M

Definition at line 74 of file SerialWombatResistanceInput.h.

## Constructor & Destructor Documentation

## ◆ SerialWombatResistanceInput()

SerialWombatResistanceInput::SerialWombatResistanceInput | ( | SerialWombatChip & | serialWombatChip | ) |
| inline

Constructor for the SerialWombatResistanceInput class.

Parameters

  SerialWombat | a reference to the Serial Wombat chip on which the Resistance Input will be measured

Definition at line 82 of file SerialWombatResistanceInput.h.

## Member Function Documentation

## ◆ begin() [1/3]

int16_t SerialWombatResistanceInput::begin | ( | uint8_t | pin | ) |
| inline

Initialize a resistance input on a given pin.

This intialization turns on sample averaging to 64 samples

Parameters

  pin | The Serial Wombat pin to set. Must be an analog pin (0-4, 16-19)

Returns
  Returns a negative error code if initialization failed.

Definition at line 93 of file SerialWombatResistanceInput.h.

## ◆ begin() [2/3]

int16_t SerialWombatResistanceInput::begin | ( | uint8_t | pin,
|  | uint16_t | averageSamples,
|  | uint16_t | filterConstant )
| inline

Initialize a resistance input on a given pin.

Parameters

  pin | The Serial Wombat pin to set. Must be an analog pin (0-4, 16-19)
  averageSamples | Number of samples to average.
  filterConstant | First Order IIR filter constant, expressed as 1/65536ths . Values closer to 65536 give heavier filtering. Sample frequency is 20Hz.

Returns
  Returns a negative error code if initialization failed.

Definition at line 112 of file SerialWombatResistanceInput.h.

## ◆ begin() [3/3]

int16_t SerialWombatResistanceInput::begin | ( | uint8_t | pin,
|  | uint16_t | averageSamples,
|  | uint16_t | filterConstant,
|  | ResistanceInputPublicDataOutput | output )
| inline

Initialize a resistance input on a given pin.

Parameters

  pin | The Serial Wombat pin to set. Must be an analog pin (0-4, 16-19)
  averageSamples | Number of samples to average.
  filterConstant | First Order IIR filter constant, expressed as 1/65536ths . Values closer to 65536 give heavier filtering. Sample frequency is 20 Hz.
  publicDataOutput | What to output as pin public data

Returns
  Returns a negative error code if initialization failed.

Definition at line 129 of file SerialWombatResistanceInput.h.

## ◆ pin()

uint8_t SerialWombatResistanceInput::pin | ( |  | ) |
| inline virtual

Used for inheritance.

Implements SerialWombatAbstractProcessedInput.

Definition at line 221 of file SerialWombatResistanceInput.h.

## ◆ readAveragedOhms()

uint16_t SerialWombatResistanceInput::readAveragedOhms | ( |  | ) |
| inline

Retreive an averaged Resistance measurement.

Conversion is based on the most recent averaged Resistance value taken by the Serial Wombat at the command time.

Returns
  A 16 bit unsigned value indicating the ohms of the Resistance conversion

Definition at line 164 of file SerialWombatResistanceInput.h.

## ◆ readFilteredOhms()

uint16_t SerialWombatResistanceInput::readFilteredOhms | ( |  | ) |
| inline

Retreive a filtered Resistance measurement.

Conversion is based on the most recent filtered Resistance value taken by the Serial Wombat at the command time.

Returns
  A 16 bit unsigned value indicating the filtered Resistance result

Definition at line 145 of file SerialWombatResistanceInput.h.

## ◆ readMaximumOhms()

uint16_t SerialWombatResistanceInput::readMaximumOhms | ( | bool | resetAfterRead | ) |
| inline

Retreive the maximum single sample Resistance value in Ohms.

The maximum value the Serial Wombat chip has seen on that pin since last reset of Min/Max

Parameters

  resetAfterRead | If True, maximum value is set to 0 after read so that subsequent values become maximum. Also resets minimum to next sample.

Returns
  A 16 bit unsigned value indicating maximum Resistance Ohms

Definition at line 184 of file SerialWombatResistanceInput.h.

## ◆ readMinimumOhms()

uint16_t SerialWombatResistanceInput::readMinimumOhms | ( | bool | resetAfterRead | ) |
| inline

Retreive the maximum single sample Resistance value in Ohms.

The maximum value the Serial Wombat chip has seen on that pin since last reset of Min/Max

Parameters

  resetAfterRead | If True, maximum value is set to 0 after read so that subsequent values become maximum. Also resets minimum to next sample.

Returns
  A 16 bit unsigned value indicating maximum Resistance Ohms

Definition at line 207 of file SerialWombatResistanceInput.h.

## ◆ swPinModeNumber()

uint8_t SerialWombatResistanceInput::swPinModeNumber | ( |  | ) |
| inline virtual

Used for ineheritance.

Implements SerialWombatAbstractProcessedInput.

Definition at line 222 of file SerialWombatResistanceInput.h.