OSDN Git Service

75b8bbe154f38412d013c5a442765f158e7e7bd7
[gokigen/Gr2Control.git] / app / src / main / java / net / osdn / gokigen / gr2control / camera / fuji_x / wrapper / FujiXStatusHolder.java
1 package net.osdn.gokigen.gr2control.camera.fuji_x.wrapper;
2
3 import android.util.Log;
4 import android.util.SparseIntArray;
5
6 import androidx.annotation.NonNull;
7 import androidx.annotation.Nullable;
8 import androidx.collection.SparseArrayCompat;
9 import androidx.fragment.app.FragmentActivity;
10
11 import net.osdn.gokigen.gr2control.R;
12 import net.osdn.gokigen.gr2control.camera.ICameraStatus;
13 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.FujiXReplyMessageReceiver;
14 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.IFujiXCommandPublisher;
15 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.messages.SetPropertyValue;
16 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXBatteryMode;
17 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXCameraProperties;
18 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXFSSControl;
19 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXFilmSimulation;
20 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXFlashMode;
21 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXFocusingMode;
22 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXImageAspectMode;
23 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXImageFormatMode;
24 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXShootingMode;
25 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXTimerMode;
26 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXWhiteBalanceMode;
27 import net.osdn.gokigen.gr2control.liveview.ICameraStatusUpdateNotify;
28
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Locale;
32
33 class FujiXStatusHolder
34 {
35     private final String TAG = toString();
36     private final FragmentActivity activity;
37     private final IFujiXCommandPublisher publisher;
38     private static final boolean logcat = true;
39     private SparseIntArray statusHolder;
40     private SparseArrayCompat<String> statusNameArray;
41
42     FujiXStatusHolder(@NonNull FragmentActivity activity, @NonNull IFujiXCommandPublisher publisher)
43     {
44         statusHolder = new SparseIntArray();
45         statusHolder.clear();
46
47         this.activity = activity;
48         this.publisher = publisher;
49         statusNameArray = new SparseArrayCompat<>();
50         prepareStatusNameArray();
51     }
52
53     private void prepareStatusNameArray()
54     {
55         statusNameArray.clear();
56         statusNameArray.append(IFujiXCameraProperties.BATTERY_LEVEL, IFujiXCameraProperties.BATTERY_LEVEL_STR);
57         statusNameArray.append(IFujiXCameraProperties.WHITE_BALANCE, IFujiXCameraProperties.WHITE_BALANCE_STR);
58         statusNameArray.append(IFujiXCameraProperties.APERTURE, IFujiXCameraProperties.APERTURE_STR);
59         statusNameArray.append(IFujiXCameraProperties.FOCUS_MODE, IFujiXCameraProperties.FOCUS_MODE_STR);
60         statusNameArray.append(IFujiXCameraProperties.SHOOTING_MODE, IFujiXCameraProperties.SHOOTING_MODE_STR);
61         statusNameArray.append(IFujiXCameraProperties.FLASH, IFujiXCameraProperties.FLASH_STR);
62         statusNameArray.append(IFujiXCameraProperties.EXPOSURE_COMPENSATION, IFujiXCameraProperties.EXPOSURE_COMPENSATION_STR);
63         statusNameArray.append(IFujiXCameraProperties.SELF_TIMER, IFujiXCameraProperties.SELF_TIMER_STR);
64         statusNameArray.append(IFujiXCameraProperties.FILM_SIMULATION, IFujiXCameraProperties.FILM_SIMULATION_STR);
65         statusNameArray.append(IFujiXCameraProperties.IMAGE_FORMAT, IFujiXCameraProperties.IMAGE_FORMAT_STR);
66         statusNameArray.append(IFujiXCameraProperties.RECMODE_ENABLE, IFujiXCameraProperties.RECMODE_ENABLE_STR);
67         statusNameArray.append(IFujiXCameraProperties.F_SS_CONTROL, IFujiXCameraProperties.F_SS_CONTROL_STR);
68         statusNameArray.append(IFujiXCameraProperties.ISO, IFujiXCameraProperties.ISO_STR);
69         statusNameArray.append(IFujiXCameraProperties.MOVIE_ISO, IFujiXCameraProperties.MOVIE_ISO_STR);
70         statusNameArray.append(IFujiXCameraProperties.FOCUS_POINT, IFujiXCameraProperties.FOCUS_POINT_STR);
71         statusNameArray.append(IFujiXCameraProperties.DEVICE_ERROR, IFujiXCameraProperties.DEVICE_ERROR_STR);
72         statusNameArray.append(IFujiXCameraProperties.IMAGE_FILE_COUNT, IFujiXCameraProperties.IMAGE_FILE_COUNT_STR);
73         statusNameArray.append(IFujiXCameraProperties.SDCARD_REMAIN_SIZE, IFujiXCameraProperties.SDCARD_REMAIN_SIZE_STR);
74         statusNameArray.append(IFujiXCameraProperties.FOCUS_LOCK, IFujiXCameraProperties.FOCUS_LOCK_STR);
75         statusNameArray.append(IFujiXCameraProperties.MOVIE_REMAINING_TIME, IFujiXCameraProperties.MOVIE_REMAINING_TIME_STR);
76         statusNameArray.append(IFujiXCameraProperties.SHUTTER_SPEED, IFujiXCameraProperties.SHUTTER_SPEED_STR);
77         statusNameArray.append(IFujiXCameraProperties.IMAGE_ASPECT, IFujiXCameraProperties.IMAGE_ASPECT_STR);
78         statusNameArray.append(IFujiXCameraProperties.BATTERY_LEVEL_2, IFujiXCameraProperties.BATTERY_LEVEL_2_STR);
79         statusNameArray.append(IFujiXCameraProperties.UNKNOWN_DF00, IFujiXCameraProperties.UNKNOWN_DF00_STR);
80         statusNameArray.append(IFujiXCameraProperties.PICTURE_JPEG_COUNT, IFujiXCameraProperties.PICTURE_JPEG_COUNT_STR);
81         statusNameArray.append(IFujiXCameraProperties.UNKNOWN_D400, IFujiXCameraProperties.UNKNOWN_D400_STR);
82         statusNameArray.append(IFujiXCameraProperties.UNKNOWN_D401, IFujiXCameraProperties.UNKNOWN_D401_STR);
83         statusNameArray.append(IFujiXCameraProperties.UNKNOWN_D52F, IFujiXCameraProperties.UNKNOWN_D52F_STR);
84         statusNameArray.append(IFujiXCameraProperties.UNKNOWN_D245, IFujiXCameraProperties.UNKNOWN_D245_STR);
85         statusNameArray.append(IFujiXCameraProperties.UNKNOWN_DF41, IFujiXCameraProperties.UNKNOWN_DF41_STR);
86         statusNameArray.append(IFujiXCameraProperties.UNKNOWN_DF26, IFujiXCameraProperties.UNKNOWN_DF26_STR);
87         statusNameArray.append(IFujiXCameraProperties.UNKNOWN_DF27, IFujiXCameraProperties.UNKNOWN_DF27_STR);
88     }
89
90     void updateValue(@Nullable ICameraStatusUpdateNotify notifier, int id, byte data0, byte data1, byte data2, byte data3)
91     {
92         try
93         {
94             int value = ((((int) data3) & 0xff) << 24) + ((((int) data2) & 0xff) << 16) + ((((int) data1) & 0xff) << 8) + (((int) data0) & 0xff);
95             int currentValue = statusHolder.get(id, -1);
96             //logcat(String.format(Locale.US, " STATUS [id: 0x%04x] 0x%08x(%d) -> 0x%08x(%d)", id, currentValue, currentValue, value, value));
97             if ((notifier != null) && (currentValue != value))
98             {
99                 statusHolder.put(id, value);
100                 //logcat(String.format(Locale.US," STATUS UPDATE [id: 0x%04x] 0x%08x(%d) -> 0x%08x(%d)", id, currentValue, currentValue, value, value));
101                 updateDetected(notifier, id, currentValue, value);
102             }
103         }
104         catch (Exception e)
105         {
106             e.printStackTrace();
107         }
108     }
109
110     private void updateDetected(@NonNull ICameraStatusUpdateNotify notifier, int id, int previous, int current)
111     {
112         try
113         {
114             //String idName = statusNameArray.get(id, "Unknown");
115             //logcat(String.format(Locale.US, " << UPDATE STATUS >> id: 0x%04x[%s] 0x%08x(%d) -> 0x%08x(%d)", id, idName, previous, previous, current, current));
116             switch (id)
117             {
118                 case IFujiXCameraProperties.FOCUS_LOCK:
119                     updateFocusedStatus(notifier, previous, current);
120                     break;
121                 case IFujiXCameraProperties.SHOOTING_MODE:
122                     updatedTakeMode(notifier, previous, current);
123                     break;
124                 case IFujiXCameraProperties.BATTERY_LEVEL:
125                 case IFujiXCameraProperties.BATTERY_LEVEL_2:
126                     updateBatteryLevel(notifier, previous, current);
127                     break;
128                 case IFujiXCameraProperties.FOCUS_MODE:
129                     updateFocusMode(notifier, previous, current);
130                     break;
131                 case IFujiXCameraProperties.APERTURE:
132                     updateAperture(notifier, previous, current);
133                     break;
134                 case IFujiXCameraProperties.SHUTTER_SPEED:
135                     updateShutterSpeed(notifier, previous, current);
136                     break;
137                 case IFujiXCameraProperties.WHITE_BALANCE:
138                     updateWhiteBalance(notifier, previous, current);
139                     break;
140                 case IFujiXCameraProperties.EXPOSURE_COMPENSATION:
141                     updateExposureCompensation(notifier, previous, current);
142                     break;
143                 case IFujiXCameraProperties.ISO:
144                     updateIsoSensitivity(notifier, previous, current);
145                     break;
146                 case IFujiXCameraProperties.DEVICE_ERROR:
147                     updateDeviceError(notifier, previous, current);
148                     break;
149                 case IFujiXCameraProperties.SELF_TIMER:
150                     updateSelfTimer(notifier, previous, current);
151                     break;
152                 case IFujiXCameraProperties.SDCARD_REMAIN_SIZE:
153                     updateSdCardRemainSize(notifier, previous, current);
154                     break;
155                 case IFujiXCameraProperties.MOVIE_REMAINING_TIME:
156                     updateMovieRemainTime(notifier, previous, current);
157                     break;
158                 case IFujiXCameraProperties.FOCUS_POINT:
159                     updateFocusPoint(notifier, previous, current);
160                     break;
161                 case IFujiXCameraProperties.F_SS_CONTROL:
162                     updateFSSControl(notifier, previous, current);
163                     break;
164                 case IFujiXCameraProperties.IMAGE_ASPECT:
165                     updateImageAspect(notifier, previous, current);
166                     break;
167                 case IFujiXCameraProperties.FILM_SIMULATION:
168                     updateFilmSimulation(notifier, previous, current);
169                     break;
170                 case IFujiXCameraProperties.FLASH:
171                     updateFlashMode(notifier, previous, current);
172                     break;
173                 case IFujiXCameraProperties.IMAGE_FORMAT:
174                     updateImageFormat(notifier, previous, current);
175                     break;
176                 case IFujiXCameraProperties.UNKNOWN_D245:
177                 case IFujiXCameraProperties.UNKNOWN_DF41:
178                 case IFujiXCameraProperties.UNKNOWN_DF26:
179                 case IFujiXCameraProperties.UNKNOWN_DF27:
180                 default:
181                     updateUnknownValue(id, previous, current);
182                     break;
183             }
184         }
185         catch (Exception e)
186         {
187             e.printStackTrace();
188         }
189     }
190
191     private void updateImageFormat(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
192     {
193         String value;
194         switch (current)
195         {
196             case IFujiXImageFormatMode.IMAGE_FORMAT_RAW:
197                 value = "RAW";
198                 break;
199             case IFujiXImageFormatMode.IMAGE_FORMAT_FINE:
200                 value = "FINE";
201                 break;
202             case IFujiXImageFormatMode.IMAGE_FORMAT_NORMAL:
203                 value = "NORMAL";
204                 break;
205             case IFujiXImageFormatMode.IMAGE_FORMAT_FINE_RAW:
206                 value = "RAW+F";
207                 break;
208             case IFujiXImageFormatMode.IMAGE_FORMAT_NORMAL_RAW:
209                 value = "RAW+N";
210                 break;
211             default:
212                 value = "UNKNOWN : " + current;
213                 break;
214         }
215         logcat(" Image Format : " + value);
216     }
217
218     private void updateFlashMode(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
219     {
220         String value;
221         switch (current)
222         {
223             case IFujiXFlashMode.FLASH_AUTO:
224                 value = "AUTO";
225                 break;
226             case IFujiXFlashMode.FLASH_OFF:
227                 value = "OFF";
228                 break;
229             case IFujiXFlashMode.FLASH_FILL:
230                 value = "FILL";
231                 break;
232             case IFujiXFlashMode.FLASH_REDEYE_AUTO:
233                 value = "REDEYE_AUTO";
234                 break;
235             case IFujiXFlashMode.FLASH_REDEYE_FILL:
236                 value = "REDEYE_FILL";
237                 break;
238             case IFujiXFlashMode.FLASH_EXTERNAL_SYNC:
239                 value = "EXTERNAL_SYNC";
240                 break;
241             case IFujiXFlashMode.FLASH_ON:
242                 value = "ON";
243                 break;
244             case IFujiXFlashMode.FLASH_REDEYE:
245                 value = "REDEYE";
246                 break;
247             case IFujiXFlashMode.FLASH_REDEYE_ON:
248                 value = "REDEYE_ON";
249                 break;
250             case IFujiXFlashMode.FLASH_REDEYE_SYNC:
251                 value = "REDEYE_SYNC";
252                 break;
253             case IFujiXFlashMode.FLASH_REDEYE_REAR:
254                 value = "REDEYE_REAR";
255                 break;
256             case IFujiXFlashMode.FLASH_SLOW_SYNC:
257                 value = "SLOW_SYNC";
258                 break;
259             case IFujiXFlashMode.FLASH_REAR_SYNC:
260                 value = "REAR_SYNC";
261                 break;
262             case IFujiXFlashMode.FLASH_COMMANDER:
263                 value = "COMMANDER";
264                 break;
265             case IFujiXFlashMode.FLASH_DISABLE:
266                 value = "DISABLE";
267                 break;
268             case IFujiXFlashMode.FLASH_ENABLE:
269                 value = "ENABLE";
270                 break;
271             default:
272                 value = " UNKNOWN : " + current;
273                 break;
274         }
275         logcat(" FLASH MODE : " + value);
276     }
277
278     private void updateFilmSimulation(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
279     {
280         String value;
281         switch (current)
282         {
283             case IFujiXFilmSimulation.FILM_SIMULATION_PROVIA:
284                 value = IFujiXFilmSimulation.FILM_SIMULATION_PROVIA_STR;
285                 break;
286             case IFujiXFilmSimulation.FILM_SIMULATION_VELVIA:
287                 value = IFujiXFilmSimulation.FILM_SIMULATION_VELVIA_STR;
288                 break;
289             case IFujiXFilmSimulation.FILM_SIMULATION_ASTIA:
290                 value = IFujiXFilmSimulation.FILM_SIMULATION_ASTIA_STR;
291                 break;
292             case IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME:
293                 value = IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_STR;
294                 break;
295             case IFujiXFilmSimulation.FILM_SIMULATION_SEPIA:
296                 value = IFujiXFilmSimulation.FILM_SIMULATION_SEPIA_STR;
297                 break;
298             case IFujiXFilmSimulation.FILM_SIMULATION_PRO_NEG_HI:
299                 value = IFujiXFilmSimulation.FILM_SIMULATION_PRO_NEG_HI_STR;
300                 break;
301             case IFujiXFilmSimulation.FILM_SIMULATION_PRO_NEG_STD:
302                 value = IFujiXFilmSimulation.FILM_SIMULATION_PRO_NEG_STD_STR;
303                 break;
304             case IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_Y_FILTER:
305                 value = IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_Y_FILTER_STR;
306                 break;
307             case IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_R_FILTER:
308                 value = IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_R_FILTER_STR;
309                 break;
310             case IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_G_FILTER:
311                 value = IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_G_FILTER_STR;
312                 break;
313             case IFujiXFilmSimulation.FILM_SIMULATION_CLASSIC_CHROME:
314                 value = IFujiXFilmSimulation.FILM_SIMULATION_CLASSIC_CHROME_STR;
315                 break;
316             case IFujiXFilmSimulation.FILM_SIMULATION_ACROS:
317                 value = IFujiXFilmSimulation.FILM_SIMULATION_ACROS_STR;
318                 break;
319             case IFujiXFilmSimulation.FILM_SIMULATION_ACROS_Y:
320                 value = IFujiXFilmSimulation.FILM_SIMULATION_ACROS_Y_STR;
321                 break;
322             case IFujiXFilmSimulation.FILM_SIMULATION_ACROS_R:
323                 value = IFujiXFilmSimulation.FILM_SIMULATION_ACROS_R_STR;
324                 break;
325             case IFujiXFilmSimulation.FILM_SIMULATION_ACROS_G:
326                 value = IFujiXFilmSimulation.FILM_SIMULATION_ACROS_G_STR;
327                 break;
328             case IFujiXFilmSimulation.FILM_SIMULATION_ETERNA:
329                 value = IFujiXFilmSimulation.FILM_SIMULATION_ETERNA_STR;
330                 break;
331             case IFujiXFilmSimulation.FILM_SIMULATION_CLASSIC_NEGATIVE:
332                 value = IFujiXFilmSimulation.FILM_SIMULATION_CLASSIC_NEGATIVE_STR;
333                 break;
334             case IFujiXFilmSimulation.FILM_SIMULATION_ETERNA_BLEACH_BYPASS:
335                 value = IFujiXFilmSimulation.FILM_SIMULATION_ETERNA_BLEACH_BYPASS_STR;
336                 break;
337             default:
338                 value = "??? " + current;
339                 break;
340         }
341         logcat(" FILM SIMULATION : " + value);
342     }
343
344     private void updateImageAspect(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
345     {
346         String value;
347         switch (current)
348         {
349             case IFujiXImageAspectMode.IMAGE_ASPECT_S_3x2:
350               value = "S:3x2";
351               break;
352             case IFujiXImageAspectMode.IMAGE_ASPECT_S_16x9:
353               value = "S:16x9";
354               break;
355             case IFujiXImageAspectMode.IMAGE_ASPECT_S_1x1:
356               value = "S:1x1";
357               break;
358             case IFujiXImageAspectMode.IMAGE_ASPECT_M_3x2:
359                 value = "M:3x2";
360                 break;
361             case IFujiXImageAspectMode.IMAGE_ASPECT_M_16x9:
362                 value = "M:16x9";
363                 break;
364             case IFujiXImageAspectMode.IMAGE_ASPECT_M_1x1:
365                 value = "M:1x1";
366                 break;
367             case IFujiXImageAspectMode.IMAGE_ASPECT_L_3x2:
368                 value = "L:3x2";
369                 break;
370             case IFujiXImageAspectMode.IMAGE_ASPECT_L_16x9:
371                 value = "L:16x9";
372                 break;
373             case IFujiXImageAspectMode.IMAGE_ASPECT_L_1x1:
374                 value = "L:1x1";
375                 break;
376             default:
377                 value = "? " + current;
378                 break;
379         }
380         logcat(" Image Aspect : " + value);
381     }
382
383
384     private void updateFSSControl(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
385     {
386         String value;
387         switch (current)
388         {
389             case IFujiXFSSControl.F_SS_CTRL_BOTH:
390                 value = "BOTH";
391                 break;
392             case IFujiXFSSControl.F_SS_CTRL_F:
393                 value = "F";
394                 break;
395             case IFujiXFSSControl.F_SS_CTRL_SS:
396                 value = "SS";
397                 break;
398             case IFujiXFSSControl.F_SS_CTRL_NONE:
399                 value = "NONE";
400                 break;
401             default:
402                 value = "? " + current;
403                 break;
404         }
405         logcat(" F_SS : " + value);
406     }
407
408     private void updateUnknownValue(int id, int previous, int current)
409     {
410         logcat(String.format(Locale.US,"<< UPDATE UNKNOWN STATUS >> id: 0x%04x 0x%08x(%d) -> 0x%08x(%d)", id, previous, previous, current, current));
411     }
412
413     private void updateFocusPoint(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
414     {
415         logcat(String.format(Locale.ENGLISH, " Focus Point : %x ", current));
416     }
417
418     private void updateMovieRemainTime(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
419     {
420         logcat(" MOVIE REMAIN : " + current);
421     }
422
423     private void updateSdCardRemainSize(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
424     {
425         logcat(" SDCARD REMAIN : " + current);
426     }
427
428     private void updateSelfTimer(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
429     {
430         int value = -1;
431         try
432         {
433             switch (current)
434             {
435                 case IFujiXTimerMode.TIMER_OFF:
436                     value = 0;
437                     break;
438
439                 case IFujiXTimerMode.TIMER_1SEC:
440                     value = 1;
441                     break;
442
443                 case IFujiXTimerMode.TIMER_2SEC:
444                     value = 2;
445                     break;
446
447                 case IFujiXTimerMode.TIMER_5SEC:
448                     value = 5;
449                     break;
450
451                 case IFujiXTimerMode.TIMER_10SEC:
452                     value = 10;
453                     break;
454
455                 default:
456                     break;
457             }
458         }
459         catch (Exception e)
460         {
461             e.printStackTrace();
462         }
463         if (value <= 0)
464         {
465             logcat(" SELF TIMER IS OFF (" + value + ")");
466         }
467         else
468         {
469             logcat(" SELF TIMER IS " + value + " sec.");
470         }
471     }
472
473     private void updateDeviceError(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
474     {
475         if (current != 0)
476         {
477             notifier.updateWarning("ERROR " + current);
478         }
479     }
480
481     private void updateIsoSensitivity(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
482     {
483         String iso = "";
484         try
485         {
486             int isoValue = (0x0000ffff & current);
487             if ((0xffff0000 & current) != 0)
488             {
489                 iso = "AUTO_" + isoValue;
490             }
491             else if (isoValue > 12800)
492             {
493                 iso = "H" + isoValue;
494
495             }
496             else if (isoValue < 200)
497             {
498                 iso = "L" + isoValue;
499             }
500             else
501             {
502                 iso = "" + isoValue;
503             }
504         }
505         catch (Exception e)
506         {
507             e.printStackTrace();
508         }
509         logcat(" ISO SENSITIVITY : " + iso);
510         notifier.updateIsoSensitivity(iso);
511     }
512
513     private void updateExposureCompensation(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
514     {
515         String exposureCompensation = "";
516         try
517         {
518             float value = ((float) current / 1000.0f);
519             exposureCompensation = String.format(Locale.ENGLISH, "%+1.1f", value);
520         }
521         catch (Exception e)
522         {
523             e.printStackTrace();
524         }
525         notifier.updatedExposureCompensation(exposureCompensation);
526     }
527
528     private void updateWhiteBalance(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
529     {
530         String value = "";
531         try
532         {
533             switch (current)
534             {
535                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_AUTO:
536                     value = "Auto";
537                     break;
538                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_FINE:
539                     value = "Fine";
540                     break;
541                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_INCANDESCENT:
542                     value = "Incandescent";
543                     break;
544                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_FLUORESCENT_1:
545                     value = "Fluorescent 1";
546                     break;
547                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_FLUORESCENT_2:
548                     value = "Fluorescent 2";
549                     break;
550                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_FLUORESCENT_3:
551                     value = "Fluorescent 3";
552                     break;
553                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_SHADE:
554                     value = "Shade";
555                     break;
556                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_UNDERWATER:
557                     value = "Underwater";
558                     break;
559                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_TEMPERATURE:
560                     value = "Kelvin";
561                     break;
562                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_CUSTOM:
563                     value = "Custom";
564                     break;
565                 default:
566                     value = "Unknown";
567                     break;
568             }
569         }
570         catch (Exception e)
571         {
572             e.printStackTrace();
573         }
574         notifier.updatedWBMode(value);
575     }
576
577     private void updateShutterSpeed(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
578     {
579         String shutterSpeed = "--";
580         try
581         {
582             if ((0x80000000 & current) != 0)
583             {
584                 int value = 0x0fffffff & current;
585                 shutterSpeed = ("1/" + (value / 1000));
586             }
587             else
588             {
589                 shutterSpeed = (current + "");
590             }
591         }
592         catch (Exception e)
593         {
594             e.printStackTrace();
595         }
596         notifier.updatedShutterSpeed(shutterSpeed);
597     }
598
599     private void updateAperture(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
600     {
601         String aperature = "---";
602         try
603         {
604             float value = ((float) current / 100.0f);
605             aperature = String.format(Locale.ENGLISH, "%1.1f", value);
606         }
607         catch (Exception e)
608         {
609             e.printStackTrace();
610         }
611         notifier.updatedAperture(aperature);
612     }
613
614     private void updateFocusMode(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
615     {
616         String mode = "";
617
618         // Focus Mode
619         if (current == IFujiXFocusingMode.FOCUS_MANUAL)
620         {
621             mode = "MF";
622         }
623         else if (current == IFujiXFocusingMode.FOCUS_CONTINUOUS_AUTO)
624         {
625             mode = "AF-C";
626         }
627         else if (current == IFujiXFocusingMode.FOCUS_SINGLE_AUTO)
628         {
629             mode = "AF-S";
630         }
631         else
632         {
633             mode = mode + current;
634         }
635         logcat(" Focus Mode : " + mode);
636     }
637
638     private void updateFocusedStatus(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
639     {
640         if (current == 1)
641         {
642             // focus Lock
643             notifier.updateFocusedStatus(true, true);
644         }
645         else
646         {
647             // focus unlock
648             notifier.updateFocusedStatus(false, false);
649         }
650     }
651
652     private void updatedTakeMode(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
653     {
654         String mode = "";
655         switch (current)
656         {
657             case IFujiXShootingMode.SHOOTING_MANUAL:
658                 mode = "M";
659                 break;
660             case IFujiXShootingMode.SHOOTING_PROGRAM:
661                 mode = "P";
662                 break;
663             case IFujiXShootingMode.SHOOTING_APERTURE:
664                 mode = "A";
665                 break;
666             case IFujiXShootingMode.SHOOTING_SHUTTER:
667                 mode = "S";
668                 break;
669             case IFujiXShootingMode.SHOOTING_CUSTOM:
670                 mode = "C";
671                 break;
672             case IFujiXShootingMode.SHOOTING_AUTO:
673                 mode = "a";
674                 break;
675             default:
676                 mode = mode + current;
677                 break;
678         }
679         notifier.updatedTakeMode(mode);
680     }
681
682     private void updateBatteryLevel(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
683     {
684         int level;
685         if ((current == IFujiXBatteryMode.BATTERY_CRITICAL) || (current == IFujiXBatteryMode.BATTERY_126S_CRITICAL))
686         {
687             level = 0;
688         }
689         else if (current == IFujiXBatteryMode.BATTERY_126S_ONE_BAR)
690         {
691             level = 20;
692         }
693         else if ((current == IFujiXBatteryMode.BATTERY_ONE_BAR) || (current == IFujiXBatteryMode.BATTERY_126S_TWO_BAR))
694         {
695             level = 40;
696         }
697         else if (current == IFujiXBatteryMode.BATTERY_126S_THREE_BAR)
698         {
699             level = 60;
700         }
701         else if ((current == IFujiXBatteryMode.BATTERY_TWO_BAR) || (current == IFujiXBatteryMode.BATTERY_126S_FOUR_BAR))
702         {
703             level = 80;
704         }
705         else // if ((current == IFujiXBatteryMode.BATTERY_FULL) || (current == IFujiXBatteryMode.BATTERY_126S_FULL))
706         {
707             level = 100;
708         }
709         notifier.updateRemainBattery(level);
710     }
711
712
713     /**
714      *   認識したカメラのステータス名称のリストを応答する
715      *
716      */
717     private List<String> getAvailableStatusNameList()
718     {
719         ArrayList<String> selection = new ArrayList<>();
720         try
721         {
722             for (int index = 0; index < statusHolder.size(); index++)
723             {
724                 int key = statusHolder.keyAt(index);
725                 selection.add(statusNameArray.get(key, String.format(Locale.US, "0x%04x", key)));
726             }
727         }
728         catch (Exception e)
729         {
730             e.printStackTrace();
731         }
732         return (selection);
733
734     }
735
736     List<String> getAvailableItemList(String listKey)
737     {
738         if ((listKey == null)||(listKey.isEmpty()))
739         {
740             // アイテム名の一覧を応答する
741             return (getAvailableStatusNameList());
742         }
743         if (listKey.matches(ICameraStatus.EFFECT))
744         {
745             return (getAvailableEffectItemList());
746         }
747         if (listKey.matches(ICameraStatus.AE))
748         {
749             return (new ArrayList<>());
750         }
751         if (listKey.matches(ICameraStatus.WHITE_BALANCE))
752         {
753             return (getAvailableResourceArrayItemList(R.array.fuji_x_white_balance));
754         }
755         if (listKey.matches(ICameraStatus.ISO_SENSITIVITY))
756         {
757             return (getAvailableResourceArrayItemList(R.array.fuji_x_iso_sensitivity));
758         }
759
760
761         /////  選択可能なステータスの一覧を取得する : でも以下はアイテム名の一覧... /////
762         /*
763         ArrayList<String> selection = new ArrayList<>();
764         try
765         {
766             for (int index = 0; index < statusHolder.size(); index++)
767             {
768                 int key = statusHolder.keyAt(index);
769                 selection.add(statusNameArray.get(key));
770             }
771         }
772         catch (Exception e)
773         {
774             e.printStackTrace();
775         }
776         */
777         return (new ArrayList<>());
778     }
779
780     private List<String> getAvailableEffectItemList()
781     {
782         // EFFECTの選択肢をリストにして返す  : Film Simulation にした。
783         ArrayList<String> selection = new ArrayList<>();
784         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_PROVIA_STR);
785         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_VELVIA_STR);
786         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_ASTIA_STR);
787         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_STR);
788         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_SEPIA_STR);
789         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_PRO_NEG_HI_STR);
790         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_PRO_NEG_STD_STR);
791         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_Y_FILTER_STR);
792         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_R_FILTER_STR);
793         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_G_FILTER_STR);
794         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_CLASSIC_CHROME_STR);
795         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_ACROS_STR);
796         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_ACROS_Y_STR);
797         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_ACROS_R_STR);
798         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_ACROS_G_STR);
799         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_ETERNA_STR);
800         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_CLASSIC_NEGATIVE_STR);
801         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_ETERNA_BLEACH_BYPASS_STR);
802         return(selection);
803     }
804
805     private List<String> getAvailableResourceArrayItemList(int id)
806     {
807         // リソースのの選択肢をリストにして返す
808         ArrayList<String> selection = new ArrayList<>();
809
810         String[] items = activity.getResources().getStringArray(id);
811         for (String item : items)
812         {
813             selection.add(item);
814         }
815         return (selection);
816     }
817
818     private String getCurrentEffectStatus()
819     {
820         // EFFECTの現在状態を応答する : FILM Simulationにした
821         try
822         {
823             int value = statusHolder.get(IFujiXCameraProperties.FILM_SIMULATION);
824             List<String> itemList = getAvailableEffectItemList();
825             if ((value >= IFujiXFilmSimulation.FILM_SIMULATION_MIN)&&(value < itemList.size()))
826             {
827                 return (itemList.get(value - 1));
828             }
829         }
830         catch (Exception e)
831         {
832             e.printStackTrace();
833         }
834         return ("");
835     }
836
837     private String getCurrentWhiteBalanceStatus()
838     {
839         // White Balanceの現在状態を取得する
840         try
841         {
842             int value = statusHolder.get(IFujiXCameraProperties.WHITE_BALANCE);
843             String[] items = activity.getResources().getStringArray(R.array.fuji_x_white_balance);
844             String[] itemValues = activity.getResources().getStringArray(R.array.fuji_x_white_balance_value);
845             int index = 0;
846             for (String itemValue : itemValues)
847             {
848                 int itemValueInt = Integer.parseInt(itemValue);
849                 if (itemValueInt == value)
850                 {
851                     return (items[index]);
852                 }
853                 index++;
854             }
855         }
856         catch (Exception e)
857         {
858             e.printStackTrace();
859         }
860         return ("");
861     }
862
863     private String getCurrentIsoSensitivityStatus()
864     {
865         String iso = "";
866         try
867         {
868             int current = statusHolder.get(IFujiXCameraProperties.ISO);
869             int isoValue = (0x0000ffff & current);
870             if ((0xffff0000 & current) != 0)
871             {
872                 iso = "AUTO_" + isoValue;
873             }
874             else if (isoValue > 12800)
875             {
876                 iso = "H" + isoValue;
877
878             }
879             else if (isoValue < 200)
880             {
881                 iso = "L" + isoValue;
882             }
883             else
884             {
885                 iso = "" + isoValue;
886             }
887         }
888         catch (Exception e)
889         {
890             e.printStackTrace();
891         }
892         logcat(" ISO SENSITIVITY : " + iso);
893         return (iso);
894     }
895
896     private void setEffectItem(String value)
897     {
898         try
899         {
900             int index = 1;
901             List<String> itemList = getAvailableEffectItemList();
902             for (String item : itemList)
903             {
904                 if (item.matches(value))
905                 {
906                     //  見つかった! この値に設定する
907                     publisher.enqueueCommand(new SetPropertyValue(new FujiXReplyMessageReceiver(" Set Film Simulation", true), IFujiXCameraProperties.FILM_SIMULATION, 4, index));
908                     return;
909                 }
910                 index++;
911             }
912         }
913         catch (Exception e)
914         {
915             e.printStackTrace();
916         }
917     }
918
919     private void setCurrentWhiteBalanceStatus(String value)
920     {
921         // White Balanceを設定する
922         try
923         {
924             String[] items = activity.getResources().getStringArray(R.array.fuji_x_white_balance);
925             String[] itemValues = activity.getResources().getStringArray(R.array.fuji_x_white_balance_value);
926             int index = 0;
927             for (String item : items)
928             {
929                 if (item.matches(value))
930                 {
931                     // 見つかった! この値を設定する
932                     String itemValue = itemValues[index];
933                     int itemValueInt = Integer.parseInt(itemValue);
934                     publisher.enqueueCommand(new SetPropertyValue(new FujiXReplyMessageReceiver(" Set White Balance", true), IFujiXCameraProperties.WHITE_BALANCE, 4, itemValueInt));
935                     return;
936                 }
937                 index++;
938             }
939         }
940         catch (Exception e)
941         {
942             e.printStackTrace();
943         }
944     }
945
946     private void setCurrentIsoSensitivityStatus(String value)
947     {
948         // ISO感度を設定する
949         try
950         {
951             String[] items = activity.getResources().getStringArray(R.array.fuji_x_iso_sensitivity);
952             String[] itemValues = activity.getResources().getStringArray(R.array.fuji_x_iso_sensitivity_value);
953             int index = 0;
954             for (String item : items)
955             {
956                 Log.v(TAG, " ===== ISO : " + value + " " + item + " ===== ");
957                 if (item.matches(value))
958                 {
959                     // 見つかった! この値を設定する
960                     String itemValue = itemValues[index];
961                     int itemValueInt = (int) Long.parseLong(itemValue,16);
962                     logcat(" SET ISO SENSITIVITY : " + value + " " + itemValueInt);
963                     publisher.enqueueCommand(new SetPropertyValue(new FujiXReplyMessageReceiver(" Set ISO", true), IFujiXCameraProperties.ISO, 8, itemValueInt));
964                     return;
965                 }
966                 index++;
967             }
968         }
969         catch (Exception e)
970         {
971             e.printStackTrace();
972         }
973     }
974
975     String getItemStatus(String key)
976     {
977         if (key.matches(ICameraStatus.EFFECT))
978         {
979             return (getCurrentEffectStatus());
980         }
981         if (key.matches(ICameraStatus.WHITE_BALANCE))
982         {
983             return (getCurrentWhiteBalanceStatus());
984         }
985         if (key.matches(ICameraStatus.ISO_SENSITIVITY))
986         {
987             return (getCurrentIsoSensitivityStatus());
988         }
989         if (key.matches(ICameraStatus.TAKE_MODE))
990         {
991             return ("");
992         }
993         try
994         {
995             int strIndex = key.indexOf("x");
996             Log.v(TAG, "getItemStatus() : " + key + " [" + strIndex + "]");
997             if (strIndex >= 1)
998             {
999                 key = key.substring(strIndex + 1);
1000                 try
1001                 {
1002                     int id = Integer.parseInt(key, 16);
1003                     int value = statusHolder.get(id);
1004                     logcat("getItemStatus() value : " + value + " key : " + key + " [" + id + "]");
1005                     // dumpStatus();
1006                     return (value + "");
1007                 }
1008                 catch (Exception e)
1009                 {
1010                     e.printStackTrace();
1011                 }
1012             }
1013
1014             for (int index = 0; index < statusNameArray.size(); index++)
1015             {
1016                 int id = statusNameArray.keyAt(index);
1017                 String strKey = statusNameArray.valueAt(index);
1018                 if (key.contentEquals(strKey))
1019                 {
1020                     int value = statusHolder.get(id);
1021                     return (value + "");
1022                 }
1023             }
1024         }
1025         catch (Exception e)
1026         {
1027             e.printStackTrace();
1028         }
1029         return ("? [" + key + "]");
1030     }
1031
1032     void setItemStatus(@NonNull String key, @NonNull String value)
1033     {
1034         try
1035         {
1036             if (logcat)
1037             {
1038                 Log.v(TAG, "setStatus(" + key + ", " + value + ")");
1039             }
1040             if (key.matches(ICameraStatus.EFFECT))
1041             {
1042                 setEffectItem(value);
1043                 return;
1044             }
1045             if (key.matches(ICameraStatus.WHITE_BALANCE))
1046             {
1047                 setCurrentWhiteBalanceStatus(value);
1048                 return;
1049             }
1050             if (key.matches(ICameraStatus.ISO_SENSITIVITY))
1051             {
1052                 setCurrentIsoSensitivityStatus(value);
1053                 // return;
1054             }
1055
1056             // ここで設定を行う。
1057         }
1058         catch (Exception e)
1059         {
1060             e.printStackTrace();
1061         }
1062     }
1063
1064
1065     private void dumpStatus()
1066     {
1067         try
1068         {
1069             Log.v(TAG, " - - - status - - - ");
1070             for (int index = 0; index < statusHolder.size(); index++)
1071             {
1072                 int key = statusHolder.keyAt(index);
1073                 int value = statusHolder.get(key);
1074                 Log.v(TAG, String.format("id : 0x%x value : %d (0x%x) ", key, value, value));
1075             }
1076             Log.v(TAG, " - - - status - - - ");
1077         }
1078         catch (Exception e)
1079         {
1080             e.printStackTrace();
1081         }
1082     }
1083
1084     private void logcat(String message)
1085     {
1086         if (logcat)
1087         {
1088             Log.v(TAG, message);
1089         }
1090     }
1091 }