mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Major formatting changes (breaks diffs). No code changes.
The changes made in this commit do not affect any actual code,
they are purely aesthetic. I ran clang-format with google style
over all .h/.cpp files in wpilibc that weren't in wpilibC++Sim
or gtest, and the eclipse formatter over all of the Java files
using the Google eclipse formatting configuration.
Change-Id: I9627bca0bc103c398ecc1c5ba17467193291ae63
This commit is contained in:
@@ -14,50 +14,45 @@
|
||||
* Creates a digital output given a channel. Common creation routine for all
|
||||
* constructors.
|
||||
*/
|
||||
void DigitalOutput::InitDigitalOutput(uint32_t channel)
|
||||
{
|
||||
m_table = NULL;
|
||||
char buf[64];
|
||||
void DigitalOutput::InitDigitalOutput(uint32_t channel) {
|
||||
m_table = NULL;
|
||||
char buf[64];
|
||||
|
||||
if (!CheckDigitalChannel(channel))
|
||||
{
|
||||
snprintf(buf, 64, "Digital Channel %d", channel);
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
|
||||
return;
|
||||
}
|
||||
m_channel = channel;
|
||||
m_pwmGenerator = (void *)~0ul;
|
||||
if (!CheckDigitalChannel(channel)) {
|
||||
snprintf(buf, 64, "Digital Channel %d", channel);
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
|
||||
return;
|
||||
}
|
||||
m_channel = channel;
|
||||
m_pwmGenerator = (void *)~0ul;
|
||||
|
||||
int32_t status = 0;
|
||||
allocateDIO(m_digital_ports[channel], false, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
int32_t status = 0;
|
||||
allocateDIO(m_digital_ports[channel], false, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
|
||||
HALReport(HALUsageReporting::kResourceType_DigitalOutput, channel);
|
||||
HALReport(HALUsageReporting::kResourceType_DigitalOutput, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of a digital output.
|
||||
* Create a digital output given a channel.
|
||||
*
|
||||
* @param channel The digital channel 0-9 are on-board, 10-25 are on the MXP port
|
||||
* @param channel The digital channel 0-9 are on-board, 10-25 are on the MXP
|
||||
* port
|
||||
*/
|
||||
DigitalOutput::DigitalOutput(uint32_t channel)
|
||||
{
|
||||
InitDigitalOutput(channel);
|
||||
}
|
||||
DigitalOutput::DigitalOutput(uint32_t channel) { InitDigitalOutput(channel); }
|
||||
|
||||
/**
|
||||
* Free the resources associated with a digital output.
|
||||
*/
|
||||
DigitalOutput::~DigitalOutput()
|
||||
{
|
||||
if (StatusIsFatal()) return;
|
||||
// Disable the PWM in case it was running.
|
||||
DisablePWM();
|
||||
DigitalOutput::~DigitalOutput() {
|
||||
if (StatusIsFatal()) return;
|
||||
// Disable the PWM in case it was running.
|
||||
DisablePWM();
|
||||
|
||||
int32_t status = 0;
|
||||
freeDIO(m_digital_ports[m_channel], &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
int32_t status = 0;
|
||||
freeDIO(m_digital_ports[m_channel], &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,68 +60,63 @@ DigitalOutput::~DigitalOutput()
|
||||
* Set the value of a digital output to either one (true) or zero (false).
|
||||
* @param value 1 (true) for high, 0 (false) for disabled
|
||||
*/
|
||||
void DigitalOutput::Set(uint32_t value)
|
||||
{
|
||||
if (StatusIsFatal()) return;
|
||||
void DigitalOutput::Set(uint32_t value) {
|
||||
if (StatusIsFatal()) return;
|
||||
|
||||
int32_t status = 0;
|
||||
setDIO(m_digital_ports[m_channel], value, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
int32_t status = 0;
|
||||
setDIO(m_digital_ports[m_channel], value, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The GPIO channel number that this object represents.
|
||||
*/
|
||||
uint32_t DigitalOutput::GetChannel() const
|
||||
{
|
||||
return m_channel;
|
||||
}
|
||||
uint32_t DigitalOutput::GetChannel() const { return m_channel; }
|
||||
|
||||
/**
|
||||
* Output a single pulse on the digital output line.
|
||||
* Send a single pulse on the digital output line where the pulse duration is specified in seconds.
|
||||
* Send a single pulse on the digital output line where the pulse duration is
|
||||
* specified in seconds.
|
||||
* Maximum pulse length is 0.0016 seconds.
|
||||
* @param length The pulselength in seconds
|
||||
*/
|
||||
void DigitalOutput::Pulse(float length)
|
||||
{
|
||||
if (StatusIsFatal()) return;
|
||||
void DigitalOutput::Pulse(float length) {
|
||||
if (StatusIsFatal()) return;
|
||||
|
||||
int32_t status = 0;
|
||||
pulse(m_digital_ports[m_channel], length, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
int32_t status = 0;
|
||||
pulse(m_digital_ports[m_channel], length, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the pulse is still going.
|
||||
* Determine if a previously started pulse is still going.
|
||||
*/
|
||||
bool DigitalOutput::IsPulsing() const
|
||||
{
|
||||
if (StatusIsFatal()) return false;
|
||||
bool DigitalOutput::IsPulsing() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
|
||||
int32_t status = 0;
|
||||
bool value = isPulsing(m_digital_ports[m_channel], &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
return value;
|
||||
int32_t status = 0;
|
||||
bool value = isPulsing(m_digital_ports[m_channel], &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the PWM frequency of the PWM output on a Digital Output line.
|
||||
*
|
||||
* The valid range is from 0.6 Hz to 19 kHz. The frequency resolution is logarithmic.
|
||||
* The valid range is from 0.6 Hz to 19 kHz. The frequency resolution is
|
||||
* logarithmic.
|
||||
*
|
||||
* There is only one PWM frequency for all digital channels.
|
||||
*
|
||||
* @param rate The frequency to output all digital output PWM signals.
|
||||
*/
|
||||
void DigitalOutput::SetPWMRate(float rate)
|
||||
{
|
||||
if (StatusIsFatal()) return;
|
||||
void DigitalOutput::SetPWMRate(float rate) {
|
||||
if (StatusIsFatal()) return;
|
||||
|
||||
int32_t status = 0;
|
||||
setPWMRate(rate, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
int32_t status = 0;
|
||||
setPWMRate(rate, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,30 +124,30 @@ void DigitalOutput::SetPWMRate(float rate)
|
||||
*
|
||||
* Allocate one of the 6 DO PWM generator resources from this module.
|
||||
*
|
||||
* Supply the initial duty-cycle to output so as to avoid a glitch when first starting.
|
||||
* Supply the initial duty-cycle to output so as to avoid a glitch when first
|
||||
* starting.
|
||||
*
|
||||
* The resolution of the duty cycle is 8-bit for low frequencies (1kHz or less)
|
||||
* but is reduced the higher the frequency of the PWM signal is.
|
||||
*
|
||||
* @param initialDutyCycle The duty-cycle to start generating. [0..1]
|
||||
*/
|
||||
void DigitalOutput::EnablePWM(float initialDutyCycle)
|
||||
{
|
||||
if(m_pwmGenerator != (void *)~0ul) return;
|
||||
void DigitalOutput::EnablePWM(float initialDutyCycle) {
|
||||
if (m_pwmGenerator != (void *)~0ul) return;
|
||||
|
||||
int32_t status = 0;
|
||||
int32_t status = 0;
|
||||
|
||||
if(StatusIsFatal()) return;
|
||||
m_pwmGenerator = allocatePWM(&status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
if (StatusIsFatal()) return;
|
||||
m_pwmGenerator = allocatePWM(&status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
|
||||
if(StatusIsFatal()) return;
|
||||
setPWMDutyCycle(m_pwmGenerator, initialDutyCycle, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
if (StatusIsFatal()) return;
|
||||
setPWMDutyCycle(m_pwmGenerator, initialDutyCycle, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
|
||||
if(StatusIsFatal()) return;
|
||||
setPWMOutputChannel(m_pwmGenerator, m_channel, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
if (StatusIsFatal()) return;
|
||||
setPWMOutputChannel(m_pwmGenerator, m_channel, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,21 +155,20 @@ void DigitalOutput::EnablePWM(float initialDutyCycle)
|
||||
*
|
||||
* Free up one of the 6 DO PWM generator resources that were in use.
|
||||
*/
|
||||
void DigitalOutput::DisablePWM()
|
||||
{
|
||||
if (StatusIsFatal()) return;
|
||||
if(m_pwmGenerator == (void *)~0ul) return;
|
||||
void DigitalOutput::DisablePWM() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (m_pwmGenerator == (void *)~0ul) return;
|
||||
|
||||
int32_t status = 0;
|
||||
int32_t status = 0;
|
||||
|
||||
// Disable the output by routing to a dead bit.
|
||||
setPWMOutputChannel(m_pwmGenerator, kDigitalChannels, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
// Disable the output by routing to a dead bit.
|
||||
setPWMOutputChannel(m_pwmGenerator, kDigitalChannels, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
|
||||
freePWM(m_pwmGenerator, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
freePWM(m_pwmGenerator, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
|
||||
m_pwmGenerator = (void *)~0ul;
|
||||
m_pwmGenerator = (void *)~0ul;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,67 +179,55 @@ void DigitalOutput::DisablePWM()
|
||||
*
|
||||
* @param dutyCycle The duty-cycle to change to. [0..1]
|
||||
*/
|
||||
void DigitalOutput::UpdateDutyCycle(float dutyCycle)
|
||||
{
|
||||
if (StatusIsFatal()) return;
|
||||
void DigitalOutput::UpdateDutyCycle(float dutyCycle) {
|
||||
if (StatusIsFatal()) return;
|
||||
|
||||
int32_t status = 0;
|
||||
setPWMDutyCycle(m_pwmGenerator, dutyCycle, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
int32_t status = 0;
|
||||
setPWMDutyCycle(m_pwmGenerator, dutyCycle, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The value to be written to the channel field of a routing mux.
|
||||
*/
|
||||
uint32_t DigitalOutput::GetChannelForRouting() const
|
||||
{
|
||||
return GetChannel();
|
||||
}
|
||||
uint32_t DigitalOutput::GetChannelForRouting() const { return GetChannel(); }
|
||||
|
||||
/**
|
||||
* @return The value to be written to the module field of a routing mux.
|
||||
*/
|
||||
uint32_t DigitalOutput::GetModuleForRouting() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
uint32_t DigitalOutput::GetModuleForRouting() const { return 0; }
|
||||
|
||||
/**
|
||||
* @return The value to be written to the analog trigger field of a routing mux.
|
||||
*/
|
||||
bool DigitalOutput::GetAnalogTriggerForRouting() const
|
||||
{
|
||||
return false;
|
||||
bool DigitalOutput::GetAnalogTriggerForRouting() const { return false; }
|
||||
|
||||
void DigitalOutput::ValueChanged(ITable *source, const std::string &key,
|
||||
EntryValue value, bool isNew) {
|
||||
Set(value.b);
|
||||
}
|
||||
|
||||
void DigitalOutput::ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew) {
|
||||
Set(value.b);
|
||||
}
|
||||
|
||||
void DigitalOutput::UpdateTable() {
|
||||
}
|
||||
void DigitalOutput::UpdateTable() {}
|
||||
|
||||
void DigitalOutput::StartLiveWindowMode() {
|
||||
if (m_table != NULL) {
|
||||
m_table->AddTableListener("Value", this, true);
|
||||
}
|
||||
if (m_table != NULL) {
|
||||
m_table->AddTableListener("Value", this, true);
|
||||
}
|
||||
}
|
||||
|
||||
void DigitalOutput::StopLiveWindowMode() {
|
||||
if (m_table != NULL) {
|
||||
m_table->RemoveTableListener(this);
|
||||
}
|
||||
if (m_table != NULL) {
|
||||
m_table->RemoveTableListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
std::string DigitalOutput::GetSmartDashboardType() const {
|
||||
return "Digital Output";
|
||||
return "Digital Output";
|
||||
}
|
||||
|
||||
void DigitalOutput::InitTable(ITable *subTable) {
|
||||
m_table = subTable;
|
||||
UpdateTable();
|
||||
m_table = subTable;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
ITable * DigitalOutput::GetTable() const {
|
||||
return m_table;
|
||||
}
|
||||
ITable *DigitalOutput::GetTable() const { return m_table; }
|
||||
|
||||
Reference in New Issue
Block a user