Skip to content

Commit

Permalink
Custom sampling rates for streams added
Browse files Browse the repository at this point in the history
  • Loading branch information
AliAyub007 committed Oct 24, 2018
1 parent a1f0ad5 commit f724b0e
Show file tree
Hide file tree
Showing 7 changed files with 440 additions and 16 deletions.
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@
</activity>
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:label="SENDA"
android:theme="@style/AppTheme.NoActionBar"></activity>
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".SettingsActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"/>

<service android:name=".LSLService" />

Expand Down
28 changes: 17 additions & 11 deletions app/src/main/java/com/example/aliayubkhan/senda/LSLService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.widget.Toast;

import java.io.IOException;
import java.util.Arrays;

import static com.example.aliayubkhan.senda.MainActivity.isAccelerometer;
import static com.example.aliayubkhan.senda.MainActivity.isAudio;
Expand All @@ -30,6 +29,13 @@
import static com.example.aliayubkhan.senda.MainActivity.isStepCounter;
import static com.example.aliayubkhan.senda.MainActivity.streamingNow;
import static com.example.aliayubkhan.senda.MainActivity.streamingNowBtn;
import static com.example.aliayubkhan.senda.SettingsActivity.audio_sampling_rate_data;
import static com.example.aliayubkhan.senda.SettingsActivity.gravity_sampling_rate_data;
import static com.example.aliayubkhan.senda.SettingsActivity.light_sampling_rate_data;
import static com.example.aliayubkhan.senda.SettingsActivity.linear_acceleration_sampling_rate_data;
import static com.example.aliayubkhan.senda.SettingsActivity.proximity_sampling_rate_data;
import static com.example.aliayubkhan.senda.SettingsActivity.rotation_vector_sampling_rate_data;
import static com.example.aliayubkhan.senda.SettingsActivity.step_count_sampling_rate_data;


