Commit baee4c7b authored by Harshith Goka's avatar Harshith Goka

Still in debugging, queue to be implemented

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