Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Skyward Boardcore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Avionics
Software Development
Skyward Boardcore
Wiki
EventHandler
Changes
Page history
New page
Templates
Clone repository
Update EventHandler
authored
2 years ago
by
Angelo Zangari
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
EventHandler.md
+15
-8
15 additions, 8 deletions
EventHandler.md
with
15 additions
and
8 deletions
EventHandler.md
View page @
3685f176
...
...
@@ -37,9 +37,11 @@ Here we define three possible events: `EV_1`, `EV_2` and `EV_3`.
#include
"events/EventHandler.h"
namespace
Boardcore
{
enum
ExampleEvents
:
uint8_t
{
EV_1
=
EV_FIRST_
SIGNAL
,
EV_1
=
EV_FIRST_
CUSTOM
,
EV_2
,
EV_3
};
...
...
@@ -58,7 +60,7 @@ public:
protected
:
void
handleEvent
(
const
Event
&
ev
)
override
{
switch
(
ev
.
sig
)
// do something according to the event's id
switch
(
ev
)
// do something according to the event's id
{
case
EV_1
:
TRACE
(
"Received EV_1
\n
"
);
...
...
@@ -70,22 +72,26 @@ protected:
TRACE
(
"Invalid event
\n
"
);
}
last_event
=
ev
.
sig
;
last_event
=
ev
;
}
private
:
uint8_t
last_event
;
};
}
// namespace Boardcore
```
##### test-myeventhandler.cpp
In order to test that our class works we can create a MyEventHandler object and start it.
We can then post some events and see what the output is.
```
cpp
#include
<
Common
.h>
#include
<
miosix
.h>
#include
"MyEventHandler.h"
using
namespace
miosix
;
using
namespace
Boardcore
;
int
main
()
{
...
...
@@ -111,14 +117,15 @@ int main()
return
0
;
}
```
##### Output
Remember to add the
`test-myeventhandler.cpp`
to
`sbs.conf`
and to specify all the needed includes.
After you run the example you should see the following output:
```
0.
1
3> Received EV_1
0.
2
3> Received EV_2
0.
3
3> Invalid event
0.
4
3> Invalid event
0.
0
3> Received EV_1
0.
1
3> Received EV_2
0.
2
3> Invalid event
0.
3
3> Invalid event
```
The last "Invalid event" is due to the
`EV_EMPTY`
posted by the
`stop()`
method of the EventHandler object.
\ No newline at end of file
This diff is collapsed.
Click to expand it.