Skip to content

Commit

Permalink
Merge pull request #1699 from fossasia/development
Browse files Browse the repository at this point in the history
chore: merge development into master branch
  • Loading branch information
CloudyPadmal authored May 4, 2019
2 parents 69f1cc5 + 0427202 commit 82d4d7c
Show file tree
Hide file tree
Showing 61 changed files with 769 additions and 372 deletions.
12 changes: 6 additions & 6 deletions .github/ISSUE_TEMPLATE
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
**Actual Behaviour**

Please state here what is currently happening.
<!-- Please state here what is currently happening. -->

**Expected Behaviour**

State here what the feature should enable the user to do.
<!-- State here what the feature should enable the user to do. -->

**Steps to reproduce it**

Add steps to reproduce bugs or add information on the place where the feature should be implemented. Add links to a sample deployment or code.
<!-- Add steps to reproduce bugs or add information on the place where the feature should be implemented. Add links to a sample deployment or code. -->

**LogCat for the issue**

Provide logs for the crash here
<!-- Provide logs for the crash here -->

**Screenshots of the issue**

Where-ever possible add a screenshot of the issue.
<!-- Where-ever possible add a screenshot of the issue. -->

**Would you like to work on the issue?**

Let us know if this issue should be assigned to you or tell us who you think could help to solve this issue.
<!-- Let us know if this issue should be assigned to you or tell us who you think could help to solve this issue. -->
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[![Gitter](https://badges.gitter.im/fossasia/pslab.svg)](https://gitter.im/fossasia/pslab?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/dd728d91bb5743ff916c16c1251f8dd5)](https://www.codacy.com/app/praveenkumar103/pslab-android?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=fossasia/pslab-android&amp;utm_campaign=Badge_Grade)
[![Mailing List](https://img.shields.io/badge/Mailing%20List-FOSSASIA-blue.svg)](mailto:pslab-fossasia@googlegroups.com)
[![Twitter Follow](https://img.shields.io/twitter/follow/pslabio.svg?style=social&label=Follow&maxAge=2592000?style=flat-square)](https://twitter.com/pslabio)

This repository holds the Android App for performing experiments with [PSLab](https://pslab.io/). PSLab is a tiny pocket science lab that provides an array of equipment for doing science and engineering experiments. It can function like an oscilloscope, waveform generator, frequency counter, programmable voltage and current source and also as a data logger. Our website is at https://pslab.io

Expand Down Expand Up @@ -126,7 +127,14 @@ You can't debug the usual way as PSLab device is connected to micro-USB port thr
To debug over Wi-Fi: http://blog.fossasia.org/android-app-debugging-over-wifi-for-pslab/

Note :
1. If you built your own hardware, change VendorID and/or ProductID in [CommunicationHandler.java](https://github.com/fossasia/pslab-android/blob/master/app/src/main/java/org/fossasia/pslab/communication/CommunicationHandler.java)
1. If you built your own hardware, change VendorID and/or ProductID in [CommunicationHandler.java](https://github.com/fossasia/pslab-android/blob/master/app/src/main/java/io/pslab/communication/CommunicationHandler.java)

### Permissions Required

1. Record_Audio : It is required for oscilloscope to accept inputs from the phone inbuilt microphone. You can find its implementation in [AudioJack.java](https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/others/AudioJack.java).
2. Access_Fine_Location and Internet : It is required for use in lux meter and compass to get the coordinates for tagging the data on the map. You can find its implementation in [GPSLogger.java](https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/others/GPSLogger.java).
3. Write_External_Storage : It is required for storing log files from instruments that can be transferred out for future analysis.
4. Read_External_Storage : While writing logs in the storage, [CSVLogger.java](https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/others/CSVLogger.java) first checks whether there is any CSVLogger directory exist or not and that require this read permission.

## Setup to use PSLab with Android App
To use PSLab device with Android, you simply need an OTG cable, an Android Device with USB Host feature enabled ( most modern phones have OTG support ) and PSLab Android App. Connect PSLab device to Android Phone via OTG cable. Rest is handled by App itself.
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "io.pslab"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 11
versionName "2.0.10"
versionCode 12
versionName "2.0.11"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/io/pslab/DataFormatter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.pslab;

import java.text.DecimalFormatSymbols;
import java.util.Locale;

public class DataFormatter {
public static final String HIGH_PRECISION_FORMAT = "%.5f";
public static final String MEDIUM_PRECISION_FORMAT = "%.4f";
public static final String LOW_PRECISION_FORMAT = "%.2f";
public static final String MINIMAL_PRECISION_FORMAT = "%.1f";

public static final char decSeparator = DecimalFormatSymbols.getInstance().getDecimalSeparator();

public static String formatDouble(double value, String format) {
return String.format(Locale.getDefault(), format, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ public void onClick(DialogInterface dialogInterface, int i) {
case android.R.id.home:
this.finish();
break;
case R.id.show_guide:
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
default:
break;
}
Expand Down
67 changes: 59 additions & 8 deletions app/src/main/java/io/pslab/activity/CompassActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.pslab.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
Expand All @@ -9,6 +11,8 @@
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
Expand All @@ -25,7 +29,13 @@
import android.widget.RadioButton;
import android.widget.TextView;

import java.util.Date;

import io.pslab.R;
import io.pslab.DataFormatter;
import io.pslab.models.CompassData;
import io.pslab.others.CSVLogger;
import io.pslab.others.CustomSnackBar;
import io.pslab.others.MathUtils;
import io.pslab.others.SwipeGestureDetector;

Expand All @@ -39,6 +49,7 @@
public class CompassActivity extends AppCompatActivity implements SensorEventListener {

private static final String PREFS_NAME = "CompassPreference";
public CSVLogger compassLogger = null;

@BindView(R.id.compass)
ImageView compass;
Expand All @@ -61,6 +72,8 @@ public class CompassActivity extends AppCompatActivity implements SensorEventLis

@BindView(R.id.compass_toolbar)
Toolbar mToolbar;
@BindView(R.id.compass_coordinator_layout)
CoordinatorLayout coordinatorLayout;

@BindView(R.id.bottom_sheet)
LinearLayout bottomSheet;
Expand All @@ -81,8 +94,10 @@ public class CompassActivity extends AppCompatActivity implements SensorEventLis

BottomSheetBehavior bottomSheetBehavior;
GestureDetector gestureDetector;
CompassData compassData = new CompassData();
private SharedPreferences compassPreference;
private float currentDegree = 0f;
public Boolean writeHeaderToFile = true;
private int direction; // 0 for X-axis, 1 for Y-axis and 2 for Z-axis
private SensorManager mSensorManager;

Expand Down Expand Up @@ -136,7 +151,7 @@ public void onClick(View v) {
tvShadow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(bottomSheetBehavior.getState()==BottomSheetBehavior.STATE_EXPANDED)
if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED)
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
tvShadow.setVisibility(View.GONE);
}
Expand Down Expand Up @@ -184,24 +199,24 @@ public void onSensorChanged(SensorEvent event) {

setCompassAnimation(degree);

degreeIndicator.setText(String.valueOf(degree));
degreeIndicator.setText(DataFormatter.formatDouble(degree, DataFormatter.MEDIUM_PRECISION_FORMAT));
currentDegree = -degree;

degree = Math.round(event.values[0]);
if (degree < 0)
degree += 360;
xAxisMagneticField.setText(String.valueOf(degree));

compassData.setBx(String.valueOf(degree));
xAxisMagneticField.setText(DataFormatter.formatDouble(degree, DataFormatter.MEDIUM_PRECISION_FORMAT));
degree = Math.round(event.values[1]);
if (degree < 0)
degree += 360;
yAxisMagneticField.setText(String.valueOf(degree));

compassData.setBy(String.valueOf(degree));
yAxisMagneticField.setText(DataFormatter.formatDouble(degree, DataFormatter.MEDIUM_PRECISION_FORMAT));
degree = Math.round(event.values[2]);
if (degree < 0)
degree += 360;
zAxisMagneticField.setText(String.valueOf(degree));
}
compassData.setBz(String.valueOf(degree));
zAxisMagneticField.setText(DataFormatter.formatDouble(degree, DataFormatter.MEDIUM_PRECISION_FORMAT)); }

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
Expand Down Expand Up @@ -308,13 +323,49 @@ public boolean onCreateOptionsMenu(Menu menu) {
return true;
}

private void recordData() {
String dateTime = CSVLogger.FILE_NAME_FORMAT.format(new Date(System.currentTimeMillis()));
compassLogger.writeCSVFile(System.currentTimeMillis() + "," + dateTime + "," + compassData.getBx()
+ "," + compassData.getBy() + "," + compassData.getBz());
CustomSnackBar.showSnackBar(coordinatorLayout,
getString(R.string.csv_store_text) + " " + compassLogger.getCurrentFilePath()
, getString(R.string.delete_capital), new View.OnClickListener() {
@Override
public void onClick(View view) {
new AlertDialog.Builder(CompassActivity.this, R.style.AlertDialogStyle)
.setTitle(R.string.delete_file)
.setMessage(R.string.delete_warning)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
compassLogger.deleteFile();
}
})
.setNegativeButton(R.string.cancel, null)
.create()
.show();
}
}, Snackbar.LENGTH_LONG);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.compass_help_icon:
bottomSheetBehavior.setState(bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN ?
BottomSheetBehavior.STATE_EXPANDED : BottomSheetBehavior.STATE_HIDDEN);
break;
case R.id.compass_record_data:
if (writeHeaderToFile) {
compassLogger = new CSVLogger(getString(R.string.compass));
compassLogger.prepareLogFile();
compassLogger.writeCSVFile("Timestamp,DateTime,Bx,By,Bz");
recordData();
writeHeaderToFile = !writeHeaderToFile;
} else {
recordData();
}
break;
case android.R.id.home:
this.finish();
break;
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/io/pslab/activity/DataLoggerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ protected void onCreate(Bundle savedInstanceState) {
getSupportActionBar().setTitle(caller);
categoryData = LocalDataLog.with().getTypeOfSensorBlocks(getString(R.string.baro_meter));
break;
case "Multimeter":
getSupportActionBar().setTitle(caller);
categoryData = LocalDataLog.with().getTypeOfSensorBlocks(getString(R.string.multimeter));
break;
default:
categoryData = LocalDataLog.with().getAllSensorBlocks();
getSupportActionBar().setTitle(getString(R.string.logged_data));
Expand Down
34 changes: 27 additions & 7 deletions app/src/main/java/io/pslab/activity/LogicalAnalyzerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -56,6 +57,8 @@ public class LogicalAnalyzerActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_logic_analyzer);
scienceLab = ScienceLabCommon.scienceLab;
ButterKnife.bind(this);
Expand All @@ -81,6 +84,30 @@ public void onClick(View v) {
}
});

removeStatusBar();

getSupportFragmentManager().beginTransaction().add(R.id.la_frame_layout, LALogicLinesFragment.newInstance(this)).commit();
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

ImageView guideImageView = findViewById(R.id.logic_analyzer_guide_button);
guideImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bottomSheetBehavior.setState(bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN ?
BottomSheetBehavior.STATE_EXPANDED : BottomSheetBehavior.STATE_HIDDEN);
}
});
}

@Override
protected void onResume() {
super.onResume();
removeStatusBar();
}
private void removeStatusBar() {
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Expand All @@ -96,14 +123,7 @@ public void onClick(View v) {
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY));
}

getSupportFragmentManager().beginTransaction().add(R.id.la_frame_layout, LALogicLinesFragment.newInstance(this)).commit();
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
Expand Down
17 changes: 14 additions & 3 deletions app/src/main/java/io/pslab/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import butterknife.BindView;
import butterknife.ButterKnife;
import io.pslab.BuildConfig;
import io.pslab.R;
import io.pslab.communication.CommunicationHandler;
import io.pslab.fragment.AboutUsFragment;
Expand Down Expand Up @@ -73,7 +74,6 @@ public class MainActivity extends AppCompatActivity {

private static final String TAG_DEVICE = "device";
private static final String TAG_INSTRUMENTS = "instruments";
private static final String TAG_SETTINGS = "settings";
private static final String TAG_ABOUTUS = "aboutUs";
private static final String TAG_PINLAYOUT = "pinLayout";
private static final String TAG_FAQ = "faq";
Expand Down Expand Up @@ -224,10 +224,10 @@ private void selectNavMenu() {
navigationView.getMenu().getItem(navItemIndex).setChecked(true);
break;
case 3:
navigationView.getMenu().getItem(4).getSubMenu().getItem(1).setChecked(true);
navigationView.getMenu().getItem(size_menu-1).getSubMenu().getItem(1).setChecked(true);
break;
case 4:
navigationView.getMenu().getItem(4).getSubMenu().getItem(0).setChecked(true);
navigationView.getMenu().getItem(size_menu-1).getSubMenu().getItem(0).setChecked(true);
break;
default:
navigationView.getMenu().getItem(0).setChecked(true);
Expand Down Expand Up @@ -279,6 +279,17 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
}
startActivity(new Intent(MainActivity.this, DataLoggerActivity.class));
break;
case R.id.nav_share_app:
if (drawer != null) {
drawer.closeDrawers();
}
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.app_name));
String shareMessage = "https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID;
shareIntent.putExtra(Intent.EXTRA_TEXT, shareMessage);
startActivity(shareIntent);
return true;
default:
navItemIndex = 0;
}
Expand Down
Loading

0 comments on commit 82d4d7c

Please sign in to comment.