/**
Expand Down Expand Up @@ -97,6 +103,8 @@ public void onCreate() {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {

System.out.println("Value of acc is: " + SettingsActivity.accelerometer_sampling_rate_data);
System.out.println("Value of audio is: " + SettingsActivity.audio_sampling_rate_data);

streamingNow.setVisibility(View.VISIBLE);
streamingNowBtn.setVisibility(View.VISIBLE);
Expand All @@ -121,7 +129,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
public void run() {

if(isAccelerometer){
accelerometer = new LSL.StreamInfo("Accelerometer "+deviceName, "marker", 3, 100, LSL.ChannelFormat.float32, "myuidaccelerometer"+uniqueID);
accelerometer = new LSL.StreamInfo("Accelerometer "+deviceName, "marker", 3, SettingsActivity.accelerometer_sampling_rate_data, LSL.ChannelFormat.float32, "myuidaccelerometer"+uniqueID);
try {
accelerometerOutlet = new LSL.StreamOutlet(accelerometer);
} catch (IOException e) {
Expand All @@ -130,7 +138,7 @@ public void run() {
}

if(isLight){
light = new LSL.StreamInfo("Light "+deviceName, "marker", 1, 100, LSL.ChannelFormat.float32, "myuidlight"+uniqueID);
light = new LSL.StreamInfo("Light "+deviceName, "marker", 1, light_sampling_rate_data, LSL.ChannelFormat.float32, "myuidlight"+uniqueID);
try {
lightOutlet = new LSL.StreamOutlet(light);
} catch (IOException e) {
Expand All @@ -139,7 +147,7 @@ public void run() {
}

if(isProximity){
proximity = new LSL.StreamInfo("Proximity "+deviceName, "marker", 1,100, LSL.ChannelFormat.float32, "myuidproximity"+uniqueID);
proximity = new LSL.StreamInfo("Proximity "+deviceName, "marker", 1,proximity_sampling_rate_data, LSL.ChannelFormat.float32, "myuidproximity"+uniqueID);
try {
proximityOutlet = new LSL.StreamOutlet(proximity);
} catch (IOException e) {
Expand All @@ -148,7 +156,7 @@ public void run() {
}

if(isLinearAcceleration){
linearAcceleration = new LSL.StreamInfo("LinearAcceleration "+deviceName, "marker", 3,100, LSL.ChannelFormat.float32, "myuidlinearacceleration"+uniqueID);
linearAcceleration = new LSL.StreamInfo("LinearAcceleration "+deviceName, "marker", 3,linear_acceleration_sampling_rate_data, LSL.ChannelFormat.float32, "myuidlinearacceleration"+uniqueID);
try {
linearAccelerationOutlet = new LSL.StreamOutlet(linearAcceleration);
} catch (IOException e) {
Expand All @@ -158,7 +166,7 @@ public void run() {
}

if(isRotation){
rotation = new LSL.StreamInfo("Rotation "+deviceName, "marker", 4, 100, LSL.ChannelFormat.float32, "myuidrotation"+uniqueID);
rotation = new LSL.StreamInfo("Rotation "+deviceName, "marker", 4, rotation_vector_sampling_rate_data, LSL.ChannelFormat.float32, "myuidrotation"+uniqueID);
try {
rotationOutlet = new LSL.StreamOutlet(rotation);
} catch (IOException e) {
Expand All @@ -168,7 +176,7 @@ public void run() {
}

if(isGravity){
gravity = new LSL.StreamInfo("Gravity "+deviceName, "marker", 3, 100, LSL.ChannelFormat.float32, "myuidgravity"+uniqueID);
gravity = new LSL.StreamInfo("Gravity "+deviceName, "marker", 3, gravity_sampling_rate_data, LSL.ChannelFormat.float32, "myuidgravity"+uniqueID);
try {
gravityOutlet = new LSL.StreamOutlet(gravity);
} catch (IOException e) {
Expand All @@ -178,7 +186,7 @@ public void run() {
}

if(isStepCounter){
stepCount = new LSL.StreamInfo("StepCount "+deviceName, "marker", 1, LSL.IRREGULAR_RATE, LSL.ChannelFormat.float32, "myuidstep"+uniqueID);
stepCount = new LSL.StreamInfo("StepCount "+deviceName, "marker", 1, step_count_sampling_rate_data, LSL.ChannelFormat.float32, "myuidstep"+uniqueID);
try {
stepCountOutlet = new LSL.StreamOutlet(stepCount);
} catch (IOException e) {
Expand All @@ -187,7 +195,7 @@ public void run() {
}

if(isAudio){
audio = new LSL.StreamInfo("Audio "+deviceName, "audio", 1, 8000, LSL.ChannelFormat.float32, "myuidaudio"+uniqueID);
audio = new LSL.StreamInfo("Audio "+deviceName, "audio", 1, audio_sampling_rate_data, LSL.ChannelFormat.float32, "myuidaudio"+uniqueID);
try {
audioOutlet = new LSL.StreamOutlet(audio);
} catch (IOException e) {
Expand All @@ -209,8 +217,6 @@ public void run() {

while (!MainActivity.checkFlag) {

System.out.println(Arrays.toString(accelerometerData));

if(isAccelerometer){
//Setting Accelerometer Data
accelerometerData[0] = MainActivity.ax;
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/com/example/aliayubkhan/senda/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import java.util.Arrays;
import java.util.List;

import static com.example.aliayubkhan.senda.SettingsActivity.getSamplingRates;
import static com.example.aliayubkhan.senda.SettingsActivity.samplingRate_set_Check;

public class MainActivity extends Activity implements SensorEventListener
{
@SuppressLint("StaticFieldLeak")
Expand Down Expand Up @@ -73,6 +76,10 @@ public class MainActivity extends Activity implements SensorEventListener

int backButtonCount = 0;

//Settings button

ImageView settings_button;

//Requesting run-time permissions

//Create placeholder for user's consent to record_audio permission.
Expand Down Expand Up @@ -182,6 +189,8 @@ public void onCreate(Bundle savedInstanceState)
stop = (Button)findViewById(R.id.stopLSL);
streamingNow = (TextView)findViewById(R.id.streamingNow);
streamingNowBtn = (ImageView) findViewById(R.id.streamingNowBtn);
settings_button = (ImageView) findViewById(R.id.settings_btn);
settings_button.setVisibility(View.VISIBLE);

requestAudioPermissions();
startPowerSaverIntent(this);
Expand All @@ -200,6 +209,9 @@ public void onClick(View v) {
if(!audioPermission){
requestAudioPermissions();
}
if(samplingRate_set_Check){
getSamplingRates();
}
startService(intent);
}

Expand All @@ -214,6 +226,14 @@ public void onClick(View v) {
}
});

settings_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
startActivity(intent);
}
});

tv.setText("Available Streams: ");


Expand Down
106 changes: 106 additions & 0 deletions app/src/main/java/com/example/aliayubkhan/senda/SettingsActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.example.aliayubkhan.senda;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

/**
* Created by aliayubkhan on 21/10/2018.
*/



