1 package jp.sfjp.gokigen.a01c.thetacamerawrapper.status
3 import android.util.Log
4 import jp.sfjp.gokigen.a01c.ICameraStatusUpdateNotify
5 import jp.sfjp.gokigen.a01c.ICameraStatusWatcher
6 import jp.sfjp.gokigen.a01c.thetacamerawrapper.status.ICameraStatus.*
7 import jp.sfjp.gokigen.a01c.utils.SimpleHttpClient
8 import org.json.JSONObject
10 class ThetaCameraStatusWatcher : ICameraStatus, ICameraStatusWatcher
12 private val httpClient = SimpleHttpClient()
13 private var whileFetching = false
14 private var currentBatteryLevel : Double = 0.0
15 private var currentCaptureStatus : String = ""
16 private var currentBatteryStatus : String = ""
19 override fun getStatusList(key: String): List<String>
21 return (ArrayList<String>())
24 override fun getStatus(key: String): String
29 override fun startStatusWatch(notifier: ICameraStatusUpdateNotify)
33 Log.v(TAG, "startStatusWatch() already starting.")
42 val getStateUrl = "http://192.168.1.1/osc/state"
43 Log.v(TAG, " >>>>> START STATUS WATCH : $getStateUrl")
46 val response: String? = httpClient.httpPostWithHeader(getStateUrl, "", null, "application/json;charset=utf-8", timeoutMs)
47 if (!(response.isNullOrEmpty()))
50 checkStatus(response, notifier)
75 private fun checkStatus(response : String, notifier: ICameraStatusUpdateNotify)
79 //Log.v(TAG, " STATUS : $response")
80 val stateObject = JSONObject(response).getJSONObject("state")
83 val batteryLevel = stateObject.getDouble(THETA_BATTERY_LEVEL)
84 if (batteryLevel != currentBatteryLevel)
86 Log.v(TAG, " BATTERY : $currentBatteryLevel => $batteryLevel")
87 currentBatteryLevel = batteryLevel
88 notifier.updateRemainBattery(currentBatteryLevel)
98 val batteryStatus = stateObject.getString(THETA_CAPTURE_STATUS)
99 if (batteryStatus != currentBatteryStatus)
101 Log.v(TAG, " BATTERY STATUS : $currentBatteryStatus => $batteryStatus")
102 currentBatteryStatus = batteryStatus
105 catch (e : Exception)
112 val captureStatus = stateObject.getString(THETA_CAPTURE_STATUS)
113 if (captureStatus != currentCaptureStatus)
115 Log.v(TAG, " CAPTURE STATUS : $currentCaptureStatus -> $captureStatus")
116 if (captureStatus != "idle")
118 notifier.updateCameraStatus(captureStatus)
120 currentCaptureStatus = captureStatus
123 catch (e : Exception)
128 catch (ee : Exception)
134 override fun stopStatusWatch()
136 whileFetching = false
141 private val TAG = ThetaCameraStatusWatcher::class.java.simpleName
142 private const val timeoutMs = 1500