Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_DAC/AP_DAC.cpp
4182 views
1
/*
2
This program is free software: you can redistribute it and/or modify
3
it under the terms of the GNU General Public License as published by
4
the Free Software Foundation, either version 3 of the License, or
5
(at your option) any later version.
6
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
11
12
You should have received a copy of the GNU General Public License
13
along with this program. If not, see <http://www.gnu.org/licenses/>.
14
*/
15
16
#include "AP_DAC.h"
17
18
#if AP_DAC_ENABLED
19
20
#include "AP_DAC.h"
21
#include "AP_DAC_Params.h"
22
#include "AP_DAC_TIx3204.h"
23
#include "AP_DAC_MCP40D1x.h"
24
25
const AP_Param::GroupInfo AP_DAC::var_info[] = {
26
27
// @Group: 1_
28
// @Path: AP_DAC_Params.cpp
29
AP_SUBGROUPINFO(params[0], "1_", 1, AP_DAC, AP_DAC_Params),
30
31
AP_GROUPEND
32
};
33
34
// Constructor
35
AP_DAC::AP_DAC()
36
{
37
AP_Param::setup_object_defaults(this, var_info);
38
}
39
40
/*
41
init - instantiate the DACs
42
*/
43
void AP_DAC::init()
44
{
45
for (uint8_t i = 0; i < ARRAY_SIZE(params); i++) {
46
const AP_DAC_Params::Type type = params[i].type;
47
switch (type) {
48
#if AP_DAC_TIX3204_ENABLED
49
case AP_DAC_Params::Type::TIx3204:
50
backends[i] = new AP_DAC_TIx3204(params[i]);
51
break;
52
#endif
53
#if AP_DAC_MCP40D1X_ENABLED
54
case AP_DAC_Params::Type::MCP40D1x:
55
backends[i] = new AP_DAC_MCP40D1x(params[i]);
56
break;
57
#endif
58
case AP_DAC_Params::Type::NONE:
59
break;
60
}
61
if (backends[i] != nullptr) {
62
backends[i]->init();
63
}
64
}
65
}
66
67
/*
68
set output voltage on a channel
69
*/
70
bool AP_DAC::set_voltage(uint8_t instance, uint8_t channel, float voltage)
71
{
72
if (instance >= ARRAY_SIZE(backends)) {
73
return false;
74
}
75
if (backends[instance] == nullptr) {
76
return false;
77
}
78
return backends[instance]->set_voltage(channel, voltage);
79
}
80
81
void AP_DAC::update()
82
{
83
for (uint8_t i = 0; i < ARRAY_SIZE(backends); i++) {
84
if (backends[i] != nullptr) {
85
backends[i]->update();
86
}
87
}
88
}
89
90
#endif // AP_DAC_ENABLED
91
92