// ダミー処理 (EEG接続完了)
applicationStatus.status = MyApplicationStatus.Status.Connected
}
+ else if (applicationStatus.status == MyApplicationStatus.Status.Scanning)
+ {
+ // ダミー処理 (高まっている状態)
+ applicationStatus.status = MyApplicationStatus.Status.Syncing
+ }
+ else if (applicationStatus.status == MyApplicationStatus.Status.Syncing)
+ {
+ // ダミー処理 (高まるのを待っている状態)
+ applicationStatus.status = MyApplicationStatus.Status.Scanning
+ }
else
{
// ダミー処理 (初期化完了)
MyApplicationStatus.Status.Searching -> {
Log.v(TAG, " SEARCHING")
thetaHardwareControl.controlLED(LedTarget.LED3, 250, LedColor.GREEN) // WIFIランプ
+ thetaHardwareControl.controlLED(LedTarget.LED6, -1, LedColor.BLUE) // Liveランプ (OFF)
thetaHardwareControl.controlLED(LedTarget.LED7, -1, LedColor.RED) // 赤ランプ
}
MyApplicationStatus.Status.Connected -> {
Log.v(TAG, " CONNECTED")
- thetaHardwareControl.controlLED(LedTarget.LED3, 0, LedColor.GREEN) // WIFIランプ
- thetaHardwareControl.controlLED(LedTarget.LED7, -1, LedColor.RED) // 赤ランプ
+ thetaHardwareControl.controlLED(LedTarget.LED3, 0, LedColor.GREEN) // WIFIランプ
+ thetaHardwareControl.controlLED(LedTarget.LED6, -1, LedColor.BLUE) // Liveランプ (OFF)
+ thetaHardwareControl.controlLED(LedTarget.LED7, -1, LedColor.RED) // 赤ランプ
}
MyApplicationStatus.Status.Scanning -> {
Log.v(TAG, " SCANNING")
- thetaHardwareControl.controlLED(LedTarget.LED3, 0, LedColor.GREEN) // WIFIランプ
- thetaHardwareControl.controlLED(LedTarget.LED7, 0, LedColor.RED) // 赤ランプ
+ thetaHardwareControl.controlLED(LedTarget.LED3, 0, LedColor.GREEN) // WIFIランプ
+ thetaHardwareControl.controlLED(LedTarget.LED6, -1, LedColor.BLUE) // Liveランプ (OFF)
+ thetaHardwareControl.controlLED(LedTarget.LED7, 0, LedColor.RED) // 赤ランプ
+ }
+ MyApplicationStatus.Status.Syncing -> {
+ Log.v(TAG, " SYNCING")
+ thetaHardwareControl.controlLED(LedTarget.LED3, 0, LedColor.GREEN) // WIFIランプ
+ thetaHardwareControl.controlLED(LedTarget.LED6, 0, LedColor.BLUE) // Liveランプ (ON)
+ thetaHardwareControl.controlLED(LedTarget.LED7, 0, LedColor.RED) // 赤ランプ
}
MyApplicationStatus.Status.FailedInitialize -> {
Log.v(TAG, " FAILED INITIALIZE")
val setupBluetooth = ThetaSetupBluetoothSPP("http://localhost:8080")
setupBluetooth.setupBluetoothSPP(object : IOperationCallback { override fun operationExecuted(result: Int, resultStr: String?)
{
- Log.v(TAG, " optionSet.getOptions(Bluetooth) : $resultStr? ")
-
+ Log.v(TAG, " optionSet.getOptions(Bluetooth) : $resultStr ($result)")
if (result == 0)
{
import jp.osdn.gokigen.thetathoughtshutter.theta.operation.ThetaOptionSetControl
import org.json.JSONObject
-class ThetaSetupBluetoothSPP(executeUrl : String = "http://192.168.1.1")
+class ThetaSetupBluetoothSPP(executeUrl : String = "http://192.168.1.1") : IOperationCallback
{
private val getOption = ThetaOptionGetControl(executeUrl)
private val setOption = ThetaOptionSetControl(executeUrl)
+ private var readyCallback : IOperationCallback? = null
+
+ companion object
+ {
+ private val TAG = ThetaSetupBluetoothSPP::class.java.simpleName
+ }
fun setupBluetoothSPP(callback : IOperationCallback?)
{
- getOption.getOptions("[ \"_bluetoothRole\", \"_bluetoothPower\", \"_bluetoothClassicEnable\" ]", object : IOperationCallback { override fun operationExecuted(result: Int, resultStr: String?)
+ this.readyCallback = callback
+ getOption.getOptions("[ \"_bluetoothRole\", \"_bluetoothPower\", \"_bluetoothClassicEnable\" ]", this)
+ }
+
+ private fun setBluetoothPowerOn(bluetoothPower : String?)
+ {
+ if (bluetoothPower == null)
+ {
+ readyCallback?.operationExecuted(-1, "")
+ return
+ }
+ try
{
- Log.v(TAG, " optionSet.getOptions(Bluetooth) : $resultStr? ")
- if (resultStr == null)
+ if (!bluetoothPower.contains("ON"))
{
- callback?.operationExecuted(-1, resultStr)
- return
+ //
+ Log.v(TAG, " --- Bluetooth Power ON ---")
+ setOption.setOptions("\"_bluetoothPower\" : \"ON\"", object : IOperationCallback {
+ override fun operationExecuted(result: Int, resultStr: String?)
+ {
+ readyCallback?.operationExecuted(result, resultStr)
+ }
+ })
}
- try
- {
- val stateObject = JSONObject(resultStr).getJSONObject("results").getJSONObject("options")
- try
- {
- // Bluetoothの状態を確認
- val bluetoothClassicEnable = stateObject.getBoolean("_bluetoothClassicEnable")
- val bluetoothPower = stateObject.getString("_bluetoothPower")
- val bluetoothRole = stateObject.getString("_bluetoothRole")
+ readyCallback?.operationExecuted(0, "OK")
+ return
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+ readyCallback?.operationExecuted(-1, "")
+ }
- if (bluetoothRole.contains("Central"))
+ private fun setBluetoothClassicEnable(bluetoothClassicEnable: Boolean, bluetoothPower: String?)
+ {
+ try
+ {
+ if (!bluetoothClassicEnable)
+ {
+ //
+ Log.v(TAG, " --- Bluetooth Classic Enable ---")
+ setOption.setOptions("\"_bluetoothClassicEnable\" : \"true\"", object : IOperationCallback {
+ override fun operationExecuted(result: Int, resultStr: String?)
{
- // Central: ON ⇒ OFF にする
- //setOption.setOptions("")
- Log.v(TAG, " --- CHANGE TO 'Peripheral' ---")
+ if (resultStr != null)
+ {
+ Log.v(TAG, "_bluetoothClassicEnable : true $resultStr ")
+ setBluetoothPowerOn(bluetoothPower)
+ }
+ else
+ {
+ readyCallback?.operationExecuted(-1, resultStr)
+ }
}
- Log.v(TAG, " BLUETOOTH CLASSIC : $bluetoothClassicEnable POWER: $bluetoothPower ROLE: $bluetoothRole")
+ })
+ }
+ else
+ {
+ setBluetoothPowerOn(bluetoothPower)
+ }
+ return
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+ readyCallback?.operationExecuted(-1, "")
+ }
+ override fun operationExecuted(result: Int, resultStr: String?)
+ {
+ Log.v(TAG, " optionSet.getOptions(Bluetooth) : $resultStr? ")
+ if (resultStr == null)
+ {
+ readyCallback?.operationExecuted(-1, resultStr)
+ return
+ }
+ try
+ {
+ val stateObject = JSONObject(resultStr).getJSONObject("results").getJSONObject("options")
+ try
+ {
+ // Bluetoothの状態を確認
+ val bluetoothClassicEnable = stateObject.getBoolean("_bluetoothClassicEnable")
+ val bluetoothPower = stateObject.getString("_bluetoothPower")
+ val bluetoothRole = stateObject.getString("_bluetoothRole")
+
+ Log.v(TAG, " BLUETOOTH CLASSIC : $bluetoothClassicEnable POWER: $bluetoothPower ROLE: $bluetoothRole")
+ if (bluetoothRole.contains("Central"))
+ {
+ // Central: ON ⇒ OFF にする
+ Log.v(TAG, " --- CHANGE TO 'Peripheral' ---")
+ setOption.setOptions("\"_bluetoothRole\" : \"Peripheral\"", object : IOperationCallback {
+ override fun operationExecuted(result: Int, resultStr: String?)
+ {
+ if (resultStr != null)
+ {
+ Log.v(TAG, "_bluetoothRole : Peripheral $resultStr ")
+ setBluetoothClassicEnable(bluetoothClassicEnable, bluetoothPower)
+ }
+ else
+ {
+ readyCallback?.operationExecuted(-1, resultStr)
+ }
+ }
+ })
}
- catch (e: Exception)
+ else
{
- e.printStackTrace()
+ setBluetoothClassicEnable(bluetoothClassicEnable, bluetoothPower)
}
-
-
-
-
-
- callback?.operationExecuted(result, resultStr)
+ return
}
- catch (e : Exception)
+ catch (e: Exception)
{
e.printStackTrace()
}
- }})
- }
- companion object
- {
- private val TAG = ThetaSetupBluetoothSPP::class.java.simpleName
+ }
+ catch (e : Exception)
+ {
+ e.printStackTrace()
+ }
+ readyCallback?.operationExecuted(-1, resultStr)
}
}