Creating Your Own Module for The KAI

Anupama Nair
Sep 29, 2019 · 2 min read
Image for post
Image for post

If you’ve jumped here from the blog that introduces you to the Kai SDK, then you're halfway to creating your first module for the Kai. If you haven’t given it a read, you may want to take a look at that blog first. Here’s the link.

Now that you’re here, let’s get you started. This blog contains a starter module that we have created for you. You can choose to start with this module just to try things out.

This module is a simple example where gestures correspond to actions taken on your computer. The Kai sends across multiple types of data on a subscription basis. Modules that are to integrate with the SDK must explicitly mention the capabilities it wants to receive. Therefore, by “subscribing” to specific Kai data, you are choosing the information that you want to receive from the Kai as and when events occur. This data could be anything from Gesture Data to Gyroscope, Accelerometer, Magnetometer or PYR data.

For the extent of this example, we’re creating a module that plays various sound clips when gestures are performed. Therefore, the data we will be subscribing to is GestureData.

You can start off by picking Visual Studio or JetBrains Rider.

Here are the steps to follow.

  • Create a new c# project.
  • Add a new New Nuget Dependency ( kai.WebSocketModule )
  • In your main function, add the following code.
using System.Threading;using System.Media;namespace Kai.Module.Boilerplate{
internal static class DefaultDataHandler
{
private const KaiCapabilities ModuleCapabilities = KaiCapabilities.GestureData;public static void Main(string[] args){KaiSDK.Initialise("<example-module-id>", "<example-module-secret>");InitialiseEvents();KaiSDK.DefaultKai.SetCapabilities(ModuleCapabilities);KaiSDK.Connect();Thread.Sleep(Timeout.Infinite); // prevent program from exiting}public static void InitialiseEvents(){// default kai event handler callbacksKaiSDK.DefaultKai.Gesture += GestureHandler;// universal error handlerKaiSDK.Error += ErrorHandler;}private static void GestureHandler(object e, GestureEventArgs gestureArg){
// Checkout: https://github.com/vicara-hq/kai-dotnet/blob/develop/Kai.BaseModule/Delegates.cs
// For specs of the eventArg classesLog.Info($"Gesture Event Triggered: {gestureArg.Gesture}");SoundPlayer player;switch(gestureArg.Gesture){case Gesture.SwipeUp:case Gesture.SideSwipeUp:player = new SoundPlayer(@"c:\one.wav");break;case Gesture.SwipeDown:case Gesture.SideSwipeDown:player = new SoundPlayer(@"c:\two.wav");break;case Gesture.SwipeLeft:case Gesture.SideSwipeLeft:player = new SoundPlayer(@"c:\three.wav");break;case Gesture.SwipeRight:case Gesture.SideSwipeRight:player = new SoundPlayer(@"c:\four.wav");break;default:return;}player.Play();}private static void ErrorHandler(object e, ErrorEventArgs errorArg){Log.Error($"Error: {errorArg.Error}");}}}

Voila! You’re done. You have now given the process of creating modules a ‘first try’. Once you’ve tried this out, you could then work on your own module. We hope this helps to kick things off!

For those of you who need more information, We have our trusty SDK documentation here. It covers pretty much everything you would need to know.

If you still need help, you can reach out to our development team at drift.me/vicara. We’re always around to help you get started!

Vicara

Vicara is an Immersive Technology Company that develops…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store