SDKJava (Android) SDK

Quick start

Android Java SDK: Quick start

Current version · 2.0.0

Quick start

Finish installation and USB permission. QuickStart.run(context, transport) takes the app Context and an authorized serial transport; the SDK discovers the only connected glove, subscribes to pose and keeps running. Call it on a worker thread.

Save the following class as QuickStart.java in the app.

import android.content.Context;
import com.qnbot.sdk.Sdk;
import com.qnbot.sdk.SdkConfig;
import com.qnbot.sdk.android.SerialTransport;
import com.qnbot.sdk.glove.Glove;
import com.qnbot.sdk.glove.GloveConfig;
import com.qnbot.sdk.glove.GloveDevice;
import com.qnbot.sdk.glove.GloveFinger;

/**
 * Streams the automatically discovered glove's pose.
 *
 * <p>Pass the host {@link Context} and an authorized {@link SerialTransport}. Run on a worker
 * thread; the pose subscription prints each sequence.
 */
public final class QuickStart {
  private QuickStart() {}

  public static void run(Context context, SerialTransport transport) {
    SdkConfig config = SdkConfig.builder().device(GloveConfig.builder().build()).build();
    try (Sdk sdk = new Sdk(config, context, transport); Glove glove = sdk.glove()) {
      GloveDevice device = glove.device();
      device.pose().subscribe(sample
          -> System.out.println("pose sequence=" + sample.sequence + " thumb="
              + (sample.value.payload.hand == null
                          || !sample.value.payload.hand.fingertips.containsKey(GloveFinger.THUMB)
                      ? "absent"
                      : sample.value.payload.hand.fingertips.get(GloveFinger.THUMB).position)
              + " index="
              + (sample.value.payload.hand == null
                          || !sample.value.payload.hand.fingertips.containsKey(GloveFinger.INDEX)
                      ? "absent"
                      : sample.value.payload.hand.fingertips.get(GloveFinger.INDEX).position)));
      glove.start();
      System.out.println("running");
      glove.runForever();
    }
  }
}

The output keeps printing pose sequence= with thumb and index positions. A missing hand component or finger prints absent; payload.hand.coordinateFrame declares the coordinate frame. The example runs glove.runForever() on the worker thread. To stop it, close the Sdk from another thread or end the process. See Examples for continuous reads, multiple outputs and other runtime modes.