import jp.osdn.gokigen.thetathoughtshutter.bluetooth.connection.IBluetoothScanResult
import jp.osdn.gokigen.thetathoughtshutter.bluetooth.connection.eeg.MindWaveConnection
import jp.osdn.gokigen.thetathoughtshutter.brainwave.BrainwaveDataHolder
+import jp.osdn.gokigen.thetathoughtshutter.brainwave.IDetectSensingReceiver
+import jp.osdn.gokigen.thetathoughtshutter.theta.ThetaCaptureControl
import jp.osdn.gokigen.thetathoughtshutter.theta.ThetaHardwareControl
import jp.osdn.gokigen.thetathoughtshutter.theta.ThetaSetupBluetoothSPP
import jp.osdn.gokigen.thetathoughtshutter.theta.operation.IOperationCallback
import java.lang.Exception
-class MainActivity : PluginActivity(), IBluetoothScanResult
+class MainActivity : PluginActivity(), IBluetoothScanResult, IDetectSensingReceiver
{
private val thetaHardwareControl = ThetaHardwareControl(this)
+ private val thetaCaptureControl = ThetaCaptureControl("http://localhost:8080")
private val applicationStatus : MyApplicationStatus = MyApplicationStatus()
- private val bluetoothConnection = MindWaveConnection(this, BrainwaveDataHolder(), this)
+ private val bluetoothConnection = MindWaveConnection(this, BrainwaveDataHolder(this), this)
companion object
{
override fun onKeyUp(keyCode: Int, event: KeyEvent?)
{
- if (keyCode == KeyReceiver.KEYCODE_CAMERA) // Shutterボタン
- {
- when (applicationStatus.status)
- {
- MyApplicationStatus.Status.Connected -> {
- // EEGからの情報を取得して撮影する
- applicationStatus.status = MyApplicationStatus.Status.Scanning
- }
- MyApplicationStatus.Status.Scanning -> {
- // スタンバイ状態に戻す
- applicationStatus.status = MyApplicationStatus.Status.Connected
- }
- else -> {
- // ダミー処理 (仮にEEG接続失敗のステータスにする)
- applicationStatus.status = MyApplicationStatus.Status.FailedInitialize
- }
- }
- }
if (keyCode == KeyReceiver.KEYCODE_WLAN_ON_OFF) // Wirelessボタン
{
if (applicationStatus.status == MyApplicationStatus.Status.Initialized)
connectToEEG()
}
}
+/*
if (keyCode == KeyReceiver.KEYCODE_MEDIA_RECORD) // Modeボタン
{
when (applicationStatus.status) {
}
}
}
-/*
if (keyCode == KeyReceiver.KEYCODE_FUNCTION) // Fnボタン (Z1のみ)
{
}
+ if (keyCode == KeyReceiver.KEYCODE_CAMERA) // Shutterボタン
+ {
+
+ }
*/
updateStatus(applicationStatus.status)
}
applicationStatus.status = MyApplicationStatus.Status.Initialized
}
-
private fun updateStatus(currentStatus : MyApplicationStatus.Status)
{
try
{
Log.v(TAG , " isApConnected : $isApConnected")
}
+ try
+ {
+ thetaCaptureControl.setupCaptureMode()
+ }
+ catch (e : Exception)
+ {
+ e.printStackTrace()
+ }
initializeBluetooth()
}
}
}
-
private fun initializeBluetooth()
{
try
e.printStackTrace()
}
}
+
+ override fun startSensing()
+ {
+ // データの検出を開始する
+ Log.v(TAG, " ===== START SENSING =====")
+ applicationStatus.status = MyApplicationStatus.Status.Scanning
+ updateStatus(applicationStatus.status)
+ }
+
+ override fun detectAttention()
+ {
+ Log.v(TAG, " ===== DETECT ATTENTION =====")
+ applicationStatus.status = MyApplicationStatus.Status.Syncing
+ updateStatus(applicationStatus.status)
+ }
+
+ override fun detectMediation()
+ {
+ //Log.v(TAG, " ===== DETECT MEDIATION =====")
+ }
+
+ override fun lostAttention()
+ {
+ Log.v(TAG, " ===== LOST ATTENTION =====")
+ applicationStatus.status = MyApplicationStatus.Status.Scanning
+ updateStatus(applicationStatus.status)
+ }
+
+ override fun lostMediation()
+ {
+ //Log.v(TAG, " ===== LOST MEDIATION =====")
+ }
+
+ override fun detectAttentionThreshold()
+ {
+ Log.v(TAG, " ===== DETECT ATTENTION THRESHOLD =====")
+ try
+ {
+ // 静止画の撮影!
+ thetaCaptureControl.doCapture()
+ }
+ catch (e : Exception)
+ {
+ e.printStackTrace()
+ }
+ }
+
+ override fun detectMediationThreshold()
+ {
+ Log.v(TAG, " ===== DETECT MEDIATION THRESHOLD =====")
+ }
+
}
//
package jp.osdn.gokigen.thetathoughtshutter.brainwave
import android.util.Log
-import jp.osdn.gokigen.thetathoughtshutter.bluetooth.connection.eeg.MindWaveConnection
import java.util.*
-class BrainwaveDataHolder(maxBufferSize: Int = 16000) : IBrainwaveDataReceiver
+class BrainwaveDataHolder(private val receiver: IDetectSensingReceiver? = null, maxBufferSize: Int = 16000) : IBrainwaveDataReceiver
{
companion object
{
private val TAG = BrainwaveDataHolder::class.java.simpleName
+ private const val THRESHOLD_ATTENTION = 80
+ private const val THRESHOLD_MEDIATION = 90
+ private const val COUNT_CONTINUOUS_ATTENTION = 5
+ private const val COUNT_CONTINUOUS_MEDIATION = 5
}
private var valueBuffer: IntArray
private var maxBufferSize = 0
private var currentPosition = 0
private var bufferIsFull = false
+ private var attentionCount = 0
+ private var mediationCount = 0
+ private var dataReceived = false
init
{
val attention = currentSummaryData.getAttention()
val mediation = currentSummaryData.getMediation()
Log.v(TAG, " ATTENTION : $attention MEDIATION : $mediation")
+ if ((!dataReceived)&&(attention > 0)&&(mediation > 0))
+ {
+ // データの受信を開始した
+ dataReceived = true
+ receiver?.startSensing()
+ }
+
+ if (attention > THRESHOLD_ATTENTION)
+ {
+ if (attentionCount == 0)
+ {
+ receiver?.detectAttention()
+ }
+ attentionCount++
+ if (attentionCount == COUNT_CONTINUOUS_ATTENTION)
+ {
+ // 検出を通知する
+ receiver?.detectAttentionThreshold()
+ }
+ }
+ else
+ {
+ // リミッターを下回ったので連続カウンタをクリアする
+ if( attentionCount > 0)
+ {
+ receiver?.lostAttention()
+ }
+ attentionCount = 0
+ }
+
+ if (mediation > THRESHOLD_MEDIATION)
+ {
+ if (mediationCount == 0)
+ {
+ receiver?.detectMediation()
+ }
+ mediationCount++
+ if (mediationCount == COUNT_CONTINUOUS_MEDIATION)
+ {
+ // 検出を通知する
+ receiver?.detectMediationThreshold()
+ }
+ }
+ else
+ {
+ // リミッターを下回ったので連続カウンタをクリアする
+ if( mediationCount > 0)
+ {
+ receiver?.lostMediation()
+ }
+ mediationCount = 0
+ }
}
catch (e : Exception)
{
--- /dev/null
+package jp.osdn.gokigen.thetathoughtshutter.theta
+
+import android.util.Log
+import jp.osdn.gokigen.thetathoughtshutter.theta.operation.IOperationCallback
+import jp.osdn.gokigen.thetathoughtshutter.theta.operation.ThetaOptionSetControl
+import jp.osdn.gokigen.thetathoughtshutter.theta.operation.ThetaSingleShotControl
+import java.lang.Exception
+
+class ThetaCaptureControl(executeUrl : String = "http://192.168.1.1")
+{
+ private val setOption = ThetaOptionSetControl(executeUrl)
+ private val singleShot = ThetaSingleShotControl(executeUrl)
+ private var isCapturing = false
+
+ companion object
+ {
+ private val TAG = ThetaCaptureControl::class.java.simpleName
+ }
+
+ fun setupCaptureMode()
+ {
+ setOption.setOptions("\"captureMode\" : \"image\"", object : IOperationCallback {
+ override fun operationExecuted(result: Int, resultStr: String?)
+ {
+ if (resultStr != null)
+ {
+ Log.v(TAG, "set to Image : $resultStr ")
+ }
+ }
+ })
+ }
+
+ fun doCapture()
+ {
+ try
+ {
+ if (isCapturing)
+ {
+ Log.v(TAG, "ALREADY START CAPTURE SEQUENCE")
+ return
+ }
+ singleShot.singleShot() // まじか、応答しない...
+ }
+ catch (e : Exception)
+ {
+ e.printStackTrace()
+ }
+ }
+}
\ No newline at end of file