BLE通信を行うためのアプリ。
Révision | 22d75a64258e6f32532b41099ee2376c8ce213cf (tree) |
---|---|
l'heure | 2020-04-05 23:23:00 |
Auteur | MRSa <mrsa@myad...> |
Commiter | MRSa |
1秒おきのサマリーデータを表示するようにした。
@@ -108,6 +108,7 @@ public class MindWaveCommunication implements BleDeviceFinder.BleScanResult | ||
108 | 108 | dataReceiver.receivedRawData(value); |
109 | 109 | return; |
110 | 110 | } |
111 | + dataReceiver.receivedSummaryData(data); | |
111 | 112 | //SimpleLogDumper.dump_bytes("RECV SPP [" + data.length + "] ", data); |
112 | 113 | } |
113 | 114 | catch (Exception e) |
@@ -1,5 +1,7 @@ | ||
1 | 1 | package net.osdn.gokigen.blecontrol.lib.data.brainwave; |
2 | 2 | |
3 | +import android.util.Log; | |
4 | + | |
3 | 5 | import androidx.annotation.NonNull; |
4 | 6 | import androidx.annotation.Nullable; |
5 | 7 |
@@ -9,10 +11,11 @@ import java.util.Arrays; | ||
9 | 11 | |
10 | 12 | public class BrainwaveDataHolder implements IBrainwaveDataReceiver |
11 | 13 | { |
12 | - //private final String TAG = toString(); | |
14 | + private final String TAG = toString(); | |
13 | 15 | |
14 | 16 | private final IBrainwaveDataDrawer dataDrawer; |
15 | 17 | private int[] valueBuffer; |
18 | + private BrainwaveSummaryData currentSummaryData; | |
16 | 19 | private int maxBufferSize; |
17 | 20 | private int currentPosition; |
18 | 21 | private boolean bufferIsFull = false; |
@@ -24,6 +27,8 @@ public class BrainwaveDataHolder implements IBrainwaveDataReceiver | ||
24 | 27 | |
25 | 28 | valueBuffer = new int[maxBufferSize]; |
26 | 29 | currentPosition = 0; |
30 | + | |
31 | + currentSummaryData = new BrainwaveSummaryData(); | |
27 | 32 | } |
28 | 33 | |
29 | 34 | @Override |
@@ -47,6 +52,21 @@ public class BrainwaveDataHolder implements IBrainwaveDataReceiver | ||
47 | 52 | dataDrawer.drawGraph(); |
48 | 53 | } |
49 | 54 | |
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 | + | |
50 | 70 | public @Nullable int[] getValues(int size) |
51 | 71 | { |
52 | 72 | int [] replyData = null; |
@@ -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 | +} |
@@ -3,4 +3,5 @@ package net.osdn.gokigen.blecontrol.lib.data.brainwave; | ||
3 | 3 | public interface IBrainwaveDataReceiver |
4 | 4 | { |
5 | 5 | void receivedRawData(int value); |
6 | + void receivedSummaryData(byte[] data); | |
6 | 7 | } |
@@ -10,12 +10,15 @@ import android.view.View; | ||
10 | 10 | |
11 | 11 | import androidx.annotation.NonNull; |
12 | 12 | |
13 | +import net.osdn.gokigen.blecontrol.lib.ble.R; | |
13 | 14 | import net.osdn.gokigen.blecontrol.lib.data.brainwave.BrainwaveDataHolder; |
15 | +import net.osdn.gokigen.blecontrol.lib.data.brainwave.BrainwaveSummaryData; | |
14 | 16 | |
15 | 17 | public class BrainwaveRawGraphView extends View implements IBrainwaveDataDrawer |
16 | 18 | { |
17 | 19 | private final String TAG = this.toString(); |
18 | 20 | private BrainwaveDataHolder dataHolder = null; |
21 | + private Context context = null; | |
19 | 22 | |
20 | 23 | public BrainwaveRawGraphView(@NonNull Context context) |
21 | 24 | { |
@@ -40,6 +43,7 @@ public class BrainwaveRawGraphView extends View implements IBrainwaveDataDrawer | ||
40 | 43 | try |
41 | 44 | { |
42 | 45 | Log.v(TAG, " initialize."); |
46 | + this.context = context; | |
43 | 47 | } |
44 | 48 | catch (Exception e) |
45 | 49 | { |
@@ -130,9 +134,91 @@ public class BrainwaveRawGraphView extends View implements IBrainwaveDataDrawer | ||
130 | 134 | */ |
131 | 135 | private void drawInformationMessages(Canvas canvas) |
132 | 136 | { |
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 | + | |
136 | 222 | |
137 | 223 | } |
138 | 224 |
@@ -60,5 +60,16 @@ | ||
60 | 60 | <string name="btn_cancel">Cancel</string> |
61 | 61 | |
62 | 62 | <string name="connect_device">Connect</string> |
63 | + <string name="sensor_not_contacted">センサが肌に密着していません。</string> | |
63 | 64 | |
65 | + <string name="value_title_delta">Delta(0.5–2.75Hz): </string> | |
66 | + <string name="value_title_theta">Theta(3.5–6.75Hz): </string> | |
67 | + <string name="value_title_lowAlpha">low Alpha(7.5–9.25Hz): </string> | |
68 | + <string name="value_title_highAlpha">high Alpha(10–11.75Hz): </string> | |
69 | + <string name="value_title_lowBeta">low Beta(13–16.75Hz): </string> | |
70 | + <string name="value_title_highBeta">high Beta(18–29.75Hz): </string> | |
71 | + <string name="value_title_lowGamma">low Gamma(31–39.75Hz): </string> | |
72 | + <string name="value_title_midGamma">mid Gamma(41–49.75Hz): </string> | |
73 | + <string name="value_title_attention">Attention: </string> | |
74 | + <string name="value_title_mediation">Mediation: </string> | |
64 | 75 | </resources> |
@@ -59,5 +59,16 @@ | ||
59 | 59 | <string name="btn_cancel">Cancel</string> |
60 | 60 | |
61 | 61 | <string name="connect_device">Connect</string> |
62 | + <string name="sensor_not_contacted">Sensor lead is not contacted.</string> | |
62 | 63 | |
64 | + <string name="value_title_delta">Delta(0.5–2.75Hz): </string> | |
65 | + <string name="value_title_theta">Theta(3.5–6.75Hz): </string> | |
66 | + <string name="value_title_lowAlpha">low Alpha(7.5–9.25Hz): </string> | |
67 | + <string name="value_title_highAlpha">high Alpha(10–11.75Hz): </string> | |
68 | + <string name="value_title_lowBeta">low Beta(13–16.75Hz): </string> | |
69 | + <string name="value_title_highBeta">high Beta(18–29.75Hz): </string> | |
70 | + <string name="value_title_lowGamma">low Gamma(31–39.75Hz): </string> | |
71 | + <string name="value_title_midGamma">mid Gamma(41–49.75Hz): </string> | |
72 | + <string name="value_title_attention">Attention: </string> | |
73 | + <string name="value_title_mediation">Mediation: </string> | |
63 | 74 | </resources> |