Skip to content

Commit

Permalink
Added fix for GPIO panel and touched up logging
Browse files Browse the repository at this point in the history
GPIO panel didn't use the new callback methods for firmware v1.0.0
Logging panel has description of the selected trigger
  • Loading branch information
scaryghost committed Mar 11, 2015
1 parent 94d4721 commit 4cb9fe6
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 22 deletions.
23 changes: 22 additions & 1 deletion res/layout/fragment_gpio.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,27 @@ contact MbientLab Inc, at www.mbientlab.com.
</EditText>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2" >

<TextView
android:id="@+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.50"
android:text="@string/label_firmware_version" />

<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:text="@string/label_gpio_firmware" />

</LinearLayout>

<View
android:layout_width="fill_parent"
android:layout_height="1dp"
Expand All @@ -89,7 +110,7 @@ contact MbientLab Inc, at www.mbientlab.com.
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.50"
android:text="@string/label_gpio_abs_value" />
android:text="@string/label_gpio_abs_reference" />

<TextView
android:id="@+id/textView4"
Expand Down
40 changes: 30 additions & 10 deletions res/layout/fragment_logging.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,49 @@
android:orientation="vertical"
android:padding="16dp" >

<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />

<ScrollView
android:id="@+id/scrollView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:layout_below="@+id/spinner1" >

<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>

<View
android:id="@+id/separatorView1"
android:layout_width="fill_parent"
android:layout_height="3dp"
android:background="@android:color/darker_gray"
android:layout_below="@+id/scrollView2" />

<ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" >
android:layout_marginTop="10dp"
android:layout_below="@+id/separatorView1" >

<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/label_log_help" />

</ScrollView>

<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_below="@+id/scrollView1" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
6 changes: 4 additions & 2 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ contact MbientLab Inc, at www.mbientlab.com.

<string name="label_log_start">Log</string>
<string name="label_log_save">Save</string>
<string name="label_log_help">Select a sensor you wish to log. Press the Log button to begin logging and the Save button to download and email the data.</string>
<string name="label_log_help">Select a sensor you wish to log. Press the Log button to begin logging and the Save button to download and email the data.
For the best results, your device should be on Android 4.4 or higher. The screen\'s orientation will be locked while the panel is active.</string>

<string name="label_neopixel_strand">Strand</string>
<string name="label_neopixel_num_leds"># of LEDs</string>
Expand Down Expand Up @@ -169,11 +170,12 @@ contact MbientLab Inc, at www.mbientlab.com.

<string name="label_gpio_pin">GPIO Pin</string>
<string name="label_gpio_analog_input">Analog Input</string>
<string name="label_gpio_abs_value">Absolute Value</string>
<string name="label_gpio_abs_reference">Abs Reference</string>
<string name="label_gpio_supply_ratio">Supply Ratio</string>
<string name="label_gpio_digital_input">Digital Input</string>
<string name="label_gpio_pull_mode">Pull Mode</string>
<string name="label_gpio_digital_output">Digital Output</string>
<string name="label_gpio_firmware">Older than 1.0.0</string>
<string name="label_gpio_read">Read</string>
<string name="label_gpio_value">Value</string>

Expand Down
39 changes: 36 additions & 3 deletions src/com/mbientlab/metawear/app/GPIOFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.CompoundButton.OnCheckedChangeListener;

