BLE通信を行うためのアプリ。
Révision | 3700f9888a182a701f9848cd55d5e2101379ee07 (tree) |
---|---|
l'heure | 2020-04-04 00:24:47 |
Auteur | MRSa <mrsa@myad...> |
Commiter | MRSa |
RAWデータ表示の準備。
@@ -98,7 +98,17 @@ public class MindWaveCommunication implements BleDeviceFinder.BleScanResult | ||
98 | 98 | return; |
99 | 99 | } |
100 | 100 | |
101 | - SimpleLogDumper.dump_bytes("RECV SPP : ", data); | |
101 | + if ((data.length == 8)||(data.length == 9)) | |
102 | + { | |
103 | + int value = ((data[5] & 0xff) * 256) + (data[6] & 0xff); | |
104 | + if (value > 32768) | |
105 | + { | |
106 | + value = value - 65536; | |
107 | + } | |
108 | + dataReceiver.receivedRawData(value); | |
109 | + return; | |
110 | + } | |
111 | + SimpleLogDumper.dump_bytes("RECV SPP [" + data.length + "] ", data); | |
102 | 112 | } |
103 | 113 | catch (Exception e) |
104 | 114 | { |
@@ -175,6 +185,12 @@ public class MindWaveCommunication implements BleDeviceFinder.BleScanResult | ||
175 | 185 | { |
176 | 186 | try |
177 | 187 | { |
188 | + if (foundDevice) | |
189 | + { | |
190 | + // すでに見つかっている | |
191 | + Log.v(TAG, " ALREADY FIND."); | |
192 | + return; | |
193 | + } | |
178 | 194 | foundDevice = true; |
179 | 195 | final BluetoothSocket btSocket = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")); |
180 | 196 | Thread thread = new Thread(new Runnable() { |
@@ -1,12 +1,17 @@ | ||
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 | |
5 | 7 | import net.osdn.gokigen.blecontrol.lib.ui.brainwave.IBrainwaveDataDrawer; |
6 | 8 | |
7 | 9 | public class BrainwaveDataHolder implements IBrainwaveDataReceiver |
8 | 10 | { |
11 | + private final String TAG = toString(); | |
12 | + | |
9 | 13 | private final IBrainwaveDataDrawer dataDrawer; |
14 | + private int value; | |
10 | 15 | |
11 | 16 | public BrainwaveDataHolder(@NonNull IBrainwaveDataDrawer dataDrawer) |
12 | 17 | { |
@@ -14,10 +19,17 @@ public class BrainwaveDataHolder implements IBrainwaveDataReceiver | ||
14 | 19 | } |
15 | 20 | |
16 | 21 | @Override |
17 | - public void receivedRawData(byte value) | |
22 | + public void receivedRawData(int value) | |
18 | 23 | { |
24 | + Log.v(TAG, " receivedRawData() : " + value); | |
19 | 25 | |
26 | + this.value = value; | |
20 | 27 | |
21 | 28 | dataDrawer.drawGraph(); |
22 | 29 | } |
30 | + | |
31 | + public int getValue() | |
32 | + { | |
33 | + return (value); | |
34 | + } | |
23 | 35 | } |
@@ -2,5 +2,5 @@ package net.osdn.gokigen.blecontrol.lib.data.brainwave; | ||
2 | 2 | |
3 | 3 | public interface IBrainwaveDataReceiver |
4 | 4 | { |
5 | - void receivedRawData(byte value); | |
5 | + void receivedRawData(int value); | |
6 | 6 | } |
@@ -2,6 +2,8 @@ package net.osdn.gokigen.blecontrol.lib.ui.brainwave; | ||
2 | 2 | |
3 | 3 | import android.content.Context; |
4 | 4 | import android.graphics.Canvas; |
5 | +import android.graphics.Color; | |
6 | +import android.graphics.Paint; | |
5 | 7 | import android.util.AttributeSet; |
6 | 8 | import android.util.Log; |
7 | 9 | import android.view.View; |
@@ -37,7 +39,7 @@ public class BrainwaveRawGraphView extends View implements IBrainwaveDataDrawer | ||
37 | 39 | { |
38 | 40 | try |
39 | 41 | { |
40 | - | |
42 | + Log.v(TAG, " initialize."); | |
41 | 43 | } |
42 | 44 | catch (Exception e) |
43 | 45 | { |
@@ -63,15 +65,26 @@ public class BrainwaveRawGraphView extends View implements IBrainwaveDataDrawer | ||
63 | 65 | |
64 | 66 | private void drawCanvas(Canvas canvas) |
65 | 67 | { |
66 | - //int centerX = canvas.getWidth() / 2; | |
67 | - //int centerY = canvas.getHeight() / 2; | |
68 | + int centerX = canvas.getWidth() / 2; | |
69 | + int centerY = canvas.getHeight() / 2; | |
68 | 70 | |
69 | 71 | Log.v(TAG, " Canvas SIZE : (" + canvas.getWidth() + "," + canvas.getHeight() +" )"); |
70 | 72 | |
71 | 73 | int rangeHeight = canvas.getHeight(); |
74 | + int rangeWidth = canvas.getWidth(); | |
72 | 75 | |
73 | 76 | // Clears the canvas. |
74 | 77 | canvas.drawARGB(255, 0, 0, 0); |
78 | + | |
79 | + // 背景真ん中のライン | |
80 | + Paint bgLine = new Paint(); | |
81 | + bgLine.setColor(Color.DKGRAY); | |
82 | + canvas.drawLine(0, centerY, rangeWidth, centerY, bgLine); | |
83 | + | |
84 | + | |
85 | + Paint paint = new Paint(); | |
86 | + paint.setColor(Color.WHITE); | |
87 | + canvas.drawText("[" + dataHolder.getValue() + "]", centerX, centerY, paint); | |
75 | 88 | } |
76 | 89 | |
77 | 90 |
@@ -80,6 +93,9 @@ public class BrainwaveRawGraphView extends View implements IBrainwaveDataDrawer | ||
80 | 93 | */ |
81 | 94 | private void drawInformationMessages(Canvas canvas) |
82 | 95 | { |
96 | + Paint paint = new Paint(); | |
97 | + paint.setColor(Color.DKGRAY); | |
98 | + canvas.drawText("[" + canvas.getWidth() + "," + canvas.getHeight() + "]", 20, 20, paint); | |
83 | 99 | |
84 | 100 | } |
85 | 101 |
@@ -7,7 +7,7 @@ buildscript { | ||
7 | 7 | |
8 | 8 | } |
9 | 9 | dependencies { |
10 | - classpath 'com.android.tools.build:gradle:3.6.1' | |
10 | + classpath 'com.android.tools.build:gradle:3.6.2' | |
11 | 11 | |
12 | 12 | // NOTE: Do not place your application dependencies here; they belong |
13 | 13 | // in the individual module build.gradle files |