/**** Includes ****/ #include "../utils/utils.h" #include "../utils/interpolate.h" #include "potentiometer.h" using namespace hw; /**** Private definitions ****/ /**** Private constants ****/ /**** Private variables ****/ /**** Private function declarations ****/ /**** Public function definitions ****/ hw::Potentiometer::Potentiometer(bsp::AnalogIn* ain_ch, uint16_t low_deadzone, uint16_t high_deadzone) { this->ain_ch = ain_ch; this->low_deadzone = low_deadzone; this->high_deadzone = high_deadzone; this->percent = 0; } hw::Potentiometer::~Potentiometer(void) { return; } uint8_t hw::Potentiometer::update(void) { // Calculate percent if(this->ain_ch->last_read <= this->low_deadzone) this->percent = 0; else if(this->ain_ch->last_read >= this->high_deadzone ) this->percent = 100; else this->percent = util::interpolate(this->ain_ch->last_read, this->low_deadzone, this->high_deadzone, 0, 100); return this->percent; } /**** Private function definitions ****/