Skip to content

Commit

Permalink
AnalogControl: added explicit setters for scale and offset
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhensley committed Sep 20, 2024
1 parent 5112a86 commit 8229443
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/hid/ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
namespace daisy
{
/**
@brief Hardware Interface for control inputs \n
Primarily designed for ADC input controls such as \n
potentiometers, and control voltage. \n
@brief Hardware Interface for control inputs \n
Primarily designed for ADC input controls such as \n
potentiometers, and control voltage. \n
@author Stephen Hensley
@date November 2019
@ingroup controls
Expand All @@ -22,7 +22,7 @@ class AnalogControl
/** destructor */
~AnalogControl() {}

/**
/**
Initializes the control
\param *adcptr is a pointer to the raw adc read value -- This can be acquired with dsy_adc_get_rawptr(), or dsy_adc_get_mux_rawptr()
\param sr is the samplerate in Hz that the Process function will be called at.
Expand All @@ -36,17 +36,17 @@ class AnalogControl
bool invert = false,
float slew_seconds = 0.002f);

/**
/**
This Initializes the AnalogControl for a -5V to 5V inverted input
All of the Init details are the same otherwise
\param *adcptr Pointer to analog digital converter
\param sr Audio engine sample rate
*/
void InitBipolarCv(uint16_t *adcptr, float sr);

/**
/**
Filters, and transforms a raw ADC read into a normalized range.
this should be called at the rate of specified by samplerate at Init time.
this should be called at the rate of specified by samplerate at Init time.
Default Initializations will return 0.0 -> 1.0
Bi-polar CV inputs will return -1.0 -> 1.0
*/
Expand All @@ -55,7 +55,7 @@ class AnalogControl
/** Returns the current stored value, without reprocessing */
inline float Value() const { return val_; }

/** Directly set the Coefficient of the one pole smoothing filter.
/** Directly set the Coefficient of the one pole smoothing filter.
\param val Value to set coefficient to. Max of 1, min of 0.
*/
// using conditionals since clamp() is unavailable
Expand All @@ -67,6 +67,18 @@ class AnalogControl
coeff_ = val;
}

/** Directly set the scaling factor used by the process function
* Normally this will be set during initialization, but
* the can be used when calibartion data is used to adjust the control.
*/
inline void SetScale(const float scale) { scale_ = scale; }

/** Directly set the offset used by the process function
* Normally this will be set during initialization, but
* the can be used when calibartion data is used to adjust the control.
*/
inline void SetOffset(const float offset) { offset_ = offset; }

/** Returns the raw unsigned 16-bit value from the ADC */
inline uint16_t GetRawValue() { return *raw_; }

Expand Down

0 comments on commit 8229443

Please sign in to comment.