Continued work

This commit is contained in:
2024-07-25 18:46:17 +03:00
parent 8c47b9cae8
commit 6219290880
60 changed files with 2024 additions and 2057 deletions

View File

@@ -11,12 +11,9 @@ using namespace hw;
/**** Private function declarations ****/
/**** Public function definitions ****/
hw::Potentiometer::Potentiometer(bsp::AnalogIn* ain_ch, uint16_t low_deadzone, uint16_t high_deadzone)
hw::Potentiometer::Potentiometer(void)
{
this->ain_ch = ain_ch;
this->low_deadzone = low_deadzone;
this->high_deadzone = high_deadzone;
this->percent = 0;
return;
}
hw::Potentiometer::~Potentiometer(void)
@@ -24,14 +21,26 @@ hw::Potentiometer::~Potentiometer(void)
return;
}
uint8_t hw::Potentiometer::update(void)
void hw::Potentiometer::init(bsp::AnalogIn* ain_ch, uint16_t low_deadzone, uint16_t high_deadzone)
{
// 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);
this->ain_ch = ain_ch;
this->low_deadzone = low_deadzone;
this->high_deadzone = high_deadzone;
this->last_percent = 0;
this->update_ain = 1;
}
uint8_t hw::Potentiometer::read(void)
{
// Update analog input
if(this->update_ain) this->ain_ch->read();
return this->percent;
// Calculate percent
if(this->ain_ch->last_read <= this->low_deadzone) this->last_percent = 0;
else if(this->ain_ch->last_read >= this->high_deadzone ) this->last_percent = 100;
else this->last_percent = util::interpolate(this->ain_ch->last_read, this->low_deadzone, this->high_deadzone, 0, 100);
return this->last_percent;
}
/**** Private function definitions ****/