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.ICameraStatusUpdateNotify
6 import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus
7 import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatusWatcher
8 import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.IPixproCommandPublisher
9 import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.IPixproCommandCallback
10 import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.specific.PixproStatusRequest
11 import jp.osdn.gokigen.gokigenassets.liveview.message.IMessageDrawer
12 import jp.osdn.gokigen.gokigenassets.utils.communication.SimpleLogDumper
13 import java.lang.Exception
15 class PixproStatusChecker : IPixproCommandCallback, ICameraStatusWatcher, ICameraStatus
17 private val statusHolder = PixproStatusHolder()
18 private var whileFetching = false
19 private var notifier: ICameraStatusUpdateNotify? = null
20 private var pollDuration: Int = EVENT_POLL_QUEUE_MS
21 private lateinit var commandPublisher : IPixproCommandPublisher
23 fun setCommandPublisher(commandPublisher : IPixproCommandPublisher)
25 this.commandPublisher = commandPublisher
26 statusHolder.setCommandPublisher(commandPublisher)
29 override fun getStatusList(key: String): List<String?>
33 return (statusHolder.getAvailableItemList(key))
42 override fun getStatus(key: String): String
46 return (statusHolder.getItemStatus(key))
55 override fun getStatusColor(key: String): Int
59 return (statusHolder.getItemStatusColor(key))
68 override fun setStatus(key: String, value: String)
70 Log.v(TAG, "setStatus($key, $value)")
73 return (statusHolder.setItemStatus(key, value))
81 override fun startStatusWatch(indicator: IMessageDrawer?, notifier: ICameraStatusUpdateNotify?)
85 Log.v(TAG, "startStatusWatch() already starting.")
90 this.notifier = notifier
98 Thread.sleep(pollDuration.toLong())
100 Log.v(TAG, " === POLL EVENT === ")
101 if (::commandPublisher.isInitialized)
103 commandPublisher.enqueueCommand(PixproStatusRequest(this))
127 override fun stopStatusWatch()
129 Log.v(TAG, "stopStatusWatch()")
130 whileFetching = false
134 override fun receivedMessage(id: Int, rx_body: ByteArray?)
138 Log.v(TAG, " RECEIVED EVENT : ${rx_body?.size} bytes.")
139 SimpleLogDumper.dumpBytes("EVT[${rx_body?.size}]", rx_body)
143 val length = rx_body?.size ?: 0
147 val takeMode = when (val take0 = rx_body?.get(16 * 136 + 8))
151 0x06.toByte() -> "ASCN"
152 0x07.toByte() -> "Video"
153 0x0c.toByte() -> "Cont."
156 statusHolder.updateValue(ICameraStatus.TAKE_MODE, takeMode)
159 val flashMode = when (val flash0 = rx_body?.get(16 * 127 + 8))
161 0x01.toByte() -> "OFF"
162 0x02.toByte() -> "AUTO"
163 0x04.toByte() -> "ON"
166 statusHolder.updateValue(ICameraStatus.TORCH_MODE, flashMode)
169 val whiteBalance = when (val wb0 = rx_body?.get(16 * 125 + 8))
171 0x01.toByte() -> "AUTO"
172 0x02.toByte() -> "Daylight"
173 0x04.toByte() -> "Cloudy"
174 0x10.toByte() -> "Fluorescent"
175 0x20.toByte() -> "Fluorescent CWF"
176 0x80.toByte() -> "Incandescent"
179 statusHolder.updateValue(ICameraStatus.WHITE_BALANCE, whiteBalance)
182 val isoSensitivity = when (val iso0 = rx_body?.get(16 * 70 + 0))
184 0x00.toByte() -> "Auto"
185 0x01.toByte() -> "100"
186 0x02.toByte() -> "200"
187 0x03.toByte() -> "400"
188 0x04.toByte() -> "800"
189 0x05.toByte() -> "1600"
190 0x06.toByte() -> "3200"
193 statusHolder.updateValue(ICameraStatus.ISO_SENSITIVITY, isoSensitivity)
195 // EXPOSURE Compensation
196 val exposureCompensation = when (val exprev0 = rx_body?.get(16 * 61 + 0))
198 0x00.toByte() -> "-3.0"
199 0x01.toByte() -> "-2.7"
200 0x02.toByte() -> "-2.3"
201 0x03.toByte() -> "-2.0"
202 0x04.toByte() -> "-1.7"
203 0x05.toByte() -> "-1.3"
204 0x06.toByte() -> "-1.0"
205 0x07.toByte() -> "-0.7"
206 0x08.toByte() -> "-0.3"
207 0x09.toByte() -> "0.0"
208 0x0a.toByte() -> "+0.3"
209 0x0b.toByte() -> "+0.7"
210 0x0c.toByte() -> "+1.0"
211 0x0d.toByte() -> "+1.3"
212 0x0e.toByte() -> "+1.7"
213 0x0f.toByte() -> "+2.0"
214 0x10.toByte() -> "+2.3"
215 0x11.toByte() -> "+2.7"
216 0x12.toByte() -> "+3.0"
220 statusHolder.updateValue(ICameraStatus.EXPREV, exposureCompensation)
223 val shutterSpeed = when (val sv = rx_body?.get(16 * 75 + 8))
225 0x01.toByte() -> "1/2000"
226 0x02.toByte() -> "1/1600"
227 0x03.toByte() -> "1/1200"
228 0x04.toByte() -> "1/1000"
229 0x05.toByte() -> "1/800"
230 0x06.toByte() -> "1/600"
231 0x07.toByte() -> "1/500"
232 0x08.toByte() -> "1/400"
233 0x09.toByte() -> "1/320"
234 0x0a.toByte() -> "1/250"
235 0x0b.toByte() -> "1/200"
236 0x0c.toByte() -> "1/160"
237 0x0d.toByte() -> "1/125"
238 0x0e.toByte() -> "1/100"
239 0x0f.toByte() -> "1/80"
240 0x10.toByte() -> "1/60"
241 0x11.toByte() -> "1/50"
242 0x12.toByte() -> "1/40"
243 0x13.toByte() -> "1/30"
244 0x14.toByte() -> "1/25"
245 0x15.toByte() -> "1/20"
246 0x16.toByte() -> "1/15"
247 0x17.toByte() -> "1/13"
248 0x18.toByte() -> "1/10"
249 0x19.toByte() -> "1/8"
250 0x1a.toByte() -> "1/6"
251 0x1b.toByte() -> "1/5"
252 0x1c.toByte() -> "1/4"
253 0x1d.toByte() -> "1/3"
254 0x1e.toByte() -> "1/2.5"
255 0x1f.toByte() -> "1/2"
256 0x20.toByte() -> "1/1.6"
257 0x21.toByte() -> "1/1.3"
258 0x22.toByte() -> "1s"
259 0x23.toByte() -> "1.3s"
260 0x24.toByte() -> "1.5s"
261 0x25.toByte() -> "2s"
262 0x26.toByte() -> "2.5s"
263 0x27.toByte() -> "3s"
264 0x28.toByte() -> "4s"
265 0x29.toByte() -> "5s"
266 0x2a.toByte() -> "6s"
267 0x2b.toByte() -> "8s"
268 0x2c.toByte() -> "10s"
269 0x2d.toByte() -> "13s"
270 0x2e.toByte() -> "15s"
271 0x2f.toByte() -> "20s"
272 0x30.toByte() -> "25s"
273 0x31.toByte() -> "30s"
277 statusHolder.updateValue(ICameraStatus.SHUTTER_SPEED, shutterSpeed)
280 val imageSize = when (val picSize = (rx_body?.get(16 * 129 + 8) ?: 0).toInt() + (rx_body?.get(16 * 129 + 9) ?: 0) * 256 + ((rx_body?.get(16 * 129 + 10) ?: 0) * 65536) + ((rx_body?.get(16 * 129 + 11) ?: 0) * 16777216))
282 0x00010000 -> "4608x3456"
283 0x00004000 -> "4608x3072"
284 0x00001000 -> "4608x2592"
285 0x00000400 -> "3648x2736"
286 0x00000020 -> "2592x1944"
287 0x00000008 -> "2048x1536"
288 0x00000004 -> "1920x1080"
289 0x00000001 -> "640x480"
292 statusHolder.updateValue(ICameraStatus.IMAGE_SIZE, imageSize)
295 val movieSize = when (val videoSize = (rx_body?.get(16 * 132 + 0) ?: 0).toInt() + (rx_body?.get(16 * 132 + 1) ?: 0) * 256 + ((rx_body?.get(16 * 132 + 2) ?: 0) * 65536) + ((rx_body?.get(16 * 132 + 3) ?: 0) * 16777216))
297 0x00400000 -> "1920×1080 30p"
298 0x00080000 -> "1280x720 60p"
299 0x00040000 -> "1280x720 30p"
300 0x00000100 -> "640x480 120p"
301 0x00000040 -> "640x480 30p"
302 else -> "[$videoSize]"
304 statusHolder.updateValue(ICameraStatus.MOVIE_SIZE, movieSize)
316 private val TAG = PixproStatusChecker::class.java.simpleName
317 private const val EVENT_POLL_QUEUE_MS = 550 // 550ms
318 private const val isDumpLog = false