blob: fa312c12e006603298e29508a90a6be8f0547037 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001
2#include "AnalogPotentiometer.h"
3
4/**
5 * Common initialization code called by all constructors.
6 */
7void AnalogPotentiometer::initPot(AnalogInput *input, double scale, double offset) {
8 m_scale = scale;
9 m_offset = offset;
10 m_analog_input = input;
11}
12
13AnalogPotentiometer::AnalogPotentiometer(int channel, double scale, double offset) {
14 m_init_analog_input = true;
15 initPot(new AnalogInput(channel), scale, offset);
16}
17
18AnalogPotentiometer::AnalogPotentiometer(AnalogInput *input, double scale, double offset) {
19 m_init_analog_input = false;
20 initPot(input, scale, offset);
21}
22
23AnalogPotentiometer::AnalogPotentiometer(AnalogInput &input, double scale, double offset) {
24 m_init_analog_input = false;
25 initPot(&input, scale, offset);
26}
27
28AnalogPotentiometer::~AnalogPotentiometer() {
29 if(m_init_analog_input){
30 delete m_analog_input;
31 m_init_analog_input = false;
32 }
33}
34
35/**
36 * Get the current reading of the potentiomere.
37 *
38 * @return The current position of the potentiometer.
39 */
40double AnalogPotentiometer::Get() const {
41 return m_analog_input->GetVoltage() * m_scale + m_offset;
42}
43
44/**
45 * Implement the PIDSource interface.
46 *
47 * @return The current reading.
48 */
49double AnalogPotentiometer::PIDGet() {
50 return Get();
51}
52
53
54/**
55 * @return the Smart Dashboard Type
56 */
57std::string AnalogPotentiometer::GetSmartDashboardType() const {
58 return "Analog Input";
59}
60
61/**
62 * Live Window code, only does anything if live window is activated.
63 */
64void AnalogPotentiometer::InitTable(std::shared_ptr<ITable> subtable) {
65 m_table = subtable;
66 UpdateTable();
67}
68
69void AnalogPotentiometer::UpdateTable() {
70 if (m_table != nullptr) {
71 m_table->PutNumber("Value", Get());
72 }
73}
74
75std::shared_ptr<ITable> AnalogPotentiometer::GetTable() const {
76 return m_table;
77}