BLE通信を行うためのアプリ。
Révision | 3f047c8fe2c1d3567210b00a7fdb34ad163fd26d (tree) |
---|---|
l'heure | 2020-04-05 01:00:39 |
Auteur | MRSa <mrsa@myad...> |
Commiter | MRSa |
RAWデータ表示機能を追加。
@@ -108,7 +108,7 @@ public class MindWaveCommunication implements BleDeviceFinder.BleScanResult | ||
108 | 108 | dataReceiver.receivedRawData(value); |
109 | 109 | return; |
110 | 110 | } |
111 | - SimpleLogDumper.dump_bytes("RECV SPP [" + data.length + "] ", data); | |
111 | + //SimpleLogDumper.dump_bytes("RECV SPP [" + data.length + "] ", data); | |
112 | 112 | } |
113 | 113 | catch (Exception e) |
114 | 114 | { |
@@ -1,35 +1,80 @@ | ||
1 | 1 | package net.osdn.gokigen.blecontrol.lib.data.brainwave; |
2 | 2 | |
3 | -import android.util.Log; | |
4 | - | |
5 | 3 | import androidx.annotation.NonNull; |
4 | +import androidx.annotation.Nullable; | |
6 | 5 | |
7 | 6 | import net.osdn.gokigen.blecontrol.lib.ui.brainwave.IBrainwaveDataDrawer; |
8 | 7 | |
8 | +import java.util.Arrays; | |
9 | + | |
9 | 10 | public class BrainwaveDataHolder implements IBrainwaveDataReceiver |
10 | 11 | { |
11 | - private final String TAG = toString(); | |
12 | + //private final String TAG = toString(); | |
12 | 13 | |
13 | 14 | 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; | |
15 | 19 | |
16 | - public BrainwaveDataHolder(@NonNull IBrainwaveDataDrawer dataDrawer) | |
20 | + public BrainwaveDataHolder(@NonNull IBrainwaveDataDrawer dataDrawer, int maxBufferSize) | |
17 | 21 | { |
18 | 22 | this.dataDrawer = dataDrawer; |
23 | + this.maxBufferSize = maxBufferSize; | |
24 | + | |
25 | + valueBuffer = new int[maxBufferSize]; | |
26 | + currentPosition = 0; | |
19 | 27 | } |
20 | 28 | |
21 | 29 | @Override |
22 | 30 | public void receivedRawData(int value) |
23 | 31 | { |
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 | + } | |
28 | 47 | dataDrawer.drawGraph(); |
29 | 48 | } |
30 | 49 | |
31 | - public int getValue() | |
50 | + public @Nullable int[] getValues(int size) | |
32 | 51 | { |
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); | |
34 | 79 | } |
35 | 80 | } |
@@ -27,6 +27,7 @@ import androidx.appcompat.app.AppCompatActivity; | ||
27 | 27 | import androidx.appcompat.widget.Toolbar; |
28 | 28 | |
29 | 29 | import android.view.Menu; |
30 | +import android.view.WindowManager; | |
30 | 31 | |
31 | 32 | import net.osdn.gokigen.blecontrol.lib.ble.R; |
32 | 33 |
@@ -42,6 +43,7 @@ public class MainActivity extends AppCompatActivity | ||
42 | 43 | setContentView(R.layout.activity_main); |
43 | 44 | Toolbar toolbar = findViewById(R.id.toolbar); |
44 | 45 | setSupportActionBar(toolbar); |
46 | + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); | |
45 | 47 | setTitle(R.string.app_name); |
46 | 48 | FloatingActionButton fab = findViewById(R.id.wifi); |
47 | 49 | fab.setOnClickListener(new View.OnClickListener() { |
@@ -37,7 +37,7 @@ public class BrainwaveMobileFragment extends Fragment implements BrainwaveConnec | ||
37 | 37 | final BrainwaveMobileViewModel brainwaveViewModel = ViewModelProviders.of(this).get(BrainwaveMobileViewModel.class); |
38 | 38 | View root = inflater.inflate(R.layout.fragment_brainwave, container, false); |
39 | 39 | final BrainwaveRawGraphView cameraLiveImageView = root.findViewById(R.id.cameraLiveImageView); |
40 | - dataHolder = new BrainwaveDataHolder(cameraLiveImageView); | |
40 | + dataHolder = new BrainwaveDataHolder(cameraLiveImageView, 16000); | |
41 | 41 | cameraLiveImageView.setDataHolder(dataHolder); |
42 | 42 | final TextView textView = root.findViewById(R.id.text_brainwave); |
43 | 43 | brainwaveViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() { |
@@ -65,14 +65,18 @@ public class BrainwaveRawGraphView extends View implements IBrainwaveDataDrawer | ||
65 | 65 | |
66 | 66 | private void drawCanvas(Canvas canvas) |
67 | 67 | { |
68 | - int centerX = canvas.getWidth() / 2; | |
69 | 68 | int centerY = canvas.getHeight() / 2; |
70 | 69 | |
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() +" )"); | |
72 | 74 | |
73 | 75 | int rangeHeight = canvas.getHeight(); |
74 | 76 | int rangeWidth = canvas.getWidth(); |
75 | 77 | |
78 | + float resolution = ((rangeHeight / 2.0f) / maxRange); | |
79 | + | |
76 | 80 | // Clears the canvas. |
77 | 81 | canvas.drawARGB(255, 0, 0, 0); |
78 | 82 |
@@ -81,10 +85,43 @@ public class BrainwaveRawGraphView extends View implements IBrainwaveDataDrawer | ||
81 | 85 | bgLine.setColor(Color.DKGRAY); |
82 | 86 | canvas.drawLine(0, centerY, rangeWidth, centerY, bgLine); |
83 | 87 | |
84 | - | |
85 | 88 | Paint paint = new Paint(); |
86 | 89 | 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); | |
88 | 125 | } |
89 | 126 | |
90 | 127 |
@@ -93,9 +130,9 @@ public class BrainwaveRawGraphView extends View implements IBrainwaveDataDrawer | ||
93 | 130 | */ |
94 | 131 | private void drawInformationMessages(Canvas canvas) |
95 | 132 | { |
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); | |
99 | 136 | |
100 | 137 | } |
101 | 138 |