• R/O
  • HTTP
  • SSH
  • HTTPS

ThetaThoughtShutter: Commit

Ricoh Theta x Nurosky Shutter


Commit MetaInfo

Révision74a755c52f4e1c46c866975a26d22fb2fd62237d (tree)
l'heure2021-02-22 23:32:08
AuteurMRSa <mrsa@myad...>
CommiterMRSa

Message de Log

データが報告されてくるようになった。

Change Summary

Modification

--- a/app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/MainActivity.kt
+++ b/app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/MainActivity.kt
@@ -10,7 +10,6 @@ import com.theta360.pluginlibrary.receiver.KeyReceiver
1010 import com.theta360.pluginlibrary.values.LedColor
1111 import com.theta360.pluginlibrary.values.LedTarget
1212 import jp.osdn.gokigen.thetathoughtshutter.R.layout
13-import jp.osdn.gokigen.thetathoughtshutter.bluetooth.connection.BluetoothDeviceFinder
1413 import jp.osdn.gokigen.thetathoughtshutter.bluetooth.connection.IBluetoothScanResult
1514 import jp.osdn.gokigen.thetathoughtshutter.bluetooth.connection.eeg.MindWaveConnection
1615 import jp.osdn.gokigen.thetathoughtshutter.brainwave.BrainwaveDataHolder
@@ -23,8 +22,7 @@ class MainActivity : PluginActivity(), IBluetoothScanResult
2322 {
2423 private val thetaHardwareControl = ThetaHardwareControl(this)
2524 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)
2826
2927 companion object
3028 {
@@ -74,25 +72,23 @@ class MainActivity : PluginActivity(), IBluetoothScanResult
7472 }
7573 if (keyCode == KeyReceiver.KEYCODE_MEDIA_RECORD) // Modeボタン
7674 {
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+ }
9692 }
9793 }
9894 /*
@@ -198,16 +194,11 @@ class MainActivity : PluginActivity(), IBluetoothScanResult
198194 super.onResume()
199195 if (isApConnected)
200196 {
201-
197+ Log.v(TAG , " isApConnected : $isApConnected")
202198 }
203199 initializeBluetooth()
204200 }
205201
206- override fun onPause()
207- {
208- super.onPause()
209- }
210-
211202 private fun initializeBluetooth()
212203 {
213204 try
--- a/app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/bluetooth/connection/eeg/MindWaveConnection.kt
+++ b/app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/bluetooth/connection/eeg/MindWaveConnection.kt
@@ -35,7 +35,7 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv
3535 {
3636 override fun onReceive(context: Context, intent: Intent)
3737 {
38- onReceiveBroadcastOfConnection(this, context, intent)
38+ onReceiveBroadcastOfConnection(this, intent)
3939 }
4040 }
4141
@@ -125,10 +125,10 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv
125125
126126 private fun serialCommunicationMain(btSocket: BluetoothSocket)
127127 {
128- Log.v(TAG, "serialCommunicationMain ")
129128 var inputStream: InputStream? = null
130129 try
131130 {
131+ Log.v(TAG, "serialCommunicationMain connect")
132132 btSocket.connect()
133133 inputStream = btSocket.inputStream
134134 }
@@ -138,6 +138,7 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv
138138 }
139139 if (inputStream == null)
140140 {
141+ Log.v(TAG, "serialCommunicationMain INPUT STREAM IS NULL...")
141142 return
142143 }
143144 if (loggingFlag)
@@ -152,6 +153,8 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv
152153 e.printStackTrace()
153154 }
154155 }
156+ Log.v(TAG, " serialCommunicationMain : SERIAL COMMUNICATION STARTED.")
157+
155158
156159 // シリアルデータの受信メイン部分
157160 var previousData = 0xff.toByte()
@@ -161,7 +164,7 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv
161164 try
162165 {
163166 val data: Int = inputStream.read()
164- Log.v(TAG, " RECEIVED ")
167+ //Log.v(TAG, " RECEIVED ")
165168 val byteData = (data and 0xff).toByte()
166169 if (previousData == byteData && byteData == 0xaa.toByte())
167170 {
@@ -192,7 +195,6 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv
192195 }
193196 }
194197
195-
196198 override fun foundBluetoothDevice(device: BluetoothDevice)
197199 {
198200 try
@@ -210,6 +212,16 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv
210212 connectBluetoothDevice(device)
211213 return
212214 }
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+ }
213225
214226 if ((!foundDevice)&&(!isPairing))
215227 {
@@ -225,78 +237,7 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv
225237 {
226238 e.printStackTrace()
227239 }
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- }
298240 }
299-*/
300241
301242 private fun connectBluetoothDevice(device : BluetoothDevice?)
302243 {
@@ -325,13 +266,15 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv
325266 }
326267 if (btSocket != null)
327268 {
269+ scanResult?.foundBluetoothDevice(device)
328270 thread.start()
271+ unregisterReceiver()
329272 }
330273 else
331274 {
332275 Log.v(TAG, " btSocket is NULL.")
333276 }
334- scanResult?.foundBluetoothDevice(device)
277+ //scanResult?.foundBluetoothDevice(device)
335278 }
336279 catch (e: Exception)
337280 {
@@ -350,7 +293,7 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv
350293 *
351294 *
352295 */
353- private fun onReceiveBroadcastOfConnection(receiver: BroadcastReceiver, context: Context, intent: Intent)
296+ private fun onReceiveBroadcastOfConnection(receiver: BroadcastReceiver, intent: Intent)
354297 {
355298 val action = intent.action
356299 if (action == null)
--- a/app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/brainwave/BrainwaveDataHolder.kt
+++ b/app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/brainwave/BrainwaveDataHolder.kt
@@ -1,11 +1,15 @@
11 package jp.osdn.gokigen.thetathoughtshutter.brainwave
22
33 import android.util.Log
4+import jp.osdn.gokigen.thetathoughtshutter.bluetooth.connection.eeg.MindWaveConnection
45 import java.util.*
56
67 class BrainwaveDataHolder(maxBufferSize: Int = 16000) : IBrainwaveDataReceiver
78 {
8- private val TAG = toString()
9+ companion object
10+ {
11+ private val TAG = BrainwaveDataHolder::class.java.simpleName
12+ }
913
1014 private var valueBuffer: IntArray
1115 private var currentSummaryData = BrainwaveSummaryData()
@@ -21,15 +25,19 @@ class BrainwaveDataHolder(maxBufferSize: Int = 16000) : IBrainwaveDataReceiver
2125
2226 override fun receivedRawData(value: Int)
2327 {
24- Log.v(TAG, " receivedRawData() : $value");
25- try {
28+ //Log.v(TAG, " receivedRawData() : $value");
29+ try
30+ {
2631 valueBuffer[currentPosition] = value
2732 currentPosition++
28- if (currentPosition == maxBufferSize) {
33+ if (currentPosition == maxBufferSize)
34+ {
2935 currentPosition = 0
3036 bufferIsFull = true
3137 }
32- } catch (e: Exception) {
38+ }
39+ catch (e: Exception)
40+ {
3341 e.printStackTrace()
3442 }
3543 }
@@ -38,6 +46,7 @@ class BrainwaveDataHolder(maxBufferSize: Int = 16000) : IBrainwaveDataReceiver
3846 {
3947 if (data != null)
4048 {
49+ Log.v(TAG, " receivedSummaryData() : ${data.size} bytes.")
4150 if (!currentSummaryData.update(data))
4251 {
4352 // parse failure...
--- a/app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/theta/ThetaSetupBluetoothSPP.kt
+++ b/app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/theta/ThetaSetupBluetoothSPP.kt
@@ -1,6 +1,5 @@
11 package jp.osdn.gokigen.thetathoughtshutter.theta
22
3-import android.graphics.Color
43 import android.util.Log
54 import jp.osdn.gokigen.thetathoughtshutter.theta.operation.IOperationCallback
65 import jp.osdn.gokigen.thetathoughtshutter.theta.operation.ThetaOptionGetControl
Afficher sur ancien navigateur de dépôt.