JQI Arduino Libraries
Arduino for the modern scientist.
 All Classes Files Functions Variables Typedefs Macros Pages
Static Public Member Functions | List of all members
SetListISR Class Reference

Static class which handles trigger interrupt routines. More...

#include <SetListArduino.h>

Static Public Member Functions

static void firstTriggerInterrupt ()
 ISR for "first trigger" of a SetList. More...
 
static void restTriggerInterrupt ()
 ISR for all other SetList triggers after the first trigger. More...
 

Detailed Description

Static class which handles trigger interrupt routines.

Summary/Rationale

This is a bit wacky-hacky, but it's the best idea I could think of. The problem here is that I want to hide the attachInterrupt functions inside the SetListArduino class, but the attachInterrupt callback cannot take any variables. Sadly, class methods are implicitly passed the class itself, ie, void firstTriggerInterrupt(SetListArduino::). The hack we're using here is to create a static class SetListISR, which will call the SetListArduino class methods as appropriate. attachInterrupt will register callbacks in SetListISR, thus avoiding the above issue.

The SetListArduino class is a singleton (ie, only one instance should ever be declared in an arduino sketch). This hack takes advantage of that, in that the SetListISR methods need to know which instance of SetListArduino to call the trigger interrupt methods on. In order for everything to work, we had to pre-decide on what the singleton SetListArduino instance should be called; Dan and I decided SetListImage made the most sense. In the .cpp file, you'll see the declaration "extern SetListArduino SetListImage;" Then, these SetListISR static methods will call functions on the object SetListImage. All works as expected, but in the arduino sketch you'll be forced to use the name SetListImage, which is hopefully a very minor inconvenience!

See also
SetListImage

Member Function Documentation

void SetListISR::firstTriggerInterrupt ( )
static

ISR for "first trigger" of a SetList.

This ISR is attached to SetListArduino::_triggerChannel on a falling edge trigger. Once SetListArduino sees that first falling edge, it changes the ISR to trigger on CHANGE (ie, rising or falling edge).

It is implemented this way because depending on whether SetList has an even or odd number of lines, the PulseBlaster trigger channel might be in a high or a low state, thus causing an off-by-one index error in the SetList table.

Note this also means that the first SetList line should be a "static" output for all Arduino-controlled devices, ie, not a DDS ramp or similar. See the README for more details.

See also
SetListArduino::_triggerChannel, SetListArduino::SetListArduino()
void SetListISR::restTriggerInterrupt ( )
static

ISR for all other SetList triggers after the first trigger.

This ISR is attached to SetListArduino::_triggerChannel on a CHANGE event. See firstTriggerInterrupt() for more details, as well as the README.

See also
firstTriggerInterrupt(), SetListArduino::_triggerChannel, SetListArduino::SetListArduino()

The documentation for this class was generated from the following files: