import com.theta360.pluginlibrary.values.LedTarget
import jp.osdn.gokigen.thetathoughtshutter.R.layout
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()
}
})
+
updateStatus(applicationStatus.status)
}
{
}
+ initializeBluetooth()
}
override fun onPause()
super.onPause()
}
+ private fun initializeBluetooth()
+ {
+ try
+ {
+ val thread = Thread {
+ try
+ {
+ val setupBluetooth = ThetaSetupBluetoothSPP("http://localhost:8080")
+ setupBluetooth.setupBluetoothSPP(object : IOperationCallback { override fun operationExecuted(result: Int, resultStr: String?)
+ {
+ Log.v(TAG, " optionSet.getOptions(Bluetooth) : $resultStr? ")
+
+
+ if (result == 0)
+ {
+ // Bluetoothの初期化終了
+ applicationStatus.status = MyApplicationStatus.Status.Initialized
+ updateStatus(applicationStatus.status)
+ }
+ }})
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+ }
+ thread.start()
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+ }
}
//
package jp.osdn.gokigen.thetathoughtshutter.theta
+import android.graphics.Color
import android.util.Log
import jp.osdn.gokigen.thetathoughtshutter.theta.operation.IOperationCallback
import jp.osdn.gokigen.thetathoughtshutter.theta.operation.ThetaOptionGetControl
import jp.osdn.gokigen.thetathoughtshutter.theta.operation.ThetaOptionSetControl
+import org.json.JSONObject
class ThetaSetupBluetoothSPP(executeUrl : String = "http://192.168.1.1")
{
private val getOption = ThetaOptionGetControl(executeUrl)
private val setOption = ThetaOptionSetControl(executeUrl)
- fun setupBluetoothSPP()
+ fun setupBluetoothSPP(callback : IOperationCallback?)
{
getOption.getOptions("[ \"_bluetoothRole\", \"_bluetoothPower\", \"_bluetoothClassicEnable\" ]", object : IOperationCallback { override fun operationExecuted(result: Int, resultStr: String?)
{
Log.v(TAG, " optionSet.getOptions(Bluetooth) : $resultStr? ")
+ if (resultStr == null)
+ {
+ callback?.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")
+
+ if (bluetoothRole.contains("Central"))
+ {
+ // Central: ON ⇒ OFF にする
+ //setOption.setOptions("")
+ Log.v(TAG, " --- CHANGE TO 'Peripheral' ---")
+ }
+ Log.v(TAG, " BLUETOOTH CLASSIC : $bluetoothClassicEnable POWER: $bluetoothPower ROLE: $bluetoothRole")
+
+
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+
+
+
+
+
+ callback?.operationExecuted(result, resultStr)
+ }
+ catch (e : Exception)
+ {
+ e.printStackTrace()
+ }
}})
}
companion object
try
{
val setOptionsUrl = "${executeUrl}/osc/commands/execute"
- val postData = "{\"name\":\"camera.getOptions\",\"parameters\":{\"timeout\":0, \"optionNames\": {$options}}}"
+ val postData = "{\"name\":\"camera.getOptions\",\"parameters\":{\"timeout\":0, \"optionNames\": $options}}"
val result: String? = httpClient.httpPostWithHeader(setOptionsUrl, postData, null, "application/json;charset=utf-8", timeoutMs)
if ((result != null) && (result.isNotEmpty()))
{