• R/O
  • HTTP
  • SSH
  • HTTPS

BLEControl: コミット

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


コミットメタ情報

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

ログメッセージ

1秒おきのサマリーデータを表示するようにした。

変更サマリ

差分

--- 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,6 +108,7 @@ public class MindWaveCommunication implements BleDeviceFinder.BleScanResult
108108 dataReceiver.receivedRawData(value);
109109 return;
110110 }
111+ dataReceiver.receivedSummaryData(data);
111112 //SimpleLogDumper.dump_bytes("RECV SPP [" + data.length + "] ", data);
112113 }
113114 catch (Exception e)
--- 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,5 +1,7 @@
11 package net.osdn.gokigen.blecontrol.lib.data.brainwave;
22
3+import android.util.Log;
4+
35 import androidx.annotation.NonNull;
46 import androidx.annotation.Nullable;
57
@@ -9,10 +11,11 @@ import java.util.Arrays;
911
1012 public class BrainwaveDataHolder implements IBrainwaveDataReceiver
1113 {
12- //private final String TAG = toString();
14+ private final String TAG = toString();
1315
1416 private final IBrainwaveDataDrawer dataDrawer;
1517 private int[] valueBuffer;
18+ private BrainwaveSummaryData currentSummaryData;
1619 private int maxBufferSize;
1720 private int currentPosition;
1821 private boolean bufferIsFull = false;
@@ -24,6 +27,8 @@ public class BrainwaveDataHolder implements IBrainwaveDataReceiver
2427
2528 valueBuffer = new int[maxBufferSize];
2629 currentPosition = 0;
30+
31+ currentSummaryData = new BrainwaveSummaryData();
2732 }
2833
2934 @Override
@@ -47,6 +52,21 @@ public class BrainwaveDataHolder implements IBrainwaveDataReceiver
4752 dataDrawer.drawGraph();
4853 }
4954
55+ @Override
56+ public void receivedSummaryData(byte[] data)
57+ {
58+ if (!currentSummaryData.update(data))
59+ {
60+ // parse failure...
61+ Log.v(TAG, " FAIL : PARSE EEG SUMMARY DATA (" + data.length + ")");
62+ }
63+ }
64+
65+ public @NonNull BrainwaveSummaryData getSummaryData()
66+ {
67+ return (currentSummaryData);
68+ }
69+
5070 public @Nullable int[] getValues(int size)
5171 {
5272 int [] replyData = null;
--- /dev/null
+++ b/app/src/main/java/net/osdn/gokigen/blecontrol/lib/data/brainwave/BrainwaveSummaryData.java
@@ -0,0 +1,118 @@
1+package net.osdn.gokigen.blecontrol.lib.data.brainwave;
2+
3+public class BrainwaveSummaryData
4+{
5+
6+ // 3-byte value : delta (0.5 - 2.75Hz), theta (3.5 - 6.75Hz), low-alpha (7.5 - 9.25Hz), high-alpha (10 - 11.75Hz), low-beta (13 - 16.75Hz), high-beta (18 - 29.75Hz), low-gamma (31 - 39.75Hz), and mid-gamma (41 - 49.75Hz).
7+ private int delta = 0;
8+ private int theta = 0;
9+ private int lowAlpha = 0;
10+ private int highAlpha = 0;
11+ private int lowBeta = 0;
12+ private int highBeta = 0;
13+ private int lowGamma = 0;
14+ private int midGamma = 0;
15+ private int poorSignal = 0;
16+ private int attention = 0;
17+ private int mediation = 0;
18+
19+ BrainwaveSummaryData()
20+ {
21+
22+ }
23+
24+ boolean update(byte[] packet)
25+ {
26+ boolean ret = false;
27+ try
28+ {
29+ int length = packet.length;
30+ if (length < 36)
31+ {
32+ return (ret);
33+ }
34+
35+ poorSignal = packet[4];
36+
37+ delta = (packet[ 7] & 0xff) * 65536 + (packet[ 8] & 0xff) * 256 + (packet[ 9] & 0xff);
38+ theta = (packet[10] & 0xff) * 65536 + (packet[11] & 0xff) * 256 + (packet[12] & 0xff);
39+ lowAlpha = (packet[13] & 0xff) * 65536 + (packet[14] & 0xff) * 256 + (packet[15] & 0xff);
40+ highAlpha = (packet[16] & 0xff) * 65536 + (packet[17] & 0xff) * 256 + (packet[18] & 0xff);
41+ lowBeta = (packet[19] & 0xff) * 65536 + (packet[20] & 0xff) * 256 + (packet[21] & 0xff);
42+ highBeta = (packet[22] & 0xff) * 65536 + (packet[23] & 0xff) * 256 + (packet[24] & 0xff);
43+ lowGamma = (packet[25] & 0xff) * 65536 + (packet[26] & 0xff) * 256 + (packet[27] & 0xff);
44+ midGamma = (packet[28] & 0xff) * 65536 + (packet[29] & 0xff) * 256 + (packet[30] & 0xff);
45+
46+ attention = (packet[32] & 0xff);
47+ mediation = (packet[34] & 0xff);
48+
49+ ret = true;
50+ }
51+ catch (Exception e)
52+ {
53+ e.printStackTrace();
54+ }
55+ return (ret);
56+ }
57+
58+ public boolean isSkinConnected()
59+ {
60+ return (!(poorSignal == 200));
61+ }
62+
63+ public int getPoorSignal()
64+ {
65+ return (poorSignal);
66+ }
67+
68+ public int getDelta()
69+ {
70+ return (delta);
71+ }
72+
73+ public int getTheta()
74+ {
75+ return (theta);
76+ }
77+
78+ public int getLowAlpha()
79+ {
80+ return (lowAlpha);
81+ }
82+
83+ public int getHighAlpha()
84+ {
85+ return (highAlpha);
86+ }
87+
88+ public int getLowBeta()
89+ {
90+ return (lowBeta);
91+ }
92+
93+ public int getHighBeta()
94+ {
95+ return (highBeta);
96+ }
97+
98+ public int getLowGamma()
99+ {
100+ return (lowGamma);
101+ }
102+
103+ public int getMidGamma()
104+ {
105+ return (midGamma);
106+ }
107+
108+ public int getAttention()
109+ {
110+ return (attention);
111+ }
112+
113+ public int getMediation()
114+ {
115+ return (mediation);
116+ }
117+
118+}
--- a/app/src/main/java/net/osdn/gokigen/blecontrol/lib/data/brainwave/IBrainwaveDataReceiver.java
+++ b/app/src/main/java/net/osdn/gokigen/blecontrol/lib/data/brainwave/IBrainwaveDataReceiver.java
@@ -3,4 +3,5 @@ package net.osdn.gokigen.blecontrol.lib.data.brainwave;
33 public interface IBrainwaveDataReceiver
44 {
55 void receivedRawData(int value);
6+ void receivedSummaryData(byte[] data);
67 }
--- 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
@@ -10,12 +10,15 @@ import android.view.View;
1010
1111 import androidx.annotation.NonNull;
1212
13+import net.osdn.gokigen.blecontrol.lib.ble.R;
1314 import net.osdn.gokigen.blecontrol.lib.data.brainwave.BrainwaveDataHolder;
15+import net.osdn.gokigen.blecontrol.lib.data.brainwave.BrainwaveSummaryData;
1416
1517 public class BrainwaveRawGraphView extends View implements IBrainwaveDataDrawer
1618 {
1719 private final String TAG = this.toString();
1820 private BrainwaveDataHolder dataHolder = null;
21+ private Context context = null;
1922
2023 public BrainwaveRawGraphView(@NonNull Context context)
2124 {
@@ -40,6 +43,7 @@ public class BrainwaveRawGraphView extends View implements IBrainwaveDataDrawer
4043 try
4144 {
4245 Log.v(TAG, " initialize.");
46+ this.context = context;
4347 }
4448 catch (Exception e)
4549 {
@@ -130,9 +134,91 @@ public class BrainwaveRawGraphView extends View implements IBrainwaveDataDrawer
130134 */
131135 private void drawInformationMessages(Canvas canvas)
132136 {
133- //Paint paint = new Paint();
134- //paint.setColor(Color.DKGRAY);
135- //canvas.drawText("[" + canvas.getWidth() + "," + canvas.getHeight() + "]", 20, 20, paint);
137+ try
138+ {
139+ BrainwaveSummaryData summaryData = dataHolder.getSummaryData();
140+ Paint paint = new Paint();
141+ paint.setColor(Color.DKGRAY);
142+
143+ Paint.FontMetrics metrics = paint.getFontMetrics();
144+ int lineHeight = (int) (metrics.bottom - metrics.top) + 2;
145+ int positionY = 20;
146+
147+ String message = context.getString(R.string.value_title_attention) + " " + summaryData.getAttention();
148+ canvas.drawText(message, 10, positionY, paint);
149+ positionY = positionY + lineHeight;
150+
151+ message = context.getString(R.string.value_title_mediation) + " " + summaryData.getMediation();
152+ canvas.drawText(message, 10, positionY, paint);
153+ positionY = positionY + lineHeight;
154+
155+
156+ if (!summaryData.isSkinConnected())
157+ {
158+ paint.setColor(Color.RED);
159+ String notConnectMessage = "Sensor lead is not connected.";
160+ if (context != null)
161+ {
162+ notConnectMessage = context.getString(R.string.sensor_not_contacted);
163+ }
164+ canvas.drawText(notConnectMessage, 10, positionY, paint);
165+ }
166+ paint.setColor(Color.DKGRAY);
167+ positionY = canvas.getHeight() - lineHeight;
168+
169+ int value = summaryData.getMidGamma();
170+ paint.setColor(Color.DKGRAY);
171+ message = context.getString(R.string.value_title_midGamma) + " " + value;
172+ canvas.drawText(message, 10, positionY, paint);
173+ positionY = positionY - lineHeight;
174+
175+ value = summaryData.getLowGamma();
176+ paint.setColor(Color.DKGRAY);
177+ message = context.getString(R.string.value_title_lowGamma) + " " + value;
178+ canvas.drawText(message, 10, positionY, paint);
179+ positionY = positionY - lineHeight;
180+
181+ value = summaryData.getHighBeta();
182+ paint.setColor(Color.DKGRAY);
183+ message = context.getString(R.string.value_title_highBeta) + " " + value;
184+ canvas.drawText(message, 10, positionY, paint);
185+ positionY = positionY - lineHeight;
186+
187+ value = summaryData.getLowBeta();
188+ paint.setColor(Color.DKGRAY);
189+ message = context.getString(R.string.value_title_lowBeta) + " " + value;
190+ canvas.drawText(message, 10, positionY, paint);
191+ positionY = positionY - lineHeight;
192+
193+ value = summaryData.getHighAlpha();
194+ paint.setColor(Color.DKGRAY);
195+ message = context.getString(R.string.value_title_highAlpha) + " " + value;
196+ canvas.drawText(message, 10, positionY, paint);
197+ positionY = positionY - lineHeight;
198+
199+ value = summaryData.getLowAlpha();
200+ paint.setColor(Color.DKGRAY);
201+ message = context.getString(R.string.value_title_lowAlpha) + " " + value;
202+ canvas.drawText(message, 10, positionY, paint);
203+ positionY = positionY - lineHeight;
204+
205+ value = summaryData.getTheta();
206+ paint.setColor(Color.DKGRAY);
207+ message = context.getString(R.string.value_title_theta) + " " + value;
208+ canvas.drawText(message, 10, positionY, paint);
209+ positionY = positionY - lineHeight;
210+
211+ value = summaryData.getDelta();
212+ paint.setColor(Color.DKGRAY);
213+ message = context.getString(R.string.value_title_delta) + " " + value;
214+ canvas.drawText(message, 10, positionY, paint);
215+ }
216+ catch (Exception e)
217+ {
218+ e.printStackTrace();
219+ }
220+
221+
136222
137223 }
138224
--- a/app/src/main/res/values-ja/strings.xml
+++ b/app/src/main/res/values-ja/strings.xml
@@ -60,5 +60,16 @@
6060 <string name="btn_cancel">Cancel</string>
6161
6262 <string name="connect_device">Connect</string>
63+ <string name="sensor_not_contacted">センサが肌に密着していません。</string>
6364
65+ <string name="value_title_delta">Delta(0.5&#8211;2.75Hz): </string>
66+ <string name="value_title_theta">Theta(3.5&#8211;6.75Hz): </string>
67+ <string name="value_title_lowAlpha">low Alpha(7.5&#8211;9.25Hz): </string>
68+ <string name="value_title_highAlpha">high Alpha(10&#8211;11.75Hz): </string>
69+ <string name="value_title_lowBeta">low Beta(13&#8211;16.75Hz): </string>
70+ <string name="value_title_highBeta">high Beta(18&#8211;29.75Hz): </string>
71+ <string name="value_title_lowGamma">low Gamma(31&#8211;39.75Hz): </string>
72+ <string name="value_title_midGamma">mid Gamma(41&#8211;49.75Hz): </string>
73+ <string name="value_title_attention">Attention: </string>
74+ <string name="value_title_mediation">Mediation: </string>
6475 </resources>
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -59,5 +59,16 @@
5959 <string name="btn_cancel">Cancel</string>
6060
6161 <string name="connect_device">Connect</string>
62+ <string name="sensor_not_contacted">Sensor lead is not contacted.</string>
6263
64+ <string name="value_title_delta">Delta(0.5&#8211;2.75Hz): </string>
65+ <string name="value_title_theta">Theta(3.5&#8211;6.75Hz): </string>
66+ <string name="value_title_lowAlpha">low Alpha(7.5&#8211;9.25Hz): </string>
67+ <string name="value_title_highAlpha">high Alpha(10&#8211;11.75Hz): </string>
68+ <string name="value_title_lowBeta">low Beta(13&#8211;16.75Hz): </string>
69+ <string name="value_title_highBeta">high Beta(18&#8211;29.75Hz): </string>
70+ <string name="value_title_lowGamma">low Gamma(31&#8211;39.75Hz): </string>
71+ <string name="value_title_midGamma">mid Gamma(41&#8211;49.75Hz): </string>
72+ <string name="value_title_attention">Attention: </string>
73+ <string name="value_title_mediation">Mediation: </string>
6374 </resources>
旧リポジトリブラウザで表示