package jp.osdn.gokigen.thetaview.scene
import android.bluetooth.BluetoothDevice
+import android.graphics.Color
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import jp.osdn.gokigen.thetaview.bluetooth.connection.IBluetoothConnection
class EEGShutter(activity : AppCompatActivity, private val bluetoothStatusNotify : IBluetoothStatusNotify, private val shutter: IThetaShutter) : IDetectSensingReceiver, IBluetoothScanResult
{
- private val bluetoothConnection = MindWaveConnection(activity, BrainwaveDataHolder(this), this)
+ private val bluetoothConnection = MindWaveConnection(activity, BrainwaveDataHolder(this), bluetoothStatusNotify, this)
+ private lateinit var indicator : IIndicator
companion object
{
private val TAG = EEGShutter::class.java.simpleName
}
+ fun setIndicator(indicator : IIndicator)
+ {
+ this.indicator = indicator
+ }
+
fun connectToEEG()
{
+ Log.v(TAG, " connectToEEG()")
try
{
- Log.v(TAG, " connectToEEG()")
+/*
+ val thread = Thread {
+ try
+ {
+ bluetoothConnection.connect("MindWave Mobile")
+ }
+ catch (e : Exception)
+ {
+ e.printStackTrace()
+
+ }
+ }
+ thread.start()
+*/
bluetoothConnection.connect("MindWave Mobile")
+
}
catch (e : Exception)
{
fun disconnectFromEEG()
{
- Log.v(TAG, " disconnectFromEEG()")
+ try
+ {
+ val thread = Thread {
+ try
+ {
+ Log.v(TAG, " disconnectFromEEG()")
+ }
+ catch (e : Exception)
+ {
+ e.printStackTrace()
+
+ }
+ }
+ thread.start()
+ }
+ catch (e : Exception)
+ {
+ e.printStackTrace()
+ }
}
override fun startSensing()
{
- TODO("Not yet implemented")
+ Log.v(TAG, " startSensing()")
}
override fun detectAttention()
{
- TODO("Not yet implemented")
+ Log.v(TAG, " detectAttention()")
}
override fun lostAttention()
{
- TODO("Not yet implemented")
+ Log.v(TAG, " lostAttention()")
}
override fun detectAttentionThreshold()
{
- TODO("Not yet implemented")
+ Log.v(TAG, " detectAttentionThreshold()")
}
override fun detectMediation()
{
- TODO("Not yet implemented")
+ Log.v(TAG, " detectMediation()")
}
override fun lostMediation()
{
- TODO("Not yet implemented")
+ Log.v(TAG, " lostMediation()")
}
override fun detectMediationThreshold()
{
- TODO("Not yet implemented")
+ Log.v(TAG, " detectMediationThreshold()")
}
override fun foundBluetoothDevice(device: BluetoothDevice)
{
- TODO("Not yet implemented")
+ Log.v(TAG, " foundBluetoothDevice() : ${device.name}")
}
override fun notFindBluetoothDevice()
{
bluetoothStatusNotify.updateBluetoothStatus(IBluetoothConnection.ConnectionStatus.Ready)
}
-}
\ No newline at end of file
+
+ override fun updateSummaryValue(attention: Int, mediation: Int)
+ {
+ Log.v(TAG, " ATTENTION : $attention MEDIATION : $mediation")
+ try
+ {
+ if (::indicator.isInitialized)
+ {
+ val colorAttention = when {
+ attention > 90 -> { Color.GREEN }
+ attention > 70 -> { Color.YELLOW }
+ attention > 50 -> { Color.WHITE }
+ attention > 30 -> { Color.LTGRAY }
+ else -> { Color.DKGRAY }
+ }
+ indicator.setMessage(IIndicator.Area.AREA_G, colorAttention, "ATTENTION : $attention")
+
+ val colorMediation = when {
+ mediation > 90 -> { Color.GREEN }
+ mediation > 70 -> { Color.YELLOW }
+ mediation > 50 -> { Color.WHITE }
+ mediation > 30 -> { Color.LTGRAY }
+ else -> { Color.DKGRAY }
+ }
+ indicator.setMessage(IIndicator.Area.AREA_G, colorMediation, "MEDIATION : $mediation")
+ indicator.invalidate()
+ }
+ }
+ catch (e : Exception)
+ {
+ e.printStackTrace()
+ }
+ }
+}