OSDN Git Service

PIXPROで、WBとフラッシュの設定をできるようにした。
authorMRSa <mrsa@myad.jp>
Sun, 29 Aug 2021 14:52:38 +0000 (23:52 +0900)
committerMRSa <mrsa@myad.jp>
Sun, 29 Aug 2021 14:52:38 +0000 (23:52 +0900)
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/pixpro/PixproCameraControl.kt
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/pixpro/wrapper/command/PixproCommandCommunicator.kt
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/pixpro/wrapper/command/messages/base/IPixproMessages.kt
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/pixpro/wrapper/command/messages/base/PixproCommandOnlyCallback.kt
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/pixpro/wrapper/command/messages/specific/PixproWhiteBalance.kt [new file with mode: 0644]
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/pixpro/wrapper/status/PixproStatusChecker.kt
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/pixpro/wrapper/status/PixproStatusConvert.kt [new file with mode: 0644]
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/pixpro/wrapper/status/PixproStatusHolder.kt
build.gradle

index de62e4a..06f56e0 100644 (file)
@@ -37,7 +37,7 @@ class PixproCameraControl(private val context: AppCompatActivity, private val vi
     private val liveViewListener = CameraLiveViewListenerImpl(context, informationNotify)
     private val cameraConnection = PixproCameraConnection(context, provider, this, statusChecker)
     private val pixproCameraParameter = PixproCamera()
-    private val commandCommunicator = PixproCommandCommunicator(pixproCameraParameter, this)
+    private val commandCommunicator = PixproCommandCommunicator(pixproCameraParameter, this, statusChecker)
     private val storeImage = StoreImage(context, liveViewListener)
 
     private lateinit var liveViewControl : PixproLiveViewControl
@@ -60,6 +60,7 @@ class PixproCameraControl(private val context: AppCompatActivity, private val vi
     override fun initialize()
     {
         Log.v(TAG, " --- initialize() : SEQ : ${preference.getConnectionSequence()}")
+        statusChecker.setCommandPublisher(commandCommunicator)
     }
 
     override fun connectToCamera()
@@ -212,6 +213,7 @@ class PixproCameraControl(private val context: AppCompatActivity, private val vi
                 liveViewControl = PixproLiveViewControl(liveViewListener, pixproCameraParameter)
             }
             liveViewControl.startLiveView()
+            statusChecker.startStatusWatch(null, null)
         }
         catch (e: Exception)
         {
index f23099a..f79120c 100644 (file)
@@ -17,7 +17,7 @@ import java.net.Socket
 import java.net.SocketException
 import java.util.*
 
-class PixproCommandCommunicator(private val pixproCamera: IPixproCamera, private val notifier: IPixproCommunicationNotify) : IPixproCommandPublisher, IPixproCommunication
+class PixproCommandCommunicator(private val pixproCamera: IPixproCamera, private val notifier: IPixproCommunicationNotify, private val statusChecker: IPixproCommandCallback) : IPixproCommandPublisher, IPixproCommunication
 {
     private var isStart = false
     private var isConnected = false
@@ -37,9 +37,9 @@ class PixproCommandCommunicator(private val pixproCamera: IPixproCamera, private
     {
         private val TAG = PixproCommandCommunicator::class.java.simpleName
         private const val BUFFER_SIZE = 1024 * 1024 + 16 // 受信バッファは 1MB
-        private const val COMMAND_SEND_RECEIVE_DURATION_MS = 5
+        private const val COMMAND_SEND_RECEIVE_DURATION_MS = 30
         private const val COMMAND_SEND_RECEIVE_DURATION_MAX = 3000
-        private const val COMMAND_POLL_QUEUE_MS = 5
+        private const val COMMAND_POLL_QUEUE_MS = 15
     }
 
     override fun connect(): Boolean
@@ -51,9 +51,13 @@ class PixproCommandCommunicator(private val pixproCamera: IPixproCamera, private
         }
         try
         {
-            Log.v(TAG, " connect()")
+            val tcpNoDelay = pixproCamera.getTcpNoDelay()
+            Log.v(TAG, " connect() $tcpNoDelay")
             socket = Socket()
-            if (pixproCamera.getTcpNoDelay())
+            socket?.reuseAddress = true
+            socket?.keepAlive = true
+            socket?.tcpNoDelay = tcpNoDelay
+            if (tcpNoDelay)
             {
                 socket?.keepAlive = false
                 socket?.setPerformancePreferences(0, 2, 0)
@@ -61,7 +65,6 @@ class PixproCommandCommunicator(private val pixproCamera: IPixproCamera, private
                 socket?.reuseAddress = false
                 socket?.trafficClass = 0x80
             }
-            socket?.tcpNoDelay = pixproCamera.getTcpNoDelay()
             socket?.connect(InetSocketAddress(pixproCamera.getIpAddress(), pixproCamera.getPortNumber()), 0)
             isConnected = true
             return (true)
@@ -154,11 +157,16 @@ class PixproCommandCommunicator(private val pixproCamera: IPixproCamera, private
                         if (command != null)
                         {
                             issueCommand(command)
+
+                            Thread.sleep(COMMAND_POLL_QUEUE_MS.toLong())
+                            Log.v(TAG, " --- RECEIVE FOR REPLY --- ")
+                            receiveFromCamera(command)
                         }
                         Thread.sleep(COMMAND_POLL_QUEUE_MS.toLong())
+
                         if (inputStream != null && inputStream.available() > 0)
                         {
-                            Log.v(TAG, " --- RECEIVE MSG --- ")
+                            Log.v(TAG, " --- RECEIVE FOR (PRIMARY) MSG --- ")
                             receiveFromCamera(PixproCommandReceiveOnly(SEQ_RECEIVE_ONLY, PixproCommandOnlyCallback()))
                         }
                     }
@@ -174,9 +182,12 @@ class PixproCommandCommunicator(private val pixproCamera: IPixproCamera, private
                 e.printStackTrace()
             }
         }
-        try {
+        try
+        {
             thread.start()
-        } catch (e: Exception) {
+        }
+        catch (e: Exception)
+        {
             e.printStackTrace()
         }
     }
@@ -210,9 +221,11 @@ class PixproCommandCommunicator(private val pixproCamera: IPixproCamera, private
     {
         try
         {
+/*
             var retryOver = true
             while (retryOver)
             {
+*/
                 //Log.v(TAG, "issueCommand : " + command.getId());
                 val commandBody: ByteArray = command.commandBody()
                 // コマンドボディが入っていた場合には、コマンド送信(入っていない場合は受信待ち)
@@ -224,12 +237,14 @@ class PixproCommandCommunicator(private val pixproCamera: IPixproCamera, private
                     // コマンドボディの2つめが入っていた場合には、コマンドを連続送信する
                     sendToCamera(command.dumpLog(), commandBody2)
                 }
+/*
                 retryOver = receiveFromCamera(command)
                 if (retryOver)
                 {
                     retryOver = command.sendRetry()
                 }
             }
+*/
         }
         catch (e: Exception)
         {
@@ -388,7 +403,7 @@ class PixproCommandCommunicator(private val pixproCamera: IPixproCamera, private
         try
         {
             var messageToSend: ByteArray? = null
-            if (received_body[8] == 0xd2.toByte() && received_body[9] == 0xd7.toByte())
+            if (received_body[8] == 0xd2.toByte() && received_body[9] == 0x07.toByte())
             {
                 messageToSend = byteArrayOf(
                     0x2e.toByte(),
@@ -461,6 +476,79 @@ class PixproCommandCommunicator(private val pixproCamera: IPixproCamera, private
                     0xff.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte()
                 )
             }
+            if (received_body[8] == 0xd2.toByte() && received_body[9] == 0xd7.toByte())
+            {
+                messageToSend = byteArrayOf(
+                    0x2e.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0xd2.toByte(),
+                    0xd7.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x01.toByte(),
+                    0x10.toByte(),
+                    0x00.toByte(),
+                    0x80.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x01.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0x00.toByte(),
+                    0xff.toByte(),
+                    0xff.toByte(),
+                    0xff.toByte(),
+                    0xff.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte()
+                )
+            }
             if (received_body[8] == 0xb9.toByte() && received_body[9] == 0x0b.toByte()) {
                 messageToSend = byteArrayOf(
                     0x2e.toByte(),
@@ -710,13 +798,15 @@ class PixproCommandCommunicator(private val pixproCamera: IPixproCamera, private
                 return false
             }
             if (receive_body[8] == 0xd2.toByte() && receive_body[9] == 0x07.toByte() ||
+                receive_body[8] == 0xd2.toByte() && receive_body[9] == 0xd7.toByte() ||
                 receive_body[8] == 0xb9.toByte() && receive_body[9] == 0x0b.toByte() ||
                 receive_body[8] == 0xba.toByte() && receive_body[9] == 0x0b.toByte() ||
                 receive_body[8] == 0xbb.toByte() && receive_body[9] == 0x0b.toByte()
             )
             {
                 isReceivedStatusMessage = true
-                Log.v(TAG, "  >>> RECEIVED HOST PRIMARY MESSAGE. <<<")
+                Log.v(TAG, "  >>> RECEIVED HOST PRIMARY MESSAGE. (${receive_body.size} bytes.)<<<")
+                statusChecker.receivedMessage(0, receive_body)
             }
         }
         catch (e: Exception)
index ed04e4f..876a29b 100644 (file)
@@ -15,6 +15,8 @@ interface IPixproMessages
         const val  SEQ_FLASH_ON = 21
         const val  SEQ_FLASH_AUTO = 22
 
+        const val  SEQ_WHITE_BALANCE = 30
+
         const val  SEQ_CONNECT_01 = 101
         const val  SEQ_CONNECT_02 = 102
         const val  SEQ_CONNECT_03 = 103
index ccdc984..c3313e6 100644 (file)
@@ -1,6 +1,7 @@
 package jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.base
 
 import android.util.Log
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.PixproCommandCommunicator
 import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.IPixproCommandCallback
 import jp.osdn.gokigen.gokigenassets.utils.communication.SimpleLogDumper
 
@@ -10,13 +11,24 @@ class PixproCommandOnlyCallback(private val isDumpReceiveMessage: Boolean = fals
     {
         private val TAG = PixproCommandOnlyCallback::class.java.simpleName
     }
+
     override fun receivedMessage(id: Int, rx_body: ByteArray?)
     {
         Log.v(TAG, " RECEIVED MESSAGE : $id (${rx_body?.size} bytes.)")
-        if ((isDumpReceiveMessage)&&(rx_body != null))
+        try
+        {
+            if (rx_body != null)
+            {
+                if (isDumpReceiveMessage)
+                {
+                    // 受信データをログに出力する
+                    SimpleLogDumper.dumpBytes("[${rx_body.size}]", rx_body)
+                }
+            }
+        }
+        catch (e: Exception)
         {
-            // 受信データをログに出力する
-            SimpleLogDumper.dumpBytes("[${rx_body.size}]", rx_body)
+            e.printStackTrace()
         }
     }
 }
diff --git a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/pixpro/wrapper/command/messages/specific/PixproWhiteBalance.kt b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/pixpro/wrapper/command/messages/specific/PixproWhiteBalance.kt
new file mode 100644 (file)
index 0000000..2f265c9
--- /dev/null
@@ -0,0 +1,178 @@
+package jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.specific
+
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.IPixproCommandCallback
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.base.IPixproMessages
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.base.PixproCommandBase
+
+class PixproWhiteBalance(private val callback: IPixproCommandCallback, whiteBalance: Int) : PixproCommandBase()
+{
+    private val data0: Byte = whiteBalance.toByte()
+
+    override fun getId() : Int
+    {
+        return (IPixproMessages.SEQ_WHITE_BALANCE)
+    }
+
+    override fun commandBody(): ByteArray
+    {
+        return byteArrayOf(
+            0x2e.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x20.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0xed.toByte(),
+            0x03.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x01.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x80.toByte(),
+
+            0x08.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x01.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x01.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x20.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x08.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0xb7.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0xb7.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            data0,
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+            0x00.toByte(),
+
+            0xff.toByte(), 0xff.toByte(), 0xff.toByte(), 0xff.toByte(),
+            0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte()
+        )
+    }
+
+    override fun responseCallback(): IPixproCommandCallback
+    {
+        return callback
+    }
+}
index 785fd77..98e3cf0 100644 (file)
@@ -5,6 +5,7 @@ import android.util.Log
 import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatusUpdateNotify
 import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus
 import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatusWatcher
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.IPixproCommandPublisher
 import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.IPixproCommandCallback
 import jp.osdn.gokigen.gokigenassets.liveview.message.IMessageDrawer
 import java.lang.Exception
@@ -14,10 +15,18 @@ class PixproStatusChecker : IPixproCommandCallback, ICameraStatusWatcher, ICamer
     private val statusHolder = PixproStatusHolder()
     private var whileFetching = false
     private var notifier: ICameraStatusUpdateNotify? = null
+    private lateinit var commandPublisher : IPixproCommandPublisher
 
     companion object
     {
         private val TAG = PixproStatusChecker::class.java.simpleName
+        private const val EVENT_POLL_QUEUE_MS = 1000
+    }
+
+    fun setCommandPublisher(commandPublisher : IPixproCommandPublisher)
+    {
+        this.commandPublisher = commandPublisher
+        statusHolder.setCommandPublisher(commandPublisher)
     }
 
     override fun getStatusList(key: String): List<String?>
@@ -30,7 +39,7 @@ class PixproStatusChecker : IPixproCommandCallback, ICameraStatusWatcher, ICamer
         {
             e.printStackTrace()
         }
-        return ArrayList()
+        return (ArrayList())
     }
 
     override fun getStatus(key: String): String
@@ -62,12 +71,17 @@ class PixproStatusChecker : IPixproCommandCallback, ICameraStatusWatcher, ICamer
     override fun setStatus(key: String, value: String)
     {
         Log.v(TAG, "setStatus($key, $value)")
+        try
+        {
+            return (statusHolder.setItemStatus(key, value))
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
     }
 
-    override fun startStatusWatch(
-        indicator: IMessageDrawer?,
-        notifier: ICameraStatusUpdateNotify?
-    )
+    override fun startStatusWatch(indicator: IMessageDrawer?, notifier: ICameraStatusUpdateNotify?)
     {
         if (whileFetching)
         {
@@ -78,6 +92,30 @@ class PixproStatusChecker : IPixproCommandCallback, ICameraStatusWatcher, ICamer
         {
             this.notifier = notifier
             whileFetching = true
+
+            val thread = Thread {
+                while (whileFetching)
+                {
+                    try
+                    {
+                        Thread.sleep(EVENT_POLL_QUEUE_MS.toLong())
+
+                        Log.v(TAG, "  ----- POLL EVENT -----  ")
+                    }
+                    catch (e: Exception)
+                    {
+                        e.printStackTrace()
+                    }
+                }
+            }
+            try
+            {
+                thread.start()
+            }
+            catch (e: Exception)
+            {
+                e.printStackTrace()
+            }
         }
         catch (e: Exception)
         {
diff --git a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/pixpro/wrapper/status/PixproStatusConvert.kt b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/pixpro/wrapper/status/PixproStatusConvert.kt
new file mode 100644 (file)
index 0000000..3b6747d
--- /dev/null
@@ -0,0 +1,69 @@
+package jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.status
+
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.IPixproCommandPublisher
+
+class PixproStatusConvert(private val statusHolder: PixproStatusHolder)
+{
+
+    companion object
+    {
+        private val TAG = PixproStatusConvert::class.java.simpleName
+    }
+    private lateinit var commandPublisher : IPixproCommandPublisher
+
+    fun setCommandPublisher(commandPublisher : IPixproCommandPublisher)
+    {
+        this.commandPublisher = commandPublisher
+    }
+
+    fun getAvailableTakeMode(): List<String?>
+    {
+        return (ArrayList())
+    }
+
+    fun getAvailableShutterSpeed(): List<String?>
+    {
+        return (ArrayList())
+    }
+
+    fun getAvailableAperture(): List<String?>
+    {
+        return (ArrayList())
+    }
+
+    fun getAvailableExpRev(): List<String?>
+    {
+        return (ArrayList())
+    }
+
+    fun getAvailableCaptureMode(): List<String?>
+    {
+        return (ArrayList())
+    }
+
+    fun getAvailableIsoSensitivity(): List<String?>
+    {
+        return (ArrayList())
+    }
+
+    fun getAvailableWhiteBalance(): List<String?>
+    {
+        return (listOf("AUTO", "Daylight", "Cloudy", "Fluorescent", "Fluorescent CWF", "Incandescent", "Underwater", "Other"))
+    }
+
+    fun getAvailableMeteringMode(): List<String?>
+    {
+        return (ArrayList())
+    }
+
+    fun getAvailablePictureEffect(): List<String?>
+    {
+        return (ArrayList())
+    }
+
+    fun getAvailableTorchMode(): List<String?>
+    {
+        return (listOf("OFF", "ON", "AUTO"))
+    }
+
+}
index ef54a30..f9cc170 100644 (file)
@@ -6,14 +6,18 @@ import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatusUpdateNotify
 import androidx.collection.SparseArrayCompat
 
 import android.util.SparseIntArray
+import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.IPixproCommandPublisher
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.base.PixproCommandOnlyCallback
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.specific.PixproFlashAuto
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.specific.PixproFlashOff
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.specific.PixproFlashOn
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.specific.PixproWhiteBalance
 import java.lang.Exception
 import java.util.*
-import kotlin.collections.ArrayList
-
 
 class PixproStatusHolder
 {
-
     companion object
     {
         private val TAG = PixproStatusHolder::class.java.simpleName
@@ -21,39 +25,12 @@ class PixproStatusHolder
 
     private val statusHolder: SparseIntArray = SparseIntArray()
     private val statusNameArray: SparseArrayCompat<String>  = SparseArrayCompat()
-    private fun prepareStatusNameArray() {
-/*
-        statusNameArray.clear();
-        statusNameArray.append(BATTERY_LEVEL, BATTERY_LEVEL_STR);
-        statusNameArray.append(WHITE_BALANCE, WHITE_BALANCE_STR);
-        statusNameArray.append(APERTURE, APERTURE_STR);
-        statusNameArray.append(FOCUS_MODE, FOCUS_MODE_STR);
-        statusNameArray.append(SHOOTING_MODE, SHOOTING_MODE_STR);
-        statusNameArray.append(FLASH, FLASH_STR);
-        statusNameArray.append(EXPOSURE_COMPENSATION, EXPOSURE_COMPENSATION_STR);
-        statusNameArray.append(SELF_TIMER, SELF_TIMER_STR);
-        statusNameArray.append(FILM_SIMULATION, FILM_SIMULATION_STR);
-        statusNameArray.append(IMAGE_FORMAT, IMAGE_FORMAT_STR);
-        statusNameArray.append(RECMODE_ENABLE, RECMODE_ENABLE_STR);
-        statusNameArray.append(F_SS_CONTROL, F_SS_CONTROL_STR);
-        statusNameArray.append(ISO, ISO_STR);
-        statusNameArray.append(MOVIE_ISO, MOVIE_ISO_STR);
-        statusNameArray.append(FOCUS_POINT, FOCUS_POINT_STR);
-        statusNameArray.append(DEVICE_ERROR, DEVICE_ERROR_STR);
-        statusNameArray.append(IMAGE_FILE_COUNT, IMAGE_FILE_COUNT_STR);
-        statusNameArray.append(SDCARD_REMAIN_SIZE, SDCARD_REMAIN_SIZE_STR);
-        statusNameArray.append(FOCUS_LOCK, FOCUS_LOCK_STR);
-        statusNameArray.append(MOVIE_REMAINING_TIME, MOVIE_REMAINING_TIME_STR);
-        statusNameArray.append(SHUTTER_SPEED, SHUTTER_SPEED_STR);
-        statusNameArray.append(IMAGE_ASPECT,IMAGE_ASPECT_STR);
-        statusNameArray.append(BATTERY_LEVEL_2, BATTERY_LEVEL_2_STR);
-
-        statusNameArray.append(UNKNOWN_DF00, UNKNOWN_DF00_STR);
-        statusNameArray.append(PICTURE_JPEG_COUNT, PICTURE_JPEG_COUNT_STR);
-        statusNameArray.append(UNKNOWN_D400, UNKNOWN_D400_STR);
-        statusNameArray.append(UNKNOWN_D401, UNKNOWN_D401_STR);
-        statusNameArray.append(UNKNOWN_D52F, UNKNOWN_D52F_STR);
-*/
+    private var statusConvert = PixproStatusConvert(this)
+    private lateinit var commandPublisher : IPixproCommandPublisher
+
+    fun setCommandPublisher(commandPublisher : IPixproCommandPublisher)
+    {
+        this.commandPublisher = commandPublisher
     }
 
     fun updateValue(
@@ -121,86 +98,299 @@ class PixproStatusHolder
         }
     }
 
-    /**
-     * 認識したカメラのステータス名称のリストを応答する
-     *
-     */
-    private val availableStatusNameList: List<String?>
-        private get() {
-            val selection: ArrayList<String?> = ArrayList()
-            try {
-                for (index in 0 until statusHolder.size()) {
-                    val key = statusHolder.keyAt(index)
-                    selection.add(
-                        statusNameArray[key, java.lang.String.format(
-                            Locale.US,
-                            "0x%04x",
-                            key
-                        )]
-                    )
-                }
-            } catch (e: Exception) {
-                e.printStackTrace()
-            }
-            return selection
+    fun getAvailableItemList(key: String?): List<String?>
+    {
+        try
+        {
+            return (when (key) {
+                ICameraStatus.TAKE_MODE -> statusConvert.getAvailableTakeMode()
+                ICameraStatus.SHUTTER_SPEED -> statusConvert.getAvailableShutterSpeed()
+                ICameraStatus.APERTURE -> statusConvert.getAvailableAperture()
+                ICameraStatus.EXPREV -> statusConvert.getAvailableExpRev()
+                ICameraStatus.CAPTURE_MODE -> statusConvert.getAvailableCaptureMode()
+                ICameraStatus.ISO_SENSITIVITY -> statusConvert.getAvailableIsoSensitivity()
+                ICameraStatus.WHITE_BALANCE -> statusConvert.getAvailableWhiteBalance()
+                ICameraStatus.AE -> statusConvert.getAvailableMeteringMode()
+                ICameraStatus.EFFECT -> statusConvert.getAvailablePictureEffect()
+                ICameraStatus.TORCH_MODE -> statusConvert.getAvailableTorchMode()
+                //ICameraStatus.BATTERY -> statusConvert.getAvailableRemainBattery()
+                //ICameraStatus.FOCUS_STATUS -> statusConvert.getAvailableFocusStatus()
+                else -> ArrayList()
+            })
+            //Log.v(TAG, " ----- getAvailableItemList($key) ")
+            //sendCamGetSettingCmd("colormode")
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
         }
+        return (ArrayList())
+    }
+
+    fun getItemStatusColor(key: String): Int
+    {
+        return (when (key) {
+            ICameraStatus.BATTERY -> getRemainBatteryColor()
+            else -> Color.WHITE
+        })
+    }
+
+    fun getItemStatus(orgKey: String): String
+    {
+        return (when (orgKey) {
+            ICameraStatus.TAKE_MODE -> getTakeMode()
+            ICameraStatus.SHUTTER_SPEED -> getShutterSpeed()
+            //ICameraStatus.APERTURE -> getAperture()
+            ICameraStatus.EXPREV -> getExpRev()
+            //ICameraStatus.CAPTURE_MODE -> getCaptureMode()
+            ICameraStatus.ISO_SENSITIVITY -> getIsoSensitivity()
+            ICameraStatus.WHITE_BALANCE -> getWhiteBalance()
+            //ICameraStatus.AE -> getMeteringMode()
+            //ICameraStatus.EFFECT -> getPictureEffect()
+            ICameraStatus.BATTERY -> getRemainBattery()
+            ICameraStatus.TORCH_MODE -> getTorchMode()
+            //ICameraStatus.FOCUS_STATUS -> getfocusStatus()
+            else -> ""
+        })
+    }
+
+    private fun getRemainBatteryColor() : Int
+    {
+        return (Color.WHITE)
+    }
 
-    fun getAvailableItemList(listKey: String?): List<String?> {
-        if (listKey == null) {
-            // アイテム名の一覧を応答する
-            return availableStatusNameList
+    private fun getTakeMode() : String
+    {
+        var status = ""
+        try
+        {
+
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
         }
+        return (status)
+    }
 
-        /////  選択可能なステータスの一覧を取得する : でも以下はアイテム名の一覧... /////
-        val selection: ArrayList<String?> = ArrayList()
-        try {
-            for (index in 0 until statusHolder.size()) {
-                val key = statusHolder.keyAt(index)
-                selection.add(statusNameArray[key])
+    private fun getShutterSpeed() : String
+    {
+        var status = ""
+        try
+        {
+
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
+        return (status)
+    }
+
+    private fun getExpRev() : String
+    {
+        var status = ""
+        try
+        {
+
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
+        return (status)
+    }
+
+    private fun getIsoSensitivity() : String
+    {
+        var status = ""
+        try
+        {
+
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
+        return (status)
+    }
+
+    private fun getRemainBattery() : String
+    {
+        var status = ""
+        try
+        {
+
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
+        return (status)
+    }
+
+    private fun getWhiteBalance() : String
+    {
+        var status = ""
+        try
+        {
+            status = "WB: "
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
+        return (status)
+    }
+
+    private fun getTorchMode() : String
+    {
+        var status = ""
+        try
+        {
+            status = "Flash: "
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
+        return (status)
+    }
+
+    fun setItemStatus(key: String, value: String)
+    {
+        Log.v(TAG, " setItemStatus(key:$key, value:$value)")
+        try
+        {
+            when (key) {
+                ICameraStatus.TAKE_MODE -> setTakeMode(value)
+                ICameraStatus.SHUTTER_SPEED -> setShutterSpeed(value)
+                //ICameraStatus.APERTURE -> setAperture(value)
+                ICameraStatus.EXPREV -> setExpRev(value)
+                //ICameraStatus.CAPTURE_MODE -> setCaptureMode(value)
+                ICameraStatus.ISO_SENSITIVITY -> setIsoSensitivity(value)
+                ICameraStatus.WHITE_BALANCE -> setWhiteBalance(value)
+                //ICameraStatus.AE -> setMeteringMode(value)
+                //ICameraStatus.EFFECT -> setPictureEffect(value)
+                ICameraStatus.TORCH_MODE -> setTorchMode(value)
+                //ICameraStatus.BATTERY -> setRemainBattery(value)
+                //ICameraStatus.FOCUS_STATUS -> setfocusStatus(value)
+                else -> return
             }
-        } catch (e: Exception) {
+        }
+        catch (e: Exception)
+        {
             e.printStackTrace()
         }
-        return selection
     }
 
-    fun getItemStatusColor(key: String): Int
+    private fun setTakeMode(value: String)
     {
-        return (Color.WHITE)
+        try
+        {
+            Log.v(TAG, " setTakeMode($value)")
+
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
     }
 
-    fun getItemStatus(orgKey: String): String {
-        var key = orgKey
-        try {
-            val strIndex = key.indexOf("x")
-            Log.v(TAG, "getItemStatus() : $key [$strIndex]")
-            if (strIndex >= 1) {
-                key = key.substring(strIndex + 1)
-                try {
-                    val id = key.toInt(16)
-                    val value = statusHolder[id]
-                    Log.v(TAG, "getItemStatus() value : $value")
-                    return value.toString() + ""
-                } catch (e: Exception) {
-                    e.printStackTrace()
-                }
+    private fun setShutterSpeed(value: String)
+    {
+        try
+        {
+            Log.v(TAG, " setShutterSpeed($value)")
+
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
+    }
+
+    private fun setExpRev(value: String)
+    {
+        try
+        {
+            Log.v(TAG, " setExpRev($value)")
+
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
+    }
+
+    private fun setIsoSensitivity(value: String)
+    {
+        try
+        {
+            Log.v(TAG, " setIsoSensitivity($value)")
+
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
+    }
+
+    private fun setWhiteBalance(value: String)
+    {
+        try
+        {
+            if (!::commandPublisher.isInitialized)
+            {
+                // 未初期化の場合はコマンドを送らない
+                return
             }
-            for (index in 0 until statusNameArray.size()) {
-                val id = statusNameArray.keyAt(index)
-                val strKey = statusNameArray.valueAt(index)
-                if (key.contentEquals(strKey)) {
-                    val value = statusHolder[id]
-                    return value.toString() + ""
-                }
+            Log.v(TAG, " setWhiteBalance($value)")
+            when (value)
+            {
+                "AUTO" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x04))
+                "Daylight" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x01))
+                "Cloudy" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x02))
+                "Fluorescent" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x10))
+                "Fluorescent CWF" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x20)) //
+                "Incandescent" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x40))  // 白熱灯
+                "Underwater" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x80))    // 不明...
+                "Other" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x08))         // 不明...
+                else -> { }
             }
-        } catch (e: Exception) {
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
+    }
+
+    private fun setTorchMode(value: String)
+    {
+        try
+        {
+            if (!::commandPublisher.isInitialized)
+            {
+                // 未初期化の場合はコマンドを送らない
+                return
+            }
+            Log.v(TAG, " setTorchMode($value)")
+            when (value)
+            {
+                "OFF" -> commandPublisher.enqueueCommand(PixproFlashOff(PixproCommandOnlyCallback()))
+                "ON" -> commandPublisher.enqueueCommand(PixproFlashOn(PixproCommandOnlyCallback()))
+                "AUTO" -> commandPublisher.enqueueCommand(PixproFlashAuto(PixproCommandOnlyCallback()))
+                else -> { }
+            }
+        }
+        catch (e: Exception)
+        {
             e.printStackTrace()
         }
-        return "? [$key]"
     }
 
-    init {
+    init
+    {
         statusHolder.clear()
-        prepareStatusNameArray()
     }
 }
index 6c813e6..691b235 100644 (file)
@@ -1,6 +1,6 @@
 // Top-level build file where you can add configuration options common to all sub-projects/modules.
 buildscript {
-    ext.kotlin_version = "1.5.21"
+    ext.kotlin_version = "1.5.30"
     repositories {
         google()
         mavenCentral()