MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/driver/TableAdcResult.cpp
2024-06-07 11:12:56 +03:00

91 lines
1.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* TableAdcResult.cpp
*
* Created on: 29 июл. 2019 г.
* Author: titov
*/
#include "TableAdcResult.hh"
#include <cmath>
#include <stdint.h>
driver::TableAdcResult::TableAdcResult(const volatile uint16_t** result,
const volatile uint16_t** buff, Id size) : data(result), buff(buff), size(size), quantity(0) {
for( Id id = 0; id < size; ++id ) {
result[id] = buff[id] = nullptr;
}
}
uint32_t driver::TableAdcResult::sum() const {
uint32_t temp = 0;
for( Id i = 0; i < quantity; ++i )
temp += *buff[i];
return temp;
}
bool driver::TableAdcResult::attach( peripheral::IAdcResult<uint16_t> * adc_result, Id position ) {
if( position < size and not data[position] and quantity < size ) {
return ( buff[quantity++] = data[position] = adc_result->result() );
} else return false;
}
const volatile float & driver::TableAdcAsValue::getValue() const {
return result;
}
bool driver::TableAdcAsValue::configure( Setting & config ) {
if( config.isValid() ) {
offset = config.offset;
coeff = config.coeff;
return true;
} else return false;
}
void driver::TableAdcAsValue::process() {
if( is_filled() ) {
uint32_t temp = sum();
result = temp * coeff + offset; //todo: hren
} else
result = NAN;
}
driver::TableAdcAsAdcChannel::operator uint32_t() const {
return sum();
}
bool driver::TableAdcAsValue::Setting::isValid() const {
using namespace std;
return isfinite( coeff ) and isfinite( offset );
}
bool driver::TableAdcResult::is_filled() const {
return size == quantity;
}