Commit fe37890b authored by Harshith Goka's avatar Harshith Goka

Integrate algorithm and android code

parent 5f927c00
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
package com.example.harshith.ddc;
import java.util.Scanner;
/**
* Created by harshith on 18/6/16.
*/
public class Live {
int reading[];
int sensors = 11 ;
public Live(){
reading = new int [sensors];
}
public Live(Live staticLive){
reading = new int [staticLive.sensors];
for (int i=0; i<sensors; i++) {
reading[i] = staticLive.reading[i];
}
}
public void updateConsole(){
Scanner scan = new Scanner(System.in).useDelimiter("\\s");
for (int i=0; i<sensors; i++) {
reading[i] = scan.nextInt();
}
}
public void update(int[] readings){
reading = readings;
}
public void print(){
for (int i=0; i<sensors; i++) {
System.out.print(reading[i] + " ");
}
System.out.print('\n');
}
}
...@@ -20,6 +20,7 @@ public class ReceiveDataThread extends Thread { ...@@ -20,6 +20,7 @@ public class ReceiveDataThread extends Thread {
public int readStatus; public int readStatus;
private StringBuilder stringBuilder = null; private StringBuilder stringBuilder = null;
int[] readings; int[] readings;
Gesture []a;
public ReceiveDataThread(BluetoothSocket bluetoothSocket, Handler handler,GlobalClass globalClass) { public ReceiveDataThread(BluetoothSocket bluetoothSocket, Handler handler,GlobalClass globalClass) {
this.bluetoothSocket = bluetoothSocket; this.bluetoothSocket = bluetoothSocket;
...@@ -27,6 +28,45 @@ public class ReceiveDataThread extends Thread { ...@@ -27,6 +28,45 @@ public class ReceiveDataThread extends Thread {
this.globalClass = globalClass; this.globalClass = globalClass;
stringBuilder = new StringBuilder(); stringBuilder = new StringBuilder();
a = new Gesture[8];
for (int i = 0; i<8; i++) {
a[i] = new StaticGesture();
}
int []hand = {0,0,0,0,0,0,0,0,0,0,0}; int q=0;
q=0; hand = new int [] {0,0,0,0,0,8,8,8,8,8,8};
// neutral
a[q].updateFrame(hand);
q=1; hand = new int [] {1,1,0,0,0,8,8,8,8,1,8};
// voice search
a[q].updateFrame(hand);
q=2; hand = new int [] {1,0,1,1,1,8,8,8,8,1,8};
// tap
a[q].updateFrame(hand);
q=3; hand = new int [] {0,1,1,1,0,8,8,8,8,1,8};
// call
a[q].updateFrame(hand);
q=4; hand = new int [] {0,0,1,1,1,8,8,8,-1,8,8};
// cam open
a[q].updateFrame(hand);
q=5; hand = new int [] {0,0,0,1,1,8,8,8,-1,8,8};
// cam click
a[q].updateFrame(hand);
q=6; hand = new int [] {1,0,1,1,0,8,8,8,8,1,8};
// music open
a[q].updateFrame(hand);
q=7; hand = new int [] {0,0,1,1,0,8,8,8,8,1,8};
// music play
a[q].updateFrame(hand);
} }
public void setProcessHandler(Handler processHandler) { public void setProcessHandler(Handler processHandler) {
...@@ -43,20 +83,95 @@ public class ReceiveDataThread extends Thread { ...@@ -43,20 +83,95 @@ public class ReceiveDataThread extends Thread {
byte[] buffer = new byte[64]; byte[] buffer = new byte[64];
int bytes = -1; int bytes = -1;
bytes = inputStream.read(buffer);
readStatus = Constants.READ_STATUS_OK;
String readMessage = new String(buffer,0,bytes);
stringBuilder.append(readMessage);
convert();
// ProcessThread processThread = new ProcessThread(globalClass); // ProcessThread processThread = new ProcessThread(globalClass);
// processThread.start(); // processThread.start();
// //
// processHandler = globalClass.getProcessHandler(); // processHandler = globalClass.getProcessHandler();
Live staticLive = new Live();
int no = 50;
//StaticLive.print();
int count = 0;
int gestActive = -1; boolean stay = true;
while(true) { while(true) {
bytes = inputStream.read(buffer); bytes = inputStream.read(buffer);
readMessage = new String(buffer,0,bytes); String readMessage = new String(buffer,0,bytes);
stringBuilder.append(readMessage); stringBuilder.append(readMessage);
convert(); int endOfLineIndex = stringBuilder.indexOf("~");
if (endOfLineIndex > 0) {
int startOfLineIndex = stringBuilder.indexOf("#");
if (startOfLineIndex > endOfLineIndex || startOfLineIndex == -1) {
startOfLineIndex = 0;
}
else if (startOfLineIndex == 0) {
startOfLineIndex = 1;
}
String dataIn = stringBuilder.substring(startOfLineIndex, endOfLineIndex);
String[] readingStrings = dataIn.split("\\+");
readings = new int[readingStrings.length];
for (int i = 0; i != readingStrings.length; i++) {
try {
readings[i] = Integer.valueOf(readingStrings[i]);
} catch (NumberFormatException e) {
}
catch (NullPointerException e) {
}
}
String testConvert = "";
for (int reading : readings) {
testConvert += " " + reading;
}
L.m(testConvert);
stringBuilder.delete(0, endOfLineIndex + 2);
if(count == no){
L.m("Gesture " + gestActive + " is activated");
count = 0;
gestActive = -1;
//if( str.equals("n") ) { stay = false; break; }
}
if(count<no){
if(readings.length == 11) {
staticLive.update(readings);
}
}
for (int i=0; i<8; i++) {
if(a[i].isInFrame(staticLive)){
if(gestActive == i){
count++; continue;
}
else{
gestActive = i; count = 1; continue;
}
}
}
// int[] flex = new int[5];
// for (int i = 0; i != 5; i++) {
// try {
// flex[i] = readings[i];
// }
// catch (ArrayIndexOutOfBoundsException e) {
//
// }
// }
//
// int[] mpu = new int[6];
// for (int i = 0; i != 6; i++) {
// try {
// mpu[i] = readings[5 + i];
// }
// catch (ArrayIndexOutOfBoundsException e) {
//
// }
// }
}
// if(processHandler != null) { // if(processHandler != null) {
// processHandler.obtainMessage(1, readings).sendToTarget(); // processHandler.obtainMessage(1, readings).sendToTarget();
// } // }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment