OSDN Git Service

SONY系ステータスの設定変更(Exposure compensation)も仮搭載。
authorMRSa <mrsa@myad.jp>
Sun, 15 Aug 2021 14:57:00 +0000 (23:57 +0900)
committerMRSa <mrsa@myad.jp>
Sun, 15 Aug 2021 14:57:00 +0000 (23:57 +0900)
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/sony/wrapper/eventlistener/SonyStatus.kt
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/sony/wrapper/eventlistener/SonyStatusCandidates.kt

index 6539df3..bec3005 100644 (file)
@@ -105,11 +105,11 @@ class SonyStatus(jsonObject : JSONObject) : ICameraStatus, ICameraChangeListener
         var color = Color.WHITE
         try
         {
-            if (currentRemainBatteryPercent < 30)
+            if (currentRemainBatteryPercent <= 30.1)
             {
                 color = Color.RED
             }
-            else if (currentRemainBatteryPercent < 50)
+            else if (currentRemainBatteryPercent <= 50.1)
             {
                 color = Color.YELLOW
             }
@@ -231,7 +231,7 @@ class SonyStatus(jsonObject : JSONObject) : ICameraStatus, ICameraChangeListener
         currentCameraStatus = parseEventStatus(currentCameraStatus, jsonObject, "cameraStatus", "cameraStatus", 1)
         currentExposureMode = parseEventStatus(currentExposureMode, jsonObject, "exposureMode", "currentExposureMode", 18)
         currentShootMode = parseEventStatus(currentShootMode, jsonObject, "shootMode", "currentShootMode",21)
-        currentExposureCompensation = parseEventStatus(currentExposureCompensation, jsonObject, "exposureCompensation", "currentExposureCompensation",25)
+        currentExposureCompensation = parseExposureCompensation(currentExposureCompensation, jsonObject)
 
         currentFlashMode = parseEventStatus(currentFlashMode, jsonObject, "flashMode", "currentFlashMode",26)
         currentFNumber = parseEventStatus(currentFNumber, jsonObject, "fNumber", "currentFNumber",27)
@@ -243,6 +243,37 @@ class SonyStatus(jsonObject : JSONObject) : ICameraStatus, ICameraChangeListener
         currentRemainBattery = parseBatteryInfo(currentRemainBattery, jsonObject)
     }
 