/**
* @author etsai
Expand All @@ -60,25 +63,47 @@ public class GPIOFragment extends ModuleFragment {
private EditText pinText;
private GPIO gpioController;
private PullMode pullMode;
private boolean olderFirmware;

private ModuleCallbacks mCallbacks= new GPIO.Callbacks() {
@Override
public void receivedAnalogInputAsAbsValue(short value) {
if (isVisible()) {
if (olderFirmware && isVisible()) {
((TextView) getView().findViewById(R.id.textView4)).setText(String.format(Locale.US, "%d mV", value));
}
}

@Override
public void receivedAnalogInputAsSupplyRatio(short value) {
if (isVisible()) {
if (olderFirmware && isVisible()) {
((TextView) getView().findViewById(R.id.textView5)).setText(String.format(Locale.US, "%d", value));
}
}

@Override
public void receivedDigitalInput(byte value) {
if (isVisible()) {
if (olderFirmware && isVisible()) {
((TextView) getView().findViewById(R.id.textView8)).setText(String.format(Locale.US, "%d", value));
}
}

@Override
public void receivedAnalogInputAsAbsValue(byte pin, short value) {
if (!olderFirmware && isVisible()) {
((TextView) getView().findViewById(R.id.textView4)).setText(String.format(Locale.US, "%d mV", value));
}
}

@Override
public void receivedAnalogInputAsSupplyRatio(byte pin, short value) {
if (!olderFirmware && isVisible()) {
((TextView) getView().findViewById(R.id.textView5)).setText(String.format(Locale.US, "%d", value));
}
}

@Override
public void receivedDigitalInput(byte pin, byte value) {
if (!olderFirmware && isVisible()) {
((TextView) getView().findViewById(R.id.textView8)).setText(String.format(Locale.US, "%d", value));
}
}
Expand All @@ -105,6 +130,14 @@ public void onNothingSelected(AdapterView<?> parent) { }
pullModeSpinner.setAdapter(new ArrayAdapter<PullMode>(getActivity(),
R.layout.command_row, R.id.command_name, PullMode.values));

((CheckBox) view.findViewById(R.id.checkBox1)).setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
olderFirmware= isChecked;
}
});

((Button) view.findViewById(R.id.button1)).setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
44 changes: 38 additions & 6 deletions src/com/mbientlab/metawear/app/LoggingFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
import java.util.Calendar;
import java.util.Locale;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.content.FileProvider;
Expand All @@ -52,6 +54,7 @@
import android.widget.Button;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.TextView;

import com.mbientlab.metawear.api.MetaWearController;
import com.mbientlab.metawear.api.Module;
Expand Down Expand Up @@ -79,6 +82,7 @@ private abstract class Sensor extends Logging.Callbacks {
private boolean ready;
protected LogEntry firstEntry;

public abstract String getDescription();
public abstract void stopSensors();
public abstract File[] saveDataToFile();
public abstract void processData(double offset, LogEntry entry);
Expand Down Expand Up @@ -163,6 +167,11 @@ public GPIOSensor(byte gpioPin) {
this.gpioPin= gpioPin;
}

@Override
public String getDescription() {
return String.format(Locale.US, "Logs ADC value of GPIO pin %d every 500ms. %s",
gpioPin, "You will need firmware 1.0.0 or higher to log GPIO data");
}
@Override
public void receivedTriggerId(byte triggerId) {
super.receivedTriggerId(triggerId);
Expand Down Expand Up @@ -242,6 +251,11 @@ public File[] saveDataToFile() {
private ArrayList<double[]> xyData= null, zData= null;
private final String CSV_HEADER_XY= "time,x-Axis,y-Axis", CSV_HEADER_Z= "time,z-Axis";

@Override
public String getDescription() {
return "Logs the accelerometer axis data sampling at 50Hz";
}

@Override
public String toString() { return "Accelerometer"; }

Expand All @@ -266,7 +280,7 @@ public void setupLogger() {
loggingController.addTrigger(LoggingTrigger.ACCELEROMETER_Z_AXIS);

accelController.enableXYZSampling().withFullScaleRange(FullScaleRange.FSR_8G)
.withOutputDataRate(OutputDataRate.ODR_100_HZ)
.withOutputDataRate(OutputDataRate.ODR_50_HZ)
.withSilentMode();
accelController.startComponents();
}
Expand Down Expand Up @@ -328,7 +342,13 @@ public File[] saveDataToFile() {

private ArrayList<double[]> tempData;
private final String CSV_HEADER_TEMP= "time,temperature";


@Override
public String getDescription() {
return String.format(Locale.US, "%s. %s","Logs the temperature value every 500ms",
"You can use the temperature panel to enable/disable thermistor mode");
}

@Override
public String toString() { return "Temperature"; }

Expand Down Expand Up @@ -389,11 +409,21 @@ public File[] saveDataToFile() {
*/
@Override
public void controllerReady(MetaWearController mwController) {


loggingController= (Logging) mwController.getModuleController(Module.LOGGING);
}

@Override
public void onAttach(Activity activity) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
super.onAttach(activity);
}

@Override
public void onPause() {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
super.onPause();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Expand All @@ -402,17 +432,19 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
public void onViewCreated(final View view, Bundle savedInstanceState) {
Spinner spinnerObj;

spinnerObj= (Spinner) view.findViewById(R.id.spinner1);
spinnerObj.setAdapter(new ArrayAdapter<Sensor>(getActivity(),
R.layout.command_row, R.id.command_name, sensors));
spinnerObj.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
public void onItemSelected(AdapterView<?> parent, View innerView,
int position, long id) {
sensorIndex= position;
TextView description= (TextView) view.findViewById(R.id.textView2);
description.setText(sensors[sensorIndex].getDescription());
}

@Override
Expand Down

0 comments on commit 4cb9fe6

Please sign in to comment.