Connecting VR and Ketai Bluetooth in Android mode

edited November 2017 in Android Mode

Hi all,

I am having problems connecting VR mode and Ketai Bluetooth connectivity in Android mode. (Win10; Porcessing 3.3.5; Android 6.0.1; Samsung S5 Neo). Independently code for Ketai bluetooth works:

import processing.vr.*;
import android.content.Intent;
import android.os.Bundle;
import ketai.net.bluetooth.*;
import ketai.ui.*;
//import ketai.net.*;

PFont fontMy;
KetaiBluetooth bt;
String info = "";

//********************************************************************
// The following code is required to enable bluetooth at startup.
//********************************************************************

void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 bt = new KetaiBluetooth(this);
 println("Creating KetaiBluetooth");
}

void onActivityResult(int requestCode, int resultCode, Intent data) {
 bt.onActivityResult(requestCode, resultCode, data);
}

//********************************************************************

void setup() {
  //fullScreen(STEREO);
  size(displayWidth, displayHeight, P3D);  
  //start listening for BT connections and connect to a device.
  bt.start();
  bt.connectDevice("00:14:03:06:37:0E");      
  //font size
  fontMy = createFont("SansSerif", 40);
  textFont(fontMy);
}

void calculate() {
}

void draw() {
  background(150);  
  translate(width/2, height/2);
  noStroke();     
  // Green box, Y axis 
  pushMatrix();
  translate(0, 200, 0);
  fill(0, 255, 0);
  box(100);
  popMatrix();
  // text from Bluetooth
 // info = "abc\ndef"; //debugging
  text(info, 20, 104);
}

void onBluetoothDataEvent(String who, byte[] data) {
  //received
  info = new String(data);
}

Everything connects nicely to my HC-05 and gets the info, and prints it next to the green box. But then I decide to add VR functionality, and everything goes wrong. So I un-comment //fullScreen(STEREO); and comment
size(displayWidth, displayHeight, P3D);, and change Android mode from "App" to "VR". The build is successful, but the app crashes and I get the following error:

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean ketai.net.bluetooth.KetaiBluetooth.start()' on a null object reference at processing.test.test2.test2.setup(test2.java:63) at processing.core.PApplet.handleDraw(Unknown Source) at processing.vr.PSurfaceVR$AndroidVRStereoRenderer.onDrawEye(Unknown Source) at com.google.vr.sdk.base.CardboardViewNativeImpl.nativeOnDrawFrame(Native Method) at com.google.vr.sdk.base.CardboardViewNativeImpl.access$2500(CardboardViewNativeImpl.java:53) at com.google.vr.sdk.base.CardboardViewNativeImpl$RendererHelper.onDrawFrame(CardboardViewNativeImpl.java:569) at com.google.vr.ndk.base.GvrSurfaceView$GLThread.guardedRun(GvrSurfaceView.java:1643) at com.google.vr.ndk.base.GvrSurfaceView$GLThread.run(GvrSurfaceView.java:1324) handleDraw() called before finishing

The VR-code will work nicely, if I comment the bt.start();and bt.connectDevice("00:14:03:06:37:0E");

Is it normal? Can Ketai work with In-built Processing Arduino VR Mode at all?

Thanks!

Answers

  • edited February 2018 Answer ✓

    I managed to get vr and ketai bluetooth working by simply declaring the kt variable in setup().

    void setup() { fullScreen(STEREO); bt = new KetaiBluetooth(this); bt.start(); ... }

    I did not need the onCreate() and onActivityResult() routines.

    (Linux Mint 18.2; Processing 3.3.6; Android mode 4.0.1; Huawei P7, P9)

  • Cool! Thanks

Sign In or Register to comment.