The following step-by-step example is done with Microsoft Visual Studio 2017. Theoretically, you can use Visual Studio 2008 or newer versions, but 2013 or newer are recommended.
After the project is created, the source editor will appear. The first thing we have to do is to import AURA SDK into project. You can do this by using the #import
directive at the top of AuraTutorial.cpp:
The #import
does the similar effect as #include
, except that it gets the type information from the "Type Libraries" (reside in the Windows Registry) instead of header files. The GUID F1AA5209-5217-4B82-BA7E-A68198999AFA
in the directive is the Lib ID of "AuraServiceLib", where the AURA SDK can be found.
#import
directive, it will generate some helper header & source files according to the information retrived from Type Libraries, so that the project sources can be compiled properly. Before these files are generated, you might see some annoying errors:As a result, it is suggested to build the project now to generate the helper files. To do this, select Build -> Build Solution (or Build AuraTutorial) in main menu:
Now the errors should be eliminated. (If the errors still occur, try to reload the solution/project by restarting Visual Studio.)
Since the AURA SDK v3.1 utilizes COM mechanism, it is required to call CoInitializeEx()
(with parameter COINIT_MULTITHREADED
) before using any AURA SDK 3.1 interfaces. After all work is done and all interfaces have been released, CoUninitialize()
should be called. So now we put them into main()
function:
Note: COM related functions are defined in Objbase.h. If the compiler fails to find declarations of these functions, add #include <objbase.h>
in your source file.
Now we can create the instance of AuraSdk and get the interface pointer:
Note that all the AURA SDK interfaces are defined in the namespace called AuraServiceLib
. For convenience, the using namespace AuraServiceLib
statement is used.
Moreover, starting from version 1.02.01, a new interface IAuraSdk2
is provided to support "explicit control releasing" function. If you need this function, you can replace IAuraSdkPtr
with IAuraSdk2Ptr
directly:
Since IAuraSdk
is inherited by IAuraSdk2
, all methods IAuraSdk
supports can still be accessed via IAuraSdk2Ptr
. See AuraServiceLib::IAuraSdk2 for more details.
After the instance of AuraSdk is created, we can aquire the control and then enumerated all AURA-compatible devices:
The parameter passed into IAuraSdk::Enumerate()
means the type of devices that should be enumerated. 0 means all types of devices. You can enumerate specific type of devices by passing other values. For details, please refer to AuraServiceLib::IAuraSdk::Enumerate().
devices
returned by IAuraSdk::Enumerate()
is a "collection" of all devices. Each device can be accessed via the Item array in this collection: AuraServiceLib::IAuraSyncDevice
interface. The Lights
property is also a "collection", so the each LED can be easily accessed similar to the devices in a device collection: Now, lets set all the LED's color to blue by modifying the Color property of IAuraRgbLight
interface. The data type of Color
property is 32-bit unsigned integer, and it's format is "0x00GGBBRR", where G equals Green, B equals Blue, and R equals Red. So "blue" should be 0x00FF0000:
Note that besides IAuraRgbLight::Color
, there are also IAuraRgbLight::Red
, IAuraRgbLight::Green
and IAuraRgbLight::Blue
properties that can set each color directly. Please refer to the reference chapter for more details.
AuraServiceLib::IAuraSyncDevice::Apply()
should be called to make the new settings take effect: IAuraSdk2
interface as described in step 6, you can call IAuraSdk2::ReleaseControl()
whenever you want to release control: