mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
Analog interrupts in C++
Analog interrupts now work in C++. The interrupts Resource was moved from a global in DigitalInput to a static member of SensorBase. An analog interrupt IT was added, and the digital interrupt one modified to prevent a linker error. Change-Id: I9a300daafed15e9666a4ccb405a509615e3dbb06
This commit is contained in:
@@ -93,3 +93,30 @@ TEST_F(AnalogLoopTest, AnalogTriggerCounterWorks) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
TEST_F(AnalogLoopTest, AsynchronusInterruptWorks) {
|
||||
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();
|
||||
|
||||
// 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.";
|
||||
|
||||
delete triggerOutput;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user