Skip to content

Instantly share code, notes, and snippets.

@pthalamy
Last active December 18, 2019 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pthalamy/22a8095e336d577b35e7138f938da9cb to your computer and use it in GitHub Desktop.
Save pthalamy/22a8095e336d577b35e7138f938da9cb to your computer and use it in GitHub Desktop.
VisibleSim InterruptionEvent snippet
// 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