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:
Thomas Clark
2014-08-04 12:19:31 -04:00
parent f57a2dc5a9
commit d521eb79b9
7 changed files with 89 additions and 20 deletions

View File

@@ -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, &param);
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;
}