1 package jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.status
3 import android.graphics.Color
4 import android.util.Log
5 import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus
6 import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.IPixproCommandPublisher
7 import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.base.PixproCommandOnlyCallback
8 import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.specific.*
9 import java.lang.Exception
12 class PixproStatusHolder
16 private val TAG = PixproStatusHolder::class.java.simpleName
19 private var statusConvert = PixproStatusConvert(this)
20 private lateinit var commandPublisher : IPixproCommandPublisher
22 private var currentTakeMode = ""
23 private var currentFlashMode = ""
24 private var currentWhiteBalance = ""
25 private var currentIsoSensitivity = ""
26 private var currentExposureCompensation = ""
27 private var currentShutterSpeed = ""
28 private var currentRemainBattery = ""
29 private var currentCaptureMode = ""
30 private var currentImageSize = ""
31 private var currentMovieSize = ""
33 fun setCommandPublisher(commandPublisher : IPixproCommandPublisher)
35 this.commandPublisher = commandPublisher
38 fun updateValue(key: String, value: String)
42 ICameraStatus.TAKE_MODE -> { currentTakeMode = value }
43 ICameraStatus.SHUTTER_SPEED -> { currentShutterSpeed = value }
44 ICameraStatus.EXPREV -> { currentExposureCompensation = value }
45 ICameraStatus.ISO_SENSITIVITY -> { currentIsoSensitivity = value }
46 ICameraStatus.WHITE_BALANCE -> { currentWhiteBalance = value }
47 ICameraStatus.TORCH_MODE -> { currentFlashMode = value }
48 ICameraStatus.BATTERY -> { currentRemainBattery = value }
49 ICameraStatus.CAPTURE_MODE -> { currentCaptureMode = value }
50 ICameraStatus.IMAGE_SIZE -> { currentImageSize = value }
51 ICameraStatus.MOVIE_SIZE -> { currentMovieSize = value }
53 //ICameraStatus.APERTURE -> { }
54 //ICameraStatus.AE -> { }
55 //ICameraStatus.EFFECT -> { }
56 //ICameraStatus.FOCUS_STATUS -> { }
61 fun getAvailableItemList(key: String?): List<String?>
66 ICameraStatus.TAKE_MODE -> statusConvert.getAvailableTakeMode()
67 ICameraStatus.SHUTTER_SPEED -> statusConvert.getAvailableShutterSpeed()
68 ICameraStatus.APERTURE -> statusConvert.getAvailableAperture()
69 ICameraStatus.EXPREV -> statusConvert.getAvailableExpRev()
70 ICameraStatus.CAPTURE_MODE -> statusConvert.getAvailableCaptureMode()
71 ICameraStatus.ISO_SENSITIVITY -> statusConvert.getAvailableIsoSensitivity()
72 ICameraStatus.WHITE_BALANCE -> statusConvert.getAvailableWhiteBalance()
73 ICameraStatus.AE -> statusConvert.getAvailableMeteringMode(currentTakeMode)
74 ICameraStatus.EFFECT -> statusConvert.getAvailablePictureEffect()
75 ICameraStatus.TORCH_MODE -> statusConvert.getAvailableTorchMode()
76 //ICameraStatus.BATTERY -> statusConvert.getAvailableRemainBattery()
77 //ICameraStatus.FOCUS_STATUS -> statusConvert.getAvailableFocusStatus()
80 //Log.v(TAG, " ----- getAvailableItemList($key) ")
81 //sendCamGetSettingCmd("colormode")
90 fun getItemStatusColor(key: String): Int
93 ICameraStatus.BATTERY -> getRemainBatteryColor()
94 ICameraStatus.CAPTURE_MODE -> getCaptureModeColor()
99 fun getItemStatus(orgKey: String): String
101 return (when (orgKey) {
102 ICameraStatus.TAKE_MODE -> getTakeMode()
103 ICameraStatus.SHUTTER_SPEED -> getShutterSpeed()
104 //ICameraStatus.APERTURE -> getAperture()
105 ICameraStatus.EXPREV -> getExpRev()
106 ICameraStatus.CAPTURE_MODE -> getCaptureMode()
107 ICameraStatus.ISO_SENSITIVITY -> getIsoSensitivity()
108 ICameraStatus.WHITE_BALANCE -> getWhiteBalance()
109 ICameraStatus.AE -> getMeteringMode()
110 ICameraStatus.EFFECT -> getPictureEffect()
111 ICameraStatus.BATTERY -> getRemainBattery()
112 ICameraStatus.TORCH_MODE -> getTorchMode()
113 //ICameraStatus.FOCUS_STATUS -> getfocusStatus()
118 private fun getCaptureModeColor() : Int
120 if (currentCaptureMode.length > 1)
127 private fun getRemainBatteryColor() : Int
132 private fun getTakeMode() : String
134 return (currentTakeMode)
137 private fun getShutterSpeed() : String
139 return (currentShutterSpeed)
142 private fun getExpRev() : String
144 return (currentExposureCompensation)
147 private fun getIsoSensitivity() : String
149 return ("ISO:$currentIsoSensitivity")
152 private fun getRemainBattery() : String
154 return (currentRemainBattery)
157 private fun getWhiteBalance() : String
159 return ("WB: $currentWhiteBalance")
162 private fun getMeteringMode() : String
164 return (when (currentTakeMode) {
165 "Video" -> { currentMovieSize }
166 else -> { currentImageSize }
171 private fun getPictureEffect() : String
176 private fun getCaptureMode() : String
178 return (currentCaptureMode)
181 private fun getTorchMode() : String
183 return ("Flash: $currentFlashMode")
186 fun setItemStatus(key: String, value: String)
188 Log.v(TAG, " setItemStatus(key:$key, value:$value)")
192 ICameraStatus.TAKE_MODE -> setTakeMode(value)
193 ICameraStatus.SHUTTER_SPEED -> setShutterSpeed(value)
194 //ICameraStatus.APERTURE -> setAperture(value)
195 ICameraStatus.EXPREV -> setExpRev(value)
196 ICameraStatus.CAPTURE_MODE -> updateValue(key, value)
197 ICameraStatus.ISO_SENSITIVITY -> setIsoSensitivity(value)
198 ICameraStatus.WHITE_BALANCE -> setWhiteBalance(value)
199 ICameraStatus.AE -> setMeteringMode(value)
200 ICameraStatus.EFFECT -> setPictureEffect(value)
201 ICameraStatus.TORCH_MODE -> setTorchMode(value)
202 //ICameraStatus.BATTERY -> setRemainBattery(value)
203 //ICameraStatus.FOCUS_STATUS -> setfocusStatus(value)
213 private fun setTakeMode(value: String)
217 if (!::commandPublisher.isInitialized)
222 Log.v(TAG, " setTakeMode($value)")
225 "P" -> commandPublisher.enqueueCommand(PixproChangeMode(PixproCommandOnlyCallback(), 0x01))
226 "M" -> commandPublisher.enqueueCommand(PixproChangeMode(PixproCommandOnlyCallback(), 0x08))
227 "ASCN" -> commandPublisher.enqueueCommand(PixproChangeMode(PixproCommandOnlyCallback(), 0x20))
228 "Video" -> commandPublisher.enqueueCommand(PixproChangeVideoMode(PixproCommandOnlyCallback()))
229 "Cont. Shot" -> commandPublisher.enqueueCommand(PixproChangeMode(PixproCommandOnlyCallback(), 0x00, 0x08))
239 private fun setShutterSpeed(value: String)
244 if (!::commandPublisher.isInitialized)
249 Log.v(TAG, " setShutterSpeed($value)")
252 "1/2000" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x01))
253 "1/1600" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x02))
254 "1/1200" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x03))
255 "1/1000" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x04))
256 "1/800" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x05))
257 "1/600" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x06))
258 "1/500" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x07))
259 "1/400" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x08))
260 "1/320" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x09))
261 "1/250" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x0a))
262 "1/200" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x0b))
263 "1/160" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x0c))
264 "1/125" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x0d))
265 "1/100" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x0e))
266 "1/80" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x0f))
267 "1/60" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x10))
268 "1/50" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x11))
269 "1/40" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x12))
270 "1/30" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x13))
271 "1/25" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x14))
272 "1/20" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x15))
273 "1/15" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x16))
274 "1/13" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x17))
275 "1/10" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x18))
276 "1/8" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x19))
277 "1/6" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x1a))
278 "1/5" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x1b))
279 "1/4" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x1c))
280 "1/3" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x1d))
281 "1/2.5" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x1e))
282 "1/2" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x1f))
283 "1/1.6" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x20))
284 "1/1.3" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x21))
285 "1s" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x22))
286 "1.3s" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x23))
287 "1.5s" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x24))
288 "2s" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x25))
289 "2.5s" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x26))
290 "3s" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x27))
291 "4s" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x28))
292 "5s" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x29))
293 "6s" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x2a))
294 "8s" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x2b))
295 "10s" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x2c))
296 "13s" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x2d))
297 "15s" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x2e))
298 "20s" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x2f))
299 "25s" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x30))
300 "30s" -> commandPublisher.enqueueCommand(PixproChangeShutterSpeed(PixproCommandOnlyCallback(), 0x31))
311 private fun setMeteringMode(value: String)
315 if (!::commandPublisher.isInitialized)
320 Log.v(TAG, " setMeteringMode($value)")
323 "4608x3456" -> commandPublisher.enqueueCommand(PixproChangeImageSize(PixproCommandOnlyCallback(), 0x00010000)) // 4608x3456
324 "4608x3072" -> commandPublisher.enqueueCommand(PixproChangeImageSize(PixproCommandOnlyCallback(), 0x00004000)) // 4608x3072
325 "4608x2592" -> commandPublisher.enqueueCommand(PixproChangeImageSize(PixproCommandOnlyCallback(), 0x00001000)) // 4608x2592
326 "3648x2736" -> commandPublisher.enqueueCommand(PixproChangeImageSize(PixproCommandOnlyCallback(), 0x00000400)) // 3648x2736
327 "2592x1944" -> commandPublisher.enqueueCommand(PixproChangeImageSize(PixproCommandOnlyCallback(), 0x00000020)) // 2592x1944
328 "2048x1536" -> commandPublisher.enqueueCommand(PixproChangeImageSize(PixproCommandOnlyCallback(), 0x00000008)) // 2048x1536
329 "1920x1080" -> commandPublisher.enqueueCommand(PixproChangeImageSize(PixproCommandOnlyCallback(), 0x00000004)) // 1920x1080
330 "640x480" -> commandPublisher.enqueueCommand(PixproChangeImageSize(PixproCommandOnlyCallback(), 0x00000001)) // 640x480
331 "1280x720 30p" -> commandPublisher.enqueueCommand(PixproChangeVideoSize(PixproCommandOnlyCallback(), 0x00040000)) // 1280x720 30p
332 "640x480 30p" -> commandPublisher.enqueueCommand(PixproChangeVideoSize(PixproCommandOnlyCallback(), 0x00000040)) // 640x480 30p
333 "640x480 120p" -> commandPublisher.enqueueCommand(PixproChangeVideoSize(PixproCommandOnlyCallback(), 0x00000100)) // 640x480 120p
334 "1920×1080 30p" -> commandPublisher.enqueueCommand(PixproChangeVideoSize(PixproCommandOnlyCallback(), 0x00400000)) // 1920x1080 30p
335 "1280x720 60p" -> commandPublisher.enqueueCommand(PixproChangeVideoSize(PixproCommandOnlyCallback(), 0x00080000)) // 1280x720 60p
346 private fun setIsoSensitivity(value: String)
350 if (!::commandPublisher.isInitialized)
355 Log.v(TAG, " setIsoSensitivity($value)")
358 "AUTO" -> commandPublisher.enqueueCommand(PixproChangeIsoSensitivity(PixproCommandOnlyCallback(), 0x00))
359 "100" -> commandPublisher.enqueueCommand(PixproChangeIsoSensitivity(PixproCommandOnlyCallback(), 0x01))
360 "200" -> commandPublisher.enqueueCommand(PixproChangeIsoSensitivity(PixproCommandOnlyCallback(), 0x02))
361 "400" -> commandPublisher.enqueueCommand(PixproChangeIsoSensitivity(PixproCommandOnlyCallback(), 0x03))
362 "800" -> commandPublisher.enqueueCommand(PixproChangeIsoSensitivity(PixproCommandOnlyCallback(), 0x04))
363 "1600" -> commandPublisher.enqueueCommand(PixproChangeIsoSensitivity(PixproCommandOnlyCallback(), 0x05))
364 "3200" -> commandPublisher.enqueueCommand(PixproChangeIsoSensitivity(PixproCommandOnlyCallback(), 0x06))
374 private fun setExpRev(value: String)
378 if (!::commandPublisher.isInitialized)
383 Log.v(TAG, " setExpRev($value)")
386 "-3.0" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x00))
387 "-2.7" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x01))
388 "-2.3" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x02))
389 "-2.0" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x03))
390 "-1.7" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x04))
391 "-1.3" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x05))
392 "-1.0" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x06))
393 "-0.7" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x07))
394 "-0.3" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x08))
395 "0.0" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x09))
396 "+0.3" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x0a))
397 "+0.7" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x0b))
398 "+1.0" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x0c))
399 "+1.3" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x0d))
400 "+1.7" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x0e))
401 "+2.0" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x0f))
402 "+2.3" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x10))
403 "+2.7" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x11))
404 "+3.0" -> commandPublisher.enqueueCommand(PixproChangeExposureCompensation(PixproCommandOnlyCallback(), 0x12))
414 private fun setWhiteBalance(value: String)
418 if (!::commandPublisher.isInitialized)
423 Log.v(TAG, " setWhiteBalance($value)")
426 "AUTO" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x01))
427 "Daylight" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x02))
428 "Cloudy" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x04))
429 "Fluorescent" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x10))
430 "Fluorescent CWF" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x20)) //
431 "Incandescent" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x80)) //
432 "Unknown" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x40)) //
433 "Other" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x08)) // 不明...
443 private fun setPictureEffect(value: String)
447 if (!::commandPublisher.isInitialized)
452 Log.v(TAG, " setPictureEffect($value)")
455 "(+) Zoom In" -> commandPublisher.enqueueCommand(PixproExecuteZoom(PixproCommandOnlyCallback(), 1))
456 "(-) Zoom Out" -> commandPublisher.enqueueCommand(PixproExecuteZoom(PixproCommandOnlyCallback(), -1))
467 private fun setTorchMode(value: String)
471 if (!::commandPublisher.isInitialized)
476 Log.v(TAG, " setTorchMode($value)")
479 "OFF" -> commandPublisher.enqueueCommand(PixproFlashOff(PixproCommandOnlyCallback()))
480 "ON" -> commandPublisher.enqueueCommand(PixproFlashOn(PixproCommandOnlyCallback()))
481 "AUTO" -> commandPublisher.enqueueCommand(PixproFlashAuto(PixproCommandOnlyCallback()))