#include "AP_DAC.h"
#if AP_DAC_ENABLED
#include "AP_DAC.h"
#include "AP_DAC_Params.h"
#include "AP_DAC_TIx3204.h"
#include "AP_DAC_MCP40D1x.h"
const AP_Param::GroupInfo AP_DAC::var_info[] = {
AP_SUBGROUPINFO(params[0], "1_", 1, AP_DAC, AP_DAC_Params),
AP_GROUPEND
};
AP_DAC::AP_DAC()
{
AP_Param::setup_object_defaults(this, var_info);
}
void AP_DAC::init()
{
for (uint8_t i = 0; i < ARRAY_SIZE(params); i++) {
const AP_DAC_Params::Type type = params[i].type;
switch (type) {
#if AP_DAC_TIX3204_ENABLED
case AP_DAC_Params::Type::TIx3204:
backends[i] = new AP_DAC_TIx3204(params[i]);
break;
#endif
#if AP_DAC_MCP40D1X_ENABLED
case AP_DAC_Params::Type::MCP40D1x:
backends[i] = new AP_DAC_MCP40D1x(params[i]);
break;
#endif
case AP_DAC_Params::Type::NONE:
break;
}
if (backends[i] != nullptr) {
backends[i]->init();
}
}
}
bool AP_DAC::set_voltage(uint8_t instance, uint8_t channel, float voltage)
{
if (instance >= ARRAY_SIZE(backends)) {
return false;
}
if (backends[instance] == nullptr) {
return false;
}
return backends[instance]->set_voltage(channel, voltage);
}
void AP_DAC::update()
{
for (uint8_t i = 0; i < ARRAY_SIZE(backends); i++) {
if (backends[i] != nullptr) {
backends[i]->update();
}
}
}
#endif