3434import androidx .appcompat .app .ActionBar ;
3535import androidx .appcompat .widget .Toolbar ;
3636import androidx .fragment .app .Fragment ;
37+ import androidx .recyclerview .widget .DefaultItemAnimator ;
38+ import androidx .recyclerview .widget .LinearLayoutManager ;
39+ import androidx .recyclerview .widget .RecyclerView ;
3740
3841import com .github .mikephil .charting .charts .LineChart ;
3942import com .github .mikephil .charting .components .Legend ;
6164import butterknife .ButterKnife ;
6265import io .pslab .R ;
6366import io .pslab .activity .guide .GuideActivity ;
67+ import io .pslab .adapters .OscilloscopeMeasurementsAdapter ;
6468import io .pslab .communication .AnalyticsClass ;
6569import io .pslab .communication .ScienceLab ;
6670import io .pslab .fragment .ChannelParametersFragment ;
7680import io .pslab .others .CustomSnackBar ;
7781import io .pslab .others .GPSLogger ;
7882import io .pslab .others .LocalDataLog ;
83+ import io .pslab .others .OscilloscopeMeasurements ;
7984import io .pslab .others .Plot2D ;
8085import io .pslab .others .ScienceLabCommon ;
8186import io .realm .Realm ;
@@ -164,6 +169,8 @@ public class OscilloscopeActivity extends GuideActivity implements View.OnClickL
164169 TextView xyPlotTextView ;
165170 @ BindView (R .id .parent_layout )
166171 View parentLayout ;
172+ @ BindView (R .id .recyclerView )
173+ RecyclerView measurementsList ;
167174 private Fragment channelParametersFragment ;
168175 private Fragment timebaseTriggerFragment ;
169176 private Fragment dataAnalysisFragment ;
@@ -184,6 +191,7 @@ public class OscilloscopeActivity extends GuideActivity implements View.OnClickL
184191 private double maxAmp , maxFreq ;
185192 private boolean isRecording = false ;
186193 private boolean isRunning = true ;
194+ private boolean isMeasurementsChecked = false ;
187195 private Realm realm ;
188196 public RealmResults <OscilloscopeData > recordedOscilloscopeData ;
189197 private CSVLogger csvLogger ;
@@ -201,7 +209,7 @@ public class OscilloscopeActivity extends GuideActivity implements View.OnClickL
201209 private double lon ;
202210 public boolean isPlaybackFourierChecked = false ;
203211 private HashMap <String , Integer > channelIndexMap ;
204- private final Integer [] channelColors = {Color .CYAN , Color .GREEN , Color .WHITE , Color .MAGENTA };
212+ public static final Integer [] channelColors = {Color .CYAN , Color .GREEN , Color .WHITE , Color .MAGENTA };
205213 private final String [] loggingYdata = new String [4 ];
206214 public String xyPlotAxis1 = "CH1" ;
207215 public String xyPlotAxis2 = "CH2" ;
@@ -211,10 +219,12 @@ public class OscilloscopeActivity extends GuideActivity implements View.OnClickL
211219 private ArrayList <ArrayList <Entry >> dataEntries = new ArrayList <>();
212220 private String [] dataParamsChannels ;
213221
214- private enum CHANNEL {CH1 , CH2 , CH3 , MIC }
222+ public enum CHANNEL {CH1 , CH2 , CH3 , MIC }
215223
216224 private enum MODE {RISING , FALLING , DUAL }
217225
226+ public enum ChannelMeasurements {FREQUENCY , PERIOD , AMPLITUDE , POSITIVE_PEAK , NEGATIVE_PEAK }
227+
218228 public OscilloscopeActivity () {
219229 super (R .layout .activity_oscilloscope );
220230 }
@@ -325,6 +335,8 @@ public void onSystemUiVisibilityChange(int i) {
325335 dataAnalysisTextView .setOnClickListener (this );
326336 xyPlotTextView .setOnClickListener (this );
327337
338+ measurementsList = findViewById (R .id .recyclerView );
339+
328340 chartInit ();
329341
330342 final Runnable runnable = new Runnable () {
@@ -624,6 +636,16 @@ public void onClick(View view) {
624636 autoScale ();
625637 }
626638 break ;
639+ case R .id .measurements :
640+ if (!isMeasurementsChecked ) {
641+ isMeasurementsChecked = true ;
642+ item .setChecked (true );
643+ measurementsList .setVisibility (View .VISIBLE );
644+ } else {
645+ isMeasurementsChecked = false ;
646+ item .setChecked (false );
647+ measurementsList .setVisibility (View .INVISIBLE );
648+ }
627649 default :
628650 break ;
629651 }
@@ -1214,6 +1236,43 @@ protected void onPostExecute(Void aVoid) {
12141236 }
12151237 }
12161238 }
1239+
1240+ if (!isFourierTransformSelected ) {
1241+ for (int i = 0 ; i < Math .min (entries .size (), paramsChannels .length ); i ++) {
1242+ CHANNEL channel = CHANNEL .valueOf (paramsChannels [i ]);
1243+ double minY = Double .MAX_VALUE ;
1244+ double maxY = -1 * Double .MIN_VALUE ;
1245+ double yRange ;
1246+ double [] voltage = new double [512 ];
1247+ ArrayList <Entry > entryArrayList = dataEntries .get (i );
1248+ for (int j = 0 ; j < entryArrayList .size (); j ++) {
1249+ Entry entry = entryArrayList .get (j );
1250+ if (j < voltage .length - 1 ) {
1251+ voltage [j ] = entry .getY ();
1252+ }
1253+ if (entry .getY () > maxY ) {
1254+ maxY = entry .getY ();
1255+ }
1256+ if (entry .getY () < minY ) {
1257+ minY = entry .getY ();
1258+ }
1259+ }
1260+ final double frequency ;
1261+ if (Objects .equals (dataParamsChannels [i ], CHANNEL .MIC .toString ())) {
1262+ frequency = analyticsClass .findFrequency (voltage , ((double ) 1 / SAMPLING_RATE ));
1263+ } else {
1264+ frequency = analyticsClass .findFrequency (voltage , timeGap / 1000000.0 );
1265+ }
1266+ double period = (1 / frequency ) * 1000.0 ;
1267+ yRange = maxY - minY ;
1268+ OscilloscopeMeasurements .channel .get (channel ).put (ChannelMeasurements .FREQUENCY , frequency );
1269+ OscilloscopeMeasurements .channel .get (channel ).put (ChannelMeasurements .PERIOD , period );
1270+ OscilloscopeMeasurements .channel .get (channel ).put (ChannelMeasurements .AMPLITUDE , yRange );
1271+ OscilloscopeMeasurements .channel .get (channel ).put (ChannelMeasurements .POSITIVE_PEAK , maxY );
1272+ OscilloscopeMeasurements .channel .get (channel ).put (ChannelMeasurements .NEGATIVE_PEAK , minY );
1273+ }
1274+ }
1275+
12171276 for (int i = 0 ; i < Math .min (entries .size (), paramsChannels .length ); i ++) {
12181277 LineDataSet dataSet ;
12191278 dataSet = new LineDataSet (entries .get (i ), paramsChannels [i ]);
@@ -1239,6 +1298,13 @@ protected void onPostExecute(Void aVoid) {
12391298 setLeftYAxisScale (yAxisScale , -1 * yAxisScale );
12401299 setRightYAxisScale (yAxisScale , -1 * yAxisScale );
12411300 }
1301+ if (isMeasurementsChecked ) {
1302+ RecyclerView .LayoutManager layoutManager = new LinearLayoutManager (OscilloscopeActivity .this );
1303+ measurementsList .setItemAnimator (new DefaultItemAnimator ());
1304+ measurementsList .setLayoutManager (layoutManager );
1305+ OscilloscopeMeasurementsAdapter adapter = new OscilloscopeMeasurementsAdapter (dataParamsChannels , channelColors );
1306+ measurementsList .setAdapter (adapter );
1307+ }
12421308 mChart .setData (data );
12431309 mChart .notifyDataSetChanged ();
12441310 mChart .invalidate ();
@@ -1272,9 +1338,9 @@ public void autoScale() {
12721338 }
12731339 final double frequency ;
12741340 if (Objects .equals (dataParamsChannels [i ], CHANNEL .MIC .toString ())) {
1275- frequency = analyticsClass .findFrequency (voltage , ((double ) 1 / SAMPLING_RATE ));
1341+ frequency = analyticsClass .findSignalFrequency (voltage , ((double ) 1 / SAMPLING_RATE ));
12761342 } else {
1277- frequency = analyticsClass .findFrequency (voltage , timeGap / 1000000.0 );
1343+ frequency = analyticsClass .findSignalFrequency (voltage , timeGap / 1000000.0 );
12781344 }
12791345 double period = (1 / frequency ) * 1000.0 ;
12801346 if (period > maxPeriod ) {
0 commit comments