Commit baee4c7b authored by Harshith Goka's avatar Harshith Goka

Still in debugging, queue to be implemented

parent 15e7149c
......@@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -22,7 +22,7 @@ class DTWtwoD extends DTW {
totalSquared += Math.pow(a[p][i] - b[q][i],2);
}
return Math.sqrt(totalSquared);
return Math.sqrt(Math.sqrt(totalSquared));
}
public int sdtwDistance(){
......
......@@ -70,16 +70,16 @@ class DynamicPrime{
a[1].printData();*/
DynamicQueue q = new DynamicQueue(a);
Live dynamiclive = new Live();
q.foremostElement = 0;
for (int i=0; i<5; i++) {
dynamiclive.update(i*2);
q.updateQueue(dynamiclive);
q.processQueue();
q.proceedExecution();
q.print();
}
// DynamicQueue q = new DynamicQueue(a);
// Live dynamiclive = new Live();
//
// q.foremostElement = 0;
// for (int i=0; i<5; i++) {
// dynamiclive.update(i*2);
// q.updateQueue(dynamiclive);
// q.processQueue();
// q.proceedExecution();
// q.print();
// }
}
}
\ No newline at end of file
package com.example.harshith.ddc;
import java.lang.reflect.Array;
import java.util.Queue;
class DynamicQueue{
public int noOfSlots = 2000;
public int noOfGestures;
......@@ -10,10 +13,12 @@ class DynamicQueue{
public int latestElement = 0;
public int foremostElement = 0;
public int[] threshold;
public DynamicQueue(DynamicGesture []gest){
public DynamicQueue(DynamicGesture []gest,int[] threshold){
gesture = gest.clone();
noOfGestures = gesture.length;
this.threshold = threshold.clone();
liveElement = new Live[noOfSlots];
for (int i=0; i<noOfSlots; i++) {
......@@ -110,8 +115,6 @@ class DynamicQueue{
}
public void processLive(int slotNo, int livesTailNo){
int threshold = 30;
DTW x;
for (int i=0; i<noOfGestures; i++) {
......@@ -124,19 +127,28 @@ class DynamicQueue{
dtwGap[slotNo][i] = x.sdtwDistance();
}
for (int i=0; i<noOfGestures; i++) {
if(dtwGap[slotNo][i]>=threshold) shortlist[slotNo][i] = false;
if(dtwGap[slotNo][i]>=threshold[i]) shortlist[slotNo][i] = false;
}
}
public void processQueue(){
for (int i=foremostElement; i!=latestElement; i=(i+1)%noOfSlots) {
// int no;
// if(latestElement > foremostElement){
// no = Math.max(foremostElement,latestElement-20)%noOfSlots;
// }
// else {
// no = (latestElement - 20)%noOfSlots;
// }
for (int i=foremostElement;i != latestElement ; i=(i+1)%noOfSlots) {
processLive(i,latestElement);
}
}
public int proceedExecution(){
for (int i=foremostElement; i!=latestElement; i=(i+1)%noOfSlots) {
int no;
no = Math.max((latestElement - 20)%noOfSlots,foremostElement);
for (int i=foremostElement; i!=no; i=(i+1)%noOfSlots) {
if(getShortlistCount(i)==0) foremostElement = (foremostElement+1)%noOfSlots;
else if(getShortlistCount(i)==1) {
//gesture execute
......
......@@ -20,13 +20,15 @@ public class ReceiveDataThread extends Thread {
GlobalClass globalClass;
public int readStatus;
private StringBuilder stringBuilder = null;
boolean isFirstTime;
int[] readings;
public ReceiveDataThread(BluetoothSocket bluetoothSocket, Handler handler,GlobalClass globalClass) {
int[] threshold;
public ReceiveDataThread(BluetoothSocket bluetoothSocket, Handler handler,GlobalClass globalClass,boolean b) {
this.bluetoothSocket = bluetoothSocket;
this.handler = handler;
this.globalClass = globalClass;
stringBuilder = new StringBuilder();
isFirstTime = b;
}
@Override
......@@ -35,13 +37,16 @@ public class ReceiveDataThread extends Thread {
InputStream tempIn = null;
tempIn = bluetoothSocket.getInputStream();
inputStream = tempIn;
if(!isFirstTime) {
byte[] clearing = new byte[1000];
inputStream.read(clearing);
}
int noOfGestures = 12;
int indx; int [][]array;
int []cons;
DynamicGesture []a = new DynamicGesture[noOfGestures];
threshold = new int[noOfGestures];
// initialising the 11 gestures
indx=0;
......@@ -58,17 +63,16 @@ public class ReceiveDataThread extends Thread {
cons = new int[] {1,1,1,1,1,0,0,0,0,1,0};
a[indx].updateFrame(array,cons);
a[indx].printData();
threshold[indx] = 40;
indx=1;
array = new int[201][11];
setValue(array,20,0,201);
setValue(array,90,1,201);
setValue(array,90,2,201);
setValue(array,90,3,201);
setValue(array,90,4,201);
setValue(array,0,0,201);
setValue(array,100,1,201);
setValue(array,100,2,201);
setValue(array,100,3,201);
setValue(array,100,4,201);
lineDraw(array, 0, 0, 51, 5, false); lineDraw(array, 50, -50, 101, 5, true); lineDraw(array, 150, 50, 51, 5, false);
setValue(array,0,8,201);
setValue(array,0,9,201);
......@@ -77,8 +81,8 @@ public class ReceiveDataThread extends Thread {
cons = new int[] {1,1,1,1,1,1,0,0,1,1,0};
a[indx].updateFrame(array,cons);
a[indx].printData();
// a[indx].printData();
threshold[indx] = 40;
indx=2;
array = new int[51][11];
......@@ -93,8 +97,8 @@ public class ReceiveDataThread extends Thread {
cons = new int[] {1,1,1,1,1,0,0,0,1,1,0};
a[indx].updateFrame(array,cons);
a[indx].printData();
// a[indx].printData();
threshold[indx] = 40;
indx=3;
array = new int[101][11];
......@@ -110,8 +114,8 @@ public class ReceiveDataThread extends Thread {
cons = new int[] {1,1,1,1,1,0,0,0,0,1,0};
a[indx].updateFrame(array,cons);
a[indx].printData();
// a[indx].printData();
threshold[indx] = 40;
indx=4;
array = new int[101][11];
......@@ -127,7 +131,8 @@ public class ReceiveDataThread extends Thread {
cons = new int[] {1,1,1,1,1,0,0,0,0,1,0};
a[indx].updateFrame(array,cons);
a[indx].printData();
// a[indx].printData();
threshold[indx] = 40;
indx=5;
......@@ -145,7 +150,8 @@ public class ReceiveDataThread extends Thread {
cons = new int[] {1,1,1,1,1,0,0,0,1,1,0};
a[indx].updateFrame(array,cons);
a[indx].printData();
// a[indx].printData();
threshold[indx] = 40;
indx=6;
......@@ -165,7 +171,8 @@ public class ReceiveDataThread extends Thread {
cons = new int[] {1,1,1,1,1,1,0,0,1,1,0};
a[indx].updateFrame(array,cons);
a[indx].printData();
// a[indx].printData();
threshold[indx] = 40;
indx=7;
......@@ -184,7 +191,8 @@ public class ReceiveDataThread extends Thread {
cons = new int[] {1,1,1,1,1,1,0,0,1,1,0};
a[indx].updateFrame(array,cons);
a[indx].printData();
// a[indx].printData();
threshold[indx] = 40;
indx=8;
......@@ -201,7 +209,8 @@ public class ReceiveDataThread extends Thread {
cons = new int[] {1,1,1,1,1,0,0,0,0,1,0};
a[indx].updateFrame(array,cons);
a[indx].printData();
// a[indx].printData();
threshold[indx] = 40;
indx=9;
......@@ -218,7 +227,8 @@ public class ReceiveDataThread extends Thread {
cons = new int[] {1,1,1,1,1,0,0,0,0,1,0};
a[indx].updateFrame(array,cons);
a[indx].printData();
// a[indx].printData();
threshold[indx] = 40;
indx=10;
......@@ -235,7 +245,8 @@ public class ReceiveDataThread extends Thread {
cons = new int[] {1,1,1,1,1,0,0,0,0,1,0};
a[indx].updateFrame(array,cons);
a[indx].printData();
// a[indx].printData();
threshold[indx] = 40;
indx=11;
......@@ -252,17 +263,18 @@ public class ReceiveDataThread extends Thread {
cons = new int[] {1,1,1,1,1,0,0,0,0,1,0};
a[indx].updateFrame(array,cons);
a[indx].printData();
// a[indx].printData();
threshold[indx] = 40;
DynamicQueue q = new DynamicQueue(a);
threshold = new int[]{5,10,10,10,10,10,10,10,10,10,30,10};
DynamicQueue q = new DynamicQueue(a,threshold);
Live dynamiclive = new Live();
byte[] buffer = new byte[64];
int bytes = -1;
String readMessage;
int i;
int i, counter = 1;
convert();
while(true) {
bytes = inputStream.read(buffer);
......@@ -273,16 +285,18 @@ public class ReceiveDataThread extends Thread {
if(readings != null && readings.length == 11) {
dynamiclive.update(readings);
q.updateQueue(dynamiclive);
q.processQueue();
i = q.proceedExecution();
if(i != -1){
Looper.prepare();
handler.obtainMessage(Constants.READ_STATUS,readStatus,i,null).sendToTarget();
L.m("Gesture " + i + " is executed");
q.gestureStatusPrint();
Looper.loop();
if(counter > 20) {
q.processQueue();
i = q.proceedExecution();
if (i != -1) {
Looper.prepare();
handler.sendMessageDelayed(handler.obtainMessage(Constants.READ_STATUS, readStatus, i, null), 10000);
L.m("Gesture " + i + " is executed");
q.gestureStatusPrint();
Looper.loop();
}
}
counter++;
// q.print();
}
}
......
......@@ -22,6 +22,7 @@ public class ReceiveService extends Service {
private static final UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
public Handler handler;
GlobalClass globalClass;
BluetoothSocket bluetoothSocket;
@Override
public void onCreate() {
......@@ -31,7 +32,8 @@ public class ReceiveService extends Service {
if(message.what == Constants.CONNECTION_STATUS) {
if(message.arg1 == Constants.CONNECTION_STATUS_OK){
Toast.makeText(getApplicationContext(),"Connected",Toast.LENGTH_LONG).show();
receiveDataThread = new ReceiveDataThread((BluetoothSocket) message.obj,handler,globalClass);
bluetoothSocket = (BluetoothSocket) message.obj;
receiveDataThread = new ReceiveDataThread((BluetoothSocket) message.obj,handler,globalClass,true);
receiveDataThread.start();
}
else if(message.arg1 == Constants.CONNECTION_STATUS_NOT_CONNECTED){
......@@ -40,7 +42,10 @@ public class ReceiveService extends Service {
}
else if (message.what == Constants.READ_STATUS) {
if(message.arg1 == Constants.READ_STATUS_OK){
Toast.makeText(getBaseContext(),"Gesture " + message.arg2 + " is executed",Toast.LENGTH_SHORT).show();
receiveDataThread = new ReceiveDataThread(bluetoothSocket,handler,globalClass,false);
receiveDataThread.start();
}
else if(message.arg1 == Constants.READ_STATUS_NOT_OK){
L.s(getBaseContext(),"Connection Lost");
......
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