sample Ketai bluetooth program error on fresh install

edited January 2016 in Questions about Code

I just installed Processing 3.0.1 and loaded the Ketai library (along with android sdk). I tried the sample program shown below and get an errors "The function onCreate(Bundle) does not exist" (line 37)and "The function drawUI does not exist." (line 111) I'm just starting out with processing and am unsure what to do. Any help is appreciated.

(edit - this has nothing to do with arduino - not sure why it was moved there - I moved it back)

/**
* Ketai Library for Android: http://ketai.org
*
* KetaiBluetooth wraps the Android Bluetooth RFCOMM Features:
* 
* Enables Bluetooth for sketch through android
* Provides list of available Devices
* Enables Discovery
* Allows writing data to device
* 
* pdated: 2012-05-18 Daniel Sauter/j.duran
*/

//required for BT enabling on startup
import android.content.Intent;
import android.os.Bundle;

import ketai.net.bluetooth.*;
import ketai.ui.*;
import ketai.net.*;

import oscP5.*;

KetaiBluetooth bt;
String info = "";
KetaiList klist;
PVector remoteMouse = new PVector();

ArrayList devicesDiscovered = new ArrayList();
boolean isConfiguring = true;
String UIText;

//********************************************************************
// The following code is required to enable bluetooth at startup.
//********************************************************************
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bt = new KetaiBluetooth(this);

}

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

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

void setup()
{

orientation(PORTRAIT);
background(78, 93, 75);
stroke(255);
textSize(24);

//start listening for BT connections
bt.start();

UIText = "d - discover devices\n" +
"b - make this device discoverable\n" +
"c - connect to device\n from discovered list.\n" +
"p - list paired devices\n" +
"i - Bluetooth info";
}

void draw()
{
if (isConfiguring)
{
ArrayList names;
background(78, 93, 75);

//based on last key pressed lets display
//  appropriately
if (key == 'i')
  info = getBluetoothInformation();
else
{
  if (key == 'p')
  {
    info = "Paired Devices:\n";
    names = bt.getPairedDeviceNames();
  }
  else
  {
    info = "Discovered Devices:\n";
    names = bt.getDiscoveredDeviceNames();
  }

  for (int i=0; i < names.size(); i++)
  {
    info += "["+i+"] "+names.get(i).toString() + "\n";
  }
}
text(UIText + "\n\n" + info, 5, 90);

}
else
{
background(78, 93, 75);
pushStyle();
fill(255);
ellipse(mouseX, mouseY, 20, 20);
fill(0, 255, 0);
stroke(0, 255, 0);
ellipse(remoteMouse.x, remoteMouse.y, 20, 20);

popStyle();
}

drawUI();
}

//Call back method to manage data received
void onBluetoothDataEvent(String who, byte[] data)
{
if (isConfiguring)
return;

//KetaiOSCMessage is the same as OscMessage
// but allows construction by byte array
KetaiOSCMessage m = new KetaiOSCMessage(data);
if (m.isValid())
{
if (m.checkAddrPattern("/remoteMouse/"))
{
if (m.checkTypetag("ii"))
{
remoteMouse.x = m.get(0).intValue();
remoteMouse.y = m.get(1).intValue();
}
}
}
}

String getBluetoothInformation()
{
String btInfo = "Server Running: ";
btInfo += bt.isStarted() + "\n";
btInfo += "Discovering: " + bt.isDiscovering() + "\n";
btInfo += "Device Discoverable: "+bt.isDiscoverable() + "\n";
btInfo += "\nConnected Devices: \n";

ArrayList devices = bt.getConnectedDeviceNames();
for (String device: devices)
{
btInfo+= device+"\n";
}

return btInfo;
}

Answers

Sign In or Register to comment.