/* * TableAdcResult.cpp * * Created on: 29 èþë. 2019 ã. * Author: titov */ #include "TableAdcResult.hh" #include #include 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 * 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; }