Ricoh Theta x Nurosky Shutter
Révision | 8dc47603055f86490fba838816a7c3e3fc3f4f28 (tree) |
---|---|
l'heure | 2021-02-23 15:57:52 |
Auteur | MRSa <mrsa@myad...> |
Commiter | MRSa |
すでにペアリングしていた時に情報を取得できなかったのを修正。
@@ -1 +1 @@ | ||
1 | -XXX | |
1 | +Theta "Thought" Shutter : Theta x Mindwave Mobile2(EEG) Shutter |
@@ -18,12 +18,14 @@ import jp.osdn.gokigen.thetathoughtshutter.theta.ThetaCaptureControl | ||
18 | 18 | import jp.osdn.gokigen.thetathoughtshutter.theta.ThetaHardwareControl |
19 | 19 | import jp.osdn.gokigen.thetathoughtshutter.theta.ThetaSetupBluetoothSPP |
20 | 20 | import jp.osdn.gokigen.thetathoughtshutter.theta.operation.IOperationCallback |
21 | +import jp.osdn.gokigen.thetathoughtshutter.theta.status.ThetaCameraStatusWatcher | |
21 | 22 | import java.lang.Exception |
22 | 23 | |
23 | 24 | class MainActivity : PluginActivity(), IBluetoothScanResult, IDetectSensingReceiver |
24 | 25 | { |
25 | 26 | private val thetaHardwareControl = ThetaHardwareControl(this) |
26 | 27 | private val thetaCaptureControl = ThetaCaptureControl("http://localhost:8080") |
28 | + private val thetaStatusWatcher = ThetaCameraStatusWatcher("http://localhost:8080") | |
27 | 29 | private val applicationStatus : MyApplicationStatus = MyApplicationStatus() |
28 | 30 | private val bluetoothConnection = MindWaveConnection(this, BrainwaveDataHolder(this), this) |
29 | 31 |
@@ -49,38 +51,24 @@ class MainActivity : PluginActivity(), IBluetoothScanResult, IDetectSensingRecei | ||
49 | 51 | { |
50 | 52 | if (keyCode == KeyReceiver.KEYCODE_WLAN_ON_OFF) // Wirelessボタン |
51 | 53 | { |
52 | - if (applicationStatus.status == MyApplicationStatus.Status.Initialized) | |
54 | + if ((applicationStatus.status == MyApplicationStatus.Status.Initialized)|| | |
55 | + (applicationStatus.status == MyApplicationStatus.Status.FailedInitialize)) | |
53 | 56 | { |
54 | 57 | // Bluetooth SPPで EEGに接続する |
55 | 58 | connectToEEG() |
56 | 59 | } |
57 | 60 | } |
58 | -/* | |
59 | 61 | if (keyCode == KeyReceiver.KEYCODE_MEDIA_RECORD) // Modeボタン |
60 | 62 | { |
61 | - when (applicationStatus.status) { | |
62 | - MyApplicationStatus.Status.Searching -> { | |
63 | - // ダミー処理 (EEG接続完了) | |
64 | - applicationStatus.status = MyApplicationStatus.Status.Connected | |
65 | - } | |
66 | - MyApplicationStatus.Status.Scanning -> { | |
67 | - // ダミー処理 (高まっている状態) | |
68 | - applicationStatus.status = MyApplicationStatus.Status.Syncing | |
69 | - } | |
70 | - MyApplicationStatus.Status.Syncing -> { | |
71 | - // ダミー処理 (高まるのを待っている状態) | |
72 | - applicationStatus.status = MyApplicationStatus.Status.Scanning | |
73 | - } | |
74 | - else -> { | |
75 | - // ダミー処理 (初期化完了) | |
76 | - applicationStatus.status = MyApplicationStatus.Status.Initialized | |
77 | - } | |
78 | - } | |
63 | + // 接続エラーにする | |
64 | + applicationStatus.status = MyApplicationStatus.Status.FailedInitialize | |
79 | 65 | } |
66 | +/* | |
80 | 67 | if (keyCode == KeyReceiver.KEYCODE_FUNCTION) // Fnボタン (Z1のみ) |
81 | 68 | { |
82 | 69 | |
83 | 70 | } |
71 | + | |
84 | 72 | if (keyCode == KeyReceiver.KEYCODE_CAMERA) // Shutterボタン |
85 | 73 | { |
86 | 74 |
@@ -272,6 +260,9 @@ class MainActivity : PluginActivity(), IBluetoothScanResult, IDetectSensingRecei | ||
272 | 260 | // Bluetoothデバイスが見つかった! |
273 | 261 | applicationStatus.status = MyApplicationStatus.Status.Connected |
274 | 262 | updateStatus(applicationStatus.status) |
263 | + | |
264 | + // 周期実行 | |
265 | + thetaStatusWatcher.startStatusWatch() | |
275 | 266 | } |
276 | 267 | catch (e : Exception) |
277 | 268 | { |
@@ -303,7 +294,7 @@ class MainActivity : PluginActivity(), IBluetoothScanResult, IDetectSensingRecei | ||
303 | 294 | |
304 | 295 | override fun detectAttention() |
305 | 296 | { |
306 | - Log.v(TAG, " ===== DETECT ATTENTION =====") | |
297 | + //Log.v(TAG, " ===== DETECT ATTENTION =====") | |
307 | 298 | applicationStatus.status = MyApplicationStatus.Status.Syncing |
308 | 299 | updateStatus(applicationStatus.status) |
309 | 300 | } |
@@ -315,7 +306,7 @@ class MainActivity : PluginActivity(), IBluetoothScanResult, IDetectSensingRecei | ||
315 | 306 | |
316 | 307 | override fun lostAttention() |
317 | 308 | { |
318 | - Log.v(TAG, " ===== LOST ATTENTION =====") | |
309 | + //Log.v(TAG, " ===== LOST ATTENTION =====") | |
319 | 310 | applicationStatus.status = MyApplicationStatus.Status.Scanning |
320 | 311 | updateStatus(applicationStatus.status) |
321 | 312 | } |
@@ -327,7 +318,7 @@ class MainActivity : PluginActivity(), IBluetoothScanResult, IDetectSensingRecei | ||
327 | 318 | |
328 | 319 | override fun detectAttentionThreshold() |
329 | 320 | { |
330 | - Log.v(TAG, " ===== DETECT ATTENTION THRESHOLD =====") | |
321 | + //Log.v(TAG, " ===== DETECT ATTENTION THRESHOLD =====") | |
331 | 322 | try |
332 | 323 | { |
333 | 324 | // 静止画の撮影! |
@@ -341,38 +332,6 @@ class MainActivity : PluginActivity(), IBluetoothScanResult, IDetectSensingRecei | ||
341 | 332 | |
342 | 333 | override fun detectMediationThreshold() |
343 | 334 | { |
344 | - Log.v(TAG, " ===== DETECT MEDIATION THRESHOLD =====") | |
335 | + //Log.v(TAG, " ===== DETECT MEDIATION THRESHOLD =====") | |
345 | 336 | } |
346 | - | |
347 | 337 | } |
348 | - | |
349 | -// | |
350 | -// ----------------------------------------------------- | |
351 | -// LED1 : 電源ランプ | |
352 | -// LED2 : カメラステータス ランプ(レンズとマイクの間) | |
353 | -// LED3 : ワイヤレスマーク ランプ | |
354 | -// LED4 : キャプチャーモード (カメラ) | |
355 | -// LED5 : キャプチャーモード (ムービー) | |
356 | -// LED6 : キャプチャーモード (LIVEストリーミング) | |
357 | -// LED7 : ビデオ録画 ランプ | |
358 | -// LED8 : メモリ警告ランプ | |
359 | -// | |
360 | -// BTN1 : 電源ボタン | |
361 | -// BTN2 : ワイヤレスボタン | |
362 | -// BTN3 : モードボタン | |
363 | -// SHUT : シャッターボタン | |
364 | -// ----------------------------------------------------- | |
365 | -// | |
366 | -// [制御可能なLED] | |
367 | -// - LED3~LED8 : カラー : "blue", "green", "red", "cyan", "magenta", "yellow", "white" | |
368 | -// - ブリンク間隔 : 1~2000 msec | |
369 | -// | |
370 | -// [KeyCode] | |
371 | -// - 27 : Shutter Button | |
372 | -// - 130 : Mode Button | |
373 | -// - 284 : Wireless Button | |
374 | -// - 119 : Fn Button (Z1 Only) | |
375 | -// | |
376 | -// | |
377 | -// http://localhost:8080/ | |
378 | -// |
@@ -62,6 +62,8 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv | ||
62 | 62 | fun disconnect() |
63 | 63 | { |
64 | 64 | foundDevice = false |
65 | + deviceFinder.reset() | |
66 | + deviceFinder.stopScan() | |
65 | 67 | } |
66 | 68 | |
67 | 69 | private fun registerReceiver() |
@@ -190,6 +192,7 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv | ||
190 | 192 | e.printStackTrace() |
191 | 193 | } |
192 | 194 | } |
195 | + Log.v(TAG, " serialCommunicationMain : SERIAL COMMUNICATION FINISHED.") | |
193 | 196 | try |
194 | 197 | { |
195 | 198 | btSocket.close() |
@@ -212,6 +215,7 @@ class MindWaveConnection(private val activity : Activity, private val dataReceiv | ||
212 | 215 | { |
213 | 216 | // すでにペアリング済み |
214 | 217 | Log.v(TAG, " ALREADY PAIRED ") |
218 | + foundDevice = true | |
215 | 219 | isPairing = true |
216 | 220 | targetDevice = device |
217 | 221 | connectBluetoothDevice(device) |
@@ -1,7 +1,6 @@ | ||
1 | 1 | package jp.osdn.gokigen.thetathoughtshutter.brainwave |
2 | 2 | |
3 | 3 | import android.util.Log |
4 | -import java.util.* | |
5 | 4 | |
6 | 5 | class BrainwaveDataHolder(private val receiver: IDetectSensingReceiver? = null, maxBufferSize: Int = 16000) : IBrainwaveDataReceiver |
7 | 6 | { |
@@ -135,21 +134,18 @@ class BrainwaveDataHolder(private val receiver: IDetectSensingReceiver? = null, | ||
135 | 134 | try { |
136 | 135 | var endPosition = currentPosition - 1 |
137 | 136 | if (currentPosition > size) { |
138 | - return Arrays.copyOfRange(valueBuffer, endPosition - size, endPosition) | |
137 | + return valueBuffer.copyOfRange(endPosition - size, endPosition) | |
139 | 138 | } |
140 | 139 | if (!bufferIsFull) { |
141 | - return Arrays.copyOfRange(valueBuffer, 0, endPosition) | |
140 | + return valueBuffer.copyOfRange(0, endPosition) | |
142 | 141 | } |
143 | 142 | if (currentPosition == 0) { |
144 | 143 | endPosition = maxBufferSize - 1 |
145 | - return Arrays.copyOfRange(valueBuffer, endPosition - size, endPosition) | |
144 | + return valueBuffer.copyOfRange(endPosition - size, endPosition) | |
146 | 145 | } |
147 | 146 | val remainSize = size - (currentPosition - 1) |
148 | - val size0: IntArray = Arrays.copyOfRange(valueBuffer, 0, currentPosition - 1) | |
149 | - val size1: IntArray = Arrays.copyOfRange( | |
150 | - valueBuffer, | |
151 | - maxBufferSize - 1 - remainSize, maxBufferSize - 1 | |
152 | - ) | |
147 | + val size0: IntArray = valueBuffer.copyOfRange(0, currentPosition - 1) | |
148 | + val size1: IntArray = valueBuffer.copyOfRange(maxBufferSize - 1 - remainSize, maxBufferSize - 1) | |
153 | 149 | replyData = IntArray(size) |
154 | 150 | System.arraycopy(size1, 0, replyData, 0, size1.size) |
155 | 151 | System.arraycopy(size0, 0, replyData, size1.size, size0.size) |
@@ -24,7 +24,7 @@ class ThetaCaptureControl(executeUrl : String = "http://192.168.1.1") | ||
24 | 24 | { |
25 | 25 | if (resultStr != null) |
26 | 26 | { |
27 | - Log.v(TAG, "set to Image : $resultStr ") | |
27 | + Log.v(TAG, "set to Image capture mode.: $resultStr ") | |
28 | 28 | } |
29 | 29 | } |
30 | 30 | }) |
@@ -39,7 +39,7 @@ class ThetaCaptureControl(executeUrl : String = "http://192.168.1.1") | ||
39 | 39 | Log.v(TAG, "ALREADY START CAPTURE SEQUENCE") |
40 | 40 | return |
41 | 41 | } |
42 | - singleShot.singleShot() // まじか、応答しない... | |
42 | + singleShot.singleShot() | |
43 | 43 | } |
44 | 44 | catch (e : Exception) |
45 | 45 | { |
@@ -0,0 +1,7 @@ | ||
1 | +package jp.osdn.gokigen.thetathoughtshutter.theta.status | |
2 | + | |
3 | +interface ICameraStatusWatcher | |
4 | +{ | |
5 | + fun startStatusWatch() | |
6 | + fun stopStatusWatch() | |
7 | +} |
@@ -0,0 +1,7 @@ | ||
1 | +package jp.osdn.gokigen.thetathoughtshutter.theta.status | |
2 | + | |
3 | +interface IStatusNotify | |
4 | +{ | |
5 | + fun changedCaptureMode(captureMode : String) | |
6 | + fun changedExposureProgram(exposureProgram : String) | |
7 | +} | |
\ No newline at end of file |
@@ -0,0 +1,6 @@ | ||
1 | +package jp.osdn.gokigen.thetathoughtshutter.theta.status | |
2 | + | |
3 | +interface IThetaStatusHolder | |
4 | +{ | |
5 | + var captureMode: String | |
6 | +} |
@@ -0,0 +1,363 @@ | ||
1 | +package jp.osdn.gokigen.thetathoughtshutter.theta.status | |
2 | + | |
3 | +import android.util.Log | |
4 | +import jp.osdn.gokigen.thetathoughtshutter.utils.SimpleHttpClient | |
5 | +import org.json.JSONObject | |
6 | + | |
7 | +class ThetaCameraStatusWatcher(private val executeUrl : String = "http://192.168.1.1", private val statusNotify : IStatusNotify? = null) : ICameraStatusWatcher, IThetaStatusHolder | |
8 | +{ | |
9 | + private val httpClient = SimpleHttpClient() | |
10 | + private var whileFetching = false | |
11 | + private var currentIsoSensitivity : Int = 0 | |
12 | + private var currentBatteryLevel : Double = 0.0 | |
13 | + private var currentAperture : Double = 0.0 | |
14 | + private var currentShutterSpeed : Double = 0.0 | |
15 | + private var currentExposureCompensation : Double = 0.0 | |
16 | + private var currentCaptureMode : String = "" | |
17 | + private var currentExposureProgram : String = "" | |
18 | + private var currentCaptureStatus : String = "" | |
19 | + private var currentWhiteBalance : String = "" | |
20 | + private var currentFilter : String = "" | |
21 | + | |
22 | + override fun startStatusWatch() | |
23 | + { | |
24 | + if (whileFetching) | |
25 | + { | |
26 | + Log.v(TAG, "startStatusWatch() already starting.") | |
27 | + return | |
28 | + } | |
29 | + whileFetching = true | |
30 | + | |
31 | + try | |
32 | + { | |
33 | + val thread = Thread { | |
34 | + try | |
35 | + { | |
36 | + val getOptionsUrl = "$executeUrl/osc/commands/execute" | |
37 | + val getStateUrl = "$executeUrl/osc/state" | |
38 | + | |
39 | + val postDataCaptureMode = "{\"name\":\"camera.getOptions\",\"parameters\":{\"timeout\":0, \"optionNames\" : [ \"captureMode\"] }}" | |
40 | + val postDataImage = "{\"name\":\"camera.getOptions\",\"parameters\":{\"timeout\":0, \"optionNames\" : [ \"aperture\",\"captureMode\",\"exposureCompensation\",\"exposureProgram\",\"iso\",\"shutterSpeed\",\"_filter\",\"whiteBalance\"] }}" | |
41 | + val postDataVideo = "{\"name\":\"camera.getOptions\",\"parameters\":{\"timeout\":0, \"optionNames\" : [ \"aperture\",\"captureMode\",\"exposureCompensation\",\"exposureProgram\",\"iso\",\"shutterSpeed\",\"whiteBalance\"] }}" | |
42 | + Log.v(TAG, " >>>>> START STATUS WATCH : $getOptionsUrl") | |
43 | + while (whileFetching) | |
44 | + { | |
45 | + val response0: String? = httpClient.httpPostWithHeader(getOptionsUrl, postDataCaptureMode, null, "application/json;charset=utf-8", timeoutMs) | |
46 | + if (!(response0.isNullOrEmpty())) | |
47 | + { | |
48 | + // 設定データ受信、解析する | |
49 | + checkStatus0(response0) | |
50 | + } | |
51 | + val postData = if (currentCaptureMode != "image") { postDataVideo } else { postDataImage } | |
52 | + val response1: String? = httpClient.httpPostWithHeader(getOptionsUrl, postData, null, "application/json;charset=utf-8", timeoutMs) | |
53 | + if (!(response1.isNullOrEmpty())) | |
54 | + { | |
55 | + // 設定データ受信、解析する | |
56 | + checkStatus1(response1) | |
57 | + } | |
58 | + val response2: String? = httpClient.httpPostWithHeader(getStateUrl, "", null, "application/json;charset=utf-8", timeoutMs) | |
59 | + if (!(response2.isNullOrEmpty())) | |
60 | + { | |
61 | + // ステータスデータ受信、解析する | |
62 | + checkStatus2(response2) | |
63 | + } | |
64 | + try | |
65 | + { | |
66 | + // ちょっと休む | |
67 | + Thread.sleep(loopWaitMs) | |
68 | + } | |
69 | + catch (e: Exception) | |
70 | + { | |
71 | + e.printStackTrace() | |
72 | + } | |
73 | + } | |
74 | + } | |
75 | + catch (e: Exception) | |
76 | + { | |
77 | + e.printStackTrace() | |
78 | + } | |
79 | + } | |
80 | + thread.start() | |
81 | + } | |
82 | + catch (e: Exception) | |
83 | + { | |
84 | + e.printStackTrace() | |
85 | + } | |
86 | + } | |
87 | + | |
88 | + private fun checkStatus0(response: String) | |
89 | + { | |
90 | + try | |
91 | + { | |
92 | + //Log.v(TAG, " STATUS0 : $response") | |
93 | + val stateObject = JSONObject(response).getJSONObject("results").getJSONObject("options") | |
94 | + try | |
95 | + { | |
96 | + val captureMode = stateObject.getString(THETA_CAPTURE_MODE) | |
97 | + if (captureMode != currentCaptureMode) | |
98 | + { | |
99 | + Log.v(TAG, " CapMode : $currentCaptureMode -> $captureMode") | |
100 | + currentCaptureMode = captureMode | |
101 | + statusNotify?.changedCaptureMode(captureMode) | |
102 | + } | |
103 | + } | |
104 | + catch (e: Exception) | |
105 | + { | |
106 | + e.printStackTrace() | |
107 | + } | |
108 | + } | |
109 | + catch (e : Exception) | |
110 | + { | |
111 | + e.printStackTrace() | |
112 | + } | |
113 | + } | |
114 | + | |
115 | + private fun checkStatus1(response: String) | |
116 | + { | |
117 | + try | |
118 | + { | |
119 | + //Log.v(TAG, " STATUS1 : $response") | |
120 | + val stateObject = JSONObject(response).getJSONObject("results").getJSONObject("options") | |
121 | + try | |
122 | + { | |
123 | + val exposureCompensation = stateObject.getDouble(THETA_EXPOSURE_COMPENSATION) | |
124 | + if (exposureCompensation != currentExposureCompensation) | |
125 | + { | |
126 | + Log.v(TAG, " XV : $currentExposureCompensation => $exposureCompensation") | |
127 | + currentExposureCompensation = exposureCompensation | |
128 | + } | |
129 | + } | |
130 | + catch (e: Exception) | |
131 | + { | |
132 | + e.printStackTrace() | |
133 | + } | |
134 | + | |
135 | + try | |
136 | + { | |
137 | + val whiteBalance = stateObject.getString(THETA_WHITE_BALANCE) | |
138 | + if (whiteBalance != currentWhiteBalance) | |
139 | + { | |
140 | + Log.v(TAG, " WB : $currentWhiteBalance => $whiteBalance") | |
141 | + currentWhiteBalance = whiteBalance | |
142 | + } | |
143 | + } | |
144 | + catch (e: Exception) | |
145 | + { | |
146 | + e.printStackTrace() | |
147 | + } | |
148 | + | |
149 | + try | |
150 | + { | |
151 | + val exposureProgram = stateObject.getString(THETA_EXPOSURE_PROGRAM) | |
152 | + if (exposureProgram != currentExposureProgram) | |
153 | + { | |
154 | + currentExposureProgram = exposureProgram | |
155 | + | |
156 | + var mode = "" | |
157 | + when (currentExposureProgram) { | |
158 | + "1" -> mode = "Manual" | |
159 | + "2" -> mode = "Normal" | |
160 | + "3" -> mode = "Aperture" | |
161 | + "4" -> mode = "Shutter" | |
162 | + "9" -> mode = "ISO" | |
163 | + } | |
164 | + statusNotify?.changedExposureProgram(mode) | |
165 | + Log.v(TAG, " ExposureProgram : $mode") | |
166 | + } | |
167 | + } | |
168 | + catch (e: Exception) | |
169 | + { | |
170 | + e.printStackTrace() | |
171 | + } | |
172 | + | |
173 | + if (currentCaptureMode == "image") | |
174 | + { | |
175 | + try | |
176 | + { | |
177 | + val filterValue = stateObject.getString(THETA_FILTER) | |
178 | + if (filterValue != currentFilter) | |
179 | + { | |
180 | + Log.v(TAG, " FILTER : $currentFilter -> $filterValue") | |
181 | + currentFilter = filterValue | |
182 | + } | |
183 | + } | |
184 | + catch (e: Exception) | |
185 | + { | |
186 | + e.printStackTrace() | |
187 | + } | |
188 | + } | |
189 | + else | |
190 | + { | |
191 | + currentFilter = "" | |
192 | + } | |
193 | + | |
194 | + try | |
195 | + { | |
196 | + val isoSensitivity = stateObject.getInt(THETA_ISO_SENSITIVITY) | |
197 | + if (isoSensitivity != currentIsoSensitivity) | |
198 | + { | |
199 | + Log.v(TAG, " ISO : $currentIsoSensitivity -> $isoSensitivity") | |
200 | + currentIsoSensitivity = isoSensitivity | |
201 | + } | |
202 | + } | |
203 | + catch (e: Exception) | |
204 | + { | |
205 | + e.printStackTrace() | |
206 | + } | |
207 | + | |
208 | + try | |
209 | + { | |
210 | + val aperture = stateObject.getDouble(THETA_APERTURE) | |
211 | + if (aperture != currentAperture) | |
212 | + { | |
213 | + Log.v(TAG, " A : $currentAperture -> $aperture") | |
214 | + currentAperture = aperture | |
215 | + } | |
216 | + } | |
217 | + catch (e: Exception) | |
218 | + { | |
219 | + e.printStackTrace() | |
220 | + } | |
221 | + | |
222 | + try | |
223 | + { | |
224 | + val shutterSpeed = stateObject.getDouble(THETA_SHUTTER_SPEED) | |
225 | + if (shutterSpeed != currentShutterSpeed) | |
226 | + { | |
227 | + Log.v(TAG, " SS : ${convertShutterSpeedString(currentShutterSpeed)}") | |
228 | + currentShutterSpeed = shutterSpeed | |
229 | + } | |
230 | + } | |
231 | + catch (e: Exception) | |
232 | + { | |
233 | + e.printStackTrace() | |
234 | + } | |
235 | + | |
236 | + } | |
237 | + catch (ee: Exception) | |
238 | + { | |
239 | + ee.printStackTrace() | |
240 | + } | |
241 | + } | |
242 | + | |
243 | + private fun convertShutterSpeedString(shutterSpeed : Double) : String | |
244 | + { | |
245 | + var inv = 0.0 | |
246 | + var stringValue = "" | |
247 | + try | |
248 | + { | |
249 | + if (shutterSpeed < 1.0) | |
250 | + { | |
251 | + inv = 1.0 / shutterSpeed | |
252 | + } | |
253 | + if (inv < 2.0) // if (inv < 10.0) | |
254 | + { | |
255 | + inv = 0.0 | |
256 | + } | |
257 | + if (inv > 0.0f) | |
258 | + { | |
259 | + // シャッター速度を分数で表示する | |
260 | + var intValue = inv.toInt() | |
261 | + val modValue = intValue % 10 | |
262 | + if (modValue == 9 || modValue == 4) | |
263 | + { | |
264 | + // ちょっと格好が悪いけど...切り上げ | |
265 | + intValue++ | |
266 | + } | |
267 | + stringValue = "1/$intValue" | |
268 | + } | |
269 | + else | |
270 | + { | |
271 | + // シャッター速度を数値(秒数)で表示する | |
272 | + stringValue = "${shutterSpeed}s " | |
273 | + } | |
274 | + } | |
275 | + catch (e : Exception) | |
276 | + { | |
277 | + e.printStackTrace() | |
278 | + } | |
279 | + return (stringValue) | |
280 | + } | |
281 | + | |
282 | + private fun checkStatus2(response: String) | |
283 | + { | |
284 | + try | |
285 | + { | |
286 | + //Log.v(TAG, " STATUS2 : $response") | |
287 | + val stateObject = JSONObject(response).getJSONObject("state") | |
288 | + try | |
289 | + { | |
290 | + val captureStatus = stateObject.getString(THETA_CAPTURE_STATUS) | |
291 | + if (captureStatus != currentCaptureStatus) | |
292 | + { | |
293 | + Log.v(TAG, " CapStatus : $currentCaptureStatus -> $captureStatus") | |
294 | + currentCaptureStatus = captureStatus | |
295 | + } | |
296 | + } | |
297 | + catch (e: Exception) | |
298 | + { | |
299 | + e.printStackTrace() | |
300 | + } | |
301 | + try | |
302 | + { | |
303 | + val batteryLevel = stateObject.getDouble(THETA_BATTERY_LEVEL) | |
304 | + if (batteryLevel != currentBatteryLevel) | |
305 | + { | |
306 | + Log.v(TAG, " BATTERY : $currentBatteryLevel => $batteryLevel") | |
307 | + currentBatteryLevel = batteryLevel | |
308 | + updateRemainBattery(currentBatteryLevel) | |
309 | + } | |
310 | + } | |
311 | + catch (e: Exception) | |
312 | + { | |
313 | + e.printStackTrace() | |
314 | + } | |
315 | + | |
316 | + } | |
317 | + catch (ee: Exception) | |
318 | + { | |
319 | + ee.printStackTrace() | |
320 | + } | |
321 | + } | |
322 | + | |
323 | + private fun updateRemainBattery(percentageDouble: Double) | |
324 | + { | |
325 | + try | |
326 | + { | |
327 | + val percentage = kotlin.math.ceil(percentageDouble * 100.0).toInt() | |
328 | + Log.v(TAG, "BATTERY : $percentage%") | |
329 | + } | |
330 | + catch (ee: java.lang.Exception) | |
331 | + { | |
332 | + ee.printStackTrace() | |
333 | + } | |
334 | + } | |
335 | + | |
336 | + override fun stopStatusWatch() | |
337 | + { | |
338 | + whileFetching = false | |
339 | + } | |
340 | + | |
341 | + companion object | |
342 | + { | |
343 | + private val TAG = ThetaCameraStatusWatcher::class.java.simpleName | |
344 | + private const val timeoutMs = 3300 | |
345 | + private const val loopWaitMs : Long = 35000 // 35sec. おきに状態を取得 | |
346 | + | |
347 | + private const val THETA_BATTERY_LEVEL = "batteryLevel" | |
348 | + private const val THETA_CAPTURE_STATUS = "_captureStatus" | |
349 | + | |
350 | + private const val THETA_APERTURE = "aperture" | |
351 | + private const val THETA_CAPTURE_MODE = "captureMode" | |
352 | + private const val THETA_EXPOSURE_COMPENSATION = "exposureCompensation" | |
353 | + private const val THETA_EXPOSURE_PROGRAM = "exposureProgram" | |
354 | + private const val THETA_ISO_SENSITIVITY = "iso" | |
355 | + private const val THETA_SHUTTER_SPEED = "shutterSpeed" | |
356 | + private const val THETA_WHITE_BALANCE = "whiteBalance" | |
357 | + private const val THETA_FILTER = "_filter" | |
358 | + } | |
359 | + | |
360 | + override var captureMode: String | |
361 | + get() = currentCaptureMode | |
362 | + set(value) { currentCaptureMode = value } | |
363 | +} |
@@ -1,9 +1,7 @@ | ||
1 | 1 | package jp.osdn.gokigen.thetathoughtshutter.utils |
2 | 2 | |
3 | -import android.app.Activity | |
4 | 3 | import android.os.Environment |
5 | 4 | import android.util.Log |
6 | -import jp.osdn.gokigen.thetathoughtshutter.R | |
7 | 5 | import java.io.File |
8 | 6 | import java.io.FileOutputStream |
9 | 7 | import java.text.SimpleDateFormat |