Defining Platform Callbacks
Now there is only one thing left to do: We need to specify that the method Application::switchLed() is to be called, whenever a falling edge triggers an interrupt of our DiPushButton input. In order to be as efficient as possible, the redBlocks HAL does not use any function pointers for callbacks to the application or from low level drivers to high level drivers. Instead, the feature of code generation with templates is used for all callbacks, i. e. short application level functions like Application::switchLed() will be inlined to the driver's code by the compiler, which results in the most efficient binary code that is possible. In order to make use of the C++ compiler's code generation features, we need to work with template specialization which is syntactically rather clumsy. Thus, the redBlocks Library provides the convenience macro RB_CONNECT_ISR_CBK that hides the syntactical details from the programmer.
With this macro we only need to add the following lines to PlatformCallbacks.h (which can also be generated from within the redBlocks Simulator, so only the last parameter needs to be filled in to finally look like this):
#include <Application.h>
RB_CONNECT_ISR_CBK(Platform::DiPushButton,
Platform::DiPushButton::CBK_ON_INPUT_CHANGED,
Application::getInstanceRef().switchLed());
This definition specifies which command is to be excecuted, when an interrupt occurs on the digital input Platform::DiPushButton. What we simply do is this: We request the single instance of class Application by calling its method getInstanceRef() and call the method switchLed() of this instance. Note that this callback definition is also platform independent, i. e. it is part of the high level functionality that is not specific to the simulation environment or target platform.
Our application is now complete and it should compile without errors. When being started later, it will connect via a TCP socket to port 10000 on the same machine, where it expects the redBlocks Simulator to be listening for incoming connections. The connection attempt fails, if the redBlocks Simulator is not running.
If you want to change the port or IP address where the redBlocks Simulator is running, you need to change the line
simulatorConnection.connect("127.0.0.1", 10000);
in main.cpp.
Before actually starting the application for simulation, the redBlocks Simulator needs to be running.