public class SettingsActivity extends AppCompatActivity {

@SuppressLint("StaticFieldLeak")
static EditText accelerometer_sampling_rate;
@SuppressLint("StaticFieldLeak")
static EditText light_sampling_rate;
@SuppressLint("StaticFieldLeak")
static EditText proximity_sampling_rate;
@SuppressLint("StaticFieldLeak")
static EditText gravity_sampling_rate;
@SuppressLint("StaticFieldLeak")
static EditText linear_acceleration_sampling_rate;
@SuppressLint("StaticFieldLeak")
static EditText rotation_vector_sampling_rate;
@SuppressLint("StaticFieldLeak")
static EditText step_count_sampling_rate;
@SuppressLint("StaticFieldLeak")
static EditText audio_sampling_rate;

//Variables to store sampling rates

public static int accelerometer_sampling_rate_data = 12;
public static int light_sampling_rate_data = 12;
public static int proximity_sampling_rate_data = 12;
public static int gravity_sampling_rate_data = 12;
public static int linear_acceleration_sampling_rate_data = 12;
public static int rotation_vector_sampling_rate_data = 12;
public static int step_count_sampling_rate_data = 12;
public static int audio_sampling_rate_data = 8000;

public static Boolean samplingRate_set_Check = Boolean.FALSE;

//Button for setting values
Button samplingSet;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);

samplingRate_set_Check = Boolean.TRUE;
samplingSet = (Button) findViewById(R.id.samplingSetBtn);

samplingSet.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
getSamplingRates();
Intent intent = new Intent(SettingsActivity.this, MainActivity.class);
startActivity(intent);
}
});
accelerometer_sampling_rate = (EditText) findViewById(R.id.accelerometer_sampling_rate);
light_sampling_rate = (EditText) findViewById(R.id.light_sampling_rate);
proximity_sampling_rate = (EditText) findViewById(R.id.proximity_sampling_rate);
gravity_sampling_rate = (EditText) findViewById(R.id.gravity_sampling_rate);
linear_acceleration_sampling_rate = (EditText) findViewById(R.id.linear_acceleration_sampling_rate);
rotation_vector_sampling_rate = (EditText) findViewById(R.id.rotation_vector_sampling_rate);
step_count_sampling_rate = (EditText) findViewById(R.id.step_count_sampling_rate);
audio_sampling_rate = (EditText) findViewById(R.id.audio_sampling_rate);


accelerometer_sampling_rate.setText(String.valueOf(accelerometer_sampling_rate_data));
light_sampling_rate.setText(String.valueOf(light_sampling_rate_data));
proximity_sampling_rate.setText(String.valueOf(proximity_sampling_rate_data));
gravity_sampling_rate.setText(String.valueOf(gravity_sampling_rate_data));
linear_acceleration_sampling_rate.setText(String.valueOf(linear_acceleration_sampling_rate_data));
rotation_vector_sampling_rate.setText(String.valueOf(rotation_vector_sampling_rate_data));
step_count_sampling_rate.setText(String.valueOf(step_count_sampling_rate_data));
audio_sampling_rate.setText(String.valueOf(audio_sampling_rate_data));
}

@Override
public void onBackPressed() {
getSamplingRates();
Intent intent = new Intent(SettingsActivity.this, MainActivity.class);
startActivity(intent);
}

