OSDN Git Service

ちょっと追加。
authorMRSa <mrsa@myad.jp>
Thu, 11 Feb 2021 14:05:03 +0000 (23:05 +0900)
committerMRSa <mrsa@myad.jp>
Thu, 11 Feb 2021 14:05:03 +0000 (23:05 +0900)
app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/MainActivity.kt
app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/MyApplicationStatus.kt [new file with mode: 0644]
app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/theta/ThetaSetupBluetoothSPP.kt [new file with mode: 0644]
app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/theta/operation/ThetaOptionGetControl.kt [new file with mode: 0644]

index f9a36f3..1f7321e 100644 (file)
@@ -13,6 +13,7 @@ import jp.osdn.gokigen.thetathoughtshutter.theta.ThetaHardwareControl
 class MainActivity : PluginActivity()
 {
     private val thetaHardwareControl = ThetaHardwareControl(this)
+    private var applicationStatus : MyApplicationStatus = MyApplicationStatus.Undefined
 
     override fun onCreate(savedInstanceState: Bundle?)
     {
diff --git a/app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/MyApplicationStatus.kt b/app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/MyApplicationStatus.kt
new file mode 100644 (file)
index 0000000..1bb26dc
--- /dev/null
@@ -0,0 +1,11 @@
+package jp.osdn.gokigen.thetathoughtshutter
+
+enum class MyApplicationStatus
+{
+    Undefined,
+    FailedInitialize,
+    Initialized,
+    Searching,
+    Connected,
+    Scanning,
+}
diff --git a/app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/theta/ThetaSetupBluetoothSPP.kt b/app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/theta/ThetaSetupBluetoothSPP.kt
new file mode 100644 (file)
index 0000000..03ac5f8
--- /dev/null
@@ -0,0 +1,24 @@
+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.ThetaOptionGetControl
+import jp.osdn.gokigen.thetathoughtshutter.theta.operation.ThetaOptionSetControl
+
+class ThetaSetupBluetoothSPP(executeUrl : String = "http://192.168.1.1")
+{
+    private val getOption = ThetaOptionGetControl(executeUrl)
+    private val setOption = ThetaOptionSetControl(executeUrl)
+
+    fun setupBluetoothSPP()
+    {
+        getOption.getOptions("[ \"_bluetoothRole\", \"_bluetoothPower\", \"_bluetoothClassicEnable\" ]", object : IOperationCallback { override fun operationExecuted(result: Int, resultStr: String?)
+        {
+            Log.v(TAG, " optionSet.getOptions(Bluetooth) : $resultStr? ")
+        }})
+    }
+    companion object
+    {
+        private val TAG = ThetaSetupBluetoothSPP::class.java.simpleName
+    }
+}
diff --git a/app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/theta/operation/ThetaOptionGetControl.kt b/app/src/main/java/jp/osdn/gokigen/thetathoughtshutter/theta/operation/ThetaOptionGetControl.kt
new file mode 100644 (file)
index 0000000..4554b44
--- /dev/null
@@ -0,0 +1,58 @@
+package jp.osdn.gokigen.thetathoughtshutter.theta.operation
+
+import android.util.Log
+import jp.osdn.gokigen.thetathoughtshutter.utils.SimpleHttpClient
+
+class ThetaOptionGetControl(private val executeUrl : String = "http://192.168.1.1")
+{
+    private val httpClient = SimpleHttpClient()
+
+    /**
+     *
+     *
+     */
+    fun getOptions(options: String, callBack: IOperationCallback? = null)
+    {
+        //Log.v(TAG, "getOptions()  MSG : $options")
+        try
+        {
+            val thread = Thread {
+                try
+                {
+                    val setOptionsUrl = "${executeUrl}/osc/commands/execute"
+                    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()))
+                    {
+                        Log.v(TAG, " getOptions() : $result (${setOptionsUrl})")
+                        callBack?.operationExecuted(0, result)
+                    }
+                    else
+                    {
+                        Log.v(TAG, "getOptions() reply is null or empty.  $postData (${setOptionsUrl})")
+                        callBack?.operationExecuted(-1, "")
+                    }
+                }
+                catch (e: Exception)
+                {
+                    Log.v(TAG, "getOptions() Exception : $options")
+                    e.printStackTrace()
+                    callBack?.operationExecuted(-1, e.localizedMessage)
+                }
+            }
+            thread.start()
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+            callBack?.operationExecuted(-1, e.localizedMessage)
+        }
+    }
+
+    companion object
+    {
+        private val TAG = ThetaOptionGetControl::class.java.simpleName
+        private const val timeoutMs = 1500
+    }
+
+}
\ No newline at end of file