+    private fun parseExposureCompensation(currentStatus: String, replyJson: JSONObject) : String
+    {
+        val indexOfCameraStatus = 25
+        var eventStatus = currentStatus
+        try
+        {
+            val resultsObj = replyJson.getJSONArray("result")
+            if ((resultsObj.length() > indexOfCameraStatus)&&(!resultsObj.isNull(indexOfCameraStatus)))
+            {
+                val cameraStatusObj = resultsObj.getJSONObject(indexOfCameraStatus)
+                val type = cameraStatusObj.getString("type")
+                if ("exposureCompensation" == type)
+                {
+                    val currentIndex = cameraStatusObj.getInt("currentExposureCompensation")
+                    val currentStep = cameraStatusObj.getInt("stepIndexOfExposureCompensation")
+                    val showValue = currentIndex.toDouble() / if (currentStep == 2) { 2.0 } else { 3.0 }
+                    eventStatus = String.format("%+1.1f", showValue)
+                }
+                else
+                {
+                    Log.w(TAG, "Event reply: Illegal Index ($indexOfCameraStatus) $type : $cameraStatusObj")
+                }
+            }
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
+        return (eventStatus)
+    }
+
     private fun parseBatteryInfo(currentStatus: String, replyJson: JSONObject) : String
     {
         val indexOfCameraStatus = 56
@@ -257,9 +288,8 @@ class SonyStatus(jsonObject : JSONObject) : ICameraStatus, ICameraChangeListener
                 val type = cameraStatusObj.getString("type")
                 if ("batteryInfo" == type)
                 {
-                    Log.v(TAG, "  =====> $batteryInfoObj")
+                    //Log.v(TAG, "  =====> $batteryInfoObj")
                     //eventStatus = cameraStatusObj.getString(key)
-
                     val numerator = batteryInfoObj.getInt("levelNumer")
                     val denominator =  batteryInfoObj.getInt("levelDenom")
                     if ((numerator <= 0)||(denominator <= 0))
index 36ad961..1045f33 100644 (file)
@@ -7,6 +7,12 @@ import org.json.JSONArray
 class SonyStatusCandidates()
 {
     private lateinit var cameraApi: ISonyCameraApi
+
+    private var expRevCurrentIndex: Int = 0
+    private var expRevUpperIndex: Int = 0
+    private var expRevLowerIndex: Int = 0
+    private var expRevStepIndex: Int = 0
+
     fun setCameraApi(sonyCameraApi: ISonyCameraApi)
     {
         cameraApi = sonyCameraApi
@@ -97,8 +103,7 @@ class SonyStatusCandidates()
 
     fun getAvailableExpRev(): List<String?>
     {
-/*
-        val apertureList : ArrayList<String> = ArrayList()
+        val availableExpRevList : ArrayList<String> = ArrayList()
         try
         {
             if (::cameraApi.isInitialized)
@@ -107,11 +112,15 @@ class SonyStatusCandidates()
                 val resultsObj = replyJson?.getJSONArray("result")
                 if (resultsObj?.isNull(1) == false)
                 {
-                    val availableItemArray = resultsObj.getJSONArray(1)
-                    for (index in 0 until availableItemArray.length())
+                    Log.v(TAG, "  getAvailableExposureCompensation: $resultsObj")
+                    expRevCurrentIndex = resultsObj.getInt(0)
+                    expRevUpperIndex = resultsObj.getInt(1)
+                    expRevLowerIndex = resultsObj.getInt(2)
+                    expRevStepIndex = resultsObj.getInt(3)  // 1: 1/3EV, 2: 1/2EV
+                    for (index in expRevLowerIndex..expRevUpperIndex)
                     {
-                        val itemString = availableItemArray.getString(index)
-                        apertureList.add(itemString)
+                        val showValue = index.toDouble() / if (expRevStepIndex == 2) { 2.0 } else { 3.0 }
+                        availableExpRevList.add(String.format("%+1.1f", showValue))
                     }
                 }
             }
@@ -120,8 +129,7 @@ class SonyStatusCandidates()
         {
             e.printStackTrace()
         }
-*/
-        return (ArrayList())
+        return (availableExpRevList)
     }
 
     fun getAvailableCaptureMode(): List<String?>
@@ -277,13 +285,31 @@ class SonyStatusCandidates()
     {
         try
         {
-/*
-            val replyJson = cameraApi.callGenericSonyApiMethod("camera", "setxxx", JSONArray().put(value), "1.0")
-            if (cameraApi.isErrorReply(replyJson))
+            val doubleValue = value.toDoubleOrNull()
+            val step : Double = if (expRevStepIndex == 2) { 2.0 } else { 3.0 }
+            if (doubleValue == null)
             {
-                Log.v(TAG, " REPLY ERROR(aperture) : $replyJson")
+                Log.v(TAG," ----- setExposureCompensation : cannot convert to double : $value" )
+                return
             }
-*/
+
+            Log.v(TAG, " ----- setExpRev($value) : $doubleValue ($expRevLowerIndex..$expRevUpperIndex) step:$step")
+
+            for (index in expRevLowerIndex..expRevUpperIndex)
+            {
+                val checkValue = index.toDouble() / step
+                if ((doubleValue - checkValue) <= 0.0f)
+                {
+                    Log.v(TAG, " ----- SET exposureCompensation : $doubleValue (index:$index)")
+                    val replyJson = cameraApi.callGenericSonyApiMethod("camera", "setExposureCompensation", JSONArray().put(index), "1.0")
+                    if (cameraApi.isErrorReply(replyJson))
+                    {
+                        Log.v(TAG, " REPLY ERROR(exposureCompensation) : $replyJson")
+                    }
+                    return
+                }
+            }
+            Log.v(TAG, " --- exposureCompensation IS NOT UPDATED ---")
         }
         catch (e: Exception)
         {
@@ -367,7 +393,7 @@ class SonyStatusCandidates()
     {
         try
         {
-            Log.v(TAG, "setTorchMode($value)")
+            Log.v(TAG, "setRemainBattery($value)")
         }
         catch (e: Exception)
         {