2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/AnalogTrigger.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2018-09-24 00:08:25 -07:00
|
|
|
#include <utility>
|
2016-09-05 13:55:31 -07:00
|
|
|
|
2019-11-08 22:53:20 -08:00
|
|
|
#include <hal/FRCUsageReporting.h>
|
2017-08-27 00:11:52 -07:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/AnalogInput.h"
|
2020-10-03 12:21:03 -04:00
|
|
|
#include "frc/Base.h"
|
2019-11-01 23:41:30 -07:00
|
|
|
#include "frc/DutyCycle.h"
|
2021-04-18 20:35:29 -07:00
|
|
|
#include "frc/Errors.h"
|
2019-09-14 15:22:54 -05:00
|
|
|
#include "frc/smartdashboard/SendableRegistry.h"
|
2015-11-15 14:49:50 -08:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
using namespace frc;
|
|
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
AnalogTrigger::AnalogTrigger(int channel)
|
2016-06-27 21:32:30 -07:00
|
|
|
: AnalogTrigger(new AnalogInput(channel)) {
|
|
|
|
|
m_ownsAnalog = true;
|
2019-09-14 15:22:54 -05:00
|
|
|
SendableRegistry::GetInstance().AddChild(this, m_analogInput);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-06-27 21:32:30 -07:00
|
|
|
AnalogTrigger::AnalogTrigger(AnalogInput* input) {
|
|
|
|
|
m_analogInput = input;
|
|
|
|
|
int32_t status = 0;
|
2019-11-01 23:41:30 -07:00
|
|
|
m_trigger = HAL_InitializeAnalogTrigger(input->m_port, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "Channel {}", input->GetChannel());
|
2019-11-01 23:41:30 -07:00
|
|
|
int index = GetIndex();
|
2016-06-27 21:32:30 -07:00
|
|
|
|
2019-11-01 23:41:30 -07:00
|
|
|
HAL_Report(HALUsageReporting::kResourceType_AnalogTrigger, index + 1);
|
|
|
|
|
SendableRegistry::GetInstance().AddLW(this, "AnalogTrigger", index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AnalogTrigger::AnalogTrigger(DutyCycle* input) {
|
|
|
|
|
m_dutyCycle = input;
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
m_trigger = HAL_InitializeAnalogTriggerDutyCycle(input->m_handle, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "Channel {}", m_dutyCycle->GetSourceChannel());
|
2019-11-01 23:41:30 -07:00
|
|
|
int index = GetIndex();
|
|
|
|
|
|
|
|
|
|
HAL_Report(HALUsageReporting::kResourceType_AnalogTrigger, index + 1);
|
|
|
|
|
SendableRegistry::GetInstance().AddLW(this, "AnalogTrigger", index);
|
2016-06-27 21:32:30 -07:00
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
AnalogTrigger::~AnalogTrigger() {
|
|
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_CleanAnalogTrigger(m_trigger, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_ReportError(status, "Channel {}", GetSourceChannel());
|
2016-06-27 21:32:30 -07:00
|
|
|
|
2018-09-24 00:08:25 -07:00
|
|
|
if (m_ownsAnalog) {
|
2016-06-27 21:32:30 -07:00
|
|
|
delete m_analogInput;
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
void AnalogTrigger::SetLimitsVoltage(double lower, double upper) {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
2018-05-31 20:47:15 -07:00
|
|
|
HAL_SetAnalogTriggerLimitsVoltage(m_trigger, lower, upper, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2019-11-01 23:41:30 -07:00
|
|
|
void AnalogTrigger::SetLimitsDutyCycle(double lower, double upper) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_SetAnalogTriggerLimitsDutyCycle(m_trigger, lower, upper, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
2019-11-01 23:41:30 -07:00
|
|
|
}
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
void AnalogTrigger::SetLimitsRaw(int lower, int upper) {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
2018-05-31 20:47:15 -07:00
|
|
|
HAL_SetAnalogTriggerLimitsRaw(m_trigger, lower, upper, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
void AnalogTrigger::SetAveraged(bool useAveragedValue) {
|
|
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_SetAnalogTriggerAveraged(m_trigger, useAveragedValue, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
void AnalogTrigger::SetFiltered(bool useFilteredValue) {
|
|
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_SetAnalogTriggerFiltered(m_trigger, useFilteredValue, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
int AnalogTrigger::GetIndex() const {
|
2019-11-01 23:41:30 -07:00
|
|
|
int32_t status = 0;
|
|
|
|
|
auto ret = HAL_GetAnalogTriggerFPGAIndex(m_trigger, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
2019-11-01 23:41:30 -07:00
|
|
|
return ret;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
bool AnalogTrigger::GetInWindow() {
|
|
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
bool result = HAL_GetAnalogTriggerInWindow(m_trigger, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
2015-06-25 15:07:55 -04:00
|
|
|
return result;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
bool AnalogTrigger::GetTriggerState() {
|
|
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
bool result = HAL_GetAnalogTriggerTriggerState(m_trigger, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
2015-06-25 15:07:55 -04:00
|
|
|
return result;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-07-29 16:48:04 -04:00
|
|
|
std::shared_ptr<AnalogTriggerOutput> AnalogTrigger::CreateOutput(
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
AnalogTriggerType type) const {
|
2015-07-29 16:48:04 -04:00
|
|
|
return std::shared_ptr<AnalogTriggerOutput>(
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
new AnalogTriggerOutput(*this, type), NullDeleter<AnalogTriggerOutput>());
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
void AnalogTrigger::InitSendable(SendableBuilder& builder) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (m_ownsAnalog) {
|
|
|
|
|
m_analogInput->InitSendable(builder);
|
|
|
|
|
}
|
2017-12-04 23:28:33 -08:00
|
|
|
}
|
2021-05-23 19:33:33 -07:00
|
|
|
|
|
|
|
|
int AnalogTrigger::GetSourceChannel() const {
|
|
|
|
|
if (m_analogInput) {
|
|
|
|
|
return m_analogInput->GetChannel();
|
|
|
|
|
} else if (m_dutyCycle) {
|
|
|
|
|
return m_dutyCycle->GetSourceChannel();
|
|
|
|
|
} else {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|