Last active
December 18, 2019 09:52
-
-
Save pthalamy/22a8095e336d577b35e7138f938da9cb to your computer and use it in GitHub Desktop.
VisibleSim InterruptionEvent snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define identifiers for distinguishing between your different interruptions | |
#define IT_MODE_EXAMPLE_INTERRUPTION 1 | |
#define IT_MODE_EXAMPLE_INTERRUPTION_2 2 | |
// ... Rest of Blockcode code unchanged | |
void InterruptionBlockCode::processLocalEvent(EventPtr pev) { | |
/// Other code | |
switch (pev->eventType) { | |
/// .... ALL THE OTHER EVENT STUFF | |
case EVENT_INTERRUPTION: { | |
std::shared_ptr<InterruptionEvent> itev = | |
std::static_pointer_cast<InterruptionEvent>(pev); | |
switch(itev->mode) { | |
case IT_MODE_EXAMPLE_INTERRUPTION: { | |
if (condition1IsMet()) { | |
// Condition is met, do your thing | |
handleInterruption1(); // Function with your code for when your condition is met | |
} else { | |
// Reschedule another interruption in 300 us | |
getScheduler()->schedule( | |
new InterruptionEvent(getScheduler()->now() + 300, // example delay in us | |
module, IT_MODE_EXAMPLE_INTERRUPTION)); | |
} | |
} break; | |
case IT_MODE_EXAMPLE_INTERRUPTION_2: | |
if (condition2IsMet()) { | |
// Condition is met, do your thing | |
handleInterruption2(); // Function with your code for when your condition is met | |
} else { | |
// Reschedule another interruption in 500 us | |
getScheduler()->schedule( | |
new InterruptionEvent(getScheduler()->now() + 500, // example delay in us | |
module, IT_MODE_EXAMPLE_INTERRUPTION_2)); | |
} | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment