Refactor UI code for analog input calibration script. Display voltage for a more clear matching calibration.

This commit is contained in:
2025-05-25 14:40:38 -07:00
parent db8c894927
commit 506293fa9c
2 changed files with 57 additions and 42 deletions

View File

@ -19,7 +19,7 @@ class AnalogInput {
~AnalogInput() {}
/**
* @brief Initializes a analog input object.
* Initializes a analog input object.
*
* @param pin gpio pin for the analog input.
*/
@ -29,7 +29,7 @@ class AnalogInput {
}
/**
* @brief Read the value of the analog input.
* Read the value of the analog input and set instance state.
*
*/
void Process() {
@ -41,16 +41,25 @@ class AnalogInput {
// Set calibration values.
void AdjustCalibrationLow(int amount) { low_ += amount; }
void AdjustCalibrationOffset(int amount) { offset_ += amount; }
void AdjustCalibrationOffset(int amount) { offset_ -= amount; }
void AdjustCalibrationHigh(int amount) { high_ += amount; }
/**
* @brief Get the current value of the analog input within a range of +/-512.
* Get the current value of the analog input within a range of +/-512.
*
* @return read value within a range of +/-512.
*
*/
inline int16_t Read() { return read_; }
/**
* Return the analog read value as voltage.
*
* @return A float representing the voltage (-5.0 to +5.0).
*
*/
inline float Voltage() { return ((read_ / 512.0) * 5.0); }
private:
uint8_t pin_;
int16_t read_;