Events

Back to Tutorials

3. Device Handler 5. Unit Process 1 2  3	  4  5  6  7  8  9  10  11  12  13  14  15  16



Events are a big thing here in ViiM. We support a great number of events useful for many situations. In this tutorial we will show you how to use two pairs of basic events: device initialized and new frame entering the bus; warning and error related events. Before attempting to understand this sample, you should check the first tutorial. Here is the new stuff on the .h

In here we declare a VBool variable and 2 methods, triggered by events. We'll look at it in depth after the .cpp. In the source file, before the setup method we have the showMessage method you have seen in the previous samples:

In openframework's setup method we add these new lines of code: Here we define which event calls which method. You can see that here we also set up our log notification system.

ViiM's log notification system informs the user about error events, bad data access, non permitted operations, etc... In line 31 we define that when there's a MESSAGE event (error, warning and/or info), the code will call the showMessage function. But because we set the log level to ERRORS in the next line, the system will only notify you when an error happens. There are four different levels for notification ( event.type ): With the event you have the event.message, which gives you a message like "ERROR: example message." or "WARNING: example message." on the console. We advise that you should always have this methods in your examples, because it might save you some headaches ;) Before the update method, we have the methods triggered by the events:
 * NONE         - You will not receive any errors or warnings
 * WARNINGS - You will only receive warning messages
 * ERRORS      - You will only receive error messages
 * ALL            - You will receive all the errors and warning messages.

For convenience and ease of understanding, these two methods are explained in the text below the code blocks. In the update method you can see the condition It means the images will only be updated when _contextInited is true. This is explained in the text below the next code block. And in the draw method: Because _contextInited starts as false, when the application gets to the draw function, it bumps in the if condition and writes "INITIALIZING DEVICE" on the screen.

This cycle will only change when the DEVICE_INITED event is triggered and the deviceInitedHandler method called, thus setting _contextInited true. This event is only triggered when the device initializes correctly and starts acquiring frames. From this point on the aforementioned if condition will be true and the images will be updated and drawn.

The enterFrameHandler method is then called over and over again when a new image is available on the bus triggering the ENTER_FRAME event. The enterFrameHandler method will then be constantly called providing the images from the kinect to the application. This second event doesn't make much of a difference in this case, but you'll see that you will be glad to have this event available in rather more complex applications.

Try it on the apps folder, ViiM_OF_Samples and choose your operating system.

3. Device Handler 5. Unit Process 1 2  3	  4  5  6  7  8  9  10  11  12  13  14  15  16

Back to Tutorials