Hello World
HelloWorld.cpp
This "HelloWorld" example demonstrates how to use the SkineticSDK library to connect to a vest and play the provided "zap.spn" pattern effect.
/**
* Copyright (C) 2022-2023 Actronika SAS
*/
#include <iostream>
#include <thread>
#include <chrono>
#include <fstream>
#include "Skinetic.h"
#define PATTERNS_PATH "./patterns/"
int main() {
SkineticSDK ski;
int ret = 1;
// Try to connect to the first vest available in Bluetooth or USB
ski.connect(ski_output_t::eAutoDetect, 0);
// Wait while connecting
while (ret == 1)
ret = ski.connectionStatus();
std::cout << "Connection status : " << ret << std::endl;
// Load .spn file as string
std::ifstream ifs(std::string(PATTERNS_PATH) + "zap.spn");
std::string json((std::istreambuf_iterator<char>(ifs)),
(std::istreambuf_iterator<char>()));
// Load pattern string into SDK
int patternID = ski.loadPatternFromJSON(json.c_str());
std::cout << "Load pattern: " << std::string(PATTERNS_PATH) + "zap.spn" << " - " << patternID << std::endl;
// Play effect with default effect settings
int EffectID = ski.playEffect(patternID, {});
std::cout << "Play effect (EffectID: " << EffectID << " - PatternID: " << patternID << ")" << std::endl;
// Wait X seconds for the effect to finish
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
// Vest disconnection
ski.disconnect();
std::cout << "Disconnect" << std::endl;
return 0;
}
Prerequisites
To run this program, you will need the following:
- SkineticSDK library
- C++ compiler
- Bluetooth or USB connection to a Skinetic vest
Usage
Connect your vest to your computer via Bluetooth or USB.
Open a terminal or command prompt and navigate to the directory where the
helloworld.cpp
file is located.Compile the program using the C++ compiler. For example, using
g++
:g++ -std=c++11 -o helloworld helloworld.cpp -I/path/to/skinetic-sdk
Make sure to replace
/path/to/skinetic-sdk
with the actual path to the SkineticSDK library.Run the compiled program:
./helloworld
The program will attempt to connect to the vest and play a predefined pattern effect. The connection status will be displayed in the console.
After a specified duration (2 seconds in this example), the effect will finish, and the vest will be disconnected.
Customization
To change the pattern file being loaded, update the
zap.spn
filename in the following line:std::ifstream ifs(std::string(PATTERNS_PATH) + "zap.spn");
You can modify the sleep duration in milliseconds to adjust the waiting time for the effect to finish. Update the following line with your desired duration:
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
Advanced Controls and Parameters
More advanced controls and parameters are available in the Skinetic.h header file, such as:
- available devices scan,
- connection callback,
- boost setting,
- effect fine-tuning,
- etc.
To explore and utilize these additional features, refer to the Skinetic.h file and its documentation. It contains a wide range of functions and settings to customize and control the behavior of the vest.
Troubleshooting
If you encounter any issues during compilation or execution, please refer to the documentation and resources provided by the SkineticSDK library.
Ensure that the vest is properly paired and within range of your computer.
Make sure that nothing else is connected to the vest (such as Unitouch Studio)
Bug reporting and support are available here.