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:
@@ -15,19 +15,19 @@ static const double kDelayTime = 0.01;
|
||||
* A fixture with an analog input and an analog output wired together
|
||||
*/
|
||||
class AnalogLoopTest : public testing::Test {
|
||||
protected:
|
||||
AnalogInput *m_input;
|
||||
AnalogOutput *m_output;
|
||||
protected:
|
||||
AnalogInput *m_input;
|
||||
AnalogOutput *m_output;
|
||||
|
||||
virtual void SetUp() override {
|
||||
m_input = new AnalogInput(TestBench::kFakeAnalogOutputChannel);
|
||||
m_output = new AnalogOutput(TestBench::kAnalogOutputChannel);
|
||||
}
|
||||
virtual void SetUp() override {
|
||||
m_input = new AnalogInput(TestBench::kFakeAnalogOutputChannel);
|
||||
m_output = new AnalogOutput(TestBench::kAnalogOutputChannel);
|
||||
}
|
||||
|
||||
virtual void TearDown() override {
|
||||
delete m_input;
|
||||
delete m_output;
|
||||
}
|
||||
virtual void TearDown() override {
|
||||
delete m_input;
|
||||
delete m_output;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -35,14 +35,14 @@ protected:
|
||||
* matches.
|
||||
*/
|
||||
TEST_F(AnalogLoopTest, AnalogInputWorks) {
|
||||
// Set the output voltage and check if the input measures the same voltage
|
||||
for(int i = 0; i < 50; i++) {
|
||||
m_output->SetVoltage(i / 10.0f);
|
||||
// Set the output voltage and check if the input measures the same voltage
|
||||
for (int i = 0; i < 50; i++) {
|
||||
m_output->SetVoltage(i / 10.0f);
|
||||
|
||||
Wait(kDelayTime);
|
||||
Wait(kDelayTime);
|
||||
|
||||
EXPECT_NEAR(m_output->GetVoltage(), m_input->GetVoltage(), 0.01f);
|
||||
}
|
||||
EXPECT_NEAR(m_output->GetVoltage(), m_input->GetVoltage(), 0.01f);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,26 +50,29 @@ TEST_F(AnalogLoopTest, AnalogInputWorks) {
|
||||
* range correctly.
|
||||
*/
|
||||
TEST_F(AnalogLoopTest, AnalogTriggerWorks) {
|
||||
AnalogTrigger trigger(m_input);
|
||||
trigger.SetLimitsVoltage(2.0f, 3.0f);
|
||||
AnalogTrigger trigger(m_input);
|
||||
trigger.SetLimitsVoltage(2.0f, 3.0f);
|
||||
|
||||
m_output->SetVoltage(1.0f);
|
||||
Wait(kDelayTime);
|
||||
m_output->SetVoltage(1.0f);
|
||||
Wait(kDelayTime);
|
||||
|
||||
EXPECT_FALSE(trigger.GetInWindow()) << "Analog trigger is in the window (2V, 3V)";
|
||||
EXPECT_FALSE(trigger.GetTriggerState()) << "Analog trigger is on";
|
||||
EXPECT_FALSE(trigger.GetInWindow())
|
||||
<< "Analog trigger is in the window (2V, 3V)";
|
||||
EXPECT_FALSE(trigger.GetTriggerState()) << "Analog trigger is on";
|
||||
|
||||
m_output->SetVoltage(2.5f);
|
||||
Wait(kDelayTime);
|
||||
m_output->SetVoltage(2.5f);
|
||||
Wait(kDelayTime);
|
||||
|
||||
EXPECT_TRUE(trigger.GetInWindow()) << "Analog trigger is not in the window (2V, 3V)";
|
||||
EXPECT_FALSE(trigger.GetTriggerState()) << "Analog trigger is on";
|
||||
EXPECT_TRUE(trigger.GetInWindow())
|
||||
<< "Analog trigger is not in the window (2V, 3V)";
|
||||
EXPECT_FALSE(trigger.GetTriggerState()) << "Analog trigger is on";
|
||||
|
||||
m_output->SetVoltage(4.0f);
|
||||
Wait(kDelayTime);
|
||||
m_output->SetVoltage(4.0f);
|
||||
Wait(kDelayTime);
|
||||
|
||||
EXPECT_FALSE(trigger.GetInWindow()) << "Analog trigger is in the window (2V, 3V)";
|
||||
EXPECT_TRUE(trigger.GetTriggerState()) << "Analog trigger is not on";
|
||||
EXPECT_FALSE(trigger.GetInWindow())
|
||||
<< "Analog trigger is in the window (2V, 3V)";
|
||||
EXPECT_TRUE(trigger.GetTriggerState()) << "Analog trigger is not on";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,46 +80,47 @@ TEST_F(AnalogLoopTest, AnalogTriggerWorks) {
|
||||
* a counter.
|
||||
*/
|
||||
TEST_F(AnalogLoopTest, AnalogTriggerCounterWorks) {
|
||||
AnalogTrigger trigger(m_input);
|
||||
trigger.SetLimitsVoltage(2.0f, 3.0f);
|
||||
AnalogTrigger trigger(m_input);
|
||||
trigger.SetLimitsVoltage(2.0f, 3.0f);
|
||||
|
||||
Counter counter(trigger);
|
||||
Counter counter(trigger);
|
||||
|
||||
// Turn the analog output low and high 50 times
|
||||
for(int i = 0; i < 50; i++) {
|
||||
m_output->SetVoltage(1.0);
|
||||
Wait(kDelayTime);
|
||||
m_output->SetVoltage(4.0);
|
||||
Wait(kDelayTime);
|
||||
}
|
||||
// Turn the analog output low and high 50 times
|
||||
for (int i = 0; i < 50; i++) {
|
||||
m_output->SetVoltage(1.0);
|
||||
Wait(kDelayTime);
|
||||
m_output->SetVoltage(4.0);
|
||||
Wait(kDelayTime);
|
||||
}
|
||||
|
||||
// The counter should be 50
|
||||
EXPECT_EQ(50, counter.Get()) << "Analog trigger counter did not count 50 ticks";
|
||||
// The counter should be 50
|
||||
EXPECT_EQ(50, counter.Get())
|
||||
<< "Analog trigger counter did not count 50 ticks";
|
||||
}
|
||||
|
||||
static void InterruptHandler(uint32_t interruptAssertedMask, void *param) {
|
||||
*(int *)param = 12345;
|
||||
*(int *)param = 12345;
|
||||
}
|
||||
|
||||
TEST_F(AnalogLoopTest, AsynchronusInterruptWorks) {
|
||||
int param = 0;
|
||||
AnalogTrigger trigger(m_input);
|
||||
trigger.SetLimitsVoltage(2.0f, 3.0f);
|
||||
int param = 0;
|
||||
AnalogTrigger trigger(m_input);
|
||||
trigger.SetLimitsVoltage(2.0f, 3.0f);
|
||||
|
||||
// Given an interrupt handler that sets an int to 12345
|
||||
AnalogTriggerOutput *triggerOutput = trigger.CreateOutput(kState);
|
||||
triggerOutput->RequestInterrupts(InterruptHandler, ¶m);
|
||||
triggerOutput->EnableInterrupts();
|
||||
// Given an interrupt handler that sets an int to 12345
|
||||
AnalogTriggerOutput *triggerOutput = trigger.CreateOutput(kState);
|
||||
triggerOutput->RequestInterrupts(InterruptHandler, ¶m);
|
||||
triggerOutput->EnableInterrupts();
|
||||
|
||||
// If the analog output moves from below to above the window
|
||||
m_output->SetVoltage(0.0);
|
||||
Wait(kDelayTime);
|
||||
m_output->SetVoltage(5.0);
|
||||
triggerOutput->CancelInterrupts();
|
||||
// If the analog output moves from below to above the window
|
||||
m_output->SetVoltage(0.0);
|
||||
Wait(kDelayTime);
|
||||
m_output->SetVoltage(5.0);
|
||||
triggerOutput->CancelInterrupts();
|
||||
|
||||
// Then the int should be 12345
|
||||
Wait(kDelayTime);
|
||||
EXPECT_EQ(12345, param) << "The interrupt did not run.";
|
||||
// Then the int should be 12345
|
||||
Wait(kDelayTime);
|
||||
EXPECT_EQ(12345, param) << "The interrupt did not run.";
|
||||
|
||||
delete triggerOutput;
|
||||
delete triggerOutput;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user