• R/O
  • HTTP
  • SSH
  • HTTPS

BLEControl: コミット

BLE通信を行うためのアプリ。


コミットメタ情報

リビジョン3f047c8fe2c1d3567210b00a7fdb34ad163fd26d (tree)
日時2020-04-05 01:00:39
作者MRSa <mrsa@myad...>
コミッターMRSa

ログメッセージ

RAWデータ表示機能を追加。

変更サマリ

差分

--- a/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ble/connect/eeg/MindWaveCommunication.java
+++ b/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ble/connect/eeg/MindWaveCommunication.java
@@ -108,7 +108,7 @@ public class MindWaveCommunication implements BleDeviceFinder.BleScanResult
108108 dataReceiver.receivedRawData(value);
109109 return;
110110 }
111- SimpleLogDumper.dump_bytes("RECV SPP [" + data.length + "] ", data);
111+ //SimpleLogDumper.dump_bytes("RECV SPP [" + data.length + "] ", data);
112112 }
113113 catch (Exception e)
114114 {
--- a/app/src/main/java/net/osdn/gokigen/blecontrol/lib/data/brainwave/BrainwaveDataHolder.java
+++ b/app/src/main/java/net/osdn/gokigen/blecontrol/lib/data/brainwave/BrainwaveDataHolder.java
@@ -1,35 +1,80 @@
11 package net.osdn.gokigen.blecontrol.lib.data.brainwave;
22
3-import android.util.Log;
4-
53 import androidx.annotation.NonNull;
4+import androidx.annotation.Nullable;
65
76 import net.osdn.gokigen.blecontrol.lib.ui.brainwave.IBrainwaveDataDrawer;
87
8+import java.util.Arrays;
9+
910 public class BrainwaveDataHolder implements IBrainwaveDataReceiver
1011 {
11- private final String TAG = toString();
12+ //private final String TAG = toString();
1213
1314 private final IBrainwaveDataDrawer dataDrawer;
14- private int value;
15+ private int[] valueBuffer;
16+ private int maxBufferSize;
17+ private int currentPosition;
18+ private boolean bufferIsFull = false;
1519
16- public BrainwaveDataHolder(@NonNull IBrainwaveDataDrawer dataDrawer)
20+ public BrainwaveDataHolder(@NonNull IBrainwaveDataDrawer dataDrawer, int maxBufferSize)
1721 {
1822 this.dataDrawer = dataDrawer;
23+ this.maxBufferSize = maxBufferSize;
24+
25+ valueBuffer = new int[maxBufferSize];
26+ currentPosition = 0;
1927 }
2028
2129 @Override
2230 public void receivedRawData(int value)
2331 {
24- Log.v(TAG, " receivedRawData() : " + value);
25-
26- this.value = value;
27-
32+ //Log.v(TAG, " receivedRawData() : " + value);
33+ try
34+ {
35+ valueBuffer[currentPosition] = value;
36+ currentPosition++;
37+ if (currentPosition == maxBufferSize)
38+ {
39+ currentPosition = 0;
40+ bufferIsFull = true;
41+ }
42+ }
43+ catch (Exception e)
44+ {
45+ e.printStackTrace();
46+ }
2847 dataDrawer.drawGraph();
2948 }
3049
31- public int getValue()
50+ public @Nullable int[] getValues(int size)
3251 {
33- return (value);
52+ int [] replyData = null;
53+ try
54+ {
55+ int endPosition = currentPosition - 1;
56+ if (currentPosition > size)
57+ {
58+ return (Arrays.copyOfRange(valueBuffer, (endPosition - size), endPosition));
59+ }
60+ if (!bufferIsFull)
61+ {
62+ return (Arrays.copyOfRange(valueBuffer, 0, endPosition));
63+ }
64+
65+ int remainSize = size - (currentPosition - 1);
66+ int [] size0 = Arrays.copyOfRange(valueBuffer, 0, (currentPosition - 1));
67+ int [] size1 = Arrays.copyOfRange(valueBuffer, ((maxBufferSize - 1) - remainSize), (maxBufferSize - 1));
68+
69+ replyData = new int[size];
70+
71+ System.arraycopy(size0, 0, replyData, 0, size0.length);
72+ System.arraycopy(size1, 0, replyData, size0.length, size1.length);
73+ }
74+ catch (Exception e)
75+ {
76+ e.printStackTrace();
77+ }
78+ return (replyData);
3479 }
3580 }
--- a/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ui/MainActivity.java
+++ b/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ui/MainActivity.java
@@ -27,6 +27,7 @@ import androidx.appcompat.app.AppCompatActivity;
2727 import androidx.appcompat.widget.Toolbar;
2828
2929 import android.view.Menu;
30+import android.view.WindowManager;
3031
3132 import net.osdn.gokigen.blecontrol.lib.ble.R;
3233
@@ -42,6 +43,7 @@ public class MainActivity extends AppCompatActivity
4243 setContentView(R.layout.activity_main);
4344 Toolbar toolbar = findViewById(R.id.toolbar);
4445 setSupportActionBar(toolbar);
46+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
4547 setTitle(R.string.app_name);
4648 FloatingActionButton fab = findViewById(R.id.wifi);
4749 fab.setOnClickListener(new View.OnClickListener() {
--- a/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ui/brainwave/BrainwaveMobileFragment.java
+++ b/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ui/brainwave/BrainwaveMobileFragment.java
@@ -37,7 +37,7 @@ public class BrainwaveMobileFragment extends Fragment implements BrainwaveConnec
3737 final BrainwaveMobileViewModel brainwaveViewModel = ViewModelProviders.of(this).get(BrainwaveMobileViewModel.class);
3838 View root = inflater.inflate(R.layout.fragment_brainwave, container, false);
3939 final BrainwaveRawGraphView cameraLiveImageView = root.findViewById(R.id.cameraLiveImageView);
40- dataHolder = new BrainwaveDataHolder(cameraLiveImageView);
40+ dataHolder = new BrainwaveDataHolder(cameraLiveImageView, 16000);
4141 cameraLiveImageView.setDataHolder(dataHolder);
4242 final TextView textView = root.findViewById(R.id.text_brainwave);
4343 brainwaveViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
--- a/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ui/brainwave/BrainwaveRawGraphView.java
+++ b/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ui/brainwave/BrainwaveRawGraphView.java
@@ -65,14 +65,18 @@ public class BrainwaveRawGraphView extends View implements IBrainwaveDataDrawer
6565
6666 private void drawCanvas(Canvas canvas)
6767 {
68- int centerX = canvas.getWidth() / 2;
6968 int centerY = canvas.getHeight() / 2;
7069
71- Log.v(TAG, " Canvas SIZE : (" + canvas.getWidth() + "," + canvas.getHeight() +" )");
70+ float magnification = 1.0f;
71+ float maxRange = 2200.0f;
72+
73+ //Log.v(TAG, " Canvas SIZE : (" + canvas.getWidth() + "," + canvas.getHeight() +" )");
7274
7375 int rangeHeight = canvas.getHeight();
7476 int rangeWidth = canvas.getWidth();
7577
78+ float resolution = ((rangeHeight / 2.0f) / maxRange);
79+
7680 // Clears the canvas.
7781 canvas.drawARGB(255, 0, 0, 0);
7882
@@ -81,10 +85,43 @@ public class BrainwaveRawGraphView extends View implements IBrainwaveDataDrawer
8185 bgLine.setColor(Color.DKGRAY);
8286 canvas.drawLine(0, centerY, rangeWidth, centerY, bgLine);
8387
84-
8588 Paint paint = new Paint();
8689 paint.setColor(Color.WHITE);
87- canvas.drawText("[" + dataHolder.getValue() + "]", centerX, centerY, paint);
90+
91+ int maxValue = 0;
92+ int minValue = 0;
93+ int[] values = dataHolder.getValues(rangeWidth);
94+ if (values != null)
95+ {
96+ int pointX = 0;
97+ //magnification
98+ float previousY = centerY;
99+ for (int value : values)
100+ {
101+ float currentY = ((float)(value)) * resolution * magnification + centerY;
102+ canvas.drawLine(pointX, previousY, (pointX + 1), currentY, paint);
103+ pointX++;
104+ previousY = currentY;
105+ if (maxValue < value)
106+ {
107+ maxValue = value;
108+ }
109+ if (minValue > value)
110+ {
111+ minValue = value;
112+ }
113+ }
114+ }
115+ String message = "max: " + maxValue + " min: " + minValue;
116+ //Log.v(TAG, message);
117+ canvas.drawText(message, rangeWidth - 125, 20, paint);
118+
119+ paint.setColor(Color.argb(255, 32, 32, 32));
120+ float lineY = ((float)(maxValue)) * resolution * magnification + centerY;
121+ canvas.drawLine(0, lineY, canvas.getWidth(), lineY, paint);
122+
123+ lineY = ((float)(minValue)) * resolution * magnification + centerY;
124+ canvas.drawLine(0, lineY, canvas.getWidth(), lineY, paint);
88125 }
89126
90127
@@ -93,9 +130,9 @@ public class BrainwaveRawGraphView extends View implements IBrainwaveDataDrawer
93130 */
94131 private void drawInformationMessages(Canvas canvas)
95132 {
96- Paint paint = new Paint();
97- paint.setColor(Color.DKGRAY);
98- canvas.drawText("[" + canvas.getWidth() + "," + canvas.getHeight() + "]", 20, 20, paint);
133+ //Paint paint = new Paint();
134+ //paint.setColor(Color.DKGRAY);
135+ //canvas.drawText("[" + canvas.getWidth() + "," + canvas.getHeight() + "]", 20, 20, paint);
99136
100137 }
101138
旧リポジトリブラウザで表示