Ricoh Theta x Nurosky Shutter
Révision | 74a755c52f4e1c46c866975a26d22fb2fd62237d (tree) |
---|---|
l'heure | 2021-02-22 23:32:08 |
Auteur | MRSa <mrsa@myad...> |
Commiter | MRSa |
データが報告されてくるようになった。
@@ -10,7 +10,6 @@ import com.theta360.pluginlibrary.receiver.KeyReceiver | ||
10 | 10 | import com.theta360.pluginlibrary.values.LedColor |
11 | 11 | import com.theta360.pluginlibrary.values.LedTarget |
12 | 12 | import jp.osdn.gokigen.thetathoughtshutter.R.layout |
13 | -import jp.osdn.gokigen.thetathoughtshutter.bluetooth.connection.BluetoothDeviceFinder | |
14 | 13 | import jp.osdn.gokigen.thetathoughtshutter.bluetooth.connection.IBluetoothScanResult |
15 | 14 | import jp.osdn.gokigen.thetathoughtshutter.bluetooth.connection.eeg.MindWaveConnection |
16 | 15 | import jp.osdn.gokigen.thetathoughtshutter.brainwave.BrainwaveDataHolder |
@@ -23,8 +22,7 @@ class MainActivity : PluginActivity(), IBluetoothScanResult | ||
23 | 22 | { |
24 | 23 | private val thetaHardwareControl = ThetaHardwareControl(this) |
25 | 24 | private val applicationStatus : MyApplicationStatus = MyApplicationStatus() |
26 | - //private val bluetoothFinder = BluetoothDeviceFinder(this, this) | |
27 | - private val bluetoothConnection = MindWaveConnection(this, BrainwaveDataHolder()) | |
25 | + private val bluetoothConnection = MindWaveConnection(this, BrainwaveDataHolder(), this) | |
28 | 26 | |
29 | 27 | companion object |
30 | 28 | { |
@@ -74,25 +72,23 @@ class MainActivity : PluginActivity(), IBluetoothScanResult | ||
74 | 72 | } |
75 | 73 | if (keyCode == KeyReceiver.KEYCODE_MEDIA_RECORD) // Modeボタン |
76 | 74 | { |
77 | - if (applicationStatus.status == MyApplicationStatus.Status.Searching) | |
78 | - { | |
79 | - // ダミー処理 (EEG接続完了) | |
80 | - applicationStatus.status = MyApplicationStatus.Status.Connected | |
81 | - } | |
82 | - else if (applicationStatus.status == MyApplicationStatus.Status.Scanning) | |
83 | - { | |
84 | - // ダミー処理 (高まっている状態) | |
85 | - applicationStatus.status = MyApplicationStatus.Status.Syncing | |
86 | - } | |
87 | - else if (applicationStatus.status == MyApplicationStatus.Status.Syncing) | |
88 | - { | |
89 | - // ダミー処理 (高まるのを待っている状態) | |
90 | - applicationStatus.status = MyApplicationStatus.Status.Scanning | |
91 | - } | |
92 | - else | |
93 | - { | |
94 | - // ダミー処理 (初期化完了) | |
95 | - applicationStatus.status = MyApplicationStatus.Status.Initialized | |
75 | + when (applicationStatus.status) { | |
76 | + MyApplicationStatus.Status.Searching -> { | |
77 | + // ダミー処理 (EEG接続完了) | |
78 | + applicationStatus.status = MyApplicationStatus.Status.Connected | |
79 | + } | |
80 | + MyApplicationStatus.Status.Scanning -> { | |
81 | + // ダミー処理 (高まっている状態) | |
82 | + applicationStatus.status = MyApplicationStatus.Status.Syncing | |
83 | + } | |
84 | + MyApplicationStatus.Status.Syncing -> { | |
85 | + // ダミー処理 (高まるのを待っている状態) | |
86 | + applicationStatus.status = MyApplicationStatus.Status.Scanning | |
87 | + } | |
88 | + else -> { | |
89 | + // ダミー処理 (初期化完了) | |
90 | + applicationStatus.status = MyApplicationStatus.Status.Initialized | |
91 | + } | |
96 | 92 | } |
97 | 93 | } |
98 | 94 | /* |
@@ -198,16 +194,11 @@ class MainActivity : PluginActivity(), IBluetoothScanResult | ||
198 | 194 | super.onResume() |
199 | 195 | if (isApConnected) |
200 | 196 | { |
201 | - | |
197 | + Log.v(TAG , " isApConnected : $isApConnected") | |
202 | 198 | } |
203 | 199 | initializeBluetooth() |
204 | 200 | } |
205 | 201 | |
206 | - override fun onPause() | |
207 | - { | |
208 | - super.onPause() | |
209 | - } | |
210 | - | |
211 | 202 | private fun initializeBluetooth() |
212 | 203 | { |
213 | 204 | try |
@@ -35,7 +35,7 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv | ||
35 | 35 | { |
36 | 36 | override fun onReceive(context: Context, intent: Intent) |
37 | 37 | { |
38 | - onReceiveBroadcastOfConnection(this, context, intent) | |
38 | + onReceiveBroadcastOfConnection(this, intent) | |
39 | 39 | } |
40 | 40 | } |
41 | 41 |
@@ -125,10 +125,10 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv | ||
125 | 125 | |
126 | 126 | private fun serialCommunicationMain(btSocket: BluetoothSocket) |
127 | 127 | { |
128 | - Log.v(TAG, "serialCommunicationMain ") | |
129 | 128 | var inputStream: InputStream? = null |
130 | 129 | try |
131 | 130 | { |
131 | + Log.v(TAG, "serialCommunicationMain connect") | |
132 | 132 | btSocket.connect() |
133 | 133 | inputStream = btSocket.inputStream |
134 | 134 | } |
@@ -138,6 +138,7 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv | ||
138 | 138 | } |
139 | 139 | if (inputStream == null) |
140 | 140 | { |
141 | + Log.v(TAG, "serialCommunicationMain INPUT STREAM IS NULL...") | |
141 | 142 | return |
142 | 143 | } |
143 | 144 | if (loggingFlag) |
@@ -152,6 +153,8 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv | ||
152 | 153 | e.printStackTrace() |
153 | 154 | } |
154 | 155 | } |
156 | + Log.v(TAG, " serialCommunicationMain : SERIAL COMMUNICATION STARTED.") | |
157 | + | |
155 | 158 | |
156 | 159 | // シリアルデータの受信メイン部分 |
157 | 160 | var previousData = 0xff.toByte() |
@@ -161,7 +164,7 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv | ||
161 | 164 | try |
162 | 165 | { |
163 | 166 | val data: Int = inputStream.read() |
164 | - Log.v(TAG, " RECEIVED ") | |
167 | + //Log.v(TAG, " RECEIVED ") | |
165 | 168 | val byteData = (data and 0xff).toByte() |
166 | 169 | if (previousData == byteData && byteData == 0xaa.toByte()) |
167 | 170 | { |
@@ -192,7 +195,6 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv | ||
192 | 195 | } |
193 | 196 | } |
194 | 197 | |
195 | - | |
196 | 198 | override fun foundBluetoothDevice(device: BluetoothDevice) |
197 | 199 | { |
198 | 200 | try |
@@ -210,6 +212,16 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv | ||
210 | 212 | connectBluetoothDevice(device) |
211 | 213 | return |
212 | 214 | } |
215 | + else if (device.bondState == BluetoothDevice.BOND_NONE) | |
216 | + { | |
217 | + // まだペアリングしていない... | |
218 | + Log.v(TAG, " NOT PAIRED, START PAIRING : ${device.name}") | |
219 | + isPairing = true | |
220 | + targetDevice = device | |
221 | + device.setPin(byteArrayOf(0x30, 0x30, 0x30, 0x30)) | |
222 | + device.createBond() | |
223 | + return | |
224 | + } | |
213 | 225 | |
214 | 226 | if ((!foundDevice)&&(!isPairing)) |
215 | 227 | { |
@@ -225,78 +237,7 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv | ||
225 | 237 | { |
226 | 238 | e.printStackTrace() |
227 | 239 | } |
228 | - //return (device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"))) | |
229 | - } | |
230 | - | |
231 | - | |
232 | -/* | |
233 | - private fun prepareBluetoothDevice(device: BluetoothDevice) : BluetoothSocket? | |
234 | - { | |
235 | - try | |
236 | - { | |
237 | - device.setPin(byteArrayOf(0x30,0x30, 0x30, 0x30)) | |
238 | - | |
239 | - val result = device.createBond() | |
240 | - if (!result) | |
241 | - { | |
242 | - // ペアリング失敗 | |
243 | - return (null) | |
244 | - } | |
245 | - | |
246 | - | |
247 | - } | |
248 | - catch (e : Exception) | |
249 | - { | |
250 | - e.printStackTrace() | |
251 | - } | |
252 | - return (device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"))) | |
253 | - } | |
254 | - | |
255 | - override fun foundBluetoothDevice(device: BluetoothDevice) | |
256 | - { | |
257 | - try | |
258 | - { | |
259 | - Log.v(TAG, " foundBluetoothDevice : ${device.name}") | |
260 | - if (foundDevice) | |
261 | - { | |
262 | - // デバイスがすでに見つかっている | |
263 | - Log.v(TAG, " ALREADY FIND BLUETOOTH DEVICE. : $device.name") | |
264 | - deviceFinder.stopScan() | |
265 | - return | |
266 | - } | |
267 | - foundDevice = true | |
268 | - deviceFinder.stopScan() | |
269 | - | |
270 | - val btSocket = prepareBluetoothDevice(device) // device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")) | |
271 | - val thread = Thread { | |
272 | - try | |
273 | - { | |
274 | - if (btSocket != null) | |
275 | - { | |
276 | - serialCommunicationMain(btSocket) | |
277 | - } | |
278 | - } | |
279 | - catch (e: Exception) | |
280 | - { | |
281 | - e.printStackTrace() | |
282 | - } | |
283 | - } | |
284 | - if (btSocket != null) | |
285 | - { | |
286 | - thread.start() | |
287 | - } | |
288 | - else | |
289 | - { | |
290 | - Log.v(TAG, " btSocket is NULL.") | |
291 | - } | |
292 | - scanResult?.foundBluetoothDevice(device) | |
293 | - } | |
294 | - catch (e: Exception) | |
295 | - { | |
296 | - e.printStackTrace() | |
297 | - } | |
298 | 240 | } |
299 | -*/ | |
300 | 241 | |
301 | 242 | private fun connectBluetoothDevice(device : BluetoothDevice?) |
302 | 243 | { |
@@ -325,13 +266,15 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv | ||
325 | 266 | } |
326 | 267 | if (btSocket != null) |
327 | 268 | { |
269 | + scanResult?.foundBluetoothDevice(device) | |
328 | 270 | thread.start() |
271 | + unregisterReceiver() | |
329 | 272 | } |
330 | 273 | else |
331 | 274 | { |
332 | 275 | Log.v(TAG, " btSocket is NULL.") |
333 | 276 | } |
334 | - scanResult?.foundBluetoothDevice(device) | |
277 | + //scanResult?.foundBluetoothDevice(device) | |
335 | 278 | } |
336 | 279 | catch (e: Exception) |
337 | 280 | { |
@@ -350,7 +293,7 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv | ||
350 | 293 | * |
351 | 294 | * |
352 | 295 | */ |
353 | - private fun onReceiveBroadcastOfConnection(receiver: BroadcastReceiver, context: Context, intent: Intent) | |
296 | + private fun onReceiveBroadcastOfConnection(receiver: BroadcastReceiver, intent: Intent) | |
354 | 297 | { |
355 | 298 | val action = intent.action |
356 | 299 | if (action == null) |
@@ -1,11 +1,15 @@ | ||
1 | 1 | package jp.osdn.gokigen.thetathoughtshutter.brainwave |
2 | 2 | |
3 | 3 | import android.util.Log |
4 | +import jp.osdn.gokigen.thetathoughtshutter.bluetooth.connection.eeg.MindWaveConnection | |
4 | 5 | import java.util.* |
5 | 6 | |
6 | 7 | class BrainwaveDataHolder(maxBufferSize: Int = 16000) : IBrainwaveDataReceiver |
7 | 8 | { |
8 | - private val TAG = toString() | |
9 | + companion object | |
10 | + { | |
11 | + private val TAG = BrainwaveDataHolder::class.java.simpleName | |
12 | + } | |
9 | 13 | |
10 | 14 | private var valueBuffer: IntArray |
11 | 15 | private var currentSummaryData = BrainwaveSummaryData() |
@@ -21,15 +25,19 @@ class BrainwaveDataHolder(maxBufferSize: Int = 16000) : IBrainwaveDataReceiver | ||
21 | 25 | |
22 | 26 | override fun receivedRawData(value: Int) |
23 | 27 | { |
24 | - Log.v(TAG, " receivedRawData() : $value"); | |
25 | - try { | |
28 | + //Log.v(TAG, " receivedRawData() : $value"); | |
29 | + try | |
30 | + { | |
26 | 31 | valueBuffer[currentPosition] = value |
27 | 32 | currentPosition++ |
28 | - if (currentPosition == maxBufferSize) { | |
33 | + if (currentPosition == maxBufferSize) | |
34 | + { | |
29 | 35 | currentPosition = 0 |
30 | 36 | bufferIsFull = true |
31 | 37 | } |
32 | - } catch (e: Exception) { | |
38 | + } | |
39 | + catch (e: Exception) | |
40 | + { | |
33 | 41 | e.printStackTrace() |
34 | 42 | } |
35 | 43 | } |
@@ -38,6 +46,7 @@ class BrainwaveDataHolder(maxBufferSize: Int = 16000) : IBrainwaveDataReceiver | ||
38 | 46 | { |
39 | 47 | if (data != null) |
40 | 48 | { |
49 | + Log.v(TAG, " receivedSummaryData() : ${data.size} bytes.") | |
41 | 50 | if (!currentSummaryData.update(data)) |
42 | 51 | { |
43 | 52 | // parse failure... |
@@ -1,6 +1,5 @@ | ||
1 | 1 | package jp.osdn.gokigen.thetathoughtshutter.theta |
2 | 2 | |
3 | -import android.graphics.Color | |
4 | 3 | import android.util.Log |
5 | 4 | import jp.osdn.gokigen.thetathoughtshutter.theta.operation.IOperationCallback |
6 | 5 | import jp.osdn.gokigen.thetathoughtshutter.theta.operation.ThetaOptionGetControl |