Skip to content

Commit

Permalink
feat: Dust Sensor (#1986)
Browse files Browse the repository at this point in the history
update: limits
  • Loading branch information
CloudyPadmal authored Oct 15, 2019
1 parent c1590b5 commit 22f627b
Show file tree
Hide file tree
Showing 14 changed files with 1,112 additions and 69 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@
android:name=".activity.GasSensorActivity"
android:screenOrientation="portrait" />
<activity android:name=".activity.MapsActivity" />
<activity
android:name=".activity.DustSensorActivity"
android:screenOrientation="portrait"/>

<receiver android:name=".receivers.USBDetachReceiver" />

Expand Down
135 changes: 135 additions & 0 deletions app/src/main/java/io/pslab/activity/DustSensorActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package io.pslab.activity;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;

import io.pslab.R;
import io.pslab.fragment.DustSensorDataFragment;
import io.pslab.fragment.DustSensorSettingsFragment;
import io.pslab.models.DustSensorData;
import io.pslab.models.PSLabSensor;
import io.pslab.models.SensorDataBlock;
import io.pslab.others.LocalDataLog;
import io.realm.RealmObject;
import io.realm.RealmResults;

public class DustSensorActivity extends PSLabSensor {

private static final String PREF_NAME = "customDialogPreference";
public RealmResults<DustSensorData> recordedDustSensorData;

@Override
public int getMenu() {
return R.menu.sensor_data_log_menu;
}

@Override
public SharedPreferences getStateSettings() {
return this.getSharedPreferences(PREF_NAME, MODE_PRIVATE);
}

@Override
public String getFirstTimeSettingID() {
return "DustSensorFirstTime";
}

@Override
public String getSensorName() {
return getResources().getString(R.string.dust_sensor);
}

@Override
public int getGuideTitle() {
return R.string.dust_sensor;
}

@Override
public int getGuideAbstract() {
return R.string.dust_sensor_intro;
}

@Override
public int getGuideSchematics() {
return 0;
}

@Override
public int getGuideDescription() {
return R.string.dust_sensor_desc;
}

@Override
public int getGuideExtraContent() {
return 0;
}

@Override
public void recordSensorDataBlockID(SensorDataBlock block) {
realm.beginTransaction();
realm.copyToRealm(block);
realm.commitTransaction();
}

@Override
public void recordSensorData(RealmObject sensorData) {
realm.beginTransaction();
realm.copyToRealm((DustSensorData) sensorData);
realm.commitTransaction();
}

@Override
public void stopRecordSensorData() {
LocalDataLog.with().refresh();
}

@Override
public Fragment getSensorFragment() {
return DustSensorDataFragment.newInstance();
}

@Override
protected void onResume() {
super.onResume();
reinstateConfigurations();
}

private void reinstateConfigurations() {
SharedPreferences luxMeterConfigurations;
luxMeterConfigurations = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
locationEnabled = luxMeterConfigurations.getBoolean(DustSensorSettingsFragment.KEY_INCLUDE_LOCATION, true);
DustSensorDataFragment.setParameters(
getValueFromText(luxMeterConfigurations.getString(DustSensorSettingsFragment.KEY_HIGH_LIMIT, "4.0"),
0.0, 5.0),
getValueFromText(luxMeterConfigurations.getString(DustSensorSettingsFragment.KEY_UPDATE_PERIOD, "1000"),
100, 1000),
luxMeterConfigurations.getString(DustSensorSettingsFragment.KEY_DUST_SENSOR_TYPE, "0"));
}

private int getValueFromText(String strValue, int lowerBound, int upperBound) {
if (strValue.isEmpty()) return lowerBound;
int value = Integer.parseInt(strValue);
if (value > upperBound) return upperBound;
else if (value < lowerBound) return lowerBound;
else return value;
}

private double getValueFromText(String strValue, double lowerBound, double upperBound) {
if (strValue.isEmpty()) return lowerBound;
double value = Double.parseDouble(strValue);
if (value > upperBound) return upperBound;
else if (value < lowerBound) return lowerBound;
else return value;
}

@Override
public void getDataFromDataLogger() {
if (getIntent().getExtras() != null && getIntent().getExtras().getBoolean(KEY_LOG)) {
viewingData = true;
recordedDustSensorData = LocalDataLog.with()
.getBlockOfDustSensorRecords(getIntent().getExtras().getLong(DATA_BLOCK));
String title = titleFormat.format(recordedDustSensorData.get(0).getTime());
getSupportActionBar().setTitle(title);
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/io/pslab/activity/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.pslab.fragment.AccelerometerSettingsFragment;
import io.pslab.fragment.BaroMeterSettingsFragment;
import io.pslab.fragment.CompassSettingsFragment;
import io.pslab.fragment.DustSensorSettingsFragment;
import io.pslab.fragment.GyroscopeSettingsFragment;
import io.pslab.fragment.LuxMeterSettingFragment;
import io.pslab.fragment.MultimeterSettingsFragment;
Expand Down Expand Up @@ -80,6 +81,9 @@ protected void onCreate(Bundle savedInstanceState) {
case PSLabSensor.COMPASS_CONFIGURATIONS:
fragment = new CompassSettingsFragment();
break;
case PSLabSensor.DUSTSENSOR_CONFIGURATIONS:
fragment = new DustSensorSettingsFragment();
break;
default:
fragment = new SettingsFragment();
break;
Expand Down
Loading

0 comments on commit 22f627b

Please sign in to comment.