• R/O
  • HTTP
  • SSH
  • HTTPS

ThetaThoughtShutter: Commit

Ricoh Theta x Nurosky Shutter


Commit MetaInfo

Révisionfdfef9efd73b0b8a34f65e1c0407a3dbb4a964c4 (tree)
l'heure2021-02-23 09:45:49
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
@@ -13,16 +13,19 @@ import jp.osdn.gokigen.thetathoughtshutter.R.layout
1313 import jp.osdn.gokigen.thetathoughtshutter.bluetooth.connection.IBluetoothScanResult
1414 import jp.osdn.gokigen.thetathoughtshutter.bluetooth.connection.eeg.MindWaveConnection
1515 import jp.osdn.gokigen.thetathoughtshutter.brainwave.BrainwaveDataHolder
16+import jp.osdn.gokigen.thetathoughtshutter.brainwave.IDetectSensingReceiver
17+import jp.osdn.gokigen.thetathoughtshutter.theta.ThetaCaptureControl
1618 import jp.osdn.gokigen.thetathoughtshutter.theta.ThetaHardwareControl
1719 import jp.osdn.gokigen.thetathoughtshutter.theta.ThetaSetupBluetoothSPP
1820 import jp.osdn.gokigen.thetathoughtshutter.theta.operation.IOperationCallback
1921 import java.lang.Exception
2022
21-class MainActivity : PluginActivity(), IBluetoothScanResult
23+class MainActivity : PluginActivity(), IBluetoothScanResult, IDetectSensingReceiver
2224 {
2325 private val thetaHardwareControl = ThetaHardwareControl(this)
26+ private val thetaCaptureControl = ThetaCaptureControl("http://localhost:8080")
2427 private val applicationStatus : MyApplicationStatus = MyApplicationStatus()
25- private val bluetoothConnection = MindWaveConnection(this, BrainwaveDataHolder(), this)
28+ private val bluetoothConnection = MindWaveConnection(this, BrainwaveDataHolder(this), this)
2629
2730 companion object
2831 {
@@ -44,24 +47,6 @@ class MainActivity : PluginActivity(), IBluetoothScanResult
4447
4548 override fun onKeyUp(keyCode: Int, event: KeyEvent?)
4649 {
47- if (keyCode == KeyReceiver.KEYCODE_CAMERA) // Shutterボタン
48- {
49- when (applicationStatus.status)
50- {
51- MyApplicationStatus.Status.Connected -> {
52- // EEGからの情報を取得して撮影する
53- applicationStatus.status = MyApplicationStatus.Status.Scanning
54- }
55- MyApplicationStatus.Status.Scanning -> {
56- // スタンバイ状態に戻す
57- applicationStatus.status = MyApplicationStatus.Status.Connected
58- }
59- else -> {
60- // ダミー処理 (仮にEEG接続失敗のステータスにする)
61- applicationStatus.status = MyApplicationStatus.Status.FailedInitialize
62- }
63- }
64- }
6550 if (keyCode == KeyReceiver.KEYCODE_WLAN_ON_OFF) // Wirelessボタン
6651 {
6752 if (applicationStatus.status == MyApplicationStatus.Status.Initialized)
@@ -70,6 +55,7 @@ class MainActivity : PluginActivity(), IBluetoothScanResult
7055 connectToEEG()
7156 }
7257 }
58+/*
7359 if (keyCode == KeyReceiver.KEYCODE_MEDIA_RECORD) // Modeボタン
7460 {
7561 when (applicationStatus.status) {
@@ -91,11 +77,14 @@ class MainActivity : PluginActivity(), IBluetoothScanResult
9177 }
9278 }
9379 }
94-/*
9580 if (keyCode == KeyReceiver.KEYCODE_FUNCTION) // Fnボタン (Z1のみ)
9681 {
9782
9883 }
84+ if (keyCode == KeyReceiver.KEYCODE_CAMERA) // Shutterボタン
85+ {
86+
87+ }
9988 */
10089 updateStatus(applicationStatus.status)
10190 }
@@ -155,7 +144,6 @@ class MainActivity : PluginActivity(), IBluetoothScanResult
155144 applicationStatus.status = MyApplicationStatus.Status.Initialized
156145 }
157146
158-
159147 private fun updateStatus(currentStatus : MyApplicationStatus.Status)
160148 {
161149 try
@@ -220,6 +208,14 @@ class MainActivity : PluginActivity(), IBluetoothScanResult
220208 {
221209 Log.v(TAG , " isApConnected : $isApConnected")
222210 }
211+ try
212+ {
213+ thetaCaptureControl.setupCaptureMode()
214+ }
215+ catch (e : Exception)
216+ {
217+ e.printStackTrace()
218+ }
223219 initializeBluetooth()
224220 }
225221
@@ -236,7 +232,6 @@ class MainActivity : PluginActivity(), IBluetoothScanResult
236232 }
237233 }
238234
239-
240235 private fun initializeBluetooth()
241236 {
242237 try
@@ -297,6 +292,58 @@ class MainActivity : PluginActivity(), IBluetoothScanResult
297292 e.printStackTrace()
298293 }
299294 }
295+
296+ override fun startSensing()
297+ {
298+ // データの検出を開始する
299+ Log.v(TAG, " ===== START SENSING =====")
300+ applicationStatus.status = MyApplicationStatus.Status.Scanning
301+ updateStatus(applicationStatus.status)
302+ }
303+
304+ override fun detectAttention()
305+ {
306+ Log.v(TAG, " ===== DETECT ATTENTION =====")
307+ applicationStatus.status = MyApplicationStatus.Status.Syncing
308+ updateStatus(applicationStatus.status)
309+ }
310+
311+ override fun detectMediation()
312+ {
313+ //Log.v(TAG, " ===== DETECT MEDIATION =====")
314+ }
315+
316+ override fun lostAttention()
317+ {
318+ Log.v(TAG, " ===== LOST ATTENTION =====")
319+ applicationStatus.status = MyApplicationStatus.Status.Scanning
320+ updateStatus(applicationStatus.status)
321+ }
322+
323+ override fun lostMediation()
324+ {
325+ //Log.v(TAG, " ===== LOST MEDIATION =====")
326+ }
327+
328+ override fun detectAttentionThreshold()
329+ {
330+ Log.v(TAG, " ===== DETECT ATTENTION THRESHOLD =====")
331+ try
332+ {
333+ // 静止画の撮影!
334+ thetaCaptureControl.doCapture()
335+ }
336+ catch (e : Exception)
337+ {
338+ e.printStackTrace()
339+ }
340+ }
341+
342+ override fun detectMediationThreshold()
343+ {
344+ Log.v(TAG, " ===== DETECT MEDIATION THRESHOLD =====")
345+ }
346+
300347 }
301348
302349 //
--- 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,14 +1,17 @@
11 package jp.osdn.gokigen.thetathoughtshutter.brainwave
22
33 import android.util.Log
4-import jp.osdn.gokigen.thetathoughtshutter.bluetooth.connection.eeg.MindWaveConnection
54 import java.util.*
65
7-class BrainwaveDataHolder(maxBufferSize: Int = 16000) : IBrainwaveDataReceiver
6+class BrainwaveDataHolder(private val receiver: IDetectSensingReceiver? = null, maxBufferSize: Int = 16000) : IBrainwaveDataReceiver
87 {
98 companion object
109 {
1110 private val TAG = BrainwaveDataHolder::class.java.simpleName
11+ private const val THRESHOLD_ATTENTION = 80
12+ private const val THRESHOLD_MEDIATION = 90
13+ private const val COUNT_CONTINUOUS_ATTENTION = 5
14+ private const val COUNT_CONTINUOUS_MEDIATION = 5
1215 }
1316
1417 private var valueBuffer: IntArray
@@ -16,6 +19,9 @@ class BrainwaveDataHolder(maxBufferSize: Int = 16000) : IBrainwaveDataReceiver
1619 private var maxBufferSize = 0
1720 private var currentPosition = 0
1821 private var bufferIsFull = false
22+ private var attentionCount = 0
23+ private var mediationCount = 0
24+ private var dataReceived = false
1925
2026 init
2127 {
@@ -58,6 +64,58 @@ class BrainwaveDataHolder(maxBufferSize: Int = 16000) : IBrainwaveDataReceiver
5864 val attention = currentSummaryData.getAttention()
5965 val mediation = currentSummaryData.getMediation()
6066 Log.v(TAG, " ATTENTION : $attention MEDIATION : $mediation")
67+ if ((!dataReceived)&&(attention > 0)&&(mediation > 0))
68+ {
69+ // データの受信を開始した
70+ dataReceived = true
71+ receiver?.startSensing()
72+ }
73+
74+ if (attention > THRESHOLD_ATTENTION)
75+ {
76+ if (attentionCount == 0)
77+ {
78+ receiver?.detectAttention()
79+ }
80+ attentionCount++
81+ if (attentionCount == COUNT_CONTINUOUS_ATTENTION)
82+ {
83+ // 検出を通知する
84+ receiver?.detectAttentionThreshold()
85+ }
86+ }
87+ else
88+ {
89+ // リミッターを下回ったので連続カウンタをクリアする
90+ if( attentionCount > 0)
91+ {
92+ receiver?.lostAttention()
93+ }
94+ attentionCount = 0
95+ }
96+
97+ if (mediation > THRESHOLD_MEDIATION)
98+ {
99+ if (mediationCount == 0)
100+ {
101+ receiver?.detectMediation()
102+ }
103+ mediationCount++
104+ if (mediationCount == COUNT_CONTINUOUS_MEDIATION)
105+ {
106+ // 検出を通知する
107+ receiver?.detectMediationThreshold()
108+ }
109+ }
110+ else
111+ {
112+ // リミッターを下回ったので連続カウンタをクリアする
113+ if( mediationCount > 0)
114+ {
115+ receiver?.lostMediation()
116+ }
117+ mediationCount = 0
118+ }
61119 }
62120 catch (e : Exception)
63121 {
--- /dev/null
+++ b/app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/brainwave/IDetectSensingReceiver.kt
@@ -0,0 +1,12 @@
1+package jp.osdn.gokigen.thetathoughtshutter.brainwave
2+
3+interface IDetectSensingReceiver
4+{
5+ fun startSensing()
6+ fun detectAttention()
7+ fun lostAttention()
8+ fun detectAttentionThreshold()
9+ fun detectMediation()
10+ fun lostMediation()
11+ fun detectMediationThreshold()
12+}
--- /dev/null
+++ b/app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/theta/ThetaCaptureControl.kt
@@ -0,0 +1,49 @@
1+package jp.osdn.gokigen.thetathoughtshutter.theta
2+
3+import android.util.Log
4+import jp.osdn.gokigen.thetathoughtshutter.theta.operation.IOperationCallback
5+import jp.osdn.gokigen.thetathoughtshutter.theta.operation.ThetaOptionSetControl
6+import jp.osdn.gokigen.thetathoughtshutter.theta.operation.ThetaSingleShotControl
7+import java.lang.Exception
8+
9+class ThetaCaptureControl(executeUrl : String = "http://192.168.1.1")
10+{
11+ private val setOption = ThetaOptionSetControl(executeUrl)
12+ private val singleShot = ThetaSingleShotControl(executeUrl)
13+ private var isCapturing = false
14+
15+ companion object
16+ {
17+ private val TAG = ThetaCaptureControl::class.java.simpleName
18+ }
19+
20+ fun setupCaptureMode()
21+ {
22+ setOption.setOptions("\"captureMode\" : \"image\"", object : IOperationCallback {
23+ override fun operationExecuted(result: Int, resultStr: String?)
24+ {
25+ if (resultStr != null)
26+ {
27+ Log.v(TAG, "set to Image : $resultStr ")
28+ }
29+ }
30+ })
31+ }
32+
33+ fun doCapture()
34+ {
35+ try
36+ {
37+ if (isCapturing)
38+ {
39+ Log.v(TAG, "ALREADY START CAPTURE SEQUENCE")
40+ return
41+ }
42+ singleShot.singleShot() // まじか、応答しない...
43+ }
44+ catch (e : Exception)
45+ {
46+ e.printStackTrace()
47+ }
48+ }
49+}
\ No newline at end of file
Afficher sur ancien navigateur de dépôt.