Files
allwpilib/wpilibc/sim/src/AnalogInput.cpp
Tyler Veness 0cb288ffba Fixes warnings thrown by cpplint.py (#154)
* Fixed cpplint.py [runtime/int] warnings

* Fixed cpplint.py [readability/casting] warnings

* Fixed cpplint.py [readability/namespace] warnings

* Fixed cpplint.py [readability/braces] warnings

* Fixed cpplint.py [whitespace/braces] warnings

* Fixed cpplint.py [runtime/explicit] warnings

* Fixed cpplint.py [runtime/printf] warnings

* Fixed cpplint.py [readability/inheritance] warnings

* Fixed cpplint.py [whitespace/tab] warnings

* Fixed cpplint.py [build/storage_class] warnings

* Fixed cpplint.py [readability/multiline_comment] warnings

* Fixed cpplint.py [whitespace/semicolon] warnings

* Fixed cpplint.py [readability/check] warnings

* Fixed cpplint.py [runtime/arrays] warnings

* Ran format.py
2016-07-10 17:47:44 -07:00

86 lines
2.5 KiB
C++

/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "AnalogInput.h"
#include <sstream>
#include "LiveWindow/LiveWindow.h"
#include "WPIErrors.h"
/**
* Construct an analog input.
*
* @param channel The channel number to represent.
*/
AnalogInput::AnalogInput(uint32_t channel) : m_channel(channel) {
std::stringstream ss;
ss << "analog/" << channel;
m_impl = new SimFloatInput(ss.str());
LiveWindow::GetInstance()->AddSensor("AnalogInput", channel, this);
}
/**
* Get a scaled sample straight from this channel.
*
* The value is scaled to units of Volts using the calibrated scaling data from
* GetLSBWeight() and GetOffset().
*
* @return A scaled sample straight from this channel.
*/
float AnalogInput::GetVoltage() const { return m_impl->Get(); }
/**
* Get a scaled sample from the output of the oversample and average engine for
* this channel.
*
* The value is scaled to units of Volts using the calibrated scaling data from
* GetLSBWeight() and GetOffset(). Using oversampling will cause this value to
* be higher resolution, but it will update more slowly. Using averaging will
* cause this value to be more stable, but it will update more slowly.
*
* @return A scaled sample from the output of the oversample and average engine
* for this channel.
*/
float AnalogInput::GetAverageVoltage() const { return m_impl->Get(); }
/**
* Get the channel number.
*
* @return The channel number.
*/
uint32_t AnalogInput::GetChannel() const { return m_channel; }
/**
* Get the Average value for the PID Source base object.
*
* @return The average voltage.
*/
double AnalogInput::PIDGet() { return GetAverageVoltage(); }
void AnalogInput::UpdateTable() {
if (m_table != nullptr) {
m_table->PutNumber("Value", GetAverageVoltage());
}
}
void AnalogInput::StartLiveWindowMode() {}
void AnalogInput::StopLiveWindowMode() {}
std::string AnalogInput::GetSmartDashboardType() const {
return "Analog Input";
}
void AnalogInput::InitTable(std::shared_ptr<ITable> subTable) {
m_table = subTable;
UpdateTable();
}
std::shared_ptr<ITable> AnalogInput::GetTable() const { return m_table; }