1 package net.osdn.gokigen.gr2control.camera.ricohgr2.wrapper;
3 import android.app.Activity;
4 import android.support.annotation.NonNull;
5 import android.util.Log;
7 import net.osdn.gokigen.gr2control.camera.ICameraStatus;
8 import net.osdn.gokigen.gr2control.camera.ICameraStatusWatcher;
9 import net.osdn.gokigen.gr2control.camera.utils.SimpleHttpClient;
10 import net.osdn.gokigen.gr2control.liveview.ICameraStatusUpdateNotify;
12 import java.util.ArrayList;
13 import java.util.List;
19 public class RicohGr2StatusChecker implements ICameraStatusWatcher, ICameraStatus
21 private final String TAG = toString();
22 private final String statusCheckUrl = "http://192.168.0.1/v1/props";
23 private final String statusSetUrl = "http://192.168.0.1/v1/params/camera";
24 private final String grCommandUrl = "http://192.168.0.1/_gr";
25 private final int sleepMs;
27 private final boolean useGrCommand;
29 private int timeoutMs = 5000;
30 private boolean whileFetching = false;
31 private RicohGr2StatusHolder statusHolder;
37 RicohGr2StatusChecker(int sleepMs, boolean useGrCommand)
39 this.useGrCommand = useGrCommand;
40 this.sleepMs = sleepMs;
48 public void startStatusWatch(@NonNull ICameraStatusUpdateNotify notifier)
50 Log.v(TAG, "startStatusWatch()");
53 this.statusHolder = new RicohGr2StatusHolder(notifier);
54 Thread thread = new Thread(new Runnable()
61 start(statusCheckUrl);
82 public void stopStatusWatch()
84 Log.v(TAG, "stoptStatusWatch()");
85 whileFetching = false;
92 private void start(@NonNull final String watchUrl)
96 Log.v(TAG, "start() already starting.");
102 whileFetching = true;
103 Thread thread = new Thread(new Runnable()
108 Log.d(TAG, "Start status watch.");
109 while (whileFetching)
113 statusHolder.updateStatus(SimpleHttpClient.httpGet(watchUrl, timeoutMs));
114 Thread.sleep(sleepMs);
121 Log.v(TAG, "STATUS WATCH STOPPED.");
133 public @NonNull List<String> getStatusList(@NonNull final String key)
137 if (statusHolder == null)
139 return (new ArrayList<>());
141 String listKey = key + "List";
142 return (statusHolder.getAvailableItemList(listKey));
148 return (new ArrayList<>());
152 public String getStatus(@NonNull String key)
156 if (statusHolder == null)
160 return (statusHolder.getItemStatus(key));
170 public void setStatus(@NonNull final String key, @NonNull final String value)
172 Thread thread = new Thread(new Runnable() {
178 String postData = key + "=" + value;
179 if ((useGrCommand)&&(key.equals("exposureMode")))
181 // 撮影モードを変更するときは、GR専用コマンドを送ることにする。
182 postData = "cmd=" + decideButtonCode(value);
183 response = SimpleHttpClient.httpPost(grCommandUrl, postData, timeoutMs);
184 Log.v(TAG, "CHANGE MODE : " + postData + " resp. (" + response.length() + "bytes.)");
187 response = SimpleHttpClient.httpPut(statusSetUrl, postData, timeoutMs);
188 Log.v(TAG, "SET PROPERTY : " + postData + " resp. (" + response.length() + "bytes.)");
192 // GR専用コマンドで、画面表示をリフレッシュ
193 response = SimpleHttpClient.httpPost(grCommandUrl, "cmd=mode refresh", timeoutMs);
194 Log.v(TAG, "refresh resp. (" + response.length() + "bytes.)");
214 * 撮影モードをGRのダイアルコマンドに変更する
217 private String decideButtonCode(String exposureMode)
219 String buttonCode = "bdial AUTO";
220 if (exposureMode == null)
224 switch (exposureMode)
227 buttonCode = "bdial MOVIE";
230 buttonCode = "bdial M";
233 buttonCode = "bdial TAV";
236 buttonCode = "bdial AV";
239 buttonCode = "bdial TV";
242 buttonCode = "bdial P";
245 buttonCode = "bdial AUTO";