static void getSamplingRates(){
accelerometer_sampling_rate_data = Integer.parseInt(String.valueOf(accelerometer_sampling_rate.getText()));
light_sampling_rate_data = Integer.parseInt(String.valueOf(light_sampling_rate.getText()));
proximity_sampling_rate_data = Integer.parseInt(String.valueOf(proximity_sampling_rate.getText()));
gravity_sampling_rate_data = Integer.parseInt(String.valueOf(gravity_sampling_rate.getText()));
linear_acceleration_sampling_rate_data = Integer.parseInt(String.valueOf(linear_acceleration_sampling_rate.getText()));
rotation_vector_sampling_rate_data = Integer.parseInt(String.valueOf(rotation_vector_sampling_rate.getText()));
step_count_sampling_rate_data = Integer.parseInt(String.valueOf(step_count_sampling_rate.getText()));
audio_sampling_rate_data = Integer.parseInt(String.valueOf(audio_sampling_rate.getText()));
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:viewportHeight="478.703"
android:viewportWidth="478.703" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M454.2,189.1l-33.6,-5.7c-3.5,-11.3 -8,-22.2 -13.5,-32.6l19.8,-27.7c8.4,-11.8 7.1,-27.9 -3.2,-38.1l-29.8,-29.8c-5.6,-5.6 -13,-8.7 -20.9,-8.7c-6.2,0 -12.1,1.9 -17.1,5.5l-27.8,19.8c-10.8,-5.7 -22.1,-10.4 -33.8,-13.9l-5.6,-33.2c-2.4,-14.3 -14.7,-24.7 -29.2,-24.7h-42.1c-14.5,0 -26.8,10.4 -29.2,24.7l-5.8,34c-11.2,3.5 -22.1,8.1 -32.5,13.7l-27.5,-19.8c-5,-3.6 -11,-5.5 -17.2,-5.5c-7.9,0 -15.4,3.1 -20.9,8.7l-29.9,29.8c-10.2,10.2 -11.6,26.3 -3.2,38.1l20,28.1c-5.5,10.5 -9.9,21.4 -13.3,32.7l-33.2,5.6c-14.3,2.4 -24.7,14.7 -24.7,29.2v42.1c0,14.5 10.4,26.8 24.7,29.2l34,5.8c3.5,11.2 8.1,22.1 13.7,32.5l-19.7,27.4c-8.4,11.8 -7.1,27.9 3.2,38.1l29.8,29.8c5.6,5.6 13,8.7 20.9,8.7c6.2,0 12.1,-1.9 17.1,-5.5l28.1,-20c10.1,5.3 20.7,9.6 31.6,13l5.6,33.6c2.4,14.3 14.7,24.7 29.2,24.7h42.2c14.5,0 26.8,-10.4 29.2,-24.7l5.7,-33.6c11.3,-3.5 22.2,-8 32.6,-13.5l27.7,19.8c5,3.6 11,5.5 17.2,5.5l0,0c7.9,0 15.3,-3.1 20.9,-8.7l29.8,-29.8c10.2,-10.2 11.6,-26.3 3.2,-38.1l-19.8,-27.8c5.5,-10.5 10.1,-21.4 13.5,-32.6l33.6,-5.6c14.3,-2.4 24.7,-14.7 24.7,-29.2v-42.1C478.9,203.8 468.5,191.5 454.2,189.1zM451.9,260.4c0,1.3 -0.9,2.4 -2.2,2.6l-42,7c-5.3,0.9 -9.5,4.8 -10.8,9.9c-3.8,14.7 -9.6,28.8 -17.4,41.9c-2.7,4.6 -2.5,10.3 0.6,14.7l24.7,34.8c0.7,1 0.6,2.5 -0.3,3.4l-29.8,29.8c-0.7,0.7 -1.4,0.8 -1.9,0.8c-0.6,0 -1.1,-0.2 -1.5,-0.5l-34.7,-24.7c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.1,4.3 -3.3,10.1 -0.6,14.7c7.8,13.1 13.6,27.2 17.4,41.9c1.3,5.2 5.6,9.1 10.8,9.9l42,7.1c1.3,0.2 2.2,1.3 2.2,2.6v42.1H451.9z"/>
<path android:fillColor="#FF000000" android:pathData="M239.4,136c-57,0 -103.3,46.3 -103.3,103.3s46.3,103.3 103.3,103.3s103.3,-46.3 103.3,-103.3S296.4,136 239.4,136zM239.4,315.6c-42.1,0 -76.3,-34.2 -76.3,-76.3s34.2,-76.3 76.3,-76.3s76.3,34.2 76.3,76.3S281.5,315.6 239.4,315.6z"/>
</vector>
21 changes: 17 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<LinearLayout
android:id="@+id/linearHorizontal"
android:layout_width="0dp"
android:layout_height="44dp"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="false"
android:layout_centerHorizontal="true"
Expand All @@ -27,7 +27,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/streamingNowBtn">
app:layout_constraintTop_toBottomOf="@+id/settings_btn">

<Button
android:id="@+id/startLSL"
Expand Down Expand Up @@ -100,7 +100,7 @@
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/linearHorizontal"
app:layout_constraintEnd_toStartOf="@+id/streamingNowBtn"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintHorizontal_bias="0.489"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
Expand All @@ -111,7 +111,7 @@
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginBottom="446dp"
android:layout_marginEnd="16dp"
android:layout_marginEnd="80dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:src="@drawable/rec"
Expand All @@ -120,4 +120,17 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/settings_btn"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginBottom="457dp"
android:layout_marginRight="4dp"
android:layout_marginTop="16dp"
android:src="@drawable/ic_settings"
app:layout_constraintBottom_toTopOf="@+id/linearHorizontal"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="VectorDrawableCompat" />
</android.support.constraint.ConstraintLayout>
Loading

0 comments on commit f724b0e

Please sign in to comment.